|
3 | 3 | //! |
4 | 4 | //! # Examples |
5 | 5 | //! |
6 | | -//! PBKDF2 is defined in terms of a keyed pseudo-random function (PRF). Most |
7 | | -//! commonly HMAC is used as this PRF. In such cases you can use [`pbkdf2_hmac`] |
8 | | -//! and [`pbkdf2_hmac_array`] functions. The former accepts a byte slice which |
9 | | -//! gets filled with generated key, while the latter returns an array with |
10 | | -//! generated key of requested length. |
| 6 | +//! PBKDF2 is defined in terms of a keyed pseudo-random function (PRF). |
| 7 | +//! The most commonly used PRF for this purpose is HMAC. In such cases |
| 8 | +//! you can use [`pbkdf2_hmac`] and [`pbkdf2_hmac_array`] functions. |
| 9 | +//! The former accepts a byte slice which gets filled with generated key, |
| 10 | +//! while the latter returns an array with generated key of requested length. |
| 11 | +//! |
| 12 | +//! Note that it is not recommended to generate keys using PBKDF2 that exceed |
| 13 | +//! the output size of the PRF (equal to the hash size in the case of HMAC). |
| 14 | +//! If you need to generate a large amount of cryptographic material, |
| 15 | +//! consider using a separate [key derivation function][KDF]. |
| 16 | +//! |
| 17 | +//! [KDF]: https://github.com/RustCrypto/KDFs |
11 | 18 | //! |
12 | 19 | //! ``` |
13 | 20 | //! # #[cfg(feature = "hmac")] { |
@@ -96,9 +103,6 @@ pub use hmac; |
96 | 103 | #[cfg(feature = "simple")] |
97 | 104 | pub use crate::simple::{Algorithm, Params, Pbkdf2}; |
98 | 105 |
|
99 | | -#[cfg(feature = "parallel")] |
100 | | -use rayon::prelude::*; |
101 | | - |
102 | 106 | use digest::{FixedOutput, InvalidLength, KeyInit, Update, typenum::Unsigned}; |
103 | 107 |
|
104 | 108 | #[cfg(feature = "hmac")] |
@@ -162,21 +166,10 @@ where |
162 | 166 | PRF: KeyInit + Update + FixedOutput + Clone + Sync, |
163 | 167 | { |
164 | 168 | let n = PRF::OutputSize::to_usize(); |
165 | | - // note: HMAC can be initialized with keys of any size, |
166 | | - // so this panic never happens with it |
167 | 169 | let prf = PRF::new_from_slice(password)?; |
168 | 170 |
|
169 | | - #[cfg(not(feature = "parallel"))] |
170 | | - { |
171 | | - for (i, chunk) in res.chunks_mut(n).enumerate() { |
172 | | - pbkdf2_body(i as u32, chunk, &prf, salt, rounds); |
173 | | - } |
174 | | - } |
175 | | - #[cfg(feature = "parallel")] |
176 | | - { |
177 | | - res.par_chunks_mut(n).enumerate().for_each(|(i, chunk)| { |
178 | | - pbkdf2_body(i as u32, chunk, &prf, salt, rounds); |
179 | | - }); |
| 171 | + for (i, chunk) in res.chunks_mut(n).enumerate() { |
| 172 | + pbkdf2_body(i as u32, chunk, &prf, salt, rounds); |
180 | 173 | } |
181 | 174 |
|
182 | 175 | Ok(()) |
|
0 commit comments