summaryrefslogtreecommitdiffstats
path: root/openpgp/src/crypto/backend/openssl/kdf.rs
diff options
context:
space:
mode:
Diffstat (limited to 'openpgp/src/crypto/backend/openssl/kdf.rs')
-rw-r--r--openpgp/src/crypto/backend/openssl/kdf.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/openpgp/src/crypto/backend/openssl/kdf.rs b/openpgp/src/crypto/backend/openssl/kdf.rs
new file mode 100644
index 00000000..11c48667
--- /dev/null
+++ b/openpgp/src/crypto/backend/openssl/kdf.rs
@@ -0,0 +1,31 @@
+use openssl::{
+ md::Md,
+ pkey::Id,
+ pkey_ctx::PkeyCtx,
+};
+
+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<()>
+ {
+ let mut pkey = PkeyCtx::new_id(Id::HKDF)?;
+ pkey.derive_init()?;
+ pkey.set_hkdf_md(Md::sha256())?;
+ pkey.set_hkdf_key(&ikm)?;
+ if let Some(salt) = salt {
+ pkey.set_hkdf_salt(salt)?;
+ }
+ pkey.add_hkdf_info(info)?;
+ pkey.derive(Some(okm))?;
+ Ok(())
+ }
+}