commit 921ffd11f650cf9002d2a052e4f1af06f8a9b23f
parent 6e0f963175c5d1efac3ef8d4091927029865185d
Author: Armin Preiml <apreiml@strohwolke.at>
Date: Thu, 2 May 2024 15:03:15 +0200
crypto::hmac: fix fail when buf is non-zero
Signed-off-by: Armin Preiml <apreiml@strohwolke.at>
Diffstat:
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/crypto/hmac/+test.ha b/crypto/hmac/+test.ha
@@ -13,7 +13,7 @@ use strings;
fn assert_hmac_sha1(keystr: str, vectors: [](str, [20]u8)) void = {
let key = strings::toutf8(keystr);
let h = sha1::sha1();
- let buf: [sha1::BLOCKSZ]u8 = [0...];
+ let buf: [sha1::BLOCKSZ]u8 = [0x1...];
for (let i = 0z; i < len(vectors); i += 1) {
hash::reset(&h);
diff --git a/crypto/hmac/hmac.ha b/crypto/hmac/hmac.ha
@@ -49,6 +49,8 @@ export fn hmac(h: *hash::hash, key: const []u8, buf: []u8) state = {
fn init(h: *hash::hash, key: []u8, keypad: []u8) void = {
const bsz = hash::bsz(h);
+
+ keypad[..] = [0...];
if (len(key) > bsz) {
hash::write(h, key);
hash::sum(h, keypad);