aboutsummaryrefslogtreecommitdiff
path: root/lib/std/crypto/utils.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-06-24 16:58:19 -0700
committerGitHub <noreply@github.com>2023-06-24 16:58:19 -0700
commit146b79af153bbd5dafda0ba12a040385c7fc58f8 (patch)
tree67e3db8b444d65c667e314770fc983a7fc8ba293 /lib/std/crypto/utils.zig
parent13853bef0df3c90633021850cc6d6abaeea03282 (diff)
parent21ac0beb436f49fe49c6982a872f2dc48e4bea5e (diff)
downloadzig-146b79af153bbd5dafda0ba12a040385c7fc58f8.tar.gz
zig-146b79af153bbd5dafda0ba12a040385c7fc58f8.zip
Merge pull request #16163 from mlugg/feat/builtins-infer-dest-ty
Infer destination type of cast builtins using result type
Diffstat (limited to 'lib/std/crypto/utils.zig')
-rw-r--r--lib/std/crypto/utils.zig16
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/std/crypto/utils.zig b/lib/std/crypto/utils.zig
index 14a235e418..ab1b6eab6a 100644
--- a/lib/std/crypto/utils.zig
+++ b/lib/std/crypto/utils.zig
@@ -24,7 +24,7 @@ pub fn timingSafeEql(comptime T: type, a: T, b: T) bool {
const s = @typeInfo(C).Int.bits;
const Cu = std.meta.Int(.unsigned, s);
const Cext = std.meta.Int(.unsigned, s + 1);
- return @bitCast(bool, @truncate(u1, (@as(Cext, @bitCast(Cu, acc)) -% 1) >> s));
+ return @as(bool, @bitCast(@as(u1, @truncate((@as(Cext, @as(Cu, @bitCast(acc))) -% 1) >> s))));
},
.Vector => |info| {
const C = info.child;
@@ -35,7 +35,7 @@ pub fn timingSafeEql(comptime T: type, a: T, b: T) bool {
const s = @typeInfo(C).Int.bits;
const Cu = std.meta.Int(.unsigned, s);
const Cext = std.meta.Int(.unsigned, s + 1);
- return @bitCast(bool, @truncate(u1, (@as(Cext, @bitCast(Cu, acc)) -% 1) >> s));
+ return @as(bool, @bitCast(@as(u1, @truncate((@as(Cext, @as(Cu, @bitCast(acc))) -% 1) >> s))));
},
else => {
@compileError("Only arrays and vectors can be compared");
@@ -60,14 +60,14 @@ pub fn timingSafeCompare(comptime T: type, a: []const T, b: []const T, endian: E
i -= 1;
const x1 = a[i];
const x2 = b[i];
- gt |= @truncate(T, (@as(Cext, x2) -% @as(Cext, x1)) >> bits) & eq;
- eq &= @truncate(T, (@as(Cext, (x2 ^ x1)) -% 1) >> bits);
+ gt |= @as(T, @truncate((@as(Cext, x2) -% @as(Cext, x1)) >> bits)) & eq;
+ eq &= @as(T, @truncate((@as(Cext, (x2 ^ x1)) -% 1) >> bits));
}
} else {
for (a, 0..) |x1, i| {
const x2 = b[i];
- gt |= @truncate(T, (@as(Cext, x2) -% @as(Cext, x1)) >> bits) & eq;
- eq &= @truncate(T, (@as(Cext, (x2 ^ x1)) -% 1) >> bits);
+ gt |= @as(T, @truncate((@as(Cext, x2) -% @as(Cext, x1)) >> bits)) & eq;
+ eq &= @as(T, @truncate((@as(Cext, (x2 ^ x1)) -% 1) >> bits));
}
}
if (gt != 0) {
@@ -102,7 +102,7 @@ pub fn timingSafeAdd(comptime T: type, a: []const T, b: []const T, result: []T,
carry = ov1[1] | ov2[1];
}
}
- return @bitCast(bool, carry);
+ return @as(bool, @bitCast(carry));
}
/// Subtract two integers serialized as arrays of the same size, in constant time.
@@ -129,7 +129,7 @@ pub fn timingSafeSub(comptime T: type, a: []const T, b: []const T, result: []T,
borrow = ov1[1] | ov2[1];
}
}
- return @bitCast(bool, borrow);
+ return @as(bool, @bitCast(borrow));
}
/// Sets a slice to zeroes.