p = BN_CTX_get(ctx);
test = BN_CTX_get(ctx);
- BN_lshift(test,BN_value_one(),bits-1);
+ if (!BN_lshift(test,BN_value_one(),bits-1))
+ goto err;
for (;;)
{
goto err;
/* step 7 */
- BN_zero(W);
+ if (!BN_zero(W)) goto err;
/* now 'buf' contains "SEED + offset - 1" */
for (k=0; k<=n; k++)
{
/* step 8 */
if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,r0))
goto err;
- BN_lshift(r0,r0,160*k);
- BN_add(W,W,r0);
+ if (!BN_lshift(r0,r0,160*k)) goto err;
+ if (!BN_add(W,W,r0)) goto err;
}
/* more of step 8 */
- BN_mask_bits(W,bits-1);
- BN_copy(X,W); /* this should be ok */
- BN_add(X,X,test); /* this should be ok */
+ if (!BN_mask_bits(W,bits-1)) goto err;
+ if (!BN_copy(X,W)) goto err;
+ if (!BN_add(X,X,test)) goto err;
/* step 9 */
- BN_lshift1(r0,q);
- BN_mod(c,X,r0,ctx);
- BN_sub(r0,c,BN_value_one());
- BN_sub(p,X,r0);
+ if (!BN_lshift1(r0,q)) goto err;
+ if (!BN_mod(c,X,r0,ctx)) goto err;
+ if (!BN_sub(r0,c,BN_value_one())) goto err;
+ if (!BN_sub(p,X,r0)) goto err;
/* step 10 */
if (BN_cmp(p,test) >= 0)
/* We now need to generate g */
/* Set r0=(p-1)/q */
- BN_sub(test,p,BN_value_one());
- BN_div(r0,NULL,test,q,ctx);
+ if (!BN_sub(test,p,BN_value_one())) goto err;
+ if (!BN_div(r0,NULL,test,q,ctx)) goto err;
- BN_set_word(test,h);
- BN_MONT_CTX_set(mont,p,ctx);
+ if (!BN_set_word(test,h)) goto err;
+ if (!BN_MONT_CTX_set(mont,p,ctx)) goto err;
for (;;)
{
/* g=test^r0%p */
- BN_mod_exp_mont(g,test,r0,p,ctx,mont);
+ if (!BN_mod_exp_mont(g,test,r0,p,ctx,mont)) goto err;
if (!BN_is_one(g)) break;
- BN_add(test,test,BN_value_one());
+ if (!BN_add(test,test,BN_value_one())) goto err;
h++;
}
ret->p=BN_dup(p);
ret->q=BN_dup(q);
ret->g=BN_dup(g);
+ if (ret->p == NULL || ret->q == NULL || ret->g == NULL)
+ {
+ ok=0;
+ goto err;
+ }
if ((m > 1) && (seed_in != NULL)) memcpy(seed_in,seed,20);
if (counter_ret != NULL) *counter_ret=counter;
if (h_ret != NULL) *h_ret=h;