static int error_check(DRBG_SELFTEST_DATA *td)
{
    static char zero[sizeof(RAND_DRBG)];
    RAND_DRBG *drbg = NULL;
    TEST_CTX t;
    unsigned char buff[1024];
    unsigned int reseed_counter_tmp;
    int ret = 0;
    if (!TEST_ptr(drbg = RAND_DRBG_new(0, 0, NULL)))
        goto err;
    if (!init(drbg, td, &t)
            || RAND_DRBG_instantiate(drbg, td->pers, drbg->max_pers + 1) > 0)
        goto err;
    t.entlen = 0;
    if (TEST_int_le(RAND_DRBG_instantiate(drbg, td->pers, td->perslen), 0))
        goto err;
    if (!TEST_false(RAND_DRBG_generate(drbg, buff, td->exlen, 0,
                                       td->adin, td->adinlen))
            || !uninstantiate(drbg))
        goto err;
    t.entlen = drbg->min_entropy - 1;
    if (!init(drbg, td, &t)
            || RAND_DRBG_instantiate(drbg, td->pers, td->perslen) > 0
            || !uninstantiate(drbg))
        goto err;
    t.entlen = drbg->max_entropy + 1;
    if (!init(drbg, td, &t)
            || RAND_DRBG_instantiate(drbg, td->pers, td->perslen) > 0
            || !uninstantiate(drbg))
        goto err;
    if (drbg->min_nonce) {
        t.noncelen = drbg->min_nonce - 1;
        if (!init(drbg, td, &t)
                || RAND_DRBG_instantiate(drbg, td->pers, td->perslen) > 0
                || !uninstantiate(drbg))
            goto err;
    }
    if (drbg->max_nonce) {
        t.noncelen = drbg->max_nonce + 1;
        if (!init(drbg, td, &t)
                || RAND_DRBG_instantiate(drbg, td->pers, td->perslen) > 0
                || !uninstantiate(drbg))
            goto err;
    }
    if (!instantiate(drbg, td, &t)
            || !TEST_true(RAND_DRBG_generate(drbg, buff, td->exlen, 0,
                                             td->adin, td->adinlen)))
        goto err;
    if (!TEST_false(RAND_DRBG_generate(drbg, buff, drbg->max_request + 1, 0,
                                       td->adin, td->adinlen)))
        goto err;
    if (!TEST_false(RAND_DRBG_generate(drbg, buff, td->exlen, 0,
                                       td->adin, drbg->max_adin + 1)))
        goto err;
    t.entlen = 0;
    if (TEST_false(RAND_DRBG_generate(drbg, buff, td->exlen, 1,
                                      td->adin, td->adinlen))
            || !uninstantiate(drbg))
        goto err;
    if (!instantiate(drbg, td, &t))
        goto err;
    reseed_counter_tmp = drbg->reseed_counter;
    drbg->reseed_counter = drbg->reseed_interval;
    t.entcnt = 0;
    if (!TEST_true(RAND_DRBG_generate(drbg, buff, td->exlen, 0,
                                      td->adin, td->adinlen))
            || !TEST_int_eq(t.entcnt, 1)
            || !TEST_int_eq(drbg->reseed_counter, reseed_counter_tmp + 1)
            || !uninstantiate(drbg))
        goto err;
    t.entlen = 0;
    if (!TEST_false(RAND_DRBG_generate(drbg, buff, td->exlen, 1,
                                       td->adin, td->adinlen))
            || !uninstantiate(drbg))
        goto err;
    if (!instantiate(drbg, td, &t))
        goto err;
    reseed_counter_tmp = drbg->reseed_counter;
    drbg->reseed_counter = drbg->reseed_interval;
    t.entcnt = 0;
    if (!TEST_true(RAND_DRBG_generate(drbg, buff, td->exlen, 0,
                                      td->adin, td->adinlen))
            || !TEST_int_eq(t.entcnt, 1)
            || !TEST_int_eq(drbg->reseed_counter, reseed_counter_tmp + 1)
            || !uninstantiate(drbg))
        goto err;
    if (!init(drbg, td, &t)
            || RAND_DRBG_reseed(drbg, td->adin, drbg->max_adin + 1) > 0)
        goto err;
    t.entlen = 0;
    if (!TEST_int_le(RAND_DRBG_reseed(drbg, td->adin, td->adinlen), 0)
            || !uninstantiate(drbg))
        goto err;
    if (!init(drbg, td, &t))
        goto err;
    t.entlen = drbg->max_entropy + 1;
    if (!TEST_int_le(RAND_DRBG_reseed(drbg, td->adin, td->adinlen), 0)
            || !uninstantiate(drbg))
        goto err;
    if (!init(drbg, td, &t))
        goto err;
    t.entlen = drbg->min_entropy - 1;
    if (!TEST_int_le(RAND_DRBG_reseed(drbg, td->adin, td->adinlen), 0)
            || !uninstantiate(drbg))
        goto err;
    if (!TEST_mem_eq(zero, sizeof(drbg->ctr), &drbg->ctr, sizeof(drbg->ctr)))
        goto err;
    ret = 1;
err:
    uninstantiate(drbg);
    RAND_DRBG_free(drbg);
    return ret;
}
['static int error_check(DRBG_SELFTEST_DATA *td)\n{\n    static char zero[sizeof(RAND_DRBG)];\n    RAND_DRBG *drbg = NULL;\n    TEST_CTX t;\n    unsigned char buff[1024];\n    unsigned int reseed_counter_tmp;\n    int ret = 0;\n    if (!TEST_ptr(drbg = RAND_DRBG_new(0, 0, NULL)))\n        goto err;\n    if (!init(drbg, td, &t)\n            || RAND_DRBG_instantiate(drbg, td->pers, drbg->max_pers + 1) > 0)\n        goto err;\n    t.entlen = 0;\n    if (TEST_int_le(RAND_DRBG_instantiate(drbg, td->pers, td->perslen), 0))\n        goto err;\n    if (!TEST_false(RAND_DRBG_generate(drbg, buff, td->exlen, 0,\n                                       td->adin, td->adinlen))\n            || !uninstantiate(drbg))\n        goto err;\n    t.entlen = drbg->min_entropy - 1;\n    if (!init(drbg, td, &t)\n            || RAND_DRBG_instantiate(drbg, td->pers, td->perslen) > 0\n            || !uninstantiate(drbg))\n        goto err;\n    t.entlen = drbg->max_entropy + 1;\n    if (!init(drbg, td, &t)\n            || RAND_DRBG_instantiate(drbg, td->pers, td->perslen) > 0\n            || !uninstantiate(drbg))\n        goto err;\n    if (drbg->min_nonce) {\n        t.noncelen = drbg->min_nonce - 1;\n        if (!init(drbg, td, &t)\n                || RAND_DRBG_instantiate(drbg, td->pers, td->perslen) > 0\n                || !uninstantiate(drbg))\n            goto err;\n    }\n    if (drbg->max_nonce) {\n        t.noncelen = drbg->max_nonce + 1;\n        if (!init(drbg, td, &t)\n                || RAND_DRBG_instantiate(drbg, td->pers, td->perslen) > 0\n                || !uninstantiate(drbg))\n            goto err;\n    }\n    if (!instantiate(drbg, td, &t)\n            || !TEST_true(RAND_DRBG_generate(drbg, buff, td->exlen, 0,\n                                             td->adin, td->adinlen)))\n        goto err;\n    if (!TEST_false(RAND_DRBG_generate(drbg, buff, drbg->max_request + 1, 0,\n                                       td->adin, td->adinlen)))\n        goto err;\n    if (!TEST_false(RAND_DRBG_generate(drbg, buff, td->exlen, 0,\n                                       td->adin, drbg->max_adin + 1)))\n        goto err;\n    t.entlen = 0;\n    if (TEST_false(RAND_DRBG_generate(drbg, buff, td->exlen, 1,\n                                      td->adin, td->adinlen))\n            || !uninstantiate(drbg))\n        goto err;\n    if (!instantiate(drbg, td, &t))\n        goto err;\n    reseed_counter_tmp = drbg->reseed_counter;\n    drbg->reseed_counter = drbg->reseed_interval;\n    t.entcnt = 0;\n    if (!TEST_true(RAND_DRBG_generate(drbg, buff, td->exlen, 0,\n                                      td->adin, td->adinlen))\n            || !TEST_int_eq(t.entcnt, 1)\n            || !TEST_int_eq(drbg->reseed_counter, reseed_counter_tmp + 1)\n            || !uninstantiate(drbg))\n        goto err;\n    t.entlen = 0;\n    if (!TEST_false(RAND_DRBG_generate(drbg, buff, td->exlen, 1,\n                                       td->adin, td->adinlen))\n            || !uninstantiate(drbg))\n        goto err;\n    if (!instantiate(drbg, td, &t))\n        goto err;\n    reseed_counter_tmp = drbg->reseed_counter;\n    drbg->reseed_counter = drbg->reseed_interval;\n    t.entcnt = 0;\n    if (!TEST_true(RAND_DRBG_generate(drbg, buff, td->exlen, 0,\n                                      td->adin, td->adinlen))\n            || !TEST_int_eq(t.entcnt, 1)\n            || !TEST_int_eq(drbg->reseed_counter, reseed_counter_tmp + 1)\n            || !uninstantiate(drbg))\n        goto err;\n    if (!init(drbg, td, &t)\n            || RAND_DRBG_reseed(drbg, td->adin, drbg->max_adin + 1) > 0)\n        goto err;\n    t.entlen = 0;\n    if (!TEST_int_le(RAND_DRBG_reseed(drbg, td->adin, td->adinlen), 0)\n            || !uninstantiate(drbg))\n        goto err;\n    if (!init(drbg, td, &t))\n        goto err;\n    t.entlen = drbg->max_entropy + 1;\n    if (!TEST_int_le(RAND_DRBG_reseed(drbg, td->adin, td->adinlen), 0)\n            || !uninstantiate(drbg))\n        goto err;\n    if (!init(drbg, td, &t))\n        goto err;\n    t.entlen = drbg->min_entropy - 1;\n    if (!TEST_int_le(RAND_DRBG_reseed(drbg, td->adin, td->adinlen), 0)\n            || !uninstantiate(drbg))\n        goto err;\n    if (!TEST_mem_eq(zero, sizeof(drbg->ctr), &drbg->ctr, sizeof(drbg->ctr)))\n        goto err;\n    ret = 1;\nerr:\n    uninstantiate(drbg);\n    RAND_DRBG_free(drbg);\n    return ret;\n}', 'RAND_DRBG *RAND_DRBG_new(int type, unsigned int flags, RAND_DRBG *parent)\n{\n    RAND_DRBG *drbg = OPENSSL_zalloc(sizeof(*drbg));\n    unsigned char *ucp = OPENSSL_zalloc(RANDOMNESS_NEEDED);\n    if (drbg == NULL || ucp == NULL) {\n        RANDerr(RAND_F_RAND_DRBG_NEW, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    drbg->size = RANDOMNESS_NEEDED;\n    drbg->randomness = ucp;\n    drbg->fork_count = rand_fork_count;\n    drbg->parent = parent;\n    if (RAND_DRBG_set(drbg, type, flags) < 0)\n        goto err;\n    if (parent != NULL) {\n        if (parent->state == DRBG_UNINITIALISED\n                && RAND_DRBG_instantiate(parent, NULL, 0) == 0)\n            goto err;\n        if (!RAND_DRBG_set_callbacks(drbg, drbg_entropy_from_parent,\n                                     drbg_release_entropy,\n                                     NULL, NULL)\n                || !RAND_DRBG_instantiate(drbg,\n                                          (unsigned char*)&drbg, sizeof(drbg)))\n            goto err;\n    }\n    return drbg;\nerr:\n    OPENSSL_free(ucp);\n    OPENSSL_free(drbg);\n    return NULL;\n}', 'int RAND_DRBG_set(RAND_DRBG *drbg, int nid, unsigned int flags)\n{\n    int ret = 1;\n    drbg->state = DRBG_UNINITIALISED;\n    drbg->flags = flags;\n    drbg->nid = nid;\n    switch (nid) {\n    default:\n        RANDerr(RAND_F_RAND_DRBG_SET, RAND_R_UNSUPPORTED_DRBG_TYPE);\n        return -2;\n    case 0:\n        return 1;\n    case NID_aes_128_ctr:\n    case NID_aes_192_ctr:\n    case NID_aes_256_ctr:\n        ret = ctr_init(drbg);\n        break;\n    }\n    if (ret < 0)\n        RANDerr(RAND_F_RAND_DRBG_SET, RAND_R_ERROR_INITIALISING_DRBG);\n    return ret;\n}']