/* Initial test without PR */
+ /* Instantiate DRBG with test entropy, nonce and personalisation
+ * string.
+ */
+
if (!FIPS_drbg_init(dctx, td->nid, td->flags))
return 0;
if (!FIPS_drbg_set_callbacks(dctx, test_entropy, 0, 0, test_nonce, 0))
* ignore bytes after the keylength: so reduce adinlen
* to half to ensure invalid data is fed in.
*/
- if (!fips_post_corrupt(FIPS_TEST_DRBG, dctx->type, &dctx->flags))
+ if (!fips_post_corrupt(FIPS_TEST_DRBG, dctx->type, &dctx->iflags))
adinlen = td->adinlen / 2;
else
adinlen = td->adinlen;
+
+ /* Generate with no PR and verify output matches expected data */
if (!FIPS_drbg_generate(dctx, randout, td->katlen, 0,
td->adin, adinlen))
goto err;
FIPSerr(FIPS_F_FIPS_DRBG_SINGLE_KAT, FIPS_R_NOPR_TEST1_FAILURE);
goto err2;
}
-
+ /* If abbreviated POST end of test */
if (quick)
{
rv = 1;
goto err;
}
-
+ /* Reseed DRBG with test entropy and additional input */
t.ent = td->entreseed;
t.entlen = td->entreseedlen;
if (!FIPS_drbg_reseed(dctx, td->adinreseed, td->adinreseedlen))
goto err;
+ /* Generate with no PR and verify output matches expected data */
if (!FIPS_drbg_generate(dctx, randout, td->kat2len, 0,
td->adin2, td->adin2len))
goto err;
FIPS_drbg_uninstantiate(dctx);
/* Now test with PR */
+
+ /* Instantiate DRBG with test entropy, nonce and personalisation
+ * string.
+ */
if (!FIPS_drbg_init(dctx, td->nid, td->flags))
return 0;
if (!FIPS_drbg_set_callbacks(dctx, test_entropy, 0, 0, test_nonce, 0))
if (!FIPS_drbg_instantiate(dctx, td->pers_pr, td->perslen_pr))
goto err;
+ /* Now generate with PR: we need to supply entropy as this will
+ * perform a reseed operation. Check output matches expected value.
+ */
+
t.ent = td->entpr_pr;
t.entlen = td->entprlen_pr;
* ignore bytes after the keylength: so reduce adinlen
* to half to ensure invalid data is fed in.
*/
- if (!fips_post_corrupt(FIPS_TEST_DRBG, dctx->type, &dctx->flags))
+ if (!fips_post_corrupt(FIPS_TEST_DRBG, dctx->type, &dctx->iflags))
adinlen = td->adinlen_pr / 2;
else
adinlen = td->adinlen_pr;
goto err2;
}
+ /* Now generate again with PR: supply new entropy again.
+ * Check output matches expected value.
+ */
+
t.ent = td->entg_pr;
t.entlen = td->entglen_pr;
FIPSerr(FIPS_F_FIPS_DRBG_SINGLE_KAT, FIPS_R_PR_TEST2_FAILURE);
goto err2;
}
-
+ /* All OK, test complete */
rv = 1;
err:
return 1;
}
-/* This is the "health check" function required by SP800-90. Induce several
- * failure modes and check an error condition is set.
+/* This function performd extensive error checking as required by SP800-90.
+ * Induce several failure modes and check an error condition is set.
+ * This function along with fips_drbg_single_kat peforms the health checking
+ * operation.
*/
-static int fips_drbg_health_check(DRBG_CTX *dctx, DRBG_SELFTEST_DATA *td)
+static int fips_drbg_error_check(DRBG_CTX *dctx, DRBG_SELFTEST_DATA *td)
{
unsigned char randout[1024];
TEST_ENT t;
goto err;
/* Don't report induced errors */
- dctx->flags |= DRBG_FLAG_NOERR;
+ dctx->iflags |= DRBG_FLAG_NOERR;
/* Personalisation string tests */
goto err;
}
- dctx->flags &= ~DRBG_FLAG_NOERR;
+ dctx->iflags &= ~DRBG_FLAG_NOERR;
if (!FIPS_drbg_uninstantiate(dctx))
{
FIPSerr(FIPS_F_FIPS_DRBG_HEALTH_CHECK, FIPS_R_UNINSTANTIATE_ERROR);
if (!do_drbg_init(dctx, td, &t))
goto err;
- dctx->flags |= DRBG_FLAG_NOERR;
+ dctx->iflags |= DRBG_FLAG_NOERR;
/* Test insufficient entropy */
goto err;
}
- dctx->flags &= ~DRBG_FLAG_NOERR;
+ dctx->iflags &= ~DRBG_FLAG_NOERR;
if (!FIPS_drbg_uninstantiate(dctx))
{
FIPSerr(FIPS_F_FIPS_DRBG_HEALTH_CHECK, FIPS_R_UNINSTANTIATE_ERROR);
if (!do_drbg_init(dctx, td, &t))
goto err;
- dctx->flags |= DRBG_FLAG_NOERR;
+ dctx->iflags |= DRBG_FLAG_NOERR;
t.entlen = dctx->max_entropy + 1;
goto err;
}
- dctx->flags &= ~DRBG_FLAG_NOERR;
+ dctx->iflags &= ~DRBG_FLAG_NOERR;
if (!FIPS_drbg_uninstantiate(dctx))
{
FIPSerr(FIPS_F_FIPS_DRBG_HEALTH_CHECK, FIPS_R_UNINSTANTIATE_ERROR);
if (!do_drbg_init(dctx, td, &t))
goto err;
- dctx->flags |= DRBG_FLAG_NOERR;
+ dctx->iflags |= DRBG_FLAG_NOERR;
t.noncelen = dctx->min_nonce - 1;
goto err;
}
- dctx->flags &= ~DRBG_FLAG_NOERR;
+ dctx->iflags &= ~DRBG_FLAG_NOERR;
if (!FIPS_drbg_uninstantiate(dctx))
{
FIPSerr(FIPS_F_FIPS_DRBG_HEALTH_CHECK, FIPS_R_UNINSTANTIATE_ERROR);
if (!do_drbg_init(dctx, td, &t))
goto err;
- dctx->flags |= DRBG_FLAG_NOERR;
+ dctx->iflags |= DRBG_FLAG_NOERR;
t.noncelen = dctx->max_nonce + 1;
goto err;
}
- dctx->flags &= ~DRBG_FLAG_NOERR;
+ dctx->iflags &= ~DRBG_FLAG_NOERR;
if (!FIPS_drbg_uninstantiate(dctx))
{
FIPSerr(FIPS_F_FIPS_DRBG_HEALTH_CHECK, FIPS_R_UNINSTANTIATE_ERROR);
td->adin, td->adinlen))
goto err;
- dctx->flags |= DRBG_FLAG_NOERR;
+ dctx->iflags |= DRBG_FLAG_NOERR;
/* Request too much data for one request */
if (FIPS_drbg_generate(dctx, randout, dctx->max_request + 1, 0,
goto err;
}
- dctx->flags &= ~DRBG_FLAG_NOERR;
+ dctx->iflags &= ~DRBG_FLAG_NOERR;
if (!FIPS_drbg_uninstantiate(dctx))
{
if (!do_drbg_init(dctx, td, &t))
goto err;
- dctx->flags |= DRBG_FLAG_NOERR;
+ dctx->iflags |= DRBG_FLAG_NOERR;
if (FIPS_drbg_reseed(dctx, td->adin, dctx->max_adin + 1) > 0)
{
goto err;
}
- dctx->flags &= ~DRBG_FLAG_NOERR;
+ dctx->iflags &= ~DRBG_FLAG_NOERR;
if (!FIPS_drbg_uninstantiate(dctx))
{
if (!do_drbg_init(dctx, td, &t))
goto err;
- dctx->flags |= DRBG_FLAG_NOERR;
+ dctx->iflags |= DRBG_FLAG_NOERR;
if (FIPS_drbg_reseed(dctx, td->adin, dctx->max_adin + 1) > 0)
{
if (!do_drbg_init(dctx, td, &t))
goto err;
- dctx->flags |= DRBG_FLAG_NOERR;
+ dctx->iflags |= DRBG_FLAG_NOERR;
t.entlen = 0;
if (!do_drbg_init(dctx, td, &t))
goto err;
- dctx->flags |= DRBG_FLAG_NOERR;
+ dctx->iflags |= DRBG_FLAG_NOERR;
t.entlen = dctx->max_entropy + 1;
if (!do_drbg_init(dctx, td, &t))
goto err;
- dctx->flags |= DRBG_FLAG_NOERR;
+ dctx->iflags |= DRBG_FLAG_NOERR;
t.entlen = dctx->min_entropy - 1;
/* A real error as opposed to an induced one: underlying function will
* indicate the error.
*/
- if (!(dctx->flags & DRBG_FLAG_NOERR))
+ if (!(dctx->iflags & DRBG_FLAG_NOERR))
FIPSerr(FIPS_F_FIPS_DRBG_HEALTH_CHECK, FIPS_R_FUNCTION_ERROR);
FIPS_drbg_uninstantiate(dctx);
return 0;
int fips_drbg_kat(DRBG_CTX *dctx, int nid, unsigned int flags)
{
- int rv;
DRBG_SELFTEST_DATA *td;
+ flags |= DRBG_FLAG_TEST;
for (td = drbg_test; td->nid != 0; td++)
{
if (td->nid == nid && td->flags == flags)
{
- rv = fips_drbg_single_kat(dctx, td, 0);
- if (rv <= 0)
- return rv;
- return fips_drbg_health_check(dctx, td);
+ if (!fips_drbg_single_kat(dctx, td, 0))
+ return 0;
+ return fips_drbg_error_check(dctx, td);
}
}
return 0;
}
+int FIPS_drbg_health_check(DRBG_CTX *dctx)
+ {
+ int rv;
+ DRBG_CTX *tctx = NULL;
+ tctx = FIPS_drbg_new(0, 0);
+ fips_post_started(FIPS_TEST_DRBG, dctx->type, &dctx->xflags);
+ if (!tctx)
+ return 0;
+ rv = fips_drbg_kat(tctx, dctx->type, dctx->xflags);
+ if (tctx)
+ FIPS_drbg_free(tctx);
+ if (rv)
+ fips_post_success(FIPS_TEST_DRBG, dctx->type, &dctx->xflags);
+ else
+ fips_post_failed(FIPS_TEST_DRBG, dctx->type, &dctx->xflags);
+ if (!rv)
+ dctx->status = DRBG_STATUS_ERROR;
+ else
+ dctx->health_check_cnt = 0;
+ return rv;
+ }
+
int FIPS_selftest_drbg(void)
{
DRBG_CTX *dctx;
rv = 0;
continue;
}
- if (!fips_drbg_health_check(dctx, td))
+ if (!fips_drbg_error_check(dctx, td))
{
fips_post_failed(FIPS_TEST_DRBG, td->nid, &td->flags);
rv = 0;