-
-
-/*
- * The following function tie the DRBG code into the RAND_METHOD
- */
-
-DRBG_CTX *RAND_DRBG_get_default(void)
-{
- if (!RUN_ONCE(&ossl_drbg_init, do_ossl_drbg_init))
- return NULL;
- return &ossl_drbg;
-}
-
-static int drbg_bytes(unsigned char *out, int count)
-{
- DRBG_CTX *dctx = RAND_DRBG_get_default();
- int ret = 0;
-
- CRYPTO_THREAD_write_lock(dctx->lock);
- do {
- size_t rcnt;
-
- if (count > (int)dctx->max_request)
- rcnt = dctx->max_request;
- else
- rcnt = count;
- ret = RAND_DRBG_generate(dctx, out, rcnt, 0, NULL, 0);
- if (!ret)
- goto err;
- out += rcnt;
- count -= rcnt;
- } while (count);
- ret = 1;
-err:
- CRYPTO_THREAD_unlock(dctx->lock);
- return ret;
-}
-
-static int drbg_status(void)
-{
- DRBG_CTX *dctx = RAND_DRBG_get_default();
- int ret;
-
- CRYPTO_THREAD_write_lock(dctx->lock);
- ret = dctx->status == DRBG_STATUS_READY ? 1 : 0;
- CRYPTO_THREAD_unlock(dctx->lock);
- return ret;
-}
-
-static void drbg_cleanup(void)
-{
- DRBG_CTX *dctx = RAND_DRBG_get_default();
-
- CRYPTO_THREAD_write_lock(dctx->lock);
- RAND_DRBG_uninstantiate(dctx);
- CRYPTO_THREAD_unlock(dctx->lock);
-}
-
-static const RAND_METHOD rand_drbg_meth =
-{
- NULL,
- drbg_bytes,
- drbg_cleanup,
- NULL,
- drbg_bytes,
- drbg_status
-};
-
-const RAND_METHOD *RAND_drbg(void)
-{
- return &rand_drbg_meth;
-}