diff --git a/.github/workflows/pbkdf2.yml b/.github/workflows/pbkdf2.yml index 7cf32d8e..c23359b2 100644 --- a/.github/workflows/pbkdf2.yml +++ b/.github/workflows/pbkdf2.yml @@ -63,4 +63,5 @@ jobs: - run: cargo test --no-default-features --features kdf - run: cargo test --no-default-features --features password-hash - run: cargo test --no-default-features --features rand_core + - run: cargo test --no-default-features --features sha2 - run: cargo test --all-features --release diff --git a/pbkdf2/CHANGELOG.md b/pbkdf2/CHANGELOG.md index d6cfb643..e275b3eb 100644 --- a/pbkdf2/CHANGELOG.md +++ b/pbkdf2/CHANGELOG.md @@ -8,8 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## 0.13.0 (UNRELEASED) ### Removed - The `parallel` crate feature ([#702]) +- `sha1` feature ([#853]) [#702]: https://github.com/RustCrypto/password-hashes/pull/702 +[#853]: https://github.com/RustCrypto/password-hashes/pull/835 ## 0.12.2 (2023-07-08) ### Fixed diff --git a/pbkdf2/Cargo.toml b/pbkdf2/Cargo.toml index d3bcb342..8358f5e9 100644 --- a/pbkdf2/Cargo.toml +++ b/pbkdf2/Cargo.toml @@ -21,7 +21,6 @@ hmac = { version = "0.13.0-rc.5", optional = true, default-features = false } kdf = { version = "0.1", optional = true } mcf = { version = "0.6", optional = true, default-features = false, features = ["base64"] } password-hash = { version = "0.6", default-features = false, optional = true } -sha1 = { version = "0.11.0-rc.5", default-features = false, optional = true } sha2 = { version = "0.11.0-rc.5", default-features = false, optional = true } [dev-dependencies] @@ -41,7 +40,6 @@ getrandom = ["password-hash/getrandom"] mcf = ["sha2", "password-hash", "dep:mcf"] phc = ["password-hash/phc", "sha2"] rand_core = ["password-hash/rand_core"] -sha1 = ["hmac", "dep:sha1"] sha2 = ["hmac", "dep:sha2"] [package.metadata.docs.rs] diff --git a/pbkdf2/benches/lib.rs b/pbkdf2/benches/lib.rs index 7b67c98e..3045029b 100644 --- a/pbkdf2/benches/lib.rs +++ b/pbkdf2/benches/lib.rs @@ -7,17 +7,6 @@ use hmac::Hmac; use pbkdf2::pbkdf2; use test::Bencher; -#[bench] -pub fn pbkdf2_hmac_sha1_16384_20(bh: &mut Bencher) { - let password = b"my secure password"; - let salt = b"salty salt"; - let mut buf = [0u8; 20]; - bh.iter(|| { - pbkdf2::>(password, salt, 16_384, &mut buf).unwrap(); - test::black_box(&buf); - }); -} - #[bench] pub fn pbkdf2_hmac_sha256_16384_20(bh: &mut Bencher) { let password = b"my secure password"; diff --git a/pbkdf2/src/algorithm.rs b/pbkdf2/src/algorithm.rs index 5c7b8880..1b26865f 100644 --- a/pbkdf2/src/algorithm.rs +++ b/pbkdf2/src/algorithm.rs @@ -11,10 +11,6 @@ use {core::str::FromStr, password_hash::Error}; #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] #[non_exhaustive] pub enum Algorithm { - /// PBKDF2-HMAC-SHA1 a.k.a. `$pbkdf2` - #[cfg(feature = "sha1")] - Pbkdf2Sha1, - /// PBKDF2-HMAC-SHA-256 a.k.a. `$pbkdf2-sha256` #[cfg(feature = "sha2")] Pbkdf2Sha256, @@ -25,10 +21,6 @@ pub enum Algorithm { } impl Algorithm { - /// PBKDF2 (SHA-1) algorithm identifier - #[cfg(feature = "sha1")] - pub const PBKDF2_SHA1_ID: &'static str = "pbkdf2"; - /// PBKDF2 (SHA-256) algorithm identifier #[cfg(feature = "sha2")] pub const PBKDF2_SHA256_ID: &'static str = "pbkdf2-sha256"; @@ -37,10 +29,6 @@ impl Algorithm { #[cfg(feature = "sha2")] pub const PBKDF2_SHA512_ID: &'static str = "pbkdf2-sha512"; - /// PBKDF2 (SHA-1) algorithm identifier - #[cfg(all(feature = "phc", feature = "sha1"))] - pub(crate) const PBKDF2_SHA1_IDENT: Ident = Ident::new_unwrap(Self::PBKDF2_SHA1_ID); - /// PBKDF2 (SHA-256) algorithm identifier #[cfg(feature = "phc")] pub(crate) const PBKDF2_SHA256_IDENT: Ident = Ident::new_unwrap(Self::PBKDF2_SHA256_ID); @@ -67,8 +55,6 @@ impl Algorithm { /// Get the Modular Crypt Format algorithm identifier for this algorithm. pub const fn to_str(self) -> &'static str { match self { - #[cfg(feature = "sha1")] - Algorithm::Pbkdf2Sha1 => Self::PBKDF2_SHA1_ID, #[cfg(feature = "sha2")] Algorithm::Pbkdf2Sha256 => Self::PBKDF2_SHA256_ID, #[cfg(feature = "sha2")] @@ -109,8 +95,6 @@ impl FromStr for Algorithm { impl From for Ident { fn from(alg: Algorithm) -> Ident { match alg { - #[cfg(feature = "sha1")] - Algorithm::Pbkdf2Sha1 => Algorithm::PBKDF2_SHA1_IDENT, Algorithm::Pbkdf2Sha256 => Algorithm::PBKDF2_SHA256_IDENT, Algorithm::Pbkdf2Sha512 => Algorithm::PBKDF2_SHA512_IDENT, } @@ -123,8 +107,6 @@ impl<'a> TryFrom<&'a str> for Algorithm { fn try_from(name: &'a str) -> password_hash::Result { match name { - #[cfg(feature = "sha1")] - Self::PBKDF2_SHA1_ID => Ok(Algorithm::Pbkdf2Sha1), #[cfg(feature = "sha2")] Self::PBKDF2_SHA256_ID => Ok(Algorithm::Pbkdf2Sha256), #[cfg(feature = "sha2")] diff --git a/pbkdf2/src/lib.rs b/pbkdf2/src/lib.rs index 272cf01c..3f011d96 100644 --- a/pbkdf2/src/lib.rs +++ b/pbkdf2/src/lib.rs @@ -86,12 +86,12 @@ pub mod mcf; #[cfg(feature = "phc")] pub mod phc; -#[cfg(any(feature = "sha1", feature = "sha2"))] +#[cfg(feature = "sha2")] mod algorithm; -#[cfg(any(feature = "sha1", feature = "sha2"))] +#[cfg(feature = "sha2")] mod params; -#[cfg(any(feature = "sha1", feature = "sha2"))] +#[cfg(feature = "sha2")] pub use crate::{algorithm::Algorithm, params::Params}; #[cfg(feature = "hmac")] pub use hmac; @@ -99,8 +99,6 @@ pub use hmac; pub use password_hash; #[cfg(any(feature = "mcf", feature = "phc"))] pub use password_hash::{PasswordHasher, PasswordVerifier}; -#[cfg(feature = "sha1")] -pub use sha1; #[cfg(feature = "sha2")] pub use sha2; @@ -261,7 +259,7 @@ where /// pbkdf2_hmac_with_params(b"password", b"salt", algorithm, params, &mut buf); /// assert_eq!(buf, hex!("669cfe52482116fda1aa2cbe409b2f56c8e4563752b7a28f6eaab614ee005178")); /// ``` -#[cfg(any(feature = "sha1", feature = "sha2"))] +#[cfg(feature = "sha2")] pub fn pbkdf2_hmac_with_params( password: &[u8], salt: &[u8], @@ -270,8 +268,6 @@ pub fn pbkdf2_hmac_with_params( out: &mut [u8], ) { let f = match algorithm { - #[cfg(feature = "sha1")] - Algorithm::Pbkdf2Sha1 => pbkdf2_hmac::, #[cfg(feature = "sha2")] Algorithm::Pbkdf2Sha256 => pbkdf2_hmac::, #[cfg(feature = "sha2")] @@ -287,7 +283,7 @@ pub fn pbkdf2_hmac_with_params( /// Supports the following password hash string formats, gated under the following crate features: /// - `mcf`: support for the Modular Crypt Format /// - `phc`: support for the Password Hashing Competition string format -#[cfg(any(feature = "sha1", feature = "sha2"))] +#[cfg(feature = "sha2")] #[cfg_attr(feature = "sha2", derive(Default))] #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub struct Pbkdf2 { @@ -307,7 +303,7 @@ impl Pbkdf2 { pub const SHA512: Self = Self::new(Algorithm::Pbkdf2Sha512, Params::RECOMMENDED); } -#[cfg(any(feature = "sha1", feature = "sha2"))] +#[cfg(feature = "sha2")] impl Pbkdf2 { /// Initialize [`Pbkdf2`] with default parameters. pub const fn new(algorithm: Algorithm, params: Params) -> Self { @@ -320,7 +316,7 @@ impl Pbkdf2 { } } -#[cfg(any(feature = "sha1", feature = "sha2"))] +#[cfg(feature = "sha2")] impl From for Pbkdf2 { fn from(algorithm: Algorithm) -> Self { Self { diff --git a/pbkdf2/tests/pbkdf2.rs b/pbkdf2/tests/pbkdf2.rs index 84ea9a8e..bd81a2e3 100644 --- a/pbkdf2/tests/pbkdf2.rs +++ b/pbkdf2/tests/pbkdf2.rs @@ -1,4 +1,5 @@ #![cfg(feature = "hmac")] + use belt_hash::BeltHash; use hex_literal::hex; use sha1::Sha1;