Always recommend a window table size.
This commit is contained in:
parent
894b44d034
commit
bda22db9d5
@ -518,7 +518,7 @@ macro_rules! curve_impl {
|
||||
(*self).into()
|
||||
}
|
||||
|
||||
fn recommended_wnaf_for_scalar(scalar: <Self::Scalar as PrimeField>::Repr) -> Option<usize> {
|
||||
fn recommended_wnaf_for_scalar(scalar: <Self::Scalar as PrimeField>::Repr) -> usize {
|
||||
Self::empirical_recommended_wnaf_for_scalar(scalar)
|
||||
}
|
||||
|
||||
@ -859,20 +859,17 @@ pub mod g1 {
|
||||
}
|
||||
|
||||
impl G1 {
|
||||
fn empirical_recommended_wnaf_for_scalar(scalar: FrRepr) -> Option<usize>
|
||||
fn empirical_recommended_wnaf_for_scalar(scalar: FrRepr) -> usize
|
||||
{
|
||||
const RECOMMENDATIONS: [usize; 3] = [12, 34, 130];
|
||||
|
||||
let mut ret = None;
|
||||
let num_bits = scalar.num_bits() as usize;
|
||||
|
||||
for (i, r) in RECOMMENDATIONS.iter().enumerate() {
|
||||
if *r >= num_bits {
|
||||
ret = Some(i + 2)
|
||||
}
|
||||
if num_bits >= 130 {
|
||||
4
|
||||
} else if num_bits >= 34 {
|
||||
3
|
||||
} else {
|
||||
2
|
||||
}
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
fn empirical_recommended_wnaf_for_num_scalars(num_scalars: usize) -> usize
|
||||
@ -1398,20 +1395,17 @@ pub mod g2 {
|
||||
}
|
||||
|
||||
impl G2 {
|
||||
fn empirical_recommended_wnaf_for_scalar(scalar: FrRepr) -> Option<usize>
|
||||
fn empirical_recommended_wnaf_for_scalar(scalar: FrRepr) -> usize
|
||||
{
|
||||
const RECOMMENDATIONS: [usize; 3] = [13, 37, 103];
|
||||
|
||||
let mut ret = None;
|
||||
let num_bits = scalar.num_bits() as usize;
|
||||
|
||||
for (i, r) in RECOMMENDATIONS.iter().enumerate() {
|
||||
if *r >= num_bits {
|
||||
ret = Some(i + 2)
|
||||
}
|
||||
if num_bits >= 103 {
|
||||
4
|
||||
} else if num_bits >= 37 {
|
||||
3
|
||||
} else {
|
||||
2
|
||||
}
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
fn empirical_recommended_wnaf_for_num_scalars(num_scalars: usize) -> usize
|
||||
|
@ -145,10 +145,9 @@ pub trait CurveProjective: PartialEq +
|
||||
/// Converts this element into its affine representation.
|
||||
fn into_affine(&self) -> Self::Affine;
|
||||
|
||||
/// Recommends a wNAF window table size given a scalar. Returns `None` if normal
|
||||
/// scalar multiplication is encouraged. If `Some` is returned, it will be between
|
||||
/// 2 and 22, inclusive.
|
||||
fn recommended_wnaf_for_scalar(scalar: <Self::Scalar as PrimeField>::Repr) -> Option<usize>;
|
||||
/// Recommends a wNAF window table size given a scalar. Always returns a number
|
||||
/// between 2 and 22, inclusive.
|
||||
fn recommended_wnaf_for_scalar(scalar: <Self::Scalar as PrimeField>::Repr) -> usize;
|
||||
|
||||
/// Recommends a wNAF window size given the number of scalars you intend to multiply
|
||||
/// a base by. Always returns a number between 2 and 22, inclusive.
|
||||
|
@ -122,7 +122,7 @@ impl<G: CurveProjective> Wnaf<(), Vec<G>, Vec<i64>> {
|
||||
) -> Wnaf<usize, &'a mut Vec<G>, &'a [i64]>
|
||||
{
|
||||
// Compute the appropriate window size for the scalar.
|
||||
let window_size = G::recommended_wnaf_for_scalar(scalar).unwrap_or(2); // TODO
|
||||
let window_size = G::recommended_wnaf_for_scalar(scalar);
|
||||
|
||||
// Compute the wNAF form of the scalar.
|
||||
wnaf_form(&mut self.scalar, scalar, window_size);
|
||||
|
Loading…
Reference in New Issue
Block a user