use super::NistP256;
use crate::ProjectivePoint;
use primeorder::PrimeCurveWithBasepointTable;
pub(super) const WINDOW_SIZE: usize = 33;
pub(super) type BasepointTable = primeorder::BasepointTable<ProjectivePoint, WINDOW_SIZE>;
pub(super) static BASEPOINT_TABLE: BasepointTable = BasepointTable::new();
impl PrimeCurveWithBasepointTable<WINDOW_SIZE> for NistP256 {
const BASEPOINT_TABLE: &'static BasepointTable = &BASEPOINT_TABLE;
}
pub(crate) mod backend {
use super::BASEPOINT_TABLE;
use crate::{NistP256, ProjectivePoint, Scalar};
use primeorder::MulBackend;
#[derive(Clone, Copy, Debug)]
pub struct PrecomputedTables;
impl MulBackend<NistP256> for PrecomputedTables {
#[inline]
fn mul_by_generator(k: &Scalar) -> ProjectivePoint {
BASEPOINT_TABLE.mul(k)
}
#[inline]
fn mul_by_generator_vartime(k: &Scalar) -> ProjectivePoint {
BASEPOINT_TABLE.mul_vartime(k)
}
}
}
#[cfg(test)]
mod tests {
use super::BASEPOINT_TABLE;
use crate::{ProjectivePoint, Scalar};
use elliptic_curve::{
array::{Array, sizes::U32},
ops::Reduce,
};
use proptest::prelude::*;
prop_compose! {
fn scalar()(bytes in any::<[u8; 32]>()) -> Scalar {
Scalar::reduce(&Array::<u8, U32>::from(bytes))
}
}
proptest! {
#[test]
fn basepoint_table_mul(x in scalar()) {
let expected = ProjectivePoint::GENERATOR * x;
let actual = BASEPOINT_TABLE.mul(&x);
prop_assert_eq!(expected, actual);
}
}
proptest! {
#[test]
fn basepoint_table_mul_vartime(x in scalar()) {
let expected = ProjectivePoint::GENERATOR * x;
let actual = BASEPOINT_TABLE.mul_vartime(&x);
prop_assert_eq!(expected, actual);
}
}
}