authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2026-04-20 12:03:05+02:00
committergravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2026-05-28 16:34:04+02:00
log03fbadbf3a1aa64faa9a74a16712a4a0f3c16653
tree491ec18a41f36f9ced828ff9b18efefb52f6a53d
parent3f1dead2fc5922b588fbfb108f421ca957d6934a

std.crypto.aes-siv: Add an assertion for the number of AD inputs

AES-SIV supports "only" up to 126 AD fields. Passing more than that never happens in any real-world protocol (it's typically 1-3), but an assert() doesn't hurt.

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

lib/std/crypto/aes_siv.zig+2
......@@ -229,6 +229,7 @@ fn AesSiv(comptime Aes: anytype) type {
229229 /// an arbitrary vector of associated data strings as specified in RFC 5297.
230230 pub fn encryptWithAdVector(c: []u8, tag: *[tag_length]u8, m: []const u8, ad: []const []const u8, key: [key_length]u8) void {
231231 debug.assert(c.len == m.len);
232 debug.assert(ad.len <= 126); // AES-SIV supports at most 126 associated data components
232233
233234 // Split key into K1 (for S2V) and K2 (for CTR)
234235 const k1 = key[0 .. Aes.key_bits / 8];
......@@ -263,6 +264,7 @@ fn AesSiv(comptime Aes: anytype) type {
263264 /// an arbitrary vector of associated data strings as specified in RFC 5297.
264265 pub fn decryptWithAdVector(m: []u8, c: []const u8, tag: [tag_length]u8, ad: []const []const u8, key: [key_length]u8) AuthenticationError!void {
265266 assert(c.len == m.len);
267 assert(ad.len <= 126); // AES-SIV supports at most 126 associated data components
266268
267269 // Split key into K1 (for S2V) and K2 (for CTR)
268270 const k1 = key[0 .. Aes.key_bits / 8];