Merge pull request #125 from fperrad/20180923_lint

two-complement: some linting
This commit is contained in:
Steffen Jaeckel 2018-09-23 21:31:27 +02:00 committed by GitHub
commit 05dea227be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 30 deletions

View File

@ -17,7 +17,7 @@
int mp_complement(const mp_int *a, mp_int *b) int mp_complement(const mp_int *a, mp_int *b)
{ {
int res = mp_neg(a, b); int res = mp_neg(a, b);
return res == MP_OKAY ? mp_sub_d(b, 1, b) : res; return (res == MP_OKAY) ? mp_sub_d(b, 1uL, b) : res;
} }
#endif #endif

View File

@ -17,12 +17,12 @@
int mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c) int mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c)
{ {
int res = MP_OKAY, bits; int res = MP_OKAY, bits;
int as = mp_isneg(a), bs = mp_isneg(b), s = 0; int as = mp_isneg(a), bs = mp_isneg(b);
mp_int *mx = 0, _mx, acpy, bcpy; mp_int *mx = NULL, _mx, acpy, bcpy;
if (as || bs) { if ((as != MP_NO) || (bs != MP_NO)) {
bits = MAX(mp_count_bits(a), mp_count_bits(b)); bits = MAX(mp_count_bits(a), mp_count_bits(b));
res = mp_init_set_int(&_mx, 1); res = mp_init_set_int(&_mx, 1uL);
if (res != MP_OKAY) { if (res != MP_OKAY) {
goto end; goto end;
} }
@ -33,7 +33,7 @@ int mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c)
goto end; goto end;
} }
if (as) { if (as != MP_NO) {
res = mp_init(&acpy); res = mp_init(&acpy);
if (res != MP_OKAY) { if (res != MP_OKAY) {
goto end; goto end;
@ -46,7 +46,7 @@ int mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c)
} }
a = &acpy; a = &acpy;
} }
if (bs) { if (bs != MP_NO) {
res = mp_init(&bcpy); res = mp_init(&bcpy);
if (res != MP_OKAY) { if (res != MP_OKAY) {
goto end; goto end;
@ -62,9 +62,8 @@ int mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c)
} }
res = mp_and(a, b, c); res = mp_and(a, b, c);
s = as & bs;
if (s && res == MP_OKAY) { if ((as != MP_NO) && (bs != MP_NO) && (res == MP_OKAY)) {
res = mp_sub(c, mx, c); res = mp_sub(c, mx, c);
} }

View File

@ -17,17 +17,17 @@
int mp_tc_div_2d(const mp_int *a, int b, mp_int *c) int mp_tc_div_2d(const mp_int *a, int b, mp_int *c)
{ {
int res; int res;
if (!mp_isneg(a)) { if (mp_isneg(a) == MP_NO) {
return mp_div_2d(a, b, c, 0); return mp_div_2d(a, b, c, NULL);
} }
res = mp_add_d(a, 1, c); res = mp_add_d(a, 1uL, c);
if (res != MP_OKAY) { if (res != MP_OKAY) {
return res; return res;
} }
res = mp_div_2d(c, b, c, 0); res = mp_div_2d(c, b, c, NULL);
return res == MP_OKAY ? mp_sub_d(c, 1, c) : res; return (res == MP_OKAY) ? mp_sub_d(c, 1uL, c) : res;
} }
#endif #endif

View File

@ -17,12 +17,12 @@
int mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c) int mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c)
{ {
int res = MP_OKAY, bits; int res = MP_OKAY, bits;
int as = mp_isneg(a), bs = mp_isneg(b), s = 0; int as = mp_isneg(a), bs = mp_isneg(b);
mp_int *mx = 0, _mx, acpy, bcpy; mp_int *mx = NULL, _mx, acpy, bcpy;
if (as || bs) { if ((as != MP_NO) || (bs != MP_NO)) {
bits = MAX(mp_count_bits(a), mp_count_bits(b)); bits = MAX(mp_count_bits(a), mp_count_bits(b));
res = mp_init_set_int(&_mx, 1); res = mp_init_set_int(&_mx, 1uL);
if (res != MP_OKAY) { if (res != MP_OKAY) {
goto end; goto end;
} }
@ -33,7 +33,7 @@ int mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c)
goto end; goto end;
} }
if (as) { if (as != MP_NO) {
res = mp_init(&acpy); res = mp_init(&acpy);
if (res != MP_OKAY) { if (res != MP_OKAY) {
goto end; goto end;
@ -46,7 +46,7 @@ int mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c)
} }
a = &acpy; a = &acpy;
} }
if (bs) { if (bs != MP_NO) {
res = mp_init(&bcpy); res = mp_init(&bcpy);
if (res != MP_OKAY) { if (res != MP_OKAY) {
goto end; goto end;
@ -62,9 +62,8 @@ int mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c)
} }
res = mp_or(a, b, c); res = mp_or(a, b, c);
s = as | bs;
if (s && res == MP_OKAY) { if (((as != MP_NO) || (bs != MP_NO)) && (res == MP_OKAY)) {
res = mp_sub(c, mx, c); res = mp_sub(c, mx, c);
} }

View File

@ -17,12 +17,12 @@
int mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c) int mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c)
{ {
int res = MP_OKAY, bits; int res = MP_OKAY, bits;
int as = mp_isneg(a), bs = mp_isneg(b), s = 0; int as = mp_isneg(a), bs = mp_isneg(b);
mp_int *mx = 0, _mx, acpy, bcpy; mp_int *mx = NULL, _mx, acpy, bcpy;
if (as || bs) { if ((as != MP_NO) || (bs != MP_NO)) {
bits = MAX(mp_count_bits(a), mp_count_bits(b)); bits = MAX(mp_count_bits(a), mp_count_bits(b));
res = mp_init_set_int(&_mx, 1); res = mp_init_set_int(&_mx, 1uL);
if (res != MP_OKAY) { if (res != MP_OKAY) {
goto end; goto end;
} }
@ -33,7 +33,7 @@ int mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c)
goto end; goto end;
} }
if (as) { if (as != MP_NO) {
res = mp_init(&acpy); res = mp_init(&acpy);
if (res != MP_OKAY) { if (res != MP_OKAY) {
goto end; goto end;
@ -46,7 +46,7 @@ int mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c)
} }
a = &acpy; a = &acpy;
} }
if (bs) { if (bs != MP_NO) {
res = mp_init(&bcpy); res = mp_init(&bcpy);
if (res != MP_OKAY) { if (res != MP_OKAY) {
goto end; goto end;
@ -62,9 +62,8 @@ int mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c)
} }
res = mp_xor(a, b, c); res = mp_xor(a, b, c);
s = as ^ bs;
if (s && res == MP_OKAY) { if ((as != bs) && (res == MP_OKAY)) {
res = mp_sub(c, mx, c); res = mp_sub(c, mx, c);
} }