Skip to content

Commit 20a4e6b

Browse files
committed
Add ProjectiveMontgomeryXpoint::GENERATOR
1 parent 9513636 commit 20a4e6b

File tree

1 file changed

+10
-5
lines changed
  • ed448-goldilocks/src/montgomery

1 file changed

+10
-5
lines changed

ed448-goldilocks/src/montgomery/x.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// use crate::constants::A_PLUS_TWO_OVER_FOUR;
22
use crate::EdwardsScalar;
33
use crate::edwards::extended::EdwardsPoint;
4-
use crate::field::FieldElement;
4+
use crate::field::{ConstMontyType, FieldElement};
55
use core::fmt;
66
use core::ops::Mul;
7+
use elliptic_curve::bigint::U448;
78
use subtle::{Choice, ConditionallyNegatable, ConditionallySelectable, ConstantTimeEq};
89

910
impl MontgomeryXpoint {
@@ -231,6 +232,12 @@ impl ProjectiveMontgomeryXpoint {
231232
W: FieldElement::ZERO,
232233
};
233234

235+
/// The generator point
236+
pub const GENERATOR: Self = Self {
237+
U: FieldElement(ConstMontyType::new(&U448::from_u64(5))),
238+
W: FieldElement::ONE,
239+
};
240+
234241
/// Compute the Y-coordinate
235242
// See https://www.rfc-editor.org/rfc/rfc7748#section-1.
236243
pub fn y(&self, sign: Choice) -> FieldElement {
@@ -258,14 +265,12 @@ mod tests {
258265
#[test]
259266
fn test_montgomery_edwards() {
260267
let scalar = EdwardsScalar::from(200u32);
261-
use crate::GOLDILOCKS_BASE_POINT as bp;
262268

263269
// Montgomery scalar mul
264-
let montgomery_bp = bp.to_montgomery_x();
265-
let montgomery_res = &(&montgomery_bp * &scalar) * &scalar;
270+
let montgomery_res = &(&ProjectiveMontgomeryXpoint::GENERATOR * &scalar) * &scalar;
266271

267272
// Goldilocks scalar mul
268-
let goldilocks_point = bp.scalar_mul(&scalar).scalar_mul(&scalar);
273+
let goldilocks_point = EdwardsPoint::GENERATOR * scalar * scalar;
269274
assert_eq!(
270275
goldilocks_point.to_montgomery_x(),
271276
montgomery_res.to_affine()

0 commit comments

Comments
 (0)