Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ed448-goldilocks/src/edwards/affine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ impl AffinePoint {
}
}

/// Convert this point to [`MontgomeryPoint`]
// See https://www.rfc-editor.org/rfc/rfc7748#section-4.2 4-isogeny maps
pub fn to_montgomery(&self) -> MontgomeryPoint {
// u = y^2/x^2

// Simplified to:
// u = (y/x)^2
let u = (self.y * self.x.invert()).square();

MontgomeryPoint(u.to_bytes())
}

/// The X coordinate
pub fn x(&self) -> [u8; 56] {
self.x.to_bytes()
Expand Down
17 changes: 10 additions & 7 deletions ed448-goldilocks/src/edwards/extended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,16 +529,19 @@ impl EdwardsPoint {
};

/// Convert this point to [`MontgomeryPoint`]
// See https://www.rfc-editor.org/rfc/rfc7748#section-4.2 4-isogeny maps
pub fn to_montgomery(&self) -> MontgomeryPoint {
// u = y^2 * [(1-dy^2)/(1-y^2)]
// Affine map:
// (x, y) = (x/z, y/z)
// Edwards to montgomery:
// u = y^2/x^2

let affine = self.to_affine();

let yy = affine.y.square();
let dyy = FieldElement::EDWARDS_D * yy;

let u = yy * (FieldElement::ONE - dyy) * (FieldElement::ONE - yy).invert();
// Simplified to:
// u = (y/z)^2/(x/z)^2
// u = ((y/z)/(x/z))^2
// u = (y/x)^2

let u = (self.Y * self.X.invert()).square();
MontgomeryPoint(u.to_bytes())
}

Expand Down
14 changes: 14 additions & 0 deletions ed448-goldilocks/src/montgomery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,18 @@ mod tests {
let goldilocks_point = bp.scalar_mul(&scalar);
assert_eq!(goldilocks_point.to_montgomery(), montgomery_res);
}

#[test]
fn test_montgomery_edwards_affine() {
let scalar = EdwardsScalar::from(200u32);
use crate::GOLDILOCKS_BASE_POINT as bp;

// Montgomery scalar mul
let montgomery_bp = bp.to_affine().to_montgomery();
let montgomery_res = &montgomery_bp * &scalar;

// Goldilocks scalar mul
let goldilocks_point = bp.scalar_mul(&scalar).to_affine();
assert_eq!(goldilocks_point.to_montgomery(), montgomery_res);
}
}