From: Dr. Stephen Henson Date: Sun, 5 Dec 2004 01:46:03 +0000 (+0000) Subject: Remaining parts of PR:620 X-Git-Tag: BEN_FIPS_TEST_6~19 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ec46cd8bb8fec06e0b1b1e41b632d1c1a4886547;p=openssl Remaining parts of PR:620 --- diff --git a/crypto/dh/dh_gen.c b/crypto/dh/dh_gen.c index a49b6f9adb..23777f5a16 100644 --- a/crypto/dh/dh_gen.c +++ b/crypto/dh/dh_gen.c @@ -149,6 +149,7 @@ DH *DH_generate_parameters(int prime_len, int generator, if (callback != NULL) callback(3,0,cb_arg); ret->p=p; ret->g=BN_new(); + if (ret->g == NULL) goto err; if (!BN_set_word(ret->g,g)) goto err; ok=1; err: diff --git a/crypto/dsa/dsa_gen.c b/crypto/dsa/dsa_gen.c index e307beb3da..e40afeea51 100644 --- a/crypto/dsa/dsa_gen.c +++ b/crypto/dsa/dsa_gen.c @@ -128,8 +128,9 @@ DSA *DSA_generate_parameters(int bits, c = BN_CTX_get(ctx2); p = BN_CTX_get(ctx2); test = BN_CTX_get(ctx2); + if (test == NULL) goto err; - BN_lshift(test,BN_value_one(),bits-1); + if (!BN_lshift(test,BN_value_one(),bits-1)) goto err; for (;;) { @@ -197,7 +198,7 @@ DSA *DSA_generate_parameters(int bits, callback(0,counter,cb_arg); /* step 7 */ - BN_zero(W); + if (!BN_zero(W)) goto err; /* now 'buf' contains "SEED + offset - 1" */ for (k=0; k<=n; k++) { @@ -213,20 +214,20 @@ DSA *DSA_generate_parameters(int bits, /* 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) @@ -252,18 +253,18 @@ end: /* 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++; } @@ -280,6 +281,11 @@ err: 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;