diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-11-16 13:39:31 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-16 13:39:31 -0800 |
| commit | ba967ae9a1eada3a08803470f557bafcfb69151e (patch) | |
| tree | 34ea140e3b9ee6ceec225e20c2dc483feb75dc81 /lib/std/mem.zig | |
| parent | 8f47e8feb60e60cc85674a9eef281197ed8a7c27 (diff) | |
| parent | 7f9e3e419c24ba51e80a4c41bcbefc820f7e0a88 (diff) | |
| download | zig-ba967ae9a1eada3a08803470f557bafcfb69151e.tar.gz zig-ba967ae9a1eada3a08803470f557bafcfb69151e.zip | |
Merge pull request #7002 from jedisct1/timingSafeEqlMinimal
Add mem.timingSafeEql() for constant-time array comparison
Diffstat (limited to 'lib/std/mem.zig')
| -rw-r--r-- | lib/std/mem.zig | 20 |
1 files changed, 0 insertions, 20 deletions
diff --git a/lib/std/mem.zig b/lib/std/mem.zig index 532c34e41c..e4d46dbf29 100644 --- a/lib/std/mem.zig +++ b/lib/std/mem.zig @@ -342,26 +342,6 @@ test "mem.zeroes" { testing.expectEqual(@as(u8, 0), c.a); } -/// Sets a slice to zeroes. -/// Prevents the store from being optimized out. -pub fn secureZero(comptime T: type, s: []T) void { - // NOTE: We do not use a volatile slice cast here since LLVM cannot - // see that it can be replaced by a memset. - const ptr = @ptrCast([*]volatile u8, s.ptr); - const length = s.len * @sizeOf(T); - @memset(ptr, 0, length); -} - -test "mem.secureZero" { - var a = [_]u8{0xfe} ** 8; - var b = [_]u8{0xfe} ** 8; - - set(u8, a[0..], 0); - secureZero(u8, b[0..]); - - testing.expectEqualSlices(u8, a[0..], b[0..]); -} - /// Initializes all fields of the struct with their default value, or zero values if no default value is present. /// If the field is present in the provided initial values, it will have that value instead. /// Structs are initialized recursively. |
