Skip to content

Commit 2561bdf

Browse files
rushilmehrakornelski
authored andcommitted
Expose EVP_HPKE_KEY
1 parent a613d4b commit 2561bdf

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

boring/src/hpke.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use crate::error::ErrorStack;
2+
use crate::{cvt_0i, cvt_p, ffi};
3+
4+
use foreign_types::ForeignType;
5+
6+
foreign_type_and_impl_send_sync! {
7+
type CType = ffi::EVP_HPKE_KEY;
8+
fn drop = ffi::EVP_HPKE_KEY_free;
9+
10+
pub struct HpkeKey;
11+
}
12+
13+
impl HpkeKey {
14+
/// Allocates and initializes a key with the `EVP_HPKE_KEY` type using the
15+
/// `EVP_hpke_x25519_hkdf_sha256` KEM algorithm.
16+
pub fn dhkem_p256_sha256(pkey: &[u8]) -> Result<HpkeKey, ErrorStack> {
17+
unsafe {
18+
ffi::init();
19+
let hpke = cvt_p(ffi::EVP_HPKE_KEY_new()).map(|p| HpkeKey::from_ptr(p))?;
20+
21+
cvt_0i(ffi::EVP_HPKE_KEY_init(
22+
hpke.as_ptr(),
23+
ffi::EVP_hpke_x25519_hkdf_sha256(),
24+
pkey.as_ptr(),
25+
pkey.len(),
26+
))?;
27+
28+
Ok(hpke)
29+
}
30+
}
31+
}

boring/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ pub mod error;
128128
pub mod ex_data;
129129
pub mod fips;
130130
pub mod hash;
131+
pub mod hpke;
131132
pub mod memcmp;
132133
pub mod nid;
133134
pub mod pkcs12;

0 commit comments

Comments
 (0)