diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-04-29 00:19:55 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-29 00:19:55 -0700 |
| commit | d65b42e07caa00dfe2f2fbf221c593ce57882784 (patch) | |
| tree | 7926cbea1499e0affe930bf6d7455dc24adf014e /lib/std/crypto/utils.zig | |
| parent | fd6200eda6d4fe19c34a59430a88a9ce38d6d7a4 (diff) | |
| parent | fa200ca0cad2705bad40eb723dedf4e3bf11f2ff (diff) | |
| download | zig-d65b42e07caa00dfe2f2fbf221c593ce57882784.tar.gz zig-d65b42e07caa00dfe2f2fbf221c593ce57882784.zip | |
Merge pull request #15481 from ziglang/use-mem-intrinsics
actually use the new memory intrinsics
Diffstat (limited to 'lib/std/crypto/utils.zig')
| -rw-r--r-- | lib/std/crypto/utils.zig | 12 |
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..]); |
