From 0bed4fb384f2e4d0f33307f63e9d3a1f023438e4 Mon Sep 17 00:00:00 2001 From: IntegratedQuantum Date: Fri, 13 Feb 2026 16:54:10 +0100 Subject: [PATCH] crypto: Allow arbitrary types for secureZeroes also removed some related ptrCasts --- lib/std/crypto.zig | 2 +- lib/std/crypto/ghash_polyval.zig | 2 +- lib/std/crypto/poly1305.zig | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/std/crypto.zig b/lib/std/crypto.zig index 7833a31237..d020d61e14 100644 --- a/lib/std/crypto.zig +++ b/lib/std/crypto.zig @@ -412,7 +412,7 @@ test "issue #4532: no index out of bounds" { /// Sets a slice to zeroes. /// Prevents the store from being optimized out. pub fn secureZero(comptime T: type, s: []volatile T) void { - @memset(s, 0); + @memset(s, std.mem.zeroes(T)); } test secureZero { diff --git a/lib/std/crypto/ghash_polyval.zig b/lib/std/crypto/ghash_polyval.zig index 45b2beb91b..8e33eb8075 100644 --- a/lib/std/crypto/ghash_polyval.zig +++ b/lib/std/crypto/ghash_polyval.zig @@ -402,7 +402,7 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type { st.pad(); mem.writeInt(u128, out[0..16], st.acc, endian); - std.crypto.secureZero(u8, @as([*]u8, @ptrCast(st))[0..@sizeOf(Self)]); + std.crypto.secureZero(Self, st[0..1]); } /// Compute the GHASH of a message. diff --git a/lib/std/crypto/poly1305.zig b/lib/std/crypto/poly1305.zig index 5bf5a57428..3d6e4d89c3 100644 --- a/lib/std/crypto/poly1305.zig +++ b/lib/std/crypto/poly1305.zig @@ -184,7 +184,7 @@ pub const Poly1305 = struct { mem.writeInt(u64, out[0..8], st.h[0], .little); mem.writeInt(u64, out[8..16], st.h[1], .little); - std.crypto.secureZero(u8, @as([*]u8, @ptrCast(st))[0..@sizeOf(Poly1305)]); + std.crypto.secureZero(Poly1305, st[0..1]); } pub fn create(out: *[mac_length]u8, msg: []const u8, key: *const [key_length]u8) void {