static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
    BN_ULONG *a = NULL;
    bn_check_top(b);
    if (words > (INT_MAX / (4 * BN_BITS2))) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
        return NULL;
    }
    if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
        return (NULL);
    }
    if (BN_get_flags(b, BN_FLG_SECURE))
        a = OPENSSL_secure_zalloc(words * sizeof(*a));
    else
        a = OPENSSL_zalloc(words * sizeof(*a));
    if (a == NULL) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
        return (NULL);
    }
    assert(b->top <= words);
    if (b->top > 0)
        memcpy(a, b->d, sizeof(*a) * b->top);
    return a;
}
['static int char2_curve_test(int n)\n{\n    int r = 0;\n    BN_CTX *ctx = NULL;\n    BIGNUM *p = NULL, *a = NULL, *b = NULL;\n    BIGNUM *x = NULL, *y = NULL, *z = NULL, *cof = NULL, *yplusone = NULL;\n    EC_GROUP *group = NULL, *variable = NULL;\n    EC_POINT *P = NULL, *Q = NULL, *R = NULL;\n    const EC_POINT *points[3];\n    const BIGNUM *scalars[3];\n    struct c2_curve_test *const test = char2_curve_tests + n;\n    if (!TEST_ptr(ctx = BN_CTX_new())\n        || !TEST_ptr(p = BN_new())\n        || !TEST_ptr(a = BN_new())\n        || !TEST_ptr(b = BN_new())\n        || !TEST_ptr(x = BN_new())\n        || !TEST_ptr(y = BN_new())\n        || !TEST_ptr(z = BN_new())\n        || !TEST_ptr(yplusone = BN_new())\n        || !TEST_true(BN_hex2bn(&p, test->p))\n        || !TEST_true(BN_hex2bn(&a, test->a))\n        || !TEST_true(BN_hex2bn(&b, test->b))\n        || !TEST_true(group = EC_GROUP_new(EC_GF2m_simple_method()))\n        || !TEST_true(EC_GROUP_set_curve_GF2m(group, p, a, b, ctx))\n        || !TEST_ptr(P = EC_POINT_new(group))\n        || !TEST_ptr(Q = EC_POINT_new(group))\n        || !TEST_ptr(R = EC_POINT_new(group))\n        || !TEST_true(BN_hex2bn(&x, test->x))\n        || !TEST_true(BN_hex2bn(&y, test->y))\n        || !TEST_true(BN_add(yplusone, y, BN_value_one())))\n        goto err;\n# ifdef OPENSSL_EC_BIN_PT_COMP\n    if (!TEST_false(EC_POINT_set_affine_coordinates_GF2m(group, P, x, yplusone,\n                                                         ctx))\n        || !TEST_true(EC_POINT_set_compressed_coordinates_GF2m(group, P, x,\n                                                               test->y_bit,\n                                                               ctx))\n        || !TEST_int_gt(EC_POINT_is_on_curve(group, P, ctx), 0)\n        || !TEST_true(BN_hex2bn(&z, test->order))\n        || !TEST_true(BN_hex2bn(&cof, test->cof))\n        || !TEST_true(EC_GROUP_set_generator(group, P, z, cof))\n        || !TEST_true(EC_POINT_get_affine_coordinates_GF2m(group, P, x, y,\n                                                           ctx)))\n        goto err;\n    BIO_printf(bio_out, "\\n%s -- Generator:\\n     x = 0x", test->name);\n    BN_print(bio_out, x);\n    BIO_printf(bio_out, "\\n     y = 0x");\n    BN_print(bio_out, y);\n    BIO_printf(bio_out, "\\n");\n    if (!TEST_true(BN_hex2bn(&z, test->y))\n        || !TEST_int_eq(0, BN_cmp(y, z)))\n        goto err;\n# else\n    if (!TEST_false(EC_POINT_set_affine_coordinates_GF2m(group, P, x, yplusone,\n                    ctx))\n        || !TEST_true(EC_POINT_set_affine_coordinates_GF2m(group, P, x, y, ctx))\n        || !TEST_int_gt(EC_POINT_is_on_curve(group, P, ctx), 0)\n        || !TEST_true(BN_hex2bn(&z, test->order))\n        || !TEST_true(BN_hex2bn(&cof, test->cof))\n        || !TEST_true(EC_GROUP_set_generator(group, P, z, cof)))\n        goto err;\n    BIO_printf(bio_out, "\\n%s -- Generator:\\n     x = 0x", test->name); \\\n    BN_print(bio_out, x); \\\n    BIO_printf(bio_out, "\\n     y = 0x"); \\\n    BN_print(bio_out, y); \\\n    BIO_printf(bio_out, "\\n");\n# endif\n    if (!TEST_int_eq(EC_GROUP_get_degree(group), test->degree)\n        || !group_order_tests(group)\n        || !TEST_ptr(variable = EC_GROUP_new(EC_GROUP_method_of(group)))\n        || !TEST_true(EC_GROUP_copy(variable, group)))\n        goto err;\n    if (n == OSSL_NELEM(char2_curve_tests) - 1) {\n        if (!TEST_true(EC_POINT_set_affine_coordinates_GF2m(group, P, x, y,\n                                                                ctx))\n            || !TEST_true(EC_POINT_copy(Q, P))\n            || !TEST_false(EC_POINT_is_at_infinity(group, Q))\n            || !TEST_true(EC_POINT_dbl(group, P, P, ctx))\n            || !TEST_int_gt(EC_POINT_is_on_curve(group, P, ctx), 0)\n            || !TEST_true(EC_POINT_invert(group, Q, ctx))\n            || !TEST_true(EC_POINT_add(group, R, P, Q, ctx))\n            || !TEST_true(EC_POINT_add(group, R, R, Q, ctx))\n            || !TEST_true(EC_POINT_is_at_infinity(group, R))\n            || !TEST_false(EC_POINT_is_at_infinity(group, Q)))\n            goto err;\n        points[0] = Q;\n        points[1] = Q;\n        points[2] = Q;\n        if (!TEST_true(BN_add(y, z, BN_value_one()))\n            || !TEST_false(BN_is_odd(y))\n            || !TEST_true(BN_rshift1(y, y)))\n            goto err;\n        scalars[0] = y;\n        scalars[1] = y;\n        BIO_printf(bio_out, "combined multiplication ...");\n        if (!TEST_true(EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx))\n            || !TEST_true(EC_POINTs_mul(group, R, z, 2, points, scalars, ctx))\n            || !TEST_int_eq(0, EC_POINT_cmp(group, P, R, ctx))\n            || !TEST_int_eq(0, EC_POINT_cmp(group, R, Q, ctx)))\n            goto err;\n        if (!TEST_true(BN_pseudo_rand(y, BN_num_bits(y), 0, 0))\n            || !TEST_true(BN_add(z, z, y)))\n            goto err;\n        BN_set_negative(z, 1);\n        scalars[0] = y;\n        scalars[1] = z;\n        if (!TEST_true(EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx))\n            || !TEST_true(EC_POINT_is_at_infinity(group, P)))\n            goto err;\n        if (!TEST_true(BN_pseudo_rand(x, BN_num_bits(y) - 1, 0, 0))\n            || !TEST_true(BN_add(z, x, y)))\n            goto err;\n        BN_set_negative(z, 1);\n        scalars[0] = x;\n        scalars[1] = y;\n        scalars[2] = z;\n        if (!TEST_true(EC_POINTs_mul(group, P, NULL, 3, points, scalars, ctx))\n            || !TEST_true(EC_POINT_is_at_infinity(group, P)))\n            goto err;;\n    }\n    r = 1;\nerr:\n    BN_CTX_free(ctx);\n    BN_free(p);\n    BN_free(a);\n    BN_free(b);\n    BN_free(x);\n    BN_free(y);\n    BN_free(z);\n    BN_free(yplusone);\n    BN_free(cof);\n    EC_POINT_free(P);\n    EC_POINT_free(Q);\n    EC_POINT_free(R);\n    EC_GROUP_free(group);\n    EC_GROUP_free(variable);\n    return r;\n}', "int BN_hex2bn(BIGNUM **bn, const char *a)\n{\n    BIGNUM *ret = NULL;\n    BN_ULONG l = 0;\n    int neg = 0, h, m, i, j, k, c;\n    int num;\n    if ((a == NULL) || (*a == '\\0'))\n        return (0);\n    if (*a == '-') {\n        neg = 1;\n        a++;\n    }\n    for (i = 0; i <= (INT_MAX/4) && isxdigit((unsigned char)a[i]); i++)\n        continue;\n    if (i == 0 || i > INT_MAX/4)\n        goto err;\n    num = i + neg;\n    if (bn == NULL)\n        return (num);\n    if (*bn == NULL) {\n        if ((ret = BN_new()) == NULL)\n            return (0);\n    } else {\n        ret = *bn;\n        BN_zero(ret);\n    }\n    if (bn_expand(ret, i * 4) == NULL)\n        goto err;\n    j = i;\n    m = 0;\n    h = 0;\n    while (j > 0) {\n        m = ((BN_BYTES * 2) <= j) ? (BN_BYTES * 2) : j;\n        l = 0;\n        for (;;) {\n            c = a[j - m];\n            k = OPENSSL_hexchar2int(c);\n            if (k < 0)\n                k = 0;\n            l = (l << 4) | k;\n            if (--m <= 0) {\n                ret->d[h++] = l;\n                break;\n            }\n        }\n        j -= (BN_BYTES * 2);\n    }\n    ret->top = h;\n    bn_correct_top(ret);\n    *bn = ret;\n    bn_check_top(ret);\n    if (ret->top != 0)\n        ret->neg = neg;\n    return (num);\n err:\n    if (*bn == NULL)\n        BN_free(ret);\n    return (0);\n}", 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n    bn_check_top(a);\n    if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n        return (0);\n    a->neg = 0;\n    a->d[0] = w;\n    a->top = (w ? 1 : 0);\n    bn_check_top(a);\n    return (1);\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n    if (bits > (INT_MAX - BN_BITS2 + 1))\n        return NULL;\n    if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n        return a;\n    return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n    bn_check_top(b);\n    if (words > b->dmax) {\n        BN_ULONG *a = bn_expand_internal(b, words);\n        if (!a)\n            return NULL;\n        if (b->d) {\n            OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n            bn_free_d(b);\n        }\n        b->d = a;\n        b->dmax = words;\n    }\n    bn_check_top(b);\n    return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n    BN_ULONG *a = NULL;\n    bn_check_top(b);\n    if (words > (INT_MAX / (4 * BN_BITS2))) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n        return NULL;\n    }\n    if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n        return (NULL);\n    }\n    if (BN_get_flags(b, BN_FLG_SECURE))\n        a = OPENSSL_secure_zalloc(words * sizeof(*a));\n    else\n        a = OPENSSL_zalloc(words * sizeof(*a));\n    if (a == NULL) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n        return (NULL);\n    }\n    assert(b->top <= words);\n    if (b->top > 0)\n        memcpy(a, b->d, sizeof(*a) * b->top);\n    return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\n    FAILTEST();\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 (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n        return malloc_impl(num, file, line);\n    if (num == 0)\n        return NULL;\n    FAILTEST();\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}']