Remaing bits of PR:620 relevant to 0.9.8.
authorDr. Stephen Henson <steve@openssl.org>
Sun, 5 Dec 2004 01:50:56 +0000 (01:50 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Sun, 5 Dec 2004 01:50:56 +0000 (01:50 +0000)
crypto/dsa/dsa_gen.c

index 878dc67ad2182b8acf03a9e474f852bbdb418acb..74da6becd558a54a5317cc37e7d55da78e19a1b2 100644 (file)
@@ -139,7 +139,8 @@ static int dsa_builtin_paramgen(DSA *ret, int bits,
        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 (;;)
                {
@@ -209,7 +210,7 @@ static int dsa_builtin_paramgen(DSA *ret, int bits,
                                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++)
                                {
@@ -225,20 +226,20 @@ static int dsa_builtin_paramgen(DSA *ret, 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)
@@ -266,18 +267,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++;
                }
 
@@ -294,6 +295,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;