EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *pctx)
{
    EVP_PKEY_CTX *rctx;
    if (!pctx->pmeth || !pctx->pmeth->copy)
        return NULL;
#ifndef OPENSSL_NO_ENGINE
    if (pctx->engine && !ENGINE_init(pctx->engine)) {
        EVPerr(EVP_F_EVP_PKEY_CTX_DUP, ERR_R_ENGINE_LIB);
        return 0;
    }
#endif
    rctx = OPENSSL_malloc(sizeof(*rctx));
    if (rctx == NULL)
        return NULL;
    rctx->pmeth = pctx->pmeth;
#ifndef OPENSSL_NO_ENGINE
    rctx->engine = pctx->engine;
#endif
    if (pctx->pkey)
        EVP_PKEY_up_ref(pctx->pkey);
    rctx->pkey = pctx->pkey;
    if (pctx->peerkey)
        EVP_PKEY_up_ref(pctx->peerkey);
    rctx->peerkey = pctx->peerkey;
    rctx->data = NULL;
    rctx->app_data = NULL;
    rctx->operation = pctx->operation;
    if (pctx->pmeth->copy(rctx, pctx) > 0)
        return rctx;
    EVP_PKEY_CTX_free(rctx);
    return NULL;
}
['EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *pctx)\n{\n    EVP_PKEY_CTX *rctx;\n    if (!pctx->pmeth || !pctx->pmeth->copy)\n        return NULL;\n#ifndef OPENSSL_NO_ENGINE\n    if (pctx->engine && !ENGINE_init(pctx->engine)) {\n        EVPerr(EVP_F_EVP_PKEY_CTX_DUP, ERR_R_ENGINE_LIB);\n        return 0;\n    }\n#endif\n    rctx = OPENSSL_malloc(sizeof(*rctx));\n    if (rctx == NULL)\n        return NULL;\n    rctx->pmeth = pctx->pmeth;\n#ifndef OPENSSL_NO_ENGINE\n    rctx->engine = pctx->engine;\n#endif\n    if (pctx->pkey)\n        EVP_PKEY_up_ref(pctx->pkey);\n    rctx->pkey = pctx->pkey;\n    if (pctx->peerkey)\n        EVP_PKEY_up_ref(pctx->peerkey);\n    rctx->peerkey = pctx->peerkey;\n    rctx->data = NULL;\n    rctx->app_data = NULL;\n    rctx->operation = pctx->operation;\n    if (pctx->pmeth->copy(rctx, pctx) > 0)\n        return rctx;\n    EVP_PKEY_CTX_free(rctx);\n    return NULL;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n        return malloc_impl(num, file, line);\n    if (num <= 0)\n        return NULL;\n    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n        ret = malloc(num);\n        CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n    } else {\n        ret = malloc(num);\n    }\n#else\n    osslargused(file); osslargused(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}', 'void EVP_PKEY_up_ref(EVP_PKEY *pkey)\n{\n    int i;\n    CRYPTO_atomic_add(&pkey->references, 1, &i, pkey->lock);\n}', 'int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock)\n{\n#ifdef __ATOMIC_RELAXED\n    *ret = __atomic_add_fetch(val, amount, __ATOMIC_RELAXED);\n#else\n    if (!CRYPTO_THREAD_write_lock(lock))\n        return 0;\n    *val += amount;\n    *ret  = *val;\n    if (!CRYPTO_THREAD_unlock(lock))\n        return 0;\n#endif\n    return 1;\n}']