Moves the message key to the HKDF function

This commit is contained in:
Vitor Pamplona
2025-09-15 16:21:11 -04:00
parent 239cac430e
commit e329b096ba
2 changed files with 8 additions and 9 deletions

View File

@@ -99,7 +99,7 @@ class Nip44v2 {
): String = decrypt(EncryptedInfo.decodePayload(payload), conversationKey)
fun checkHMacAad(
messageKey: MessageKey,
messageKey: Hkdf.MessageKey,
decoded: EncryptedInfo,
) {
val calculatedMac = hmacAad(messageKey.hmacKey, decoded.ciphertext, decoded.nonce)
@@ -208,13 +208,7 @@ class Nip44v2 {
fun getMessageKeys(
conversationKey: ByteArray,
nonce: ByteArray,
): MessageKey = hkdf.fastExpand(conversationKey, nonce)
class MessageKey(
val chachaKey: ByteArray,
val chachaNonce: ByteArray,
val hmacKey: ByteArray,
)
): Hkdf.MessageKey = hkdf.fastExpand(conversationKey, nonce)
/** @return 32B shared secret */
fun computeConversationKey(

View File

@@ -20,7 +20,6 @@
*/
package com.vitorpamplona.quartz.nip44Encryption.crypto
import com.vitorpamplona.quartz.nip44Encryption.Nip44v2.MessageKey
import java.nio.ByteBuffer
import javax.crypto.Mac
import javax.crypto.spec.SecretKeySpec
@@ -123,4 +122,10 @@ class Hkdf(
hmacKey = hmacKey,
)
}
class MessageKey(
val chachaKey: ByteArray,
val chachaNonce: ByteArray,
val hmacKey: ByteArray,
)
}