Skip to content

Commit 61c2791

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 61c2791

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-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

+51-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> {
@@ -584,11 +613,32 @@ impl<T> fmt::Debug for Rsa<T> {
584613
}
585614
}
586615

616+
cfg_if! {
617+
if #[cfg(any(ossl110, libressl273))] {
618+
use ffi::{RSA_test_flags, RSA_set_flags, RSA_clear_flags};
619+
} else {
620+
#[allow(bad_style)]
621+
unsafe fn RSA_test_flags(r: *const ffi::RSA, flags: c_int) -> c_int {
622+
(*r).flags & flags
623+
}
624+
625+
#[allow(bad_style)]
626+
unsafe fn RSA_set_flags(r: *mut ffi::RSA, flags: c_int) {
627+
(*r).flags |= flags;
628+
}
629+
630+
#[allow(bad_style)]
631+
unsafe fn RSA_clear_flags(r: *mut ffi::RSA, flags: c_int) {
632+
(*r).flags &= !flags;
633+
}
634+
}
635+
}
636+
587637
cfg_if! {
588638
if #[cfg(any(ossl110, libressl273, boringssl))] {
589639
use ffi::{
590640
RSA_get0_key, RSA_get0_factors, RSA_get0_crt_params, RSA_set0_key, RSA_set0_factors,
591-
RSA_set0_crt_params,
641+
RSA_set0_crt_params
592642
};
593643
} else {
594644
#[allow(bad_style)]

0 commit comments

Comments
 (0)