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->neg = b->neg;
    a->top = b->top;
    a->flags |= b->flags & BN_FLG_FIXED_TOP;
    bn_check_top(a);
    return a;
}
['int ec_curve_nid_from_params(const EC_GROUP *group)\n{\n    int ret = -1, nid, len, field_type, param_len;\n    size_t i, seed_len;\n    const unsigned char *seed, *params_seed, *params;\n    unsigned char *param_bytes = NULL;\n    const EC_CURVE_DATA *data;\n    const EC_POINT *generator = NULL;\n    const EC_METHOD *meth;\n    const BIGNUM *cofactor = NULL;\n    BIGNUM *bn[NUM_BN_FIELDS] = {NULL, NULL, NULL, NULL, NULL, NULL};\n    BN_CTX *ctx = NULL;\n    meth = EC_GROUP_method_of(group);\n    if (meth == NULL)\n        return -1;\n    nid = EC_GROUP_get_curve_name(group);\n    field_type = EC_METHOD_get_field_type(meth);\n    seed_len = EC_GROUP_get_seed_len(group);\n    seed = EC_GROUP_get0_seed(group);\n    cofactor = EC_GROUP_get0_cofactor(group);\n    ctx = BN_CTX_new();\n    if (ctx == NULL)\n        return -1;\n    BN_CTX_start(ctx);\n    param_len = BN_num_bytes(group->order);\n    len = BN_num_bytes(group->field);\n    if (len > param_len)\n        param_len = len;\n    param_bytes = OPENSSL_malloc(param_len * NUM_BN_FIELDS);\n    if (param_bytes == NULL)\n        goto end;\n    for (i = 0; i < NUM_BN_FIELDS; ++i) {\n        if ((bn[i] = BN_CTX_get(ctx)) == NULL)\n            goto end;\n    }\n    if (!(EC_GROUP_get_curve(group, bn[0], bn[1], bn[2], ctx)\n        && ((generator = EC_GROUP_get0_generator(group)) != NULL)\n        && EC_POINT_get_affine_coordinates(group, generator, bn[3], bn[4], ctx)\n        && EC_GROUP_get_order(group, bn[5], ctx)))\n        goto end;\n    for (i = 0; i < NUM_BN_FIELDS; ++i) {\n        if (BN_bn2binpad(bn[i], &param_bytes[i*param_len], param_len) <= 0)\n            goto end;\n    }\n    for (i = 0; i < curve_list_length; i++) {\n        const ec_list_element curve = curve_list[i];\n        data = curve.data;\n        params_seed = (const unsigned char *)(data + 1);\n        params = params_seed + data->seed_len;\n        if (data->field_type == field_type\n            && param_len == data->param_len\n            && (nid <= 0 || nid == curve.nid)\n            && (BN_is_zero(cofactor)\n                || BN_is_word(cofactor, (const BN_ULONG)curve.data->cofactor))\n            && (data->seed_len == 0 || seed_len == 0\n                || ((size_t)data->seed_len == seed_len\n                     && memcmp(params_seed, seed, seed_len) == 0))\n            && memcmp(param_bytes, params, param_len * NUM_BN_FIELDS)\n                             == 0) {\n            ret = curve.nid;\n            goto end;\n        }\n    }\n    ret = NID_undef;\nend:\n    OPENSSL_free(param_bytes);\n    BN_CTX_end(ctx);\n    BN_CTX_free(ctx);\n    return ret;\n}', 'int BN_num_bits(const BIGNUM *a)\n{\n    int i = a->top - 1;\n    bn_check_top(a);\n    if (BN_is_zero(a))\n        return 0;\n    return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));\n}', 'int BN_is_zero(const BIGNUM *a)\n{\n    return a->top == 0;\n}', 'int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx)\n{\n    if (group->order == NULL)\n        return 0;\n    if (!BN_copy(order, group->order))\n        return 0;\n    return !BN_is_zero(order);\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->neg = b->neg;\n    a->top = b->top;\n    a->flags |= b->flags & BN_FLG_FIXED_TOP;\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}']