added ntlm + utf-16le conversion
This commit is contained in:
		
							
								
								
									
										11
									
								
								src/misc.typ
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/misc.typ
									
									
									
									
									
								
							| @@ -1,5 +1,7 @@ | ||||
| #import "utils.typ": xor-bytes | ||||
| #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) = { | ||||
|   if key.len() > block-size { | ||||
| @@ -45,4 +47,13 @@ | ||||
|   let o-key-pad = xor-bytes(key, o-pad) | ||||
|  | ||||
|   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 | ||||
|  | ||||
|   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