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 {...@@ -43,7 +43,7 @@ pub const Curve25519 = struct {
43 var swap: u8 = 0;43 var swap: u8 = 0;
44 var pos: usize = bits - 1;44 var pos: usize = bits - 1;
45 while (true) : (pos -= 1) {45 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;
47 swap ^= b;47 swap ^= b;
48 Fe.cSwap2(&x2, &x3, &z2, &z3, swap);48 Fe.cSwap2(&x2, &x3, &z2, &z3, swap);
49 swap = b;49 swap = b;
lib/std/crypto/25519/edwards25519.zig+2-2
...@@ -28,7 +28,7 @@ pub const Edwards25519 = struct {...@@ -28,7 +28,7 @@ pub const Edwards25519 = struct {
28 const vxx = x.sq().mul(v);28 const vxx = x.sq().mul(v);
29 const has_m_root = vxx.sub(u).isZero();29 const has_m_root = vxx.sub(u).isZero();
30 const has_p_root = vxx.add(u).isZero();30 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
32 return error.InvalidEncoding;32 return error.InvalidEncoding;
33 }33 }
34 x.cMov(x.mul(Fe.sqrtm1), 1 - @boolToInt(has_m_root));34 x.cMov(x.mul(Fe.sqrtm1), 1 - @boolToInt(has_m_root));
...@@ -130,7 +130,7 @@ pub const Edwards25519 = struct {...@@ -130,7 +130,7 @@ pub const Edwards25519 = struct {
130 var pos: usize = 252;130 var pos: usize = 252;
131 while (true) : (pos -= 4) {131 while (true) : (pos -= 4) {
132 q = q.dbl().dbl().dbl().dbl();132 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;
134 q = q.add(pcSelect(pc, b));134 q = q.add(pcSelect(pc, b));
135 if (pos == 0) break;135 if (pos == 0) break;
136 }136 }