authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-29 05:51:20+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-29 05:51:20+02:00
logd534cfa787cfa077b24e949b19749bd5c6e89a80
tree7141c4849880b7fba9fc4397b056e587f6365423
parentef7f828338604415549c4ad886358786fdf16c02
parentb1240e13872509f1806924ec9b3df653510088f2

Merge pull request 'std.crypto.aes-siv: Add an assertion for the number of AD inputs' (#31977) from jedisct1/zig:associated-data-vector-length-can-overrun-fixed-stack-buffer into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31977 Reviewed-by: Andrew Kelley <andrew@ziglang.org>

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

lib/std/crypto/aes_siv.zig+4-2
......@@ -226,9 +226,10 @@ fn AesSiv(comptime Aes: anytype) type {
226226
227227 /// Encrypts plaintext with multiple associated data components.
228228 /// This is the most general form of AES-SIV encryption that accepts
229 /// an arbitrary vector of associated data strings as specified in RFC 5297.
229 /// a vector of up to 126 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];
......@@ -260,9 +261,10 @@ fn AesSiv(comptime Aes: anytype) type {
260261
261262 /// Decrypts ciphertext with multiple associated data components.
262263 /// This is the most general form of AES-SIV decryption that accepts
263 /// an arbitrary vector of associated data strings as specified in RFC 5297.
264 /// a vector of up to 126 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];