diff options
| author | Frank Denis <github@pureftpd.org> | 2020-08-15 08:55:48 +0200 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-08-16 22:35:27 -0700 |
| commit | 263c44473896597346bc244d82a2b436d7d2da02 (patch) | |
| tree | fd6989ebe7fb7c753ea6f3ccaacbac329198753d /lib/std | |
| parent | ed558bfbaa737b187d894eddb8573cde15a3fb33 (diff) | |
| download | zig-263c44473896597346bc244d82a2b436d7d2da02.tar.gz zig-263c44473896597346bc244d82a2b436d7d2da02.zip | |
Move loop decrements into continuations
Suggested by @daurnimator
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/crypto/25519/curve25519.zig | 3 | ||||
| -rw-r--r-- | lib/std/crypto/25519/edwards25519.zig | 3 | ||||
| -rw-r--r-- | lib/std/crypto/25519/scalar.zig | 3 |
3 files changed, 3 insertions, 6 deletions
diff --git a/lib/std/crypto/25519/curve25519.zig b/lib/std/crypto/25519/curve25519.zig index 8b8f8a5586..b3e014b6d1 100644 --- a/lib/std/crypto/25519/curve25519.zig +++ b/lib/std/crypto/25519/curve25519.zig @@ -44,7 +44,7 @@ pub const Curve25519 = struct { var z3 = Fe.one; var swap: u8 = 0; var pos: usize = bits - 1; - while (true) { + while (true) : (pos -= 1) { const b = (s[pos / 8] >> @intCast(u3, pos & 7)) & 1; swap ^= b; Fe.cSwap2(&x2, &x3, &z2, &z3, swap); @@ -68,7 +68,6 @@ pub const Curve25519 = struct { z3 = x1.mul(z2); z2 = tmp1.mul(tmp0); if (pos == 0) break; - pos -= 1; } Fe.cSwap2(&x2, &x3, &z2, &z3, swap); z2 = z2.invert(); diff --git a/lib/std/crypto/25519/edwards25519.zig b/lib/std/crypto/25519/edwards25519.zig index 3f2ede511a..a7044794b2 100644 --- a/lib/std/crypto/25519/edwards25519.zig +++ b/lib/std/crypto/25519/edwards25519.zig @@ -132,12 +132,11 @@ pub const Edwards25519 = struct { fn pcMul(pc: [16]Edwards25519, s: [32]u8) !Edwards25519 { var q = Edwards25519.identityElement(); var pos: usize = 252; - while (true) { + while (true) : (pos -= 4) { q = q.dbl().dbl().dbl().dbl(); const b = (s[pos / 8] >> @intCast(u3, pos & 7)) & 0xf; q = q.add(pcSelect(pc, b)); if (pos == 0) break; - pos -= 4; } try q.rejectIdentity(); return q; diff --git a/lib/std/crypto/25519/scalar.zig b/lib/std/crypto/25519/scalar.zig index c3340ab61e..3a3a29d4bc 100644 --- a/lib/std/crypto/25519/scalar.zig +++ b/lib/std/crypto/25519/scalar.zig @@ -116,13 +116,12 @@ pub fn rejectNonCanonical(s: [32]u8) !void { var c: u8 = 0; var n: u8 = 1; var i: usize = 31; - while (true) { + while (true) : (i -= 1) { const xs = @as(u16, s[i]); const xfield_size = @as(u16, field_size[i]); c |= @intCast(u8, ((xs -% xfield_size) >> 8) & n); n &= @intCast(u8, ((xs ^ xfield_size) -% 1) >> 8); if (i == 0) break; - i -= 1; } if (c == 0) { return error.NonCanonical; |
