added ntlm + utf-16le conversion
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								manual.pdf
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								manual.pdf
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							| @@ -13,25 +13,31 @@ | |||||||
| ) | ) | ||||||
| #tidy.show-module(sha-doc) | #tidy.show-module(sha-doc) | ||||||
|  |  | ||||||
|  | #pagebreak(weak: true) | ||||||
|  |  | ||||||
| #let md-doc = mod( | #let md-doc = mod( | ||||||
|   read("src/md.typ"), |   read("src/md.typ"), | ||||||
|   name: "md" |   name: "md" | ||||||
| ) | ) | ||||||
| #tidy.show-module(md-doc) | #tidy.show-module(md-doc) | ||||||
|  |  | ||||||
|  | #pagebreak(weak: true) | ||||||
|  |  | ||||||
| #let misc-doc = mod( | #let misc-doc = mod( | ||||||
|   read("src/misc.typ"), |   read("src/misc.typ"), | ||||||
|   name: "misc" |   name: "misc" | ||||||
| ) | ) | ||||||
| #tidy.show-module(misc-doc) | #tidy.show-module(misc-doc) | ||||||
|  |  | ||||||
|  | #pagebreak(weak: true) | ||||||
|  |  | ||||||
| #let base-doc = mod( | #let base-doc = mod( | ||||||
|   read("src/base.typ"), |   read("src/base.typ"), | ||||||
|   name: "base" |   name: "base" | ||||||
| ) | ) | ||||||
| #tidy.show-module(base-doc) | #tidy.show-module(base-doc) | ||||||
|  |  | ||||||
| #pagebreak() | #pagebreak(weak: true) | ||||||
|  |  | ||||||
| #let utils-doc = mod( | #let utils-doc = mod( | ||||||
|   read("src/utils.typ"), |   read("src/utils.typ"), | ||||||
|   | |||||||
							
								
								
									
										11
									
								
								src/misc.typ
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/misc.typ
									
									
									
									
									
								
							| @@ -1,5 +1,7 @@ | |||||||
| #import "utils.typ": xor-bytes | #import "utils.typ": xor-bytes | ||||||
| #import "sha.typ": sha1 | #import "sha.typ": sha1 | ||||||
|  | #import "md.typ": md4 | ||||||
|  | #import "utils.typ": utf8-to-utf16le | ||||||
|  |  | ||||||
| #let _compute-block-sized-key(key, hash-func: sha1, block-size: 64) = { | #let _compute-block-sized-key(key, hash-func: sha1, block-size: 64) = { | ||||||
|   if key.len() > block-size { |   if key.len() > block-size { | ||||||
| @@ -45,4 +47,13 @@ | |||||||
|   let o-key-pad = xor-bytes(key, o-pad) |   let o-key-pad = xor-bytes(key, o-pad) | ||||||
|  |  | ||||||
|   return hash-func(o-key-pad + hash-func(i-key-pad + message)) |   return hash-func(o-key-pad + hash-func(i-key-pad + message)) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /// New Technology LAN Manager (aka. Windows password hash) | ||||||
|  | /// ```example | ||||||
|  | /// #bytes-to-hex(ntlm("Bellevue")) | ||||||
|  | /// ``` | ||||||
|  | /// -> bytes | ||||||
|  | #let ntlm(password) = { | ||||||
|  |   return md4(utf8-to-utf16le(password)) | ||||||
| } | } | ||||||
| @@ -116,4 +116,29 @@ | |||||||
|   let d2 = a |   let d2 = a | ||||||
|  |  | ||||||
|   return a2.bit-or(b2).bit-or(c2).bit-or(d2) |   return a2.bit-or(b2).bit-or(c2).bit-or(d2) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /// Converts a UTF-8 string to UTF-16LE | ||||||
|  | /// -> bytes | ||||||
|  | #let utf8-to-utf16le( | ||||||
|  |   /// -> str | ||||||
|  |   string | ||||||
|  | ) = { | ||||||
|  |   let utf16le-bytes = () | ||||||
|  |   for c in string.codepoints() { | ||||||
|  |     let u = c.to-unicode() | ||||||
|  |     if u <= 0xffff { | ||||||
|  |       utf16le-bytes.push(u.bit-and(0xff)) | ||||||
|  |       utf16le-bytes.push(u.bit-rshift(8)) | ||||||
|  |     } else { | ||||||
|  |       let u2 = u - 0x10000 | ||||||
|  |       let hs = 0xd800 + u2.bit-rshift(10) | ||||||
|  |       let ls = 0xdc00 + u2.bit-and(0x3ff) | ||||||
|  |       utf16le-bytes.push(hs.bit-and(0xff)) | ||||||
|  |       utf16le-bytes.push(hs.bit-rshift(8)) | ||||||
|  |       utf16le-bytes.push(ls.bit-and(0xff)) | ||||||
|  |       utf16le-bytes.push(ls.bit-rshift(8)) | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |   return bytes(utf16le-bytes) | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user