Added Usage Example for Argon2 Password Hashing#36
Added Usage Example for Argon2 Password Hashing#36Chidwan3578 wants to merge 3 commits intoDaemoniorum-LLC:mainfrom
Conversation
I have added the Argon2 usage example to the module documentation in crates/arcanum-hash/src/argon2_impl.rs. The example covers: Selecting parameters (Moderate). Hashing a password (with automatic salt generation). Verifying a password. Key derivation with a manual salt.
paraphilic-ecchymosis
left a comment
There was a problem hiding this comment.
Thanks for contributing! This is a solid first PR and the example structure is good.
One required change before merging:
The key derivation section uses let salt = [0u8; 16] which shows an all-zeros salt. Issue #27 specifically requires demonstrating "Generating a random salt" - this is a security-sensitive detail that people will copy-paste.
Please update lines 21-23 to show proper salt generation:
// 4. Key Derivation (e.g., for encryption)
use rand::rngs::OsRng;
use rand::RngCore;
let mut salt = [0u8; 16];
OsRng.fill_bytes(&mut salt);
let derived_key = Argon2::derive_key(password, &salt, ¶ms, 32)?;This matches the pattern already used internally by hash_password() and teaches safe practices.
Minor suggestion for future PRs: Create a feature branch (e.g., feat/argon2-example) instead of PRing from your fork's main branch. This keeps your main in sync with upstream.
Once the salt generation is fixed, this is ready to merge!
Suggested Changes are made.
I have added the Argon2 usage example to the module documentation in
crates/arcanum-hash/src/argon2_impl.rs
Changes:
Modified argon2_impl.rs to include a ## Example section in the module-level doc comments.
The example demonstrates the end-to-end flow: parameter selection, hashing, verification, and key derivation.
Testing:
Issue [Docs] Add Argon2 password hashing example #27