bsaes-armv7.pl: remove partial register operations in CTR subroutine.
[openssl.git] / crypto / bn / bn_mul.c
index 6938c88cb229b5f9b5670f1e3e7d152ee132de92..12e5be80eb2b442db28f6b1955c0d583bb91bb83 100644 (file)
@@ -78,8 +78,8 @@
    assembler counterparts for the systems that use assembler files.  */
 
 BN_ULONG bn_sub_part_words(BN_ULONG *r,
-                          const BN_ULONG *a, const BN_ULONG *b,
-                          size_t cl, ssize_t dl)
+       const BN_ULONG *a, const BN_ULONG *b,
+       int cl, int dl)
        {
        BN_ULONG c, t;
 
@@ -126,7 +126,7 @@ BN_ULONG bn_sub_part_words(BN_ULONG *r,
                }
        else
                {
-               ssize_t save_dl = dl;
+               int save_dl = dl;
 #ifdef BN_COUNT
                fprintf(stderr, "  bn_sub_part_words %d + %d (dl > 0, c = %d)\n", cl, dl, c);
 #endif
@@ -205,8 +205,8 @@ BN_ULONG bn_sub_part_words(BN_ULONG *r,
 #endif
 
 BN_ULONG bn_add_part_words(BN_ULONG *r,
-                          const BN_ULONG *a, const BN_ULONG *b,
-                          size_t cl, ssize_t dl)
+       const BN_ULONG *a, const BN_ULONG *b,
+       int cl, int dl)
        {
        BN_ULONG c, l, t;
 
@@ -222,7 +222,7 @@ BN_ULONG bn_add_part_words(BN_ULONG *r,
 
        if (dl < 0)
                {
-               ssize_t save_dl = dl;
+               int save_dl = dl;
 #ifdef BN_COUNT
                fprintf(stderr, "  bn_add_part_words %d + %d (dl < 0, c = %d)\n", cl, dl, c);
 #endif
@@ -390,8 +390,8 @@ BN_ULONG bn_add_part_words(BN_ULONG *r,
  * a[1]*b[1]
  */
 /* dnX may not be positive, but n2/2+dnX has to be */
-void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, size_t n2,
-                     int dna, int dnb, BN_ULONG *t)
+void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
+       int dna, int dnb, BN_ULONG *t)
        {
        int n=n2/2,c1,c2;
        int tna=n+dna, tnb=n+dnb;
@@ -505,16 +505,16 @@ void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, size_t n2,
         * r[32] holds (b[1]*b[1])
         */
 
-       c1=bn_add_words(t,r,&(r[n2]),n2);
+       c1=(int)(bn_add_words(t,r,&(r[n2]),n2));
 
        if (neg) /* if t[32] is negative */
                {
-               c1-=bn_sub_words(&(t[n2]),t,&(t[n2]),n2);
+               c1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));
                }
        else
                {
                /* Might have a carry */
-               c1+=bn_add_words(&(t[n2]),&(t[n2]),t,n2);
+               c1+=(int)(bn_add_words(&(t[n2]),&(t[n2]),t,n2));
                }
 
        /* t[32] holds (a[0]-a[1])*(b[1]-b[0])+(a[0]*b[0])+(a[1]*b[1])
@@ -522,7 +522,7 @@ void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, size_t n2,
         * r[32] holds (b[1]*b[1])
         * c1 holds the carry bits
         */
-       c1+=bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2);
+       c1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2));
        if (c1)
                {
                p= &(r[n+n2]);
@@ -551,7 +551,7 @@ void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,
             int tna, int tnb, BN_ULONG *t)
        {
        int i,j,n2=n*2;
-       int c1,c2,neg,zero;
+       int c1,c2,neg;
        BN_ULONG ln,lo,*p;
 
 # ifdef BN_COUNT
@@ -567,7 +567,7 @@ void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,
        /* r=(a[0]-a[1])*(b[1]-b[0]) */
        c1=bn_cmp_part_words(a,&(a[n]),tna,n-tna);
        c2=bn_cmp_part_words(&(b[n]),b,tnb,tnb-n);
-       zero=neg=0;
+       neg=0;
        switch (c1*3+c2)
                {
        case -4:
@@ -575,7 +575,6 @@ void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,
                bn_sub_part_words(&(t[n]),b,      &(b[n]),tnb,n-tnb); /* - */
                break;
        case -3:
-               zero=1;
                /* break; */
        case -2:
                bn_sub_part_words(t,      &(a[n]),a,      tna,tna-n); /* - */
@@ -585,7 +584,6 @@ void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,
        case -1:
        case 0:
        case 1:
-               zero=1;
                /* break; */
        case 2:
                bn_sub_part_words(t,      a,      &(a[n]),tna,n-tna); /* + */
@@ -593,7 +591,6 @@ void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,
                neg=1;
                break;
        case 3:
-               zero=1;
                /* break; */
        case 4:
                bn_sub_part_words(t,      a,      &(a[n]),tna,n-tna);
@@ -1012,7 +1009,6 @@ int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
                {
                if (i >= -1 && i <= 1)
                        {
-                       int sav_j =0;
                        /* Find out the power of two lower or equal
                           to the longest of the two numbers */
                        if (i >= 0)
@@ -1023,22 +1019,23 @@ int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
                                {
                                j = BN_num_bits_word((BN_ULONG)bl);
                                }
-                       sav_j = j;
                        j = 1<<(j-1);
                        assert(j <= al || j <= bl);
                        k = j+j;
                        t = BN_CTX_get(ctx);
+                       if (t == NULL)
+                               goto err;
                        if (al > j || bl > j)
                                {
-                               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,
                                        j,al-j,bl-j,t->d);
                                }
                        else    /* al <= j || bl <= j */
                                {
-                               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,
                                        j,al-j,bl-j,t->d);
                                }