summaryrefslogtreecommitdiffstats
path: root/openpgp/src/crypto/backend/rust/kdf.rs
blob: ac98a49640f0d303a2369e9630325af8d70ca846 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use hkdf::Hkdf;
use sha2::Sha256;

use crate::{
    Result,
    crypto::{
        SessionKey,
        backend::interface::Kdf,
    },
};

impl Kdf for super::Backend {
    fn hkdf_sha256(ikm: &SessionKey, salt: Option<&[u8]>, info: &[u8],
                   okm: &mut SessionKey)
                   -> Result<()>
    {
        Ok(Hkdf::<Sha256>::new(salt, &ikm).expand(info, okm)
           .map_err(|e| crate::Error::InvalidOperation(e.to_string()))?)
    }
}