Merge pull request #784 from P-E-Meunier/master

Adding dp(), dq() and qi() methods to RSA, to get the CRT parameters back
This commit is contained in:
Steven Fackler 2017-12-02 08:44:12 -08:00 committed by GitHub
commit b40bddfe02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 0 deletions

View File

@ -172,6 +172,12 @@ extern "C" {
d: *mut *const ::BIGNUM,
);
pub fn RSA_get0_factors(r: *const ::RSA, p: *mut *const ::BIGNUM, q: *mut *const ::BIGNUM);
pub fn RSA_get0_crt_params(
r: *const ::RSA,
dmp1: *mut *const ::BIGNUM,
dmq1: *mut *const ::BIGNUM,
iqmp: *mut *const ::BIGNUM,
);
pub fn RSA_set0_key(
r: *mut ::RSA,
n: *mut ::BIGNUM,

View File

@ -222,6 +222,39 @@ impl RsaRef {
}
}
}
pub fn dp(&self) -> Option<&BigNumRef> {
unsafe {
let dp = compat::crt_params(self.as_ptr())[0];
if dp.is_null() {
None
} else {
Some(BigNumRef::from_ptr(dp as *mut _))
}
}
}
pub fn dq(&self) -> Option<&BigNumRef> {
unsafe {
let dq = compat::crt_params(self.as_ptr())[1];
if dq.is_null() {
None
} else {
Some(BigNumRef::from_ptr(dq as *mut _))
}
}
}
pub fn qi(&self) -> Option<&BigNumRef> {
unsafe {
let qi = compat::crt_params(self.as_ptr())[2];
if qi.is_null() {
None
} else {
Some(BigNumRef::from_ptr(qi as *mut _))
}
}
}
}
impl Rsa {
@ -348,6 +381,12 @@ mod compat {
[p, q]
}
pub unsafe fn crt_params(r: *const RSA) -> [*const BIGNUM; 3] {
let (mut dp, mut dq, mut qi) = (ptr::null(), ptr::null(), ptr::null());
ffi::RSA_get0_crt_params(r, &mut dp, &mut dq, &mut qi);
[dp, dq, qi]
}
pub unsafe fn set_key(r: *mut RSA, n: *mut BIGNUM, e: *mut BIGNUM, d: *mut BIGNUM) -> c_int {
ffi::RSA_set0_key(r, n, e, d)
}
@ -379,6 +418,10 @@ mod compat {
[(*r).p, (*r).q]
}
pub unsafe fn crt_params(r: *const RSA) -> [*const BIGNUM; 3] {
[(*r).dmp1, (*r).dmq1, (*r).iqmp]
}
pub unsafe fn set_key(r: *mut RSA, n: *mut BIGNUM, e: *mut BIGNUM, d: *mut BIGNUM) -> c_int {
(*r).n = n;
(*r).e = e;