use crate::{Crypto, CryptoError, HpkeKdfId, IkmRef, Okm, Prk, PrkRef};
const HPKE_VERSION: &[u8] = b"HPKE-v1";
pub fn labeled_extract<C: Crypto>(
crypto_backend: &C,
alg: HpkeKdfId,
suite_id: &[u8],
salt: &[u8],
label: &str,
ikm: IkmRef<'_>,
) -> Result<Prk, CryptoError> {
crypto_backend.kdf_extract_concated(
alg,
salt,
&[
IkmRef::from(HPKE_VERSION),
IkmRef::from(suite_id),
IkmRef::from(label.as_bytes()),
ikm,
],
)
}
pub fn labeled_expand<'a, C, PRK>(
crypto_backend: &C,
alg: HpkeKdfId,
suite_id: &[u8],
prk: PRK,
label: &'static str,
info: &[u8],
len: usize,
) -> Result<Okm, CryptoError>
where
C: Crypto,
PRK: Into<PrkRef<'a>>,
{
#[allow(
clippy::cast_possible_truncation,
reason = "`len` will not exceed u16::MAX in our use cases"
)]
crypto_backend.kdf_expand_multi_info(
alg,
prk.into(),
&[
&(len as u16).to_be_bytes(),
HPKE_VERSION,
suite_id,
label.as_bytes(),
info,
],
len,
)
}