Skip to content
Open
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
16 changes: 16 additions & 0 deletions src/wnaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ pub(crate) fn wnaf_form<S: AsRef<[u8]>>(wnaf: &mut Vec<i64>, c: S, window: usize
pos += window;
}
}

if carry > 0 {
wnaf.push(carry as i64);
}
}

/// Performs w-NAF exponentiation with the provided window table and w-NAF form scalar.
Expand Down Expand Up @@ -504,3 +508,15 @@ impl<G: Group, const WINDOW_SIZE: usize> Mul<&WnafScalar<G::Scalar, WINDOW_SIZE>
wnaf_exp(&self.table, &rhs.wnaf)
}
}

#[cfg(test)]
mod tests {
use super::wnaf_form;

#[test]
fn wnaf_form_keeps_final_carry() {
let mut wnaf = vec![];
wnaf_form(&mut wnaf, [0xff], 4);
assert_eq!(wnaf, vec![-1, 0, 0, 0, 0, 0, 0, 0, 1]);
}
}