Enhance consistency by using BIO_flush() instead of fflush().
[openssl.git] / crypto / bn / bn_mul.c
index 38c47f3d1f09383d2e5616768afede1b9c849a6b..36e9c4d9ffeae93f7bf0adedff317504eca4913b 100644 (file)
@@ -66,7 +66,7 @@
  * n2 must be a power of 2.
  * We multiply and return the result.
  * t must be 2*n2 words in size
- * We calulate
+ * We calculate
  * a[0]*b[0]
  * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0])
  * a[1]*b[1]
@@ -585,10 +585,13 @@ printf("BN_mul %d * %d\n",a->top,b->top);
                }
        top=al+bl;
 
+       BN_CTX_start(ctx);
        if ((r == a) || (r == b))
-               rr= &(ctx->bn[ctx->tos+1]);
+               {
+               if ((rr = BN_CTX_get(ctx)) == NULL) goto err;
+               }
        else
-               rr=r;
+               rr = r;
 
 #if defined(BN_MUL_COMBA) || defined(BN_RECURSION)
        if (al == bl)
@@ -596,14 +599,14 @@ printf("BN_mul %d * %d\n",a->top,b->top);
 #  ifdef BN_MUL_COMBA
 /*             if (al == 4)
                        {
-                       if (bn_wexpand(rr,8) == NULL) return(0);
+                       if (bn_wexpand(rr,8) == NULL) goto err;
                        rr->top=8;
                        bn_mul_comba4(rr->d,a->d,b->d);
                        goto end;
                        }
                else */ if (al == 8)
                        {
-                       if (bn_wexpand(rr,16) == NULL) return(0);
+                       if (bn_wexpand(rr,16) == NULL) goto err;
                        rr->top=16;
                        bn_mul_comba8(rr->d,a->d,b->d);
                        goto end;
@@ -614,20 +617,20 @@ printf("BN_mul %d * %d\n",a->top,b->top);
                if (al < BN_MULL_SIZE_NORMAL)
 #endif
                        {
-                       if (bn_wexpand(rr,top) == NULL) return(0);
+                       if (bn_wexpand(rr,top) == NULL) goto err;
                        rr->top=top;
                        bn_mul_normal(rr->d,a->d,al,b->d,bl);
                        goto end;
                        }
 #  ifdef BN_RECURSION
-               goto symetric;
+               goto symmetric;
 #  endif
                }
 #endif
 #ifdef BN_RECURSION
        else if ((al < BN_MULL_SIZE_NORMAL) || (bl < BN_MULL_SIZE_NORMAL))
                {
-               if (bn_wexpand(rr,top) == NULL) return(0);
+               if (bn_wexpand(rr,top) == NULL) goto err;
                rr->top=top;
                bn_mul_normal(rr->d,a->d,al,b->d,bl);
                goto end;
@@ -640,33 +643,33 @@ printf("BN_mul %d * %d\n",a->top,b->top);
                        bn_wexpand(b,al);
                        b->d[bl]=0;
                        bl++;
-                       goto symetric;
+                       goto symmetric;
                        }
                else if ((i ==  -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA))
                        {
                        bn_wexpand(a,bl);
                        a->d[al]=0;
                        al++;
-                       goto symetric;
+                       goto symmetric;
                        }
                }
 #endif
 
-       /* asymetric and >= 4 */ 
-       if (bn_wexpand(rr,top) == NULL) return(0);
+       /* asymmetric and >= 4 */ 
+       if (bn_wexpand(rr,top) == NULL) goto err;
        rr->top=top;
        bn_mul_normal(rr->d,a->d,al,b->d,bl);
 
 #ifdef BN_RECURSION
        if (0)
                {
-symetric:
-               /* symetric and > 4 */
+symmetric:
+               /* symmetric and > 4 */
                /* 16 or larger */
                j=BN_num_bits_word((BN_ULONG)al);
                j=1<<(j-1);
                k=j+j;
-               t= &(ctx->bn[ctx->tos]);
+               t = BN_CTX_get(ctx);
                if (al == j) /* exact multiple */
                        {
                        bn_wexpand(t,k*2);
@@ -693,7 +696,11 @@ end:
 #endif
        bn_fix_top(rr);
        if (r != rr) BN_copy(r,rr);
+       BN_CTX_end(ctx);
        return(1);
+err:
+       BN_CTX_end(ctx);
+       return(0);
        }
 
 void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)