]> git.ipfire.org Git - thirdparty/openssl.git/blobdiff - crypto/bn/bn_prime.c
Seek out and destroy another evil cast.
[thirdparty/openssl.git] / crypto / bn / bn_prime.c
index 39b99ea6c3317aa64711cf4c1b58d3cf88d8fb88..e2cfef37259eaad2612b0b874ca56367d19f0bcd 100644 (file)
@@ -83,11 +83,13 @@ BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe, BIGNUM *add,
        BIGNUM t;
        int found=0;
        int i,j,c1=0;
-       BN_CTX *ctx;
+       BN_CTX *ctx,*ctx2=NULL;
        int checks = BN_prime_checks_for_size(bits);
 
        ctx=BN_CTX_new();
        if (ctx == NULL) goto err;
+       ctx2=BN_CTX_new();
+       if (ctx2 == NULL) goto err;
        if (ret == NULL)
                {
                if ((rnd=BN_new()) == NULL) goto err;
@@ -119,7 +121,7 @@ loop:
 
        if (!safe)
                {
-               i=BN_is_prime(rnd,checks,callback,ctx,cb_arg);
+               i=BN_is_prime_fasttest(rnd,checks,callback,ctx,ctx2,cb_arg,0);
                if (i == -1) goto err;
                if (i == 0) goto loop;
                }
@@ -133,11 +135,11 @@ loop:
 
                for (i=0; i<checks; i++)
                        {
-                       j=BN_is_prime(rnd,1,callback,ctx,cb_arg);
+                       j=BN_is_prime_fasttest(rnd,1,callback,ctx,ctx2,cb_arg,0);
                        if (j == -1) goto err;
                        if (j == 0) goto loop;
 
-                       j=BN_is_prime(&t,1,callback,ctx,cb_arg);
+                       j=BN_is_prime_fasttest(&t,1,callback,ctx,ctx2,cb_arg,0);
                        if (j == -1) goto err;
                        if (j == 0) goto loop;
 
@@ -151,6 +153,7 @@ err:
        if (!found && (ret == NULL) && (rnd != NULL)) BN_free(rnd);
        BN_free(&t);
        if (ctx != NULL) BN_CTX_free(ctx);
+       if (ctx2 != NULL) BN_CTX_free(ctx2);
        return(found ? rnd : NULL);
        }