Repository navigation
chore(deps): remove the rand dependency in favour of getrandom - #187
Merged
Merged
Conversation
CASArgon::generate_salt() drew its salt with rand 0.8's OsRng, the last rand use in the password hashers. Fill a [MaybeUninit<u8>; KDF_SALT_LENGTH] with getrandom::fill_uninit instead, which avoids the zeroed-buffer pattern CodeQL flags as rust/hard-coded-cryptographic-value. The signature stays infallible and still panics if the OS RNG fails; document that under # Panics. Add a test that two salts are KDF_SALT_LENGTH long and differ. Part of #180. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
random_bytes (behind every AEAD's generate_key / generate_nonce and the AES-KW generate_kek) and the CASAeadSeal::seal nonce now come from getrandom::fill_uninit on an uninitialised MaybeUninit buffer instead of rand 0.8's OsRng. Drawing into uninitialised memory keeps CodeQL's rust/hard-coded-cryptographic-value rule quiet, and the stack buffer in random_bytes is wrapped in Zeroizing so the returned Vec is the only copy. Public API is unchanged: the generators stay infallible and panic if the OS RNG fails, as rand's OsRng did; this is now documented with # Panics sections. seal already returns CasResult, so an RNG failure there returns CasError::EncryptionFailed instead of panicking. Adds tests that consecutive generate_key / generate_nonce (and generate_kek) calls have the right lengths and differ. Part of #179. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…getrandom instead of rand refactor: generate the Argon2 KDF salt with getrandom instead of rand
…nternal generate_signing_and_verification_key() drew its key from rand 0.8's OsRng through SigningKey::new, the last place cas-lib hands slh-dsa 0.0.3 a rand_core 0.6 RNG. SigningKey::new only fills SK.seed, SK.prf and PK.seed (n bytes each, in that order) and builds the key from them, exactly what the public slh_keygen_internal does with caller-supplied seeds. Draw the three seeds with getrandom::fill_uninit into a Zeroizing buffer instead and call slh_keygen_internal. n is read from the parameter set's public SkLen (4n), with compile-time checks that SkLen = 4n and VkLen = 2n, so the seeds can't have the length slh_keygen_internal panics on. The function stays infallible and panics if the OS RNG fails, now documented under # Panics. Key and signature encodings are unchanged. Tests: a unit test feeds SigningKey::new a replay RNG and checks the new path builds the same key from the same bytes, plus NIST ACVP SLH-DSA-keyGen-FIPS205 SLH-DSA-SHAKE-128f known-answer tests (tcId 31-40) for slh_keygen_internal and a fresh-key sign/verify round trip. Part of #181 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… getrandom instead of rand refactor: generate AEAD keys and nonces with getrandom instead of rand
Nothing in src/ uses rand any more: RSA keys come from getrandom's SysRng, and Ed25519 keys, SLH-DSA seeds, AEAD keys and nonces, and Argon2/PBKDF2 salts from getrandom::fill / fill_uninit. Drop rand 0.8 from Cargo.toml; Cargo.lock loses rand, rand_chacha, ppv-lite86, getrandom 0.2, wasi 0.11 and zerocopy 0.8 (removals only, no remaining crate changes version). The HKDF and password-hasher tests draw their random inputs from getrandom directly, with alphanumeric test passwords mapped from random bytes. Docs and comments that said OsRng now name the OS random number generator. Part of #182. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…om seeds via slh_keygen_internal refactor: generate SLH-DSA keys from getrandom seeds via slh_keygen_internal
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
chore(deps): remove the rand dependency
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.
Summary
Removes the
randcrate from cas-lib. Every OS-randomness call now goes throughgetrandom0.4, which was already a dependency and is now the crate's only OS RNG. Done as one child PR per sub-issue of #172, each reviewed, CI-tested on Linux/Windows/macOS and merged into this branch:CASArgon::generate_saltusesgetrandom::fill_uninitgenerate_key/generate_nonce/generate_kekand thesealnonce usegetrandom::fill_uninit; keys go through a buffer zeroized on dropslh_keygen_internal(whatSigningKey::newdoes internally, without the rand_core 0.6 RNG); adds NIST ACVP SLH-DSA-SHAKE-128f keygen KATsrandfromCargo.toml/Cargo.lock(removals only), moves tests to getrandom, fixesOsRngwording in docs and CLAUDE.mdBehaviour
docs/EXAMPLES.mdstill compiles against cas-lib alone.SigningKey::newbyte-for-byte).seal: an OS RNG failure now returnsCasError::EncryptionFailedinstead of panicking (no newCasErrorvariants).generate_key/generate_nonce/generate_kek/generate_salt/ SLH-DSA keygen stay infallible and still panic if the OS RNG fails, as before; now documented under# Panics.fill_uninit), so CodeQL'srust/hard-coded-cryptographic-valuenever sees a zero-filled key/nonce buffer.Dependency tree
rand0.8,rand_chacha,ppv-lite86,getrandom0.2,wasi0.11,zerocopy0.8.rand_core0.6, only viaslh-dsa0.0.3 andsignature2 — removed by Track slh-dsa 0.2.0 (currently 0.2.0-rc.5) #171 when slh-dsa 0.2.0 is released (see the note on Track slh-dsa 0.2.0 (currently 0.2.0-rc.5) #171 about switching back toSigningKey::new).getrandom0.3 is build-time only (cc→jobserver, building zstd-sys).Testing
Final branch locally on Windows:
cargo build --release --locked(no warnings),cargo test --release --locked243 passed / 0 failed,cargo audit --deny unsound --deny yankedclean.Closes #179
Closes #180
Closes #181
Closes #182
Part of #172 (stays open until #171 removes rand_core 0.6).
🤖 Generated with Claude Code