crypto: Allow arbitrary types for secureZeroes

also removed some related ptrCasts
This commit is contained in:
IntegratedQuantum 2026-02-13 16:54:10 +01:00
parent 469bf6af07
commit 0bed4fb384
3 changed files with 3 additions and 3 deletions

View file

@ -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 {

View file

@ -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.

View file

@ -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 {