summaryrefslogtreecommitdiffstats
path: root/crypto/bn/bn_add.c
diff options
context:
space:
mode:
authorBodo Möller <bodo@openssl.org>2000-12-07 22:06:09 +0000
committerBodo Möller <bodo@openssl.org>2000-12-07 22:06:09 +0000
commit8dea52fa4270a71535b2677953662499946f02e3 (patch)
tree6c419fda8d18eac4d092e595ed5a087d6a89f1d0 /crypto/bn/bn_add.c
parentf7356b677b35ad58ea2db85cfd22af83b0267978 (diff)
Fix some things that look like bugs.
One problem that looked like a problem in bn_recp.c at first turned out to be a BN_mul bug. An example is given in bn_recp.c; finding the bug responsible for this is left as an exercise.
Diffstat (limited to 'crypto/bn/bn_add.c')
-rw-r--r--crypto/bn/bn_add.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/crypto/bn/bn_add.c b/crypto/bn/bn_add.c
index 5d24691233..6cba07e9f6 100644
--- a/crypto/bn/bn_add.c
+++ b/crypto/bn/bn_add.c
@@ -64,6 +64,7 @@
int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
{
const BIGNUM *tmp;
+ int a_neg = a->neg;
bn_check_top(a);
bn_check_top(b);
@@ -73,10 +74,10 @@ int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
* -a + b b-a
* -a + -b -(a+b)
*/
- if (a->neg ^ b->neg)
+ if (a_neg ^ b->neg)
{
/* only one is negative */
- if (a->neg)
+ if (a_neg)
{ tmp=a; a=b; b=tmp; }
/* we are now a - b */
@@ -94,12 +95,11 @@ int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
return(1);
}
- if (a->neg) /* both are neg */
+ if (!BN_uadd(r,a,b)) return(0);
+ if (a_neg) /* both are neg */
r->neg=1;
else
r->neg=0;
-
- if (!BN_uadd(r,a,b)) return(0);
return(1);
}
@@ -160,6 +160,7 @@ int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
*(rp++)= *(ap++);
}
/* memcpy(rp,ap,sizeof(*ap)*(max-i));*/
+ r->neg = 0;
return(1);
}
@@ -251,6 +252,7 @@ int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
#endif
r->top=max;
+ r->neg=0;
bn_fix_top(r);
return(1);
}