aboutsummaryrefslogtreecommitdiff
path: root/lib/std/crypto/utils.zig
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std/crypto/utils.zig')
-rw-r--r--lib/std/crypto/utils.zig12
1 files changed, 4 insertions, 8 deletions
diff --git a/lib/std/crypto/utils.zig b/lib/std/crypto/utils.zig
index 38dc236455..14a235e418 100644
--- a/lib/std/crypto/utils.zig
+++ b/lib/std/crypto/utils.zig
@@ -134,12 +134,8 @@ pub fn timingSafeSub(comptime T: type, a: []const T, b: []const T, result: []T,
/// Sets a slice to zeroes.
/// Prevents the store from being optimized out.
-pub fn secureZero(comptime T: type, s: []T) void {
- // TODO: implement `@memset` for non-byte-sized element type in the llvm backend
- //@memset(@as([]volatile T, s), 0);
- const ptr = @ptrCast([*]volatile u8, s.ptr);
- const length = s.len * @sizeOf(T);
- @memset(ptr[0..length], 0);
+pub inline fn secureZero(comptime T: type, s: []T) void {
+ @memset(@as([]volatile T, s), 0);
}
test "crypto.utils.timingSafeEql" {
@@ -148,7 +144,7 @@ test "crypto.utils.timingSafeEql" {
random.bytes(a[0..]);
random.bytes(b[0..]);
try testing.expect(!timingSafeEql([100]u8, a, b));
- mem.copy(u8, a[0..], b[0..]);
+ a = b;
try testing.expect(timingSafeEql([100]u8, a, b));
}
@@ -201,7 +197,7 @@ test "crypto.utils.secureZero" {
var a = [_]u8{0xfe} ** 8;
var b = [_]u8{0xfe} ** 8;
- mem.set(u8, a[0..], 0);
+ @memset(a[0..], 0);
secureZero(u8, b[0..]);
try testing.expectEqualSlices(u8, a[0..], b[0..]);