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
14 changes: 11 additions & 3 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions pbkdf2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.13.0 (UNRELEASED)
### Removed
- The `parallel` crate feature ([#702])

[#702]: https://github.com/RustCrypto/password-hashes/pull/702

## 0.12.2 (2023-07-08)
### Fixed
- Use `RECOMMENDED_ROUNDS` in `Default` impl for `Params` ([#442])
Expand Down
3 changes: 0 additions & 3 deletions pbkdf2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ rust-version = "1.85"
digest = { version = "0.11.0-rc.1", features = ["mac"] }

# optional dependencies
rayon = { version = "1.7", optional = true }
password-hash = { version = "0.6.0-rc.0", default-features = false, optional = true, features = ["rand_core"] }
hmac = { version = "0.13.0-rc.1", default-features = false, optional = true }
sha1 = { version = "0.11.0-rc.2", default-features = false, optional = true }
Expand All @@ -34,8 +33,6 @@ belt-hash = "0.2.0-rc.1"
[features]
default = ["hmac"]
std = ["password-hash/os_rng"]

parallel = ["rayon", "std"]
simple = ["hmac", "password-hash", "sha2"]

[package.metadata.docs.rs]
Expand Down
35 changes: 14 additions & 21 deletions pbkdf2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
//!
//! # Examples
//!
//! PBKDF2 is defined in terms of a keyed pseudo-random function (PRF). Most
//! commonly HMAC is used as this PRF. In such cases you can use [`pbkdf2_hmac`]
//! and [`pbkdf2_hmac_array`] functions. The former accepts a byte slice which
//! gets filled with generated key, while the latter returns an array with
//! generated key of requested length.
//! PBKDF2 is defined in terms of a keyed pseudo-random function (PRF).
//! The most commonly used PRF for this purpose is HMAC. In such cases
//! you can use [`pbkdf2_hmac`] and [`pbkdf2_hmac_array`] functions.
//! The former accepts a byte slice which gets filled with generated key,
//! while the latter returns an array with generated key of requested length.
//!
//! Note that it is not recommended to generate keys using PBKDF2 that exceed
//! the output size of the PRF (equal to the hash size in the case of HMAC).
//! If you need to generate a large amount of cryptographic material,
//! consider using a separate [key derivation function][KDF].
//!
//! [KDF]: https://github.com/RustCrypto/KDFs
//!
//! ```
//! # #[cfg(feature = "hmac")] {
Expand Down Expand Up @@ -96,9 +103,6 @@ pub use hmac;
#[cfg(feature = "simple")]
pub use crate::simple::{Algorithm, Params, Pbkdf2};

#[cfg(feature = "parallel")]
use rayon::prelude::*;

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

#[cfg(feature = "hmac")]
Expand Down Expand Up @@ -162,21 +166,10 @@ where
PRF: KeyInit + Update + FixedOutput + Clone + Sync,
{
let n = PRF::OutputSize::to_usize();
// note: HMAC can be initialized with keys of any size,
// so this panic never happens with it
let prf = PRF::new_from_slice(password)?;

#[cfg(not(feature = "parallel"))]
{
for (i, chunk) in res.chunks_mut(n).enumerate() {
pbkdf2_body(i as u32, chunk, &prf, salt, rounds);
}
}
#[cfg(feature = "parallel")]
{
res.par_chunks_mut(n).enumerate().for_each(|(i, chunk)| {
pbkdf2_body(i as u32, chunk, &prf, salt, rounds);
});
for (i, chunk) in res.chunks_mut(n).enumerate() {
pbkdf2_body(i as u32, chunk, &prf, salt, rounds);
}

Ok(())
Expand Down