mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-07-30 20:11:23 +00:00
ff: Move pow_vartime back into Field trait
The only places we don't use constant u64 limbs, we use PrimeField::char instead (except in a single test where we use a field element).
This commit is contained in:
@@ -2,8 +2,6 @@ use super::fq2::Fq2;
|
||||
use ff::{Field, PrimeField};
|
||||
use std::ops::{AddAssign, MulAssign, SubAssign};
|
||||
|
||||
#[cfg(test)]
|
||||
use ff::PowVartime;
|
||||
#[cfg(test)]
|
||||
use std::ops::Neg;
|
||||
|
||||
@@ -1644,11 +1642,15 @@ fn test_fq_pow() {
|
||||
assert_eq!(c, target);
|
||||
}
|
||||
|
||||
use byteorder::ByteOrder;
|
||||
let mut char_limbs = [0; 6];
|
||||
byteorder::LittleEndian::read_u64_into(Fq::char().as_ref(), &mut char_limbs);
|
||||
|
||||
for _ in 0..1000 {
|
||||
// Exponentiating by the modulus should have no effect in a prime field.
|
||||
let a = Fq::random(&mut rng);
|
||||
|
||||
assert_eq!(a, a.pow_vartime(Fq::char()));
|
||||
assert_eq!(a, a.pow_vartime(char_limbs));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
use super::fq::{Fq, FROBENIUS_COEFF_FQ2_C1, NEGATIVE_ONE};
|
||||
use ff::{Field, PowVartime};
|
||||
use ff::Field;
|
||||
use rand_core::RngCore;
|
||||
use std::cmp::Ordering;
|
||||
use std::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};
|
||||
|
@@ -7,8 +7,6 @@ use std::ops::{AddAssign, MulAssign, SubAssign};
|
||||
#[PrimeFieldReprEndianness = "little"]
|
||||
pub struct Fr([u64; 4]);
|
||||
|
||||
#[cfg(test)]
|
||||
use ff::PowVartime;
|
||||
#[cfg(test)]
|
||||
use rand_core::SeedableRng;
|
||||
#[cfg(test)]
|
||||
@@ -430,11 +428,15 @@ fn test_fr_pow() {
|
||||
assert_eq!(c, target);
|
||||
}
|
||||
|
||||
use byteorder::ByteOrder;
|
||||
let mut char_limbs = [0; 4];
|
||||
byteorder::LittleEndian::read_u64_into(Fr::char().as_ref(), &mut char_limbs);
|
||||
|
||||
for _ in 0..1000 {
|
||||
// Exponentiating by the modulus should have no effect in a prime field.
|
||||
let a = Fr::random(&mut rng);
|
||||
|
||||
assert_eq!(a, a.pow_vartime(Fr::char()));
|
||||
assert_eq!(a, a.pow_vartime(char_limbs));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -23,7 +23,7 @@ pub use self::fr::{Fr, FrRepr};
|
||||
|
||||
use super::{Engine, PairingCurveAffine};
|
||||
|
||||
use ff::{BitIterator, Field, PowVartime, ScalarEngine};
|
||||
use ff::{BitIterator, Field, ScalarEngine};
|
||||
use group::CurveAffine;
|
||||
use std::ops::{AddAssign, MulAssign, Neg, SubAssign};
|
||||
use subtle::CtOption;
|
||||
|
@@ -1,10 +1,10 @@
|
||||
use ff::PowVartime;
|
||||
use ff::{Endianness, Field, PrimeField};
|
||||
use group::{CurveAffine, CurveProjective};
|
||||
use rand_core::SeedableRng;
|
||||
use rand_xorshift::XorShiftRng;
|
||||
use std::ops::MulAssign;
|
||||
|
||||
use crate::{Engine, Field, PairingCurveAffine, PrimeField};
|
||||
use crate::{Engine, PairingCurveAffine};
|
||||
|
||||
pub fn engine_tests<E: Engine>() {
|
||||
let mut rng = XorShiftRng::from_seed([
|
||||
@@ -130,8 +130,14 @@ fn random_bilinearity_tests<E: Engine>() {
|
||||
|
||||
let mut cd = c;
|
||||
cd.mul_assign(&d);
|
||||
let mut cd = cd.into_repr();
|
||||
<E::Fr as PrimeField>::ReprEndianness::toggle_little_endian(&mut cd);
|
||||
|
||||
let abcd = E::pairing(a, b).pow_vartime(cd.into_repr());
|
||||
use byteorder::ByteOrder;
|
||||
let mut cd_limbs = [0; 4];
|
||||
byteorder::LittleEndian::read_u64_into(cd.as_ref(), &mut cd_limbs);
|
||||
|
||||
let abcd = E::pairing(a, b).pow_vartime(cd_limbs);
|
||||
|
||||
assert_eq!(acbd, adbc);
|
||||
assert_eq!(acbd, abcd);
|
||||
|
Reference in New Issue
Block a user