Skip to content

Commit 83f4b31

Browse files
committed
pkey_ctx/set_rsa_keygen_pubexp: fix ossl <=1.1
Use the deprecated EVP_PKEY_CTX_set_rsa_keygen_pubexp macro via EVP_PKEY_CTX_ctrl
1 parent d174a0a commit 83f4b31

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

openssl-sys/src/rsa.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ pub const RSA_F4: c_long = 0x10001;
77

88
cfg_if! {
99
if #[cfg(not(ossl300))] {
10+
pub unsafe fn EVP_PKEY_CTX_set_rsa_keygen_pubexp(ctx: *mut EVP_PKEY_CTX, pubexp: *mut BIGNUM) -> c_int {
11+
EVP_PKEY_CTX_ctrl(
12+
ctx,
13+
EVP_PKEY_RSA,
14+
EVP_PKEY_OP_KEYGEN,
15+
EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP,
16+
0,
17+
pubexp as *mut _,
18+
)
19+
}
1020
pub unsafe fn EVP_PKEY_CTX_set_rsa_padding(ctx: *mut EVP_PKEY_CTX, pad: c_int) -> c_int {
1121
EVP_PKEY_CTX_ctrl(
1222
ctx,
@@ -82,6 +92,7 @@ pub unsafe fn EVP_PKEY_CTX_set0_rsa_oaep_label(
8292

8393
pub const EVP_PKEY_CTRL_RSA_PADDING: c_int = EVP_PKEY_ALG_CTRL + 1;
8494
pub const EVP_PKEY_CTRL_RSA_PSS_SALTLEN: c_int = EVP_PKEY_ALG_CTRL + 2;
95+
pub const EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP: c_int = EVP_PKEY_ALG_CTRL + 4;
8596

8697
pub const EVP_PKEY_CTRL_RSA_MGF1_MD: c_int = EVP_PKEY_ALG_CTRL + 5;
8798

openssl/src/pkey_ctx.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ use crate::pkey::{HasPrivate, HasPublic, Id, PKey, PKeyRef, Private};
7373
use crate::rsa::Padding;
7474
use crate::sign::RsaPssSaltlen;
7575
use crate::{cvt, cvt_p};
76+
use cfg_if::cfg_if;
7677
use foreign_types::{ForeignType, ForeignTypeRef};
7778
#[cfg(not(any(boringssl, awslc)))]
7879
use libc::c_int;
@@ -490,10 +491,20 @@ impl<T> PkeyCtxRef<T> {
490491
#[inline]
491492
pub fn set_rsa_keygen_pubexp(&mut self, pubexp: &BigNumRef) -> Result<(), ErrorStack> {
492493
unsafe {
493-
cvt(ffi::EVP_PKEY_CTX_set1_rsa_keygen_pubexp(
494-
self.as_ptr(),
495-
pubexp.as_ptr(),
496-
))?;
494+
cfg_if! {
495+
if #[cfg(ossl300)] {
496+
cvt(ffi::EVP_PKEY_CTX_set1_rsa_keygen_pubexp(
497+
self.as_ptr(),
498+
pubexp.as_ptr(),
499+
))?;
500+
} else {
501+
cvt(ffi::EVP_PKEY_CTX_set_rsa_keygen_pubexp(
502+
self.as_ptr(),
503+
// Dupe the BN because the EVP_PKEY_CTX takes ownership of it and will free it.
504+
cvt_p(ffi::BN_dup(pubexp.as_ptr()))?,
505+
))?;
506+
}
507+
}
497508
}
498509

499510
Ok(())

0 commit comments

Comments
 (0)