Remaining parts of PR:620
authorDr. Stephen Henson <steve@openssl.org>
Sun, 5 Dec 2004 01:46:03 +0000 (01:46 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Sun, 5 Dec 2004 01:46:03 +0000 (01:46 +0000)
crypto/dh/dh_gen.c
crypto/dsa/dsa_gen.c

index a49b6f9adb838cc04283c173df07dd418ba39d36..23777f5a16c433924ea025671d642cee8001033a 100644 (file)
@@ -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:
index e307beb3da75a859d1d7a8d2d2c85cccc73e3ada..e40afeea516aaeddeba996c4dff3d6a32c4b6f88 100644 (file)
@@ -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;