#include <string.h>
#include <openssl/crypto.h>
-#include <openssl/evp.h>
-#include <openssl/aes.h>
#include <openssl/err.h>
#include <openssl/fips_rand.h>
#include "fips_rand_lcl.h"
if (rv == -2)
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)
{
if (!fips_drbg_kat(&tctx, type, flags | DRBG_FLAG_TEST))
{
FIPSerr(FIPS_F_FIPS_DRBG_INIT, FIPS_R_SELFTEST_FAILURE);
+ dctx->status = DRBG_STATUS_ERROR;
return 0;
}
}
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)
{
dctx->status = DRBG_STATUS_READY;
- dctx->reseed_counter = 1;
+ if (!(dctx->flags & DRBG_CUSTOM_RESEED))
+ dctx->reseed_counter = 1;
end:
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)
dctx->flags | DRBG_FLAG_TEST))
{
FIPSerr(FIPS_F_FIPS_DRBG_CHECK, FIPS_R_SELFTEST_FAILURE);
+ dctx->status = DRBG_STATUS_ERROR;
return 0;
}
dctx->health_check_cnt = 0;
}
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;
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->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)
{
if (!FIPS_drbg_reseed(dctx, adin, adinlen))
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)