Skip to content

Commit 04a756b

Browse files
committed
Implement F::characteristic
1 parent 467f0c1 commit 04a756b

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

ec/src/models/short_weierstrass_jacobian.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ impl<P: Parameters> GroupAffine<P> {
142142
/// Checks if `self` is in the subgroup having order that equaling that of
143143
/// `P::ScalarField`.
144144
pub fn is_in_correct_subgroup_assuming_on_curve(&self) -> bool {
145-
self.mul_bits(BitIteratorBE::new(P::ScalarField::characteristic()))
145+
use core::convert::TryInto;
146+
let characteristic = P::ScalarField::characteristic();
147+
self.mul_bits(BitIteratorBE::new(&ark_ff::biginteger::to_64x4(characteristic.try_into().unwrap())))
146148
.is_zero()
147149
}
148150
}

ec/src/models/twisted_edwards_extended.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ impl<P: Parameters> GroupAffine<P> {
110110
/// Checks that the current point is in the prime order subgroup given
111111
/// the point on the curve.
112112
pub fn is_in_correct_subgroup_assuming_on_curve(&self) -> bool {
113-
self.mul_bits(BitIteratorBE::new(P::ScalarField::characteristic()))
113+
use core::convert::TryInto;
114+
let characteristic = P::ScalarField::characteristic();
115+
self.mul_bits(BitIteratorBE::new(&ark_ff::biginteger::to_64x4(characteristic.try_into().unwrap())))
114116
.is_zero()
115117
}
116118
}

ff/src/fields/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub trait Field:
123123

124124
/// Returns the characteristic of the field,
125125
/// in little-endian representation.
126-
fn characteristic() -> &'static [u64] {
126+
fn characteristic() -> &'static [u32] {
127127
Self::BasePrimeField::characteristic()
128128
}
129129

ff/src/fields/models/fp12_2over3over2.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
fields::{fp6_3over2::*, Field, Fp2, Fp2Parameters},
44
One,
55
};
6-
use core::marker::PhantomData;
6+
use core::{convert::TryInto, marker::PhantomData};
77
use core::ops::{AddAssign, SubAssign};
88

99
type Fp2Params<P> = <<P as Fp12Parameters>::Fp6Params as Fp6Parameters>::Fp2Params;
@@ -135,7 +135,8 @@ impl<P: Fp12Parameters> Fp12<P> {
135135
// Faster Squaring in the Cyclotomic Subgroup of Sixth Degree Extensions
136136
// - Robert Granger and Michael Scott
137137
//
138-
if characteristic_square_mod_6_is_one(Self::characteristic()) {
138+
let characteristic = Self::characteristic();
139+
if characteristic_square_mod_6_is_one(&super::to_64x4(characteristic.try_into().unwrap())) {
139140
let fp2_nr = <P::Fp6Params as Fp6Parameters>::mul_fp2_by_nonresidue;
140141

141142
let r0 = &self.c0.c0;

ff/src/fields/models/webnode_new.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,10 +1121,6 @@ impl<C: Fp256Parameters> FromBytes for NewFp256<C> {
11211121
})
11221122
}
11231123
}
1124-
// + core::iter::Sum<Self>
1125-
// + for<'a> core::iter::Sum<&'a Self>
1126-
// + core::iter::Product<Self>
1127-
// + for<'a> core::iter::Product<&'a Self>
11281124

11291125
impl<C: Fp256Parameters> Field for NewFp256<C> {
11301126
type BasePrimeField = Self;
@@ -1150,9 +1146,8 @@ impl<C: Fp256Parameters> Field for NewFp256<C> {
11501146
self
11511147
}
11521148
#[inline]
1153-
fn characteristic() -> &'static [u64] {
1154-
todo!()
1155-
// P::MODULUS.as_ref()
1149+
fn characteristic() -> &'static [u32] {
1150+
&C::MODULUS.0
11561151
}
11571152
#[inline]
11581153
fn from_random_bytes_with_flags<F: Flags>(bytes: &[u8]) -> Option<(Self, F)> {

0 commit comments

Comments
 (0)