From a64a25533547172bd0bee30417962afa1540dd90 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sun, 4 Oct 2026 11:29:43 +0200 Subject: [PATCH] crypto.aessiv: there's no special case for the empty string Add a test for that case by the way. --- lib/std/crypto/aes_siv.zig | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/std/crypto/aes_siv.zig b/lib/std/crypto/aes_siv.zig index b3be102831e902f61864a67ca304b01dfa73c32a..c60e361462b10e68e996d5eb4ae5edb76078a56b 100644 --- a/lib/std/crypto/aes_siv.zig +++ b/lib/std/crypto/aes_siv.zig @@ -63,13 +63,6 @@ fn AesSiv(comptime Aes: anytype) type { var d: [16]u8 = undefined; - // Special case: single empty string - if (strings.len == 1 and strings[0].len == 0) { - CmacImpl.create(&d, &[_]u8{}, &key); - iv.* = d; - return; - } - // Initialize with CMAC of zero block const zero_block: [16]u8 = @splat(0); CmacImpl.create(&d, &zero_block, &key); @@ -416,6 +409,19 @@ test "Aes128Siv - empty plaintext" { try Aes128Siv.decrypt(&decrypted, &ciphertext, tag, ad, null, key); } +test "Aes128Siv - empty plaintext without associated data" { + const key: [Aes128Siv.key_length]u8 = @splat(0x42); + var ciphertext: [0]u8 = undefined; + var tag: [Aes128Siv.tag_length]u8 = undefined; + + Aes128Siv.encrypt(&ciphertext, &tag, "", null, null, key); + + try testing.expectEqual([_]u8{ + 0x23, 0xef, 0x43, 0xc1, 0x08, 0x55, 0x68, 0x98, + 0x27, 0x56, 0xaf, 0x5c, 0x9f, 0xda, 0x7e, 0xab, + }, tag); +} + test "Aes128Siv - with nonce" { const key: [32]u8 = @splat(0x69); const nonce: [16]u8 = @splat(0x42); -- 2.54.0