mirror of
https://github.com/saymrwulf/pasta_curves-source.git
synced 2026-09-06 20:20:34 +00:00
Remove FieldExt::ROOT_OF_UNITY
We can use the `ff::PrimeField::root_of_unity` method everywhere we currently use this associated constant. If there is a more general need for accessing this as an associated constant, we should consider that for `ff::PrimeField`.
This commit is contained in:
parent
275dad22ad
commit
aeda766c34
5 changed files with 17 additions and 19 deletions
|
|
@ -6,6 +6,9 @@ and this project adheres to Rust's notion of
|
||||||
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
### Removed
|
||||||
|
- `pasta_curves::arithmetic`:
|
||||||
|
- `FieldExt::ROOT_OF_UNITY` (use `ff::PrimeField::root_of_unity` instead).
|
||||||
|
|
||||||
## [0.2.1] - 2021-09-17
|
## [0.2.1] - 2021-09-17
|
||||||
### Changed
|
### Changed
|
||||||
|
|
|
||||||
|
|
@ -28,10 +28,7 @@ pub trait FieldExt: ff::PrimeField + From<bool> + Ord + Group<Scalar = Self> {
|
||||||
/// Modulus of the field written as a string for display purposes
|
/// Modulus of the field written as a string for display purposes
|
||||||
const MODULUS: &'static str;
|
const MODULUS: &'static str;
|
||||||
|
|
||||||
/// Generator of the $2^S$ multiplicative subgroup
|
/// Inverse of `PrimeField::root_of_unity()`
|
||||||
const ROOT_OF_UNITY: Self;
|
|
||||||
|
|
||||||
/// Inverse of `ROOT_OF_UNITY`
|
|
||||||
const ROOT_OF_UNITY_INV: Self;
|
const ROOT_OF_UNITY_INV: Self;
|
||||||
|
|
||||||
/// The value $(T-1)/2$ such that $2^S \cdot T = p - 1$ with $T$ odd.
|
/// The value $(T-1)/2$ such that $2^S \cdot T = p - 1$ with $T$ odd.
|
||||||
|
|
@ -233,7 +230,7 @@ impl<F: FieldExt> SqrtTables<F> {
|
||||||
marker: PhantomData,
|
marker: PhantomData,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut gtab = (0..4).scan(F::ROOT_OF_UNITY, |gi, _| {
|
let mut gtab = (0..4).scan(F::root_of_unity(), |gi, _| {
|
||||||
// gi == ROOT_OF_UNITY^(256^i)
|
// gi == ROOT_OF_UNITY^(256^i)
|
||||||
let gtab_i: Vec<F> = (0..256)
|
let gtab_i: Vec<F> = (0..256)
|
||||||
.scan(F::one(), |acc, _| {
|
.scan(F::one(), |acc, _| {
|
||||||
|
|
@ -331,7 +328,7 @@ impl<F: FieldExt> SqrtTables<F> {
|
||||||
|
|
||||||
let sqdiv = res.square() * div;
|
let sqdiv = res.square() * div;
|
||||||
let is_square = (sqdiv - num).is_zero();
|
let is_square = (sqdiv - num).is_zero();
|
||||||
let is_nonsquare = (sqdiv - F::ROOT_OF_UNITY * num).is_zero();
|
let is_nonsquare = (sqdiv - F::root_of_unity() * num).is_zero();
|
||||||
assert!(bool::from(
|
assert!(bool::from(
|
||||||
num.is_zero() | div.is_zero() | (is_square ^ is_nonsquare)
|
num.is_zero() | div.is_zero() | (is_square ^ is_nonsquare)
|
||||||
));
|
));
|
||||||
|
|
@ -348,7 +345,7 @@ impl<F: FieldExt> SqrtTables<F> {
|
||||||
|
|
||||||
let sq = res.square();
|
let sq = res.square();
|
||||||
let is_square = (sq - u).is_zero();
|
let is_square = (sq - u).is_zero();
|
||||||
let is_nonsquare = (sq - F::ROOT_OF_UNITY * u).is_zero();
|
let is_nonsquare = (sq - F::root_of_unity() * u).is_zero();
|
||||||
assert!(bool::from(u.is_zero() | (is_square ^ is_nonsquare)));
|
assert!(bool::from(u.is_zero() | (is_square ^ is_nonsquare)));
|
||||||
|
|
||||||
(is_square, res)
|
(is_square, res)
|
||||||
|
|
|
||||||
|
|
@ -1100,7 +1100,7 @@ impl Ep {
|
||||||
0x4000000000000000,
|
0x4000000000000000,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/// `(F::ROOT_OF_UNITY.invert().unwrap() * z).sqrt().unwrap()`
|
/// `(F::root_of_unity().invert().unwrap() * z).sqrt().unwrap()`
|
||||||
pub const THETA: Fp = Fp::from_raw([
|
pub const THETA: Fp = Fp::from_raw([
|
||||||
0xca330bcc09ac318e,
|
0xca330bcc09ac318e,
|
||||||
0x51f64fc4dc888857,
|
0x51f64fc4dc888857,
|
||||||
|
|
@ -1200,7 +1200,7 @@ impl Eq {
|
||||||
0x4000000000000000,
|
0x4000000000000000,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/// `(F::ROOT_OF_UNITY.invert().unwrap() * z).sqrt().unwrap()`
|
/// `(F::root_of_unity().invert().unwrap() * z).sqrt().unwrap()`
|
||||||
pub const THETA: Fq = Fq::from_raw([
|
pub const THETA: Fq = Fq::from_raw([
|
||||||
0x632cae9872df1b5d,
|
0x632cae9872df1b5d,
|
||||||
0x38578ccadf03ac27,
|
0x38578ccadf03ac27,
|
||||||
|
|
|
||||||
|
|
@ -673,7 +673,6 @@ lazy_static! {
|
||||||
impl FieldExt for Fp {
|
impl FieldExt for Fp {
|
||||||
const MODULUS: &'static str =
|
const MODULUS: &'static str =
|
||||||
"0x40000000000000000000000000000000224698fc094cf91b992d30ed00000001";
|
"0x40000000000000000000000000000000224698fc094cf91b992d30ed00000001";
|
||||||
const ROOT_OF_UNITY: Self = ROOT_OF_UNITY;
|
|
||||||
const ROOT_OF_UNITY_INV: Self = Fp::from_raw([
|
const ROOT_OF_UNITY_INV: Self = Fp::from_raw([
|
||||||
0xf0b87c7db2ce91f6,
|
0xf0b87c7db2ce91f6,
|
||||||
0x84a0a1d8859f066f,
|
0x84a0a1d8859f066f,
|
||||||
|
|
@ -854,8 +853,8 @@ fn test_sqrt_ratio_and_alt() {
|
||||||
assert!(v_alt == v);
|
assert!(v_alt == v);
|
||||||
|
|
||||||
// (false, sqrt(ROOT_OF_UNITY * num/div)), if num and div are nonzero and num/div is a nonsquare in the field
|
// (false, sqrt(ROOT_OF_UNITY * num/div)), if num and div are nonzero and num/div is a nonsquare in the field
|
||||||
let num = num * Fp::ROOT_OF_UNITY;
|
let num = num * Fp::root_of_unity();
|
||||||
let expected = Fp::TWO_INV * Fp::ROOT_OF_UNITY * Fp::from_u64(5).invert().unwrap();
|
let expected = Fp::TWO_INV * Fp::root_of_unity() * Fp::from_u64(5).invert().unwrap();
|
||||||
let (is_square, v) = Fp::sqrt_ratio(&num, &div);
|
let (is_square, v) = Fp::sqrt_ratio(&num, &div);
|
||||||
assert!(!bool::from(is_square));
|
assert!(!bool::from(is_square));
|
||||||
assert!(v == expected || (-v) == expected);
|
assert!(v == expected || (-v) == expected);
|
||||||
|
|
@ -904,7 +903,7 @@ fn test_zeta() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_root_of_unity() {
|
fn test_root_of_unity() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Fp::ROOT_OF_UNITY.pow_vartime(&[1 << Fp::S, 0, 0, 0]),
|
Fp::root_of_unity().pow_vartime(&[1 << Fp::S, 0, 0, 0]),
|
||||||
Fp::one()
|
Fp::one()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -912,7 +911,7 @@ fn test_root_of_unity() {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_inv_root_of_unity() {
|
fn test_inv_root_of_unity() {
|
||||||
assert_eq!(Fp::ROOT_OF_UNITY_INV, Fp::ROOT_OF_UNITY.invert().unwrap());
|
assert_eq!(Fp::ROOT_OF_UNITY_INV, Fp::root_of_unity().invert().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
|
|
|
||||||
|
|
@ -673,7 +673,6 @@ lazy_static! {
|
||||||
impl FieldExt for Fq {
|
impl FieldExt for Fq {
|
||||||
const MODULUS: &'static str =
|
const MODULUS: &'static str =
|
||||||
"0x40000000000000000000000000000000224698fc0994a8dd8c46eb2100000001";
|
"0x40000000000000000000000000000000224698fc0994a8dd8c46eb2100000001";
|
||||||
const ROOT_OF_UNITY: Self = ROOT_OF_UNITY;
|
|
||||||
const ROOT_OF_UNITY_INV: Self = Fq::from_raw([
|
const ROOT_OF_UNITY_INV: Self = Fq::from_raw([
|
||||||
0x57eecda0a84b6836,
|
0x57eecda0a84b6836,
|
||||||
0x4ad38b9084b8a80c,
|
0x4ad38b9084b8a80c,
|
||||||
|
|
@ -854,8 +853,8 @@ fn test_sqrt_ratio_and_alt() {
|
||||||
assert!(v_alt == v);
|
assert!(v_alt == v);
|
||||||
|
|
||||||
// (false, sqrt(ROOT_OF_UNITY * num/div)), if num and div are nonzero and num/div is a nonsquare in the field
|
// (false, sqrt(ROOT_OF_UNITY * num/div)), if num and div are nonzero and num/div is a nonsquare in the field
|
||||||
let num = num * Fq::ROOT_OF_UNITY;
|
let num = num * Fq::root_of_unity();
|
||||||
let expected = Fq::TWO_INV * Fq::ROOT_OF_UNITY * Fq::from_u64(5).invert().unwrap();
|
let expected = Fq::TWO_INV * Fq::root_of_unity() * Fq::from_u64(5).invert().unwrap();
|
||||||
let (is_square, v) = Fq::sqrt_ratio(&num, &div);
|
let (is_square, v) = Fq::sqrt_ratio(&num, &div);
|
||||||
assert!(!bool::from(is_square));
|
assert!(!bool::from(is_square));
|
||||||
assert!(v == expected || (-v) == expected);
|
assert!(v == expected || (-v) == expected);
|
||||||
|
|
@ -903,7 +902,7 @@ fn test_zeta() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_root_of_unity() {
|
fn test_root_of_unity() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Fq::ROOT_OF_UNITY.pow_vartime(&[1 << Fq::S, 0, 0, 0]),
|
Fq::root_of_unity().pow_vartime(&[1 << Fq::S, 0, 0, 0]),
|
||||||
Fq::one()
|
Fq::one()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -911,7 +910,7 @@ fn test_root_of_unity() {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_inv_root_of_unity() {
|
fn test_inv_root_of_unity() {
|
||||||
assert_eq!(Fq::ROOT_OF_UNITY_INV, Fq::ROOT_OF_UNITY.invert().unwrap());
|
assert_eq!(Fq::ROOT_OF_UNITY_INV, Fq::root_of_unity().invert().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue