Repository navigation
ecc: require hashSz to match hashType for deterministic k - #12060
yosuke-wolfssl wants to merge 1 commit into
Conversation
|
- wc_ecc_gen_deterministic_k() returns BAD_FUNC_ARG when hashSz is not the digest size of hashType. - Updated Doxygen for wc_ecc_gen_deterministic_k(). - tests: add test_wc_ecc_deterministic_hash_type. Issue: F-17433
9336ffb to
e01fa3d
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12060
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-bugs
Not reviewed (no scan target covers them): doc/dox_comments/header_files/ecc.h, tests/api/test_ecc.h
Coverage: 2 of 2 in-scope changed file(s) opened by the reviewer
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Max
|
@claude review |
There was a problem hiding this comment.
I reviewed this PR and didn't find any bugs. Because it changes the ECDSA deterministic-k (RFC 6979) path and is a deliberate behaviour change for callers, a human look is still worthwhile.
What was reviewed:
- The new
wc_HmacSizeByType(hashType) != hashSzcheck inwc_ecc_gen_deterministic_k. It runs after the WC_HASH_TYPE_NONE mapping, so the defaultwc_ecc_set_deterministicpath (32/48/64-byte digests) is unaffected. - The existing direct callers: the KATs in wolfcrypt/test/test.c and tests/unit-mcdc/test_ecc_whitebox.c all pass a digest size that matches the hash type, so they keep passing.
- The trade-off: callers of
wc_ecc_set_deterministic_exthat sign a digest of a different length (the RFC 6979 §3.6 two-hash variant) used to get signatures. Throughwc_ecc_sign_hashthey now get ECC_PRIV_KEY_E. The PR states this is intended. Whether it needs a release note is a maintainer call. - I did not build or run anything, so the new test and the guard combinations were only checked by reading.
Extended reasoning...
The change adds one size check to wc_ecc_gen_deterministic_k in wolfcrypt/src/ecc.c, plus Doxygen updates and a new API test. It touches crypto code: ECDSA nonce generation. It tightens input validation and does not change how k is derived for inputs that are still accepted. I deferred because this is a crypto path and the change breaks callers that pair a hash type with a digest of a different length, which is a compatibility decision for maintainers. Earlier Copilot inline threads were resolved by the author after a follow-up commit, and nobody else has resolved them.



Problem
wc_ecc_gen_deterministic_k()keys every HMAC withhashTypebut sizes the RFC 6979 K/V state from the length of the digest being signed (VSz = KSz = hashSz). Nothing checks that the two agree, andwc_ecc_set_deterministic_ex()stores any hash type on the key.Fix (
wolfcrypt/src/ecc.c)wc_ecc_gen_deterministic_k()returnsBAD_FUNC_ARGwhenhashSz != wc_HashGetDigestSize(hashType). Throughwc_ecc_sign_hash()the failure is reported asECC_PRIV_KEY_E.A mismatch is rejected rather than supported as the RFC 6979 §3.6 two-hash variant. This matches RSA-PSS and the ML-DSA/SLH-DSA pre-hash APIs, which already reject a digest whose length does not match the hash type.
The doxygen for
wc_ecc_gen_deterministic_k()now documents the requirement and theBAD_FUNC_ARGreturn.Closes f-17433.
Tests
New
test_wc_ecc_deterministic_hash_type(P-256 key, runs on FIPS v7 and later):hashTypesetWC_HASH_TYPE_SHA2560WC_HASH_TYPE_SHA256ECC_PRIV_KEY_EWC_HASH_TYPE_SHA384ECC_PRIV_KEY_EVerification
0and the test fails.--enable-ecc CPPFLAGS=-DWOLFSSL_ECDSA_DETERMINISTIC_Kand--enable-all(variant): new test passes,eccAPI group has 0 failures,testwolfcryptpasses including the RFC 6979 known-answer tests.-Werror.