Repository navigation
refactor: generate the Argon2 KDF salt with getrandom instead of rand - #183
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>
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
CASArgon::generate_salt()drew its salt withrand0.8 (OsRng.gen::<[u8; KDF_SALT_LENGTH]>()), the lastranduse insrc/password_hashers. It now usesgetrandom0.4 (already a dependency), and therandimport is gone.pub fn generate_salt() -> Vec<u8>, still exactlyKDF_SALT_LENGTH(16) bytes.rand'sOsRngdid), now withexpect("getrandom failure")likeget_ed25519_key_pair(), and documented under a new# Panicssection.unsafe.Cargo.toml/Cargo.lockuntouched (removingrandis Remove the rand dependency #182).CodeQL
rust/hard-coded-cryptographic-valueflags a zero-filled buffer later used as crypto input. The salt is never zero-initialised: it is a[MaybeUninit<u8>; KDF_SALT_LENGTH]passed togetrandom::fill_uninit, and the initialised&mut [u8]it returns is copied out with.to_vec().Tests
argon2_generate_salt_is_random_and_kdf_salt_length: twogenerate_salt()calls are bothKDF_SALT_LENGTHlong and differ.argon2_derive_with_salt_known_answerand all other existing tests/vectors are unedited and pass.cargo build --release --lockedOK;cargo test --release --locked: 235 passed, 0 failed (password_hashers: 40, including Wycheproof suites with network). Clippy isn't installed for the pinned toolchain locally, so it wasn't run.Part of #180
🤖 Generated with Claude Code