add parentheses for explicit operator association

This commit is contained in:
Francois Perrad 2015-10-17 18:28:05 +02:00 committed by Steffen Jaeckel
parent 99c84acc4c
commit 81d5f0e39a
7 changed files with 19 additions and 19 deletions

View File

@ -66,7 +66,7 @@ int fast_s_mp_sqr (mp_int * a, mp_int * b)
* we halve the distance since they approach at a rate of 2x
* and we have to round because odd cases need to be executed
*/
iy = MIN(iy, (ty-tx+1)>>1);
iy = MIN(iy, ((ty-tx)+1)>>1);
/* execute loop */
for (iz = 0; iz < iy; iz++) {

View File

@ -190,7 +190,7 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
/* step 3.1 if xi == yt then set q{i-t-1} to b-1,
* otherwise set q{i-t-1} to (xi*b + x{i-1})/yt */
if (x.dp[i] == y.dp[t]) {
q.dp[i - t - 1] = ((((mp_digit)1) << DIGIT_BIT) - 1);
q.dp[(i - t) - 1] = ((((mp_digit)1) << DIGIT_BIT) - 1);
} else {
mp_word tmp;
tmp = ((mp_word) x.dp[i]) << ((mp_word) DIGIT_BIT);
@ -199,7 +199,7 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
if (tmp > (mp_word) MP_MASK) {
tmp = MP_MASK;
}
q.dp[i - t - 1] = (mp_digit) (tmp & (mp_word) (MP_MASK));
q.dp[(i - t) - 1] = (mp_digit) (tmp & (mp_word) (MP_MASK));
}
/* while (q{i-t-1} * (yt * b + y{t-1})) >
@ -207,16 +207,16 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
do q{i-t-1} -= 1;
*/
q.dp[i - t - 1] = (q.dp[i - t - 1] + 1) & MP_MASK;
q.dp[(i - t) - 1] = (q.dp[(i - t) - 1] + 1) & MP_MASK;
do {
q.dp[i - t - 1] = (q.dp[i - t - 1] - 1) & MP_MASK;
q.dp[(i - t) - 1] = (q.dp[(i - t) - 1] - 1) & MP_MASK;
/* find left hand */
mp_zero (&t1);
t1.dp[0] = ((t - 1) < 0) ? 0 : y.dp[t - 1];
t1.dp[1] = y.dp[t];
t1.used = 2;
if ((res = mp_mul_d (&t1, q.dp[i - t - 1], &t1)) != MP_OKAY) {
if ((res = mp_mul_d (&t1, q.dp[(i - t) - 1], &t1)) != MP_OKAY) {
goto LBL_Y;
}
@ -228,11 +228,11 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
} while (mp_cmp_mag(&t1, &t2) == MP_GT);
/* step 3.3 x = x - q{i-t-1} * y * b**{i-t-1} */
if ((res = mp_mul_d (&y, q.dp[i - t - 1], &t1)) != MP_OKAY) {
if ((res = mp_mul_d (&y, q.dp[(i - t) - 1], &t1)) != MP_OKAY) {
goto LBL_Y;
}
if ((res = mp_lshd (&t1, i - t - 1)) != MP_OKAY) {
if ((res = mp_lshd (&t1, (i - t) - 1)) != MP_OKAY) {
goto LBL_Y;
}
@ -245,14 +245,14 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
if ((res = mp_copy (&y, &t1)) != MP_OKAY) {
goto LBL_Y;
}
if ((res = mp_lshd (&t1, i - t - 1)) != MP_OKAY) {
if ((res = mp_lshd (&t1, (i - t) - 1)) != MP_OKAY) {
goto LBL_Y;
}
if ((res = mp_add (&x, &t1, &x)) != MP_OKAY) {
goto LBL_Y;
}
q.dp[i - t - 1] = (q.dp[i - t - 1] - 1UL) & MP_MASK;
q.dp[(i - t) - 1] = (q.dp[(i - t) - 1] - 1UL) & MP_MASK;
}
}

View File

@ -54,8 +54,8 @@ int mp_export(void* rop, size_t* countp, int order, size_t size,
for (j = 0; j < size; ++j) {
unsigned char* byte = (
(unsigned char*)rop +
(((order == -1) ? i : (count - 1 - i)) * size) +
((endian == -1) ? j : (size - 1 - j))
(((order == -1) ? i : ((count - 1) - i)) * size) +
((endian == -1) ? j : ((size - 1) - j))
);
if (j >= (size - nail_bytes)) {
@ -63,9 +63,9 @@ int mp_export(void* rop, size_t* countp, int order, size_t size,
continue;
}
*byte = (unsigned char)((j == (size - nail_bytes - 1)) ? (t.dp[0] & odd_nail_mask) : (t.dp[0] & 0xFF));
*byte = (unsigned char)((j == ((size - nail_bytes) - 1)) ? (t.dp[0] & odd_nail_mask) : (t.dp[0] & 0xFF));
if ((result = mp_div_2d(&t, ((j == (size - nail_bytes - 1)) ? (8 - odd_nails) : 8), &t, NULL)) != MP_OKAY) {
if ((result = mp_div_2d(&t, ((j == ((size - nail_bytes) - 1)) ? (8 - odd_nails) : 8), &t, NULL)) != MP_OKAY) {
mp_clear(&t);
return result;
}

View File

@ -47,8 +47,8 @@ int mp_import(mp_int* rop, size_t count, int order, size_t size,
for (j = 0; j < (size - nail_bytes); ++j) {
unsigned char byte = *(
(unsigned char*)op +
(((order == 1) ? i : (count - 1 - i)) * size) +
((endian == 1) ? (j + nail_bytes) : (size - 1 - j - nail_bytes))
(((order == 1) ? i : ((count - 1) - i)) * size) +
((endian == 1) ? (j + nail_bytes) : (((size - 1) - j) - nail_bytes))
);
if (

View File

@ -42,7 +42,7 @@ int mp_lshd (mp_int * a, int b)
top = a->dp + a->used - 1;
/* base */
bottom = a->dp + a->used - 1 - b;
bottom = (a->dp + a->used - 1) - b;
/* much like mp_rshd this is implemented using a sliding window
* except the window goes the otherway around. Copying from

View File

@ -38,7 +38,7 @@ mp_sqr (mp_int * a, mp_int * b)
/* can we use the fast comba multiplier? */
if ((((a->used * 2) + 1) < MP_WARRAY) &&
(a->used <
(1 << ((sizeof(mp_word) * CHAR_BIT) - (2 * DIGIT_BIT) - 1)))) {
(1 << (((sizeof(mp_word) * CHAR_BIT) - (2 * DIGIT_BIT)) - 1)))) {
res = fast_s_mp_sqr (a, b);
} else
#endif

View File

@ -47,7 +47,7 @@ s_mp_sub (mp_int * a, mp_int * b, mp_int * c)
u = 0;
for (i = 0; i < min; i++) {
/* T[i] = A[i] - B[i] - U */
*tmpc = *tmpa++ - *tmpb++ - u;
*tmpc = (*tmpa++ - *tmpb++) - u;
/* U = carry bit of T[i]
* Note this saves performing an AND operation since