Skip to content

Commit 28ec035

Browse files
authored
elliptic-curve: bump ff and group to v0.13 (#1166)
1 parent 4457586 commit 28ec035

File tree

6 files changed

+69
-32
lines changed

6 files changed

+69
-32
lines changed

Cargo.lock

Lines changed: 23 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

elliptic-curve/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ zeroize = { version = "1.5", default-features = false }
2727
# optional dependencies
2828
base64ct = { version = "1", optional = true, default-features = false }
2929
digest = { version = "0.10", optional = true }
30-
ff = { version = "0.12", optional = true, default-features = false }
31-
group = { version = "0.12", optional = true, default-features = false }
30+
ff = { version = "0.13", optional = true, default-features = false }
31+
group = { version = "0.13", optional = true, default-features = false }
3232
hkdf = { version = "0.12", optional = true, default-features = false }
3333
hex-literal = { version = "0.3", optional = true }
3434
pem-rfc7468 = { version = "0.6", optional = true }

elliptic-curve/src/dev.rs

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ use crate::{
1616
ScalarArithmetic,
1717
};
1818
use core::{
19-
iter::Sum,
19+
iter::{Product, Sum},
2020
ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign},
2121
};
2222
use ff::{Field, PrimeField};
23-
use generic_array::arr;
2423
use hex_literal::hex;
2524
use pkcs8::AssociatedOid;
2625

@@ -102,6 +101,9 @@ impl JwkParameters for MockCurve {
102101
pub struct Scalar(ScalarCore);
103102

104103
impl Field for Scalar {
104+
const ZERO: Self = Self(ScalarCore::ZERO);
105+
const ONE: Self = Self(ScalarCore::ONE);
106+
105107
fn random(mut rng: impl RngCore) -> Self {
106108
let mut bytes = FieldBytes::default();
107109

@@ -113,14 +115,6 @@ impl Field for Scalar {
113115
}
114116
}
115117

116-
fn zero() -> Self {
117-
Self(ScalarCore::ZERO)
118-
}
119-
120-
fn one() -> Self {
121-
Self(ScalarCore::ONE)
122-
}
123-
124118
fn is_zero(&self) -> Choice {
125119
self.0.is_zero()
126120
}
@@ -142,14 +136,25 @@ impl Field for Scalar {
142136
fn sqrt(&self) -> CtOption<Self> {
143137
unimplemented!();
144138
}
139+
140+
fn sqrt_ratio(_num: &Self, _div: &Self) -> (Choice, Self) {
141+
unimplemented!();
142+
}
145143
}
146144

147145
impl PrimeField for Scalar {
148146
type Repr = FieldBytes;
149147

148+
const MODULUS: &'static str =
149+
"0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff";
150150
const NUM_BITS: u32 = 256;
151151
const CAPACITY: u32 = 255;
152+
const TWO_INV: Self = Self::ZERO; // BOGUS!
153+
const MULTIPLICATIVE_GENERATOR: Self = Self::ZERO; // BOGUS! Should be 7
152154
const S: u32 = 4;
155+
const ROOT_OF_UNITY: Self = Self::ZERO; // BOGUS! Should be 0xffc97f062a770992ba807ace842a3dfc1546cad004378daf0592d7fbb41e6602
156+
const ROOT_OF_UNITY_INV: Self = Self::ZERO; // BOGUS!
157+
const DELTA: Self = Self::ZERO; // BOGUS!
153158

154159
fn from_repr(bytes: FieldBytes) -> CtOption<Self> {
155160
ScalarCore::from_be_bytes(bytes).map(Self)
@@ -162,19 +167,6 @@ impl PrimeField for Scalar {
162167
fn is_odd(&self) -> Choice {
163168
self.0.is_odd()
164169
}
165-
166-
fn multiplicative_generator() -> Self {
167-
7u64.into()
168-
}
169-
170-
fn root_of_unity() -> Self {
171-
Self::from_repr(arr![u8;
172-
0xff, 0xc9, 0x7f, 0x06, 0x2a, 0x77, 0x09, 0x92, 0xba, 0x80, 0x7a, 0xce, 0x84, 0x2a,
173-
0x3d, 0xfc, 0x15, 0x46, 0xca, 0xd0, 0x04, 0x37, 0x8d, 0xaf, 0x05, 0x92, 0xd7, 0xfb,
174-
0xb4, 0x1e, 0x66, 0x02,
175-
])
176-
.unwrap()
177-
}
178170
}
179171

180172
#[cfg(feature = "bits")]
@@ -314,6 +306,30 @@ impl Neg for Scalar {
314306
}
315307
}
316308

309+
impl Sum for Scalar {
310+
fn sum<I: Iterator<Item = Self>>(_iter: I) -> Self {
311+
unimplemented!();
312+
}
313+
}
314+
315+
impl<'a> Sum<&'a Scalar> for Scalar {
316+
fn sum<I: Iterator<Item = &'a Scalar>>(_iter: I) -> Self {
317+
unimplemented!();
318+
}
319+
}
320+
321+
impl Product for Scalar {
322+
fn product<I: Iterator<Item = Self>>(_iter: I) -> Self {
323+
unimplemented!();
324+
}
325+
}
326+
327+
impl<'a> Product<&'a Scalar> for Scalar {
328+
fn product<I: Iterator<Item = &'a Scalar>>(_iter: I) -> Self {
329+
unimplemented!();
330+
}
331+
}
332+
317333
impl Reduce<U256> for Scalar {
318334
fn from_uint_reduced(w: U256) -> Self {
319335
let (r, underflow) = w.sbb(&MockCurve::ORDER, Limb::ZERO);

elliptic-curve/src/hash2curve/isogeny.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub trait Isogeny: Field + AddAssign + Mul<Output = Self> {
2828
/// Map from the isogeny points to the main curve
2929
fn isogeny(x: Self, y: Self) -> (Self, Self) {
3030
let mut xs = GenericArray::<Self, Self::Degree>::default();
31-
xs[0] = Self::one();
31+
xs[0] = Self::ONE;
3232
xs[1] = x;
3333
xs[2] = x.square();
3434
for i in 3..Self::Degree::to_usize() {
@@ -48,7 +48,7 @@ pub trait Isogeny: Field + AddAssign + Mul<Output = Self> {
4848

4949
/// Compute the ISO transform
5050
fn compute_iso(xxs: &[Self], k: &[Self]) -> Self {
51-
let mut xx = Self::zero();
51+
let mut xx = Self::ZERO;
5252
for (xi, ki) in xxs.iter().zip(k.iter()) {
5353
xx += *xi * ki;
5454
}

elliptic-curve/src/hash2curve/osswu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub trait OsswuMap: Field + Sgn0 {
4646
let tv3 = Self::PARAMS.z * tv1; // Z * u^2
4747
let mut tv2 = tv3.square(); // tv3^2
4848
let mut xd = tv2 + tv3; // tv3^2 + tv3
49-
let x1n = Self::PARAMS.map_b * (xd + Self::one()); // B * (xd + 1)
49+
let x1n = Self::PARAMS.map_b * (xd + Self::ONE); // B * (xd + 1)
5050
xd *= -Self::PARAMS.map_a; // -A * xd
5151

5252
let tv = Self::PARAMS.z * Self::PARAMS.map_a;

elliptic-curve/src/scalar/nonzero.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ where
282282

283283
// Write a 1 instead of a 0 to ensure this type's non-zero invariant
284284
// is upheld.
285-
self.scalar = Scalar::<C>::one();
285+
self.scalar = Scalar::<C>::ONE;
286286
}
287287
}
288288

@@ -348,6 +348,6 @@ mod tests {
348348
fn zeroize() {
349349
let mut scalar = NonZeroScalar::new(Scalar::from(42u64)).unwrap();
350350
scalar.zeroize();
351-
assert_eq!(*scalar, Scalar::one());
351+
assert_eq!(*scalar, Scalar::ONE);
352352
}
353353
}

0 commit comments

Comments
 (0)