Skip to content

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
wolfSSL:masterfrom
kareem-wolfssl:zd21858
Open

Fix potential mismatch in size between DECL_MP_INT_SIZE_DYN and NEW_MP_INT_SIZE, fix unused variable warning in random.c.#10503
kareem-wolfssl wants to merge 3 commits into
wolfSSL:masterfrom
kareem-wolfssl:zd21858

Conversation

@kareem-wolfssl
Copy link
Copy Markdown
Contributor

Description

Fixes zd#21858, #10499

Testing

Built in tests

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

…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.
@kareem-wolfssl kareem-wolfssl self-assigned this May 19, 2026
Copilot AI review requested due to automatic review settings May 19, 2026 23:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 avoid memset exceeding the allocated buffer when DECL_MP_INT_SIZE_DYN(..., bits, max) uses max.
  • Add mp_bitsused(...) > {RSA_MAX_SIZE, MAX_ECC_BITS_USE} guards in multiple RSA/ECC code paths and propagate wc_RsaEncryptSize() errors in wc_RsaDirect().
  • Fix random.c so HASHDRBG seed variables are not declared when CUSTOM_RAND_GENERATE_BLOCK is 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.

Comment thread wolfssl/wolfcrypt/sp_int.h Outdated
Comment thread wolfssl/wolfcrypt/sp_int.h Outdated
@kareem-wolfssl kareem-wolfssl marked this pull request as draft May 19, 2026 23:38
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 19, 2026

MemBrowse Memory Report

gcc-arm-cortex-m4

  • FLASH: .text +320 B (+0.2%, 197,889 B / 262,144 B, total: 75% used)

gcc-arm-cortex-m4-baremetal

  • FLASH: .text +64 B (+0.1%, 64,955 B / 262,144 B, total: 25% used)

gcc-arm-cortex-m4-min-ecc

  • FLASH: .text +64 B (+0.1%, 60,477 B / 262,144 B, total: 23% used)

gcc-arm-cortex-m4-tls12

  • FLASH: .text +64 B (+0.1%, 121,117 B / 262,144 B, total: 46% used)

@kareem-wolfssl kareem-wolfssl marked this pull request as ready for review May 20, 2026 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants