static void ctr_XOR(RAND_DRBG_CTR *ctr, const unsigned char *in, size_t inlen)
{
    size_t i, n;
    if (in == NULL || inlen == 0)
        return;
    n = inlen < ctr->keylen ? inlen : ctr->keylen;
    for (i = 0; i < n; i++)
        ctr->K[i] ^= in[i];
    if (inlen <= ctr->keylen)
        return;
    n = inlen - ctr->keylen;
    if (n > 16) {
        n = 16;
    }
    for (i = 0; i < n; i++)
        ctr->V[i] ^= in[i + ctr->keylen];
}
['int rand_drbg_restart(RAND_DRBG *drbg,\n                      const unsigned char *buffer, size_t len, size_t entropy)\n{\n    int reseeded = 0;\n    const unsigned char *adin = NULL;\n    size_t adinlen = 0;\n    if (drbg->pool != NULL) {\n        RANDerr(RAND_F_RAND_DRBG_RESTART, ERR_R_INTERNAL_ERROR);\n        RAND_POOL_free(drbg->pool);\n        drbg->pool = NULL;\n    }\n    if (buffer != NULL) {\n        if (entropy > 0) {\n            if (drbg->max_entropylen < len) {\n                RANDerr(RAND_F_RAND_DRBG_RESTART,\n                    RAND_R_ENTROPY_INPUT_TOO_LONG);\n                return 0;\n            }\n            if (entropy > 8 * len) {\n                RANDerr(RAND_F_RAND_DRBG_RESTART, RAND_R_ENTROPY_OUT_OF_RANGE);\n                return 0;\n            }\n            drbg->pool = RAND_POOL_new(entropy, len, len);\n            if (drbg->pool == NULL)\n                return 0;\n            RAND_POOL_add(drbg->pool, buffer, len, entropy);\n        } else {\n            if (drbg->max_adinlen < len) {\n                RANDerr(RAND_F_RAND_DRBG_RESTART,\n                        RAND_R_ADDITIONAL_INPUT_TOO_LONG);\n                return 0;\n            }\n            adin = buffer;\n            adinlen = len;\n        }\n    }\n    if (drbg->state == DRBG_ERROR)\n        RAND_DRBG_uninstantiate(drbg);\n    if (drbg->state == DRBG_UNINITIALISED) {\n        drbg_setup(drbg, NULL);\n        reseeded = (drbg->state == DRBG_READY);\n    }\n    if (drbg->state == DRBG_READY) {\n        if (adin != NULL) {\n            ctr_reseed(drbg, adin, adinlen, NULL, 0);\n        } else if (reseeded == 0) {\n            RAND_DRBG_reseed(drbg, NULL, 0);\n        }\n    }\n    if (drbg->pool != NULL) {\n        drbg->state = DRBG_ERROR;\n        RANDerr(RAND_F_RAND_DRBG_RESTART, ERR_R_INTERNAL_ERROR);\n        RAND_POOL_free(drbg->pool);\n        drbg->pool = NULL;\n        return 0;\n    }\n    return drbg->state == DRBG_READY;\n}', 'int ctr_reseed(RAND_DRBG *drbg,\n               const unsigned char *entropy, size_t entropylen,\n               const unsigned char *adin, size_t adinlen)\n{\n    if (entropy == NULL)\n        return 0;\n    ctr_update(drbg, entropy, entropylen, adin, adinlen, NULL, 0);\n    return 1;\n}', 'static void ctr_update(RAND_DRBG *drbg,\n                       const unsigned char *in1, size_t in1len,\n                       const unsigned char *in2, size_t in2len,\n                       const unsigned char *nonce, size_t noncelen)\n{\n    RAND_DRBG_CTR *ctr = &drbg->ctr;\n    inc_128(ctr);\n    AES_encrypt(ctr->V, ctr->K, &ctr->ks);\n    if (ctr->keylen != 16) {\n        inc_128(ctr);\n        AES_encrypt(ctr->V, ctr->K + 16, &ctr->ks);\n    }\n    inc_128(ctr);\n    AES_encrypt(ctr->V, ctr->V, &ctr->ks);\n    if (ctr->keylen == 24) {\n        memcpy(ctr->V + 8, ctr->V, 8);\n        memcpy(ctr->V, ctr->K + 24, 8);\n    }\n    if (drbg->flags & RAND_DRBG_FLAG_CTR_USE_DF) {\n        if (in1 != NULL || nonce != NULL || in2 != NULL)\n            ctr_df(ctr, in1, in1len, nonce, noncelen, in2, in2len);\n        if (in1len)\n            ctr_XOR(ctr, ctr->KX, drbg->seedlen);\n    } else {\n        ctr_XOR(ctr, in1, in1len);\n        ctr_XOR(ctr, in2, in2len);\n    }\n    AES_set_encrypt_key(ctr->K, drbg->strength, &ctr->ks);\n}', 'static void ctr_XOR(RAND_DRBG_CTR *ctr, const unsigned char *in, size_t inlen)\n{\n    size_t i, n;\n    if (in == NULL || inlen == 0)\n        return;\n    n = inlen < ctr->keylen ? inlen : ctr->keylen;\n    for (i = 0; i < n; i++)\n        ctr->K[i] ^= in[i];\n    if (inlen <= ctr->keylen)\n        return;\n    n = inlen - ctr->keylen;\n    if (n > 16) {\n        n = 16;\n    }\n    for (i = 0; i < n; i++)\n        ctr->V[i] ^= in[i + ctr->keylen];\n}']