Commit ff048054 authored by Chris Cole's avatar Chris Cole
Browse files

Added mod_mul.

parent 7cbe372c
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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 })