Skip to content

Commit 67e63ee

Browse files
committed
Correct U1 as the identity for CapacityUsed, not U0
1 parent 0a82375 commit 67e63ee

File tree

4 files changed

+37
-37
lines changed

4 files changed

+37
-37
lines changed

curve25519-dalek/src/hazmat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use core::{
88
};
99

1010
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
11-
use typenum::{U0, Unsigned};
11+
use typenum::{U1, Unsigned};
1212

1313
use ff::{Field, FromUniformBytes, PrimeField};
1414

@@ -37,7 +37,7 @@ pub struct OpaqueFieldElement(Underlying);
3737
/// Usage is recommended to be done via `LazyFieldWithCapacity<U3>` which is
3838
/// comprehensive to all backends.
3939
#[derive(Copy)]
40-
pub struct FieldElement<U: Unsigned = U0>(pub(crate) OpaqueFieldElement, pub(crate) PhantomData<U>);
40+
pub struct FieldElement<U: Unsigned = U1>(pub(crate) OpaqueFieldElement, pub(crate) PhantomData<U>);
4141
unsafe impl<U: Unsigned> Send for FieldElement<U> {}
4242
unsafe impl<U: Unsigned> Sync for FieldElement<U> {}
4343

curve25519-dalek/src/hazmat/lazy_field.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use core::{fmt::Debug, ops::Add};
44

55
use typenum::{
6-
B1, U0, Unsigned,
6+
B1, U1, Unsigned,
77
type_operators::{Cmp, IsLessOrEqual},
88
};
99

@@ -15,7 +15,7 @@ pub use eager::*;
1515
/// An element which can be reduced.
1616
pub trait Reducible {
1717
/// The reduced element.
18-
type Output: Field + LazyField<U0>;
18+
type Output: Field + LazyField<U1>;
1919
/// Reduce to a reduced element.
2020
fn reduce(&self) -> Self::Output;
2121
}
@@ -73,5 +73,5 @@ pub trait LazyField<CapacityUsed: Unsigned>:
7373
///
7474
/// `LazyFieldWithCapacity<U1>` is _recommended_ due to the widespread popularity of 255-bit
7575
/// fields.
76-
pub trait LazyFieldWithCapacity<U: Unsigned + Cmp<Self::Capacity>>: LazyField<U0> {}
77-
impl<U: Unsigned + Cmp<Self::Capacity>, F: LazyField<U0>> LazyFieldWithCapacity<U> for F {}
76+
pub trait LazyFieldWithCapacity<U: Unsigned + Cmp<Self::Capacity>>: LazyField<U1> {}
77+
impl<U: Unsigned + Cmp<Self::Capacity>, F: LazyField<U1>> LazyFieldWithCapacity<U> for F {}

curve25519-dalek/src/hazmat/lazy_field/eager.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use core::{
88
};
99

1010
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
11-
use typenum::{B1, U0, U256, Unsigned, type_operators::IsLessOrEqual};
11+
use typenum::{B1, U1, U256, Unsigned, type_operators::IsLessOrEqual};
1212

1313
use rand_core::{RngCore, TryRngCore};
1414

@@ -36,13 +36,13 @@ impl<U: Unsigned, F: Field> Debug for EagerField<U, F> {
3636
}
3737
}
3838

39-
impl<F: Field> EagerField<U0, F> {
39+
impl<F: Field> EagerField<U1, F> {
4040
const fn from(field: F) -> Self {
4141
Self(field, PhantomData)
4242
}
4343
}
4444

45-
impl<F: Field> ConditionallySelectable for EagerField<U0, F> {
45+
impl<F: Field> ConditionallySelectable for EagerField<U1, F> {
4646
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
4747
Self::from(<_>::conditional_select(&a.0, &b.0, choice))
4848
}
@@ -58,99 +58,99 @@ impl<U: Unsigned, F: Field> PartialEq for EagerField<U, F> {
5858
}
5959
}
6060
impl<U: Unsigned, F: Field> Eq for EagerField<U, F> {}
61-
impl<F: Field> Neg for EagerField<U0, F> {
61+
impl<F: Field> Neg for EagerField<U1, F> {
6262
type Output = Self;
6363
fn neg(self) -> Self {
6464
Self::from(self.0.neg())
6565
}
6666
}
67-
impl<F: Field> Add for EagerField<U0, F> {
67+
impl<F: Field> Add for EagerField<U1, F> {
6868
type Output = Self;
6969
fn add(self, other: Self) -> Self {
7070
Self::from(self.0.add(other.0))
7171
}
7272
}
73-
impl<F: Field> Sub for EagerField<U0, F> {
73+
impl<F: Field> Sub for EagerField<U1, F> {
7474
type Output = Self;
7575
fn sub(self, other: Self) -> Self {
7676
Self::from(self.0.sub(other.0))
7777
}
7878
}
79-
impl<F: Field> Mul for EagerField<U0, F> {
79+
impl<F: Field> Mul for EagerField<U1, F> {
8080
type Output = Self;
8181
fn mul(self, other: Self) -> Self {
8282
Self::from(self.0.mul(other.0))
8383
}
8484
}
85-
impl<F: Field> Sum for EagerField<U0, F> {
85+
impl<F: Field> Sum for EagerField<U1, F> {
8686
fn sum<I: Iterator<Item = Self>>(iter: I) -> Self {
8787
Self::from(F::sum(iter.map(|item| item.0)))
8888
}
8989
}
90-
impl<F: Field> Product for EagerField<U0, F> {
90+
impl<F: Field> Product for EagerField<U1, F> {
9191
fn product<I: Iterator<Item = Self>>(iter: I) -> Self {
9292
Self::from(F::product(iter.map(|item| item.0)))
9393
}
9494
}
95-
impl<'a, F: Field> Add<&'a Self> for EagerField<U0, F> {
95+
impl<'a, F: Field> Add<&'a Self> for EagerField<U1, F> {
9696
type Output = Self;
9797
fn add(self, other: &'a Self) -> Self {
9898
Self::from(self.0.add(&other.0))
9999
}
100100
}
101-
impl<'a, F: Field> Sub<&'a Self> for EagerField<U0, F> {
101+
impl<'a, F: Field> Sub<&'a Self> for EagerField<U1, F> {
102102
type Output = Self;
103103
fn sub(self, other: &'a Self) -> Self {
104104
Self::from(self.0.sub(&other.0))
105105
}
106106
}
107-
impl<'a, F: Field> Mul<&'a Self> for EagerField<U0, F> {
107+
impl<'a, F: Field> Mul<&'a Self> for EagerField<U1, F> {
108108
type Output = Self;
109109
fn mul(self, other: &'a Self) -> Self {
110110
Self::from(self.0.mul(&other.0))
111111
}
112112
}
113-
impl<'a, F: Field> Sum<&'a Self> for EagerField<U0, F> {
113+
impl<'a, F: Field> Sum<&'a Self> for EagerField<U1, F> {
114114
fn sum<I: Iterator<Item = &'a Self>>(iter: I) -> Self {
115115
Self::from(F::sum(iter.map(|item| &item.0)))
116116
}
117117
}
118-
impl<'a, F: Field> Product<&'a Self> for EagerField<U0, F> {
118+
impl<'a, F: Field> Product<&'a Self> for EagerField<U1, F> {
119119
fn product<I: Iterator<Item = &'a Self>>(iter: I) -> Self {
120120
Self::from(F::product(iter.map(|item| &item.0)))
121121
}
122122
}
123-
impl<F: Field> AddAssign for EagerField<U0, F> {
123+
impl<F: Field> AddAssign for EagerField<U1, F> {
124124
fn add_assign(&mut self, other: Self) {
125125
self.0.add_assign(other.0);
126126
}
127127
}
128-
impl<F: Field> SubAssign for EagerField<U0, F> {
128+
impl<F: Field> SubAssign for EagerField<U1, F> {
129129
fn sub_assign(&mut self, other: Self) {
130130
self.0.sub_assign(other.0);
131131
}
132132
}
133-
impl<F: Field> MulAssign for EagerField<U0, F> {
133+
impl<F: Field> MulAssign for EagerField<U1, F> {
134134
fn mul_assign(&mut self, other: Self) {
135135
self.0.mul_assign(other.0);
136136
}
137137
}
138-
impl<'a, F: Field> AddAssign<&'a Self> for EagerField<U0, F> {
138+
impl<'a, F: Field> AddAssign<&'a Self> for EagerField<U1, F> {
139139
fn add_assign(&mut self, other: &'a Self) {
140140
self.0.add_assign(&other.0);
141141
}
142142
}
143-
impl<'a, F: Field> SubAssign<&'a Self> for EagerField<U0, F> {
143+
impl<'a, F: Field> SubAssign<&'a Self> for EagerField<U1, F> {
144144
fn sub_assign(&mut self, other: &'a Self) {
145145
self.0.sub_assign(&other.0);
146146
}
147147
}
148-
impl<'a, F: Field> MulAssign<&'a Self> for EagerField<U0, F> {
148+
impl<'a, F: Field> MulAssign<&'a Self> for EagerField<U1, F> {
149149
fn mul_assign(&mut self, other: &'a Self) {
150150
self.0.mul_assign(&other.0);
151151
}
152152
}
153-
impl<F: Field> Field for EagerField<U0, F> {
153+
impl<F: Field> Field for EagerField<U1, F> {
154154
const ZERO: Self = Self::from(F::ZERO);
155155
const ONE: Self = Self::from(F::ONE);
156156
fn try_from_rng<R: TryRngCore + ?Sized>(rng: &mut R) -> Result<Self, R::Error> {
@@ -197,7 +197,7 @@ impl<F: Field> Field for EagerField<U0, F> {
197197
}
198198

199199
impl<U: Unsigned, F: Field> Reducible for EagerField<U, F> {
200-
type Output = EagerField<U0, F>;
200+
type Output = EagerField<U1, F>;
201201
fn reduce(&self) -> Self::Output {
202202
Self::Output::from(self.0)
203203
}

curve25519-dalek/src/hazmat/lazy_field25519.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use core::ops::Add;
22

3-
use typenum::{U0, Unsigned, type_operators::IsLessOrEqual};
3+
use typenum::{U1, Unsigned, type_operators::IsLessOrEqual};
44

55
use super::{FieldElement, OpaqueFieldElement, lazy_field::*};
66
use crate::field::FieldElement as Underlying;
77

8-
type ReducibleOutput = FieldElement<U0>;
8+
type ReducibleOutput = FieldElement<U1>;
99
impl<U: Unsigned> Reducible for FieldElement<U>
1010
where
1111
FieldElement<U>: LazyField<U>,
@@ -70,7 +70,7 @@ mod tests {
7070
use crate::hazmat::lazy_field::{EagerField, LazyField, LazyFieldWithCapacity, Reducible};
7171

7272
#[test]
73-
fn three_add_and_then_mul() {
73+
fn lazy_add_then_mul() {
7474
use crate::hazmat::FieldElement;
7575
use core::marker::PhantomData;
7676
use ff::Field;
@@ -88,13 +88,13 @@ mod tests {
8888
assert_eq!(a.add(&b).add(&c).mul(&d.add(&e).add(&f)), expected);
8989

9090
assert_eq!(
91-
EagerField(a, PhantomData::<typenum::U0>)
92-
.add(&EagerField(b, PhantomData::<typenum::U0>))
93-
.add(&EagerField(c, PhantomData::<typenum::U0>))
91+
EagerField(a, PhantomData::<typenum::U1>)
92+
.add(&EagerField(b, PhantomData::<typenum::U1>))
93+
.add(&EagerField(c, PhantomData::<typenum::U1>))
9494
.mul(
95-
&EagerField(d, PhantomData::<typenum::U0>)
96-
.add(&EagerField(e, PhantomData::<typenum::U0>))
97-
.add(&EagerField(f, PhantomData::<typenum::U0>))
95+
&EagerField(d, PhantomData::<typenum::U1>)
96+
.add(&EagerField(e, PhantomData::<typenum::U1>))
97+
.add(&EagerField(f, PhantomData::<typenum::U1>))
9898
)
9999
.0,
100100
expected

0 commit comments

Comments
 (0)