BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
{
    bn_check_top(b);
    if (a == b)
        return a;
    if (bn_wexpand(a, b->top) == NULL)
        return NULL;
    if (b->top > 0)
        memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);
    a->top = b->top;
    a->neg = b->neg;
    bn_check_top(a);
    return a;
}
['static int pkey_ec_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)\n{\n    EC_PKEY_CTX *dctx = ctx->data;\n    EC_GROUP *group;\n    switch (type) {\n    case EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID:\n        group = EC_GROUP_new_by_curve_name(p1);\n        if (group == NULL) {\n            ECerr(EC_F_PKEY_EC_CTRL, EC_R_INVALID_CURVE);\n            return 0;\n        }\n        EC_GROUP_free(dctx->gen_group);\n        dctx->gen_group = group;\n        return 1;\n    case EVP_PKEY_CTRL_EC_PARAM_ENC:\n        if (!dctx->gen_group) {\n            ECerr(EC_F_PKEY_EC_CTRL, EC_R_NO_PARAMETERS_SET);\n            return 0;\n        }\n        EC_GROUP_set_asn1_flag(dctx->gen_group, p1);\n        return 1;\n#ifndef OPENSSL_NO_EC\n    case EVP_PKEY_CTRL_EC_ECDH_COFACTOR:\n        if (p1 == -2) {\n            if (dctx->cofactor_mode != -1)\n                return dctx->cofactor_mode;\n            else {\n                EC_KEY *ec_key = ctx->pkey->pkey.ec;\n                return EC_KEY_get_flags(ec_key) & EC_FLAG_COFACTOR_ECDH ? 1 :\n                    0;\n            }\n        } else if (p1 < -1 || p1 > 1)\n            return -2;\n        dctx->cofactor_mode = p1;\n        if (p1 != -1) {\n            EC_KEY *ec_key = ctx->pkey->pkey.ec;\n            if (!ec_key->group)\n                return -2;\n            if (BN_is_one(ec_key->group->cofactor))\n                return 1;\n            if (!dctx->co_key) {\n                dctx->co_key = EC_KEY_dup(ec_key);\n                if (!dctx->co_key)\n                    return 0;\n            }\n            if (p1)\n                EC_KEY_set_flags(dctx->co_key, EC_FLAG_COFACTOR_ECDH);\n            else\n                EC_KEY_clear_flags(dctx->co_key, EC_FLAG_COFACTOR_ECDH);\n        } else {\n            EC_KEY_free(dctx->co_key);\n            dctx->co_key = NULL;\n        }\n        return 1;\n#endif\n    case EVP_PKEY_CTRL_EC_KDF_TYPE:\n        if (p1 == -2)\n            return dctx->kdf_type;\n        if (p1 != EVP_PKEY_ECDH_KDF_NONE && p1 != EVP_PKEY_ECDH_KDF_X9_62)\n            return -2;\n        dctx->kdf_type = p1;\n        return 1;\n    case EVP_PKEY_CTRL_EC_KDF_MD:\n        dctx->kdf_md = p2;\n        return 1;\n    case EVP_PKEY_CTRL_GET_EC_KDF_MD:\n        *(const EVP_MD **)p2 = dctx->kdf_md;\n        return 1;\n    case EVP_PKEY_CTRL_EC_KDF_OUTLEN:\n        if (p1 <= 0)\n            return -2;\n        dctx->kdf_outlen = (size_t)p1;\n        return 1;\n    case EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN:\n        *(int *)p2 = dctx->kdf_outlen;\n        return 1;\n    case EVP_PKEY_CTRL_EC_KDF_UKM:\n        OPENSSL_free(dctx->kdf_ukm);\n        dctx->kdf_ukm = p2;\n        if (p2)\n            dctx->kdf_ukmlen = p1;\n        else\n            dctx->kdf_ukmlen = 0;\n        return 1;\n    case EVP_PKEY_CTRL_GET_EC_KDF_UKM:\n        *(unsigned char **)p2 = dctx->kdf_ukm;\n        return dctx->kdf_ukmlen;\n    case EVP_PKEY_CTRL_MD:\n        if (EVP_MD_type((const EVP_MD *)p2) != NID_sha1 &&\n            EVP_MD_type((const EVP_MD *)p2) != NID_ecdsa_with_SHA1 &&\n            EVP_MD_type((const EVP_MD *)p2) != NID_sha224 &&\n            EVP_MD_type((const EVP_MD *)p2) != NID_sha256 &&\n            EVP_MD_type((const EVP_MD *)p2) != NID_sha384 &&\n            EVP_MD_type((const EVP_MD *)p2) != NID_sha512) {\n            ECerr(EC_F_PKEY_EC_CTRL, EC_R_INVALID_DIGEST_TYPE);\n            return 0;\n        }\n        dctx->md = p2;\n        return 1;\n    case EVP_PKEY_CTRL_GET_MD:\n        *(const EVP_MD **)p2 = dctx->md;\n        return 1;\n    case EVP_PKEY_CTRL_PEER_KEY:\n    case EVP_PKEY_CTRL_DIGESTINIT:\n    case EVP_PKEY_CTRL_PKCS7_SIGN:\n    case EVP_PKEY_CTRL_CMS_SIGN:\n        return 1;\n    default:\n        return -2;\n    }\n}', 'int BN_is_one(const BIGNUM *a)\n{\n    return BN_abs_is_word(a, 1) && !a->neg;\n}', 'int BN_abs_is_word(const BIGNUM *a, const BN_ULONG w)\n{\n    return ((a->top == 1) && (a->d[0] == w)) || ((w == 0) && (a->top == 0));\n}', 'EC_KEY *EC_KEY_dup(const EC_KEY *ec_key)\n{\n    EC_KEY *ret = EC_KEY_new_method(ec_key->engine);\n    if (ret == NULL)\n        return NULL;\n    if (EC_KEY_copy(ret, ec_key) == NULL) {\n        EC_KEY_free(ret);\n        return NULL;\n    }\n    return ret;\n}', 'EC_KEY *EC_KEY_copy(EC_KEY *dest, const EC_KEY *src)\n{\n    if (dest == NULL || src == NULL) {\n        ECerr(EC_F_EC_KEY_COPY, ERR_R_PASSED_NULL_PARAMETER);\n        return NULL;\n    }\n    if (src->meth != dest->meth) {\n        if (dest->meth->finish != NULL)\n            dest->meth->finish(dest);\n        if (dest->group && dest->group->meth->keyfinish)\n            dest->group->meth->keyfinish(dest);\n#ifndef OPENSSL_NO_ENGINE\n        if (ENGINE_finish(dest->engine) == 0)\n            return 0;\n        dest->engine = NULL;\n#endif\n    }\n    if (src->group != NULL) {\n        const EC_METHOD *meth = EC_GROUP_method_of(src->group);\n        EC_GROUP_free(dest->group);\n        dest->group = EC_GROUP_new(meth);\n        if (dest->group == NULL)\n            return NULL;\n        if (!EC_GROUP_copy(dest->group, src->group))\n            return NULL;\n        if (src->pub_key != NULL) {\n            EC_POINT_free(dest->pub_key);\n            dest->pub_key = EC_POINT_new(src->group);\n            if (dest->pub_key == NULL)\n                return NULL;\n            if (!EC_POINT_copy(dest->pub_key, src->pub_key))\n                return NULL;\n        }\n        if (src->priv_key != NULL) {\n            if (dest->priv_key == NULL) {\n                dest->priv_key = BN_new();\n                if (dest->priv_key == NULL)\n                    return NULL;\n            }\n            if (!BN_copy(dest->priv_key, src->priv_key))\n                return NULL;\n            if (src->group->meth->keycopy\n                && src->group->meth->keycopy(dest, src) == 0)\n                return NULL;\n        }\n    }\n    dest->enc_flag = src->enc_flag;\n    dest->conv_form = src->conv_form;\n    dest->version = src->version;\n    dest->flags = src->flags;\n    if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_EC_KEY,\n                            &dest->ex_data, &src->ex_data))\n        return NULL;\n    if (src->meth != dest->meth) {\n#ifndef OPENSSL_NO_ENGINE\n        if (src->engine != NULL && ENGINE_init(src->engine) == 0)\n            return NULL;\n        dest->engine = src->engine;\n#endif\n        dest->meth = src->meth;\n    }\n    if (src->meth->copy != NULL && src->meth->copy(dest, src) == 0)\n        return NULL;\n    return dest;\n}', 'int EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src)\n{\n    if (dest->meth->group_copy == 0) {\n        ECerr(EC_F_EC_GROUP_COPY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n        return 0;\n    }\n    if (dest->meth != src->meth) {\n        ECerr(EC_F_EC_GROUP_COPY, EC_R_INCOMPATIBLE_OBJECTS);\n        return 0;\n    }\n    if (dest == src)\n        return 1;\n    dest->pre_comp_type = src->pre_comp_type;\n    switch (src->pre_comp_type) {\n    case PCT_none:\n        dest->pre_comp.ec = NULL;\n        break;\n    case PCT_nistz256:\n#ifdef ECP_NISTZ256_ASM\n        dest->pre_comp.nistz256 = EC_nistz256_pre_comp_dup(src->pre_comp.nistz256);\n#endif\n        break;\n#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128\n    case PCT_nistp224:\n        dest->pre_comp.nistp224 = EC_nistp224_pre_comp_dup(src->pre_comp.nistp224);\n        break;\n    case PCT_nistp256:\n        dest->pre_comp.nistp256 = EC_nistp256_pre_comp_dup(src->pre_comp.nistp256);\n        break;\n    case PCT_nistp521:\n        dest->pre_comp.nistp521 = EC_nistp521_pre_comp_dup(src->pre_comp.nistp521);\n        break;\n#else\n    case PCT_nistp224:\n    case PCT_nistp256:\n    case PCT_nistp521:\n        break;\n#endif\n    case PCT_ec:\n        dest->pre_comp.ec = EC_ec_pre_comp_dup(src->pre_comp.ec);\n        break;\n    }\n    if (src->mont_data != NULL) {\n        if (dest->mont_data == NULL) {\n            dest->mont_data = BN_MONT_CTX_new();\n            if (dest->mont_data == NULL)\n                return 0;\n        }\n        if (!BN_MONT_CTX_copy(dest->mont_data, src->mont_data))\n            return 0;\n    } else {\n        BN_MONT_CTX_free(dest->mont_data);\n        dest->mont_data = NULL;\n    }\n    if (src->generator != NULL) {\n        if (dest->generator == NULL) {\n            dest->generator = EC_POINT_new(dest);\n            if (dest->generator == NULL)\n                return 0;\n        }\n        if (!EC_POINT_copy(dest->generator, src->generator))\n            return 0;\n    } else {\n        EC_POINT_clear_free(dest->generator);\n        dest->generator = NULL;\n    }\n    if ((src->meth->flags & EC_FLAGS_CUSTOM_CURVE) == 0) {\n        if (!BN_copy(dest->order, src->order))\n            return 0;\n        if (!BN_copy(dest->cofactor, src->cofactor))\n            return 0;\n    }\n    dest->curve_name = src->curve_name;\n    dest->asn1_flag = src->asn1_flag;\n    dest->asn1_form = src->asn1_form;\n    if (src->seed) {\n        OPENSSL_free(dest->seed);\n        dest->seed = OPENSSL_malloc(src->seed_len);\n        if (dest->seed == NULL)\n            return 0;\n        if (!memcpy(dest->seed, src->seed, src->seed_len))\n            return 0;\n        dest->seed_len = src->seed_len;\n    } else {\n        OPENSSL_free(dest->seed);\n        dest->seed = NULL;\n        dest->seed_len = 0;\n    }\n    return dest->meth->group_copy(dest, src);\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n    bn_check_top(b);\n    if (a == b)\n        return a;\n    if (bn_wexpand(a, b->top) == NULL)\n        return NULL;\n    if (b->top > 0)\n        memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n    a->top = b->top;\n    a->neg = b->neg;\n    bn_check_top(a);\n    return a;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n    return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']