From 79cbfce36d16113c007a3b2a6d797169c3bd3e8e Mon Sep 17 00:00:00 2001 From: Takashi Kojo Date: Fri, 31 Jul 2026 17:02:33 +0900 Subject: [PATCH 1/2] Honor WC_SIG_MIN_HASH_TYPE override in signature decision test --- tests/api/test_signature.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/tests/api/test_signature.c b/tests/api/test_signature.c index 5a8bf2d490..28b8f3d2dc 100644 --- a/tests/api/test_signature.c +++ b/tests/api/test_signature.c @@ -41,6 +41,13 @@ #include #include +/* Effective hash floor used by wc_SignatureVerify/Generate; mirrors the + * default in wolfcrypt/src/signature.c. A build may lower it (e.g. + * --enable-wolfclu defines WC_SIG_MIN_HASH_TYPE=WC_HASH_TYPE_MD5). */ +#ifndef WC_SIG_MIN_HASH_TYPE + #define WC_SIG_MIN_HASH_TYPE WC_HASH_TYPE_SHA256 +#endif + /* Testing wc_SignatureGetSize() for signature type ECC */ int test_wc_SignatureGetSize_ecc(void) { @@ -337,10 +344,14 @@ int test_wc_SignatureDecisionCoverage(void) #ifndef NO_SHA /* Hash weaker than WC_SIG_MIN_HASH_TYPE (default SHA-256) - * rejected by wc_SignatureCheckHashStrength() */ - ExpectIntEQ(wc_SignatureVerify(WC_HASH_TYPE_SHA, sig_type, - data, data_len, sig, sig_len, &ecc, key_len), - WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + * rejected by wc_SignatureCheckHashStrength(). Only assert + * when SHA-1 is below the effective floor of this build. */ + if (wc_HashGetDigestSize(WC_SIG_MIN_HASH_TYPE) > + wc_HashGetDigestSize(WC_HASH_TYPE_SHA)) { + ExpectIntEQ(wc_SignatureVerify(WC_HASH_TYPE_SHA, sig_type, + data, data_len, sig, sig_len, &ecc, key_len), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + } #endif /* Real signature that fails verification: SIG_VERIFY_E. @@ -518,8 +529,11 @@ int test_wc_SignatureDecisionCoverage(void) } #ifndef NO_SHA - /* Weak hash rejected before any hashing/signing occurs */ - { + /* Weak hash rejected before any hashing/signing occurs. Only + * assert when SHA-1 is below the effective floor of this + * build. */ + if (wc_HashGetDigestSize(WC_SIG_MIN_HASH_TYPE) > + wc_HashGetDigestSize(WC_HASH_TYPE_SHA)) { word32 lenCopy = (word32)eccSigMax; ExpectIntEQ(wc_SignatureGenerate(WC_HASH_TYPE_SHA, sig_type, data, data_len, genSig, &lenCopy, &ecc, key_len, &rng), From d06579277d1fa2bec8769cacce13e047ecb99dee Mon Sep 17 00:00:00 2001 From: Takashi Kojo Date: Sun, 2 Aug 2026 20:56:01 +0900 Subject: [PATCH 2/2] Move WC_SIG_MIN_HASH_TYPE default into signature.h --- tests/api/test_signature.c | 7 ------- wolfcrypt/src/signature.c | 10 ---------- wolfssl/wolfcrypt/signature.h | 10 ++++++++++ 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/tests/api/test_signature.c b/tests/api/test_signature.c index 28b8f3d2dc..25b7ca7dd6 100644 --- a/tests/api/test_signature.c +++ b/tests/api/test_signature.c @@ -41,13 +41,6 @@ #include #include -/* Effective hash floor used by wc_SignatureVerify/Generate; mirrors the - * default in wolfcrypt/src/signature.c. A build may lower it (e.g. - * --enable-wolfclu defines WC_SIG_MIN_HASH_TYPE=WC_HASH_TYPE_MD5). */ -#ifndef WC_SIG_MIN_HASH_TYPE - #define WC_SIG_MIN_HASH_TYPE WC_HASH_TYPE_SHA256 -#endif - /* Testing wc_SignatureGetSize() for signature type ECC */ int test_wc_SignatureGetSize_ecc(void) { diff --git a/wolfcrypt/src/signature.c b/wolfcrypt/src/signature.c index a45bdd0d92..797cfeffb9 100644 --- a/wolfcrypt/src/signature.c +++ b/wolfcrypt/src/signature.c @@ -53,16 +53,6 @@ #endif #endif -/* Minimum hash strength accepted by the wc_SignatureVerify/Generate - * convenience APIs. Default is SHA-256 to keep MD5 and SHA-1 (both with - * known collision attacks) out of new code. Define WC_SIG_MIN_HASH_TYPE - * to a weaker wc_HashType (e.g. WC_HASH_TYPE_SHA) to opt back into legacy - * behavior. The lower-level wc_SignatureVerifyHash/wc_SignatureGenerateHash - * APIs are unaffected. */ -#ifndef WC_SIG_MIN_HASH_TYPE - #define WC_SIG_MIN_HASH_TYPE WC_HASH_TYPE_SHA256 -#endif - static int wc_SignatureCheckHashStrength(enum wc_HashType hash_type) { int min_sz, this_sz; diff --git a/wolfssl/wolfcrypt/signature.h b/wolfssl/wolfcrypt/signature.h index 7f7b2acfab..e036072259 100644 --- a/wolfssl/wolfcrypt/signature.h +++ b/wolfssl/wolfcrypt/signature.h @@ -35,6 +35,16 @@ extern "C" { #endif +/* Minimum hash strength accepted by the wc_SignatureVerify/Generate + * convenience APIs. Default is SHA-256 to keep MD5 and SHA-1 (both with + * known collision attacks) out of new code. Define WC_SIG_MIN_HASH_TYPE + * to a weaker wc_HashType (e.g. WC_HASH_TYPE_SHA) to opt back into legacy + * behavior. The lower-level wc_SignatureVerifyHash/wc_SignatureGenerateHash + * APIs are unaffected. */ +#ifndef WC_SIG_MIN_HASH_TYPE + #define WC_SIG_MIN_HASH_TYPE WC_HASH_TYPE_SHA256 +#endif + enum wc_SignatureType { WC_SIGNATURE_TYPE_NONE = 0, WC_SIGNATURE_TYPE_ECC = 1,