Skip to content

Commit a988df0

Browse files
committed
Rename to MontgomeryPoint to MontgomeryXpoint
1 parent 9e8656b commit a988df0

File tree

3 files changed

+45
-45
lines changed

3 files changed

+45
-45
lines changed

ed448-goldilocks/src/edwards/extended.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,8 @@ impl EdwardsPoint {
532532
T: FieldElement::ZERO,
533533
};
534534

535-
/// Convert this point to [`MontgomeryPoint`]
536-
pub fn to_montgomery(&self) -> MontgomeryPoint {
535+
/// Convert this point to [`MontgomeryXpoint`]
536+
pub fn to_montgomery_x(&self) -> MontgomeryXpoint {
537537
// u = y^2 * [(1-dy^2)/(1-y^2)]
538538

539539
let affine = self.to_affine();
@@ -543,7 +543,7 @@ impl EdwardsPoint {
543543

544544
let u = yy * (FieldElement::ONE - dyy) * (FieldElement::ONE - yy).invert();
545545

546-
MontgomeryPoint(u.to_bytes())
546+
MontgomeryXpoint(u.to_bytes())
547547
}
548548

549549
/// Generic scalar multiplication to compute s*P

ed448-goldilocks/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub use edwards::{
6060
WideEdwardsScalarBytes,
6161
};
6262
pub use field::{MODULUS_LIMBS, ORDER, Scalar, WIDE_ORDER};
63-
pub use montgomery::{MontgomeryPoint, ProjectiveMontgomeryPoint};
63+
pub use montgomery::{MontgomeryXpoint, ProjectiveMontgomeryXpoint};
6464
#[cfg(feature = "signing")]
6565
pub use sign::*;
6666

ed448-goldilocks/src/montgomery.rs

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@ use core::fmt;
1818
use core::ops::Mul;
1919
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq};
2020

21-
impl MontgomeryPoint {
21+
impl MontgomeryXpoint {
2222
/// First low order point on Curve448 and it's twist
23-
pub const LOW_A: MontgomeryPoint = MontgomeryPoint([
23+
pub const LOW_A: MontgomeryXpoint = MontgomeryXpoint([
2424
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2525
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2626
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2727
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2828
]);
2929
/// Second low order point on Curve448 and it's twist
30-
pub const LOW_B: MontgomeryPoint = MontgomeryPoint([
30+
pub const LOW_B: MontgomeryXpoint = MontgomeryXpoint([
3131
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3232
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3333
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3434
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3535
]);
3636
/// Third low order point on Curve448 and it's twist
37-
pub const LOW_C: MontgomeryPoint = MontgomeryPoint([
37+
pub const LOW_C: MontgomeryXpoint = MontgomeryXpoint([
3838
0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3939
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff,
4040
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
@@ -44,51 +44,51 @@ impl MontgomeryPoint {
4444

4545
/// A point in Montgomery form
4646
#[derive(Copy, Clone)]
47-
pub struct MontgomeryPoint(pub [u8; 56]);
47+
pub struct MontgomeryXpoint(pub [u8; 56]);
4848

49-
impl Default for MontgomeryPoint {
50-
fn default() -> MontgomeryPoint {
49+
impl Default for MontgomeryXpoint {
50+
fn default() -> MontgomeryXpoint {
5151
Self([0u8; 56])
5252
}
5353
}
5454

55-
impl elliptic_curve::zeroize::DefaultIsZeroes for MontgomeryPoint {}
55+
impl elliptic_curve::zeroize::DefaultIsZeroes for MontgomeryXpoint {}
5656

57-
impl fmt::Debug for MontgomeryPoint {
57+
impl fmt::Debug for MontgomeryXpoint {
5858
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
5959
self.0[..].fmt(formatter)
6060
}
6161
}
6262

63-
impl ConstantTimeEq for MontgomeryPoint {
64-
fn ct_eq(&self, other: &MontgomeryPoint) -> Choice {
63+
impl ConstantTimeEq for MontgomeryXpoint {
64+
fn ct_eq(&self, other: &MontgomeryXpoint) -> Choice {
6565
self.0.ct_eq(&other.0)
6666
}
6767
}
6868

69-
impl PartialEq for MontgomeryPoint {
70-
fn eq(&self, other: &MontgomeryPoint) -> bool {
69+
impl PartialEq for MontgomeryXpoint {
70+
fn eq(&self, other: &MontgomeryXpoint) -> bool {
7171
self.ct_eq(other).into()
7272
}
7373
}
74-
impl Eq for MontgomeryPoint {}
74+
impl Eq for MontgomeryXpoint {}
7575

7676
/// A Projective point in Montgomery form
7777
#[derive(Copy, Clone, Debug)]
78-
pub struct ProjectiveMontgomeryPoint {
78+
pub struct ProjectiveMontgomeryXpoint {
7979
U: FieldElement,
8080
W: FieldElement,
8181
}
8282

83-
impl Mul<&EdwardsScalar> for &MontgomeryPoint {
84-
type Output = MontgomeryPoint;
83+
impl Mul<&EdwardsScalar> for &MontgomeryXpoint {
84+
type Output = MontgomeryXpoint;
8585

8686
#[allow(clippy::suspicious_arithmetic_impl)]
87-
fn mul(self, scalar: &EdwardsScalar) -> MontgomeryPoint {
87+
fn mul(self, scalar: &EdwardsScalar) -> MontgomeryXpoint {
8888
// Algorithm 8 of Costello-Smith 2017
8989
let affine_u = FieldElement::from_bytes(&self.0);
90-
let mut x0 = ProjectiveMontgomeryPoint::identity();
91-
let mut x1 = ProjectiveMontgomeryPoint {
90+
let mut x0 = ProjectiveMontgomeryXpoint::identity();
91+
let mut x1 = ProjectiveMontgomeryXpoint {
9292
U: affine_u,
9393
W: FieldElement::ONE,
9494
};
@@ -99,7 +99,7 @@ impl Mul<&EdwardsScalar> for &MontgomeryPoint {
9999
let bit = bits[s] as u8;
100100
let choice: u8 = swap ^ bit;
101101

102-
ProjectiveMontgomeryPoint::conditional_swap(&mut x0, &mut x1, Choice::from(choice));
102+
ProjectiveMontgomeryXpoint::conditional_swap(&mut x0, &mut x1, Choice::from(choice));
103103
differential_add_and_double(&mut x0, &mut x1, &affine_u);
104104

105105
swap = bit;
@@ -109,15 +109,15 @@ impl Mul<&EdwardsScalar> for &MontgomeryPoint {
109109
}
110110
}
111111

112-
impl Mul<&MontgomeryPoint> for &EdwardsScalar {
113-
type Output = MontgomeryPoint;
112+
impl Mul<&MontgomeryXpoint> for &EdwardsScalar {
113+
type Output = MontgomeryXpoint;
114114

115-
fn mul(self, point: &MontgomeryPoint) -> MontgomeryPoint {
115+
fn mul(self, point: &MontgomeryXpoint) -> MontgomeryXpoint {
116116
point * self
117117
}
118118
}
119119

120-
impl MontgomeryPoint {
120+
impl MontgomeryXpoint {
121121
/// Returns the generator specified in RFC7748
122122
pub const GENERATOR: Self = Self([
123123
0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -144,30 +144,30 @@ impl MontgomeryPoint {
144144
}
145145

146146
/// Convert the point to a ProjectiveMontgomeryPoint
147-
pub fn to_projective(&self) -> ProjectiveMontgomeryPoint {
148-
ProjectiveMontgomeryPoint {
147+
pub fn to_projective(&self) -> ProjectiveMontgomeryXpoint {
148+
ProjectiveMontgomeryXpoint {
149149
U: FieldElement::from_bytes(&self.0),
150150
W: FieldElement::ONE,
151151
}
152152
}
153153
}
154154

155-
impl ConditionallySelectable for ProjectiveMontgomeryPoint {
155+
impl ConditionallySelectable for ProjectiveMontgomeryXpoint {
156156
fn conditional_select(
157-
a: &ProjectiveMontgomeryPoint,
158-
b: &ProjectiveMontgomeryPoint,
157+
a: &ProjectiveMontgomeryXpoint,
158+
b: &ProjectiveMontgomeryXpoint,
159159
choice: Choice,
160-
) -> ProjectiveMontgomeryPoint {
161-
ProjectiveMontgomeryPoint {
160+
) -> ProjectiveMontgomeryXpoint {
161+
ProjectiveMontgomeryXpoint {
162162
U: FieldElement::conditional_select(&a.U, &b.U, choice),
163163
W: FieldElement::conditional_select(&a.W, &b.W, choice),
164164
}
165165
}
166166
}
167167

168168
fn differential_add_and_double(
169-
P: &mut ProjectiveMontgomeryPoint,
170-
Q: &mut ProjectiveMontgomeryPoint,
169+
P: &mut ProjectiveMontgomeryXpoint,
170+
Q: &mut ProjectiveMontgomeryXpoint,
171171
affine_PmQ: &FieldElement,
172172
) {
173173
let t0 = P.U + P.W;
@@ -203,19 +203,19 @@ fn differential_add_and_double(
203203
Q.W = t17; // W_{Q'} = U_D * 4 (W_P U_Q - U_P W_Q)^2
204204
}
205205

206-
impl ProjectiveMontgomeryPoint {
206+
impl ProjectiveMontgomeryXpoint {
207207
/// The identity element of the group: the point at infinity.
208-
pub fn identity() -> ProjectiveMontgomeryPoint {
209-
ProjectiveMontgomeryPoint {
208+
pub fn identity() -> ProjectiveMontgomeryXpoint {
209+
ProjectiveMontgomeryXpoint {
210210
U: FieldElement::ONE,
211211
W: FieldElement::ZERO,
212212
}
213213
}
214214

215215
/// Convert the point to affine form
216-
pub fn to_affine(&self) -> MontgomeryPoint {
216+
pub fn to_affine(&self) -> MontgomeryXpoint {
217217
let x = self.U * self.W.invert();
218-
MontgomeryPoint(x.to_bytes())
218+
MontgomeryXpoint(x.to_bytes())
219219
}
220220
}
221221

@@ -230,11 +230,11 @@ mod tests {
230230
use crate::GOLDILOCKS_BASE_POINT as bp;
231231

232232
// Montgomery scalar mul
233-
let montgomery_bp = bp.to_montgomery();
233+
let montgomery_bp = bp.to_montgomery_x();
234234
let montgomery_res = &montgomery_bp * &scalar;
235235

236236
// Goldilocks scalar mul
237237
let goldilocks_point = bp.scalar_mul(&scalar);
238-
assert_eq!(goldilocks_point.to_montgomery(), montgomery_res);
238+
assert_eq!(goldilocks_point.to_montgomery_x(), montgomery_res);
239239
}
240240
}

0 commit comments

Comments
 (0)