Skip to content

Commit 9695573

Browse files
jack-fortanixnewpavlov
authored andcommitted
Fix an overflow in Streebog causing panic or incorrect output (#91)
1 parent 7f3080b commit 9695573

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

streebog/src/streebog.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,10 @@ impl StreebogState {
6161
}
6262

6363
fn update_sigma(&mut self, m: &Block) {
64-
let mut over = false;
64+
let mut carry = 0;
6565
for (a, b) in self.sigma.iter_mut().zip(m.iter()) {
66-
let (res, loc_over) = (*a).overflowing_add(*b);
67-
*a = res;
68-
if over { *a += 1; }
69-
over = loc_over;
66+
carry = (*a as u16) + (*b as u16) + (carry >> 8);
67+
*a = (carry & 0xFF) as u8;
7068
}
7169
}
7270

0 commit comments

Comments
 (0)