← ALL ADVISORIES

HIGH BYTERAY-2026-0330Disclosed

wolfSSL — Predictable DRBG Seed from the Kernel Time Stamp in Nucleus RTOS Builds

On Nucleus RTOS builds, wolfSSL's seed function seeds the C library generator from NU_Get_Time_Stamp() and returns rand() output as the DRBG seed. The time stamp is a system counter with no secret in it, so the seed, and everything drawn from the DRBG, can be recomputed by searching candidate counter values.

Advisory
BYTERAY-2026-0330
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_NUCLEUS 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_NUCLEUS has no entropy source. It passes the Nucleus kernel time stamp, NU_Get_Time_Stamp(), to srand() and copies rand() output into the seed buffer. It reads the time stamp again after every eight bytes.

The time stamp is a counter the system generates. It holds no secret, and rand() expands it deterministically. The DRBG state after initialisation is therefore a function of a counter value an observer can estimate. Someone who sees a value the DRBG produced, such as a TLS hello random or an AES-GCM IV, can search for the counter value that reproduces it and then compute every other value the generator gave out.

The branch carries its own build warning, "potential for not enough entropy, currently being used for testing", but nothing stops it from shipping. Only builds for Nucleus take it. A default ./configure build does not; it seeds from /dev/urandom.

Affected Products and Versions

  • Component: wolfcrypt/src/random.c, wc_GenerateSeed(), the WOLFSSL_NUCLEUS branch.
  • Required build: WOLFSSL_NUCLEUS defined (wolfcrypt/src/random.c:8569). One in-tree configuration defines it (IDE/CSBENCH/user_settings.h:16).
  • No seed override in place. CUSTOM_RAND_GENERATE_SEED and CUSTOM_RAND_GENERATE_SEED_OS come 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 ./configure build does not include this code.
  • Other releases were not checked.

Technical Details

The function is at wolfcrypt/src/random.c:8574-8587, directly after the warning at wolfcrypt/src/random.c:8573:

#warning "potential for not enough entropy, currently being used for testing"
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
{
    int i;
    srand(NU_Get_Time_Stamp());

    for (i = 0; i < sz; i++ ) {
        output[i] = rand() % 256;
        if ((i % 8) == 7) {
            srand(NU_Get_Time_Stamp());
        }
    }

    return 0;
}

The generator is seeded at wolfcrypt/src/random.c:8577 and again after every eighth byte. Each block of eight bytes is therefore the start of the rand() sequence for one time-stamp reading. If the time stamp has not advanced between two blocks, the blocks are identical. The function always returns 0. How the seed is used:

  1. wc_InitRng() (wolfcrypt/src/random.c:3400) calls _InitRng() (wolfcrypt/src/random.c:2745).
  2. _InitRng() requests the seed from wc_GenerateSeed() (wolfcrypt/src/random.c:3135). With WC_RNG_SEED_CB the default callback is the same function (wolfcrypt/src/random.c:390). Reseeding also calls it (wolfcrypt/src/random.c:4685).
  3. The branch above fills the buffer from the time-stamp readings taken during the call (wolfcrypt/src/random.c:8577-8584).
  4. Hash_DRBG_Instantiate() takes that buffer as its entropy input (wolfcrypt/src/random.c:3178).
  5. wc_RNG_GenerateBlock() hands out DRBG output (wolfcrypt/src/random.c:5605).
  6. That output reaches the wire: per-message AES-GCM IVs from wc_AesGcmSetIV() (wolfcrypt/src/aes.c:15126), session ticket IVs from DefTicketEncCb() (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_NUCLEUS and 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 NU_Get_Time_Stamp() at seeding time from an estimate of boot time and the counter rate. Devices that start TLS shortly after power-on keep that value in a narrow range.
  • 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 time-stamp 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 WOLFSSL_NUCLEUS on a Linux host, with NU_Get_Time_Stamp() replaced by a settable counter held at one value. A 64-byte seed came out as one eight-byte block repeated eight times and matched a separate replay of the rand() algorithm from the counter value alone; a search over 2201 candidate counter values through wc_InitRng() and wc_AesGcmSetIV() reproduced the victim's DRBG output and AES-GCM IV and tag.

Behaviour on a Nucleus target, including how far the time stamp 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 remove the srand(NU_Get_Time_Stamp())/rand() loop from the Nucleus path and seed from a real entropy source: a hardware RNG peripheral through wolfSSL's hardware hooks, or a Nucleus entropy service. Where none is available, wc_GenerateSeed() should fail closed with an error so that RNG setup and the TLS operations that depend on it abort. Turning the existing #warning into an #error for non-test configurations would match the testing-only intent the code already states.

Workaround: define CUSTOM_RAND_GENERATE_SEED to a function that reads a hardware entropy source. 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