WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
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
3 changes: 2 additions & 1 deletion 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 argon2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ hex-literal = "1"
default = ["alloc", "getrandom", "simple"]
alloc = ["password-hash?/alloc"]

getrandom = ["simple", "phc/getrandom"]
getrandom = ["simple", "password-hash/getrandom"]
parallel = ["dep:rayon"]
simple = ["password-hash", "phc"]
zeroize = ["dep:zeroize"]
Expand Down
34 changes: 18 additions & 16 deletions argon2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@
#![cfg_attr(all(feature = "alloc", feature = "getrandom"), doc = "```")]
#![cfg_attr(not(all(feature = "alloc", feature = "getrandom")), doc = "```ignore")]
//! # fn main() -> Result<(), Box<dyn core::error::Error>> {
//! // NOTE: example requires `getrandom` feature is enabled
//!
//! use argon2::{
//! password_hash::{PasswordHash, PasswordHasher, PasswordVerifier, phc::Salt},
//! password_hash::{PasswordHasher, PasswordVerifier, phc::PasswordHash},
//! Argon2
//! };
//!
//! let password = b"hunter42"; // Bad password; don't actually use!
//! let salt = Salt::generate(); // Note: needs the `getrandom` feature of `argon2` enabled
//!
//! // Argon2 with default params (Argon2id v19)
//! // Argon2 with default params (Argon2id v19), generating a random salt
//! let argon2 = Argon2::default();
//!
//! // Hash password to PHC string ($argon2id$v=19$...)
//! let password_hash = argon2.hash_password(password, &salt)?.to_string();
//! let password_hash = argon2.hash_password(password)?.to_string();
//!
//! // Verify password against PHC string.
//! //
Expand All @@ -66,28 +67,25 @@
#![cfg_attr(all(feature = "alloc", feature = "getrandom"), doc = "```")]
#![cfg_attr(not(all(feature = "alloc", feature = "getrandom")), doc = "```ignore")]
//! # fn main() -> Result<(), Box<dyn core::error::Error>> {
//! // NOTE: example requires `getrandom` feature is enabled
//!
//! use argon2::{
//! password_hash::{
//! phc::{PasswordHash, Salt},
//! PasswordHasher, PasswordVerifier,
//! },
//! password_hash::{PasswordHasher, PasswordVerifier, phc::PasswordHash},
//! Algorithm, Argon2, Params, Version
//! };
//!
//! let password = b"hunter42"; // Bad password; don't actually use!
//! let salt = Salt::generate(); // Note: needs the `getrandom` feature of `argon2` enabled
//!
//! // Argon2 with default params (Argon2id v19) and pepper
//! let argon2 = Argon2::new_with_secret(
//! b"secret pepper",
//! Algorithm::default(),
//! Version::default(),
//! Params::default()
//! )
//! .unwrap();
//! )?;
//!
//! // Hash password to PHC string ($argon2id$v=19$...)
//! let password_hash = argon2.hash_password(password, &salt)?.to_string();
//! // Hash password to PHC string ($argon2id$v=19$...), generating a random salt
//! let password_hash = argon2.hash_password(password)?.to_string();
//!
//! // Verify password against PHC string.
//! //
Expand Down Expand Up @@ -640,13 +638,17 @@ impl CustomizedPasswordHasher<PasswordHash> for Argon2<'_> {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
cpu_feat_avx2: self.cpu_feat_avx2,
}
.hash_password(password, salt)
.hash_password_with_salt(password, salt)
}
}

#[cfg(all(feature = "alloc", feature = "password-hash"))]
impl PasswordHasher<PasswordHash> for Argon2<'_> {
fn hash_password(&self, password: &[u8], salt: &[u8]) -> password_hash::Result<PasswordHash> {
fn hash_password_with_salt(
&self,
password: &[u8],
salt: &[u8],
) -> password_hash::Result<PasswordHash> {
let salt = Salt::new(salt).map_err(|_| password_hash::Error::SaltInvalid)?;

let output_len = self
Expand Down Expand Up @@ -719,7 +721,7 @@ mod tests {
let params = Params::new(m_cost, t_cost, p_cost, None).unwrap();
let hasher = Argon2::new(Algorithm::default(), version, params);
let hash = hasher
.hash_password(EXAMPLE_PASSWORD, EXAMPLE_SALT)
.hash_password_with_salt(EXAMPLE_PASSWORD, EXAMPLE_SALT)
.unwrap();

assert_eq!(hash.version.unwrap(), version.into());
Expand Down
2 changes: 1 addition & 1 deletion argon2/tests/kat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ fn hashtest(
assert_eq!(out, expected_raw_hash);

// Test hash encoding
let phc_hash = ctx.hash_password(pwd, salt).unwrap().to_string();
let phc_hash = ctx.hash_password_with_salt(pwd, salt).unwrap().to_string();
assert_eq!(phc_hash, expected_phc_hash);

let hash = PasswordHash::new(alternative_phc_hash).unwrap();
Expand Down
5 changes: 4 additions & 1 deletion argon2/tests/phc_strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ fn check_hash_encoding_parameters_order() {

let password = b"password";
let salt = [0u8; 8];
let password_hash = ctx.hash_password(password, &salt).unwrap().to_string();
let password_hash = ctx
.hash_password_with_salt(password, &salt)
.unwrap()
.to_string();

// The parameters shall appear in the m,t,p,keyid,data order
assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion balloon-hash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sha2 = "0.11.0-rc.3"
default = ["alloc", "getrandom", "password-hash"]
alloc = ["password-hash/alloc"]

getrandom = ["phc/getrandom"]
getrandom = ["password-hash/getrandom"]
parallel = ["dep:rayon"]
password-hash = ["dep:password-hash", "dep:phc"]
zeroize = ["dep:zeroize"]
Expand Down
36 changes: 12 additions & 24 deletions balloon-hash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,26 @@

//! # Usage (simple with default params)
//!
//! Note: this example requires the `rand_core` crate with the `std` feature
//! enabled for `rand_core::OsRng` (embedded platforms can substitute their
//! own RNG)
//!
//! Add the following to your crate's `Cargo.toml` to import it:
//!
//! ```toml
//! [dependencies]
//! balloon-hash = "0.2"
//! rand_core = { version = "0.6", features = ["std"] }
//! sha2 = "0.9"
//! ```
//!
//! The `zeroize` crate feature will zeroize allocated memory created when
//! using the [`Balloon::hash`] function. It will do nothing when the `alloc`
//! crate feature is not active.
//!
//! The following example demonstrates the high-level password hashing API:
//!
#![cfg_attr(feature = "getrandom", doc = "```")]
#![cfg_attr(not(feature = "getrandom"), doc = "```ignore")]
#![cfg_attr(all(feature = "alloc", feature = "getrandom"), doc = "```")]
#![cfg_attr(not(all(feature = "alloc", feature = "getrandom")), doc = "```ignore")]
//! # fn main() -> Result<(), Box<dyn core::error::Error>> {
//! // NOTE: example requires `getrandom` feature is enabled
//!
//! use balloon_hash::{
//! password_hash::{PasswordHash, PasswordHasher, PasswordVerifier, phc::Salt},
//! password_hash::{PasswordHasher, PasswordVerifier, phc::PasswordHash},
//! Balloon
//! };
//! use sha2::Sha256;
//!
//! let password = b"hunter42"; // Bad password; don't actually use!
//! let salt = Salt::generate(); // Note: needs the `getrandom` feature of `balloon-hash` enabled
//!
//! // Balloon with default params
//! let balloon = Balloon::<Sha256>::default();
//!
//! // Hash password to PHC string ($balloon$v=1$...)
//! let password_hash = balloon.hash_password(password, &salt)?.to_string();
//! let password_hash = balloon.hash_password(password)?.to_string();
//!
//! // Verify password against PHC string
//! let parsed_hash = PasswordHash::new(&password_hash)?;
Expand Down Expand Up @@ -235,7 +219,7 @@ where
}
}

Self::new(algorithm, params, self.secret).hash_password(password, salt)
Self::new(algorithm, params, self.secret).hash_password_with_salt(password, salt)
}
}

Expand All @@ -245,7 +229,11 @@ where
D: Digest + FixedOutputReset,
Array<u8, D::OutputSize>: ArrayDecoding,
{
fn hash_password(&self, password: &[u8], salt: &[u8]) -> password_hash::Result<PasswordHash> {
fn hash_password_with_salt(
&self,
password: &[u8],
salt: &[u8],
) -> password_hash::Result<PasswordHash> {
let salt = Salt::new(salt).map_err(|_| password_hash::Error::SaltInvalid)?;
let hash = self.hash(password, &salt)?;
let output = Output::new(&hash).map_err(|_| password_hash::Error::OutputSize)?;
Expand Down
2 changes: 1 addition & 1 deletion balloon-hash/tests/balloon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn hash_simple_retains_configured_params() {
let params = Params::new(s_cost, t_cost, p_cost).unwrap();
let hasher = Balloon::<Sha256>::new(Algorithm::default(), params, None);
let hash = hasher
.hash_password(EXAMPLE_PASSWORD, EXAMPLE_SALT)
.hash_password_with_salt(EXAMPLE_PASSWORD, EXAMPLE_SALT)
.unwrap();

assert_eq!(hash.version.unwrap(), 1);
Expand Down
6 changes: 3 additions & 3 deletions password-auth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ fn generate_phc_hash(password: &[u8], salt: &[u8]) -> password_hash::Result<Pass
// Algorithms below are in order of preference
//
#[cfg(feature = "argon2")]
return Argon2::default().hash_password(password, salt);
return Argon2::default().hash_password_with_salt(password, salt);

#[cfg(feature = "scrypt")]
return Scrypt.hash_password(password, salt);
return Scrypt.hash_password_with_salt(password, salt);

#[cfg(feature = "pbkdf2")]
return Pbkdf2.hash_password(password, salt);
return Pbkdf2.hash_password_with_salt(password, salt);
}

/// Verify the provided password against the provided password hash.
Expand Down
2 changes: 1 addition & 1 deletion pbkdf2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ belt-hash = "0.2.0-rc.3"

[features]
default = ["hmac"]
getrandom = ["simple", "phc/getrandom"]
getrandom = ["simple", "password-hash/getrandom"]
simple = ["hmac", "dep:password-hash", "dep:phc", "sha2"]

[package.metadata.docs.rs]
Expand Down
7 changes: 4 additions & 3 deletions pbkdf2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,17 @@
#![cfg_attr(feature = "simple", doc = "```")]
#![cfg_attr(not(feature = "simple"), doc = "```ignore")]
//! # fn main() -> Result<(), Box<dyn core::error::Error>> {
//! // NOTE: example requires `getrandom` feature is enabled
//!
//! use pbkdf2::{
//! password_hash::{PasswordHash, PasswordHasher, PasswordVerifier, phc::Salt},
//! password_hash::{PasswordHasher, PasswordVerifier, phc::PasswordHash},
//! Pbkdf2
//! };
//!
//! let password = b"hunter42"; // Bad password; don't actually use!
//! let salt = Salt::generate();
//!
//! // Hash password to PHC string ($pbkdf2-sha256$...)
//! let password_hash = Pbkdf2.hash_password(password, &salt)?.to_string();
//! let password_hash = Pbkdf2.hash_password(password)?.to_string();
//!
//! // Verify password against PHC string
//! let parsed_hash = PasswordHash::new(&password_hash)?;
Expand Down
2 changes: 1 addition & 1 deletion pbkdf2/src/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl CustomizedPasswordHasher<PasswordHash> for Pbkdf2 {
}

impl PasswordHasher<PasswordHash> for Pbkdf2 {
fn hash_password(&self, password: &[u8], salt: &[u8]) -> Result<PasswordHash> {
fn hash_password_with_salt(&self, password: &[u8], salt: &[u8]) -> Result<PasswordHash> {
self.hash_password_customized(password, salt, None, None, Params::default())
}
}
Expand Down
2 changes: 1 addition & 1 deletion scrypt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ phc = { version = "0.6.0-rc.0", optional = true, features = ["rand_core"] }
default = ["simple", "rayon"]
alloc = ["password-hash?/alloc"]

getrandom = ["simple", "phc/getrandom"]
getrandom = ["simple", "password-hash/getrandom"]
rayon = ["dep:rayon"]
simple = ["dep:password-hash", "dep:phc"]

Expand Down
5 changes: 3 additions & 2 deletions scrypt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#![cfg_attr(all(feature = "alloc", feature = "getrandom"), doc = "```")]
#![cfg_attr(not(all(feature = "alloc", feature = "getrandom")), doc = "```ignore")]
//! # fn main() -> Result<(), Box<dyn core::error::Error>> {
//! // NOTE: example requires `getrandom` feature is enabled
//!
//! use scrypt::{
//! password_hash::{
//! PasswordHasher, PasswordVerifier, phc::{PasswordHash, Salt}
Expand All @@ -23,10 +25,9 @@
//! };
//!
//! let password = b"hunter42"; // Bad password; don't actually use!
//! let salt = Salt::generate();
//!
//! // Hash password to PHC string ($scrypt$...)
//! let password_hash = Scrypt.hash_password(password, &salt)?.to_string();
//! let password_hash = Scrypt.hash_password(password)?.to_string();
//!
//! // Verify password against PHC string
//! let parsed_hash = PasswordHash::new(&password_hash)?;
Expand Down
2 changes: 1 addition & 1 deletion scrypt/src/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl CustomizedPasswordHasher<PasswordHash> for Scrypt {
}

impl PasswordHasher<PasswordHash> for Scrypt {
fn hash_password(&self, password: &[u8], salt: &[u8]) -> Result<PasswordHash> {
fn hash_password_with_salt(&self, password: &[u8], salt: &[u8]) -> Result<PasswordHash> {
self.hash_password_customized(password, salt, None, None, Params::default())
}
}
3 changes: 2 additions & 1 deletion yescrypt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ password-hash = { version = "0.6.0-rc.4", optional = true, default-features = fa
hex-literal = "1"

[features]
default = ["simple"]
default = ["getrandom"]
getrandom = ["simple", "password-hash/getrandom"]
simple = ["dep:mcf", "dep:password-hash"]

[package.metadata.docs.rs]
Expand Down
10 changes: 5 additions & 5 deletions yescrypt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@

//! # Usage
//! ## Password Hashing
//! NOTE: the `simple` crate feature must be enabled (on-by-default)
#![cfg_attr(feature = "simple", doc = "```")]
#![cfg_attr(not(feature = "simple"), doc = "```ignore")]
#![cfg_attr(feature = "getrandom", doc = "```")]
#![cfg_attr(not(feature = "getrandom"), doc = "```ignore")]
//! # fn main() -> yescrypt::password_hash::Result<()> {
//! // NOTE: example requires `getrandom` feature is enabled
//!
//! use yescrypt::{Yescrypt, PasswordHasher, PasswordVerifier};
//!
//! let password = b"pleaseletmein"; // don't actually use this as a password!
//! let salt = b"WZaPV7LSUEKMo34."; // unique per password, ideally 16-bytes and random
//! let password_hash = Yescrypt.hash_password(password, salt)?;
//! let password_hash = Yescrypt.hash_password(password)?;
//! assert!(password_hash.as_str().starts_with("$y$"));
//!
//! // verify password is correct for the given hash
Expand Down
2 changes: 1 addition & 1 deletion yescrypt/src/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl CustomizedPasswordHasher<PasswordHash> for Yescrypt {
}

impl PasswordHasher<PasswordHash> for Yescrypt {
fn hash_password(&self, password: &[u8], salt: &[u8]) -> Result<PasswordHash> {
fn hash_password_with_salt(&self, password: &[u8], salt: &[u8]) -> Result<PasswordHash> {
self.hash_password_customized(password, salt, None, None, Params::default())
}
}
Expand Down