mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-27 23:36:21 +02:00
Moves the message key to the HKDF function
This commit is contained in:
@@ -99,7 +99,7 @@ class Nip44v2 {
|
|||||||
): String = decrypt(EncryptedInfo.decodePayload(payload), conversationKey)
|
): String = decrypt(EncryptedInfo.decodePayload(payload), conversationKey)
|
||||||
|
|
||||||
fun checkHMacAad(
|
fun checkHMacAad(
|
||||||
messageKey: MessageKey,
|
messageKey: Hkdf.MessageKey,
|
||||||
decoded: EncryptedInfo,
|
decoded: EncryptedInfo,
|
||||||
) {
|
) {
|
||||||
val calculatedMac = hmacAad(messageKey.hmacKey, decoded.ciphertext, decoded.nonce)
|
val calculatedMac = hmacAad(messageKey.hmacKey, decoded.ciphertext, decoded.nonce)
|
||||||
@@ -208,13 +208,7 @@ class Nip44v2 {
|
|||||||
fun getMessageKeys(
|
fun getMessageKeys(
|
||||||
conversationKey: ByteArray,
|
conversationKey: ByteArray,
|
||||||
nonce: ByteArray,
|
nonce: ByteArray,
|
||||||
): MessageKey = hkdf.fastExpand(conversationKey, nonce)
|
): Hkdf.MessageKey = hkdf.fastExpand(conversationKey, nonce)
|
||||||
|
|
||||||
class MessageKey(
|
|
||||||
val chachaKey: ByteArray,
|
|
||||||
val chachaNonce: ByteArray,
|
|
||||||
val hmacKey: ByteArray,
|
|
||||||
)
|
|
||||||
|
|
||||||
/** @return 32B shared secret */
|
/** @return 32B shared secret */
|
||||||
fun computeConversationKey(
|
fun computeConversationKey(
|
||||||
|
@@ -20,7 +20,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.vitorpamplona.quartz.nip44Encryption.crypto
|
package com.vitorpamplona.quartz.nip44Encryption.crypto
|
||||||
|
|
||||||
import com.vitorpamplona.quartz.nip44Encryption.Nip44v2.MessageKey
|
|
||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
import javax.crypto.Mac
|
import javax.crypto.Mac
|
||||||
import javax.crypto.spec.SecretKeySpec
|
import javax.crypto.spec.SecretKeySpec
|
||||||
@@ -123,4 +122,10 @@ class Hkdf(
|
|||||||
hmacKey = hmacKey,
|
hmacKey = hmacKey,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MessageKey(
|
||||||
|
val chachaKey: ByteArray,
|
||||||
|
val chachaNonce: ByteArray,
|
||||||
|
val hmacKey: ByteArray,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user