int BN_set_word(BIGNUM *a, BN_ULONG w)
{
    bn_check_top(a);
    if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
        return 0;
    a->neg = 0;
    a->d[0] = w;
    a->top = (w ? 1 : 0);
    a->flags &= ~BN_FLG_FIXED_TOP;
    bn_check_top(a);
    return 1;
}
['int ec_GFp_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,\n                      BN_CTX *ctx)\n{\n    int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *,\n                      const BIGNUM *, BN_CTX *);\n    int (*field_sqr) (const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *);\n    const BIGNUM *p;\n    BN_CTX *new_ctx = NULL;\n    BIGNUM *n0, *n1, *n2, *n3;\n    int ret = 0;\n    if (EC_POINT_is_at_infinity(group, a)) {\n        BN_zero(r->Z);\n        r->Z_is_one = 0;\n        return 1;\n    }\n    field_mul = group->meth->field_mul;\n    field_sqr = group->meth->field_sqr;\n    p = group->field;\n    if (ctx == NULL) {\n        ctx = new_ctx = BN_CTX_new();\n        if (ctx == NULL)\n            return 0;\n    }\n    BN_CTX_start(ctx);\n    n0 = BN_CTX_get(ctx);\n    n1 = BN_CTX_get(ctx);\n    n2 = BN_CTX_get(ctx);\n    n3 = BN_CTX_get(ctx);\n    if (n3 == NULL)\n        goto err;\n    if (a->Z_is_one) {\n        if (!field_sqr(group, n0, a->X, ctx))\n            goto err;\n        if (!BN_mod_lshift1_quick(n1, n0, p))\n            goto err;\n        if (!BN_mod_add_quick(n0, n0, n1, p))\n            goto err;\n        if (!BN_mod_add_quick(n1, n0, group->a, p))\n            goto err;\n    } else if (group->a_is_minus3) {\n        if (!field_sqr(group, n1, a->Z, ctx))\n            goto err;\n        if (!BN_mod_add_quick(n0, a->X, n1, p))\n            goto err;\n        if (!BN_mod_sub_quick(n2, a->X, n1, p))\n            goto err;\n        if (!field_mul(group, n1, n0, n2, ctx))\n            goto err;\n        if (!BN_mod_lshift1_quick(n0, n1, p))\n            goto err;\n        if (!BN_mod_add_quick(n1, n0, n1, p))\n            goto err;\n    } else {\n        if (!field_sqr(group, n0, a->X, ctx))\n            goto err;\n        if (!BN_mod_lshift1_quick(n1, n0, p))\n            goto err;\n        if (!BN_mod_add_quick(n0, n0, n1, p))\n            goto err;\n        if (!field_sqr(group, n1, a->Z, ctx))\n            goto err;\n        if (!field_sqr(group, n1, n1, ctx))\n            goto err;\n        if (!field_mul(group, n1, n1, group->a, ctx))\n            goto err;\n        if (!BN_mod_add_quick(n1, n1, n0, p))\n            goto err;\n    }\n    if (a->Z_is_one) {\n        if (!BN_copy(n0, a->Y))\n            goto err;\n    } else {\n        if (!field_mul(group, n0, a->Y, a->Z, ctx))\n            goto err;\n    }\n    if (!BN_mod_lshift1_quick(r->Z, n0, p))\n        goto err;\n    r->Z_is_one = 0;\n    if (!field_sqr(group, n3, a->Y, ctx))\n        goto err;\n    if (!field_mul(group, n2, a->X, n3, ctx))\n        goto err;\n    if (!BN_mod_lshift_quick(n2, n2, 2, p))\n        goto err;\n    if (!BN_mod_lshift1_quick(n0, n2, p))\n        goto err;\n    if (!field_sqr(group, r->X, n1, ctx))\n        goto err;\n    if (!BN_mod_sub_quick(r->X, r->X, n0, p))\n        goto err;\n    if (!field_sqr(group, n0, n3, ctx))\n        goto err;\n    if (!BN_mod_lshift_quick(n3, n0, 3, p))\n        goto err;\n    if (!BN_mod_sub_quick(n0, n2, r->X, p))\n        goto err;\n    if (!field_mul(group, n0, n1, n0, ctx))\n        goto err;\n    if (!BN_mod_sub_quick(r->Y, n0, n3, p))\n        goto err;\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    BN_CTX_free(new_ctx);\n    return ret;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n    BIGNUM *ret;\n    CTXDBG_ENTRY("BN_CTX_get", ctx);\n    if (ctx->err_stack || ctx->too_many)\n        return NULL;\n    if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n        ctx->too_many = 1;\n        BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n        return NULL;\n    }\n    BN_zero(ret);\n    ctx->used++;\n    CTXDBG_RET(ctx, ret);\n    return ret;\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    a->flags &= ~BN_FLG_FIXED_TOP;\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}', 'int BN_mod_sub_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n                     const BIGNUM *m)\n{\n    if (!BN_sub(r, a, b))\n        return 0;\n    if (r->neg)\n        return BN_add(r, r, m);\n    return 1;\n}', 'int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n{\n    int ret, r_neg, cmp_res;\n    bn_check_top(a);\n    bn_check_top(b);\n    if (a->neg != b->neg) {\n        r_neg = a->neg;\n        ret = BN_uadd(r, a, b);\n    } else {\n        cmp_res = BN_ucmp(a, b);\n        if (cmp_res > 0) {\n            r_neg = a->neg;\n            ret = BN_usub(r, a, b);\n        } else if (cmp_res < 0) {\n            r_neg = !b->neg;\n            ret = BN_usub(r, b, a);\n        } else {\n            r_neg = 0;\n            BN_zero(r);\n            ret = 1;\n        }\n    }\n    r->neg = r_neg;\n    bn_check_top(r);\n    return ret;\n}']