Skip to content

settings.h, random.c: warn when MICRIUM seeds from Math_Rand - #11922

Open
yosuke-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
yosuke-wolfssl:fix/f-16887
Open

yosuke-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
yosuke-wolfssl:fix/f-16887

Conversation

@yosuke-wolfssl

Copy link
Copy Markdown
Contributor

Problem

When MICRIUM is defined and no RNG override is set, settings.h maps CUSTOM_RAND_GENERATE to uC/LIB Math_Rand(). wc_GenerateSeed() then fills the whole DRBG seed from it, without any warning.

Micrium has no entropy API, so Math_Rand() stays as the fallback, which keeps existing builds compiling. The change makes the fallback visible.

Fix (wolfcrypt/src/random.c)

  • settings.h no longer sets the Math_Rand default for MICRIUM.
  • random.c gains a MICRIUM && !CUSTOM_RAND_GENERATE_BLOCK arm of wc_GenerateSeed(), next to the Deos arm and following the same pattern. It seeds from Math_Rand() and emits a #warning (#pragma message on MSVC/TASKING) naming CUSTOM_RAND_GENERATE_SEED.
  • Sample user_settings.h and README.md document how to supply a hardware seed.

Seed source per configuration:

Configuration Seed source
MICRIUM only Math_Rand() + build warning
CUSTOM_RAND_GENERATE_SEED / _SEED_OS / CUSTOM_RAND_GENERATE user function, no warning
WOLFSSL_SILABS_SE_ACCEL, STM32_RNG hardware TRNG (unchanged)
Platform arms earlier in the chain (USE_WINDOWS_API simulator, PIC32, Freescale RNGA/RNGB) that platform's source instead of Math_Rand()

Closes f-16887.

Verification

  • Compiled random.c against the open-source Micrium headers (uC-OS3/CPU/LIB/Clk, POSIX port) for each override case: the warning fires only in the default case.
  • Linked against uC-LIB's lib_math.c: wc_GenerateSeed() output (19 bytes, odd tail) matches the LCG sequence from seed 1.
  • Host build and testwolfcrypt pass (MICRIUM not set).
  • No CI job builds MICRIUM.

- settings.h no longer defaults CUSTOM_RAND_GENERATE to Math_Rand
  for MICRIUM.
- random.c gains a MICRIUM wc_GenerateSeed arm that fills the seed
  from Math_Rand() and emits a #warning (#pragma message on MSVC and
  TASKING) naming CUSTOM_RAND_GENERATE_SEED.
- The Micrium sample user_settings.h and README show how to supply a
  hardware seed source.

Issue: F-16887
@yosuke-wolfssl yosuke-wolfssl self-assigned this Oct 29, 2026
@yosuke-wolfssl
yosuke-wolfssl requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot October 29, 2026 06:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

@yosuke-wolfssl
yosuke-wolfssl requested review from wolfSSL-Fenrir-bot and removed request for wolfSSL-Fenrir-bot October 29, 2026 06:40

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #11922

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): IDE/ECLIPSE/MICRIUM/README.md, IDE/ECLIPSE/MICRIUM/user_settings.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

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #11922

Fenrir already completed a review of this PR at commit 8189deaa8b2c (run 3546); its findings are the review threads on the PR. Push a new commit to request another review.

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.

4 participants