authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2020-11-02 14:58:43+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-11-02 13:38:20-05:00
logad9655db3a0e831f8e88bc902db7363547f9a12b
tree533001f18ebf8a6c16b5c1e65af7bbd8d72b073c
parent061ff11b2b8aca33fec0d5d381855d5bd3aa6ff9

Fix Gimli for big-endian targets


1 files changed, 12 insertions(+), 0 deletions(-)

lib/std/crypto/gimli.zig+12
......@@ -48,7 +48,14 @@ pub const State = struct {
4848 return mem.asBytes(&self.data);
4949 }
5050
51 inline fn endianSwap(self: *Self) void {
52 for (self.data) |*w| {
53 w.* = mem.littleToNative(u32, w.*);
54 }
55 }
56
5157 fn permute_unrolled(self: *Self) void {
58 self.endianSwap();
5259 const state = &self.data;
5360 comptime var round = @as(u32, 24);
5461 inline while (round > 0) : (round -= 1) {
......@@ -74,9 +81,11 @@ pub const State = struct {
7481 else => {},
7582 }
7683 }
84 self.endianSwap();
7785 }
7886
7987 fn permute_small(self: *Self) void {
88 self.endianSwap();
8089 const state = &self.data;
8190 var round = @as(u32, 24);
8291 while (round > 0) : (round -= 1) {
......@@ -102,6 +111,7 @@ pub const State = struct {
102111 else => {},
103112 }
104113 }
114 self.endianSwap();
105115 }
106116
107117 const Lane = Vector(4, u32);
......@@ -115,6 +125,7 @@ pub const State = struct {
115125 }
116126
117127 fn permute_vectorized(self: *Self) void {
128 self.endianSwap();
118129 const state = &self.data;
119130 var x = Lane{ state[0], state[1], state[2], state[3] };
120131 var y = Lane{ state[4], state[5], state[6], state[7] };
......@@ -146,6 +157,7 @@ pub const State = struct {
146157 state[4 + i] = y[i];
147158 state[8 + i] = z[i];
148159 }
160 self.endianSwap();
149161 }
150162
151163 pub const permute = if (std.Target.current.cpu.arch == .x86_64) impl: {