Fix potential mismatch in size between DECL_MP_INT_SIZE_DYN and NEW_MP_INT_SIZE, fix unused variable warning in random.c.#10503
Open
kareem-wolfssl wants to merge 3 commits into
Open
Conversation
…D_GENERATE_BLOCK. Fixes wolfSSL#10499.
…P_INT_SIZE. In some configurations DECL_MP_INT_SIZE_DYN will set the size to max while NEW_MP_INT_SIZE will memset bits.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses potential size mismatches between stack-allocated SP-math mp_int buffers and the amount of memory cleared/initialized, adds explicit key-size bounds checks in RSA/ECC paths to fail fast on oversized moduli, and fixes a build-configuration-specific unused-variable warning in RNG initialization.
Changes:
- Update
NEW_MP_INT_SIZE()(SP math, static stack mode) to zero based on the declared digit buffer size to avoidmemsetexceeding the allocated buffer whenDECL_MP_INT_SIZE_DYN(..., bits, max)usesmax. - Add
mp_bitsused(...) > {RSA_MAX_SIZE, MAX_ECC_BITS_USE}guards in multiple RSA/ECC code paths and propagatewc_RsaEncryptSize()errors inwc_RsaDirect(). - Fix
random.cso HASHDRBG seed variables are not declared whenCUSTOM_RAND_GENERATE_BLOCKis enabled, and add an API test covering oversized RSA modulus handling.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| wolfssl/wolfcrypt/sp_int.h | Fix SP-math static-stack clearing to respect the actual declared digit buffer size. |
| wolfcrypt/src/rsa.c | Add oversized-modulus guards in several RSA paths and propagate wc_RsaEncryptSize() failures. |
| wolfcrypt/src/random.c | Adjust preprocessor guards to eliminate unused-variable warnings under CUSTOM_RAND_GENERATE_BLOCK. |
| wolfcrypt/src/ecc.c | Add oversized-modulus/key-size guards across several ECC arithmetic/sign/verify paths. |
| tests/api/test_rsa.h | Register new RSA oversized-modulus test. |
| tests/api/test_rsa.c | Add test ensuring oversized modulus returns WC_KEY_SIZE_E (and doesn’t overflow stack buffers). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes zd#21858, #10499
Testing
Built in tests
Checklist