|
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::ConstMontyType; |
4 | 5 | use crate::field::FieldElement;
|
5 | 6 | use core::fmt;
|
6 | 7 | use core::ops::Mul;
|
| 8 | +use elliptic_curve::bigint::U448; |
7 | 9 | use subtle::{Choice, ConditionallyNegatable, ConditionallySelectable, ConstantTimeEq};
|
8 | 10 |
|
9 | 11 | // Low order points on Curve448 and it's twist
|
@@ -227,6 +229,12 @@ impl ProjectiveMontgomeryXpoint {
|
227 | 229 | W: FieldElement::ZERO,
|
228 | 230 | };
|
229 | 231 |
|
| 232 | + /// The generator point |
| 233 | + pub const GENERATOR: Self = Self { |
| 234 | + U: FieldElement(ConstMontyType::new(&U448::from_u64(5))), |
| 235 | + W: FieldElement::ONE, |
| 236 | + }; |
| 237 | + |
230 | 238 | /// Compute the Y-coordinate
|
231 | 239 | // See https://www.rfc-editor.org/rfc/rfc7748#section-1.
|
232 | 240 | pub fn y(&self, sign: Choice) -> FieldElement {
|
@@ -254,14 +262,12 @@ mod tests {
|
254 | 262 | #[test]
|
255 | 263 | fn test_montgomery_edwards() {
|
256 | 264 | let scalar = EdwardsScalar::from(200u32);
|
257 |
| - use crate::GOLDILOCKS_BASE_POINT as bp; |
258 | 265 |
|
259 | 266 | // Montgomery scalar mul
|
260 |
| - let montgomery_bp = bp.to_montgomery_x(); |
261 |
| - let montgomery_res = &(&montgomery_bp * &scalar) * &scalar; |
| 267 | + let montgomery_res = &(&ProjectiveMontgomeryXpoint::GENERATOR * &scalar) * &scalar; |
262 | 268 |
|
263 | 269 | // Goldilocks scalar mul
|
264 |
| - let goldilocks_point = bp.scalar_mul(&scalar).scalar_mul(&scalar); |
| 270 | + let goldilocks_point = EdwardsPoint::GENERATOR * scalar * scalar; |
265 | 271 | assert_eq!(
|
266 | 272 | goldilocks_point.to_montgomery_x(),
|
267 | 273 | montgomery_res.to_affine()
|
|
0 commit comments