mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-07-30 20:11:23 +00:00
ff: PrimeField::{is_even, is_odd}
This commit is contained in:
@@ -127,7 +127,7 @@ impl<E: JubjubEngine> Point<E, Unknown> {
|
||||
tmp1.mul_assign(&tmp2);
|
||||
|
||||
tmp1.sqrt().map(|mut x| {
|
||||
if x.into_repr().is_odd() != sign {
|
||||
if x.is_odd() != sign {
|
||||
x = x.neg();
|
||||
}
|
||||
|
||||
@@ -172,9 +172,8 @@ impl<E: JubjubEngine, Subgroup> Point<E, Subgroup> {
|
||||
|
||||
assert_eq!(E::Fr::NUM_BITS, 255);
|
||||
|
||||
let x_repr = x.into_repr();
|
||||
let mut y_repr = y.into_repr();
|
||||
if x_repr.is_odd() {
|
||||
if x.is_odd() {
|
||||
y_repr.as_mut()[3] |= 0x8000000000000000u64;
|
||||
}
|
||||
|
||||
|
@@ -481,6 +481,11 @@ impl PrimeField for Fs {
|
||||
r.0
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn is_odd(&self) -> bool {
|
||||
self.into_repr().is_odd()
|
||||
}
|
||||
|
||||
fn char() -> FsRepr {
|
||||
MODULUS
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
use ff::{BitIterator, Field, PrimeField, PrimeFieldRepr, SqrtField};
|
||||
use ff::{BitIterator, Field, PrimeField, SqrtField};
|
||||
use std::ops::{AddAssign, MulAssign, Neg, SubAssign};
|
||||
use subtle::CtOption;
|
||||
|
||||
@@ -60,7 +60,7 @@ impl<E: JubjubEngine> Point<E, Unknown> {
|
||||
rhs.add_assign(&x2);
|
||||
|
||||
rhs.sqrt().map(|mut y| {
|
||||
if y.into_repr().is_odd() != sign {
|
||||
if y.is_odd() != sign {
|
||||
y = y.neg();
|
||||
}
|
||||
|
||||
|
@@ -237,7 +237,7 @@ fn test_get_for<E: JubjubEngine>(params: &E::Params) {
|
||||
let p = edwards::Point::<E, _>::get_for_y(y, sign, params);
|
||||
if bool::from(p.is_some()) {
|
||||
let mut p = p.unwrap();
|
||||
assert!(p.to_xy().0.into_repr().is_odd() == sign);
|
||||
assert!(p.to_xy().0.is_odd() == sign);
|
||||
p = p.negate();
|
||||
assert!(edwards::Point::<E, _>::get_for_y(y, !sign, params).unwrap() == p);
|
||||
}
|
||||
|
Reference in New Issue
Block a user