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
2 changes: 1 addition & 1 deletion .github/workflows/argon2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
targets: ${{ matrix.target }}
- run: cargo build --target ${{ matrix.target }} --no-default-features
- run: cargo build --target ${{ matrix.target }} --no-default-features --features password-hash
- run: cargo build --target ${{ matrix.target }} --no-default-features --features simple
- run: cargo build --target ${{ matrix.target }} --no-default-features --features password-hash
- run: cargo build --target ${{ matrix.target }} --no-default-features --features zeroize

minimal-versions:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scrypt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
toolchain: ${{ matrix.rust }}
targets: ${{ matrix.target }}
- run: cargo build --target ${{ matrix.target }} --no-default-features
- run: cargo build --target ${{ matrix.target }} --no-default-features --features simple
- run: cargo build --target ${{ matrix.target }} --no-default-features --features password-hash

minimal-versions:
# disabled until belt-block gets published
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sha-crypt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
toolchain: ${{ matrix.rust }}
targets: ${{ matrix.target }}
- run: cargo build --target ${{ matrix.target }} --no-default-features
- run: cargo build --target ${{ matrix.target }} --no-default-features --features simple
- run: cargo build --target ${{ matrix.target }} --no-default-features --features password-hash

minimal-versions:
if: false # disabled while using pre-releases
Expand Down
2 changes: 1 addition & 1 deletion .readme/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ publish = false
[dependencies]
password-hash = "0.6.0-rc.3"
argon2 = { path = "../argon2" }
pbkdf2 = { path = "../pbkdf2", features = ["simple"] }
pbkdf2 = { path = "../pbkdf2", features = ["password-hash"] }
scrypt = { path = "../scrypt" }
9 changes: 2 additions & 7 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ opt-level = 2
argon2 = { path = "./argon2" }
pbkdf2 = { path = "./pbkdf2" }
scrypt = { path = "./scrypt" }

password-hash = { git = "https://github.com/RustCrypto/traits" }
8 changes: 4 additions & 4 deletions argon2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ blake2 = { version = "0.11.0-rc.3", default-features = false }
# optional dependencies
rayon = { version = "1.7", optional = true }
password-hash = { version = "0.6.0-rc.5", optional = true, features = ["phc"] }
phc = { version = "0.6.0-rc.0", optional = true, features = ["rand_core"] }
zeroize = { version = "1", default-features = false, optional = true }

[target.'cfg(any(target_arch = "x86", target_arch = "x86_64"))'.dependencies]
Expand All @@ -33,12 +32,13 @@ cpufeatures = "0.2.17"
hex-literal = "1"

[features]
default = ["alloc", "getrandom", "simple"]
default = ["alloc", "getrandom", "password-hash"]
alloc = ["password-hash?/alloc"]

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

[lints.rust.unexpected_cfgs]
Expand Down
2 changes: 1 addition & 1 deletion argon2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ mod tests {
}

#[test]
fn hash_simple_retains_configured_params() {
fn password_hash_retains_configured_params() {
// Non-default but valid parameters
let t_cost = 4;
let m_cost = 2048;
Expand Down
4 changes: 2 additions & 2 deletions balloon-hash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ crypto-bigint = { version = "0.7.0-rc.9", default-features = false, features = [

# optional dependencies
password-hash = { version = "0.6.0-rc.5", optional = true, default-features = false, features = ["phc"] }
phc = { version = "0.6.0-rc.0", optional = true, features = ["rand_core"] }
rayon = { version = "1.7", optional = true }
zeroize = { version = "1", default-features = false, optional = true }

Expand All @@ -33,7 +32,8 @@ alloc = ["password-hash/alloc"]

getrandom = ["password-hash/getrandom"]
parallel = ["dep:rayon"]
password-hash = ["dep:password-hash", "dep:phc"]
password-hash = ["dep:password-hash"]
rand_core = ["password-hash/rand_core"]
zeroize = ["dep:zeroize"]

[package.metadata.docs.rs]
Expand Down
2 changes: 1 addition & 1 deletion balloon-hash/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use {
fmt::{self, Display},
str::FromStr,
},
phc::{ParamsString, PasswordHash},
password_hash::phc::{ParamsString, PasswordHash},
};

/// Balloon password hash parameters.
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 @@ -74,7 +74,7 @@ fn test_vectors() {

#[cfg(all(feature = "password-hash", feature = "alloc"))]
#[test]
fn hash_simple_retains_configured_params() {
fn password_hash_retains_configured_params() {
use balloon_hash::PasswordHasher;
use sha2::Sha256;

Expand Down
9 changes: 4 additions & 5 deletions password-auth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ rust-version = "1.85"

[dependencies]
getrandom = { version = "0.3", default-features = false }
password-hash = { version = "0.6.0-rc.5", features = ["alloc", "phc"] }
phc = { version = "0.6.0-rc.0", features = ["getrandom"] }
password-hash = { version = "0.6.0-rc.5", features = ["alloc", "getrandom", "phc"] }

# optional dependencies
argon2 = { version = "0.6.0-rc.4", optional = true, default-features = false, features = ["alloc", "simple"] }
pbkdf2 = { version = "0.13.0-rc.4", optional = true, default-features = false, features = ["simple"] }
scrypt = { version = "0.12.0-rc.5", optional = true, default-features = false, features = ["simple"] }
argon2 = { version = "0.6.0-rc.4", optional = true, default-features = false, features = ["alloc", "password-hash"] }
pbkdf2 = { version = "0.13.0-rc.4", optional = true, default-features = false, features = ["password-hash"] }
scrypt = { version = "0.12.0-rc.5", optional = true, default-features = false, features = ["password-hash"] }

[features]
default = ["argon2", "std"]
Expand Down
1 change: 1 addition & 0 deletions password-auth/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use alloc::string::ToString;
use core::fmt;
use password_hash::phc;

/// Password hash parse errors.
// This type has no public constructor and deliberately keeps `phc::Error` out of the public API
Expand Down
16 changes: 8 additions & 8 deletions password-auth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub use crate::errors::{ParseError, VerifyError};
use alloc::string::{String, ToString};
use password_hash::{
PasswordHasher, PasswordVerifier,
phc::{ParamsString, PasswordHash, Salt},
phc::{ParamsString, PasswordHash},
};

#[cfg(not(any(feature = "argon2", feature = "pbkdf2", feature = "scrypt")))]
Expand All @@ -48,26 +48,26 @@ use scrypt::Scrypt;
/// Uses the best available password hashing algorithm given the enabled
/// crate features (typically Argon2 unless explicitly disabled).
pub fn generate_hash(password: impl AsRef<[u8]>) -> String {
let salt = Salt::generate();
generate_phc_hash(password.as_ref(), &salt)
.map(|hash| hash.to_string())
generate_phc_hash(password.as_ref())
.as_ref()
.map(ToString::to_string)
.expect("password hashing error")
}

/// Generate a PHC hash using the preferred algorithm.
#[allow(unreachable_code)]
fn generate_phc_hash(password: &[u8], salt: &[u8]) -> password_hash::Result<PasswordHash> {
fn generate_phc_hash(password: &[u8]) -> password_hash::Result<PasswordHash> {
//
// Algorithms below are in order of preference
//
#[cfg(feature = "argon2")]
return Argon2::default().hash_password_with_salt(password, salt);
return Argon2::default().hash_password(password);

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

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

/// Verify the provided password against the provided password hash.
Expand Down
6 changes: 3 additions & 3 deletions pbkdf2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ digest = { version = "0.11.0-rc.4", features = ["mac"] }
# optional dependencies
hmac = { version = "0.13.0-rc.3", default-features = false, optional = true }
password-hash = { version = "0.6.0-rc.5", default-features = false, optional = true, features = ["phc"] }
phc = { version = "0.6.0-rc.0", optional = true, features = ["rand_core"] }
sha1 = { version = "0.11.0-rc.3", default-features = false, optional = true }
sha2 = { version = "0.11.0-rc.3", default-features = false, optional = true }

Expand All @@ -33,8 +32,9 @@ belt-hash = "0.2.0-rc.3"

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

[package.metadata.docs.rs]
all-features = true
18 changes: 9 additions & 9 deletions pbkdf2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@
//!
//! ```toml
//! [dependencies]
//! pbkdf2 = { version = "0.12", features = ["simple"] }
//! pbkdf2 = { version = "0.12", features = ["password-hash"] }
//! rand_core = { version = "0.6", features = ["std"] }
//! ```
//!
//! The following example demonstrates the high-level password hashing API:
//!
#![cfg_attr(feature = "simple", doc = "```")]
#![cfg_attr(not(feature = "simple"), doc = "```ignore")]
#![cfg_attr(feature = "password-hash", doc = "```")]
#![cfg_attr(not(feature = "password-hash"), doc = "```ignore")]
//! # fn main() -> Result<(), Box<dyn core::error::Error>> {
//! // NOTE: example requires `getrandom` feature is enabled
//!
Expand Down Expand Up @@ -83,20 +83,20 @@
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg"
)]

#[cfg(feature = "simple")]
#[cfg(feature = "password-hash")]
extern crate alloc;

#[cfg(feature = "simple")]
#[cfg(feature = "password-hash")]
pub use password_hash;

#[cfg(feature = "simple")]
mod simple;
#[cfg(feature = "password-hash")]
mod phc;

#[cfg(feature = "hmac")]
pub use hmac;

#[cfg(feature = "simple")]
pub use crate::simple::{Algorithm, Params, Pbkdf2};
#[cfg(feature = "password-hash")]
pub use crate::phc::{Algorithm, Params, Pbkdf2};

use digest::{FixedOutput, InvalidLength, KeyInit, Update, typenum::Unsigned};

Expand Down
6 changes: 4 additions & 2 deletions pbkdf2/src/simple.rs → pbkdf2/src/phc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ use core::{
fmt::{self, Display, Formatter},
str::FromStr,
};
use password_hash::{CustomizedPasswordHasher, Error, PasswordHasher, Result};
use phc::{Decimal, Ident, Output, ParamsString, PasswordHash, Salt};
use password_hash::{
CustomizedPasswordHasher, Error, PasswordHasher, Result,
phc::{Decimal, Ident, Output, ParamsString, PasswordHash, Salt},
};
use sha2::{Sha256, Sha512};

#[cfg(feature = "sha1")]
Expand Down
7 changes: 4 additions & 3 deletions pbkdf2/tests/simple.rs → pbkdf2/tests/phc.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Tests for `password-hash` crate integration.
//! Tests for `password-hash` crate integration with Password Hashing Competition (PHC) string
//! format as the password hash serialization.
//!
//! PBKDF2-SHA256 vectors adapted from: https://stackoverflow.com/a/5136918
//! PHC PBKDF2-SHA256 vectors adapted from: https://stackoverflow.com/a/5136918

#![cfg(feature = "simple")]
#![cfg(feature = "password-hash")]

use hex_literal::hex;
use pbkdf2::{Algorithm, Params, Pbkdf2, password_hash::CustomizedPasswordHasher};
Expand Down
8 changes: 4 additions & 4 deletions scrypt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ rayon = { version = "1.11", optional = true }

# optional dependencies
password-hash = { version = "0.6.0-rc.5", optional = true, default-features = false, features = ["phc"] }
phc = { version = "0.6.0-rc.0", optional = true, features = ["rand_core"] }

[features]
default = ["simple", "rayon"]
default = ["password-hash", "rayon"]
alloc = ["password-hash?/alloc"]

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

[package.metadata.docs.rs]
all-features = true
10 changes: 5 additions & 5 deletions scrypt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ pub mod errors;
mod params;
mod romix;

#[cfg(feature = "simple")]
mod simple;
#[cfg(feature = "password-hash")]
mod phc;

pub use crate::params::Params;

#[cfg(feature = "simple")]
#[cfg(feature = "password-hash")]
pub use password_hash;

#[cfg(feature = "simple")]
pub use crate::simple::{ALG_ID, Scrypt};
#[cfg(feature = "password-hash")]
pub use crate::phc::{ALG_ID, Scrypt};

/// The scrypt key derivation function.
///
Expand Down
Loading