wolfSSL — Unchecked TRNG Initialization Failure in Infineon/Cypress HAL Seed Generation
On Infineon/Cypress HAL builds, wc_GenerateSeed returns success without writing the seed buffer when cyhal_trng_init fails. The DRBG is then seeded from whatever the buffer already held, and no error reaches the caller.
- Advisory
- BYTERAY-2026-0400
- CWE
- CWE-1213
- Vendor
- wolfSSL
- Product
- wolfSSL
- Reported
- 2026-09-28
- Disclosure
- 2026-12-03
- Affected
- wolfSSL 5.9.2 (tested at master commit d95483f), builds for the Infineon/Cypress HAL with CY_USING_HAL and COMPONENT_WOLFSSL
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
wolfCrypt takes the seed material for its DRBG from wc_GenerateSeed(). On Infineon/Cypress PSoC and ModusToolbox builds, that function reads the hardware TRNG through the cyhal API.
The function starts the TRNG with cyhal_trng_init() and fills the caller's buffer only if that call succeeds. If it fails, the fill is skipped and the function still returns 0, the wolfSSL success code. The caller is told that seeding worked while the buffer holds whatever was in it before.
The DRBG is then instantiated or reseeded from that data. On an embedded target the old contents can be the same on every boot, and everything derived from the DRBG repeats with them. Only builds that define CY_USING_HAL and COMPONENT_WOLFSSL contain this code. Default builds are not affected.
Affected Products and Versions
- Component:
wolfcrypt/src/random.c,wc_GenerateSeed(), the Infineon/Cypress HAL implementation. - Required build:
CY_USING_HALandCOMPONENT_WOLFSSL(wolfcrypt/src/random.c:9577), the usual ModusToolbox and PSoC configuration. - 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 whole seed operation hangs on the result of cyhal_trng_init() (wolfcrypt/src/random.c:9589-9608):
result = cyhal_trng_init(&obj);
if (result == CY_RSLT_SUCCESS) {
/* fill output from cyhal_trng_generate(), then cyhal_trng_free() */
}
return 0;
There is no else branch. When initialization fails, the fill loop and cyhal_trng_free() are skipped and control reaches the unconditional return 0 at wolfcrypt/src/random.c:9608. Nothing has been written to output.
What the callers do with that result:
- DRBG instantiation calls
wc_GenerateSeed()atwolfcrypt/src/random.c:3135and treats only a non-zero return as a failure (wolfcrypt/src/random.c:3144). PollAndReSeedcalls it atwolfcrypt/src/random.c:4685with the same test atwolfcrypt/src/random.c:4687. Its seed buffer is a cached buffer kept in the RNG object (wolfcrypt/src/random.c:4659), a fresh heap allocation (wolfcrypt/src/random.c:4662), or a stack array (wolfcrypt/src/random.c:4666). None of them is cleared before the call.- On a zero return the buffer is handed on as a full-entropy seed. The seed health test,
wc_RNG_TestSeed()(wolfcrypt/src/random.c:2525), looks only at the bytes it is given. It cannot tell that the same stale bytes were delivered on an earlier call or an earlier boot. - No error reaches
wc_InitRng()or the TLS layer.
Reachability and Preconditions
- The library is built with
CY_USING_HALandCOMPONENT_WOLFSSL. cyhal_trng_init()fails at run time, for example because of a TRNG resource or clock conflict on the board.- A remote party cannot cause that failure on demand. The defect shows up on devices where the entropy provider does not start, and it does so silently.
- No authentication state is involved. The affected code runs whenever an RNG is created or reseeded.
Impact
On a device where the TRNG does not initialize, the DRBG is seeded from uninitialized stack memory, stale heap contents or a previously cached seed. These contents often repeat across reboots on embedded targets. When they do, DRBG output repeats too: TLS handshake randoms, session keys, nonces and session-ticket keys. Where that repetition occurs, an observer of the device's traffic is in a position to reproduce keying material. The condition is not reported anywhere, so an integrator has no signal that the device is running without a working entropy source.
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 return an error, for example RNG_FAILURE_E, when cyhal_trng_init() does not succeed, and to return 0 only after the buffer has been filled and the TRNG released. The callers already treat any non-zero return from wc_GenerateSeed() as fatal, so propagating the error is enough. A bounded retry for transient initialization failures is optional.
There is no build option that changes this behaviour on the affected port. Until the function reports the failure, integrators can check at start-up that the hardware TRNG initializes and stop if it does not, before any wolfCrypt RNG is created.
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.