From f8de352e6db068fb38bcc726562feb9b3441944f Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Mon, 6 Nov 2017 21:55:20 +0100 Subject: [PATCH] Reduce nesting, improve readability --- .../curve25519/ref10/curve25519_ref10.c | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/src/libsodium/crypto_core/curve25519/ref10/curve25519_ref10.c b/src/libsodium/crypto_core/curve25519/ref10/curve25519_ref10.c index 9ddf3929..9228f3e2 100644 --- a/src/libsodium/crypto_core/curve25519/ref10/curve25519_ref10.c +++ b/src/libsodium/crypto_core/curve25519/ref10/curve25519_ref10.c @@ -192,29 +192,30 @@ slide_vartime(signed char *r, const unsigned char *a) r[i] = 1 & (a[i >> 3] >> (i & 7)); } for (i = 0; i < 256; ++i) { - if (r[i]) { - for (b = 1; b <= 6 && i + b < 256; ++b) { - if (r[i + b]) { - ribs = r[i + b] << b; - cmp = r[i] + ribs; - if (cmp <= 15) { - r[i] = cmp; - r[i + b] = 0; - } else { - cmp = r[i] - ribs; - if (cmp >= -15) { - r[i] = cmp; - for (k = i + b; k < 256; ++k) { - if (!r[k]) { - r[k] = 1; - break; - } - r[k] = 0; - } - } else { - break; - } + if (! r[i]) { + continue; + } + for (b = 1; b <= 6 && i + b < 256; ++b) { + if (! r[i + b]) { + continue; + } + ribs = r[i + b] << b; + cmp = r[i] + ribs; + if (cmp <= 15) { + r[i] = cmp; + r[i + b] = 0; + } else { + cmp = r[i] - ribs; + if (cmp < -15) { + break; + } + r[i] = cmp; + for (k = i + b; k < 256; ++k) { + if (! r[k]) { + r[k] = 1; + break; } + r[k] = 0; } } }