File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -128,6 +128,7 @@ pub mod error;
128
128
pub mod ex_data;
129
129
pub mod fips;
130
130
pub mod hash;
131
+ pub mod hpke;
131
132
pub mod memcmp;
132
133
pub mod nid;
133
134
pub mod pkcs12;
You can’t perform that action at this time.
0 commit comments