diff --git a/Cargo.lock b/Cargo.lock index 20a6d902..2643e49d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/crypto/dalek-ff-group/Cargo.toml b/crypto/dalek-ff-group/Cargo.toml index 92b76a22..81719de1 100644 --- a/crypto/dalek-ff-group/Cargo.toml +++ b/crypto/dalek-ff-group/Cargo.toml @@ -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" diff --git a/crypto/dalek-ff-group/src/field.rs b/crypto/dalek-ff-group/src/field.rs index 675405b9..68f61572 100644 --- a/crypto/dalek-ff-group/src/field.rs +++ b/crypto/dalek-ff-group/src/field.rs @@ -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) } }