diff --git a/src/wnaf.rs b/src/wnaf.rs index 175d676..13685a6 100644 --- a/src/wnaf.rs +++ b/src/wnaf.rs @@ -144,6 +144,10 @@ pub(crate) fn wnaf_form>(wnaf: &mut Vec, 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. @@ -504,3 +508,15 @@ impl Mul<&WnafScalar 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]); + } +}