authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2020-08-15 11:11:33+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-16 22:35:27-07:00
logd86cde575239d4e38631d562fba8b4001d436ebd
tree32c6c9e4a2875fc274c54deb5d55fb40a66ebe7f
parentbcef123d902b9d1d8a27b0414932b1b92f6f1a7e

Add comment, use @truncate


2 files changed, 3 insertions(+), 3 deletions(-)

lib/std/crypto/25519/curve25519.zig+1-1
......@@ -43,7 +43,7 @@ pub const Curve25519 = struct {
4343 var swap: u8 = 0;
4444 var pos: usize = bits - 1;
4545 while (true) : (pos -= 1) {
46 const b = (s[pos / 8] >> @intCast(u3, pos & 7)) & 1;
46 const b = (s[pos >> 3] >> @truncate(u3, pos)) & 1;
4747 swap ^= b;
4848 Fe.cSwap2(&x2, &x3, &z2, &z3, swap);
4949 swap = b;
lib/std/crypto/25519/edwards25519.zig+2-2
......@@ -28,7 +28,7 @@ pub const Edwards25519 = struct {
2828 const vxx = x.sq().mul(v);
2929 const has_m_root = vxx.sub(u).isZero();
3030 const has_p_root = vxx.add(u).isZero();
31 if ((@boolToInt(has_m_root) | @boolToInt(has_p_root)) == 0) {
31 if ((@boolToInt(has_m_root) | @boolToInt(has_p_root)) == 0) { // best-effort to avoid two conditional branches
3232 return error.InvalidEncoding;
3333 }
3434 x.cMov(x.mul(Fe.sqrtm1), 1 - @boolToInt(has_m_root));
......@@ -130,7 +130,7 @@ pub const Edwards25519 = struct {
130130 var pos: usize = 252;
131131 while (true) : (pos -= 4) {
132132 q = q.dbl().dbl().dbl().dbl();
133 const b = (s[pos / 8] >> @intCast(u3, pos & 7)) & 0xf;
133 const b = (s[pos >> 3] >> @truncate(u3, pos)) & 0xf;
134134 q = q.add(pcSelect(pc, b));
135135 if (pos == 0) break;
136136 }