Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ blake3 = "1.8.5"
hex = "0.4.3"
thiserror = "2.0.18"
ed25519-dalek = "3.0.0"
argon2 = "0.5"
argon2 = "0.6"

[dev-dependencies]
rand_chacha = "0.3"
Expand Down
24 changes: 18 additions & 6 deletions crates/crypto/src/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
//! generation and hashing, constant-time comparison. Lives here because
//! RustCrypto (argon2, blake3) and the RNG stay quarantined in this crate.

use argon2::password_hash::{PasswordHash, PasswordHasher, PasswordVerifier, SaltString};
use argon2::password_hash::phc::PasswordHash;
use argon2::password_hash::{PasswordHasher, PasswordVerifier};
use argon2::Argon2;
use std::sync::OnceLock;

Expand All @@ -11,11 +12,10 @@
use rand_core::{OsRng, RngCore};
let mut salt = [0u8; 16];
OsRng.fill_bytes(&mut salt);
let salt = SaltString::encode_b64(&salt).expect("16 bytes is a valid salt length");
Argon2::default()
.hash_password(password.as_bytes(), &salt)
.expect("argon2 hashing with default parameters cannot fail")
.to_string()
let hash: PasswordHash = Argon2::default()
.hash_password_with_salt(password.as_bytes(), &salt)
.expect("argon2 hashing with default parameters cannot fail");
hash.to_string()
}

static DUMMY: OnceLock<String> = OnceLock::new();
Expand Down Expand Up @@ -102,6 +102,18 @@
);
}

#[test]
fn hash_from_argon2_0_5_still_verifies() {
// Made by argon2 0.5.3 (the version before 0.6): rows stored by older
// sc-forge builds must keep verifying after the upgrade.
let legacy = concat!(
"$argon2id$v=19$m=19456,t=2,p=1$12Jq/QaZmfBGlN6TfZu3Rg",
"$nVEPZmM6n6sSG8yZfXvFF5E00aLDJTCVu7bpGnEhDyU"
);
assert!(verify_password("legacy-0.5-fixture-pw", Some(legacy)));
Comment thread
tonibergholm-codento marked this conversation as resolved.
Dismissed
assert!(!verify_password("legacy-0.5-fixture-px", Some(legacy)));
Comment thread
tonibergholm-codento marked this conversation as resolved.
Dismissed
}

#[test]
fn same_password_hashes_differently() {
let p = pw();
Expand Down
Loading