Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable BN_mod_sqrt() for upcoming LibreSSL 3.8.2 #2063

Merged
merged 2 commits into from Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion openssl-sys/src/handwritten/bn.rs
Expand Up @@ -75,7 +75,6 @@ extern "C" {
m: *const BIGNUM,
ctx: *mut BN_CTX,
) -> c_int;
#[cfg(ossl110)]
pub fn BN_mod_sqrt(
ret: *mut BIGNUM,
a: *const BIGNUM,
Expand Down
17 changes: 11 additions & 6 deletions openssl/src/bn.rs
Expand Up @@ -655,7 +655,6 @@ 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,
Expand Down Expand Up @@ -1490,17 +1489,23 @@ mod tests {
assert!(b.is_const_time())
}

#[cfg(ossl110)]
#[test]
fn test_mod_sqrt() {
let mut ctx = BigNumContext::new().unwrap();

let s = BigNum::from_hex_str("47A8DD7626B9908C80ACD7E0D3344D69").unwrap();
let p = BigNum::from_hex_str("81EF47265B58BCE5").unwrap();
let s = BigNum::from_hex_str("2").unwrap();
let p = BigNum::from_hex_str("7DEB1").unwrap();
let mut sqrt = BigNum::new().unwrap();
let mut out = BigNum::new().unwrap();

out.mod_sqrt(&s, &p, &mut ctx).unwrap();
assert_eq!(out, BigNum::from_hex_str("7C6D179E19B97BDD").unwrap());
// Square the root because OpenSSL randomly returns one of 2E42C or 4FA85
sqrt.mod_sqrt(&s, &p, &mut ctx).unwrap();
out.mod_sqr(&sqrt, &p, &mut ctx).unwrap();
assert!(out == s);

let s = BigNum::from_hex_str("3").unwrap();
let p = BigNum::from_hex_str("5").unwrap();
assert!(out.mod_sqrt(&s, &p, &mut ctx).is_err());
}

#[test]
Expand Down