wolfSSL — Predictable DRBG Seed from the OS Tick Counter in Apache Mynewt Builds
On Apache Mynewt builds, wolfSSL's seed function seeds the C library generator from the OS tick counter and returns rand() output as the DRBG seed. The tick counter is the time since boot and is not secret, so the seed, and everything drawn from the DRBG, can be recomputed by searching candidate uptimes.
- Advisory
- BYTERAY-2026-0328
- 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 (tested at master commit d95483f), builds with WOLFSSL_APACHE_MYNEWT that do not supply their own seed source
- 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 implementation selected by WOLFSSL_APACHE_MYNEWT has no entropy source. It passes os_time_get(), the Mynewt OS tick counter, to srand() and copies rand() output into the seed buffer. It reads the tick counter again after every eight bytes.
The tick counter is the time since boot. It carries no secret, and it advances slowly compared with the loop, so successive reads often return the same value and the seed contains repeated eight-byte blocks. The DRBG state after initialisation is a function of a guessable uptime. Someone who sees a value the DRBG produced, such as a TLS hello random or an AES-GCM IV, can search for the tick value that reproduces it and then compute every other value the generator gave out.
Only builds for Apache Mynewt take this branch. A default ./configure build does not; it seeds from /dev/urandom.
Affected Products and Versions
- Component:
wolfcrypt/src/random.c,wc_GenerateSeed(), theWOLFSSL_APACHE_MYNEWTbranch. - Required build:
WOLFSSL_APACHE_MYNEWTdefined (wolfcrypt/src/random.c:8893). The in-tree Mynewt package file sets it (IDE/mynewt/crypto.wolfssl.pkg.yml:29). - No seed override in place.
CUSTOM_RAND_GENERATE_SEEDandCUSTOM_RAND_GENERATE_SEED_OScome first in the same chain (wolfcrypt/src/random.c:7743,wolfcrypt/src/random.c:7756). - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- A default
./configurebuild does not include this code. - Other releases were not checked.
Technical Details
The function is at wolfcrypt/src/random.c:8897-8910:
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
{
int i;
srand(os_time_get());
for (i = 0; i < sz; i++ ) {
output[i] = rand() % 256;
if ((i % 8) == 7) {
srand(os_time_get());
}
}
return 0;
}
The generator is seeded at wolfcrypt/src/random.c:8900 and again at wolfcrypt/src/random.c:8905 after every eighth byte. Each block of eight bytes is therefore the start of the rand() sequence for one tick reading. If the tick has not advanced between two blocks, the blocks are identical. The function always returns 0. How the seed is used:
wc_InitRng()(wolfcrypt/src/random.c:3400) calls_InitRng()(wolfcrypt/src/random.c:2745)._InitRng()requests the seed fromwc_GenerateSeed()(wolfcrypt/src/random.c:3135). WithWC_RNG_SEED_CBthe default callback is the same function (wolfcrypt/src/random.c:390). Reseeding also calls it (wolfcrypt/src/random.c:4685).- The branch above fills the buffer from the tick readings taken during the call.
Hash_DRBG_Instantiate()takes that buffer as its entropy input (wolfcrypt/src/random.c:3178).wc_RNG_GenerateBlock()hands out DRBG output (wolfcrypt/src/random.c:5605).- That output reaches the wire: per-message AES-GCM IVs from
wc_AesGcmSetIV()(wolfcrypt/src/aes.c:15126), session ticket IVs fromDefTicketEncCb()(src/internal.c:44924), and TLS handshake randoms. Keys generated on the device come from the same stream.
Reachability and Preconditions
- The library is built with
WOLFSSL_APACHE_MYNEWTand uses the stock seed function. - Any integration that calls
wc_InitRng(), or lets the TLS layer do so, seeds its DRBG through this branch. No unusual option or call sequence is involved. - The attacker is a passive observer of TLS or DTLS traffic from the device. No authentication and no interaction with the device are needed.
- The attacker can bound
os_time_get()at seeding time from an estimate of boot time and the tick rate. Devices that start TLS shortly after power-on seed with a small tick value. - The attacker observes at least one DRBG-derived value to confirm a candidate, and needs the
rand()implementation of the C library the firmware was linked with.
Impact
On these builds the DRBG seed is determined by the tick counter at initialisation. An observer who pins that value recovers the DRBG state and can compute the session keys, GCM IVs, session ticket keys and locally generated keys drawn from it. Predictable per-message IVs also break GCM's integrity guarantee through nonce reuse. The main effect is that secret material on affected builds can be derived from public observations.
ByteRay compiled the unmodified wolfCrypt sources with the flags of the in-tree Mynewt package on a Linux host, with os_time_get() replaced by a settable counter. Two separate processes started at the same tick produced identical seeds, made of one eight-byte block repeated, and identical AES-GCM key, IV, ciphertext and tag; a search over a window of 4096 candidate ticks reproduced all four through wc_InitRng() and wc_AesGcmSetIV(), and a control build seeded from the host's /dev/urandom differed on every run.
Behaviour on a Mynewt device, including how far the tick advances during one call, was not measured.
Remediation and Mitigation
ByteRay has not confirmed a fixed wolfSSL release for this issue as of 2026-12-03, and has not checked it against wolfSSL changes made after the tested commit.
The fix direction is to replace the srand(os_time_get())/rand() loop with a read from Mynewt's TRNG interface on boards that have one, and to fail closed on boards that do not: wc_GenerateSeed() returns an entropy error and DRBG instantiation aborts. A tick counter may be mixed into seed material that comes mainly from a real entropy source. It should not be the only input. A build-time guard should stop a Mynewt configuration without an entropy source from using this fallback.
Workaround: define CUSTOM_RAND_GENERATE_SEED to a function that reads the board's TRNG. That macro takes precedence over this branch. Treat keys generated by a build that used the stock function as exposed and replace them.
Timeline
- 2026-09-27 — Reported to wolfSSL.
- 2026-12-03 — Public disclosure.
Credits
Discovered and reported by Mehrun P. Hunter and Shahriyar Jalayeri of ByteRay Ltd.
References
- Apache Mynewt branch of wc_GenerateSeed at the tested commit
- BYTERAY-2026-0325, the PIC32 branch of the same function
- BYTERAY-2026-0326, the EBSnet RTP branch of the same function
- BYTERAY-2026-0327, the INtime RTOS 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