Reduce nesting, improve readability

This commit is contained in:
Frank Denis 2017-11-06 21:55:20 +01:00
parent 1621448f6c
commit f8de352e6d

View File

@ -192,9 +192,13 @@ slide_vartime(signed char *r, const unsigned char *a)
r[i] = 1 & (a[i >> 3] >> (i & 7)); r[i] = 1 & (a[i >> 3] >> (i & 7));
} }
for (i = 0; i < 256; ++i) { for (i = 0; i < 256; ++i) {
if (r[i]) { if (! r[i]) {
continue;
}
for (b = 1; b <= 6 && i + b < 256; ++b) { for (b = 1; b <= 6 && i + b < 256; ++b) {
if (r[i + b]) { if (! r[i + b]) {
continue;
}
ribs = r[i + b] << b; ribs = r[i + b] << b;
cmp = r[i] + ribs; cmp = r[i] + ribs;
if (cmp <= 15) { if (cmp <= 15) {
@ -202,7 +206,9 @@ slide_vartime(signed char *r, const unsigned char *a)
r[i + b] = 0; r[i + b] = 0;
} else { } else {
cmp = r[i] - ribs; cmp = r[i] - ribs;
if (cmp >= -15) { if (cmp < -15) {
break;
}
r[i] = cmp; r[i] = cmp;
for (k = i + b; k < 256; ++k) { for (k = i + b; k < 256; ++k) {
if (! r[k]) { if (! r[k]) {
@ -211,11 +217,6 @@ slide_vartime(signed char *r, const unsigned char *a)
} }
r[k] = 0; r[k] = 0;
} }
} else {
break;
}
}
}
} }
} }
} }