static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
    BN_ULONG *a = NULL;
    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 probable_prime_dh_safe(BIGNUM *p, int bits, const BIGNUM *padd,\n                                  const BIGNUM *rem, BN_CTX *ctx)\n{\n    int i, ret = 0;\n    BIGNUM *t1, *qadd, *q;\n    bits--;\n    BN_CTX_start(ctx);\n    t1 = BN_CTX_get(ctx);\n    q = BN_CTX_get(ctx);\n    qadd = BN_CTX_get(ctx);\n    if (qadd == NULL)\n        goto err;\n    if (!BN_rshift1(qadd, padd))\n        goto err;\n    if (!BN_rand(q, bits, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ODD))\n        goto err;\n    if (!BN_mod(t1, q, qadd, ctx))\n        goto err;\n    if (!BN_sub(q, q, t1))\n        goto err;\n    if (rem == NULL) {\n        if (!BN_add_word(q, 1))\n            goto err;\n    } else {\n        if (!BN_rshift1(t1, rem))\n            goto err;\n        if (!BN_add(q, q, t1))\n            goto err;\n    }\n    if (!BN_lshift1(p, q))\n        goto err;\n    if (!BN_add_word(p, 1))\n        goto err;\n loop:\n    for (i = 1; i < NUMPRIMES; i++) {\n        BN_ULONG pmod = BN_mod_word(p, (BN_ULONG)primes[i]);\n        BN_ULONG qmod = BN_mod_word(q, (BN_ULONG)primes[i]);\n        if (pmod == (BN_ULONG)-1 || qmod == (BN_ULONG)-1)\n            goto err;\n        if (pmod == 0 || qmod == 0) {\n            if (!BN_add(p, p, padd))\n                goto err;\n            if (!BN_add(q, q, qadd))\n                goto err;\n            goto loop;\n        }\n    }\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    bn_check_top(p);\n    return ret;\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n           BN_CTX *ctx)\n{\n    int ret;\n    if (BN_is_zero(divisor)) {\n        BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n        return 0;\n    }\n    if (divisor->d[divisor->top - 1] == 0) {\n        BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n        return 0;\n    }\n    ret = bn_div_fixed_top(dv, rm, num, divisor, ctx);\n    if (ret) {\n        if (dv != NULL)\n            bn_correct_top(dv);\n        if (rm != NULL)\n            bn_correct_top(rm);\n    }\n    return ret;\n}', 'int BN_rshift1(BIGNUM *r, const BIGNUM *a)\n{\n    BN_ULONG *ap, *rp, t, c;\n    int i, j;\n    bn_check_top(r);\n    bn_check_top(a);\n    if (BN_is_zero(a)) {\n        BN_zero(r);\n        return 1;\n    }\n    i = a->top;\n    ap = a->d;\n    j = i - (ap[i - 1] == 1);\n    if (a != r) {\n        if (bn_wexpand(r, j) == NULL)\n            return 0;\n        r->neg = a->neg;\n    }\n    rp = r->d;\n    t = ap[--i];\n    c = (t & 1) ? BN_TBIT : 0;\n    if (t >>= 1)\n        rp[i] = t;\n    while (i > 0) {\n        t = ap[--i];\n        rp[i] = ((t >> 1) & BN_MASK2) | c;\n        c = (t & 1) ? BN_TBIT : 0;\n    }\n    r->top = j;\n    if (!r->top)\n        r->neg = 0;\n    bn_check_top(r);\n    return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n    return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\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    return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n    BN_ULONG *a = NULL;\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}']