remove unnecessary calls to EC_POINT_copy()
[openssl.git] / crypto / rsa / rsa_gen.c
index 89e2f2e2e2d527c594695d425dba3c0f7eebec47..00c25adbc588485e022a9a0b1608ca0b6ce16ba2 100644 (file)
@@ -74,11 +74,12 @@ RSA *RSA_generate_key(int bits, unsigned long e_value,
        if (ctx == NULL) goto err;
        ctx2=BN_CTX_new();
        if (ctx2 == NULL) goto err;
-       r0= &(ctx->bn[0]);
-       r1= &(ctx->bn[1]);
-       r2= &(ctx->bn[2]);
-       r3= &(ctx->bn[3]);
-       ctx->tos+=4;
+       BN_CTX_start(ctx);
+       r0 = BN_CTX_get(ctx);
+       r1 = BN_CTX_get(ctx);
+       r2 = BN_CTX_get(ctx);
+       r3 = BN_CTX_get(ctx);
+       if (r3 == NULL) goto err;
 
        bitsp=(bits+1)/2;
        bitsq=bits-bitsp;
@@ -94,7 +95,7 @@ RSA *RSA_generate_key(int bits, unsigned long e_value,
         * unsigned long can be larger */
        for (i=0; i<sizeof(unsigned long)*8; i++)
                {
-               if (e_value & (1<<i))
+               if (e_value & (1UL<<i))
                        BN_set_bit(rsa->e,i);
                }
 #else
@@ -157,7 +158,7 @@ RSA *RSA_generate_key(int bits, unsigned long e_value,
                goto err;
                }
 */
-       rsa->d=(BIGNUM *)BN_mod_inverse(NULL,rsa->e,r0,ctx2);   /* d */
+       rsa->d=BN_mod_inverse(NULL,rsa->e,r0,ctx2);     /* d */
        if (rsa->d == NULL) goto err;
 
        /* calculate d mod (p-1) */
@@ -181,6 +182,7 @@ err:
                RSAerr(RSA_F_RSA_GENERATE_KEY,ERR_LIB_BN);
                ok=0;
                }
+       BN_CTX_end(ctx);
        BN_CTX_free(ctx);
        BN_CTX_free(ctx2);