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
11 changes: 9 additions & 2 deletions argon2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ impl PasswordHasher<PasswordHash> for Argon2<'_> {
password: &[u8],
salt: &[u8],
) -> password_hash::Result<PasswordHash> {
let salt = Salt::new(salt).map_err(|_| password_hash::Error::SaltInvalid)?;
let salt = Salt::new(salt)?;

let output_len = self
.params
Expand All @@ -662,7 +662,7 @@ impl PasswordHasher<PasswordHash> for Argon2<'_> {
.ok_or(password_hash::Error::OutputSize)?;

self.hash_password_into(password, &salt, out)?;
let output = Output::new(out).map_err(|_| password_hash::Error::OutputSize)?;
let output = Output::new(out)?;

Ok(PasswordHash {
algorithm: self.algorithm.ident(),
Expand All @@ -674,6 +674,13 @@ impl PasswordHasher<PasswordHash> for Argon2<'_> {
}
}

#[cfg(all(feature = "alloc", feature = "password-hash"))]
impl PasswordVerifier<str> for Argon2<'_> {
fn verify_password(&self, password: &[u8], hash: &str) -> password_hash::Result<()> {
self.verify_password(password, &PasswordHash::new(hash)?)
}
}

impl From<Params> for Argon2<'_> {
fn from(params: Params) -> Self {
Self::new(Algorithm::default(), Version::default(), params)
Expand Down
15 changes: 13 additions & 2 deletions balloon-hash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ where
password: &[u8],
salt: &[u8],
) -> password_hash::Result<PasswordHash> {
let salt = Salt::new(salt).map_err(|_| password_hash::Error::SaltInvalid)?;
let salt = Salt::new(salt)?;
let hash = self.hash(password, &salt)?;
let output = Output::new(&hash).map_err(|_| password_hash::Error::OutputSize)?;
let output = Output::new(&hash)?;

Ok(PasswordHash {
algorithm: self.algorithm.ident(),
Expand All @@ -248,6 +248,17 @@ where
}
}

#[cfg(all(feature = "alloc", feature = "password-hash"))]
impl<D> PasswordVerifier<str> for Balloon<'_, D>
where
D: Digest + FixedOutputReset,
Array<u8, D::OutputSize>: ArrayDecoding,
{
fn verify_password(&self, password: &[u8], hash: &str) -> password_hash::Result<()> {
self.verify_password(password, &PasswordHash::new(hash)?)
}
}

impl<D: Digest + FixedOutputReset> From<Params> for Balloon<'_, D>
where
Array<u8, D::OutputSize>: ArrayDecoding,
Expand Down
4 changes: 2 additions & 2 deletions pbkdf2/src/phc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl CustomizedPasswordHasher<PasswordHash> for Pbkdf2 {
return Err(Error::Version);
}

let salt = Salt::new(salt).map_err(|_| Error::SaltInvalid)?;
let salt = Salt::new(salt)?;

let mut buffer = [0u8; Output::MAX_LENGTH];
let out = buffer
Expand All @@ -54,7 +54,7 @@ impl CustomizedPasswordHasher<PasswordHash> for Pbkdf2 {
};

f(password, &salt, params.rounds, out);
let output = Output::new(out).map_err(|_| Error::OutputSize)?;
let output = Output::new(out)?;

Ok(PasswordHash {
algorithm: *algorithm.ident(),
Expand Down
4 changes: 2 additions & 2 deletions scrypt/src/phc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ impl CustomizedPasswordHasher<PasswordHash> for Scrypt {
return Err(Error::Version);
}

let salt = Salt::new(salt).map_err(|_| Error::SaltInvalid)?;
let salt = Salt::new(salt)?;
let len = params.len.unwrap_or(Params::RECOMMENDED_LEN);

let mut buffer = [0u8; Output::MAX_LENGTH];
let out = buffer.get_mut(..len).ok_or(Error::OutputSize)?;
scrypt(password, &salt, &params, out).map_err(|_| Error::OutputSize)?;
let output = Output::new(out).map_err(|_| Error::OutputSize)?;
let output = Output::new(out)?;

Ok(PasswordHash {
algorithm: ALG_ID,
Expand Down
11 changes: 11 additions & 0 deletions sha-crypt/src/mcf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,17 @@ where
}
}

impl<D> PasswordVerifier<str> for ShaCrypt<D>
where
Self: ShaCryptCore,
{
fn verify_password(&self, password: &[u8], hash: &str) -> password_hash::Result<()> {
// TODO(tarcieri): better mapping from `mcf::Error` and `password_hash::Error`?
let hash = PasswordHashRef::new(hash).map_err(|_| Error::EncodingInvalid)?;
self.verify_password(password, hash)
}
}

impl ShaCryptCore for ShaCrypt<Sha256> {
const MCF_ID: &'static str = "5";
type Output = [u8; BLOCK_SIZE_SHA256];
Expand Down
8 changes: 8 additions & 0 deletions yescrypt/src/mcf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,11 @@ impl PasswordVerifier<PasswordHashRef> for Yescrypt {
Ok(())
}
}

impl PasswordVerifier<str> for Yescrypt {
fn verify_password(&self, password: &[u8], hash: &str) -> Result<()> {
// TODO(tarcieri): better mapping from `mcf::Error` and `password_hash::Error`?
let hash = PasswordHashRef::new(hash).map_err(|_| Error::EncodingInvalid)?;
self.verify_password(password, hash)
}
}