Skip to content

Commit 72089c5

Browse files
committed
more explicit types mp_err, mp_ord, mp_bool, mp_sign
* MP_STRICT_TYPES enables enums * Wc++-compat catches some implicit conversions if MP_STRICT_TYPES is defined * 100% backwards compatible API/ABI if MP_STRICT_TYPES is not defined
1 parent b718609 commit 72089c5

File tree

128 files changed

+553
-461
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+553
-461
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ matrix:
112112
- gcc-4.9
113113

114114
# clang for x86-64 architecture (64-bit longs and 64-bit pointers)
115-
- env: CONV_WARNINGS=1 BUILDOPTIONS='--with-cc=clang-7 --with-m64 --with-valgrind'
115+
- env: CONV_WARNINGS=strict BUILDOPTIONS='--with-cc=clang-7 --with-m64 --with-valgrind'
116+
- env: CONV_WARNINGS=relaxed BUILDOPTIONS='--with-cc=clang-7 --with-m64 --with-valgrind'
116117
- env: BUILDOPTIONS='--with-cc=clang-6.0 --with-m64 --with-valgrind'
117118
addons:
118119
apt:

bn_deprecated.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,73 +7,73 @@
77
/* SPDX-License-Identifier: Unlicense */
88
#include <tommath_private.h>
99
#ifdef BN_FAST_MP_INVMOD_C
10-
int fast_mp_invmod(const mp_int *a, const mp_int *b, mp_int *c)
10+
mp_err fast_mp_invmod(const mp_int *a, const mp_int *b, mp_int *c)
1111
{
1212
return s_mp_invmod_fast(a, b, c);
1313
}
1414
#endif
1515
#ifdef BN_FAST_MP_MONTGOMERY_REDUCE_C
16-
int fast_mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho)
16+
mp_err fast_mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho)
1717
{
1818
return s_mp_montgomery_reduce_fast(x, n, rho);
1919
}
2020
#endif
2121
#ifdef BN_FAST_S_MP_MUL_DIGS_C
22-
int fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
22+
mp_err fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
2323
{
2424
return s_mp_mul_digs_fast(a, b, c, digs);
2525
}
2626
#endif
2727
#ifdef BN_FAST_S_MP_MUL_HIGH_DIGS_C
28-
int fast_s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
28+
mp_err fast_s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
2929
{
3030
return s_mp_mul_high_digs_fast(a, b, c, digs);
3131
}
3232
#endif
3333
#ifdef BN_FAST_S_MP_SQR_C
34-
int fast_s_mp_sqr(const mp_int *a, mp_int *b)
34+
mp_err fast_s_mp_sqr(const mp_int *a, mp_int *b)
3535
{
3636
return s_mp_sqr_fast(a, b);
3737
}
3838
#endif
3939
#ifdef BN_MP_BALANCE_MUL_C
40-
int mp_balance_mul(const mp_int *a, const mp_int *b, mp_int *c)
40+
mp_err mp_balance_mul(const mp_int *a, const mp_int *b, mp_int *c)
4141
{
4242
return s_mp_balance_mul(a, b, c);
4343
}
4444
#endif
4545
#ifdef BN_MP_EXPTMOD_FAST_C
46-
int mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, int redmode)
46+
mp_err mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, int redmode)
4747
{
4848
return s_mp_exptmod_fast(G, X, P, Y, redmode);
4949
}
5050
#endif
5151
#ifdef BN_MP_INVMOD_SLOW_C
52-
int mp_invmod_slow(const mp_int *a, const mp_int *b, mp_int *c)
52+
mp_err mp_invmod_slow(const mp_int *a, const mp_int *b, mp_int *c)
5353
{
5454
return s_mp_invmod_slow(a, b, c);
5555
}
5656
#endif
5757
#ifdef BN_MP_KARATSUBA_MUL_C
58-
int mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c)
58+
mp_err mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c)
5959
{
6060
return s_mp_karatsuba_mul(a, b, c);
6161
}
6262
#endif
6363
#ifdef BN_MP_KARATSUBA_SQR_C
64-
int mp_karatsuba_sqr(const mp_int *a, mp_int *b)
64+
mp_err mp_karatsuba_sqr(const mp_int *a, mp_int *b)
6565
{
6666
return s_mp_karatsuba_sqr(a, b);
6767
}
6868
#endif
6969
#ifdef BN_MP_TOOM_MUL_C
70-
int mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c)
70+
mp_err mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c)
7171
{
7272
return s_mp_toom_mul(a, b, c);
7373
}
7474
#endif
7575
#ifdef BN_MP_TOOM_SQR_C
76-
int mp_toom_sqr(const mp_int *a, mp_int *b)
76+
mp_err mp_toom_sqr(const mp_int *a, mp_int *b)
7777
{
7878
return s_mp_toom_sqr(a, b);
7979
}

bn_mp_2expt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
* Simple algorithm which zeroes the int, grows it then just sets one bit
99
* as required.
1010
*/
11-
int mp_2expt(mp_int *a, int b)
11+
mp_err mp_2expt(mp_int *a, int b)
1212
{
13-
int res;
13+
mp_err res;
1414

1515
/* zero a as per default */
1616
mp_zero(a);

bn_mp_abs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
*
88
* Simple function copies the input and fixes the sign to positive
99
*/
10-
int mp_abs(const mp_int *a, mp_int *b)
10+
mp_err mp_abs(const mp_int *a, mp_int *b)
1111
{
12-
int res;
12+
mp_err res;
1313

1414
/* copy a to b */
1515
if (a != b) {

bn_mp_add.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
/* SPDX-License-Identifier: Unlicense */
55

66
/* high level addition (handles signs) */
7-
int mp_add(const mp_int *a, const mp_int *b, mp_int *c)
7+
mp_err mp_add(const mp_int *a, const mp_int *b, mp_int *c)
88
{
9-
int sa, sb, res;
9+
mp_sign sa, sb;
10+
mp_err res;
1011

1112
/* get sign of both inputs */
1213
sa = a->sign;

bn_mp_add_d.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
/* SPDX-License-Identifier: Unlicense */
55

66
/* single digit addition */
7-
int mp_add_d(const mp_int *a, mp_digit b, mp_int *c)
7+
mp_err mp_add_d(const mp_int *a, mp_digit b, mp_int *c)
88
{
9-
int res, ix, oldused;
9+
mp_err res;
10+
int ix, oldused;
1011
mp_digit *tmpa, *tmpc, mu;
1112

1213
/* grow c as required */

bn_mp_addmod.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
/* SPDX-License-Identifier: Unlicense */
55

66
/* d = a + b (mod c) */
7-
int mp_addmod(const mp_int *a, const mp_int *b, const mp_int *c, mp_int *d)
7+
mp_err mp_addmod(const mp_int *a, const mp_int *b, const mp_int *c, mp_int *d)
88
{
9-
int res;
9+
mp_err res;
1010
mp_int t;
1111

1212
if ((res = mp_init(&t)) != MP_OKAY) {

bn_mp_and.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
/* SPDX-License-Identifier: Unlicense */
55

66
/* AND two ints together */
7-
int mp_and(const mp_int *a, const mp_int *b, mp_int *c)
7+
mp_err mp_and(const mp_int *a, const mp_int *b, mp_int *c)
88
{
9-
int res, ix, px;
9+
int ix, px;
10+
mp_err res;
1011
mp_int t;
1112
const mp_int *x;
1213

bn_mp_cmp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/* SPDX-License-Identifier: Unlicense */
55

66
/* compare two ints (signed)*/
7-
int mp_cmp(const mp_int *a, const mp_int *b)
7+
mp_ord mp_cmp(const mp_int *a, const mp_int *b)
88
{
99
/* compare based on sign */
1010
if (a->sign != b->sign) {

bn_mp_cmp_d.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/* SPDX-License-Identifier: Unlicense */
55

66
/* compare a digit */
7-
int mp_cmp_d(const mp_int *a, mp_digit b)
7+
mp_ord mp_cmp_d(const mp_int *a, mp_digit b)
88
{
99
/* compare based on sign */
1010
if (a->sign == MP_NEG) {

0 commit comments

Comments
 (0)