Skip to content

Commit e2de5d6

Browse files
committed
Rename MontgomeryPoint fields from x|y to U|V
1 parent a51ac91 commit e2de5d6

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
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: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,34 @@ use crate::{AffinePoint, Curve448, Curve448FieldBytes, ORDER};
2525
/// A point in Montgomery form including the y-coordinate.
2626
#[derive(Copy, Clone, Debug, Default, Eq)]
2727
pub struct MontgomeryPoint {
28-
pub(super) x: FieldElement,
29-
pub(super) y: FieldElement,
28+
pub(super) U: FieldElement,
29+
pub(super) V: FieldElement,
3030
}
3131

3232
impl MontgomeryPoint {
3333
/// The identity element of the group: the point at infinity.
3434
pub const IDENTITY: Self = Self {
35-
x: FieldElement::ZERO,
36-
y: FieldElement::ONE,
35+
U: FieldElement::ZERO,
36+
V: FieldElement::ONE,
3737
};
3838

39-
pub(crate) fn new(x: FieldElement, y: FieldElement) -> Self {
40-
Self { x, y }
39+
pub(crate) fn new(U: FieldElement, V: FieldElement) -> Self {
40+
Self { U, V }
4141
}
4242
}
4343

4444
impl ConditionallySelectable for MontgomeryPoint {
4545
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
4646
Self {
47-
x: FieldElement::conditional_select(&a.x, &b.x, choice),
48-
y: FieldElement::conditional_select(&a.y, &b.y, choice),
47+
U: FieldElement::conditional_select(&a.U, &b.U, choice),
48+
V: FieldElement::conditional_select(&a.V, &b.V, choice),
4949
}
5050
}
5151
}
5252

5353
impl ConstantTimeEq for MontgomeryPoint {
5454
fn ct_eq(&self, other: &Self) -> Choice {
55-
self.x.ct_eq(&other.x) & self.y.ct_eq(&other.y)
55+
self.U.ct_eq(&other.U) & self.V.ct_eq(&other.V)
5656
}
5757
}
5858

@@ -65,8 +65,8 @@ impl PartialEq for MontgomeryPoint {
6565
impl From<&MontgomeryPoint> for ProjectiveMontgomeryPoint {
6666
fn from(value: &MontgomeryPoint) -> Self {
6767
ProjectiveMontgomeryPoint {
68-
U: value.x,
69-
V: value.y,
68+
U: value.U,
69+
V: value.V,
7070
W: FieldElement::ONE,
7171
}
7272
}
@@ -80,7 +80,7 @@ impl From<MontgomeryPoint> for ProjectiveMontgomeryPoint {
8080

8181
impl From<&MontgomeryPoint> for MontgomeryXpoint {
8282
fn from(value: &MontgomeryPoint) -> Self {
83-
MontgomeryXpoint(value.x.to_bytes())
83+
MontgomeryXpoint(value.U.to_bytes())
8484
}
8585
}
8686

@@ -93,8 +93,8 @@ impl From<MontgomeryPoint> for MontgomeryXpoint {
9393
impl From<&MontgomeryPoint> for AffinePoint {
9494
// https://www.rfc-editor.org/rfc/rfc7748#section-4.2
9595
fn from(value: &MontgomeryPoint) -> AffinePoint {
96-
let x = value.x;
97-
let y = value.y;
96+
let x = value.U;
97+
let y = value.V;
9898
let mut t0 = x.square(); // x^2
9999
let t1 = t0 + FieldElement::ONE; // x^2+1
100100
t0 -= FieldElement::ONE; // x^2-1
@@ -140,19 +140,19 @@ impl AffineCoordinates for MontgomeryPoint {
140140
type FieldRepr = Curve448FieldBytes;
141141

142142
fn x(&self) -> Self::FieldRepr {
143-
self.x.to_bytes().into()
143+
self.U.to_bytes().into()
144144
}
145145

146146
fn y(&self) -> Self::FieldRepr {
147-
self.y.to_bytes().into()
147+
self.V.to_bytes().into()
148148
}
149149

150150
fn x_is_odd(&self) -> Choice {
151-
self.x.is_negative()
151+
self.U.is_negative()
152152
}
153153

154154
fn y_is_odd(&self) -> Choice {
155-
self.y.is_negative()
155+
self.V.is_negative()
156156
}
157157
}
158158

@@ -259,10 +259,10 @@ impl PartialEq for ProjectiveMontgomeryPoint {
259259
impl From<&ProjectiveMontgomeryPoint> for MontgomeryPoint {
260260
fn from(value: &ProjectiveMontgomeryPoint) -> Self {
261261
let W_inv = value.W.invert();
262-
let x = value.U * W_inv;
263-
let y = value.V * W_inv;
262+
let U = value.U * W_inv;
263+
let V = value.V * W_inv;
264264

265-
MontgomeryPoint { x, y }
265+
MontgomeryPoint { U, V }
266266
}
267267
}
268268

@@ -404,10 +404,10 @@ impl CurveGroup for ProjectiveMontgomeryPoint {
404404

405405
fn to_affine(&self) -> Self::AffineRepr {
406406
let W_inv = self.W.invert();
407-
let x = self.U * W_inv;
408-
let y = self.V * W_inv;
407+
let U = self.U * W_inv;
408+
let V = self.V * W_inv;
409409

410-
MontgomeryPoint { x, y }
410+
MontgomeryPoint { U, V }
411411
}
412412
}
413413

@@ -427,10 +427,10 @@ impl GroupEncoding for ProjectiveMontgomeryPoint {
427427
_ => (Choice::from(0), Choice::from(0)),
428428
};
429429

430-
FieldElement::from_repr(&x_bytes).and_then(|x| {
430+
FieldElement::from_repr(&x_bytes).and_then(|U| {
431431
CtOption::new(
432432
ProjectiveMontgomeryXpoint {
433-
U: x,
433+
U,
434434
W: FieldElement::ONE,
435435
}
436436
.to_extended(sign),
@@ -448,13 +448,13 @@ impl GroupEncoding for ProjectiveMontgomeryPoint {
448448
let affine = self.to_affine();
449449
let mut compressed_bytes = Array::default();
450450

451-
compressed_bytes[0] = if affine.y.is_negative().unwrap_u8() == 1 {
451+
compressed_bytes[0] = if affine.V.is_negative().unwrap_u8() == 1 {
452452
0x03
453453
} else {
454454
0x02
455455
};
456456

457-
compressed_bytes[1..].copy_from_slice(&affine.x.to_bytes()[..]);
457+
compressed_bytes[1..].copy_from_slice(&affine.U.to_bytes()[..]);
458458
compressed_bytes
459459
}
460460
}

0 commit comments

Comments
 (0)