Skip to content

Commit 45db96f

Browse files
committed
Make ProjectiveNielsPoint::identity() and associated constant
1 parent e25ccd1 commit 45db96f

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-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() {

0 commit comments

Comments
 (0)