Skip to content

Commit d4e7a21

Browse files
committed
Add y-coordinate recovery
1 parent 729ab18 commit d4e7a21

File tree

1 file changed

+18
-1
lines changed
  • ed448-goldilocks/src/montgomery

1 file changed

+18
-1
lines changed

ed448-goldilocks/src/montgomery/x.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::edwards::extended::EdwardsPoint;
44
use crate::field::FieldElement;
55
use core::fmt;
66
use core::ops::Mul;
7-
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq};
7+
use subtle::{Choice, ConditionallyNegatable, ConditionallySelectable, ConstantTimeEq};
88

99
impl MontgomeryXpoint {
1010
/// First low order point on Curve448 and it's twist
@@ -131,6 +131,23 @@ impl MontgomeryXpoint {
131131
&self.0
132132
}
133133

134+
/// Compute the Y-coordinate
135+
pub fn y(&self, sign: Choice) -> [u8; 56] {
136+
self.y_internal(sign).to_bytes()
137+
}
138+
139+
// See https://www.rfc-editor.org/rfc/rfc7748#section-1.
140+
pub(super) fn y_internal(&self, sign: Choice) -> FieldElement {
141+
// v^2 = u^3 + A*u^2 + u
142+
let u = FieldElement::from_bytes(&self.0);
143+
let uu = u.square();
144+
let vv = uu * u + FieldElement::J * uu + u;
145+
146+
let mut v = vv.sqrt();
147+
v.conditional_negate(v.is_negative() ^ sign);
148+
v
149+
}
150+
134151
/// Convert the point to a ProjectiveMontgomeryPoint
135152
pub fn to_projective(&self) -> ProjectiveMontgomeryXpoint {
136153
ProjectiveMontgomeryXpoint {

0 commit comments

Comments
 (0)