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 generate_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_perslen + 1) > 0)
        goto err;
    t.entropylen = 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.entropylen = drbg->min_entropylen - 1;
    if (!init(drbg, td, &t)
            || RAND_DRBG_instantiate(drbg, td->pers, td->perslen) > 0
            || !uninstantiate(drbg))
        goto err;
    t.entropylen = drbg->max_entropylen + 1;
    if (!init(drbg, td, &t)
            || RAND_DRBG_instantiate(drbg, td->pers, td->perslen) > 0
            || !uninstantiate(drbg))
        goto err;
    if (drbg->min_noncelen) {
        t.noncelen = drbg->min_noncelen - 1;
        if (!init(drbg, td, &t)
                || RAND_DRBG_instantiate(drbg, td->pers, td->perslen) > 0
                || !uninstantiate(drbg))
            goto err;
    }
    if (drbg->max_noncelen) {
        t.noncelen = drbg->max_noncelen + 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_adinlen + 1)))
        goto err;
    t.entropylen = 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;
    generate_counter_tmp = drbg->generate_counter;
    drbg->generate_counter = drbg->reseed_interval;
    t.entropycnt = 0;
    if (!TEST_true(RAND_DRBG_generate(drbg, buff, td->exlen, 0,
                                      td->adin, td->adinlen))
            || !TEST_int_eq(t.entropycnt, 1)
            || !TEST_int_eq(drbg->generate_counter, generate_counter_tmp + 1)
            || !uninstantiate(drbg))
        goto err;
    t.entropylen = 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;
    generate_counter_tmp = drbg->generate_counter;
    drbg->generate_counter = drbg->reseed_interval;
    t.entropycnt = 0;
    if (!TEST_true(RAND_DRBG_generate(drbg, buff, td->exlen, 0,
                                      td->adin, td->adinlen))
            || !TEST_int_eq(t.entropycnt, 1)
            || !TEST_int_eq(drbg->generate_counter, generate_counter_tmp + 1)
            || !uninstantiate(drbg))
        goto err;
    if (!init(drbg, td, &t)
            || RAND_DRBG_reseed(drbg, td->adin, drbg->max_adinlen + 1) > 0)
        goto err;
    t.entropylen = 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.entropylen = drbg->max_entropylen + 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.entropylen = drbg->min_entropylen - 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->data), &drbg->data, sizeof(drbg->data)))
        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 generate_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_perslen + 1) > 0)\n        goto err;\n    t.entropylen = 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.entropylen = drbg->min_entropylen - 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.entropylen = drbg->max_entropylen + 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_noncelen) {\n        t.noncelen = drbg->min_noncelen - 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_noncelen) {\n        t.noncelen = drbg->max_noncelen + 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_adinlen + 1)))\n        goto err;\n    t.entropylen = 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    generate_counter_tmp = drbg->generate_counter;\n    drbg->generate_counter = drbg->reseed_interval;\n    t.entropycnt = 0;\n    if (!TEST_true(RAND_DRBG_generate(drbg, buff, td->exlen, 0,\n                                      td->adin, td->adinlen))\n            || !TEST_int_eq(t.entropycnt, 1)\n            || !TEST_int_eq(drbg->generate_counter, generate_counter_tmp + 1)\n            || !uninstantiate(drbg))\n        goto err;\n    t.entropylen = 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    generate_counter_tmp = drbg->generate_counter;\n    drbg->generate_counter = drbg->reseed_interval;\n    t.entropycnt = 0;\n    if (!TEST_true(RAND_DRBG_generate(drbg, buff, td->exlen, 0,\n                                      td->adin, td->adinlen))\n            || !TEST_int_eq(t.entropycnt, 1)\n            || !TEST_int_eq(drbg->generate_counter, generate_counter_tmp + 1)\n            || !uninstantiate(drbg))\n        goto err;\n    if (!init(drbg, td, &t)\n            || RAND_DRBG_reseed(drbg, td->adin, drbg->max_adinlen + 1) > 0)\n        goto err;\n    t.entropylen = 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.entropylen = drbg->max_entropylen + 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.entropylen = drbg->min_entropylen - 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->data), &drbg->data, sizeof(drbg->data)))\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    return rand_drbg_new(0, type, flags, parent);\n}', 'static RAND_DRBG *rand_drbg_new(int secure,\n                                int type,\n                                unsigned int flags,\n                                RAND_DRBG *parent)\n{\n    RAND_DRBG *drbg = secure ?\n        OPENSSL_secure_zalloc(sizeof(*drbg)) : OPENSSL_zalloc(sizeof(*drbg));\n    if (drbg == NULL) {\n        RANDerr(RAND_F_RAND_DRBG_NEW, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    drbg->secure = secure && CRYPTO_secure_allocated(drbg);\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 (!RAND_DRBG_set_callbacks(drbg, rand_drbg_get_entropy,\n                                 rand_drbg_cleanup_entropy,\n                                 NULL, NULL))\n        goto err;\n    return drbg;\nerr:\n    if (drbg->secure)\n        OPENSSL_secure_free(drbg);\n    else\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 0;\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 = drbg_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}']