summaryrefslogtreecommitdiffstats
path: root/crypto/bn
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2002-05-30 16:47:45 +0000
committerRichard Levitte <levitte@openssl.org>2002-05-30 16:47:45 +0000
commit9cdf87f19431b32a50b12e468cf2a9557cfc3568 (patch)
tree5aa5e1f88093d6b8013b9e2f1af0b18201b9bef6 /crypto/bn
parenta81e9d3dc45f29c1a5fde7fa641a43f796fe92d4 (diff)
Check the return values where memory allocation failures may happen.
PR: 49
Diffstat (limited to 'crypto/bn')
-rw-r--r--crypto/bn/bn_div.c8
-rw-r--r--crypto/bn/bn_mont.c6
-rw-r--r--crypto/bn/bn_mul.c14
3 files changed, 14 insertions, 14 deletions
diff --git a/crypto/bn/bn_div.c b/crypto/bn/bn_div.c
index ac1a09615a..f9a095e3b3 100644
--- a/crypto/bn/bn_div.c
+++ b/crypto/bn/bn_div.c
@@ -200,10 +200,10 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
/* First we normalise the numbers */
norm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);
- BN_lshift(sdiv,divisor,norm_shift);
+ if (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;
sdiv->neg=0;
norm_shift+=BN_BITS2;
- BN_lshift(snum,num,norm_shift);
+ if (!(BN_lshift(snum,num,norm_shift))) goto err;
snum->neg=0;
div_n=sdiv->top;
num_n=snum->top;
@@ -327,7 +327,7 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
tmp->top=j;
j=wnum.top;
- BN_sub(&wnum,&wnum,tmp);
+ if (!BN_sub(&wnum,&wnum,tmp)) goto err;
snum->top=snum->top+wnum.top-j;
@@ -335,7 +335,7 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
{
q--;
j=wnum.top;
- BN_add(&wnum,&wnum,sdiv);
+ if (!BN_add(&wnum,&wnum,sdiv)) goto err;
snum->top+=wnum.top-j;
}
*(resp--)=q;
diff --git a/crypto/bn/bn_mont.c b/crypto/bn/bn_mont.c
index 82942a4759..c9ebdbaabe 100644
--- a/crypto/bn/bn_mont.c
+++ b/crypto/bn/bn_mont.c
@@ -221,7 +221,7 @@ int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,
if (!BN_mul(t1,t2,&mont->N,ctx)) goto err;
if (!BN_add(t2,a,t1)) goto err;
- BN_rshift(ret,t2,mont->ri);
+ if (!BN_rshift(ret,t2,mont->ri)) goto err;
#endif /* MONT_WORD */
if (BN_ucmp(ret, &(mont->N)) >= 0)
@@ -282,8 +282,8 @@ int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
BN_ULONG buf[2];
mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;
- BN_zero(R);
- BN_set_bit(R,BN_BITS2); /* R */
+ if (!(BN_zero(R))) goto err;
+ if (!(BN_set_bit(R,BN_BITS2))) goto err; /* R */
buf[0]=mod->d[0]; /* tmod = N mod word size */
buf[1]=0;
diff --git a/crypto/bn/bn_mul.c b/crypto/bn/bn_mul.c
index 7bffc9c16a..fd598b8b3d 100644
--- a/crypto/bn/bn_mul.c
+++ b/crypto/bn/bn_mul.c
@@ -964,7 +964,7 @@ int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
if ((al == 0) || (bl == 0))
{
- BN_zero(r);
+ if (!BN_zero(r)) goto err;
return(1);
}
top=al+bl;
@@ -1044,7 +1044,7 @@ int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
if (i == 1 && !BN_get_flags(b,BN_FLG_STATIC_DATA))
{
BIGNUM *tmp_bn = (BIGNUM *)b;
- bn_wexpand(tmp_bn,al);
+ if (bn_wexpand(tmp_bn,al) == NULL) goto err;
tmp_bn->d[bl]=0;
bl++;
i--;
@@ -1052,7 +1052,7 @@ int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
else if (i == -1 && !BN_get_flags(a,BN_FLG_STATIC_DATA))
{
BIGNUM *tmp_bn = (BIGNUM *)a;
- bn_wexpand(tmp_bn,bl);
+ if (bn_wexpand(tmp_bn,bl) == NULL) goto err;
tmp_bn->d[al]=0;
al++;
i++;
@@ -1067,14 +1067,14 @@ int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
t = BN_CTX_get(ctx);
if (al == j) /* exact multiple */
{
- bn_wexpand(t,k*2);
- bn_wexpand(rr,k*2);
+ if (bn_wexpand(t,k*2) == NULL) goto err;
+ if (bn_wexpand(rr,k*2) == NULL) goto err;
bn_mul_recursive(rr->d,a->d,b->d,al,t->d);
}
else
{
- bn_wexpand(t,k*4);
- bn_wexpand(rr,k*4);
+ if (bn_wexpand(t,k*4) == NULL) goto err;
+ if (bn_wexpand(rr,k*4) == NULL) goto err;
bn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);
}
rr->top=top;