Skip to content

Commit 6ba2bce

Browse files
Alex RischAlex Risch
Alex Risch
authored and
Alex Risch
committed
fix: Hmac Fixes
Updated handling of hmac to use hkdf keys
1 parent c67dfd2 commit 6ba2bce

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

library/src/main/java/org/xmtp/android/library/Conversations.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package org.xmtp.android.library
22

33
import android.util.Log
44
import com.google.protobuf.kotlin.toByteString
5-
import com.google.protobuf.kotlin.toByteStringUtf8
65
import io.grpc.StatusException
76
import kotlinx.coroutines.CancellationException
87
import kotlinx.coroutines.channels.awaitClose
@@ -327,7 +326,7 @@ data class Conversations(
327326
Crypto.deriveKey(
328327
conversation.keyMaterial!!,
329328
ByteArray(0),
330-
info.toByteStringUtf8().toByteArray()
329+
info.toByteArray(Charsets.UTF_8),
331330
)
332331
val hmacKeyData = HmacKeyData.newBuilder()
333332
hmacKeyData.hmacKey = hmacKey.toByteString()

library/src/main/java/org/xmtp/android/library/Crypto.kt

+1-6
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,7 @@ class Crypto {
8787
salt: ByteArray,
8888
info: ByteArray,
8989
): ByteArray {
90-
val keySpec = SecretKeySpec(secret, "HmacSHA256")
91-
val hmac = Mac.getInstance("HmacSHA256")
92-
hmac.init(keySpec)
93-
val derivedKey = hmac.doFinal(salt + info)
94-
95-
return derivedKey.copyOfRange(0, 32)
90+
return Hkdf.computeHkdf("HMACSHA256", secret, salt, info, 32)
9691
}
9792

9893
fun verifyHmacSignature(

0 commit comments

Comments
 (0)