From e491b4db2d0492d1a35184b2cd54c22fd9295974 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Wed, 12 Jun 2019 07:51:04 +0200 Subject: [PATCH] fix clang-tidy warnings --- bn_mp_reduce.c | 6 +++-- bn_s_mp_invmod_slow.c | 3 ++- bn_s_mp_karatsuba_mul.c | 54 +++++++++++++++++++++++++++-------------- 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/bn_mp_reduce.c b/bn_mp_reduce.c index d5d3fb1..5748550 100644 --- a/bn_mp_reduce.c +++ b/bn_mp_reduce.c @@ -64,10 +64,12 @@ mp_err mp_reduce(mp_int *x, const mp_int *m, const mp_int *mu) /* If x < 0, add b**(k+1) to it */ if (mp_cmp_d(x, 0uL) == MP_LT) { mp_set(&q, 1uL); - if ((err = mp_lshd(&q, um + 1)) != MP_OKAY) + if ((err = mp_lshd(&q, um + 1)) != MP_OKAY) { goto CLEANUP; - if ((err = mp_add(x, &q, x)) != MP_OKAY) + } + if ((err = mp_add(x, &q, x)) != MP_OKAY) { goto CLEANUP; + } } /* Back off if it's too big */ diff --git a/bn_s_mp_invmod_slow.c b/bn_s_mp_invmod_slow.c index faf6221..c03a3d7 100644 --- a/bn_s_mp_invmod_slow.c +++ b/bn_s_mp_invmod_slow.c @@ -125,8 +125,9 @@ top: } /* if not zero goto step 4 */ - if (!MP_IS_ZERO(&u)) + if (!MP_IS_ZERO(&u)) { goto top; + } /* now a = C, b = D, gcd == g*v */ diff --git a/bn_s_mp_karatsuba_mul.c b/bn_s_mp_karatsuba_mul.c index 6ef96c7..85899fb 100644 --- a/bn_s_mp_karatsuba_mul.c +++ b/bn_s_mp_karatsuba_mul.c @@ -45,22 +45,29 @@ mp_err s_mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c) B = B >> 1; /* init copy all the temps */ - if (mp_init_size(&x0, B) != MP_OKAY) + if (mp_init_size(&x0, B) != MP_OKAY) { goto LBL_ERR; - if (mp_init_size(&x1, a->used - B) != MP_OKAY) + } + if (mp_init_size(&x1, a->used - B) != MP_OKAY) { goto X0; - if (mp_init_size(&y0, B) != MP_OKAY) + } + if (mp_init_size(&y0, B) != MP_OKAY) { goto X1; - if (mp_init_size(&y1, b->used - B) != MP_OKAY) + } + if (mp_init_size(&y1, b->used - B) != MP_OKAY) { goto Y0; + } /* init temps */ - if (mp_init_size(&t1, B * 2) != MP_OKAY) + if (mp_init_size(&t1, B * 2) != MP_OKAY) { goto Y1; - if (mp_init_size(&x0y0, B * 2) != MP_OKAY) + } + if (mp_init_size(&x0y0, B * 2) != MP_OKAY) { goto T1; - if (mp_init_size(&x1y1, B * 2) != MP_OKAY) + } + if (mp_init_size(&x1y1, B * 2) != MP_OKAY) { goto X0Y0; + } /* now shift the digits */ x0.used = y0.used = B; @@ -103,35 +110,46 @@ mp_err s_mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c) /* now calc the products x0y0 and x1y1 */ /* after this x0 is no longer required, free temp [x0==t2]! */ - if (mp_mul(&x0, &y0, &x0y0) != MP_OKAY) + if (mp_mul(&x0, &y0, &x0y0) != MP_OKAY) { goto X1Y1; /* x0y0 = x0*y0 */ - if (mp_mul(&x1, &y1, &x1y1) != MP_OKAY) + } + if (mp_mul(&x1, &y1, &x1y1) != MP_OKAY) { goto X1Y1; /* x1y1 = x1*y1 */ + } /* now calc x1+x0 and y1+y0 */ - if (s_mp_add(&x1, &x0, &t1) != MP_OKAY) + if (s_mp_add(&x1, &x0, &t1) != MP_OKAY) { goto X1Y1; /* t1 = x1 - x0 */ - if (s_mp_add(&y1, &y0, &x0) != MP_OKAY) + } + if (s_mp_add(&y1, &y0, &x0) != MP_OKAY) { goto X1Y1; /* t2 = y1 - y0 */ - if (mp_mul(&t1, &x0, &t1) != MP_OKAY) + } + if (mp_mul(&t1, &x0, &t1) != MP_OKAY) { goto X1Y1; /* t1 = (x1 + x0) * (y1 + y0) */ + } /* add x0y0 */ - if (mp_add(&x0y0, &x1y1, &x0) != MP_OKAY) + if (mp_add(&x0y0, &x1y1, &x0) != MP_OKAY) { goto X1Y1; /* t2 = x0y0 + x1y1 */ - if (s_mp_sub(&t1, &x0, &t1) != MP_OKAY) + } + if (s_mp_sub(&t1, &x0, &t1) != MP_OKAY) { goto X1Y1; /* t1 = (x1+x0)*(y1+y0) - (x1y1 + x0y0) */ + } /* shift by B */ - if (mp_lshd(&t1, B) != MP_OKAY) + if (mp_lshd(&t1, B) != MP_OKAY) { goto X1Y1; /* t1 = (x0y0 + x1y1 - (x1-x0)*(y1-y0))<