Since asn1.h gets included recursively from many places, the easiest
[openssl.git] / crypto / bn / bn_add.c
index 12797225b878ef0b9902b140ec6f5d4689367629..6cba07e9f670ad83e4061357ea0a90ab135ad15c 100644 (file)
 #include "bn_lcl.h"
 
 /* r can == a or b */
-int BN_add(r, a, b)
-BIGNUM *r;
-BIGNUM *a;
-BIGNUM *b;
+int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
        {
-       BIGNUM *tmp;
+       const BIGNUM *tmp;
+       int a_neg = a->neg;
 
        bn_check_top(a);
        bn_check_top(b);
@@ -76,10 +74,10 @@ 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 */
@@ -97,25 +95,21 @@ 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);
        }
 
 /* unsigned add of b to a, r must be large enough */
-int BN_uadd(r,a,b)
-BIGNUM *r;
-BIGNUM *a;
-BIGNUM *b;
+int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
        {
        register int i;
        int max,min;
        BN_ULONG *ap,*bp,*rp,carry,t1;
-       BIGNUM *tmp;
+       const BIGNUM *tmp;
 
        bn_check_top(a);
        bn_check_top(b);
@@ -166,19 +160,14 @@ BIGNUM *b;
                        *(rp++)= *(ap++);
                }
        /* memcpy(rp,ap,sizeof(*ap)*(max-i));*/
+       r->neg = 0;
        return(1);
        }
 
 /* unsigned subtraction of b from a, a must be larger than b. */
-int BN_usub(r, a, b)
-BIGNUM *r;
-BIGNUM *a;
-BIGNUM *b;
+int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
        {
        int max,min;
-#if 0
-       int ret=1;
-#endif
        register BN_ULONG t1,t2,*ap,*bp,*rp;
        int i,carry;
 #if defined(IRIX_CC_BUG) && !defined(LINT)
@@ -263,18 +252,16 @@ BIGNUM *b;
 #endif
 
        r->top=max;
+       r->neg=0;
        bn_fix_top(r);
        return(1);
        }
 
-int BN_sub(r, a, b)
-BIGNUM *r;
-BIGNUM *a;
-BIGNUM *b;
+int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
        {
        int max;
        int add=0,neg=0;
-       BIGNUM *tmp;
+       const BIGNUM *tmp;
 
        bn_check_top(a);
        bn_check_top(b);