added ntlm + utf-16le conversion

This commit is contained in:
Louis Heredero 2024-12-22 01:10:33 +01:00
parent 02ee768ebb
commit e191d82407
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
4 changed files with 43 additions and 1 deletions

Binary file not shown.

View File

@ -13,25 +13,31 @@
)
#tidy.show-module(sha-doc)
#pagebreak(weak: true)
#let md-doc = mod(
read("src/md.typ"),
name: "md"
)
#tidy.show-module(md-doc)
#pagebreak(weak: true)
#let misc-doc = mod(
read("src/misc.typ"),
name: "misc"
)
#tidy.show-module(misc-doc)
#pagebreak(weak: true)
#let base-doc = mod(
read("src/base.typ"),
name: "base"
)
#tidy.show-module(base-doc)
#pagebreak()
#pagebreak(weak: true)
#let utils-doc = mod(
read("src/utils.typ"),

View File

@ -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 {
@ -46,3 +48,12 @@
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))
}

View File

@ -117,3 +117,28 @@
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)
}