From d2c9a51d1e9aa9de1341bfb52caf8b15daffe79c Mon Sep 17 00:00:00 2001 From: Frank Denis <124872+jedisct1@users.noreply.github.com> Date: Tue, 23 Jul 2024 01:04:32 +0200 Subject: [PATCH] Fix function definition: ChaCha20With64BitNonce counter is u64 (#20734) Fixes #20732 --- lib/std/crypto/chacha20.zig | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/std/crypto/chacha20.zig b/lib/std/crypto/chacha20.zig index ded0a18b49..ccac14511a 100644 --- a/lib/std/crypto/chacha20.zig +++ b/lib/std/crypto/chacha20.zig @@ -590,21 +590,21 @@ fn ChaChaWith64BitNonce(comptime rounds_nb: usize) type { const k = keyToWords(key); var c: [4]u32 = undefined; - c[0] = @as(u32, @truncate(counter)); - c[1] = @as(u32, @truncate(counter >> 32)); + c[0] = @truncate(counter); + c[1] = @truncate(counter >> 32); c[2] = mem.readInt(u32, nonce[0..4], .little); c[3] = mem.readInt(u32, nonce[4..8], .little); ChaChaImpl(rounds_nb).chacha20Xor(out, in, k, c, true); } /// Write the output of the ChaCha20 stream cipher into `out`. - pub fn stream(out: []u8, counter: u32, key: [key_length]u8, nonce: [nonce_length]u8) void { + pub fn stream(out: []u8, counter: u64, key: [key_length]u8, nonce: [nonce_length]u8) void { assert(out.len <= 64 * (@as(u71, 1 << 64) - counter)); const k = keyToWords(key); var c: [4]u32 = undefined; - c[0] = @as(u32, @truncate(counter)); - c[1] = @as(u32, @truncate(counter >> 32)); + c[0] = @truncate(counter); + c[1] = @truncate(counter >> 32); c[2] = mem.readInt(u32, nonce[0..4], .little); c[3] = mem.readInt(u32, nonce[4..8], .little); ChaChaImpl(rounds_nb).chacha20Stream(out, k, c, true);