Skip to content

random: add WC_RNG_SEED_DEVICE to seed from a nominated device - #11216

Open
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:rng_seed_device
Open

random: add WC_RNG_SEED_DEVICE to seed from a nominated device#11216
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:rng_seed_device

Conversation

@dgarske

@dgarske dgarske commented Aug 20, 2026

Copy link
Copy Markdown
Member

Adds WC_RNG_SEED_DEVICE, an optional macro naming a device to seed the DRBG from before the default sources, for platforms that expose a hardware RNG such as /dev/hwrng (the NXP i.MX95 EdgeLock Secure Enclave, among others). Its value is a quoted string, set either by autotools --with-rng-seed-device=PATH, by CMake -DWOLFSSL_RNG_SEED_DEVICE=PATH, or directly as #define WC_RNG_SEED_DEVICE "/dev/hwrng" in user_settings.h; the two build systems take an unquoted path and add the quoting for you. The device attempt is self-contained and strictly additive: any failure to open or fill it falls through to the untouched getrandom() -> /dev/urandom -> /dev/random chain, so a default build is unchanged. Also fixes two pre-existing bugs in wc_GenerateSeed() (happy to split these out): WOLFSSL_KEEP_RNG_SEED_FD_OPEN with NO_DEV_URANDOM does not compile on master due to a dangling else, and the seed read loop spins forever if read() returns 0. Two new os-check-linux CI configs cover the device and fallback paths.

Copilot AI lite review requested due to automatic review settings August 20, 2026 04:21
@dgarske dgarske self-assigned this Aug 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an opt-in mechanism for seeding the wolfCrypt DRBG from a nominated device (e.g. /dev/hwrng) before the existing OS entropy fallback chain, and tightens up edge cases in the existing filesystem seeding path. This fits into wolfcrypt/src/random.c’s platform entropy acquisition (wc_GenerateSeed) and the build-system knobs that control it.

Changes:

  • Add WC_RNG_SEED_DEVICE support to attempt seeding from a configured device before the existing sources, with best-effort fallback.
  • Fix wc_GenerateSeed() filesystem seeding edge cases (compile issue in WOLFSSL_KEEP_RNG_SEED_FD_OPEN + avoid infinite loop on read() returning 0).
  • Add Autotools/CMake configuration switches and Linux CI configs to exercise both the device and fallback paths.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
wolfcrypt/src/random.c Adds WC_RNG_SEED_DEVICE seeding attempt and fixes /dev/*random seeding loop/FD-open logic.
configure.ac Introduces --with-rng-seed-device=PATH to define WC_RNG_SEED_DEVICE in Autotools builds.
CMakeLists.txt Adds WOLFSSL_RNG_SEED_DEVICE cache option to emit -DWC_RNG_SEED_DEVICE=... for CMake builds.
cmake/options.h.in Adds WC_RNG_SEED_DEVICE to generated options.h for CMake parity.
.github/configs/os-check-linux.json Adds two Linux CI configurations to cover the device and fallback seeding paths.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread configure.ac
Comment on lines +8764 to +8766
fi
AM_CFLAGS="$AM_CFLAGS -DWC_RNG_SEED_DEVICE=\\\"$RNG_SEED_DEVICE\\\""
fi
Comment thread wolfcrypt/src/random.c Outdated
Comment on lines +5989 to +5991
/* Nominated entropy source, usually a hardware RNG. Best effort: on
* any failure fall through to the default sources below. Reads use a
* scratch cursor so a partial read leaves output untouched. */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants