Commit 21afcf0b authored by Alex Page's avatar Alex Page
Browse files

bn: Add mod_sqrt

parent d7dae6fb
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -73,6 +73,13 @@ extern "C" {
        m: *const BIGNUM,
        ctx: *mut BN_CTX,
    ) -> c_int;
    #[cfg(ossl110)]
    pub fn BN_mod_sqrt(
        ret: *mut BIGNUM,
        a: *const BIGNUM,
        p: *const BIGNUM,
        ctx: *mut BN_CTX,
    ) -> *mut BIGNUM;

    pub fn BN_mod_word(r: *const BIGNUM, w: BN_ULONG) -> BN_ULONG;
    pub fn BN_div_word(r: *mut BIGNUM, w: BN_ULONG) -> BN_ULONG;
+20 −0
Original line number Diff line number Diff line
@@ -639,6 +639,26 @@ impl BigNumRef {
        }
    }

    /// Places into `self` the modular square root of `a` such that `self^2 = a (mod p)`
    #[corresponds(BN_mod_sqrt)]
    #[cfg(ossl110)]
    pub fn mod_sqrt(
        &mut self,
        a: &BigNumRef,
        p: &BigNumRef,
        ctx: &mut BigNumContextRef,
    ) -> Result<(), ErrorStack> {
        unsafe {
            cvt_p(ffi::BN_mod_sqrt(
                self.as_ptr(),
                a.as_ptr(),
                p.as_ptr(),
                ctx.as_ptr(),
            ))
            .map(|_| ())
        }
    }

    /// Places the result of `a^p` in `self`.
    #[corresponds(BN_exp)]
    pub fn exp(