authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2026-10-04 11:29:43+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-07 00:29:37+02:00
log4465f34532491c3c185c3ee6008a00a8c907abf9
tree962e388f0e0ff85509a921c04defc0f8db7802f6
parent57e52b7edb1312d84abf079259e7ed153074ea9f
signature Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

crypto.aessiv: there's no special case for the empty string

Add a test for that case by the way.

1 files changed, 13 insertions(+), 7 deletions(-)

lib/std/crypto/aes_siv.zig+13-7
......@@ -63,13 +63,6 @@ fn AesSiv(comptime Aes: anytype) type {
6363
6464 var d: [16]u8 = undefined;
6565
66 // Special case: single empty string
67 if (strings.len == 1 and strings[0].len == 0) {
68 CmacImpl.create(&d, &[_]u8{}, &key);
69 iv.* = d;
70 return;
71 }
72
7366 // Initialize with CMAC of zero block
7467 const zero_block: [16]u8 = @splat(0);
7568 CmacImpl.create(&d, &zero_block, &key);
......@@ -416,6 +409,19 @@ test "Aes128Siv - empty plaintext" {
416409 try Aes128Siv.decrypt(&decrypted, &ciphertext, tag, ad, null, key);
417410}
418411
412test "Aes128Siv - empty plaintext without associated data" {
413 const key: [Aes128Siv.key_length]u8 = @splat(0x42);
414 var ciphertext: [0]u8 = undefined;
415 var tag: [Aes128Siv.tag_length]u8 = undefined;
416
417 Aes128Siv.encrypt(&ciphertext, &tag, "", null, null, key);
418
419 try testing.expectEqual([_]u8{
420 0x23, 0xef, 0x43, 0xc1, 0x08, 0x55, 0x68, 0x98,
421 0x27, 0x56, 0xaf, 0x5c, 0x9f, 0xda, 0x7e, 0xab,
422 }, tag);
423}
424
419425test "Aes128Siv - with nonce" {
420426 const key: [32]u8 = @splat(0x69);
421427 const nonce: [16]u8 = @splat(0x42);