Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions elliptic-curve/src/arithmetic/wnaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//! such that no two consecutive digits are non-zero.
//!
//! A configurable window size trades memory for speed: a larger window precomputes more multiples
//! of the base point (a table of `2^(w-1)` entries) but requires fewer group additions per-bit of
//! of the base point (a table of `2^(w-2)` entries) but requires fewer group additions per-bit of
//! the scalar.
//!
//! # RustCrypto Notes
Expand All @@ -39,13 +39,18 @@ pub trait WnafGroup: Group {
}

/// Replaces the contents of `table` with a w-NAF window table for the given window size.
///
/// For a window of size `w`, non-zero wNAF digits are odd and have magnitude at most
/// `2^(w-1) - 1`. The table is indexed by `|digit| / 2`, so the required size is
/// `(2^(w-1) - 1) / 2 + 1 = 2^(w-2)` entries.
pub(crate) fn wnaf_table<G: Group>(table: &mut Vec<G>, mut base: G, window: usize) {
let table_len = 1 << (window - 2);
table.clear();
table.reserve(1 << (window - 1));
table.reserve(table_len);

let dbl = base.double();

for _ in 0..(1 << (window - 1)) {
for _ in 0..table_len {
table.push(base);
base.add_assign(&dbl);
}
Expand Down