polymorph_webcrypto_guest/pbkdf2_sha1.rs
1//! `pbkdf2-sha1` derivation parameterization: PBKDF2 over HMAC-SHA-1, for
2//! compatibility with existing password databases that fix it. The
3//! construction is not affected by SHA-1's collision attacks (PBKDF2
4//! relies on HMAC's PRF property), but prefer
5//! [`pbkdf2_sha2`](crate::pbkdf2_sha2) where the parameters are yours to
6//! choose.
7//!
8//! The [`Password`](crate::Password) resource and its import stay
9//! [`pbkdf2`](crate::pbkdf2)'s, so one imported password can parameterize
10//! derivations over either hash family.
11
12use crate::{bindings, DeriveInput, Error, Password};
13
14/// Parameterize a PBKDF2-HMAC-SHA-1 derivation over an imported password.
15/// See [`pbkdf2_sha2::prepare`](crate::pbkdf2_sha2::prepare) for the
16/// `salt` and `iterations` contracts.
17pub async fn prepare(
18 input: &Password,
19 salt: impl Into<Vec<u8>>,
20 iterations: u32,
21) -> Result<DeriveInput, Error> {
22 Ok(DeriveInput::from_raw(
23 bindings::pbkdf2_sha1::prepare(input.as_raw(), salt.into(), iterations).await?,
24 ))
25}