Skip to content

Commit ff8aeba

Browse files
committed
Make ProjectiveNielsPoint::identity() and associated constant
1 parent b120a04 commit ff8aeba

File tree

3 files changed

+27
-7
lines changed

3 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
@@ -23,7 +23,7 @@ impl From<&ExtendedPoint> for LookupTable {
2323
impl LookupTable {
2424
/// Selects a projective niels point from a lookup table in constant time
2525
pub fn select(&self, index: u32) -> ProjectiveNielsPoint {
26-
let mut result = ProjectiveNielsPoint::identity();
26+
let mut result = ProjectiveNielsPoint::IDENTITY;
2727

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

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

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

3-
use crate::curve::twedwards::extended::ExtendedPoint;
43
use crate::curve::twedwards::extensible::ExtensiblePoint;
54
use crate::field::FieldElement;
65
use subtle::{Choice, ConditionallyNegatable, ConditionallySelectable};
76

87
impl Default for ProjectiveNielsPoint {
98
fn default() -> ProjectiveNielsPoint {
10-
ProjectiveNielsPoint::identity()
9+
ProjectiveNielsPoint::IDENTITY
1110
}
1211
}
1312

1413
// Its a variant of Niels, where a Z coordinate is added for unmixed readdition
1514
// ((y+x)/2, (y-x)/2, dxy, Z)
16-
#[derive(Copy, Clone)]
15+
#[derive(Copy, Clone, Debug)]
1716
pub struct ProjectiveNielsPoint {
1817
pub(crate) Y_plus_X: FieldElement,
1918
pub(crate) Y_minus_X: FieldElement,
@@ -46,9 +45,12 @@ impl ConditionallyNegatable for ProjectiveNielsPoint {
4645
}
4746

4847
impl ProjectiveNielsPoint {
49-
pub fn identity() -> ProjectiveNielsPoint {
50-
ExtendedPoint::IDENTITY.to_projective_niels()
51-
}
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+
};
5254

5355
pub fn to_extensible(self) -> ExtensiblePoint {
5456
let A = self.Y_plus_X - self.Y_minus_X;
@@ -65,6 +67,23 @@ impl ProjectiveNielsPoint {
6567
#[cfg(test)]
6668
mod tests {
6769
use super::*;
70+
use crate::curve::twedwards::extended::ExtendedPoint;
71+
72+
#[test]
73+
fn identity() {
74+
// Internally are compared by converting to `ExtendedPoint`.
75+
// Here the right-side identity point is converted to Niel's
76+
// and then both sides are converted to twisted-curve form.
77+
assert_eq!(
78+
ProjectiveNielsPoint::IDENTITY,
79+
ExtendedPoint::IDENTITY.to_projective_niels(),
80+
);
81+
// Here only the left-side identity point is converted.
82+
assert_eq!(
83+
ProjectiveNielsPoint::IDENTITY.to_extensible(),
84+
ExtendedPoint::IDENTITY,
85+
);
86+
}
6887

6988
#[test]
7089
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)