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
argon2: remove version from params
In the PHC string format, version is out-of-band from the rest of the
parameters.

This change reflects that in the API and types.
  • Loading branch information
tarcieri committed Aug 27, 2021
commit 1db5246e3f32074ad82768a3ebf181da8bb889dd
15 changes: 8 additions & 7 deletions argon2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl Default for Argon2<'_> {
params.t_cost,
params.m_cost,
params.p_cost,
params.version,
Version::default(),
)
.expect("invalid default Argon2 params")
}
Expand Down Expand Up @@ -352,7 +352,6 @@ impl<'key> Argon2<'key> {
t_cost: self.t_cost,
p_cost: self.threads,
output_size: self.output_size.unwrap_or(Params::DEFAULT_OUTPUT_SIZE),
version: self.version,
}
}

Expand Down Expand Up @@ -439,17 +438,19 @@ impl PasswordHasher for Argon2<'_> {
.transpose()?
.unwrap_or_default();

let version = version
.map(Version::try_from)
.transpose()?
.unwrap_or_default();

let salt = salt.into();

let mut hasher = Self::new(
self.secret,
params.t_cost,
params.m_cost,
params.p_cost,
version
.map(Version::try_from)
.transpose()?
.unwrap_or_else(|| params.version),
version,
)?;

// TODO(tarcieri): pass these via `Params` when `Argon::new` accepts `Params`
Expand Down Expand Up @@ -477,7 +478,7 @@ impl<'key> TryFrom<&Params> for Argon2<'key> {
params.t_cost,
params.m_cost,
params.p_cost,
params.version,
Version::default(),
)?;

argon2.output_size = Some(params.output_size);
Expand Down
22 changes: 1 addition & 21 deletions argon2/src/params.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
//! Argon2 password hash parameters.

use crate::Version;

#[cfg(feature = "password-hash")]
use {
core::convert::{TryFrom, TryInto},
core::convert::TryFrom,
password_hash::{ParamsString, PasswordHash},
};

Expand All @@ -31,10 +29,6 @@ pub struct Params {

/// Size of the output (in bytes).
pub output_size: usize,

/// Algorithm version.
// TODO(tarcieri): make this separate from params in the next breaking release?
pub version: Version,
}

impl Params {
Expand All @@ -58,7 +52,6 @@ impl Default for Params {
t_cost: Self::DEFAULT_T_COST,
p_cost: Self::DEFAULT_P_COST,
output_size: Self::DEFAULT_OUTPUT_SIZE,
version: Version::default(),
}
}
}
Expand All @@ -82,12 +75,6 @@ impl<'a> TryFrom<&'a PasswordHash<'a>> for Params {
}
}

if let Some(version) = hash.version {
params.version = version
.try_into()
.map_err(|_| password_hash::Error::Version)?;
}

if let Some(output) = &hash.hash {
params.output_size = output.len();
}
Expand Down Expand Up @@ -148,13 +135,6 @@ impl ParamsBuilder {
self
}

/// Set algorithm version.
// TODO(tarcieri): make this separate from params in the next breaking release?
pub fn version(mut self, version: Version) -> Self {
self.params.version = version;
self
}

/// Get the finished [`Params`].
pub fn params(self) -> Params {
self.params
Expand Down