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 {...@@ -48,7 +48,14 @@ pub const State = struct {
48 return mem.asBytes(&self.data);48 return mem.asBytes(&self.data);
49 }49 }
5050
51 inline fn endianSwap(self: *Self) void {
52 for (self.data) |*w| {
53 w.* = mem.littleToNative(u32, w.*);
54 }
55 }
56
51 fn permute_unrolled(self: *Self) void {57 fn permute_unrolled(self: *Self) void {
58 self.endianSwap();
52 const state = &self.data;59 const state = &self.data;
53 comptime var round = @as(u32, 24);60 comptime var round = @as(u32, 24);
54 inline while (round > 0) : (round -= 1) {61 inline while (round > 0) : (round -= 1) {
...@@ -74,9 +81,11 @@ pub const State = struct {...@@ -74,9 +81,11 @@ pub const State = struct {
74 else => {},81 else => {},
75 }82 }
76 }83 }
84 self.endianSwap();
77 }85 }
7886
79 fn permute_small(self: *Self) void {87 fn permute_small(self: *Self) void {
88 self.endianSwap();
80 const state = &self.data;89 const state = &self.data;
81 var round = @as(u32, 24);90 var round = @as(u32, 24);
82 while (round > 0) : (round -= 1) {91 while (round > 0) : (round -= 1) {
...@@ -102,6 +111,7 @@ pub const State = struct {...@@ -102,6 +111,7 @@ pub const State = struct {
102 else => {},111 else => {},
103 }112 }
104 }113 }
114 self.endianSwap();
105 }115 }
106116
107 const Lane = Vector(4, u32);117 const Lane = Vector(4, u32);
...@@ -115,6 +125,7 @@ pub const State = struct {...@@ -115,6 +125,7 @@ pub const State = struct {
115 }125 }
116126
117 fn permute_vectorized(self: *Self) void {127 fn permute_vectorized(self: *Self) void {
128 self.endianSwap();
118 const state = &self.data;129 const state = &self.data;
119 var x = Lane{ state[0], state[1], state[2], state[3] };130 var x = Lane{ state[0], state[1], state[2], state[3] };
120 var y = Lane{ state[4], state[5], state[6], state[7] };131 var y = Lane{ state[4], state[5], state[6], state[7] };
...@@ -146,6 +157,7 @@ pub const State = struct {...@@ -146,6 +157,7 @@ pub const State = struct {
146 state[4 + i] = y[i];157 state[4 + i] = y[i];
147 state[8 + i] = z[i];158 state[8 + i] = z[i];
148 }159 }
160 self.endianSwap();
149 }161 }
150162
151 pub const permute = if (std.Target.current.cpu.arch == .x86_64) impl: {163 pub const permute = if (std.Target.current.cpu.arch == .x86_64) impl: {