Bump dalek-ff-group version

This commit is contained in:
Luke Parker 2022-08-18 17:11:55 -04:00
parent a2aa182cc4
commit c53e7ad6c7
No known key found for this signature in database
GPG key ID: F9F1386DB1E119B6
3 changed files with 7 additions and 10 deletions

2
Cargo.lock generated
View file

@ -1378,7 +1378,7 @@ dependencies = [
[[package]]
name = "dalek-ff-group"
version = "0.1.2"
version = "0.1.3"
dependencies = [
"crypto-bigint",
"curve25519-dalek 3.2.0",

View file

@ -1,6 +1,6 @@
[package]
name = "dalek-ff-group"
version = "0.1.2"
version = "0.1.3"
description = "ff/group bindings around curve25519-dalek"
license = "MIT"
repository = "https://github.com/serai-dex/serai"

View file

@ -165,27 +165,24 @@ impl FieldElement {
}
pub fn sqrt_ratio_i(u: FieldElement, v: FieldElement) -> (Choice, FieldElement) {
let i = SQRT_M1;
let v3 = v.square() * v;
let v7 = v3.square() * v;
let mut r = (u * v3) *
(u * v7).pow((-FieldElement::from(5u8)) * FieldElement::from(8u8).invert().unwrap());
let check = (v) * r.square();
let i = SQRT_M1;
let check = v * r.square();
let correct_sign = check.ct_eq(&u);
let flipped_sign = check.ct_eq(&(-u));
let flipped_sign_i = check.ct_eq(&((-u) * i));
let r_prime = i * r;
r.conditional_assign(&r_prime, flipped_sign | flipped_sign_i);
r.conditional_assign(&(r * i), flipped_sign | flipped_sign_i);
let r_is_negative = r.is_odd();
r.conditional_negate(r_is_negative);
let was_non_zero_square = correct_sign | flipped_sign;
(was_non_zero_square, r)
(correct_sign | flipped_sign, r)
}
}