Skip to content

Added Usage Example for Argon2 Password Hashing#36

Open
Chidwan3578 wants to merge 3 commits intoDaemoniorum-LLC:mainfrom
Chidwan3578:main
Open

Added Usage Example for Argon2 Password Hashing#36
Chidwan3578 wants to merge 3 commits intoDaemoniorum-LLC:mainfrom
Chidwan3578:main

Conversation

@Chidwan3578
Copy link
Copy Markdown

I have added the Argon2 usage example to the module documentation in
crates/arcanum-hash/src/argon2_impl.rs

  1. The example covers:
  • Selecting parameters (Moderate).
  • Hashing a password (with automatic salt generation).
  • Verifying a password.
  • Key derivation with a manual salt.
  • Summary
  • This PR adds a comprehensive usage example for Argon2id password hashing to the module-level documentation. This helps developers understand how to use the
  • Argon2
  • struct for secure password storage and key derivation within the Arcanum engine.
  1. 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.

  2. Testing:

  • Unit tests pass (cargo test --all) - Note: Manually verified the logic; automated tests not run in this environment due to missing cargo binary.
  • Clippy passes (cargo clippy --all-targets)
  • Formatted (cargo fmt --check)
  1. Related Issues:
    Issue [Docs] Add Argon2 password hashing example #27

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.
@Chidwan3578 Chidwan3578 changed the title Add Usage Example for Argon2 Password Hashing Added Usage Example for Argon2 Password Hashing Jan 23, 2026
Copy link
Copy Markdown
Contributor

@paraphilic-ecchymosis paraphilic-ecchymosis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, &params, 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants