Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Under WOLFSSL_ASN_TEMPLATE, the DigestInfo validator accepts malformed 05 80 NULL parameters, allowing them to be signed and verified despite the DER-only contract.
2 open issues
What changed in this PR
This PR tightens wolfCrypt’s signature hash APIs to reject malformed or mismatched hash inputs consistently, addressing the RSA_W_ENC behavior reported in #12231.
Changes:
- Adds shared DigestInfo validation for RSA_W_ENC generation and verification, with
SIG_TYPE_Ewhen ASN support is unavailable. - Rejects wrong-length ECC and plain RSA hashes during generation.
- Adds regression tests and clarifies API input requirements and return codes.
| File | Description |
|---|---|
wolfssl/wolfcrypt/signature.h |
Clarifies which APIs add or accept DigestInfo. |
wolfcrypt/src/signature.c |
Adds shared DigestInfo validation and generation length checks. |
tests/api/test_signature.c |
Covers valid encodings, malformed inputs, and hash-length mismatches. |
doc/dox_comments/header_files/signature.h |
Documents hash input requirements and validation errors. |
Review effort: Balanced
|
8b1f335 to
4066e98
Compare
|
@claude review |
d1e1c02 to
e35b551
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12263
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): doc/dox_comments/header_files/signature.h
Coverage: 3 of 3 in-scope changed file(s) opened by the reviewer
Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
Review tier: Max
e35b551 to
d97f663
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12263
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): doc/dox_comments/header_files/signature.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: Lite
Fenrir's latest completed scan found no issues; clearing the prior automated change request.
|
Jenkins retest this please |
wc_SignatureGenerateHash_ex() signed whatever it was given. For WC_SIGNATURE_TYPE_RSA_W_ENC a bare digest produced PKCS#1 v1.5 padding without a DigestInfo, which no other implementation accepts, and the default self-verify then failed with ASN_PARSE_E after the signature buffer was already written. For ECC and plain RSA a hash of the wrong length for hash_type was signed as-is. wc_SignatureVerifyHash() parsed the DigestInfo but skipped the AlgorithmIdentifier OID and ignored trailing data, so a DigestInfo for another hash, or one followed by extra bytes, passed validation. Both functions now apply the same checks. For RSA_W_ENC, hash_data must be exactly one DER DigestInfo whose AlgorithmIdentifier holds the OID of hash_type with absent or NULL (05 00) parameters, and whose digest has the hash_type size. The OID and parameters are compared byte for byte, because GetAlgoId() matches only an OID sum in NO_VERIFY_OID builds and for hashes OidFromId() does not know, and the template GetAlgoId() reads an indefinite-length NULL (05 80) as an empty one. For the other types, hash_len must be the hash_type digest size. WC_HASH_TYPE_MD5_SHA returns HASH_TYPE_E, since MD5||SHA-1 has no DigestInfo OID and wc_HashGetOID() maps it to the MD5 OID. A hash type whose OID OidFromId() does not know, such as SM3, also returns HASH_TYPE_E. Without ASN support, the RSA_W_ENC hash APIs return SIG_TYPE_E, as the data APIs already do. Fixes wolfSSL#12231. Fixes F-16574. Fixes F-16575.
d97f663 to
4981cfc
Compare


Description
wc_SignatureGenerateHash_ex()signed any input, so an RSA_W_ENC caller passing a bare hash got a signature no other implementation accepts, andwc_SignatureVerifyHash()accepted a DigestInfo with the wrong OID or trailing data. Both now validate the hash input the same way.Fixes #12231, F-16574 and F-16575.
hash_type, on generate and verify.hash_typedigest size, as verify already did.SIG_TYPE_Ewithout ASN, matching the data APIs.WC_SIGNATURE_TYPE_RSA_W_ENCenum comment says which APIs add the DigestInfo.Behavior change
wc_SignatureGenerateHash_ex(..., verify=0)now fails for input it used to sign: a bare hash with RSA_W_ENC, or a wrong-length hash with ECC or RSA. Withverify=1these already failed in the self-verify.Testing
test_wc_SignatureFeatureCoverage: DigestInfo round trip, bare hash, trailing data, nested and non-NULL AlgorithmIdentifier, missing NULL parameter, OID mismatch, wrong digest size, BLAKE2B, and wrong-length ECC and RSA hashes on generate.