Added mod_mul.

This commit is contained in:
Chris Cole 2014-11-29 19:40:48 -05:00
parent 7cbe372ce1
commit ff04805497
1 changed files with 7 additions and 0 deletions

View File

@ -45,6 +45,7 @@ extern {
fn BN_exp(r: *mut BIGNUM, a: *mut BIGNUM, p: *mut BIGNUM, ctx: *mut BN_CTX) -> c_int;
fn BN_mod_exp(r: *mut BIGNUM, a: *mut BIGNUM, p: *mut BIGNUM, m: *mut BIGNUM, ctx: *mut BN_CTX) -> c_int;
fn BN_mod_inverse(r: *mut BIGNUM, a: *mut BIGNUM, n: *mut BIGNUM, ctx: *mut BN_CTX) -> *const BIGNUM;
fn BN_mod_word(r: *mut BIGNUM, w: c_ulong) -> c_ulong;
fn BN_gcd(r: *mut BIGNUM, a: *mut BIGNUM, b: *mut BIGNUM, ctx: *mut BN_CTX) -> c_int;
/* Bit operations on BIGNUMs */
@ -232,6 +233,12 @@ impl BigNum {
}
}
pub fn mod_word(&self, w: c_ulong) -> c_ulong {
unsafe {
return BN_mod_word(self.raw(), w);
}
}
pub fn checked_gcd(&self, a: &BigNum) -> Result<BigNum, SslError> {
unsafe {
with_bn_in_ctx!(r, ctx, { BN_gcd(r.raw(), self.raw(), a.raw(), ctx) == 1 })