"print" is GNU bc specific.
[oweals/openssl.git] / crypto / bn / bn_exp2.c
index eface739b34aad4fcb972653d8864d623035d566..4f4e9e329989d5b415bba73dd14eda0a245e7f83 100644 (file)
@@ -9,21 +9,14 @@
  * bits=1  75.4%  79.4%
  * bits=2  61.2%  62.4%
  * bits=3  61.3%  59.3%
- * The lack of speed improvment is also a function of the pre-calculation
+ * The lack of speed improvement is also a function of the pre-calculation
  * which could be removed.
  */
 #define EXP2_TABLE_BITS        2 /* 1  2  3  4  5  */
 #define EXP2_TABLE_SIZE        4 /* 2  4  8 16 32  */
 
-int BN_mod_exp2_mont(rr,a1,p1,a2,p2,m,ctx,in_mont)
-BIGNUM *rr;
-BIGNUM *a1;
-BIGNUM *p1;
-BIGNUM *a2;
-BIGNUM *p2;
-BIGNUM *m;
-BN_CTX *ctx;
-BN_MONT_CTX *in_mont;
+int BN_mod_exp2_mont(BIGNUM *rr, BIGNUM *a1, BIGNUM *p1, BIGNUM *a2,
+            BIGNUM *p2, BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)
        {
        int i,j,k,bits,bits1,bits2,ret=0,wstart,wend,window,xvalue,yvalue;
        int start=1,ts=0,x,y;
@@ -42,15 +35,19 @@ BN_MONT_CTX *in_mont;
                BNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);
                return(0);
                }
-       d= &(ctx->bn[ctx->tos++]);
-       r= &(ctx->bn[ctx->tos++]);
        bits1=BN_num_bits(p1);
        bits2=BN_num_bits(p2);
        if ((bits1 == 0) && (bits2 == 0))
                {
-               BN_one(r);
+               BN_one(rr);
                return(1);
                }
+
+       BN_CTX_start(ctx);
+       d = BN_CTX_get(ctx);
+       r = BN_CTX_get(ctx);
+       if (d == NULL || r == NULL) goto err;
+
        bits=(bits1 > bits2)?bits1:bits2;
 
        /* If this is not done, things will break in the montgomery
@@ -190,7 +187,7 @@ BN_MONT_CTX *in_mont;
        ret=1;
 err:
        if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);
-       ctx->tos-=2;
+       BN_CTX_end(ctx);
        for (i=0; i<ts; i++)
                {
                for (j=0; j<ts; j++)