Fix DH_get_nid() so that it does not cache values.
[openssl.git] / crypto / ffc / ffc_key_generate.c
index b8c85480c12a9bb857544dec9126a1c73d28804a..aeabae010fd0a6c977e51b8ccb3c0c29bd0f0a2c 100644 (file)
 int ffc_generate_private_key(BN_CTX *ctx, const FFC_PARAMS *params,
                              int N, int s, BIGNUM *priv)
 {
-#ifdef FIPS_MODE
-    return ffc_generate_private_key_fips(ctx, params, N, s, priv);
-#else
-    do {
-        if (!BN_priv_rand_range_ex(priv, params->q, ctx))
-            return 0;
-    } while (BN_is_zero(priv) || BN_is_one(priv));
-    return 1;
-#endif /* FIPS_MODE */
-}
-
-int ffc_generate_private_key_fips(BN_CTX *ctx, const FFC_PARAMS *params,
-                                  int N, int s, BIGNUM *priv)
-{
-    int ret = 0;
+    int ret = 0, qbits = BN_num_bits(params->q);
     BIGNUM *m, *two_powN = NULL;
 
+    /* Deal with the edge case where the value of N is not set */
+    if (N == 0)
+        N = qbits;
+    if (s == 0)
+        s = N / 2;
+
     /* Step (2) : check range of N */
-    if (N < 2 * s || N > BN_num_bits(params->q))
+    if (N < 2 * s || N > qbits)
         return 0;
 
     two_powN = BN_new();
@@ -50,6 +42,7 @@ int ffc_generate_private_key_fips(BN_CTX *ctx, const FFC_PARAMS *params,
 
     /* Step (5) : M = min(2 ^ N, q) */
     m = (BN_cmp(two_powN, params->q) > 0) ? params->q : two_powN;
+
     do {
         /* Steps (3, 4 & 7) :  c + 1 = 1 + random[0..2^N - 1] */
         if (!BN_priv_rand_range_ex(priv, two_powN, ctx)