authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-11-03 11:22:54-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-11-03 11:22:54-05:00
logf2cb63c2e1a08db4ac29de3db1bf5b4d28a11e92
tree7ee3710d69819d2517baaabd4e83e936f74a8ba4
parent50604971745c0ddd2373bba933c30b59db624d2b
parent8d7c160fb40a3495e0b118e24190ea483d7d8782
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #6956 from jedisct1/more-gimli-be-fixes

Another big-endian fix for Gimli

1 files changed, 24 insertions(+), 26 deletions(-)

lib/std/crypto/gimli.zig+24-26
......@@ -33,7 +33,7 @@ pub const State = struct {
3333 var data: [BLOCKBYTES / 4]u32 = undefined;
3434 var i: usize = 0;
3535 while (i < State.BLOCKBYTES) : (i += 4) {
36 data[i / 4] = mem.readIntLittle(u32, initial_state[i..][0..4]);
36 data[i / 4] = mem.readIntNative(u32, initial_state[i..][0..4]);
3737 }
3838 return Self{ .data = data };
3939 }
......@@ -184,27 +184,31 @@ pub const State = struct {
184184
185185test "permute" {
186186 // test vector from gimli-20170627
187 var state = State{
188 .data = blk: {
189 var input: [12]u32 = undefined;
190 var i = @as(u32, 0);
191 while (i < 12) : (i += 1) {
192 input[i] = i * i * i + i *% 0x9e3779b9;
193 }
194 testing.expectEqualSlices(u32, &input, &[_]u32{
195 0x00000000, 0x9e3779ba, 0x3c6ef37a, 0xdaa66d46,
196 0x78dde724, 0x1715611a, 0xb54cdb2e, 0x53845566,
197 0xf1bbcfc8, 0x8ff34a5a, 0x2e2ac522, 0xcc624026,
198 });
199 break :blk input;
200 },
187 const tv_input = [3][4]u32{
188 [4]u32{ 0x00000000, 0x9e3779ba, 0x3c6ef37a, 0xdaa66d46 },
189 [4]u32{ 0x78dde724, 0x1715611a, 0xb54cdb2e, 0x53845566 },
190 [4]u32{ 0xf1bbcfc8, 0x8ff34a5a, 0x2e2ac522, 0xcc624026 },
201191 };
192 var input: [48]u8 = undefined;
193 var i: usize = 0;
194 while (i < 12) : (i += 1) {
195 mem.writeIntLittle(u32, input[i * 4 ..][0..4], tv_input[i / 4][i % 4]);
196 }
197
198 var state = State.init(input);
202199 state.permute();
203 testing.expectEqualSlices(u32, &state.data, &[_]u32{
204 0xba11c85a, 0x91bad119, 0x380ce880, 0xd24c2c68,
205 0x3eceffea, 0x277a921c, 0x4f73a0bd, 0xda5a9cd8,
206 0x84b673f0, 0x34e52ff7, 0x9e2bef49, 0xf41bb8d6,
207 });
200
201 const tv_output = [3][4]u32{
202 [4]u32{ 0xba11c85a, 0x91bad119, 0x380ce880, 0xd24c2c68 },
203 [4]u32{ 0x3eceffea, 0x277a921c, 0x4f73a0bd, 0xda5a9cd8 },
204 [4]u32{ 0x84b673f0, 0x34e52ff7, 0x9e2bef49, 0xf41bb8d6 },
205 };
206 var expected_output: [48]u8 = undefined;
207 i = 0;
208 while (i < 12) : (i += 1) {
209 mem.writeIntLittle(u32, expected_output[i * 4 ..][0..4], tv_output[i / 4][i % 4]);
210 }
211 testing.expectEqualSlices(u8, state.toSliceConst(), expected_output[0..]);
208212}
209213
210214pub const Hash = struct {
......@@ -269,9 +273,6 @@ pub fn hash(out: *[Hash.digest_length]u8, in: []const u8, options: Hash.Options)
269273}
270274
271275test "hash" {
272 // https://github.com/ziglang/zig/issues/5127
273 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
274
275276 // a test vector (30) from NIST KAT submission.
276277 var msg: [58 / 2]u8 = undefined;
277278 try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C");
......@@ -423,9 +424,6 @@ pub const Aead = struct {
423424};
424425
425426test "cipher" {
426 // https://github.com/ziglang/zig/issues/5127
427 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
428
429427 var key: [32]u8 = undefined;
430428 try std.fmt.hexToBytes(&key, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F");
431429 var nonce: [16]u8 = undefined;