authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2020-11-03 09:13:14+01:00
committergravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2020-11-03 09:13:14+01:00
log8d7c160fb40a3495e0b118e24190ea483d7d8782
tree396d1804952192764d01a4b4146f06b24b7ff670
parentd764636d21f9aafa1e9a33f625156a829cc5d747

Make Gimli test vector look like the python implementation


1 files changed, 22 insertions(+), 2 deletions(-)

lib/std/crypto/gimli.zig+22-2
......@@ -184,11 +184,31 @@ pub const State = struct {
184184
185185test "permute" {
186186 // test vector from gimli-20170627
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 },
191 };
187192 var input: [48]u8 = undefined;
188 try std.fmt.hexToBytes(input[0..], "00000000ba79379e7af36e3c466da6da24e7dd781a6115172edb4cb566558453c8cfbbf15a4af38f22c52a2e264062cc");
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
189198 var state = State.init(input);
190199 state.permute();
191 htest.assertEqual("5ac811ba19d1ba9180e80c38682c4cd2eaffce3e1c927a27bda0734fd89c5adaf073b684f72fe53449ef2b9ed6b81bf4", state.toSliceConst());
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..]);
192212}
193213
194214pub const Hash = struct {