Repository navigation
Conversation
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.
Contributor
There was a problem hiding this comment.
🟢 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
|
Member
Author
|
Jenkins retest this please |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Eight RNG tests in
wolfcrypt/test/test.ccheck 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 globaldevId. On a port whose crypto callback servesWC_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_testfails withNEEDS_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_testskipped its counter and statistics checks for the same reason.Using
INVALID_DEVIDinstead doesn't work everywhere. On aNO_DEV_RANDOMport such as the bare-metal RW612 setup, the crypto callback is the only seed source, and an RNG without adevIdcan't be seeded at all.So
wolfcrypt_test()now registers a small test device that passes seed requests on to thedevIdit captured at registration, throughwc_GenerateSeed(), and declines everything else. An RNG on that device is seeded from the same source an RNG ondevIdwould use, and it still generates in the DRBG. The DRBG tests use it asRNG_DRBG_DEVIDand the RNG lock tests, which need the same property, asRNG_LOCK_DEVID. Both macros pick it only while it is registered, so a test run outsidewolfcrypt_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/SHA512builds, where the DRBG hashes through itsdevId, and async builds, which treat adevIdas a hardware handle, keep today's choice.Testing
seed-onlycb-no-swdevconfiguration fromcryptocb-only.yml: all RNG tests pass.--enable-rng-extras --enable-rng-bank --enable-cryptocb,--enable-all --enable-rng-extras --enable-rng-bank, and aWOLF_CRYPTO_CB_ONLY_SHA256build with swdev: all RNG tests pass.NO_DEV_RANDOMhost build whose only seed source is the test callback, which also servesWC_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.