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;
}