summaryrefslogtreecommitdiff
path: root/lib/freebl/mpi/mpi.c
diff options
context:
space:
mode:
authorFranziskus Kiefer <franziskuskiefer@gmail.com>2015-11-09 08:13:38 +0100
committerFranziskus Kiefer <franziskuskiefer@gmail.com>2015-11-09 08:13:38 +0100
commit712274457c3253d077c9b82c6f456f9f43456371 (patch)
tree1e97ab21155c83887f1150b86b252d162f6c6eea /lib/freebl/mpi/mpi.c
parent7d252d8828fb1f88a37392118e2d2352d05c6d3d (diff)
downloadnss-hg-712274457c3253d077c9b82c6f456f9f43456371.tar.gz
Bug 1220683 - Checking return values in mpi.c, r=mt
Diffstat (limited to 'lib/freebl/mpi/mpi.c')
-rw-r--r--lib/freebl/mpi/mpi.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/freebl/mpi/mpi.c b/lib/freebl/mpi/mpi.c
index 0cacc4081..0feecbc3b 100644
--- a/lib/freebl/mpi/mpi.c
+++ b/lib/freebl/mpi/mpi.c
@@ -11,6 +11,7 @@
#if defined(OSF1)
#include <c_asm.h>
#endif
+#include <assert.h>
#if defined(__arm__) && \
((defined(__thumb__) && !defined(__thumb2__)) || defined(__ARM_ARCH_3__))
@@ -545,7 +546,9 @@ mp_err mp_div_d(const mp_int *a, mp_digit d, mp_int *q, mp_digit *r)
rem = DIGIT(a, 0) & mask;
if(q) {
- mp_copy(a, q);
+ if((res = mp_copy(a, q)) != MP_OKAY) {
+ return res;
+ }
s_mp_div_2d(q, pow);
}
@@ -1314,8 +1317,8 @@ mp_err mp_sqrt(const mp_int *a, mp_int *b)
for(;;) {
/* t = (x * x) - a */
- mp_copy(&x, &t); /* can't fail, t is big enough for original x */
- if((res = mp_sqr(&t, &t)) != MP_OKAY ||
+ if((res = mp_copy(&x, &t)) != MP_OKAY ||
+ (res = mp_sqr(&t, &t)) != MP_OKAY ||
(res = mp_sub(&t, a, &t)) != MP_OKAY)
goto CLEANUP;
@@ -1488,8 +1491,10 @@ mp_err s_mp_exptmod(const mp_int *a, const mp_int *b, const mp_int *m, mp_int *c
mp_set(&s, 1);
/* mu = b^2k / m */
- s_mp_add_d(&mu, 1);
- s_mp_lshd(&mu, 2 * USED(m));
+ if((res = s_mp_add_d(&mu, 1)) != MP_OKAY)
+ goto CLEANUP;
+ if((res = s_mp_lshd(&mu, 2 * USED(m))) != MP_OKAY)
+ goto CLEANUP;
if((res = mp_div(&mu, m, &mu, NULL)) != MP_OKAY)
goto CLEANUP;
@@ -1700,7 +1705,8 @@ int mp_cmp_int(const mp_int *a, long z)
ARGCHK(a != NULL, MP_EQ);
- mp_init(&tmp); mp_set_int(&tmp, z);
+ assert(mp_init(&tmp) == MP_OKAY);
+ assert(mp_set_int(&tmp, z) == MP_OKAY);
out = mp_cmp(a, &tmp);
mp_clear(&tmp);
@@ -1937,8 +1943,8 @@ mp_err mp_xgcd(const mp_int *a, const mp_int *b, mp_int *g, mp_int *x, mp_int *y
MP_CHECKOK( s_mp_mul_2d(&gx,n) );
}
- mp_copy(&xc, &u);
- mp_copy(&yc, &v);
+ MP_CHECKOK(mp_copy(&xc, &u));
+ MP_CHECKOK(mp_copy(&yc, &v));
mp_set(&A, 1); mp_set(&D, 1);
/* Loop through binary GCD algorithm */
@@ -4271,7 +4277,7 @@ mp_err s_mp_div(mp_int *rem, /* i: dividend, o: remainder */
*/
for (i = 4; s_mp_cmp(&t, &part) > 0 && i > 0; --i) {
--q_msd;
- s_mp_sub(&t, div); /* t -= div */
+ MP_CHECKOK(s_mp_sub(&t, div)); /* t -= div */
}
if (i < 0) {
res = MP_RANGE;