Skip to content

Commit d2c9a51

Browse files
authored
Fix function definition: ChaCha20With64BitNonce counter is u64 (#20734)
Fixes #20732
1 parent eac7fd4 commit d2c9a51

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/std/crypto/chacha20.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -590,21 +590,21 @@ fn ChaChaWith64BitNonce(comptime rounds_nb: usize) type {
590590

591591
const k = keyToWords(key);
592592
var c: [4]u32 = undefined;
593-
c[0] = @as(u32, @truncate(counter));
594-
c[1] = @as(u32, @truncate(counter >> 32));
593+
c[0] = @truncate(counter);
594+
c[1] = @truncate(counter >> 32);
595595
c[2] = mem.readInt(u32, nonce[0..4], .little);
596596
c[3] = mem.readInt(u32, nonce[4..8], .little);
597597
ChaChaImpl(rounds_nb).chacha20Xor(out, in, k, c, true);
598598
}
599599

600600
/// Write the output of the ChaCha20 stream cipher into `out`.
601-
pub fn stream(out: []u8, counter: u32, key: [key_length]u8, nonce: [nonce_length]u8) void {
601+
pub fn stream(out: []u8, counter: u64, key: [key_length]u8, nonce: [nonce_length]u8) void {
602602
assert(out.len <= 64 * (@as(u71, 1 << 64) - counter));
603603

604604
const k = keyToWords(key);
605605
var c: [4]u32 = undefined;
606-
c[0] = @as(u32, @truncate(counter));
607-
c[1] = @as(u32, @truncate(counter >> 32));
606+
c[0] = @truncate(counter);
607+
c[1] = @truncate(counter >> 32);
608608
c[2] = mem.readInt(u32, nonce[0..4], .little);
609609
c[3] = mem.readInt(u32, nonce[4..8], .little);
610610
ChaChaImpl(rounds_nb).chacha20Stream(out, k, c, true);

0 commit comments

Comments
 (0)