Skip to content

Keep the DRBG-state RNG tests off devices that serve generate - #11943

Open
Frauschi wants to merge 1 commit into
wolfSSL:masterfrom
Frauschi:fix-rng-epoch-test-cryptocb
Open

Frauschi wants to merge 1 commit into
wolfSSL:masterfrom
Frauschi:fix-rng-epoch-test-cryptocb

Conversation

@Frauschi

Copy link
Copy Markdown
Member

Description

Eight RNG tests in wolfcrypt/test/test.c check the Hash-DRBG's own state: reseed counters, the entropy epoch, the next-seed and pool banks, and the lock. They create their RNGs with the global devId. On a port whose crypto callback serves WC_ALGO_TYPE_RNG (EdgeLock on RW612, STM32, Silicon Labs), wc_RNG_GenerateBlock() goes to the device instead, so the DRBG state they assert on never changes. On frdm_rw612, rng_epoch_test fails with NEEDS_RECOVERY_E. The other seven build only with the RNG extras, and fail the same way on a host build whose test device also serves generate. rng_drbg_svc_test skipped its counter and statistics checks for the same reason.

Using INVALID_DEVID instead doesn't work everywhere. On a NO_DEV_RANDOM port such as the bare-metal RW612 setup, the crypto callback is the only seed source, and an RNG without a devId can't be seeded at all.

So wolfcrypt_test() now registers a small test device that passes seed requests on to the devId it captured at registration, through wc_GenerateSeed(), and declines everything else. An RNG on that device is seeded from the same source an RNG on devId would use, and it still generates in the DRBG. The DRBG tests use it as RNG_DRBG_DEVID and the RNG lock tests, which need the same property, as RNG_LOCK_DEVID. Both macros pick it only while it is registered, so a test run outside wolfcrypt_test(), or after a crypto callback test has cleared the device table, keeps today's choice. The device is unregistered when the suite ends.

Old FIPS and CAVP selftest builds, where wc_GenerateSeed() isn't exported, WOLF_CRYPTO_CB_ONLY_SHA256/SHA512 builds, where the DRBG hashes through its devId, and async builds, which treat a devId as a hardware handle, keep today's choice.

Testing

  • seed-onlycb-no-swdev configuration from cryptocb-only.yml: all RNG tests pass.
  • Default host build with --enable-rng-extras --enable-rng-bank --enable-cryptocb, --enable-all --enable-rng-extras --enable-rng-bank, and a WOLF_CRYPTO_CB_ONLY_SHA256 build with swdev: all RNG tests pass.
  • A NO_DEV_RANDOM host build whose only seed source is the test callback, which also serves WC_ALGO_TYPE_RNG. This stands in for a port like those above. Before the change, 9 of the 10 RNG tests fail; after it, all pass.
  • frdm_rw612 with the EdgeLock port: the wolfCrypt suite passes 54/54, including RNGSVC, RNGEPOCH and RNGLIFE.

rng_epoch_test, rng_lifecycle_test, rng_entropy_invalidate_test,
rng_drbg_rbgc_test, rng_drbg_nextseedstest, rng_pool_test,
random_bank_test and rng_lock_fork_test check the Hash-DRBG's own state:
reseed counters, the entropy epoch, the next-seed and pool banks, the
lock. They created their RNGs and banks with the global devId, so on a
port whose crypto callback serves WC_ALGO_TYPE_RNG (EdgeLock on RW612,
STM32, Silicon Labs and others), wc_RNG_GenerateBlock() went to the
device and the DRBG state they assert on never moved. On frdm_rw612
rng_epoch_test fails with NEEDS_RECOVERY_E. The other seven build only
with the RNG extras, and fail the same way on a host build whose test
device also serves generate. rng_drbg_svc_test skipped its counter and
statistics checks for the same reason.

INVALID_DEVID does not fix it: on a NO_DEV_RANDOM port such as the
bare-metal RW612 setup the crypto callback is the only seed source, and
an RNG without a devId cannot seed at all. wolfcrypt_test() now
registers a small device next to the other test devices whenever devId
names one. It answers a seed request by calling wc_GenerateSeed() for
the devId captured at registration, on an OS_Seed of its own, since the
caller's is read without the RNG lock by the next-seed producer, and
declines everything else, so an RNG on it seeds from wherever one on
devId would and still generates in the DRBG. The nine tests use it as
RNG_DRBG_DEVID and the RNG lock tests, which need the same property, as
RNG_LOCK_DEVID; rng_drbg_svc_test counts generation on it as local.
Registration replaces a forwarder that a run which failed early left
behind, and the device is unregistered when the suite ends.

Both macros pick the forwarder only while it is registered, so a test
run outside wolfcrypt_test(), or after a crypto callback test has
cleared the device table, keeps the old choice: devId for the DRBG
tests, and INVALID_DEVID for the lock tests unless
WOLF_CRYPTO_CB_SEED_ONLY_TEST. Builds without the forwarder keep it as
well. That covers old FIPS and CAVP selftest builds, where
wc_GenerateSeed() is not exported, builds whose DRBG hash is
WOLF_CRYPTO_CB_ONLY and so has to run on devId, async builds, which
treat a devId as a hardware device handle, and builds without an RNG.
@Frauschi Frauschi self-assigned this Oct 30, 2026
Copilot AI balanced review requested due to automatic review settings October 30, 2026 16:24

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.

🟢 Approval recommended

No active review issues remain for the RNG test updates.

No open issues 🎉

What changed in this PR

This PR keeps RNG tests that inspect Hash-DRBG state on the software generation path while preserving device-backed seeding, including on ports without another entropy source.

Changes:

  • Adds a seed-forwarding test callback, registered and removed by wolfcrypt_test().
  • Routes DRBG-state and lock tests through the forwarder when available.
  • Preserves existing device selection for unsupported configurations and when the forwarder is not registered.
File Description
wolfcrypt/​test/​test.c Adds the seed-forwarding device and updates RNG tests to exercise software DRBG state.

Review effort: Balanced

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

@Frauschi

Frauschi commented Nov 2, 2026

Copy link
Copy Markdown
Member Author

Jenkins retest this please

@Frauschi Frauschi assigned wolfSSL-Bot and unassigned Frauschi Nov 2, 2026
@Frauschi
Frauschi requested a review from douzzer November 2, 2026 09:34
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.

3 participants