authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2026-10-06 10:41:10+02:00
committergravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2026-10-06 10:41:10+02:00
log54460688aeb62584186e2fd3cb8998a8fa349c09
tree50a1fd60b282f6dc659081d835f43864ee7dc16d
parentc389ce7d00a5f8803b17140da4fd114983f1d748
parenta64a25533547172bd0bee30417962afa1540dd90

Merge pull request 'crypto.aessiv: there's no special case for the empty string' (#37084) from jedisct1/zig:aessivempty into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/37084

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 {...@@ -63,13 +63,6 @@ fn AesSiv(comptime Aes: anytype) type {
6363
64 var d: [16]u8 = undefined;64 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
73 // Initialize with CMAC of zero block66 // Initialize with CMAC of zero block
74 const zero_block: [16]u8 = @splat(0);67 const zero_block: [16]u8 = @splat(0);
75 CmacImpl.create(&d, &zero_block, &key);68 CmacImpl.create(&d, &zero_block, &key);
...@@ -416,6 +409,19 @@ test "Aes128Siv - empty plaintext" {...@@ -416,6 +409,19 @@ test "Aes128Siv - empty plaintext" {
416 try Aes128Siv.decrypt(&decrypted, &ciphertext, tag, ad, null, key);409 try Aes128Siv.decrypt(&decrypted, &ciphertext, tag, ad, null, key);
417}410}
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
419test "Aes128Siv - with nonce" {425test "Aes128Siv - with nonce" {
420 const key: [32]u8 = @splat(0x69);426 const key: [32]u8 = @splat(0x69);
421 const nonce: [16]u8 = @splat(0x42);427 const nonce: [16]u8 = @splat(0x42);