← ALL ADVISORIES

MEDIUM BYTERAY-2026-0388Disclosed

wolfSSL — DRBG Seed Passed Through One-Byte-Seeded rand() in the NETOS Seed Callback

The NETOS project supplies every Hash_DRBG seed through my_rng_generate_seed, which seeds libc rand() with one entropy-pool byte and emits one rand() byte per seed byte. The rand() stage adds no entropy, the pool's quality is never checked, and the pool accessor waits forever when the pool is empty.

Advisory
BYTERAY-2026-0388
CWE
CWE-337
CVSS
5.6 (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:L)
Vendor
wolfSSL
Product
wolfSSL
Reported
2026-09-28
Disclosure
2026-12-03
Affected
wolfSSL 5.9.2 (tested at master commit d95483f), builds made from the IDE/NETOS project, where CUSTOM_RAND_GENERATE_SEED is my_rng_generate_seed
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

The NETOS project in IDE/NETOS does not let wolfSSL gather OS entropy. Its settings register a custom function, my_rng_generate_seed(), as the only source of seed material for the Hash_DRBG.

That function works one byte at a time. It takes a byte from the platform entropy pool, passes it to srand(), and writes the next value of rand() as the seed byte. The state of rand() after srand() is that single byte, so every seed byte is a fixed function of one pool byte. The rand() stage contributes nothing and can at best pass on what the pool byte carried.

The DRBG therefore depends entirely on a pool whose quality the code does not check. The pool accessor discards the density value the pool reports and sleeps in a loop without a bound when the pool is empty. This seed path is the unconditional setting for the NETOS project. The standard ./configure build does not use it.

Affected Products and Versions

  • Component: IDE/NETOS/wolfssl_netos_custom.c, my_rng_generate_seed() and get_byte_from_pool().
  • Required build: the NETOS project settings, which define CUSTOM_RAND_GENERATE_SEED as my_rng_generate_seed inside an #if 1 block (IDE/NETOS/user_settings.h:471-475). The user_settings.h-cert3389 variant in the same directory has the same definition.
  • 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 body of the seed callback, at IDE/NETOS/wolfssl_netos_custom.c:69-80:

    srand(get_byte_from_pool());

    for (i = 0; i < sz; i++) {
        output[i] = (unsigned char) rand();
        srand(get_byte_from_pool());
    }

Data flow:

  1. get_byte_from_pool() waits until the pool reports at least one byte, then pops one byte with ent_pop() (IDE/NETOS/wolfssl_netos_custom.c:49-67). The density value that ent_pop() returns is not used.
  2. srand() receives that byte (IDE/NETOS/wolfssl_netos_custom.c:72, IDE/NETOS/wolfssl_netos_custom.c:76). The generator now has one of 256 states.
  3. output[i] receives the low byte of the next rand() value (IDE/NETOS/wolfssl_netos_custom.c:75). It is one of at most 256 fixed values.
  4. wc_GenerateSeed() forwards to the callback (wolfcrypt/src/random.c:7750-7754), and the RNG initialization uses the result to seed the Hash_DRBG (wolfcrypt/src/random.c:3135).

The wait in step 1 is while (ent_get_byte_count() == 0) tx_thread_sleep(1); (IDE/NETOS/wolfssl_netos_custom.c:56-57). A comment above it marks the loop as needing improvement. There is no timeout and no error return, so a starved pool blocks seeding indefinitely.

Whether the seed is predictable depends on the NetOS entropy pool, which is outside the wolfSSL tree. What the tree shows is that no stage conditions the pool output, measures it or fails closed. BYTERAY-2026-0389 describes a related use of rand() in another example port.

Reachability and Preconditions

  • The device runs a build made from the NETOS project. No further option is needed.
  • For key recovery, the NetOS pool must deliver bytes that an attacker can model, which was not established, and the attacker must observe the device's TLS handshakes from the network. No authentication is needed.
  • The hang needs the pool to stay empty, which is a device condition and not something a peer controls directly.

Impact

Every TLS random, session key, IV and nonce on these builds derives from this seed. If the pool under-delivers, an observer who can enumerate its likely output can rebuild the DRBG seed offline, match it against a captured handshake random, and derive session keys or impersonate the device. With a sound pool the construction still adds nothing to it. A pool that stays empty stops the calling thread in the seed path, so RNG initialization and reseeding never return.

ByteRay did not build a proof of concept for this issue. The analysis is from source review.

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 fill the seed buffer from the entropy pool directly and remove the srand() and rand() stage. If conditioning is wanted, hash a larger pool sample with SHA-256. The pool accessor should use the reported density, enforce a minimum, and return an error when the pool is starved. Integrators using this project can replace the callback with one that reads a hardware RNG or the pool directly, and should check the entropy quality of the platform pool before deployment.

Timeline

  • 2026-09-28 — Reported to wolfSSL.
  • 2026-12-03 — Public disclosure.

Credits

Discovered and reported by Mehrun P. Hunter and Shahriyar Jalayeri of ByteRay Ltd.

References