diff --git a/Cargo.lock b/Cargo.lock index fe3065e0..21157be4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -328,7 +328,6 @@ dependencies = [ "hex-literal", "hmac", "password-hash", - "rayon", "sha1", "sha2", "streebog", @@ -518,9 +517,18 @@ checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" [[package]] name = "wasi" -version = "0.14.4+wasi-0.2.4" +version = "0.14.5+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4494f6290a82f5fe584817a676a34b9d6763e8d9d18204009fb31dceca98fd4" +dependencies = [ + "wasip2", +] + +[[package]] +name = "wasip2" +version = "1.0.0+wasi-0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88a5f4a424faf49c3c2c344f166f0662341d470ea185e939657aaff130f0ec4a" +checksum = "03fa2761397e5bd52002cd7e73110c71af2109aca4e521a9f40473fe685b0a24" dependencies = [ "wit-bindgen", ] diff --git a/pbkdf2/CHANGELOG.md b/pbkdf2/CHANGELOG.md index 179287cd..d6cfb643 100644 --- a/pbkdf2/CHANGELOG.md +++ b/pbkdf2/CHANGELOG.md @@ -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]) diff --git a/pbkdf2/Cargo.toml b/pbkdf2/Cargo.toml index 230a802d..7da80e40 100644 --- a/pbkdf2/Cargo.toml +++ b/pbkdf2/Cargo.toml @@ -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 } @@ -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] diff --git a/pbkdf2/src/lib.rs b/pbkdf2/src/lib.rs index 6550061a..65c864d7 100644 --- a/pbkdf2/src/lib.rs +++ b/pbkdf2/src/lib.rs @@ -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")] { @@ -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")] @@ -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(())