diff options
| author | [email protected] <[email protected]> | 2017-12-02 12:30:50 +0100 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2017-12-02 12:30:50 +0100 |
| commit | fccb2eab4e39726fcfd2af79f20c872f488a14b3 (patch) | |
| tree | 52b113d210b314e6b07a1519d5da178384ee1168 /openssl/src | |
| parent | Merge pull request #783 from ignatenkobrain/patch-1 (diff) | |
| download | rust-openssl-fccb2eab4e39726fcfd2af79f20c872f488a14b3.tar.xz rust-openssl-fccb2eab4e39726fcfd2af79f20c872f488a14b3.zip | |
Adding dp(), dq() and qi() methods to RSA, to get the CRT parameters back
Diffstat (limited to 'openssl/src')
| -rw-r--r-- | openssl/src/rsa.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/openssl/src/rsa.rs b/openssl/src/rsa.rs index 3f4e8014..b02b9216 100644 --- a/openssl/src/rsa.rs +++ b/openssl/src/rsa.rs @@ -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; |