Skip to content

Commit

Permalink
chacha: safer outputting: 0..4 loop
Browse files Browse the repository at this point in the history
  • Loading branch information
kazcw committed Sep 12, 2021
1 parent 7fa7c43 commit 7d9607a
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions rand_chacha/src/guts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,13 @@ fn refill_wide_impl<Mach: Machine>(
let sc = m.unpack(state.c);
let sd = [m.unpack(state.d), d1, d2, d3];
state.d = d4.into();
out[0..4].copy_from_slice(&(a[0] + k).to_lanes());
out[4..8].copy_from_slice(&(b[0] + sb).to_lanes());
out[8..12].copy_from_slice(&(c[0] + sc).to_lanes());
out[12..16].copy_from_slice(&(d[0] + sd[0]).to_lanes());
out[16..20].copy_from_slice(&(a[1] + k).to_lanes());
out[20..24].copy_from_slice(&(b[1] + sb).to_lanes());
out[24..28].copy_from_slice(&(c[1] + sc).to_lanes());
out[28..32].copy_from_slice(&(d[1] + sd[1]).to_lanes());
out[32..36].copy_from_slice(&(a[2] + k).to_lanes());
out[36..40].copy_from_slice(&(b[2] + sb).to_lanes());
out[40..44].copy_from_slice(&(c[2] + sc).to_lanes());
out[44..48].copy_from_slice(&(d[2] + sd[2]).to_lanes());
out[48..52].copy_from_slice(&(a[3] + k).to_lanes());
out[52..56].copy_from_slice(&(b[3] + sb).to_lanes());
out[56..60].copy_from_slice(&(c[3] + sc).to_lanes());
out[60..64].copy_from_slice(&(d[3] + sd[3]).to_lanes());
for i in 0..4 {
let i4 = i * 4;
out[i4..(i4+4)].copy_from_slice(&(a[i] + k).to_lanes());
out[(i4+4)..(i4+8)].copy_from_slice(&(b[i] + sb).to_lanes());
out[(i4+8)..(i4+12)].copy_from_slice(&(c[i] + sc).to_lanes());
out[(i4+12)..(i4+16)].copy_from_slice(&(d[i] + sd[i]).to_lanes());
}
}

dispatch!(m, Mach, {
Expand Down

0 comments on commit 7d9607a

Please sign in to comment.