authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2026-07-12 13:23:53+02:00
committergravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2026-07-12 13:23:53+02:00
logcc5dbff35fc8024cff0a1559de12ffbf7b809107
tree2259cd02591b5671399cbb672edb77139c3b8487
parentcb5635714cbd8c7fc2911536e59e58b96fe0ba1f
parente3395669223afa70a5cae1dd9a12b3a5f0656209

Merge pull request 'crypto.mode.ctr: make the counter wrap, even in parallel updates' (#35909) from jedisct1/zig:ctr-mode-wrap into master

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

1 files changed, 8 insertions(+), 1 deletions(-)

lib/std/crypto/modes.zig+8-1
......@@ -55,7 +55,7 @@ pub fn ctrSlice(
5555 inline while (j < parallel_count) : (j += 1) {
5656 mem.writeInt(CounterInt, counters[j * block_length + counter_offset ..][0..counter_size], cnt_val +% j, endian);
5757 }
58 cnt_val += parallel_count;
58 cnt_val +%= parallel_count;
5959 block_cipher.xorWide(parallel_count, dst[i .. i + wide_block_length][0..wide_block_length], src[i .. i + wide_block_length][0..wide_block_length], counters);
6060 }
6161 mem.writeInt(CounterInt, counterBlock[counter_offset..][0..counter_size], cnt_val, endian);
......@@ -224,4 +224,11 @@ test "ctr mode" {
224224 const expected = [_]u8{ 0x7e, 0x48, 0x15, 0xa8, 0x16, 0x66, 0xf0, 0xea, 0xad, 0x3c, 0x07, 0x97, 0x2f, 0xe8, 0x25, 0xc1 };
225225 try testing.expectEqualSlices(u8, expected[0..], out[0..]);
226226 }
227
228 // Make the counter wrap
229 {
230 const iv_top: [16]u8 = @splat(0xff);
231 var buf: [256]u8 = @splat(0);
232 ctr(aes.AesEncryptCtx(aes.Aes128), ctx, buf[0..], buf[0..], iv_top, .little);
233 }
227234}