Skip to content

Commit 4a66f7e

Browse files
authored
Merge pull request sfackler#2453 from huwcbjones/huw/sys/params
sys: add symbols to construct an EVP_PKEY from a param builder
2 parents 2d20b57 + fc11cbf commit 4a66f7e

File tree

5 files changed

+75
-10
lines changed

5 files changed

+75
-10
lines changed

openssl-sys/build/run_bindgen.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ const INCLUDES: &str = "
5959
6060
#if OPENSSL_VERSION_NUMBER >= 0x30000000
6161
#include <openssl/provider.h>
62+
#include <openssl/params.h>
63+
#include <openssl/param_build.h>
6264
#endif
6365
6466
#if OPENSSL_VERSION_NUMBER >= 0x30200000

openssl-sys/src/evp.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ pub const EVP_CTRL_GCM_SET_IVLEN: c_int = 0x9;
3838
pub const EVP_CTRL_GCM_GET_TAG: c_int = 0x10;
3939
pub const EVP_CTRL_GCM_SET_TAG: c_int = 0x11;
4040

41-
#[cfg(ossl300)]
42-
pub const EVP_PKEY_KEY_PARAMETERS: c_int = OSSL_KEYMGMT_SELECT_ALL_PARAMETERS;
43-
#[cfg(ossl300)]
44-
pub const EVP_PKEY_PRIVATE_KEY: c_int = EVP_PKEY_KEY_PARAMETERS | OSSL_KEYMGMT_SELECT_PRIVATE_KEY;
45-
#[cfg(ossl300)]
46-
pub const EVP_PKEY_PUBLIC_KEY: c_int = EVP_PKEY_KEY_PARAMETERS | OSSL_KEYMGMT_SELECT_PUBLIC_KEY;
47-
#[cfg(ossl300)]
48-
pub const EVP_PKEY_KEYPAIR: c_int = EVP_PKEY_PUBLIC_KEY | OSSL_KEYMGMT_SELECT_PRIVATE_KEY;
41+
cfg_if! {
42+
if #[cfg(ossl300)] {
43+
pub const EVP_PKEY_KEY_PARAMETERS: c_int = OSSL_KEYMGMT_SELECT_ALL_PARAMETERS;
44+
pub const EVP_PKEY_PRIVATE_KEY: c_int = EVP_PKEY_KEY_PARAMETERS | OSSL_KEYMGMT_SELECT_PRIVATE_KEY;
45+
pub const EVP_PKEY_PUBLIC_KEY: c_int = EVP_PKEY_KEY_PARAMETERS | OSSL_KEYMGMT_SELECT_PUBLIC_KEY;
46+
pub const EVP_PKEY_KEYPAIR: c_int = EVP_PKEY_PUBLIC_KEY | OSSL_KEYMGMT_SELECT_PRIVATE_KEY;
47+
}
48+
}
4949

5050
pub unsafe fn EVP_get_digestbynid(type_: c_int) -> *const EVP_MD {
5151
EVP_get_digestbyname(OBJ_nid2sn(type_))

openssl-sys/src/handwritten/params.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ use libc::*;
33

44
extern "C" {
55
pub fn OSSL_PARAM_free(p: *mut OSSL_PARAM);
6+
pub fn OSSL_PARAM_dup(params: *const OSSL_PARAM) -> *mut OSSL_PARAM;
7+
pub fn OSSL_PARAM_merge(
8+
params: *const OSSL_PARAM,
9+
params1: *const OSSL_PARAM,
10+
) -> *mut OSSL_PARAM;
611
pub fn OSSL_PARAM_construct_uint(key: *const c_char, buf: *mut c_uint) -> OSSL_PARAM;
712
pub fn OSSL_PARAM_construct_end() -> OSSL_PARAM;
813
pub fn OSSL_PARAM_construct_octet_string(
@@ -12,6 +17,10 @@ extern "C" {
1217
) -> OSSL_PARAM;
1318

1419
pub fn OSSL_PARAM_locate(p: *mut OSSL_PARAM, key: *const c_char) -> *mut OSSL_PARAM;
20+
pub fn OSSL_PARAM_locate_const(
21+
params: *const OSSL_PARAM,
22+
key: *const c_char,
23+
) -> *const OSSL_PARAM;
1524
pub fn OSSL_PARAM_get_BN(p: *const OSSL_PARAM, val: *mut *mut BIGNUM) -> c_int;
1625
pub fn OSSL_PARAM_get_utf8_string(
1726
p: *const OSSL_PARAM,
@@ -30,4 +39,53 @@ extern "C" {
3039
val: *mut *const c_void,
3140
used_len: *mut usize,
3241
) -> c_int;
42+
43+
pub fn OSSL_PARAM_BLD_new() -> *mut OSSL_PARAM_BLD;
44+
pub fn OSSL_PARAM_BLD_free(bld: *mut OSSL_PARAM_BLD);
45+
pub fn OSSL_PARAM_BLD_to_param(bld: *mut OSSL_PARAM_BLD) -> *mut OSSL_PARAM;
46+
pub fn OSSL_PARAM_BLD_push_uint(
47+
bld: *mut OSSL_PARAM_BLD,
48+
key: *const c_char,
49+
val: c_uint,
50+
) -> c_int;
51+
pub fn OSSL_PARAM_BLD_push_size_t(
52+
bld: *mut OSSL_PARAM_BLD,
53+
key: *const c_char,
54+
val: size_t,
55+
) -> c_int;
56+
pub fn OSSL_PARAM_BLD_push_BN(
57+
bld: *mut OSSL_PARAM_BLD,
58+
key: *const c_char,
59+
bn: *const BIGNUM,
60+
) -> c_int;
61+
pub fn OSSL_PARAM_BLD_push_BN_pad(
62+
bld: *mut OSSL_PARAM_BLD,
63+
key: *const c_char,
64+
bn: *const BIGNUM,
65+
sz: size_t,
66+
) -> c_int;
67+
pub fn OSSL_PARAM_BLD_push_utf8_string(
68+
bld: *mut OSSL_PARAM_BLD,
69+
key: *const c_char,
70+
buf: *const c_char,
71+
bsize: size_t,
72+
) -> c_int;
73+
pub fn OSSL_PARAM_BLD_push_utf8_ptr(
74+
bld: *mut OSSL_PARAM_BLD,
75+
key: *const c_char,
76+
buf: *mut c_char,
77+
bsize: size_t,
78+
) -> c_int;
79+
pub fn OSSL_PARAM_BLD_push_octet_string(
80+
bld: *mut OSSL_PARAM_BLD,
81+
key: *const c_char,
82+
buf: *const c_void,
83+
bsize: size_t,
84+
) -> c_int;
85+
pub fn OSSL_PARAM_BLD_push_octet_ptr(
86+
bld: *mut OSSL_PARAM_BLD,
87+
key: *const c_char,
88+
buf: *mut c_void,
89+
bsize: size_t,
90+
) -> c_int;
3391
}

openssl-sys/src/handwritten/types.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1134,12 +1134,15 @@ pub enum OSSL_LIB_CTX {}
11341134
#[repr(C)]
11351135
pub struct OSSL_PARAM {
11361136
key: *const c_char,
1137-
data_type: c_uchar,
1137+
data_type: c_uint,
11381138
data: *mut c_void,
11391139
data_size: size_t,
11401140
return_size: size_t,
11411141
}
11421142

1143+
#[cfg(ossl300)]
1144+
pub enum OSSL_PARAM_BLD {}
1145+
11431146
#[cfg(ossl300)]
11441147
pub enum EVP_KDF {}
11451148
#[cfg(ossl300)]

systest/build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ fn main() {
8383
}
8484

8585
if version >= 0x30000000 {
86-
cfg.header("openssl/provider.h");
86+
cfg.header("openssl/provider.h")
87+
.header("openssl/params.h")
88+
.header("openssl/param_build.h");
8789
}
8890
if version >= 0x30200000 {
8991
cfg.header("openssl/thread.h");

0 commit comments

Comments
 (0)