Random: add DRBG reseed support#130
Conversation
dgarske
left a comment
There was a problem hiding this comment.
Skoll Code Review
Scan type: reviewOverall recommendation: COMMENT
Findings: 4 total — 4 posted, 0 skipped
4 finding(s) posted as inline comments (see file-level comments below)
Posted findings
- [Medium] test_reseed_empty asserts nothing and silently passes on either outcome —
tests/test_random.py:61-66 - [Low] Non-ASCII em-dash in test comment violates ASCII-only convention —
tests/test_random.py:66 - [Low] test_reseed only checks output length, not that reseed had any effect —
tests/test_random.py:55-58 - [Low] Per-method feature gate inside class body differs from repo's module-level gating pattern —
wolfcrypt/random.py:81-89
Review generated by Skoll
dgarske
left a comment
There was a problem hiding this comment.
Skoll Multi-Scan Review
Modes: review + review-securityOverall recommendation: COMMENT
Findings: 3 total — 3 posted, 0 skipped
3 finding(s) posted as inline comments (see file-level comments below)
Posted findings
- [Medium] [review] reseed error branch missing # pragma: no cover used by every other error path —
wolfcrypt/random.py:88 - [Low] [review] Trailing whitespace on blank line inside test_reseed_multiple —
tests/test_random.py:79 - [Low] [review] Seed bytes use % 255, likely intended % 256 —
tests/test_random.py:61,77
Review generated by Skoll
- add pragma no cover - format using ruff - fix module factor in test_random
dgarske
left a comment
There was a problem hiding this comment.
Skoll Code Review
Scan type: reviewOverall recommendation: COMMENT
Findings: 3 total — 3 posted, 0 skipped
3 finding(s) posted as inline comments (see file-level comments below)
Posted findings
- [Medium] HASHDRBG feature not detected on Windows non-FIPS build; reseed() silently unavailable —
scripts/build_ffi.py:381 - [Low] test_reseed_multiple is non-deterministic —
tests/test_random.py:72-85 - [Low] reseed() accepts bytes only with no input normalization —
wolfcrypt/random.py:82-89
Review generated by Skoll
- Make test_reseed_multiple deterministic - Add HAVE_HASHDRBG to windows/non_fips/user_settings.h
dgarske
left a comment
There was a problem hiding this comment.
Skoll Code Review
Scan type: reviewOverall recommendation: COMMENT
Findings: 3 total — 3 posted, 0 skipped
2 finding(s) posted as inline comments (see file-level comments below)
1 finding(s) not tied to a diff line (full detail below)
Posted findings
- [Low] Misleading comment in test_reseed_multiple (no random seed sizes used) —
tests/test_random.py:76 - [Low] HASHDRBG feature detection relies on explicit #define that wolfSSL may only set implicitly —
scripts/build_ffi.py:381
Findings not tied to a diff line
Type stub lib.pyi not updated with HASHDRBG_ENABLED / wc_RNG_DRBG_Reseed
File: wolfcrypt/_ffi/lib.pyi:33
Function: N/A (module-level stub)
Severity: Medium
The repo maintains a hand-written CFFI type stub at wolfcrypt/_ffi/lib.pyi that enumerates every *_ENABLED feature flag (lines 7-33, including HKDF_ENABLED, ML_DSA_ENABLED, etc.). This PR introduces a new build-time flag HASHDRBG_ENABLED (used in wolfcrypt/random.py:81 and tests/test_random.py:57,71) and a new native function wc_RNG_DRBG_Reseed (used in wolfcrypt/random.py:87), but does not add either to the stub. The project ships mypy and ty in its [dependency-groups] dev (see pyproject.toml), so a type check would report _lib.HASHDRBG_ENABLED as attr-defined error. Adding the flag keeps the stub's flag section complete and consistent.
Recommendation: Add HASHDRBG_ENABLED: int to the flags section of lib.pyi (and, for completeness, wc_RNG_DRBG_Reseed) so the stub stays in sync with the CFFI-generated symbols this PR references.
Referenced code: wolfcrypt/_ffi/lib.pyi:33-36 (4 lines)
Review generated by Skoll
| """ | ||
| Test that consecutive reseeding of the random number generator works. | ||
| """ | ||
| # Using our own rng for getting random seed sizes. |
There was a problem hiding this comment.
🔵 [Low] Misleading comment in test_reseed_multiple (no random seed sizes used)
The comment # Using our own rng for getting random seed sizes. does not match the code: the loop uses a fixed seed of size 32 on every iteration and no randomness at all. This looks like a copy/paste leftover from an earlier version of the test and is confusing to future readers.
Fix: Remove or correct the inaccurate comment so it describes what the test actually does.
| features["ML_DSA"] = 1 if '#define HAVE_DILITHIUM' in defines else 0 | ||
| features["ML_KEM"] = 1 if '#define WOLFSSL_HAVE_MLKEM' in defines else 0 | ||
| features["HKDF"] = 1 if "#define HAVE_HKDF" in defines else 0 | ||
| features["HASHDRBG"] = 1 if "#define HAVE_HASHDRBG" in defines else 0 |
There was a problem hiding this comment.
🔵 [Low] HASHDRBG feature detection relies on explicit #define that wolfSSL may only set implicitly
features["HASHDRBG"] is detected by searching for the literal string #define HAVE_HASHDRBG in options.h/user_settings.h. Unlike most features, wolfSSL auto-enables Hash-DRBG inside random.h (see the bundled header: #if !defined(WC_NO_HASHDRBG) && !defined(CUSTOM_RAND_GENERATE_BLOCK) -> #define HAVE_HASHDRBG), so the symbol is not guaranteed to appear in options.h/user_settings.h. For the bundled configure output it does appear (options.h lines 131-132), and the PR correctly adds it to windows/non_fips/user_settings.h, so current builds are fine. However, a user supplying a custom user_settings.h that relies on the implicit default (defines neither HAVE_HASHDRBG nor WC_NO_HASHDRBG) would build a library that fully supports wc_RNG_DRBG_Reseed yet get HASHDRBG=0, silently dropping the reseed() method. This is a false-negative (safe, no crash) and is consistent with how other flags are detected, so it is not blocking.
Fix: Consider mirroring wolfSSL's own gating logic (default-on unless WC_NO_HASHDRBG / CUSTOM_RAND_GENERATE_BLOCK), or document that HAVE_HASHDRBG must be explicitly defined in user_settings.h for reseed support. Low priority since configure builds and the new Windows non_fips settings both define it explicitly.
Only available when Hash-DRBG is enabled, which is the default.