Skip to content

Commit 64e4b43

Browse files
committed
Rename MontgomeryPoint fields from x|y to U|V
1 parent 7bb720f commit 64e4b43

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

ed448-goldilocks/src/montgomery/ops.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl Add<&MontgomeryPoint> for &ProjectiveMontgomeryPoint {
5959
// With "Trade-Off Technique".
6060
fn add(self, rhs: &MontgomeryPoint) -> ProjectiveMontgomeryPoint {
6161
let (x1, y1, z1) = (self.U, self.V, self.W);
62-
let (x2, y2) = (rhs.x, rhs.y);
62+
let (x2, y2) = (rhs.U, rhs.V);
6363

6464
let t0 = x1 * x2;
6565
let t1 = y1 * y2;
@@ -160,7 +160,7 @@ impl Mul<&MontgomeryScalar> for &MontgomeryPoint {
160160
fn mul(self, rhs: &MontgomeryScalar) -> ProjectiveMontgomeryPoint {
161161
pub const A2: FieldElement = FieldElement(ConstMontyType::new(&U448::from_u64(312652)));
162162

163-
let MontgomeryPoint { x: xP, y: yP } = self;
163+
let MontgomeryPoint { U: xP, V: yP } = self;
164164
let (
165165
ProjectiveMontgomeryXpoint { U: xQ, W: zQ },
166166
ProjectiveMontgomeryXpoint { U: xD, W: zD },

ed448-goldilocks/src/montgomery/point.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ use crate::{AffinePoint, Curve448, Curve448FieldBytes, ORDER};
2020
/// A point in Montgomery form including the y-coordinate.
2121
#[derive(Copy, Clone, Debug, Default, Eq)]
2222
pub struct MontgomeryPoint {
23-
pub(super) x: FieldElement,
24-
pub(super) y: FieldElement,
23+
pub(super) U: FieldElement,
24+
pub(super) V: FieldElement,
2525
}
2626

2727
impl MontgomeryPoint {
2828
/// The identity element of the group: the point at infinity.
2929
pub const IDENTITY: Self = Self {
30-
x: FieldElement::ZERO,
31-
y: FieldElement::ONE,
30+
U: FieldElement::ZERO,
31+
V: FieldElement::ONE,
3232
};
3333

34-
pub(crate) fn new(x: FieldElement, y: FieldElement) -> Self {
35-
Self { x, y }
34+
pub(crate) fn new(U: FieldElement, V: FieldElement) -> Self {
35+
Self { U, V }
3636
}
3737

3838
/// Generate a random [`MontgomeryPoint`].
@@ -56,15 +56,15 @@ impl MontgomeryPoint {
5656
impl ConditionallySelectable for MontgomeryPoint {
5757
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
5858
Self {
59-
x: FieldElement::conditional_select(&a.x, &b.x, choice),
60-
y: FieldElement::conditional_select(&a.y, &b.y, choice),
59+
U: FieldElement::conditional_select(&a.U, &b.U, choice),
60+
V: FieldElement::conditional_select(&a.V, &b.V, choice),
6161
}
6262
}
6363
}
6464

6565
impl ConstantTimeEq for MontgomeryPoint {
6666
fn ct_eq(&self, other: &Self) -> Choice {
67-
self.x.ct_eq(&other.x) & self.y.ct_eq(&other.y)
67+
self.U.ct_eq(&other.U) & self.V.ct_eq(&other.V)
6868
}
6969
}
7070

@@ -77,8 +77,8 @@ impl PartialEq for MontgomeryPoint {
7777
impl From<&MontgomeryPoint> for ProjectiveMontgomeryPoint {
7878
fn from(value: &MontgomeryPoint) -> Self {
7979
ProjectiveMontgomeryPoint {
80-
U: value.x,
81-
V: value.y,
80+
U: value.U,
81+
V: value.V,
8282
W: FieldElement::ONE,
8383
}
8484
}
@@ -92,7 +92,7 @@ impl From<MontgomeryPoint> for ProjectiveMontgomeryPoint {
9292

9393
impl From<&MontgomeryPoint> for MontgomeryXpoint {
9494
fn from(value: &MontgomeryPoint) -> Self {
95-
MontgomeryXpoint(value.x.to_bytes())
95+
MontgomeryXpoint(value.U.to_bytes())
9696
}
9797
}
9898

@@ -105,8 +105,8 @@ impl From<MontgomeryPoint> for MontgomeryXpoint {
105105
impl From<&MontgomeryPoint> for AffinePoint {
106106
// https://www.rfc-editor.org/rfc/rfc7748#section-4.2
107107
fn from(value: &MontgomeryPoint) -> AffinePoint {
108-
let x = value.x;
109-
let y = value.y;
108+
let x = value.U;
109+
let y = value.V;
110110
let mut t0 = x.square(); // x^2
111111
let t1 = t0 + FieldElement::ONE; // x^2+1
112112
t0 -= FieldElement::ONE; // x^2-1
@@ -161,23 +161,23 @@ impl AffineCoordinates for MontgomeryPoint {
161161
let right = x.square() * x + FieldElement::J * xx + x;
162162
let is_on_curve = left.ct_eq(&right);
163163

164-
CtOption::new(Self { x, y }, is_on_curve)
164+
CtOption::new(Self { U: x, V: y }, is_on_curve)
165165
}
166166

167167
fn x(&self) -> Self::FieldRepr {
168-
self.x.to_bytes().into()
168+
self.U.to_bytes().into()
169169
}
170170

171171
fn y(&self) -> Self::FieldRepr {
172-
self.y.to_bytes().into()
172+
self.V.to_bytes().into()
173173
}
174174

175175
fn x_is_odd(&self) -> Choice {
176-
self.x.is_negative()
176+
self.U.is_negative()
177177
}
178178

179179
fn y_is_odd(&self) -> Choice {
180-
self.y.is_negative()
180+
self.V.is_negative()
181181
}
182182
}
183183

@@ -269,10 +269,10 @@ impl PartialEq for ProjectiveMontgomeryPoint {
269269
impl From<&ProjectiveMontgomeryPoint> for MontgomeryPoint {
270270
fn from(value: &ProjectiveMontgomeryPoint) -> Self {
271271
let W_inv = value.W.invert();
272-
let x = value.U * W_inv;
273-
let y = value.V * W_inv;
272+
let U = value.U * W_inv;
273+
let V = value.V * W_inv;
274274

275-
MontgomeryPoint { x, y }
275+
MontgomeryPoint { U, V }
276276
}
277277
}
278278

@@ -417,10 +417,10 @@ impl CurveGroup for ProjectiveMontgomeryPoint {
417417

418418
fn to_affine(&self) -> Self::AffineRepr {
419419
let W_inv = self.W.invert();
420-
let x = self.U * W_inv;
421-
let y = self.V * W_inv;
420+
let U = self.U * W_inv;
421+
let V = self.V * W_inv;
422422

423-
MontgomeryPoint { x, y }
423+
MontgomeryPoint { U, V }
424424
}
425425
}
426426

@@ -432,9 +432,9 @@ impl GroupEncoding for ProjectiveMontgomeryPoint {
432432
let sign = bytes[0] & 1;
433433
bytes[0] &= 0xfe;
434434

435-
FieldElement::from_repr(&bytes).map(|x| {
435+
FieldElement::from_repr(&bytes).map(|U| {
436436
ProjectiveMontgomeryXpoint {
437-
U: x,
437+
U,
438438
W: FieldElement::ONE,
439439
}
440440
.to_extended(Choice::from(sign))
@@ -448,9 +448,9 @@ impl GroupEncoding for ProjectiveMontgomeryPoint {
448448

449449
fn to_bytes(&self) -> Self::Repr {
450450
let affine = self.to_affine();
451-
let mut bytes = affine.x.to_bytes();
451+
let mut bytes = affine.U.to_bytes();
452452

453-
if affine.y.is_negative().unwrap_u8() == 1 {
453+
if affine.V.is_negative().unwrap_u8() == 1 {
454454
bytes[0] |= 0x01;
455455
}
456456

0 commit comments

Comments
 (0)