wolfSSL — Predictable DRBG Seed from the Core Timer in PIC32 Builds Without the Hardware RNG
On Microchip PIC32 builds without the PIC32MZ hardware RNG, wolfSSL's seed function seeds the C library generator from the CPU core timer and returns rand() output as the DRBG seed. The core timer counts cycles since reset and is not secret, so the seed, and everything drawn from the DRBG, can be recomputed by search.
- Advisory
- BYTERAY-2026-0325
- CWE
- CWE-323
- CVSS
- 7.4 (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:N)
- Vendor
- wolfSSL
- Product
- wolfSSL
- Reported
- 2026-09-27
- Disclosure
- 2026-12-03
- Affected
- wolfSSL 5.9.2 through 5.9.4, builds with MICROCHIP_PIC32 or MICROCHIP_MPLAB_HARMONY without WOLFSSL_PIC32MZ_RNG that do not supply their own seed source
- 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
wolfSSL's random number generator is a Hash_DRBG. It takes its entropy from wc_GenerateSeed(), which has one implementation per platform. The PIC32 implementation has two forms. With WOLFSSL_PIC32MZ_RNG it reads the hardware generator on PIC32MZ parts. Without that macro it has no entropy source: it passes the CPU core timer to srand() and copies rand() output into the seed buffer, reading the timer again after every eight bytes.
The core timer is a free-running count of CPU cycles since reset. Nothing else goes into the seed, so the DRBG state after initialisation is a function of a few timer readings taken a few instructions apart. Someone who sees a value the DRBG produced, such as a TLS hello random or an AES-GCM IV, can search for the readings that reproduce it and then compute every other value the generator gave out.
Only PIC32 builds without the hardware RNG take this branch. A default ./configure build does not. The branch emits no build warning.
Affected Products and Versions
- Component:
wolfcrypt/src/random.c,wc_GenerateSeed(), theMICROCHIP_PIC32/MICROCHIP_MPLAB_HARMONYbranch whenWOLFSSL_PIC32MZ_RNGis not defined. - Required build:
MICROCHIP_PIC32orMICROCHIP_MPLAB_HARMONY, noWOLFSSL_PIC32MZ_RNG, and none of the seed sources tested earlier in the same chain: the custom seed macros (wolfcrypt/src/random.c:7743-7769) and the ATECC device (wolfcrypt/src/random.c:7939-7940). MICROCHIP_PIC32alone does not defineWOLFSSL_PIC32MZ_RNG(wolfssl/wolfcrypt/settings.h:1308-1319). OnlyWOLFSSL_MICROCHIP_PIC32MZdoes, andNO_PIC32MZ_RNGturns it off again (wolfssl/wolfcrypt/settings.h:1321-1334). A PIC32MX build, a Harmony build without the MZ macro, and an MZ build withNO_PIC32MZ_RNGall take this branch.- Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- The
v5.9.2-stableandv5.9.4-stabletags contain the same branch, unguarded. - Fixed on master. No wolfSSL release contains the fix.
- A default
./configurebuild does not include this code. Earlier releases were not checked.
Technical Details
The branch first picks the counter to read (wolfcrypt/src/random.c:7960-7973): SYS_TIME_CounterGet on Harmony 3, _CP0_GET_COUNT on older Harmony, ReadCoreTimer otherwise. The seed function is at wolfcrypt/src/random.c:8025-8036:
/* uses the core timer, in nanoseconds to seed srand */
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
{
int i;
srand(PIC32_SEED_COUNT() * 25);
for (i = 0; i < sz; i++ ) {
output[i] = rand() % 256;
if ( (i % 8) == 7)
srand(PIC32_SEED_COUNT() * 25);
}
return 0;
}
Each block of eight bytes is the start of the rand() sequence for one counter reading. The first reading is one 32-bit value. Each later reading is taken a few instructions after the previous one. Multiplying by 25 adds nothing. The function always returns 0. How the seed is used:
wc_InitRng()andwc_InitRng_ex()call the common initialiser with no nonce and no personalization string (wolfcrypt/src/random.c:3400-3411).- The initialiser requests the seed from
wc_GenerateSeed()(wolfcrypt/src/random.c:3135). WithWC_RNG_SEED_CBthe default callback is the same function (wolfcrypt/src/random.c:390). - The seed health test (
wolfcrypt/src/random.c:2525-2630, called atwolfcrypt/src/random.c:3159) checks only for repeated and over-frequent byte values.rand()output passes it. - The DRBG is instantiated from the seed alone (
wolfcrypt/src/random.c:3178-3184). - Reseeding calls the same function (
wolfcrypt/src/random.c:4685). - DRBG output reaches the wire.
wc_AesGcmSetIV()draws per-message GCM IVs from it (wolfcrypt/src/aes.c:15126), and a TLS session sends it as the hello random.
Reachability and Preconditions
- The library is built for PIC32 without
WOLFSSL_PIC32MZ_RNGand uses the stock seed function. A build that definesCUSTOM_RAND_GENERATE_SEED,CUSTOM_RAND_GENERATE_SEED_OSorCUSTOM_RAND_GENERATE, or that seeds from an ATECC device, does not reach this code. - The in-tree MPLAB X projects define
WOLFSSL_MICROCHIP_PIC32MZand use the hardware branch. - The attacker observes at least one value derived from the DRBG. A passive observer of a TLS handshake gets the hello random. No authentication and no interaction with the device are needed.
- The attacker can bound the core timer value at seeding time, from the time since reset and the CPU clock rate.
- The attacker needs the
rand()implementation of the C library the firmware was linked with.
Impact
Confirmed from source: on these builds the DRBG seed is determined by the core timer readings taken during one call and by nothing else. Every value drawn from the generator follows from the seed. That covers ephemeral key shares, signature nonces, AES-GCM IVs, session ticket IVs and long-term keys generated on the device. Repeated or predictable GCM IVs also break GCM's integrity guarantee.
ByteRay compiled the unmodified wolfCrypt sources with MICROCHIP_PIC32 on a Linux host, with the core timer replaced by a model that advances a fixed amount per read. Two separate processes produced identical 36-byte seeds and, from wc_InitRng() onward, identical AES-GCM key, IV, ciphertext and tag. A program with no wolfSSL code predicted the seed from the timer value, and a search over the time since power-on in 1 ms steps reproduced the IV, ciphertext and tag. A control build seeded from the host's /dev/urandom differed on every run.
Not verified: behaviour on a PIC32 part. On hardware the gap between the readings of one call depends on the cost of the toolchain's rand() and on interrupts. The size of the search on a real device was not measured.
Remediation and Mitigation
Fixed on master by commit 09c1648ad4502e7974cef18d47d14367b85d579c, part of PR 12065, merged 2026-11-10. The commit puts a build-time #error in front of this branch unless WOLFSSL_ACCEPT_WEAK_ENTROPY is defined, and adds the configure option --enable-weak-entropy, which defines that macro. The srand()/rand() code is unchanged behind the guard. A PIC32 build without the hardware RNG therefore stops on master until the integrator provides a seed source or explicitly accepts the weak one. The fix is on master only. No wolfSSL release contains it as of 2026-12-03.
For affected releases: on PIC32MZ parts, define WOLFSSL_MICROCHIP_PIC32MZ and leave NO_PIC32MZ_RNG undefined so the hardware generator is used. On parts without one, define CUSTOM_RAND_GENERATE_SEED to a function that reads a real entropy source. Treat keys generated by a build that used the stock function as exposed and replace them. After updating, do not define WOLFSSL_ACCEPT_WEAK_ENTROPY in a build that handles real secrets.
Timeline
- 2026-09-27 — Reported to wolfSSL.
- 2026-11-09 — wolfSSL opened PR 12065.
- 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.
References
- PIC32 branch of wc_GenerateSeed without the hardware RNG, at the tested commit
- wolfSSL PR 12065
- Fix commit 09c1648ad450
- BYTERAY-2026-0326, the EBSnet RTP branch of the same function
- BYTERAY-2026-0327, the INtime RTOS branch of the same function
- BYTERAY-2026-0328, the Apache Mynewt branch of the same function
- BYTERAY-2026-0329, the Deos branch of the same function
- BYTERAY-2026-0330, the Nucleus RTOS branch of the same function
- BYTERAY-2026-0298, the constant test seed in the same function