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;
}
['int bn_rsa_fips186_4_gen_prob_primes(BIGNUM *p, BIGNUM *Xpout,\n                                     BIGNUM *p1, BIGNUM *p2,\n                                     const BIGNUM *Xp, const BIGNUM *Xp1,\n                                     const BIGNUM *Xp2, int nlen,\n                                     const BIGNUM *e, BN_CTX *ctx, BN_GENCB *cb)\n{\n    int ret = 0;\n    BIGNUM *p1i = NULL, *p2i = NULL, *Xp1i = NULL, *Xp2i = NULL;\n    int bitlen;\n    if (p == NULL || Xpout == NULL)\n        return 0;\n    BN_CTX_start(ctx);\n    p1i = (p1 != NULL) ? p1 : BN_CTX_get(ctx);\n    p2i = (p2 != NULL) ? p2 : BN_CTX_get(ctx);\n    Xp1i = (Xp1 != NULL) ? (BIGNUM *)Xp1 : BN_CTX_get(ctx);\n    Xp2i = (Xp2 != NULL) ? (BIGNUM *)Xp2 : BN_CTX_get(ctx);\n    if (p1i == NULL || p2i == NULL || Xp1i == NULL || Xp2i == NULL)\n        goto err;\n    bitlen = bn_rsa_fips186_4_aux_prime_min_size(nlen);\n    if (bitlen == 0)\n        goto err;\n    if (Xp1 == NULL) {\n        if (!BN_priv_rand(Xp1i, bitlen, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ODD))\n            goto err;\n    }\n    if (Xp2 == NULL) {\n        if (!BN_priv_rand(Xp2i, bitlen, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ODD))\n            goto err;\n    }\n    if (!bn_rsa_fips186_4_find_aux_prob_prime(Xp1i, p1i, ctx, cb)\n            || !bn_rsa_fips186_4_find_aux_prob_prime(Xp2i, p2i, ctx, cb))\n        goto err;\n    if ((BN_num_bits(p1i) + BN_num_bits(p2i)) >=\n            bn_rsa_fips186_4_aux_prime_max_sum_size_for_prob_primes(nlen))\n        goto err;\n    if (!bn_rsa_fips186_4_derive_prime(p, Xpout, Xp, p1i, p2i, nlen, e, ctx, cb))\n        goto err;\n    ret = 1;\nerr:\n    if (p1 == NULL)\n        BN_clear(p1i);\n    if (p2 == NULL)\n        BN_clear(p2i);\n    if (Xp1 == NULL)\n        BN_clear(Xp1i);\n    if (Xp2 == NULL)\n        BN_clear(Xp2i);\n    BN_CTX_end(ctx);\n    return ret;\n}', 'static int bn_rsa_fips186_4_find_aux_prob_prime(const BIGNUM *Xp1,\n                                                BIGNUM *p1, BN_CTX *ctx,\n                                                BN_GENCB *cb)\n{\n    int ret = 0;\n    int i = 0;\n    int checks = bn_rsa_fips186_4_aux_prime_MR_min_checks(BN_num_bits(Xp1));\n    if (checks == 0 || BN_copy(p1, Xp1) == NULL)\n        return 0;\n    for(;;) {\n        i++;\n        BN_GENCB_call(cb, 0, i);\n        if (BN_is_prime_fasttest_ex(p1, checks, ctx, 1, cb))\n            break;\n        if (!BN_add_word(p1, 2))\n            goto err;\n    }\n    BN_GENCB_call(cb, 2, i);\n    ret = 1;\nerr:\n    return ret;\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n    bn_check_top(b);\n    if (a == b)\n        return a;\n    if (bn_wexpand(a, b->top) == NULL)\n        return NULL;\n    if (b->top > 0)\n        memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n    a->neg = b->neg;\n    a->top = b->top;\n    a->flags |= b->flags & BN_FLG_FIXED_TOP;\n    bn_check_top(a);\n    return a;\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}', '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    INCREMENT(malloc_count);\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    if (allow_customize) {\n        allow_customize = 0;\n    }\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    (void)(file); (void)(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}']