wolfSSL — Constant DRBG Seed in the Test Seed Fallback of wc_GenerateSeed
For a list of embedded platform macros, and for Freescale builds with no RNG driver, wc_GenerateSeed compiles to a stub that fills the DRBG seed with the bytes 0, 1, 2 and so on. The build prints a warning and succeeds. Every random value the library then produces is the same on every device and every boot.
- Advisory
- BYTERAY-2026-0298
- CWE
- CWE-337
- CVSS
- 9.8 (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)
- Vendor
- wolfSSL
- Product
- wolfSSL
- Reported
- 2026-09-27
- Disclosure
- 2026-12-03
- Affected
- wolfSSL 5.9.2 through 5.9.4, builds where wc_GenerateSeed is the USE_TEST_GENSEED stub (WOLFSSL_LEANPSK, NO_STM32_RNG, MBED and the other listed platform macros, or a Freescale build with no RNG driver) and no custom seed is supplied
- Fixed in
- Master commit 09c1648ad4502e7974cef18d47d14367b85d579c (PR 12065, merged 2026-11-10). Not in a wolfSSL stable release as of 2026-12-03.
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
wolfCrypt's WC_RNG is a Hash_DRBG. Its seed comes from wc_GenerateSeed(), which wolfcrypt/src/random.c implements once per platform in one long #elif chain. For a list of platform macros, and for Freescale MQX and KSDK builds where no RNG driver was selected, the chain has no entropy source to offer. It defines USE_TEST_GENSEED instead, and the function that gets compiled writes output[i] = i.
The seed is then the fixed byte string 00 01 02 03 .... It passes the seed health test, the DRBG instantiates, and wc_InitRng() returns success. Everything that DRBG produces, including TLS hello randoms and ephemeral key material, is a fixed sequence that can be computed from the public source.
The only signal is a compile-time warning. A default ./configure build on a desktop or server operating system does not use the stub; it reads the operating system's random source. The affected builds are embedded ports that define one of the listed macros and have not supplied their own seed function.
Affected Products and Versions
- Component: wolfCrypt RNG seeding, the
USE_TEST_GENSEEDvariant ofwc_GenerateSeed()inwolfcrypt/src/random.c. - Selected by
WOLFSSL_SAFERTOS,WOLFSSL_LEANPSK,WOLFSSL_IAR_ARM,WOLFSSL_MDK_ARM,WOLFSSL_uITRON4,WOLFSSL_uTKERNEL2,WOLFSSL_LPC43xx,NO_STM32_RNG,MBED,WOLFSSL_EMBOS,WOLFSSL_CHIBIOS,WOLFSSL_AZSPHEREorWOLFSSL_GENSEED_FORTEST, when no earlier branch of the chain matched. - Also selected on
FREESCALE_MQX,FREESCALE_KSDK_MQX,FREESCALE_KSDK_BMandFREESCALE_FREE_RTOSbuilds withoutWOLFSSL_CAAMwhen none of the RNGA, RNGB or TRNG drivers was chosen, for example withFREESCALE_NO_RNG. ./configure --enable-leanpskadds-DWOLFSSL_LEANPSKand no seed source (configure.ac:1249), so it selects the stub.- In-tree configurations that reach the stub include
IDE/MQX/user_settings.h:59-60,IDE/VS-AZURE-SPHERE/user_settings.h:4, and the STM32 template for parts without a hardware RNG (examples/configs/user_settings_stm32.h:222-235). - Not affected: builds that define
CUSTOM_RAND_GENERATE_SEED,CUSTOM_RAND_GENERATE_SEED_OS,CUSTOM_RAND_GENERATEorCUSTOM_RAND_GENERATE_BLOCK, and builds where a hardware branch earlier in the chain applies, such asSTM32_RNG.WOLFSSL_CONTIKIis in the list, butwolfssl/wolfcrypt/settings.h:1285-1288gives Contiki aCUSTOM_RAND_GENERATEdefault that is handled first. - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- The
v5.9.2-stableandv5.9.4-stabletags have the same macro list, the same Freescale fallback and the same stub. Earlier releases were not checked. - Fixed on master by PR 12065, merged 2026-11-10. No stable release contains the fix.
- A default
./configurebuild does not include the stub.
Technical Details
The chain begins at wolfcrypt/src/random.c:7743 with the application overrides and continues through the hardware and operating system ports. Near its end is a branch for platforms that have nothing:
#elif defined(WOLFSSL_SAFERTOS) || defined(WOLFSSL_LEANPSK) || \
defined(WOLFSSL_IAR_ARM) || defined(WOLFSSL_MDK_ARM) || \
defined(WOLFSSL_uITRON4) || defined(WOLFSSL_uTKERNEL2) || \
defined(WOLFSSL_LPC43xx) || defined(NO_STM32_RNG) || \
defined(MBED) || defined(WOLFSSL_EMBOS) || \
defined(WOLFSSL_GENSEED_FORTEST) || defined(WOLFSSL_CHIBIOS) || \
defined(WOLFSSL_CONTIKI) || defined(WOLFSSL_AZSPHERE)
The comment that follows says these platforms have no default seed and that the integrator needs to implement one. The branch body is a single line, #define USE_TEST_GENSEED, at wolfcrypt/src/random.c:9623. The Freescale block does the same at wolfcrypt/src/random.c:8162-8169 when no RNGA, RNGB or TRNG macro matched; wolfssl/wolfcrypt/settings.h:2370-2371 leaves all of them undefined for FREESCALE_NO_RNG.
After the chain closes, USE_TEST_GENSEED selects this function:
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
{
word32 i;
/* WC_OCTET, not (byte): the cast does not truncate where
* CHAR_BIT != 8, so sz > 256 would emit values above 0xFF. */
for (i = 0; i < sz; i++ )
output[i] = WC_OCTET(i);
(void)os;
return 0;
}
It is preceded by #warning "write a real random seed!!!!, just for testing now", or a #pragma message on MSVC and TASKING (wolfcrypt/src/random.c:9917-9921). Nothing fails.
The path from the stub to the wire:
src/internal.c:8393-8404: aWOLFSSLobject that was not given a context RNG allocates its ownWC_RNGand callswc_InitRng_ex().wolfcrypt/src/random.c:3135:_InitRng()callswc_GenerateSeed().wc_InitRng()andwc_InitRng_ex()pass no nonce and no personalization string (wolfcrypt/src/random.c:3400-3411).wolfcrypt/src/random.c:9927-9928: the stub writes the counting sequence and returns 0.wolfcrypt/src/random.c:3159:wc_RNG_TestSeed()checks for 31 equal consecutive bytes and for one byte value occurring 325 times in a 512-byte window (wolfcrypt/src/random.c:2505-2523). A counting sequence passes both.wolfcrypt/src/random.c:3178-3184:Hash_DRBG_Instantiate()builds the DRBG state from that seed alone.src/internal.c:34895andsrc/internal.c:39370draw the ClientHello and ServerHello randoms from that DRBG, andsrc/internal.c:6552draws the ephemeral ECC key.
Reseeding calls the same function (wolfcrypt/src/random.c:4685), so it adds nothing. The Hash_DRBG is enabled unless the build opts out (wolfssl/wolfcrypt/random.h:198-200).
Reachability and Preconditions
- The build defines one of the macros above, or is a Freescale build with no RNG driver, and defines none of the custom seed or generator macros.
WC_RNG_SEED_CBon its own does not change this. In a non-FIPS build the default callback iswc_GenerateSeed(wolfcrypt/src/random.c:390). Only an application that installs a real source withwc_SetSeed_Cb()avoids the stub.- The build produced the warning and was shipped anyway. A warning stops a build only where warnings are treated as errors; wolfSSL's autotools build appends
-Werroronly in a version-control checkout (m4/ax_harden_compiler_flags.m4:106-108), and IDE projects follow the integrator's own settings. - No runtime configuration is involved. Every
wc_InitRng()call in the process gets the same seed. - The attacker sends nothing special. Knowing that the device runs such a build is enough. No authentication or user interaction is needed.
Impact
Confirmed from the source: on an affected build the DRBG seed is a constant, so every WC_RNG instance starts in the same state, on every device and after every boot. Two TLS session objects that follow the same code path draw the same hello random and the same ephemeral private key.
ByteRay compiled the wolfCrypt sources with the flag set that ./configure --enable-leanpsk emits. wc_GenerateSeed() returned success with the bytes 00 01 02 ... 0f, wc_InitRng() accepted them, and two separate process runs produced identical output. The same program built with the default configuration read the operating system source and differed between runs. A FREESCALE_MQX build with FREESCALE_NO_RNG was checked at the preprocessor level and selects the same stub.
Not demonstrated: recovery of TLS session keys from a captured handshake with such a device. It follows from the source, because the ephemeral key exchange secrets come from the same DRBG, but ByteRay did not run a handshake against an affected build. Long-term keys generated on the device with this RNG are predictable in the same way.
Remediation and Mitigation
Fixed on master by commit 09c1648ad4502e7974cef18d47d14367b85d579c in PR 12065. The commit puts an #error in front of the stub unless the build defines WOLFSSL_ACCEPT_WEAK_ENTROPY, adds --enable-weak-entropy to configure, and makes configure warn when --enable-leanpsk is used without it. A later commit in the same pull request, 6cf0385bd5dd682979196caf90a8d46146cb59a8, compiles the stub only when no custom seed or generator macro is defined. The macro list, the Freescale fallback and the stub are still in the tree. What changed is that the build fails until the integrator supplies a seed source or accepts the test seed by name.
The fix is on master only. No wolfSSL release contains it as of 2026-12-03.
On 5.9.4 and earlier, define CUSTOM_RAND_GENERATE_SEED to a function backed by a hardware TRNG or another real entropy source, or define CUSTOM_RAND_GENERATE_BLOCK to replace the DRBG. Search build logs for write a real random seed. If a product shipped with the stub, treat every key generated on the device as known and regenerate it after the seed source is corrected.
Timeline
- 2026-09-27 — Reported to wolfSSL.
- 2026-11-09 — wolfSSL opened PR 12065, "Random: stricter weak entropy source checks".
- 2026-11-10 — PR 12065 merged to master.
- 2026-12-03 — Public disclosure.
Credits
Discovered and reported by Mehrun P. Hunter and Shahriyar Jalayeri of ByteRay Ltd.