summaryrefslogtreecommitdiffstats
path: root/openpgp/src/crypto/backend/nettle/kdf.rs
diff options
context:
space:
mode:
Diffstat (limited to 'openpgp/src/crypto/backend/nettle/kdf.rs')
-rw-r--r--openpgp/src/crypto/backend/nettle/kdf.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/openpgp/src/crypto/backend/nettle/kdf.rs b/openpgp/src/crypto/backend/nettle/kdf.rs
new file mode 100644
index 00000000..a016a3a3
--- /dev/null
+++ b/openpgp/src/crypto/backend/nettle/kdf.rs
@@ -0,0 +1,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(())
+ }
+}