Repository navigation
Fail EVP_DigestSignFinal() for ECDSA when buffer is too small - #11924
julek-wolfssl wants to merge 1 commit into
Conversation
The EC branch returned success without writing the signature when the DER encoding did not fit in *siglen, and set *siglen past the end of the caller's buffer. Fail instead and leave sig and *siglen unchanged. Get the sig == NULL size from wc_ecc_sig_size(), as EVP_PKEY_size() and EVP_PKEY_sign() do. size * 2 + 8 was too small for brainpoolP512r1 (136 vs 137) and read ecc_sets[-1] for keys with explicit curve parameters. The size is now the DER maximum: P-521 139 (was 140) and prime239v1-3 66 (was 68). Fixes wolfSSL#11904
There was a problem hiding this comment.
🟡 Changes recommended
The test guard enables Brainpool key generation in FIPS 6+ development configurations, where it is prohibited, causing the key-generation assertion to fail before signature sizing is exercised.
1 open issue
What changed in this PR
Fixes #11904 in wolfSSL’s OpenSSL compatibility layer by correcting ECDSA signature buffer handling and size queries.
Changes:
- Rejects undersized signature buffers without changing the buffer or its reported length.
- Uses
wc_ecc_sig_size()for size queries, fixing Brainpool sizing and explicit-curve handling. - Adds regression checks for undersized buffers and the Brainpool P512 maximum signature size.
| File | Description |
|---|---|
wolfcrypt/src/evp.c |
Corrects ECDSA buffer validation and signature sizing. |
tests/api/test_evp_pkey.h |
Declares and registers the new size-query test. |
tests/api/test_evp_pkey.c |
Adds buffer-failure checks and Brainpool sizing coverage. |
Review effort: Balanced
| #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && !defined(NO_SHA256) && \ | ||
| defined(HAVE_ECC_BRAINPOOL) && \ | ||
| (defined(HAVE_ECC512) || defined(HAVE_ALL_CURVES)) && \ | ||
| ECC_MIN_KEY_SZ <= 512 |
|
|
Thanks Juliusz! I tested 0a71909 with both reproducers from #11904 ( |

The EC branch of
EVP_DigestSignFinal()returned success without writing the signature when the DER encoding did not fit in*siglen, and it set*siglenpast the end of the caller's buffer. It now fails in that case and leavessigand*siglenunchanged.The
sig == NULLsize query now useswc_ecc_sig_size(), matchingEVP_PKEY_size()andEVP_PKEY_sign(). The previoussize * 2 + 8calculation had two problems:ecc_sets[-1]for keys with explicit curve parameters.The reported size is now the DER maximum. For P-521 it is 139 (was 140), and for prime239v1-3 it is 66 (was 68).
Fixes #11904