multiplication using projective

This commit is contained in:
Nicholas Ward 2021-11-30 15:22:06 -08:00
parent 39300bcf01
commit b9868ec782
3 changed files with 13 additions and 8 deletions

View File

@ -16,23 +16,22 @@ fn digits_per_scalar<C: Curve>() -> usize {
#[derive(Clone)] #[derive(Clone)]
pub struct MultiplicationPrecomputation<C: Curve> { pub struct MultiplicationPrecomputation<C: Curve> {
/// [(2^w)^i] g for each i < digits_per_scalar. /// [(2^w)^i] g for each i < digits_per_scalar.
powers: Vec<AffinePoint<C>>, powers: Vec<ProjectivePoint<C>>,
} }
impl<C: Curve> ProjectivePoint<C> { impl<C: Curve> ProjectivePoint<C> {
pub fn mul_precompute(&self) -> MultiplicationPrecomputation<C> { pub fn mul_precompute(&self) -> MultiplicationPrecomputation<C> {
let num_digits = digits_per_scalar::<C>(); let num_digits = digits_per_scalar::<C>();
let mut powers_proj = Vec::with_capacity(num_digits); let mut powers = Vec::with_capacity(num_digits);
powers_proj.push(*self); powers.push(*self);
for i in 1..num_digits { for i in 1..num_digits {
let mut power_i_proj = powers_proj[i - 1]; let mut power_i = powers[i - 1];
for _j in 0..WINDOW_BITS { for _j in 0..WINDOW_BITS {
power_i_proj = power_i_proj.double(); power_i = power_i.double();
} }
powers_proj.push(power_i_proj); powers.push(power_i);
} }
let powers = ProjectivePoint::batch_to_affine(&powers_proj);
MultiplicationPrecomputation { powers } MultiplicationPrecomputation { powers }
} }
@ -59,7 +58,11 @@ impl<C: Curve> ProjectivePoint<C> {
all_summands.push(u_summands); all_summands.push(u_summands);
} }
let all_sums = affine_multisummation_batch_inversion(all_summands); let all_sums: Vec<ProjectivePoint<C>> = all_summands
.iter()
.cloned()
.map(|vec| vec.iter().fold(ProjectivePoint::ZERO, |a, &b| a + b))
.collect();
for i in 0..all_sums.len() { for i in 0..all_sums.len() {
u = u + all_sums[i]; u = u + all_sums[i];
y = y + u; y = y + u;

View File

@ -3,4 +3,5 @@ pub mod curve_msm;
pub mod curve_multiplication; pub mod curve_multiplication;
pub mod curve_summation; pub mod curve_summation;
pub mod curve_types; pub mod curve_types;
pub mod ecdsa;
pub mod secp256k1; pub mod secp256k1;

View File

@ -3,6 +3,7 @@ pub mod arithmetic_extension;
pub mod arithmetic_u32; pub mod arithmetic_u32;
pub mod biguint; pub mod biguint;
pub mod curve; pub mod curve;
//pub mod ecdsa;
pub mod hash; pub mod hash;
pub mod insert; pub mod insert;
pub mod interpolation; pub mod interpolation;