#include <openssl/rand.h>
DSA *DSA_generate_parameters(int bits, unsigned char *seed_in, int seed_len,
- int *counter_ret, unsigned long *h_ret, void (*callback)(),
+ int *counter_ret, unsigned long *h_ret,
+ void (*callback)(int, int, void *),
void *cb_arg)
{
int ok=0;
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;
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);
{
for (;;) /* find q */
{
- int seed_is_random = 0;
+ int seed_is_random;
/* step 1 */
if (callback != NULL) callback(0,m++,cb_arg);
seed_is_random = 1;
}
else
- /* use random seed if 'seed_in' turns out to be bad */
- seed_len=0;
+ {
+ seed_is_random = 0;
+ seed_len=0; /* use random seed if 'seed_in' turns out to be bad*/
+ }
memcpy(buf,seed,SHA_DIGEST_LENGTH);
memcpy(buf2,seed,SHA_DIGEST_LENGTH);
/* precompute "SEED + 1" for step 7: */
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 */
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)
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);
}