diff --git a/src/curve.rs b/src/curve.rs index 3a5ab52..ca3e4a1 100644 --- a/src/curve.rs +++ b/src/curve.rs @@ -890,6 +890,13 @@ impl EdwardsBasepointTable { } table } + + /// Get the basepoint for this table as an `ExtendedPoint`. + pub fn basepoint(&self) -> ExtendedPoint { + // self.0[0][0] has 1*(16^2)^0*B, but as an `AffineNielsPoint` + // Add identity to convert to extended. + (&ExtendedPoint::identity() + &self.0[0][0]).to_extended() + } } impl ExtendedPoint { @@ -1271,6 +1278,13 @@ mod test { assert_eq!(compressed, constants::BASE_CMPRSSD); } + /// Test that `EdwardsBasepointTable::basepoint()` gives the correct basepoint. + #[test] + fn basepoint_table_basepoint_function_correct() { + let bp = constants::ED25519_BASEPOINT_TABLE.basepoint(); + assert_eq!(bp.compress_edwards(), constants::BASE_CMPRSSD); + } + /// Test `impl Add for ExtendedPoint` /// using basepoint + basepoint versus the 2*basepoint constant. #[test] diff --git a/src/decaf.rs b/src/decaf.rs index a0514ae..9d1a830 100644 --- a/src/decaf.rs +++ b/src/decaf.rs @@ -276,6 +276,11 @@ impl DecafBasepointTable { pub fn create(basepoint: &DecafPoint) -> DecafBasepointTable { DecafBasepointTable(EdwardsBasepointTable::create(&basepoint.0)) } + + /// Get the basepoint for this table as a `DecafPoint`. + pub fn basepoint(&self) -> DecafPoint { + DecafPoint(self.0.basepoint()) + } } // ------------------------------------------------------------------------