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
1 change: 1 addition & 0 deletions .github/workflows/pbkdf2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions pbkdf2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions pbkdf2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down
11 changes: 0 additions & 11 deletions pbkdf2/benches/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Hmac<sha1::Sha1>>(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";
Expand Down
18 changes: 0 additions & 18 deletions pbkdf2/src/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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";
Expand All @@ -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);
Expand All @@ -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")]
Expand Down Expand Up @@ -109,8 +95,6 @@ impl FromStr for Algorithm {
impl From<Algorithm> 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,
}
Expand All @@ -123,8 +107,6 @@ impl<'a> TryFrom<&'a str> for Algorithm {

fn try_from(name: &'a str) -> password_hash::Result<Algorithm> {
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")]
Expand Down
18 changes: 7 additions & 11 deletions pbkdf2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,19 @@ 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;
#[cfg(any(feature = "mcf", feature = "phc"))]
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;

Expand Down Expand Up @@ -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],
Expand All @@ -270,8 +268,6 @@ pub fn pbkdf2_hmac_with_params(
out: &mut [u8],
) {
let f = match algorithm {
#[cfg(feature = "sha1")]
Algorithm::Pbkdf2Sha1 => pbkdf2_hmac::<sha1::Sha1>,
#[cfg(feature = "sha2")]
Algorithm::Pbkdf2Sha256 => pbkdf2_hmac::<sha2::Sha256>,
#[cfg(feature = "sha2")]
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -320,7 +316,7 @@ impl Pbkdf2 {
}
}

#[cfg(any(feature = "sha1", feature = "sha2"))]
#[cfg(feature = "sha2")]
impl From<Algorithm> for Pbkdf2 {
fn from(algorithm: Algorithm) -> Self {
Self {
Expand Down
1 change: 1 addition & 0 deletions pbkdf2/tests/pbkdf2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg(feature = "hmac")]

use belt_hash::BeltHash;
use hex_literal::hex;
use sha1::Sha1;
Expand Down
Loading