polymorph_webcrypto_guest/hkdf_sha1.rs
1//! `hkdf-sha1` derivation parameterization: HKDF over SHA-1, for
2//! compatibility with existing protocols that fix it. The construction is
3//! not affected by SHA-1's collision attacks (HKDF relies on HMAC's PRF
4//! property), but prefer [`hkdf_sha2`](crate::hkdf_sha2) where the
5//! protocol is yours to choose.
6//!
7//! The [`Ikm`](crate::Ikm) resource and its import stay
8//! [`hkdf`](crate::hkdf)'s, so one imported secret can parameterize
9//! derivations over either hash family.
10
11use crate::{bindings, DeriveInput, Error, Ikm};
12
13/// Parameterize an HKDF-SHA-1 derivation over imported keying material.
14/// See [`hkdf_sha2::prepare`](crate::hkdf_sha2::prepare) for the `salt`
15/// and `info` contracts.
16pub async fn prepare(
17 input: &Ikm,
18 salt: impl Into<Vec<u8>>,
19 info: impl Into<Vec<u8>>,
20) -> Result<DeriveInput, Error> {
21 Ok(DeriveInput::from_raw(
22 bindings::hkdf_sha1::prepare(input.as_raw(), salt.into(), info.into()).await?,
23 ))
24}
25
26/// Chain an HKDF-SHA-1 derivation from another derivation's output. See
27/// [`hkdf_sha2::prepare_from`](crate::hkdf_sha2::prepare_from).
28pub async fn prepare_from(
29 input: &DeriveInput,
30 salt: impl Into<Vec<u8>>,
31 info: impl Into<Vec<u8>>,
32) -> Result<DeriveInput, Error> {
33 Ok(DeriveInput::from_raw(
34 bindings::hkdf_sha1::prepare_from(input.as_raw(), salt.into(), info.into()).await?,
35 ))
36}