summaryrefslogtreecommitdiffstats
path: root/openpgp/src/crypto/backend/nettle/kdf.rs
blob: a016a3a3fcb614ad507cd016002ee30ad40fb5c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use nettle::{
    kdf::hkdf,
    hash::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<()>
    {
        assert!(okm.len() <= 255 * 32);
        const NO_SALT: [u8; 32] = [0; 32];
        let salt = salt.unwrap_or(&NO_SALT);
        hkdf::<Sha256>(&ikm[..], salt, info, okm);
        Ok(())
    }
}