Skip to content

Random: stricter weak entropy source checks. Remove from default options on all builds. - #12065

Open
danielinux wants to merge 7 commits into
wolfSSL:masterfrom
danielinux:fix-weak-entropy
Open

danielinux wants to merge 7 commits into
wolfSSL:masterfrom
danielinux:fix-weak-entropy

Conversation

@danielinux

@danielinux danielinux commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Description

  • Enable HW crypto TRNG where available, as default option.
  • Use weak entropy sources only when WOLFSSL_ACCEPT_WEAK_ENTROPY option is enabled.
  • remove weak entropy as default in all ports
  • refuse to build with insufficient entropy on all platforms, until the user enables it by defining WOLFSSL_ACCEPT_WEAK_ENTROPY or passing --enable-weak-entropy via configure

Addresses F-5990, F7303, F-7425, part of zd22758

Testing

Might require furter updates to examples / testing

danielinux and others added 3 commits November 9, 2026 08:51
Zero-entropy (USE_TEST_GENSEED) and clock-seeded wc_GenerateSeed platform
paths now #error at build time unless WOLFSSL_ACCEPT_WEAK_ENTROPY is
defined. Adds --enable-weak-entropy to configure; in-tree sample configs
that select a weak seed opt in explicitly.
Related: F-7303, F-7425, F-8310.
Enable hardware entropy where supported and require an explicit seed source otherwise. Remove weak entropy opt-ins from the 12 affected configurations and STM32 templates, and reject timer-seeded PIC32MZ EC RNG by default.
Copilot AI balanced review requested due to automatic review settings November 9, 2026 09:46
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

gcc-arm-cortex-m0plus

  • FLASH: .text +24 B (+0.0%, 70,827 B / 262,144 B, total: 27% used)

gcc-arm-cortex-m3

  • FLASH: .text +20 B (+0.0%, 131,781 B / 262,144 B, total: 50% used)

gcc-arm-cortex-m4-openssl-compat

  • FLASH: .text +320 B (+0.0%, 801,508 B / 1,048,576 B, total: 76% used)

gcc-arm-cortex-m7

  • FLASH: .text +64 B (+0.0%, 209,100 B / 262,144 B, total: 80% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

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.

🟡 Changes recommended

RNG configuration regressions reject valid custom-block and disabled-RNG builds, select incompatible STM32 HAL APIs, and introduce unintended hardware crypto dependencies.

4 open issues
What changed in this PR

This PR hardens wolfCrypt entropy selection by requiring explicit acceptance of weak seed sources and updating embedded integrations to use hardware or application-provided entropy.

Changes:

  • Adds compile-time weak-entropy guards and a --enable-weak-entropy configure option.
  • Removes automatic test-seed selections from integration settings and preserves hardware RNG use where available.
  • Fixes Cypress TRNG initialization failure handling and adds focused regression tests.
File Description
wolfcrypt/​src/​random.c Adds entropy guards and reports Cypress TRNG initialization failures.
tests/​weak_entropy_defaults.py Checks integration defaults and weak-source opt-ins.
tests/​cypress_trng_failure.py Tests Cypress TRNG failure and success paths.
tests/​arduino_entropy_guard.py Tests Arduino entropy guards and custom-seed precedence.
RTOS/​nuttx/​wolfssl/​user_settings.h Requires STM32 hardware RNG or explicit seed configuration.
RTOS/​nuttx/​wolfssl/​README.md Documents seed requirements and version constraints.
mcapi/​user_settings.h Adds guidance for targets without a hardware TRNG.
IDE/​VS-AZURE-SPHERE/​user_settings.h Adds custom-seed guidance.
IDE/​STM32Cube/​README.md Documents hardware RNG retention and external seed requirements.
IDE/​STM32Cube/​MX2/​README.md Clarifies RNG independence from hardware acceleration.
IDE/​STM32Cube/​MX2/​mx_wolfSSL_parameters.json Updates the hardware-crypto option description.
IDE/​STM32Cube/​MX2/​mx_wolfSSL_conf_template.h.hbs Removes test defaults and retains hardware RNG in software-crypto mode.
IDE/​STM32Cube/​default_conf.ftl Replaces test defaults with explicit seed requirements.
IDE/​STARCORE/​user_settings.h Gates the example seed and preserves application overrides.
IDE/​RISCV/​SIFIVE-HIFIVE1/​user_settings.h Requires opt-in for the predictable example seed.
IDE/​Renesas/​e2studio/​SK-S7G2/​common/​user_settings.h Requires an explicit source when SCE TRNG is disabled.
IDE/​Renesas/​e2studio/​RX72N/​EnvisionKit/​wolfssl_demo/​user_settings.h Removes automatic test seeding without TSIP.
IDE/​Renesas/​e2studio/​RX65N/​RSK/​wolfssl_demo/​user_settings.h Requires explicit seed configuration without TSIP.
IDE/​Renesas/​e2studio/​RX65N/​GR-ROSE/​common/​user_settings.h Requires explicit seed configuration without TSIP.
IDE/​Renesas/​e2studio/​RA6M3/​common/​user_settings.h Requires an integrated SCE or custom entropy source.
IDE/​Renesas/​e2studio/​Projects/​common/​user_settings.h Removes automatic test seeding without TSIP.
IDE/​Renesas/​e2studio/​DK-S7G2/​user_settings.h Requires an explicit source when SCE TRNG is disabled.
IDE/​Renesas/​cs+/​Projects/​common/​user_settings.h Replaces the test seed with custom-source guidance.
IDE/​qemu-falcon-neon/​user_settings.h Makes deterministic RNG use explicitly opt-in.
IDE/​MSVS-2019-AZSPHERE/​user_settings.h Adds custom-seed guidance.
IDE/​MPLABX16/​user_settings.h Removes the PIC24 test-seed default.
IDE/​MDK5-ARM/​Conf/​user_settings.h Defaults to hardware RNG and gates test seeds.
IDE/​m33mu-falcon-verify/​user_settings.h Makes deterministic RNG use explicitly opt-in.
IDE/​INTIME-RTOS/​user_settings.h Documents entropy requirements for older INtime releases.
IDE/​IAR-MSP430/​user_settings.h Gates timer-based seeding and preserves custom sources.
IDE/​IAR-EWARM/​Projects/​user_settings.h Removes the test-seed default and documents explicit opt-in.
IDE/​IAR-EWARM/​embOS/​SAMV71_XULT/​embOS_SAMV71_XULT_user_settings/​user_settings.h Adds custom-seed guidance.
IDE/​IAR-EWARM/​embOS/​custom_port/​custom_port_user_settings/​user_settings.h Adds custom-seed guidance.
IDE/​GCC-ARM/​Header/​user_settings.h Gates predictable example RNG hooks.
IDE/​ECLIPSE/​RTTHREAD/​user_settings.h Replaces test seeding with hardware-source guidance.
IDE/​C2000/​user_settings.h Selects the oscillator-noise entropy source.
IDE/​C2000/​compile.sh Includes noise-source code in the regular compile sweep.
IDE/​AURIX/​user_settings.h Gates the predictable seed and preserves custom sources.
examples/​configs/​user_settings_stm32.h Requires explicit entropy on devices without an RNG.
examples/​configs/​user_settings_arduino.h Documents hardware entropy and weak-source opt-in.
configure.ac Adds and reports the weak-entropy acceptance option.

Review effort: Balanced

Comment thread IDE/MDK5-ARM/Conf/user_settings.h Resolved
Comment thread wolfcrypt/src/random.c Resolved

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.

🟡 Changes recommended

Active moderate and critical findings show that the weak-entropy opt-in contract is blocked in generated configurations and bypassed by ungated VxWorks simulator and NetBurner fallback paths, while the added regression tests are not run in CI.

6 open issues
4 resolved since last review

Review effort: Lite

Comment thread wolfcrypt/src/random.c Outdated
Comment on lines +9408 to +9409
#elif defined(CUSTOM_RAND_GENERATE_BLOCK)
/* The application supplies complete random blocks. No DRBG seed is used. */
Comment thread wolfcrypt/src/random.c
Comment on lines +10296 to +10298
#ifndef WOLFSSL_ACCEPT_WEAK_ENTROPY
# error "WOLFSSL_VXWORKS 6.x tick-seeded rand_r is weak: provide a real entropy source; test only: define WOLFSSL_ACCEPT_WEAK_ENTROPY"
#endif
Comment on lines +628 to +629
!defined(CUSTOM_RAND_GENERATE_BLOCK) && \
!defined(CUSTOM_RAND_GENERATE) && !defined(WOLFSSL_GENSEED_FORTEST)
Comment thread IDE/STM32Cube/default_conf.ftl Outdated
Comment on lines +294 to +295
!defined(CUSTOM_RAND_GENERATE_BLOCK) && \
!defined(CUSTOM_RAND_GENERATE) && !defined(WOLFSSL_GENSEED_FORTEST)
Comment thread examples/configs/user_settings_stm32.h Resolved
Comment thread tests/weak_entropy_defaults.py Resolved

@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 #12065

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs
Not reviewed (no scan target covers them): .github/configs/os-check-linux.json, .github/membrowse-targets.json, .github/workflows/arduino.yml, .github/workflows/pic32mz-sim.yml, .github/workflows/sbom.yml, .github/workflows/zephyr.yml, IDE/AURIX/user_settings.h, IDE/C2000/compile.sh, IDE/C2000/user_settings.h, IDE/ECLIPSE/RTTHREAD/user_settings.h, IDE/GCC-ARM/Header/user_settings.h, IDE/IAR-EWARM/Projects/user_settings.h, IDE/IAR-EWARM/embOS/SAMV71_XULT/embOS_SAMV71_XULT_user_settings/user_settings.h, IDE/IAR-EWARM/embOS/custom_port/custom_port_user_settings/user_settings.h, IDE/IAR-MSP430/user_settings.h, IDE/INTIME-RTOS/user_settings.h, IDE/MDK5-ARM/Conf/user_settings.h, IDE/MPLABX16/user_settings.h, IDE/MSVS-2019-AZSPHERE/user_settings.h, IDE/RISCV/SIFIVE-HIFIVE1/user_settings.h and 30 more
Coverage: 1 of 1 in-scope changed file(s) opened by the reviewer

Findings: 2
2 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

Comment thread wolfcrypt/src/random.c Resolved
Comment thread wolfcrypt/src/random.c Resolved
danielinux and others added 2 commits November 9, 2026 13:23
my_rng_generate_seed() funneled each pool byte through
srand()/rand(), so every seed byte was a fixed function of exactly one
pool byte: the libc stage added no entropy, its low 8 bits are not
guaranteed one-to-one, and it used process-global non-reentrant state.
Fill the output directly from the pool and add a source-level
regression check alongside the PR 12065 entropy review tests.
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.

3 participants