From 546b78c14c89a29b65eb28d3be9e7a4fc056657f Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Wed, 15 Jul 2026 23:44:40 +0200 Subject: [PATCH] hash: consistent error code for uninitialized wc_Hash ops under debug Under DEBUG_WOLFSSL the hash->type != type check in wc_HashUpdate, wc_HashFinal and wc_HashFree fired for an uninitialized hash (hash->type == WC_HASH_TYPE_NONE), returning BAD_FUNC_ARG where a non-debug build returns HASH_TYPE_E from the type switch, so the returned error code depended on whether DEBUG_WOLFSSL was defined. Only apply the mismatch check to initialized hashes; the genuine init-then-wrong-type misuse check is preserved. --- wolfcrypt/src/hash.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wolfcrypt/src/hash.c b/wolfcrypt/src/hash.c index ed6342ae4fe..f421f7188e9 100644 --- a/wolfcrypt/src/hash.c +++ b/wolfcrypt/src/hash.c @@ -1143,7 +1143,7 @@ int wc_HashUpdate(wc_HashAlg* hash, enum wc_HashType type, const byte* data, return BAD_FUNC_ARG; #ifdef DEBUG_WOLFSSL - if (hash->type != type) { + if (hash->type != WC_HASH_TYPE_NONE && hash->type != type) { WOLFSSL_MSG("Hash update type mismatch!"); return BAD_FUNC_ARG; } @@ -1292,7 +1292,7 @@ int wc_HashFinal(wc_HashAlg* hash, enum wc_HashType type, byte* out) return BAD_FUNC_ARG; #ifdef DEBUG_WOLFSSL - if (hash->type != type) { + if (hash->type != WC_HASH_TYPE_NONE && hash->type != type) { WOLFSSL_MSG("Hash final type mismatch!"); return BAD_FUNC_ARG; } @@ -1443,7 +1443,7 @@ int wc_HashFree(wc_HashAlg* hash, enum wc_HashType type) return BAD_FUNC_ARG; #ifdef DEBUG_WOLFSSL - if (hash->type != type) { + if (hash->type != WC_HASH_TYPE_NONE && hash->type != type) { WOLFSSL_MSG("Hash free type mismatch!"); return BAD_FUNC_ARG; }