mirror of
https://github.com/vacp2p/mix.git
synced 2026-01-09 22:18:09 -05:00
Truncate HMAC to 16 bytes
This commit is contained in:
@@ -25,5 +25,6 @@ proc kdf*(key: openArray[byte]): seq[byte] =
|
||||
result = hash[0..15]
|
||||
|
||||
# This function computes a HMAC for 'data' using given 'key'.
|
||||
proc hmac*(key, data: openArray[byte]): array[32, byte] =
|
||||
return sha256.hmac(key, data).data
|
||||
proc hmac*(key, data: openArray[byte]): seq[byte] =
|
||||
let hmac = sha256.hmac(key, data).data
|
||||
result = hmac[0..15]
|
||||
@@ -53,7 +53,7 @@ suite "cryptographic_functions_tests":
|
||||
let data: seq[byte] = cast[seq[byte]]("thisisdata")
|
||||
|
||||
# Expected HMAC (hexadecimal representation)
|
||||
let expectedHmacHex = "b075dd302655e085d35e8cef5dfdf101e0701c21bd00baf0e568d5d556c1150c"
|
||||
let expectedHmacHex = "b075dd302655e085d35e8cef5dfdf101"
|
||||
let expectedHmac = fromHex(expectedHmacHex)
|
||||
|
||||
# Compute HMAC
|
||||
@@ -106,7 +106,7 @@ suite "cryptographic_functions_tests":
|
||||
# Define test data
|
||||
let emptyKey: array[0, byte] = []
|
||||
let emptyData: array[0, byte] = []
|
||||
let expectedHmacHex = "b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad" # SHA-256 HMAC of empty key and data
|
||||
let expectedHmacHex = "b613679a0814d9ec772f95d778c35fc5" # SHA-256 HMAC of empty key and data
|
||||
let expectedHmac = fromHex(expectedHmacHex)
|
||||
|
||||
# Compute HMAC
|
||||
|
||||
Reference in New Issue
Block a user