Nils Larsch submitted;
authorGeoff Thorpe <geoff@openssl.org>
Sun, 8 Dec 2002 16:45:26 +0000 (16:45 +0000)
committerGeoff Thorpe <geoff@openssl.org>
Sun, 8 Dec 2002 16:45:26 +0000 (16:45 +0000)
  - a patch to fix a memory leak in rsa_gen.c
  - a note about compiler warnings with unions
  - a note about improving structure element names

This applies his patch and implements a solution to the notes.

apps/dsaparam.c
crypto/bn/bn.h
crypto/bn/bn_depr.c
crypto/bn/bn_prime.c
crypto/dh/dh_depr.c
crypto/dsa/dsa_depr.c
crypto/rsa/rsa_depr.c
crypto/rsa/rsa_gen.c

index 63e2cab45f545f055514cc11aab901180816d0c8..7a3110136cc62b67ddf7350eab0210f548bf5011 100644 (file)
@@ -281,10 +281,7 @@ bad:
        if (numbits > 0)
                {
                BN_GENCB cb;
-               cb.ver = 2;
-               cb.cb_2 = dsa_cb;
-               cb.arg = bio_err;
-
+               BN_GENCB_set(&cb, dsa_cb, bio_err);
                assert(need_rand);
                dsa = DSA_new();
                if(!dsa)
index c1b5b41935852ca98bf650c2a5c48acab364ca47..58263baf9a56f0d0879dab6082f1080fa5138c09 100644 (file)
@@ -299,10 +299,22 @@ struct bn_gencb_st
                void (*cb_1)(int, int, void *);
                /* if(ver==2) - new callback style */
                int (*cb_2)(int, int, BN_GENCB *);
-               };
+               } cb;
        };
 /* Wrapper function to make using BN_GENCB easier,  */
 int BN_GENCB_call(BN_GENCB *cb, int a, int b);
+/* Macro to populate a BN_GENCB structure with an "old"-style callback */
+#define BN_GENCB_set_old(gencb, callback, cb_arg) { \
+               BN_GENCB *tmp_gencb = (gencb); \
+               tmp_gencb->ver = 1; \
+               tmp_gencb->arg = (cb_arg); \
+               tmp_gencb->cb.cb_1 = (callback); }
+/* Macro to populate a BN_GENCB structure with a "new"-style callback */
+#define BN_GENCB_set(gencb, callback, cb_arg) { \
+               BN_GENCB *tmp_gencb = (gencb); \
+               tmp_gencb->ver = 2; \
+               tmp_gencb->arg = (cb_arg); \
+               tmp_gencb->cb.cb_2 = (callback); }
 
 #define BN_prime_checks 0 /* default: select number of iterations
                             based on the size of the number */
index 76c349833c7634b5fd1e2d0bd7520284d9cb854a..35e912728815717a3eab7ddae2d48238dbfa6675 100644 (file)
@@ -70,9 +70,7 @@ BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe,
        BIGNUM *rnd=NULL;
        int found = 0;
 
-       cb.ver = 1;
-       cb.arg = cb_arg;
-       cb.cb_1 = callback;
+       BN_GENCB_set_old(&cb, callback, cb_arg);
 
        if (ret == NULL)
                {
@@ -94,9 +92,7 @@ int BN_is_prime(const BIGNUM *a, int checks, void (*callback)(int,int,void *),
        BN_CTX *ctx_passed, void *cb_arg)
        {
        BN_GENCB cb;
-       cb.ver = 1;
-       cb.arg = cb_arg;
-       cb.cb_1 = callback;
+       BN_GENCB_set_old(&cb, callback, cb_arg);
        return BN_is_prime_ex(a, checks, ctx_passed, &cb);
        }
 
@@ -106,9 +102,7 @@ int BN_is_prime_fasttest(const BIGNUM *a, int checks,
                int do_trial_division)
        {
        BN_GENCB cb;
-       cb.ver = 1;
-       cb.arg = cb_arg;
-       cb.cb_1 = callback;
+       BN_GENCB_set_old(&cb, callback, cb_arg);
        return BN_is_prime_fasttest_ex(a, checks, ctx_passed,
                                do_trial_division, &cb);
        }
index a9ec01d9160b90739028d358908e21135f2d2e56..43eb9e6dfd0bf5eba8220db8217e04043c403f2d 100644 (file)
@@ -142,11 +142,11 @@ int BN_GENCB_call(BN_GENCB *cb, int a, int b)
                {
        case 1:
                /* Deprecated-style callbacks */
-               cb->cb_1(a, b, cb->arg);
+               cb->cb.cb_1(a, b, cb->arg);
                return 1;
        case 2:
                /* New-style callbacks */
-               return cb->cb_2(a, b, cb);
+               return cb->cb.cb_2(a, b, cb);
        default:
                break;
                }
index 8a909b1959bab8aaf54981247fc8d369b0c1a931..3eb319e2a8523a220e27373c55edfab3aae4ae28 100644 (file)
@@ -70,9 +70,7 @@ DH *DH_generate_parameters(int prime_len, int generator,
        if((ret=DH_new()) == NULL)
                return NULL;
 
-       cb.ver = 1;
-       cb.arg = cb_arg;
-       cb.cb_1 = callback;
+       BN_GENCB_set_old(&cb, callback, cb_arg);
 
        if(DH_generate_parameters_ex(ret, prime_len, generator, &cb))
                return ret;
index c16315389b39f01c1fe3298cdb2416bbc525171f..cb80457211e4177629a4a9e56a89be19eed2428f 100644 (file)
@@ -91,9 +91,7 @@ DSA *DSA_generate_parameters(int bits,
 
        if ((ret=DSA_new()) == NULL) return NULL;
 
-       cb.ver = 1;
-       cb.arg = cb_arg;
-       cb.cb_1 = callback;
+       BN_GENCB_set_old(&cb, callback, cb_arg);
 
        if(DSA_generate_parameters_ex(ret, bits, seed_in, seed_len,
                                counter_ret, h_ret, &cb))
index 25fa9543936fba84a8db8bdb75ab04386582e6d1..3773d037c658becab981fa35182b4cf34e39c525 100644 (file)
@@ -71,9 +71,7 @@ RSA *RSA_generate_key(int bits, unsigned long e_value,
        if((rsa=RSA_new()) == NULL)
                return 0;
 
-       cb.ver = 1;
-       cb.arg = cb_arg;
-       cb.cb_1 = callback;
+       BN_GENCB_set_old(&cb, callback, cb_arg);
 
        if(RSA_generate_key_ex(rsa, bits, e_value, &cb))
                return rsa;
index a45b9aab5c3c169225119d63e564fbec2d0d0b80..e3ae03e6914c8b7b614aaa0b7936ef4fc30e4551 100644 (file)
@@ -166,22 +166,16 @@ int RSA_generate_key_ex(RSA *rsa, int bits, unsigned long e_value, BN_GENCB *cb)
                goto err;
                }
 */
-       rsa->d=BN_mod_inverse(NULL,rsa->e,r0,ctx2);     /* d */
-       if (rsa->d == NULL) goto err;
+       if (!BN_mod_inverse(rsa->d,rsa->e,r0,ctx2)) goto err;   /* d */
 
        /* calculate d mod (p-1) */
-       rsa->dmp1=BN_new();
-       if (rsa->dmp1 == NULL) goto err;
        if (!BN_mod(rsa->dmp1,rsa->d,r1,ctx)) goto err;
 
        /* calculate d mod (q-1) */
-       rsa->dmq1=BN_new();
-       if (rsa->dmq1 == NULL) goto err;
        if (!BN_mod(rsa->dmq1,rsa->d,r2,ctx)) goto err;
 
        /* calculate inverse of q mod p */
-       rsa->iqmp=BN_mod_inverse(NULL,rsa->q,rsa->p,ctx2);
-       if (rsa->iqmp == NULL) goto err;
+       if (!BN_mod_inverse(rsa->iqmp,rsa->q,rsa->p,ctx2)) goto err;
 
        ok=1;
 err: