Rename BasepointTable as EdwardsBasepointTable.

This commit is contained in:
Henry & Isis 2017-03-10 22:21:17 -08:00 committed by Henry de Valence
parent f312160d2c
commit c873f725a5
2 changed files with 12 additions and 12 deletions

View file

@ -23,7 +23,7 @@ use field::FieldElement;
use curve::ExtendedPoint;
use curve::AffineNielsPoint;
use curve::CompressedEdwardsY;
use curve::BasepointTable;
use curve::EdwardsBasepointTable;
use scalar::Scalar;
pub const d: FieldElement = FieldElement([
@ -226,7 +226,7 @@ pub const bi: [AffineNielsPoint; 8] = [
///
/// The table is defined so `constants::base[i][j-1] = j*(16^2i)*B`,
/// for `0 ≤ i < 32`, `1 ≤ j < 9`.
pub const ED25519_BASEPOINT_TABLE: BasepointTable = BasepointTable([
pub const ED25519_BASEPOINT_TABLE: EdwardsBasepointTable = EdwardsBasepointTable([
[
AffineNielsPoint{
y_plus_x: FieldElement([25967493, -14356035, 29566456, 3660896, -12694345, 4014787, 27544626, -11754271, -6079156, 2047605]),

View file

@ -827,27 +827,27 @@ impl ScalarMult<Scalar> for ExtendedPoint {
/// Precomputation
#[derive(Clone)]
pub struct BasepointTable(pub [[AffineNielsPoint; 8]; 32]);
pub struct EdwardsBasepointTable(pub [[AffineNielsPoint; 8]; 32]);
impl BasepointTable {
impl EdwardsBasepointTable {
/// Create a table of precomputed multiples of `basepoint`.
pub fn create(basepoint: &ExtendedPoint) -> Box<BasepointTable> {
pub fn create(basepoint: &ExtendedPoint) -> Box<EdwardsBasepointTable> {
// Create the table storage
// XXX this is a dirty hack, does placement new work here?
let mut table = box [[AffineNielsPoint::identity(); 8]; 32];
// XXX can we be assured that this is not allocated on the stack?
// XXX can we skip the initialization without too much unsafety?
let mut table = box EdwardsBasepointTable([[AffineNielsPoint::identity(); 8]; 32]);
let mut P = basepoint.clone();
for i in 0..32 {
// P = (16^2)^i * B
let mut jP = P.to_affine_niels();
for j in 1..9 {
// table[i][j-1] is supposed to be j*(16^2)^i*B
table[i][j-1] = jP;
table.0[i][j-1] = jP;
jP = (&P + &jP).to_extended().to_affine_niels();
}
P = P.mult_by_pow_2(8);
}
// XXX can we do just 1 alloc instead of 2?
return Box::new(BasepointTable(*table));
return table
}
/// Construct an `ExtendedPoint` from a `Scalar`, `scalar`, by
@ -1313,7 +1313,7 @@ mod test {
/// Test precomputed basepoint mult
#[test]
fn test_precomputed_basepoint_mult() {
let table = BasepointTable::create(&constants::ED25519_BASEPOINT);
let table = EdwardsBasepointTable::create(&constants::ED25519_BASEPOINT);
let aB_1 = ExtendedPoint::basepoint_mult(&A_SCALAR);
let aB_2 = table.basepoint_mult(&A_SCALAR);
assert_eq!(aB_1.compress_edwards(),
@ -1490,6 +1490,6 @@ mod bench {
#[bench]
fn create_basepoint_table(b: &mut Bencher) {
let aB = ExtendedPoint::basepoint_mult(&A_SCALAR);
b.iter(|| BasepointTable::create(&aB));
b.iter(|| EdwardsBasepointTable::create(&aB));
}
}