X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=crypto%2Fdsa%2Fdsa_gen.c;h=e911e5ae738ccf1ff6832cd814612a4e16b55478;hp=710a4faa66bd996d0d559d48246607b5337644dd;hb=a6576c56ddb2c09f6d78f6d29917eb1442c2c5f2;hpb=7865b871c0307ad2d71a8f3dc066b7cfd0d99c4a diff --git a/crypto/dsa/dsa_gen.c b/crypto/dsa/dsa_gen.c index 710a4faa66..e911e5ae73 100644 --- a/crypto/dsa/dsa_gen.c +++ b/crypto/dsa/dsa_gen.c @@ -79,8 +79,10 @@ #include #include -DSA *DSA_generate_parameters(int bits, unsigned char *seed_in, int seed_len, - int *counter_ret, unsigned long *h_ret, void (*callback)(), +DSA *DSA_generate_parameters(int bits, + unsigned char *seed_in, int seed_len, + int *counter_ret, unsigned long *h_ret, + void (*callback)(int, int, void *), void *cb_arg) { int ok=0; @@ -93,7 +95,7 @@ DSA *DSA_generate_parameters(int bits, unsigned char *seed_in, int seed_len, int k,n=0,i,b,m=0; int counter=0; int r=0; - BN_CTX *ctx=NULL,*ctx2=NULL,*ctx3=NULL,*ctx4=NULL; + BN_CTX *ctx=NULL,*ctx2=NULL,*ctx3=NULL; unsigned int h=2; DSA *ret=NULL; @@ -111,19 +113,19 @@ DSA *DSA_generate_parameters(int bits, unsigned char *seed_in, int seed_len, if ((ctx=BN_CTX_new()) == NULL) goto err; if ((ctx2=BN_CTX_new()) == NULL) goto err; if ((ctx3=BN_CTX_new()) == NULL) goto err; - if ((ctx4=BN_CTX_new()) == NULL) goto err; if ((ret=DSA_new()) == NULL) goto err; if ((mont=BN_MONT_CTX_new()) == NULL) goto err; - r0= &(ctx2->bn[0]); - g= &(ctx2->bn[1]); - W= &(ctx2->bn[2]); - q= &(ctx2->bn[3]); - X= &(ctx2->bn[4]); - c= &(ctx2->bn[5]); - p= &(ctx2->bn[6]); - test= &(ctx2->bn[7]); + BN_CTX_start(ctx2); + r0 = BN_CTX_get(ctx2); + g = BN_CTX_get(ctx2); + W = BN_CTX_get(ctx2); + q = BN_CTX_get(ctx2); + X = BN_CTX_get(ctx2); + c = BN_CTX_get(ctx2); + p = BN_CTX_get(ctx2); + test = BN_CTX_get(ctx2); BN_lshift(test,BN_value_one(),bits-1); @@ -167,11 +169,11 @@ DSA *DSA_generate_parameters(int bits, unsigned char *seed_in, int seed_len, if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,q)) goto err; /* step 4 */ - r = BN_is_prime_fasttest(q, DSS_prime_checks, callback, ctx3, ctx4, cb_arg, seed_is_random); + r = BN_is_prime_fasttest(q, DSS_prime_checks, callback, ctx3, cb_arg, seed_is_random); if (r > 0) - break; + break; if (r != 0) - goto err; + goto err; /* do a callback call */ /* step 5 */ @@ -228,7 +230,7 @@ DSA *DSA_generate_parameters(int bits, unsigned char *seed_in, int seed_len, if (BN_cmp(p,test) >= 0) { /* step 11 */ - r = BN_is_prime_fasttest(p, DSS_prime_checks, callback, ctx3, ctx4, cb_arg, 1); + r = BN_is_prime_fasttest(p, DSS_prime_checks, callback, ctx3, cb_arg, 1); if (r > 0) goto end; /* found it */ if (r != 0) @@ -281,9 +283,12 @@ err: if (h_ret != NULL) *h_ret=h; } if (ctx != NULL) BN_CTX_free(ctx); - if (ctx2 != NULL) BN_CTX_free(ctx2); + if (ctx2 != NULL) + { + BN_CTX_end(ctx2); + BN_CTX_free(ctx2); + } if (ctx3 != NULL) BN_CTX_free(ctx3); - if (ctx4 != NULL) BN_CTX_free(ctx4); if (mont != NULL) BN_MONT_CTX_free(mont); return(ok?ret:NULL); }