Simplify BN_rand_range
[openssl.git] / crypto / dsa / dsa_ossl.c
index 96295dc24f74ff621e4cc20ba880cec862ab9f9f..734681733703217a38fc1b14fbe3b195f708b345 100644 (file)
@@ -92,7 +92,7 @@ dsa_finish,
 NULL
 };
 
-DSA_METHOD *DSA_OpenSSL(void)
+const DSA_METHOD *DSA_OpenSSL(void)
 {
        return &openssl_dsa_meth;
 }
@@ -180,13 +180,9 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
        kinv=NULL;
 
        /* Get random k */
-       for (;;)
-               {
-               if (!BN_rand(&k, BN_num_bits(dsa->q), 0, 0)) goto err;
-               if (BN_cmp(&k,dsa->q) >= 0)
-                       BN_sub(&k,&k,dsa->q);
-               if (!BN_is_zero(&k)) break;
-               }
+       do
+               if (!BN_rand_range(&k, dsa->q)) goto err;
+       while (BN_is_zero(&k));
 
        if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P))
                {