Avoids creating a byte array and recreating it again inside of the Mac instance.

This commit is contained in:
Vitor Pamplona
2025-09-15 12:30:56 -04:00
parent 67f9557081
commit bd70058f78
2 changed files with 13 additions and 1 deletions
@@ -210,7 +210,7 @@ class Nip44v2 {
"AAD associated data must be 32 bytes, but it was ${aad.size} bytes"
}
return hkdf.extract(aad + message, key)
return hkdf.extract(aad, message, key)
}
fun getMessageKeys(
@@ -37,6 +37,18 @@ class Hkdf(
return mac.doFinal(key)
}
fun extract(
key1: ByteArray,
key2: ByteArray,
salt: ByteArray,
): ByteArray {
val mac = Mac.getInstance(algorithm)
mac.init(SecretKeySpec(salt, algorithm))
mac.update(key1)
mac.update(key2)
return mac.doFinal()
}
fun expand(
key: ByteArray,
nonce: ByteArray,