authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2020-09-29 13:09:11+02:00
committergravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2020-09-29 13:23:04+02:00
log4194714965a8080e6faa87d9859cc90aab07fe54
tree77b478cb8ae4d41297c89255395858e78cd1612a
parent613f8fe83fc2db4bc39f18ad1a8190d33a4a1181

Don't unroll the gimli permutation on release-small


1 files changed, 37 insertions(+), 1 deletions(-)

lib/std/crypto/gimli.zig+37-1
......@@ -38,7 +38,7 @@ pub const State = struct {
3838 return mem.sliceAsBytes(self.data[0..]);
3939 }
4040
41 pub fn permute(self: *Self) void {
41 fn _permute_unrolled(self: *Self) void {
4242 const state = &self.data;
4343 comptime var round = @as(u32, 24);
4444 inline while (round > 0) : (round -= 1) {
......@@ -66,6 +66,42 @@ pub const State = struct {
6666 }
6767 }
6868
69 fn _permute_small(self: *Self) void {
70 const state = &self.data;
71 var round = @as(u32, 24);
72 while (round > 0) : (round -= 1) {
73 var column = @as(usize, 0);
74 while (column < 4) : (column += 1) {
75 const x = math.rotl(u32, state[column], 24);
76 const y = math.rotl(u32, state[4 + column], 9);
77 const z = state[8 + column];
78 state[8 + column] = ((x ^ (z << 1)) ^ ((y & z) << 2));
79 state[4 + column] = ((y ^ x) ^ ((x | z) << 1));
80 state[column] = ((z ^ y) ^ ((x & y) << 3));
81 }
82 switch (round & 3) {
83 0 => {
84 mem.swap(u32, &state[0], &state[1]);
85 mem.swap(u32, &state[2], &state[3]);
86 state[0] ^= round | 0x9e377900;
87 },
88 2 => {
89 mem.swap(u32, &state[0], &state[2]);
90 mem.swap(u32, &state[1], &state[3]);
91 },
92 else => {},
93 }
94 }
95 }
96
97 pub fn permute(self: *Self) void {
98 if (std.builtin.mode == .ReleaseSmall) {
99 self._permute_small();
100 } else {
101 self._permute_unrolled();
102 }
103 }
104
69105 pub fn squeeze(self: *Self, out: []u8) void {
70106 var i = @as(usize, 0);
71107 while (i + RATE <= out.len) : (i += RATE) {