Add function to get the basepoint from a basepoint table

This commit is contained in:
Henry de Valence 2017-05-03 18:18:00 -07:00 committed by Henry & Isis
parent 127169c151
commit 0ae0d2b72a
2 changed files with 19 additions and 0 deletions

View file

@ -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<ExtendedPoint> for ExtendedPoint`
/// using basepoint + basepoint versus the 2*basepoint constant.
#[test]

View file

@ -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())
}
}
// ------------------------------------------------------------------------