| ... | @@ -63,13 +63,6 @@ fn AesSiv(comptime Aes: anytype) type { | ... | @@ -63,13 +63,6 @@ fn AesSiv(comptime Aes: anytype) type { |
| 63 | | 63 | |
| 64 | var d: [16]u8 = undefined; | 64 | var d: [16]u8 = undefined; |
| 65 | | 65 | |
| 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 block | 66 | // 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 | } |
| 418 | | 411 | |
| | 412 | test "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 | |
| 419 | test "Aes128Siv - with nonce" { | 425 | test "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); |