+
+static int drbg_stick = 0;
+
+void FIPS_drbg_stick(void)
+ {
+ drbg_stick = 1;
+ }
+
+/* Continuous DRBG utility function */
+int drbg_cprng_test(DRBG_CTX *dctx, const unsigned char *out)
+ {
+ /* No CPRNG in test mode */
+ if (dctx->flags & DRBG_FLAG_TEST)
+ return 1;
+ /* Check block is valid: should never happen */
+ if (dctx->lb_valid == 0)
+ {
+ FIPSerr(FIPS_F_DRBG_CPRNG_TEST, FIPS_R_INTERNAL_ERROR);
+ fips_set_selftest_fail();
+ return 0;
+ }
+ if (drbg_stick)
+ memcpy(dctx->lb, out, dctx->blocklength);
+ /* Check against last block: fail if match */
+ if (!memcmp(dctx->lb, out, dctx->blocklength))
+ {
+ FIPSerr(FIPS_F_DRBG_CPRNG_TEST, FIPS_R_DRBG_STUCK);
+ fips_set_selftest_fail();
+ return 0;
+ }
+ /* Save last block for next comparison */
+ memcpy(dctx->lb, out, dctx->blocklength);
+ return 1;
+ }