Skip to content

Commit e11aa92

Browse files
committed
ML-KEM/ML-DSA part 1: openssl-sys changes
Splitting up sfackler#2405 into a few parts as suggest by @alex. This adds the non-param-builder openssl-sys changes.
1 parent 3c27685 commit e11aa92

File tree

7 files changed

+131
-3
lines changed

7 files changed

+131
-3
lines changed

openssl-sys/src/core_dispatch.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use super::*;
2+
use libc::*;
3+
4+
/* OpenSSL 3.* only */
5+
6+
pub const OSSL_KEYMGMT_SELECT_PRIVATE_KEY: c_int = 0x01;
7+
pub const OSSL_KEYMGMT_SELECT_PUBLIC_KEY: c_int = 0x02;
8+
pub const OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS: c_int = 0x04;
9+
pub const OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS: c_int = 0x80;
10+
pub const OSSL_KEYMGMT_SELECT_ALL_PARAMETERS: c_int =
11+
OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS | OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS;

openssl-sys/src/evp.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ 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;
49+
4150
pub unsafe fn EVP_get_digestbynid(type_: c_int) -> *const EVP_MD {
4251
EVP_get_digestbyname(OBJ_nid2sn(type_))
4352
}

openssl-sys/src/handwritten/evp.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,27 @@ extern "C" {
493493
#[cfg(any(ossl110, libressl270))]
494494
pub fn EVP_PKEY_up_ref(pkey: *mut EVP_PKEY) -> c_int;
495495

496+
#[cfg(ossl300)]
497+
pub fn EVP_PKEY_fromdata_init(ctx: *mut EVP_PKEY_CTX) -> c_int;
498+
499+
#[cfg(ossl300)]
500+
pub fn EVP_PKEY_fromdata(
501+
ctx: *mut EVP_PKEY_CTX,
502+
ppkey: *mut *mut EVP_PKEY,
503+
selection: c_int,
504+
param: *mut OSSL_PARAM,
505+
) -> c_int;
506+
507+
#[cfg(ossl300)]
508+
pub fn EVP_PKEY_todata(
509+
ppkey: *const EVP_PKEY,
510+
selection: c_int,
511+
param: *mut *mut OSSL_PARAM,
512+
) -> c_int;
513+
514+
#[cfg(ossl300)]
515+
pub fn EVP_PKEY_generate(ctx: *mut EVP_PKEY_CTX, k: *mut *mut EVP_PKEY) -> c_int;
516+
496517
pub fn d2i_AutoPrivateKey(
497518
a: *mut *mut EVP_PKEY,
498519
pp: *mut *const c_uchar,
@@ -539,6 +560,12 @@ extern "C" {
539560

540561
pub fn EVP_PKEY_CTX_new(k: *mut EVP_PKEY, e: *mut ENGINE) -> *mut EVP_PKEY_CTX;
541562
pub fn EVP_PKEY_CTX_new_id(id: c_int, e: *mut ENGINE) -> *mut EVP_PKEY_CTX;
563+
#[cfg(ossl300)]
564+
pub fn EVP_PKEY_CTX_new_from_name(
565+
libctx: *mut OSSL_LIB_CTX,
566+
name: *const c_char,
567+
propquery: *const c_char,
568+
) -> *mut EVP_PKEY_CTX;
542569
pub fn EVP_PKEY_CTX_free(ctx: *mut EVP_PKEY_CTX);
543570

544571
pub fn EVP_PKEY_CTX_ctrl(
@@ -589,6 +616,14 @@ extern "C" {
589616
pub fn EVP_PKEY_paramgen(ctx: *mut EVP_PKEY_CTX, key: *mut *mut EVP_PKEY) -> c_int;
590617

591618
pub fn EVP_PKEY_sign_init(ctx: *mut EVP_PKEY_CTX) -> c_int;
619+
620+
#[cfg(ossl340)]
621+
pub fn EVP_PKEY_sign_message_init(
622+
ctx: *mut EVP_PKEY_CTX,
623+
algo: *mut EVP_SIGNATURE,
624+
params: *const OSSL_PARAM,
625+
) -> c_int;
626+
592627
pub fn EVP_PKEY_sign(
593628
ctx: *mut EVP_PKEY_CTX,
594629
sig: *mut c_uchar,
@@ -597,6 +632,14 @@ extern "C" {
597632
tbslen: size_t,
598633
) -> c_int;
599634
pub fn EVP_PKEY_verify_init(ctx: *mut EVP_PKEY_CTX) -> c_int;
635+
636+
#[cfg(ossl340)]
637+
pub fn EVP_PKEY_verify_message_init(
638+
ctx: *mut EVP_PKEY_CTX,
639+
algo: *mut EVP_SIGNATURE,
640+
params: *const OSSL_PARAM,
641+
) -> c_int;
642+
600643
pub fn EVP_PKEY_verify(
601644
ctx: *mut EVP_PKEY_CTX,
602645
sig: *const c_uchar,
@@ -628,6 +671,28 @@ extern "C" {
628671
sig: *const c_uchar,
629672
siglen: size_t,
630673
) -> c_int;
674+
675+
#[cfg(ossl300)]
676+
pub fn EVP_PKEY_encapsulate_init(ctx: *mut EVP_PKEY_CTX, params: *const OSSL_PARAM) -> c_int;
677+
#[cfg(ossl300)]
678+
pub fn EVP_PKEY_encapsulate(
679+
ctx: *mut EVP_PKEY_CTX,
680+
wrappedkey: *mut c_uchar,
681+
wrappedkeylen: *mut size_t,
682+
genkey: *mut c_uchar,
683+
genkeylen: *mut size_t,
684+
) -> c_int;
685+
686+
#[cfg(ossl300)]
687+
pub fn EVP_PKEY_decapsulate_init(ctx: *mut EVP_PKEY_CTX, params: *const OSSL_PARAM) -> c_int;
688+
#[cfg(ossl300)]
689+
pub fn EVP_PKEY_decapsulate(
690+
ctx: *mut EVP_PKEY_CTX,
691+
genkey: *mut c_uchar,
692+
genkeylen: *mut size_t,
693+
wrappedkey: *const c_uchar,
694+
wrappedkeylen: size_t,
695+
) -> c_int;
631696
}
632697

633698
const_ptr_api! {
@@ -733,6 +798,14 @@ cfg_if! {
733798
buf: *const c_uchar,
734799
bsize: size_t,
735800
) -> c_int;
801+
pub fn EVP_SIGNATURE_free(s: *mut EVP_SIGNATURE);
802+
pub fn EVP_SIGNATURE_up_ref(s: *mut EVP_SIGNATURE) -> c_int;
803+
pub fn EVP_SIGNATURE_fetch(ctx: *mut OSSL_LIB_CTX,
804+
algorithm: *const c_char,
805+
properties: *const c_char)
806+
-> *mut EVP_SIGNATURE;
807+
pub fn EVP_SIGNATURE_get0_name(s: *const EVP_SIGNATURE) -> *const c_char;
808+
pub fn EVP_SIGNATURE_get0_description(s: *const EVP_SIGNATURE) -> *const c_char;
736809
}
737810
}
738811
}

openssl-sys/src/handwritten/params.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,32 @@ use super::super::*;
22
use libc::*;
33

44
extern "C" {
5-
#[cfg(ossl300)]
5+
pub fn OSSL_PARAM_free(p: *mut OSSL_PARAM);
66
pub fn OSSL_PARAM_construct_uint(key: *const c_char, buf: *mut c_uint) -> OSSL_PARAM;
7-
#[cfg(ossl300)]
87
pub fn OSSL_PARAM_construct_end() -> OSSL_PARAM;
9-
#[cfg(ossl300)]
108
pub fn OSSL_PARAM_construct_octet_string(
119
key: *const c_char,
1210
buf: *mut c_void,
1311
bsize: size_t,
1412
) -> OSSL_PARAM;
1513

14+
pub fn OSSL_PARAM_locate(p: *mut OSSL_PARAM, key: *const c_char) -> *mut OSSL_PARAM;
15+
pub fn OSSL_PARAM_get_BN(p: *const OSSL_PARAM, val: *mut *mut BIGNUM) -> c_int;
16+
pub fn OSSL_PARAM_get_utf8_string(
17+
p: *const OSSL_PARAM,
18+
val: *mut *mut c_char,
19+
max_len: usize,
20+
) -> c_int;
21+
pub fn OSSL_PARAM_get_utf8_string_ptr(p: *const OSSL_PARAM, val: *mut *const c_char) -> c_int;
22+
pub fn OSSL_PARAM_get_octet_string(
23+
p: *const OSSL_PARAM,
24+
val: *mut *mut c_void,
25+
max_len: usize,
26+
used_len: *mut usize,
27+
) -> c_int;
28+
pub fn OSSL_PARAM_get_octet_string_ptr(
29+
p: *const OSSL_PARAM,
30+
val: *mut *const c_void,
31+
used_len: *mut usize,
32+
) -> c_int;
1633
}

openssl-sys/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ mod openssl {
7272
pub use self::bio::*;
7373
pub use self::bn::*;
7474
pub use self::cms::*;
75+
#[cfg(ossl300)]
76+
pub use self::core_dispatch::*;
7577
pub use self::crypto::*;
7678
pub use self::dh::*;
7779
pub use self::dsa::*;
@@ -104,6 +106,8 @@ mod openssl {
104106
mod bio;
105107
mod bn;
106108
mod cms;
109+
#[cfg(ossl300)]
110+
mod core_dispatch;
107111
mod crypto;
108112
mod dh;
109113
mod dsa;

openssl-sys/src/types.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ cfg_if! {
1919
}
2020
}
2121
}
22+
23+
cfg_if! {
24+
if #[cfg(ossl300)] {
25+
pub enum EVP_SIGNATURE {}
26+
}
27+
}

openssl/build.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ fn main() {
4747
println!("cargo:rustc-check-cfg=cfg(ossl310)");
4848
println!("cargo:rustc-check-cfg=cfg(ossl320)");
4949
println!("cargo:rustc-check-cfg=cfg(ossl330)");
50+
println!("cargo:rustc-check-cfg=cfg(ossl340)");
51+
println!("cargo:rustc-check-cfg=cfg(ossl350)");
5052

5153
if env::var("DEP_OPENSSL_LIBRESSL").is_ok() {
5254
println!("cargo:rustc-cfg=libressl");
@@ -175,5 +177,11 @@ fn main() {
175177
if version >= 0x3_03_00_00_0 {
176178
println!("cargo:rustc-cfg=ossl330");
177179
}
180+
if version >= 0x3_04_00_00_0 {
181+
println!("cargo:rustc-cfg=ossl340");
182+
}
183+
if version >= 0x3_05_00_00_0 {
184+
println!("cargo:rustc-cfg=ossl350");
185+
}
178186
}
179187
}

0 commit comments

Comments
 (0)