Use BN_rand_range().
[openssl.git] / crypto / dh / dh_key.c
index 0e4fee1..7a0ace7 100644 (file)
@@ -101,7 +101,6 @@ const DH_METHOD *DH_OpenSSL(void)
 static int generate_key(DH *dh)
        {
        int ok=0;
-       unsigned int i;
        BN_CTX ctx;
        BN_MONT_CTX *mont;
        BIGNUM *pub_key=NULL,*priv_key=NULL;
@@ -110,15 +109,9 @@ static int generate_key(DH *dh)
 
        if (dh->priv_key == NULL)
                {
-               i=dh->length;
-               if (i == 0)
-                       {
-                       /* Make the number p-1 bits long */
-                       i=BN_num_bits(dh->p)-1;
-                       }
                priv_key=BN_new();
                if (priv_key == NULL) goto err;
-               if (!BN_rand(priv_key,i,0,0)) goto err;
+               if (!BN_rand_range(priv_key, dh->p)) goto err;
                }
        else
                priv_key=dh->priv_key;