mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-08 21:00:40 +00:00
use one buffer instead of two
This commit is contained in:
parent
dfcac0d8e2
commit
ca2926ac89
2 changed files with 22 additions and 19 deletions
|
|
@ -70,7 +70,6 @@ impl VartimeMultiscalarMul for Pippenger {
|
||||||
I::Item: Borrow<Scalar>,
|
I::Item: Borrow<Scalar>,
|
||||||
J: IntoIterator<Item = Option<EdwardsPoint>>,
|
J: IntoIterator<Item = Option<EdwardsPoint>>,
|
||||||
{
|
{
|
||||||
use backend::serial::curve_models::ProjectiveNielsPoint;
|
|
||||||
use traits::Identity;
|
use traits::Identity;
|
||||||
|
|
||||||
let mut scalars = scalars.into_iter();
|
let mut scalars = scalars.into_iter();
|
||||||
|
|
@ -95,14 +94,16 @@ impl VartimeMultiscalarMul for Pippenger {
|
||||||
// (scanning the whole set per digit position).
|
// (scanning the whole set per digit position).
|
||||||
let scalars = scalars
|
let scalars = scalars
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|s| s.borrow().to_pippenger_radix(w).0)
|
.map(|s| s.borrow().to_pippenger_radix(w).0);
|
||||||
.collect::<Vec<_>>();
|
|
||||||
let points: Vec<ProjectiveNielsPoint> = match points
|
let points = points
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|p| p.map(|P| P.to_projective_niels()))
|
.map(|p| p.map(|P| P.to_projective_niels()));
|
||||||
.collect::<Option<Vec<_>>>()
|
|
||||||
{
|
let scalars_points = scalars.zip(points).map(|(s,maybe_p)| maybe_p.map(|p| (s,p) ) )
|
||||||
Some(x) => x,
|
.collect::<Option<Vec<_>>>();
|
||||||
|
let scalars_points = match scalars_points {
|
||||||
|
Some(sp) => sp,
|
||||||
None => return None,
|
None => return None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -122,7 +123,7 @@ impl VartimeMultiscalarMul for Pippenger {
|
||||||
// and add/sub the point to the corresponding bucket.
|
// and add/sub the point to the corresponding bucket.
|
||||||
// Note: if we add support for precomputed lookup tables,
|
// Note: if we add support for precomputed lookup tables,
|
||||||
// we'll be adding/subtractiong point premultiplied by `digits[i]` to buckets[0].
|
// we'll be adding/subtractiong point premultiplied by `digits[i]` to buckets[0].
|
||||||
for (digits, pt) in scalars.iter().zip(points.iter()) {
|
for (digits, pt) in scalars_points.iter() {
|
||||||
let digit = digits[digit_index];
|
let digit = digits[digit_index];
|
||||||
if digit > 0 {
|
if digit > 0 {
|
||||||
let b = (digit - 1) as usize;
|
let b = (digit - 1) as usize;
|
||||||
|
|
|
||||||
|
|
@ -48,18 +48,20 @@ impl VartimeMultiscalarMul for Pippenger {
|
||||||
let digits_count: usize = (256 + w - 1) / w; // == ceil(256/w)
|
let digits_count: usize = (256 + w - 1) / w; // == ceil(256/w)
|
||||||
let buckets_count: usize = max_digit / 2; // digits are signed+centered hence 2^w/2, excluding 0-th bucket
|
let buckets_count: usize = max_digit / 2; // digits are signed+centered hence 2^w/2, excluding 0-th bucket
|
||||||
|
|
||||||
// Collect optimized scalars and points in buffers for repeated access
|
// Collect optimized scalars and points in a buffer for repeated access
|
||||||
// (scanning the whole set per digit position).
|
// (scanning the whole collection per each digit position).
|
||||||
let scalars = scalars
|
let scalars = scalars
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|s| s.borrow().to_pippenger_radix(w).0)
|
.map(|s| s.borrow().to_pippenger_radix(w).0);
|
||||||
.collect::<Vec<_>>();
|
|
||||||
let points: Vec<CachedPoint> = match points
|
let points = points
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|p| p.map(|P| CachedPoint::from(ExtendedPoint::from(P))))
|
.map(|p| p.map(|P| CachedPoint::from(ExtendedPoint::from(P))));
|
||||||
.collect::<Option<Vec<_>>>()
|
|
||||||
{
|
let scalars_points = scalars.zip(points).map(|(s,maybe_p)| maybe_p.map(|p| (s,p) ) )
|
||||||
Some(x) => x,
|
.collect::<Option<Vec<_>>>();
|
||||||
|
let scalars_points = match scalars_points {
|
||||||
|
Some(sp) => sp,
|
||||||
None => return None,
|
None => return None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -79,7 +81,7 @@ impl VartimeMultiscalarMul for Pippenger {
|
||||||
// and add/sub the point to the corresponding bucket.
|
// and add/sub the point to the corresponding bucket.
|
||||||
// Note: if we add support for precomputed lookup tables,
|
// Note: if we add support for precomputed lookup tables,
|
||||||
// we'll be adding/subtractiong point premultiplied by `digits[i]` to buckets[0].
|
// we'll be adding/subtractiong point premultiplied by `digits[i]` to buckets[0].
|
||||||
for (digits, pt) in scalars.iter().zip(points.iter()) {
|
for (digits, pt) in scalars_points.iter() {
|
||||||
let digit = digits[digit_index];
|
let digit = digits[digit_index];
|
||||||
if digit > 0 {
|
if digit > 0 {
|
||||||
let b = (digit - 1) as usize;
|
let b = (digit - 1) as usize;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue