diff --git a/src/edwards.rs b/src/edwards.rs index 53f1499..e03230b 100644 --- a/src/edwards.rs +++ b/src/edwards.rs @@ -190,11 +190,10 @@ impl CompressedEdwardsY { if is_valid_y_coord.unwrap_u8() != 1u8 { return None; } - // Flip the sign of X if it's not correct + // FieldElement::sqrt_ratio_i always returns the nonnegative square root, + // so we negate according to the supplied sign bit. let compressed_sign_bit = Choice::from(self.as_bytes()[31] >> 7); - let current_sign_bit = X.is_negative(); - - X.conditional_negate(current_sign_bit ^ compressed_sign_bit); + X.conditional_negate(compressed_sign_bit); Some(EdwardsPoint{ X: X, Y: Y, Z: Z, T: &X * &Y }) }