Skip to content

Commit e7e355b

Browse files
author
John Nunley
committed
feat: Expose operations for RSA flags
This commit adds the functions needed to manipulated the flags on the RSA object. These flags are not used in normal SSL as far as I know, but are used by custom providers/engines to change some functionality. The functions I've added are as follows: - RSA_test_flags - RSA_set_flags - RSA_clear_flags Since these operations are not available on OpenSSL 1.0.2 or earlier, I've also added shims that allow one to directly manipulate the "flags" variable on these older versions. This patch is made on behalf of Marvell Technology Inc. Signed-off-by: John Nunley <[email protected]>
1 parent 538a5cb commit e7e355b

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

openssl-sys/src/handwritten/rsa.rs

+7
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ extern "C" {
4545
iqmp: *mut *const BIGNUM,
4646
);
4747

48+
#[cfg(any(ossl110, libressl273))]
49+
pub fn RSA_test_flags(r: *const RSA, flags: c_int) -> c_int;
50+
#[cfg(any(ossl110, libressl273))]
51+
pub fn RSA_set_flags(r: *mut RSA, flags: c_int);
52+
#[cfg(any(ossl110, libressl273))]
53+
pub fn RSA_clear_flags(r: *mut RSA, flags: c_int);
54+
4855
#[cfg(not(ossl110))]
4956
pub fn RSA_generate_key(
5057
modsz: c_int,

openssl/src/rsa.rs

+33-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,26 @@ impl<T> ToOwned for RsaRef<T> {
9191
}
9292
}
9393

94+
impl<T> Rsa<T> {
95+
/// Sets the RSA flags on the object.
96+
#[corresponds(RSA_set_flags)]
97+
#[cfg(not(boringssl))]
98+
pub fn set_flags(&mut self, flags: i32) {
99+
unsafe {
100+
RSA_set_flags(self.as_ptr(), flags);
101+
}
102+
}
103+
104+
/// Clears the RSA flags on the object.
105+
#[corresponds(RSA_set_flags)]
106+
#[cfg(not(boringssl))]
107+
pub fn clear_flags(&mut self, flags: i32) {
108+
unsafe {
109+
RSA_clear_flags(self.as_ptr(), flags);
110+
}
111+
}
112+
}
113+
94114
impl<T> RsaRef<T>
95115
where
96116
T: HasPrivate,
@@ -366,6 +386,15 @@ where
366386
BigNumRef::from_const_ptr(e)
367387
}
368388
}
389+
390+
/// Tells if the provided set of RSA flags are set.
391+
///
392+
/// This function returns the union of all flags that were set on the RSA object.
393+
#[corresponds(RSA_test_flags)]
394+
#[cfg(not(boringssl))]
395+
pub fn test_flags(&self, flags: i32) -> i32 {
396+
unsafe { RSA_test_flags(self.as_ptr(), flags) }
397+
}
369398
}
370399

371400
impl Rsa<Public> {
@@ -588,8 +617,11 @@ cfg_if! {
588617
if #[cfg(any(ossl110, libressl273, boringssl))] {
589618
use ffi::{
590619
RSA_get0_key, RSA_get0_factors, RSA_get0_crt_params, RSA_set0_key, RSA_set0_factors,
591-
RSA_set0_crt_params,
620+
RSA_set0_crt_params
592621
};
622+
623+
#[cfg(not(boringssl))]
624+
use ffi::{RSA_test_flags, RSA_set_flags, RSA_clear_flags};
593625
} else {
594626
#[allow(bad_style)]
595627
unsafe fn RSA_get0_key(

0 commit comments

Comments
 (0)