static int pkey_dh_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
{
    DH *dh = NULL;
    DH_PKEY_CTX *dctx = ctx->data;
    BN_GENCB *pcb;
    int ret;
    if (dctx->rfc5114_param) {
        switch (dctx->rfc5114_param) {
        case 1:
            dh = DH_get_1024_160();
            break;
        case 2:
            dh = DH_get_2048_224();
            break;
        case 3:
            dh = DH_get_2048_256();
            break;
        default:
            return -2;
        }
        EVP_PKEY_assign(pkey, EVP_PKEY_DHX, dh);
        return 1;
    }
    if (ctx->pkey_gencb) {
        pcb = BN_GENCB_new();
        if (pcb == NULL)
            return 0;
        evp_pkey_set_cb_translate(pcb, ctx);
    } else
        pcb = NULL;
#ifndef OPENSSL_NO_DSA
    if (dctx->use_dsa) {
        DSA *dsa_dh;
        dsa_dh = dsa_dh_generate(dctx, pcb);
        BN_GENCB_free(pcb);
        if (dsa_dh == NULL)
            return 0;
        dh = DSA_dup_DH(dsa_dh);
        DSA_free(dsa_dh);
        if (!dh)
            return 0;
        EVP_PKEY_assign(pkey, EVP_PKEY_DHX, dh);
        return 1;
    }
#endif
    dh = DH_new();
    if (dh == NULL) {
        BN_GENCB_free(pcb);
        return 0;
    }
    ret = DH_generate_parameters_ex(dh,
                                    dctx->prime_len, dctx->generator, pcb);
    BN_GENCB_free(pcb);
    if (ret)
        EVP_PKEY_assign_DH(pkey, dh);
    else
        DH_free(dh);
    return ret;
}
['static int pkey_dh_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)\n{\n    DH *dh = NULL;\n    DH_PKEY_CTX *dctx = ctx->data;\n    BN_GENCB *pcb;\n    int ret;\n    if (dctx->rfc5114_param) {\n        switch (dctx->rfc5114_param) {\n        case 1:\n            dh = DH_get_1024_160();\n            break;\n        case 2:\n            dh = DH_get_2048_224();\n            break;\n        case 3:\n            dh = DH_get_2048_256();\n            break;\n        default:\n            return -2;\n        }\n        EVP_PKEY_assign(pkey, EVP_PKEY_DHX, dh);\n        return 1;\n    }\n    if (ctx->pkey_gencb) {\n        pcb = BN_GENCB_new();\n        if (pcb == NULL)\n            return 0;\n        evp_pkey_set_cb_translate(pcb, ctx);\n    } else\n        pcb = NULL;\n#ifndef OPENSSL_NO_DSA\n    if (dctx->use_dsa) {\n        DSA *dsa_dh;\n        dsa_dh = dsa_dh_generate(dctx, pcb);\n        BN_GENCB_free(pcb);\n        if (dsa_dh == NULL)\n            return 0;\n        dh = DSA_dup_DH(dsa_dh);\n        DSA_free(dsa_dh);\n        if (!dh)\n            return 0;\n        EVP_PKEY_assign(pkey, EVP_PKEY_DHX, dh);\n        return 1;\n    }\n#endif\n    dh = DH_new();\n    if (dh == NULL) {\n        BN_GENCB_free(pcb);\n        return 0;\n    }\n    ret = DH_generate_parameters_ex(dh,\n                                    dctx->prime_len, dctx->generator, pcb);\n    BN_GENCB_free(pcb);\n    if (ret)\n        EVP_PKEY_assign_DH(pkey, dh);\n    else\n        DH_free(dh);\n    return ret;\n}', 'make_dh(1024_160)', 'BIGNUM *BN_dup(const BIGNUM *a)\n{\n    BIGNUM *t;\n    if (a == NULL)\n        return NULL;\n    bn_check_top(a);\n    t = BN_get_flags(a, BN_FLG_SECURE) ? BN_secure_new() : BN_new();\n    if (t == NULL)\n        return NULL;\n    if (!BN_copy(t, a)) {\n        BN_free(t);\n        return NULL;\n    }\n    bn_check_top(t);\n    return t;\n}', 'int BN_get_flags(const BIGNUM *b, int n)\n{\n    return b->flags & n;\n}', 'BIGNUM *BN_new(void)\n{\n    BIGNUM *ret;\n    if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {\n        BNerr(BN_F_BN_NEW, ERR_R_MALLOC_FAILURE);\n        return (NULL);\n    }\n    ret->flags = BN_FLG_MALLOCED;\n    bn_check_top(ret);\n    return (ret);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\n    if (ret != NULL)\n        memset(ret, 0, num);\n    return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\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    (void)file;\n    (void)line;\n    ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n    if (ret && (num > 2048)) {\n        extern unsigned char cleanse_ctr;\n        ((unsigned char *)ret)[0] = cleanse_ctr;\n    }\n#endif\n    return ret;\n}', 'int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key)\n{\n    if (pkey == NULL || !EVP_PKEY_set_type(pkey, type))\n        return 0;\n    pkey->pkey.ptr = key;\n    return (key != NULL);\n}', 'int EVP_PKEY_set_type(EVP_PKEY *pkey, int type)\n{\n    return pkey_set_type(pkey, type, NULL, -1);\n}']