{
if (dctx->uninstantiate)
dctx->uninstantiate(dctx);
- OPENSSL_cleanse(&dctx->d, sizeof(dctx->d));
- OPENSSL_free(dctx);
+ /* Don't free up default DRBG */
+ if (dctx == FIPS_get_default_drbg())
+ {
+ memset(dctx, 0, sizeof(DRBG_CTX));
+ dctx->type = 0;
+ dctx->status = DRBG_STATUS_UNINITIALISED;
+ }
+ else
+ {
+ OPENSSL_cleanse(&dctx->d, sizeof(dctx->d));
+ OPENSSL_free(dctx);
+ }
}
static size_t fips_get_entropy(DRBG_CTX *dctx, unsigned char **pout,
{
unsigned char *tout, *p;
size_t bl = dctx->entropy_blocklen, rv;
+ if (!dctx->get_entropy)
+ return 0;
if (dctx->xflags & DRBG_FLAG_TEST || !bl)
return dctx->get_entropy(dctx, pout, entropy, min_len, max_len);
rv = dctx->get_entropy(dctx, &tout, entropy + bl,
FIPSerr(FIPS_F_FIPS_DRBG_INSTANTIATE, FIPS_R_ERROR_RETRIEVING_ENTROPY);
FIPSerr(FIPS_F_FIPS_DRBG_INSTANTIATE, FIPS_R_ERROR_RETRIEVING_NONCE);
FIPSerr(FIPS_F_FIPS_DRBG_INSTANTIATE, FIPS_R_INSTANTIATE_ERROR);
+ FIPSerr(FIPS_F_FIPS_DRBG_INSTANTIATE, FIPS_R_DRBG_NOT_INITIALISED);
#endif
int r = 0;
goto end;
}
+ if (!dctx->instantiate)
+ {
+ r = FIPS_R_DRBG_NOT_INITIALISED;
+ goto end;
+ }
+
if (dctx->status != DRBG_STATUS_UNINITIALISED)
{
if (dctx->status == DRBG_STATUS_ERROR)
goto end;
}
- if (dctx->max_nonce > 0)
+ if (dctx->max_nonce > 0 && dctx->get_nonce)
{
noncelen = dctx->get_nonce(dctx, &nonce,
dctx->strength / 2,
const unsigned char *adin, size_t adinlen, int hcheck)
{
unsigned char *entropy = NULL;
- size_t entlen;
+ size_t entlen = 0;
int r = 0;
#if 0
- FIPSerr(FIPS_F_FIPS_DRBG_RESEED, FIPS_R_NOT_INSTANTIATED);
- FIPSerr(FIPS_F_FIPS_DRBG_RESEED, FIPS_R_ADDITIONAL_INPUT_TOO_LONG);
+ FIPSerr(FIPS_F_DRBG_RESEED, FIPS_R_NOT_INSTANTIATED);
+ FIPSerr(FIPS_F_DRBG_RESEED, FIPS_R_ADDITIONAL_INPUT_TOO_LONG);
#endif
if (dctx->status != DRBG_STATUS_READY
&& dctx->status != DRBG_STATUS_RESEED)
return 1;
if (r && !(dctx->iflags & DRBG_FLAG_NOERR))
- FIPSerr(FIPS_F_FIPS_DRBG_RESEED, r);
+ FIPSerr(FIPS_F_DRBG_RESEED, r);
return 0;
}
{
int r = 0;
+ if (FIPS_selftest_failed())
+ {
+ FIPSerr(FIPS_F_FIPS_DRBG_GENERATE, FIPS_R_SELFTEST_FAILED);
+ return 0;
+ }
+
if (!fips_drbg_check(dctx))
return 0;
static int drbg_stick = 0;
-void FIPS_drbg_stick(void)
+void FIPS_drbg_stick(int onoff)
{
- drbg_stick = 1;
+ drbg_stick = onoff;
}
/* Continuous DRBG utility function */