authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2026-09-28 12:52:52+02:00
committergravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2026-10-04 14:03:54+02:00
log8b0f9360cfa60e4711d909e599643ab948c403f8
tree9bec2dd528ac0d3e64462a7dac9d4d0adf3976f8
parente782da3d89cfae1bac37d7c3bcebf0ac5b2cb6b0

Add a test for specialized vs regular AEGIS state updates


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

lib/std/crypto/aegis.zig+38
...@@ -823,6 +823,44 @@ fn AegisMac(comptime T: type) type {...@@ -823,6 +823,44 @@ fn AegisMac(comptime T: type) type {
823const htest = @import("test.zig");823const htest = @import("test.zig");
824const testing = std.testing;824const testing = std.testing;
825825
826fn hashStateOutputs(comptime State: type, key: anytype, nonce: anytype) [32]u8 {
827 var msg: [State.rate]u8 = undefined;
828 for (&msg, 0..) |*x, i| x.* = @truncate(i *% 31 +% 5);
829 var out: [State.rate]u8 = undefined;
830 var h: crypto.hash.sha2.Sha256 = .init(.{});
831
832 var st = State.init(key, nonce);
833 st.absorb(&msg);
834 st.enc(&out, &msg);
835 h.update(&out);
836 st.dec(&out, &msg);
837 h.update(&out);
838 st.decLast(out[3..], msg[3..]);
839 h.update(out[3..]);
840 inline for (.{ 128, 256 }) |tag_bits| {
841 var st2 = st;
842 h.update(&st2.finalize(tag_bits, 33, 12345));
843 st2 = st;
844 h.update(&st2.finalizeMac(tag_bits, 54321));
845 }
846 return h.finalResult();
847}
848
849test "Aegis bitsliced states" {
850 const key = "0123456789abcdef0123456789ABCDEF";
851 const nonce = "nonce0123456789Nnonce0123456789N";
852 inline for (.{ 1, 2, 4 }) |degree| {
853 try testing.expectEqual(
854 hashStateOutputs(State128X(degree), key[0..16].*, nonce[0..16].*),
855 hashStateOutputs(bitsliced.State128X(degree), key[0..16].*, nonce[0..16].*),
856 );
857 try testing.expectEqual(
858 hashStateOutputs(State256X(degree), key.*, nonce.*),
859 hashStateOutputs(bitsliced.State256X(degree), key.*, nonce.*),
860 );
861 }
862}
863
826test "Aegis128L test vector 1" {864test "Aegis128L test vector 1" {
827 const key: [Aegis128L.key_length]u8 = [_]u8{ 0x10, 0x01 } ++ @as([14]u8, @splat(0x00));865 const key: [Aegis128L.key_length]u8 = [_]u8{ 0x10, 0x01 } ++ @as([14]u8, @splat(0x00));
828 const nonce: [Aegis128L.nonce_length]u8 = [_]u8{ 0x10, 0x00, 0x02 } ++ @as([13]u8, @splat(0x00));866 const nonce: [Aegis128L.nonce_length]u8 = [_]u8{ 0x10, 0x00, 0x02 } ++ @as([13]u8, @splat(0x00));