From b67558286134ceb520511c5d2638b1be023bc612 Mon Sep 17 00:00:00 2001 From: Michal Rybecky Date: Wed, 1 Apr 2026 13:16:42 +0200 Subject: [PATCH] hmac: add comments explaining why each buffer needs erasing As requested in review: clarify that the padding arrays carry key material (key XOR fixed constant, trivially reversible), not just padding bytes. --- src/basic/hmac.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/basic/hmac.c b/src/basic/hmac.c index 3697fe2252..72cf59d468 100644 --- a/src/basic/hmac.c +++ b/src/basic/hmac.c @@ -17,13 +17,13 @@ void hmac_sha256(const void *key, uint8_t res[static SHA256_DIGEST_SIZE]) { uint8_t inner_padding[HMAC_BLOCK_SIZE] = { }; - CLEANUP_ERASE(inner_padding); + CLEANUP_ERASE(inner_padding); /* carries key ^ 0x36, trivially reversible to the original key */ uint8_t outer_padding[HMAC_BLOCK_SIZE] = { }; - CLEANUP_ERASE(outer_padding); + CLEANUP_ERASE(outer_padding); /* carries key ^ 0x5c, trivially reversible to the original key */ uint8_t replacement_key[SHA256_DIGEST_SIZE]; - CLEANUP_ERASE(replacement_key); + CLEANUP_ERASE(replacement_key); /* SHA-256 of the key when key_size > block size */ struct sha256_ctx hash; - CLEANUP_ERASE(hash); + CLEANUP_ERASE(hash); /* intermediate state derived from key material */ assert(key); assert(key_size > 0);