clarify comment
[openssl.git] / fips / rand / fips_drbg_lib.c
index a0bb9eda64d53e949a8ff88f82543414108c1b91..015b95a972682a8ce3c393b7b9fa79e3350db301 100644 (file)
@@ -79,6 +79,8 @@ int FIPS_drbg_init(DRBG_CTX *dctx, int type, unsigned int flags)
                rv = fips_drbg_ctr_init(dctx);
        if (rv == -2)
                rv = fips_drbg_hmac_init(dctx);
+       if (rv == -2)
+               rv = fips_drbg_ec_init(dctx);
 
        if (rv <= 0)
                {
@@ -113,8 +115,14 @@ DRBG_CTX *FIPS_drbg_new(int type, unsigned int flags)
                FIPSerr(FIPS_F_FIPS_DRBG_NEW, ERR_R_MALLOC_FAILURE);
                return NULL;
                }
+
        if (type == 0)
+               {
+               memset(dctx, 0, sizeof(DRBG_CTX));
+               dctx->type = 0;
+               dctx->status = DRBG_STATUS_UNINITIALISED;
                return dctx;
+               }
 
        if (FIPS_drbg_init(dctx, type, flags) <= 0)
                {
@@ -243,7 +251,8 @@ int FIPS_drbg_instantiate(DRBG_CTX *dctx,
 
 
        dctx->status = DRBG_STATUS_READY;
-       dctx->reseed_counter = 1;
+       if (!(dctx->flags & DRBG_CUSTOM_RESEED))
+               dctx->reseed_counter = 1;
 
        end:
 
@@ -307,7 +316,8 @@ int FIPS_drbg_reseed(DRBG_CTX *dctx,
                goto end;
 
        dctx->status = DRBG_STATUS_READY;
-       dctx->reseed_counter = 1;
+       if (!(dctx->flags & DRBG_CUSTOM_RESEED))
+               dctx->reseed_counter = 1;
        end:
 
        if (entropy && dctx->cleanup_entropy)
@@ -343,7 +353,7 @@ static int fips_drbg_check(DRBG_CTX *dctx)
        }
 
 int FIPS_drbg_generate(DRBG_CTX *dctx, unsigned char *out, size_t outlen,
-                       int strength, int prediction_resistance,
+                       int prediction_resistance,
                        const unsigned char *adin, size_t adinlen)
        {
        int r = 0;
@@ -367,13 +377,15 @@ int FIPS_drbg_generate(DRBG_CTX *dctx, unsigned char *out, size_t outlen,
                return 0;
                }
 
-       if (strength > dctx->strength)
+       if (adinlen > dctx->max_adin)
                {
-               r = FIPS_R_INSUFFICIENT_SECURITY_STRENGTH;
+               r = FIPS_R_ADDITIONAL_INPUT_TOO_LONG;
                goto end;
                }
 
-       if (dctx->reseed_counter >= dctx->reseed_interval)
+       if (dctx->flags & DRBG_CUSTOM_RESEED)
+               dctx->generate(dctx, NULL, outlen, NULL, 0);
+       else if (dctx->reseed_counter >= dctx->reseed_interval)
                dctx->status = DRBG_STATUS_RESEED;
 
        if (dctx->status == DRBG_STATUS_RESEED || prediction_resistance)
@@ -393,10 +405,13 @@ int FIPS_drbg_generate(DRBG_CTX *dctx, unsigned char *out, size_t outlen,
                dctx->status = DRBG_STATUS_ERROR;
                goto end;
                }
-       if (dctx->reseed_counter >= dctx->reseed_interval)
-               dctx->status = DRBG_STATUS_RESEED;
-       else
-               dctx->reseed_counter++;
+       if (!(dctx->flags & DRBG_CUSTOM_RESEED))
+               {
+               if (dctx->reseed_counter >= dctx->reseed_interval)
+                       dctx->status = DRBG_STATUS_RESEED;
+               else
+                       dctx->reseed_counter++;
+               }
 
        end:
        if (r)