int BN_sub_word(BIGNUM *a, BN_ULONG w)
{
    int i;
    bn_check_top(a);
    w &= BN_MASK2;
    if (!w)
        return 1;
    if (BN_is_zero(a)) {
        i = BN_set_word(a, w);
        if (i != 0)
            BN_set_negative(a, 1);
        return i;
    }
    if (a->neg) {
        a->neg = 0;
        i = BN_add_word(a, w);
        a->neg = 1;
        return (i);
    }
    if ((a->top == 1) && (a->d[0] < w)) {
        a->d[0] = w - a->d[0];
        a->neg = 1;
        return (1);
    }
    i = 0;
    for (;;) {
        if (a->d[i] >= w) {
            a->d[i] -= w;
            break;
        } else {
            a->d[i] = (a->d[i] - w) & BN_MASK2;
            i++;
            w = 1;
        }
    }
    if ((a->d[i] == 0) && (i == (a->top - 1)))
        a->top--;
    bn_check_top(a);
    return (1);
}
['int DH_check_params(const DH *dh, int *ret)\n{\n    int ok = 0;\n    BIGNUM *tmp = NULL;\n    BN_CTX *ctx = NULL;\n    *ret = 0;\n    ctx = BN_CTX_new();\n    if (ctx == NULL)\n        goto err;\n    BN_CTX_start(ctx);\n    tmp = BN_CTX_get(ctx);\n    if (tmp == NULL)\n        goto err;\n    if (!BN_is_odd(dh->p))\n        *ret |= DH_CHECK_P_NOT_PRIME;\n    if (BN_is_negative(dh->g) || BN_is_zero(dh->g) || BN_is_one(dh->g))\n        *ret |= DH_NOT_SUITABLE_GENERATOR;\n    if (BN_copy(tmp, dh->p) == NULL || !BN_sub_word(tmp, 1))\n        goto err;\n    if (BN_cmp(dh->g, tmp) >= 0)\n        *ret |= DH_NOT_SUITABLE_GENERATOR;\n    ok = 1;\n err:\n    if (ctx != NULL) {\n        BN_CTX_end(ctx);\n        BN_CTX_free(ctx);\n    }\n    return (ok);\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    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_sub_word(BIGNUM *a, BN_ULONG w)\n{\n    int i;\n    bn_check_top(a);\n    w &= BN_MASK2;\n    if (!w)\n        return 1;\n    if (BN_is_zero(a)) {\n        i = BN_set_word(a, w);\n        if (i != 0)\n            BN_set_negative(a, 1);\n        return i;\n    }\n    if (a->neg) {\n        a->neg = 0;\n        i = BN_add_word(a, w);\n        a->neg = 1;\n        return (i);\n    }\n    if ((a->top == 1) && (a->d[0] < w)) {\n        a->d[0] = w - a->d[0];\n        a->neg = 1;\n        return (1);\n    }\n    i = 0;\n    for (;;) {\n        if (a->d[i] >= w) {\n            a->d[i] -= w;\n            break;\n        } else {\n            a->d[i] = (a->d[i] - w) & BN_MASK2;\n            i++;\n            w = 1;\n        }\n    }\n    if ((a->d[i] == 0) && (i == (a->top - 1)))\n        a->top--;\n    bn_check_top(a);\n    return (1);\n}']