Skip to content

Commit 5653757

Browse files
committed
Make ProjectiveNielsPoint::identity() and associated constant
1 parent 20eeeff commit 5653757

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

ed448-goldilocks/src/curve/scalar_mul/window/wnaf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl From<&ExtendedPoint> for LookupTable {
2222
impl LookupTable {
2323
/// Selects a projective niels point from a lookup table in constant time
2424
pub fn select(&self, index: u32) -> ProjectiveNielsPoint {
25-
let mut result = ProjectiveNielsPoint::identity();
25+
let mut result = ProjectiveNielsPoint::IDENTITY;
2626

2727
for i in 1..9 {
2828
let swap = index.ct_eq(&(i as u32));

ed448-goldilocks/src/curve/twedwards/projective.rs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#![allow(non_snake_case)]
22

3-
use crate::curve::twedwards::{extended::ExtendedPoint, extensible::ExtensiblePoint};
3+
use crate::curve::twedwards::extended::ExtendedPoint;
44
use crate::field::FieldElement;
55
use subtle::{Choice, ConditionallyNegatable, ConditionallySelectable};
66

77
impl Default for ProjectiveNielsPoint {
88
fn default() -> ProjectiveNielsPoint {
9-
ProjectiveNielsPoint::identity()
9+
ProjectiveNielsPoint::IDENTITY
1010
}
1111
}
1212

1313
// Its a variant of Niels, where a Z coordinate is added for unmixed readdition
1414
// ((y+x)/2, (y-x)/2, dxy, Z)
15-
#[derive(Copy, Clone)]
15+
#[derive(Copy, Clone, Debug)]
1616
pub struct ProjectiveNielsPoint {
1717
pub(crate) Y_plus_X: FieldElement,
1818
pub(crate) Y_minus_X: FieldElement,
@@ -45,9 +45,12 @@ impl ConditionallyNegatable for ProjectiveNielsPoint {
4545
}
4646

4747
impl ProjectiveNielsPoint {
48-
pub fn identity() -> ProjectiveNielsPoint {
49-
ExtensiblePoint::IDENTITY.to_projective_niels()
50-
}
48+
pub const IDENTITY: ProjectiveNielsPoint = ProjectiveNielsPoint {
49+
Y_plus_X: FieldElement::ONE,
50+
Y_minus_X: FieldElement::ONE,
51+
Td: FieldElement::ZERO,
52+
Z: FieldElement::TWO,
53+
};
5154

5255
pub fn to_extended(self) -> ExtendedPoint {
5356
let A = self.Y_plus_X - self.Y_minus_X;
@@ -63,6 +66,23 @@ impl ProjectiveNielsPoint {
6366
#[cfg(test)]
6467
mod tests {
6568
use super::*;
69+
use crate::curve::twedwards::extensible::ExtensiblePoint;
70+
71+
#[test]
72+
fn identity() {
73+
// Internally are compared by converting to `ExtendedPoint`.
74+
// Here the right-side identity point is converted to Niel's
75+
// and then both sides are converted to twisted-curve form.
76+
assert_eq!(
77+
ProjectiveNielsPoint::IDENTITY,
78+
ExtensiblePoint::IDENTITY.to_projective_niels(),
79+
);
80+
// Here only the left-side identity point is converted.
81+
assert_eq!(
82+
ProjectiveNielsPoint::IDENTITY.to_extended(),
83+
ExtendedPoint::IDENTITY,
84+
);
85+
}
6686

6787
#[test]
6888
fn test_conditional_negate() {

ed448-goldilocks/src/field/element.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ impl FieldElement {
246246
"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000262a8",
247247
)));
248248
pub const ONE: Self = Self(ConstMontyType::new(&U448::ONE));
249+
pub const TWO: Self = Self(ConstMontyType::new(&U448::from_u64(2)));
249250
pub const TWISTED_D: Self = Self(ConstMontyType::new(&U448::from_be_hex(
250251
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffffffffffffffffffffffffffffffffffffffffffffffff6755",
251252
)));

0 commit comments

Comments
 (0)