|
1 | 1 | // use crate::constants::A_PLUS_TWO_OVER_FOUR;
|
2 | 2 | use crate::EdwardsScalar;
|
3 | 3 | use crate::edwards::extended::EdwardsPoint;
|
4 |
| -use crate::field::FieldElement; |
| 4 | +use crate::field::{ConstMontyType, FieldElement}; |
5 | 5 | use core::fmt;
|
6 | 6 | use core::ops::Mul;
|
| 7 | +use elliptic_curve::bigint::U448; |
7 | 8 | use subtle::{Choice, ConditionallyNegatable, ConditionallySelectable, ConstantTimeEq};
|
8 | 9 |
|
9 | 10 | impl MontgomeryXpoint {
|
@@ -231,6 +232,12 @@ impl ProjectiveMontgomeryXpoint {
|
231 | 232 | W: FieldElement::ZERO,
|
232 | 233 | };
|
233 | 234 |
|
| 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 | + |
234 | 241 | /// Compute the Y-coordinate
|
235 | 242 | // See https://www.rfc-editor.org/rfc/rfc7748#section-1.
|
236 | 243 | pub fn y(&self, sign: Choice) -> FieldElement {
|
@@ -258,14 +265,12 @@ mod tests {
|
258 | 265 | #[test]
|
259 | 266 | fn test_montgomery_edwards() {
|
260 | 267 | let scalar = EdwardsScalar::from(200u32);
|
261 |
| - use crate::GOLDILOCKS_BASE_POINT as bp; |
262 | 268 |
|
263 | 269 | // 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; |
266 | 271 |
|
267 | 272 | // Goldilocks scalar mul
|
268 |
| - let goldilocks_point = bp.scalar_mul(&scalar).scalar_mul(&scalar); |
| 273 | + let goldilocks_point = EdwardsPoint::GENERATOR * scalar * scalar; |
269 | 274 | assert_eq!(
|
270 | 275 | goldilocks_point.to_montgomery_x(),
|
271 | 276 | montgomery_res.to_affine()
|
|
0 commit comments