From aa7970c80534cd03441aa958230b0318bf8a6c4b Mon Sep 17 00:00:00 2001 From: revofusion Date: Sun, 31 May 2026 20:54:04 -0600 Subject: [PATCH] Fix: append final carry after wnaf_form loop. --- src/wnaf.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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]); + } +}