int BN_set_bit(BIGNUM *a, int n)
{
    int i, j, k;
    if (n < 0)
        return 0;
    i = n / BN_BITS2;
    j = n % BN_BITS2;
    if (a->top <= i) {
        if (bn_wexpand(a, i + 1) == NULL)
            return (0);
        for (k = a->top; k < i + 1; k++)
            a->d[k] = 0;
        a->top = i + 1;
    }
    a->d[i] |= (((BN_ULONG)1) << j);
    bn_check_top(a);
    return (1);
}
['static int test_gf2m_modsolvequad()\n{\n    BIGNUM *a, *b[2], *c, *d, *e;\n    int i, j, s = 0, t, st = 0;\n    int p0[] = { 163, 7, 6, 3, 0, -1 };\n    int p1[] = { 193, 15, 0, -1 };\n    a = BN_new();\n    b[0] = BN_new();\n    b[1] = BN_new();\n    c = BN_new();\n    d = BN_new();\n    e = BN_new();\n    BN_GF2m_arr2poly(p0, b[0]);\n    BN_GF2m_arr2poly(p1, b[1]);\n    for (i = 0; i < NUM0; i++) {\n        BN_bntest_rand(a, 512, 0, 0);\n        for (j = 0; j < 2; j++) {\n            t = BN_GF2m_mod_solve_quad(c, a, b[j], ctx);\n            if (t) {\n                s++;\n                BN_GF2m_mod_sqr(d, c, b[j], ctx);\n                BN_GF2m_add(d, c, d);\n                BN_GF2m_mod(e, a, b[j]);\n                BN_GF2m_add(e, e, d);\n                if (!BN_is_zero(e)) {\n                    printf("GF(2^m) modular solve quadratic test failed!\\n");\n                    goto err;\n                }\n            }\n        }\n    }\n    if (s == 0) {\n        printf("All %i tests of GF(2^m) modular solve quadratic resulted in no roots;\\n",\n                NUM0);\n        printf("this is very unlikely and probably indicates an error.\\n");\n        goto err;\n    }\n    st = 1;\n err:\n    BN_free(a);\n    BN_free(b[0]);\n    BN_free(b[1]);\n    BN_free(c);\n    BN_free(d);\n    BN_free(e);\n    return st;\n}', 'int BN_GF2m_arr2poly(const int p[], BIGNUM *a)\n{\n    int i;\n    bn_check_top(a);\n    BN_zero(a);\n    for (i = 0; p[i] != -1; i++) {\n        if (BN_set_bit(a, p[i]) == 0)\n            return 0;\n    }\n    bn_check_top(a);\n    return 1;\n}', 'int BN_set_bit(BIGNUM *a, int n)\n{\n    int i, j, k;\n    if (n < 0)\n        return 0;\n    i = n / BN_BITS2;\n    j = n % BN_BITS2;\n    if (a->top <= i) {\n        if (bn_wexpand(a, i + 1) == NULL)\n            return (0);\n        for (k = a->top; k < i + 1; k++)\n            a->d[k] = 0;\n        a->top = i + 1;\n    }\n    a->d[i] |= (((BN_ULONG)1) << j);\n    bn_check_top(a);\n    return (1);\n}']