zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit d86cde575239d4e38631d562fba8b4001d436ebd (tree)
parent bcef123d902b9d1d8a27b0414932b1b92f6f1a7e
Author: Frank Denis <github@pureftpd.org>
Date:   Sat, 15 Aug 2020 11:11:33 +0200

Add comment, use @truncate

Diffstat:
Mlib/std/crypto/25519/curve25519.zig | 2+-
Mlib/std/crypto/25519/edwards25519.zig | 4++--
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/std/crypto/25519/curve25519.zig b/lib/std/crypto/25519/curve25519.zig @@ -43,7 +43,7 @@ pub const Curve25519 = struct { var swap: u8 = 0; var pos: usize = bits - 1; while (true) : (pos -= 1) { - const b = (s[pos / 8] >> @intCast(u3, pos & 7)) & 1; + const b = (s[pos >> 3] >> @truncate(u3, pos)) & 1; swap ^= b; Fe.cSwap2(&x2, &x3, &z2, &z3, swap); swap = b; diff --git a/lib/std/crypto/25519/edwards25519.zig b/lib/std/crypto/25519/edwards25519.zig @@ -28,7 +28,7 @@ pub const Edwards25519 = struct { const vxx = x.sq().mul(v); const has_m_root = vxx.sub(u).isZero(); const has_p_root = vxx.add(u).isZero(); - if ((@boolToInt(has_m_root) | @boolToInt(has_p_root)) == 0) { + if ((@boolToInt(has_m_root) | @boolToInt(has_p_root)) == 0) { // best-effort to avoid two conditional branches return error.InvalidEncoding; } x.cMov(x.mul(Fe.sqrtm1), 1 - @boolToInt(has_m_root)); @@ -130,7 +130,7 @@ pub const Edwards25519 = struct { var pos: usize = 252; while (true) : (pos -= 4) { q = q.dbl().dbl().dbl().dbl(); - const b = (s[pos / 8] >> @intCast(u3, pos & 7)) & 0xf; + const b = (s[pos >> 3] >> @truncate(u3, pos)) & 0xf; q = q.add(pcSelect(pc, b)); if (pos == 0) break; }