Skip to content

Commit

Permalink
Use wrapping integer ops
Browse files Browse the repository at this point in the history
  • Loading branch information
ebfe committed Apr 23, 2015
1 parent 3bafbe2 commit 3f50f81
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/blake2b.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ impl Blake2b {

macro_rules! g(
($r: expr, $i: expr, $a: expr, $b: expr, $c: expr, $d: expr) => ({
$a = $a + $b + m[SIGMA[$r][2*$i+0] as usize];
$a = $a.wrapping_add($b).wrapping_add(m[SIGMA[$r][2*$i+0] as usize]);
$d = ($d ^ $a).rotate_right(32);
$c = $c + $d;
$c = $c.wrapping_add($d);
$b = ($b ^ $c).rotate_right(24);
$a = $a + $b + m[SIGMA[$r][2*$i+1] as usize];
$a = $a.wrapping_add($b).wrapping_add(m[SIGMA[$r][2*$i+1] as usize]);
$d = ($d ^ $a).rotate_right(16);
$c = $c + $d;
$c = $c.wrapping_add($d);
$b = ($b ^ $c).rotate_right(63);
});
);
Expand Down
8 changes: 4 additions & 4 deletions src/blake2s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ impl Blake2s {

macro_rules! g(
($r: expr, $i: expr, $a: expr, $b: expr, $c: expr, $d: expr) => ({
$a = $a + $b + m[SIGMA[$r][2*$i+0] as usize];
$a = $a.wrapping_add($b).wrapping_add(m[SIGMA[$r][2*$i+0] as usize]);
$d = ($d ^ $a).rotate_right(16);
$c = $c + $d;
$c = $c.wrapping_add($d);
$b = ($b ^ $c).rotate_right(12);
$a = $a + $b + m[SIGMA[$r][2*$i+1] as usize];
$a = $a.wrapping_add($b).wrapping_add(m[SIGMA[$r][2*$i+1] as usize]);
$d = ($d ^ $a).rotate_right(8);
$c = $c + $d;
$c = $c.wrapping_add($d);
$b = ($b ^ $c).rotate_right(7);
});
);
Expand Down

0 comments on commit 3f50f81

Please sign in to comment.