crypto/rsa/rsa_chk.c:103: error: BUFFER_OVERRUN_L3
  Offset: [4, +oo] (⇐ [0, +oo] + 4) Size: [0, 8388607] by call to `BN_mul`.
Showing all 21 steps of the trace


crypto/rsa/rsa_chk.c:82:9: Call
80.   
81.       /* q prime? */
82.       if (BN_is_prime_ex(key->q, BN_prime_checks, NULL, cb) != 1) {
              ^
83.           ret = 0;
84.           RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_Q_NOT_PRIME);

crypto/bn/bn_prime.c:182:12: Call
  180.                      BN_GENCB *cb)
  181.   {
  182.       return BN_is_prime_fasttest_ex(a, checks, ctx_passed, 0, cb);
                    ^
  183.   }
  184.   

crypto/bn/bn_prime.c:223:11: Call
    221.           goto err;
    222.   
    223.       ret = bn_miller_rabin_is_prime(w, checks, ctx, cb, 0, &status);
                     ^
    224.       if (!ret)
    225.           goto err;

crypto/bn/bn_prime.c:315:14: Call
      313.           }
      314.           /* (Step 4.5) z = b^m mod w */
      315.           if (!BN_mod_exp_mont(z, b, m, w, ctx, mont))
                          ^
      316.               goto err;
      317.           /* (Step 4.6) if (z = 1 or z = w-1) */

crypto/bn/bn_exp.c:354:14: Call
        352.   
        353.       if (a->neg || BN_ucmp(a, m) >= 0) {
        354.           if (!BN_nnmod(val[0], a, m, ctx))
                            ^
        355.               goto err;
        356.           aa = val[0];

crypto/bn/bn_mod.c:20:11: Call
          18.        */
          19.   
          20.       if (!(BN_mod(r, m, d, ctx)))
                          ^
          21.           return 0;
          22.       if (!r->neg)

crypto/bn/bn_div.c:209:1: Parameter `*dv->d`
            207.    * If 'dv' or 'rm' is NULL, the respective value is not returned.
            208.    */
            209. > int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
            210.              BN_CTX *ctx)
            211.   {

crypto/rsa/rsa_chk.c:97:10: Call
95.   
96.       /* n = p*q * r_3...r_i? */
97.       if (!BN_mul(i, key->p, key->q, ctx)) {
                ^
98.           ret = -1;
99.           goto err;

crypto/bn/bn_mul.c:497:1: Parameter `*r->d`
  495.   #endif                          /* BN_RECURSION */
  496.   
  497. > int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
  498.   {
  499.       int ret = bn_mul_fixed_top(r, a, b, ctx);

crypto/bn/bn_mul.c:499:15: Call
  497.   int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
  498.   {
  499.       int ret = bn_mul_fixed_top(r, a, b, ctx);
                       ^
  500.   
  501.       bn_correct_top(r);

crypto/bn/bn_mul.c:507:1: Parameter `*r->d`
    505.   }
    506.   
    507. > int bn_mul_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
    508.   {
    509.       int ret = 0;

crypto/rsa/rsa_chk.c:103:14: Call
101.       for (idx = 0; idx < ex_primes; idx++) {
102.           pinfo = sk_RSA_PRIME_INFO_value(key->prime_infos, idx);
103.           if (!BN_mul(i, i, pinfo->r, ctx)) {
                    ^
104.               ret = -1;
105.               goto err;

crypto/bn/bn_mul.c:497:1: Parameter `*b->d`
  495.   #endif                          /* BN_RECURSION */
  496.   
  497. > int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
  498.   {
  499.       int ret = bn_mul_fixed_top(r, a, b, ctx);

crypto/bn/bn_mul.c:499:15: Call
  497.   int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
  498.   {
  499.       int ret = bn_mul_fixed_top(r, a, b, ctx);
                       ^
  500.   
  501.       bn_correct_top(r);

crypto/bn/bn_mul.c:507:1: Parameter `*b->d`
    505.   }
    506.   
    507. > int bn_mul_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
    508.   {
    509.       int ret = 0;

crypto/bn/bn_mul.c:587:17: Call
    585.                   if (bn_wexpand(rr, k * 4) == NULL)
    586.                       goto err;
    587.                   bn_mul_part_recursive(rr->d, a->d, b->d,
                           ^
    588.                                         j, al - j, bl - j, t->d);
    589.               } else {            /* al <= j || bl <= j */

crypto/bn/bn_mul.c:322:1: Parameter `*b`
      320.    */
      321.   /* tnX may not be negative but less than n */
      322. > void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,
      323.                              int tna, int tnb, BN_ULONG *t)
      324.   {

crypto/bn/bn_mul.c:330:9: Call
      328.   
      329.       if (n < 8) {
      330.           bn_mul_normal(r, a, n + tna, b, n + tnb);
                     ^
      331.           return;
      332.       }

crypto/bn/bn_mul.c:622:1: <Length trace>
620.   }
621.   
622. > void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
623.   {
624.       BN_ULONG *rr;

crypto/bn/bn_mul.c:622:1: Parameter `*b`
        620.   }
        621.   
        622. > void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
        623.   {
        624.       BN_ULONG *rr;

crypto/bn/bn_mul.c:657:50: Array access: Offset: [4, +oo] (⇐ [0, +oo] + 4) Size: [0, 8388607] by call to `BN_mul` 
        655.           if (--nb <= 0)
        656.               return;
        657.           rr[4] = bn_mul_add_words(&(r[4]), a, na, b[4]);
                                                                ^
        658.           rr += 4;
        659.           r += 4;

void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
{
    BN_ULONG *rr;
    if (na < nb) {
        int itmp;
        BN_ULONG *ltmp;
        itmp = na;
        na = nb;
        nb = itmp;
        ltmp = a;
        a = b;
        b = ltmp;
    }
    rr = &(r[na]);
    if (nb <= 0) {
        (void)bn_mul_words(r, a, na, 0);
        return;
    } else
        rr[0] = bn_mul_words(r, a, na, b[0]);
    for (;;) {
        if (--nb <= 0)
            return;
        rr[1] = bn_mul_add_words(&(r[1]), a, na, b[1]);
        if (--nb <= 0)
            return;
        rr[2] = bn_mul_add_words(&(r[2]), a, na, b[2]);
        if (--nb <= 0)
            return;
        rr[3] = bn_mul_add_words(&(r[3]), a, na, b[3]);
        if (--nb <= 0)
            return;
        rr[4] = bn_mul_add_words(&(r[4]), a, na, b[4]);
        rr += 4;
        r += 4;
        b += 4;
    }
}
['int RSA_check_key_ex(const RSA *key, BN_GENCB *cb)\n{\n#ifdef FIPS_MODE\n    return rsa_sp800_56b_check_public(key)\n               && rsa_sp800_56b_check_private(key)\n               && rsa_sp800_56b_check_keypair(key, NULL, -1, RSA_bits(key));\n#else\n    BIGNUM *i, *j, *k, *l, *m;\n    BN_CTX *ctx;\n    int ret = 1, ex_primes = 0, idx;\n    RSA_PRIME_INFO *pinfo;\n    if (key->p == NULL || key->q == NULL || key->n == NULL\n            || key->e == NULL || key->d == NULL) {\n        RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_VALUE_MISSING);\n        return 0;\n    }\n    if (key->version == RSA_ASN1_VERSION_MULTI) {\n        ex_primes = sk_RSA_PRIME_INFO_num(key->prime_infos);\n        if (ex_primes <= 0\n                || (ex_primes + 2) > rsa_multip_cap(BN_num_bits(key->n))) {\n            RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_INVALID_MULTI_PRIME_KEY);\n            return 0;\n        }\n    }\n    i = BN_new();\n    j = BN_new();\n    k = BN_new();\n    l = BN_new();\n    m = BN_new();\n    ctx = BN_CTX_new();\n    if (i == NULL || j == NULL || k == NULL || l == NULL\n            || m == NULL || ctx == NULL) {\n        ret = -1;\n        RSAerr(RSA_F_RSA_CHECK_KEY_EX, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    if (BN_is_one(key->e)) {\n        ret = 0;\n        RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_BAD_E_VALUE);\n    }\n    if (!BN_is_odd(key->e)) {\n        ret = 0;\n        RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_BAD_E_VALUE);\n    }\n    if (BN_is_prime_ex(key->p, BN_prime_checks, NULL, cb) != 1) {\n        ret = 0;\n        RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_P_NOT_PRIME);\n    }\n    if (BN_is_prime_ex(key->q, BN_prime_checks, NULL, cb) != 1) {\n        ret = 0;\n        RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_Q_NOT_PRIME);\n    }\n    for (idx = 0; idx < ex_primes; idx++) {\n        pinfo = sk_RSA_PRIME_INFO_value(key->prime_infos, idx);\n        if (BN_is_prime_ex(pinfo->r, BN_prime_checks, NULL, cb) != 1) {\n            ret = 0;\n            RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_MP_R_NOT_PRIME);\n        }\n    }\n    if (!BN_mul(i, key->p, key->q, ctx)) {\n        ret = -1;\n        goto err;\n    }\n    for (idx = 0; idx < ex_primes; idx++) {\n        pinfo = sk_RSA_PRIME_INFO_value(key->prime_infos, idx);\n        if (!BN_mul(i, i, pinfo->r, ctx)) {\n            ret = -1;\n            goto err;\n        }\n    }\n    if (BN_cmp(i, key->n) != 0) {\n        ret = 0;\n        if (ex_primes)\n            RSAerr(RSA_F_RSA_CHECK_KEY_EX,\n                   RSA_R_N_DOES_NOT_EQUAL_PRODUCT_OF_PRIMES);\n        else\n            RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_N_DOES_NOT_EQUAL_P_Q);\n    }\n    if (!BN_sub(i, key->p, BN_value_one())) {\n        ret = -1;\n        goto err;\n    }\n    if (!BN_sub(j, key->q, BN_value_one())) {\n        ret = -1;\n        goto err;\n    }\n    if (!BN_mul(l, i, j, ctx)) {\n        ret = -1;\n        goto err;\n    }\n    if (!BN_gcd(m, i, j, ctx)) {\n        ret = -1;\n        goto err;\n    }\n    for (idx = 0; idx < ex_primes; idx++) {\n        pinfo = sk_RSA_PRIME_INFO_value(key->prime_infos, idx);\n        if (!BN_sub(k, pinfo->r, BN_value_one())) {\n            ret = -1;\n            goto err;\n        }\n        if (!BN_mul(l, l, k, ctx)) {\n            ret = -1;\n            goto err;\n        }\n        if (!BN_gcd(m, m, k, ctx)) {\n            ret = -1;\n            goto err;\n        }\n    }\n    if (!BN_div(k, NULL, l, m, ctx)) {\n        ret = -1;\n        goto err;\n    }\n    if (!BN_mod_mul(i, key->d, key->e, k, ctx)) {\n        ret = -1;\n        goto err;\n    }\n    if (!BN_is_one(i)) {\n        ret = 0;\n        RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_D_E_NOT_CONGRUENT_TO_1);\n    }\n    if (key->dmp1 != NULL && key->dmq1 != NULL && key->iqmp != NULL) {\n        if (!BN_sub(i, key->p, BN_value_one())) {\n            ret = -1;\n            goto err;\n        }\n        if (!BN_mod(j, key->d, i, ctx)) {\n            ret = -1;\n            goto err;\n        }\n        if (BN_cmp(j, key->dmp1) != 0) {\n            ret = 0;\n            RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_DMP1_NOT_CONGRUENT_TO_D);\n        }\n        if (!BN_sub(i, key->q, BN_value_one())) {\n            ret = -1;\n            goto err;\n        }\n        if (!BN_mod(j, key->d, i, ctx)) {\n            ret = -1;\n            goto err;\n        }\n        if (BN_cmp(j, key->dmq1) != 0) {\n            ret = 0;\n            RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_DMQ1_NOT_CONGRUENT_TO_D);\n        }\n        if (!BN_mod_inverse(i, key->q, key->p, ctx)) {\n            ret = -1;\n            goto err;\n        }\n        if (BN_cmp(i, key->iqmp) != 0) {\n            ret = 0;\n            RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_IQMP_NOT_INVERSE_OF_Q);\n        }\n    }\n    for (idx = 0; idx < ex_primes; idx++) {\n        pinfo = sk_RSA_PRIME_INFO_value(key->prime_infos, idx);\n        if (!BN_sub(i, pinfo->r, BN_value_one())) {\n            ret = -1;\n            goto err;\n        }\n        if (!BN_mod(j, key->d, i, ctx)) {\n            ret = -1;\n            goto err;\n        }\n        if (BN_cmp(j, pinfo->d) != 0) {\n            ret = 0;\n            RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_MP_EXPONENT_NOT_CONGRUENT_TO_D);\n        }\n        if (!BN_mod_inverse(i, pinfo->pp, pinfo->r, ctx)) {\n            ret = -1;\n            goto err;\n        }\n        if (BN_cmp(i, pinfo->t) != 0) {\n            ret = 0;\n            RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_MP_COEFFICIENT_NOT_INVERSE_OF_R);\n        }\n    }\n err:\n    BN_free(i);\n    BN_free(j);\n    BN_free(k);\n    BN_free(l);\n    BN_free(m);\n    BN_CTX_free(ctx);\n    return ret;\n#endif\n}', 'int BN_is_prime_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,\n                   BN_GENCB *cb)\n{\n    return BN_is_prime_fasttest_ex(a, checks, ctx_passed, 0, cb);\n}', 'int BN_is_prime_fasttest_ex(const BIGNUM *w, int checks, BN_CTX *ctx_passed,\n                            int do_trial_division, BN_GENCB *cb)\n{\n    int i, status, ret = -1;\n    BN_CTX *ctx = NULL;\n    if (BN_cmp(w, BN_value_one()) <= 0)\n        return 0;\n    if (BN_is_odd(w)) {\n        if (BN_is_word(w, 3))\n            return 1;\n    } else {\n        return BN_is_word(w, 2);\n    }\n    if (do_trial_division) {\n        for (i = 1; i < NUMPRIMES; i++) {\n            BN_ULONG mod = BN_mod_word(w, primes[i]);\n            if (mod == (BN_ULONG)-1)\n                return -1;\n            if (mod == 0)\n                return BN_is_word(w, primes[i]);\n        }\n        if (!BN_GENCB_call(cb, 1, -1))\n            return -1;\n    }\n    if (ctx_passed != NULL)\n        ctx = ctx_passed;\n    else if ((ctx = BN_CTX_new()) == NULL)\n        goto err;\n    ret = bn_miller_rabin_is_prime(w, checks, ctx, cb, 0, &status);\n    if (!ret)\n        goto err;\n    ret = (status == BN_PRIMETEST_PROBABLY_PRIME);\nerr:\n    if (ctx_passed == NULL)\n        BN_CTX_free(ctx);\n    return ret;\n}', 'int bn_miller_rabin_is_prime(const BIGNUM *w, int iterations, BN_CTX *ctx,\n                             BN_GENCB *cb, int enhanced, int *status)\n{\n    int i, j, a, ret = 0;\n    BIGNUM *g, *w1, *w3, *x, *m, *z, *b;\n    BN_MONT_CTX *mont = NULL;\n    if (!BN_is_odd(w))\n        return 0;\n    BN_CTX_start(ctx);\n    g = BN_CTX_get(ctx);\n    w1 = BN_CTX_get(ctx);\n    w3 = BN_CTX_get(ctx);\n    x = BN_CTX_get(ctx);\n    m = BN_CTX_get(ctx);\n    z = BN_CTX_get(ctx);\n    b = BN_CTX_get(ctx);\n    if (!(b != NULL\n            && BN_copy(w1, w)\n            && BN_sub_word(w1, 1)\n            && BN_copy(w3, w)\n            && BN_sub_word(w3, 3)))\n        goto err;\n    if (BN_is_zero(w3) || BN_is_negative(w3))\n        goto err;\n    a = 1;\n    while (!BN_is_bit_set(w1, a))\n        a++;\n    if (!BN_rshift(m, w1, a))\n        goto err;\n    mont = BN_MONT_CTX_new();\n    if (mont == NULL || !BN_MONT_CTX_set(mont, w, ctx))\n        goto err;\n    if (iterations == BN_prime_checks)\n        iterations = BN_prime_checks_for_size(BN_num_bits(w));\n    for (i = 0; i < iterations; ++i) {\n        if (!BN_priv_rand_range(b, w3) || !BN_add_word(b, 2))\n            goto err;\n        if (enhanced) {\n            if (!BN_gcd(g, b, w, ctx))\n                goto err;\n            if (!BN_is_one(g)) {\n                *status = BN_PRIMETEST_COMPOSITE_WITH_FACTOR;\n                ret = 1;\n                goto err;\n            }\n        }\n        if (!BN_mod_exp_mont(z, b, m, w, ctx, mont))\n            goto err;\n        if (BN_is_one(z) || BN_cmp(z, w1) == 0)\n            goto outer_loop;\n        for (j = 1; j < a ; ++j) {\n            if (!BN_copy(x, z) || !BN_mod_mul(z, x, x, w, ctx))\n                goto err;\n            if (BN_cmp(z, w1) == 0)\n                goto outer_loop;\n            if (BN_is_one(z))\n                goto composite;\n        }\n        if (!BN_copy(x, z) || !BN_mod_mul(z, x, x, w, ctx))\n            goto err;\n        if (BN_is_one(z))\n            goto composite;\n        if (!BN_copy(x, z))\n            goto err;\ncomposite:\n        if (enhanced) {\n            if (!BN_sub_word(x, 1) || !BN_gcd(g, x, w, ctx))\n                goto err;\n            if (BN_is_one(g))\n                *status = BN_PRIMETEST_COMPOSITE_NOT_POWER_OF_PRIME;\n            else\n                *status = BN_PRIMETEST_COMPOSITE_WITH_FACTOR;\n        } else {\n            *status = BN_PRIMETEST_COMPOSITE;\n        }\n        ret = 1;\n        goto err;\nouter_loop: ;\n        if (!BN_GENCB_call(cb, 1, i))\n            goto err;\n    }\n    *status = BN_PRIMETEST_PROBABLY_PRIME;\n    ret = 1;\nerr:\n    BN_clear(g);\n    BN_clear(w1);\n    BN_clear(w3);\n    BN_clear(x);\n    BN_clear(m);\n    BN_clear(z);\n    BN_clear(b);\n    BN_CTX_end(ctx);\n    BN_MONT_CTX_free(mont);\n    return ret;\n}', 'int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n                    const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n    int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n    int start = 1;\n    BIGNUM *d, *r;\n    const BIGNUM *aa;\n    BIGNUM *val[TABLE_SIZE];\n    BN_MONT_CTX *mont = NULL;\n    if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n            || BN_get_flags(a, BN_FLG_CONSTTIME) != 0\n            || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n        return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);\n    }\n    bn_check_top(a);\n    bn_check_top(p);\n    bn_check_top(m);\n    if (!BN_is_odd(m)) {\n        BNerr(BN_F_BN_MOD_EXP_MONT, BN_R_CALLED_WITH_EVEN_MODULUS);\n        return 0;\n    }\n    bits = BN_num_bits(p);\n    if (bits == 0) {\n        if (BN_abs_is_word(m, 1)) {\n            ret = 1;\n            BN_zero(rr);\n        } else {\n            ret = BN_one(rr);\n        }\n        return ret;\n    }\n    BN_CTX_start(ctx);\n    d = BN_CTX_get(ctx);\n    r = BN_CTX_get(ctx);\n    val[0] = BN_CTX_get(ctx);\n    if (val[0] == NULL)\n        goto err;\n    if (in_mont != NULL)\n        mont = in_mont;\n    else {\n        if ((mont = BN_MONT_CTX_new()) == NULL)\n            goto err;\n        if (!BN_MONT_CTX_set(mont, m, ctx))\n            goto err;\n    }\n    if (a->neg || BN_ucmp(a, m) >= 0) {\n        if (!BN_nnmod(val[0], a, m, ctx))\n            goto err;\n        aa = val[0];\n    } else\n        aa = a;\n    if (!bn_to_mont_fixed_top(val[0], aa, mont, ctx))\n        goto err;\n    window = BN_window_bits_for_exponent_size(bits);\n    if (window > 1) {\n        if (!bn_mul_mont_fixed_top(d, val[0], val[0], mont, ctx))\n            goto err;\n        j = 1 << (window - 1);\n        for (i = 1; i < j; i++) {\n            if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n                !bn_mul_mont_fixed_top(val[i], val[i - 1], d, mont, ctx))\n                goto err;\n        }\n    }\n    start = 1;\n    wvalue = 0;\n    wstart = bits - 1;\n    wend = 0;\n#if 1\n    j = m->top;\n    if (m->d[j - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n        if (bn_wexpand(r, j) == NULL)\n            goto err;\n        r->d[0] = (0 - m->d[0]) & BN_MASK2;\n        for (i = 1; i < j; i++)\n            r->d[i] = (~m->d[i]) & BN_MASK2;\n        r->top = j;\n        r->flags |= BN_FLG_FIXED_TOP;\n    } else\n#endif\n    if (!bn_to_mont_fixed_top(r, BN_value_one(), mont, ctx))\n        goto err;\n    for (;;) {\n        if (BN_is_bit_set(p, wstart) == 0) {\n            if (!start) {\n                if (!bn_mul_mont_fixed_top(r, r, r, mont, ctx))\n                    goto err;\n            }\n            if (wstart == 0)\n                break;\n            wstart--;\n            continue;\n        }\n        j = wstart;\n        wvalue = 1;\n        wend = 0;\n        for (i = 1; i < window; i++) {\n            if (wstart - i < 0)\n                break;\n            if (BN_is_bit_set(p, wstart - i)) {\n                wvalue <<= (i - wend);\n                wvalue |= 1;\n                wend = i;\n            }\n        }\n        j = wend + 1;\n        if (!start)\n            for (i = 0; i < j; i++) {\n                if (!bn_mul_mont_fixed_top(r, r, r, mont, ctx))\n                    goto err;\n            }\n        if (!bn_mul_mont_fixed_top(r, r, val[wvalue >> 1], mont, ctx))\n            goto err;\n        wstart -= wend + 1;\n        wvalue = 0;\n        start = 0;\n        if (wstart < 0)\n            break;\n    }\n#if defined(SPARC_T4_MONT)\n    if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n        j = mont->N.top;\n        val[0]->d[0] = 1;\n        for (i = 1; i < j; i++)\n            val[0]->d[i] = 0;\n        val[0]->top = j;\n        if (!BN_mod_mul_montgomery(rr, r, val[0], mont, ctx))\n            goto err;\n    } else\n#endif\n    if (!BN_from_montgomery(rr, r, mont, ctx))\n        goto err;\n    ret = 1;\n err:\n    if (in_mont == NULL)\n        BN_MONT_CTX_free(mont);\n    BN_CTX_end(ctx);\n    bn_check_top(rr);\n    return ret;\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n    if (!(BN_mod(r, m, d, ctx)))\n        return 0;\n    if (!r->neg)\n        return 1;\n    return (d->neg ? BN_sub : BN_add) (r, r, d);\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_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n    int ret = bn_mul_fixed_top(r, a, b, ctx);\n    bn_correct_top(r);\n    bn_check_top(r);\n    return ret;\n}', 'int bn_mul_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n    int ret = 0;\n    int top, al, bl;\n    BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n    int i;\n#endif\n#ifdef BN_RECURSION\n    BIGNUM *t = NULL;\n    int j = 0, k;\n#endif\n    bn_check_top(a);\n    bn_check_top(b);\n    bn_check_top(r);\n    al = a->top;\n    bl = b->top;\n    if ((al == 0) || (bl == 0)) {\n        BN_zero(r);\n        return 1;\n    }\n    top = al + bl;\n    BN_CTX_start(ctx);\n    if ((r == a) || (r == b)) {\n        if ((rr = BN_CTX_get(ctx)) == NULL)\n            goto err;\n    } else\n        rr = r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n    i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n    if (i == 0) {\n# if 0\n        if (al == 4) {\n            if (bn_wexpand(rr, 8) == NULL)\n                goto err;\n            rr->top = 8;\n            bn_mul_comba4(rr->d, a->d, b->d);\n            goto end;\n        }\n# endif\n        if (al == 8) {\n            if (bn_wexpand(rr, 16) == NULL)\n                goto err;\n            rr->top = 16;\n            bn_mul_comba8(rr->d, a->d, b->d);\n            goto end;\n        }\n    }\n#endif\n#ifdef BN_RECURSION\n    if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n        if (i >= -1 && i <= 1) {\n            if (i >= 0) {\n                j = BN_num_bits_word((BN_ULONG)al);\n            }\n            if (i == -1) {\n                j = BN_num_bits_word((BN_ULONG)bl);\n            }\n            j = 1 << (j - 1);\n            assert(j <= al || j <= bl);\n            k = j + j;\n            t = BN_CTX_get(ctx);\n            if (t == NULL)\n                goto err;\n            if (al > j || bl > j) {\n                if (bn_wexpand(t, k * 4) == NULL)\n                    goto err;\n                if (bn_wexpand(rr, k * 4) == NULL)\n                    goto err;\n                bn_mul_part_recursive(rr->d, a->d, b->d,\n                                      j, al - j, bl - j, t->d);\n            } else {\n                if (bn_wexpand(t, k * 2) == NULL)\n                    goto err;\n                if (bn_wexpand(rr, k * 2) == NULL)\n                    goto err;\n                bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n            }\n            rr->top = top;\n            goto end;\n        }\n    }\n#endif\n    if (bn_wexpand(rr, top) == NULL)\n        goto err;\n    rr->top = top;\n    bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n    rr->neg = a->neg ^ b->neg;\n    rr->flags |= BN_FLG_FIXED_TOP;\n    if (r != rr && BN_copy(r, rr) == NULL)\n        goto err;\n    ret = 1;\n err:\n    bn_check_top(r);\n    BN_CTX_end(ctx);\n    return ret;\n}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,\n                           int tna, int tnb, BN_ULONG *t)\n{\n    int i, j, n2 = n * 2;\n    int c1, c2, neg;\n    BN_ULONG ln, lo, *p;\n    if (n < 8) {\n        bn_mul_normal(r, a, n + tna, b, n + tnb);\n        return;\n    }\n    c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);\n    c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);\n    neg = 0;\n    switch (c1 * 3 + c2) {\n    case -4:\n        bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n        bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n        break;\n    case -3:\n    case -2:\n        bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n        bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n        neg = 1;\n        break;\n    case -1:\n    case 0:\n    case 1:\n    case 2:\n        bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n        bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n        neg = 1;\n        break;\n    case 3:\n    case 4:\n        bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n        bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n        break;\n    }\n# if 0\n    if (n == 4) {\n        bn_mul_comba4(&(t[n2]), t, &(t[n]));\n        bn_mul_comba4(r, a, b);\n        bn_mul_normal(&(r[n2]), &(a[n]), tn, &(b[n]), tn);\n        memset(&r[n2 + tn * 2], 0, sizeof(*r) * (n2 - tn * 2));\n    } else\n# endif\n    if (n == 8) {\n        bn_mul_comba8(&(t[n2]), t, &(t[n]));\n        bn_mul_comba8(r, a, b);\n        bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n        memset(&r[n2 + tna + tnb], 0, sizeof(*r) * (n2 - tna - tnb));\n    } else {\n        p = &(t[n2 * 2]);\n        bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);\n        bn_mul_recursive(r, a, b, n, 0, 0, p);\n        i = n / 2;\n        if (tna > tnb)\n            j = tna - i;\n        else\n            j = tnb - i;\n        if (j == 0) {\n            bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]),\n                             i, tna - i, tnb - i, p);\n            memset(&r[n2 + i * 2], 0, sizeof(*r) * (n2 - i * 2));\n        } else if (j > 0) {\n            bn_mul_part_recursive(&(r[n2]), &(a[n]), &(b[n]),\n                                  i, tna - i, tnb - i, p);\n            memset(&(r[n2 + tna + tnb]), 0,\n                   sizeof(BN_ULONG) * (n2 - tna - tnb));\n        } else {\n            memset(&r[n2], 0, sizeof(*r) * n2);\n            if (tna < BN_MUL_RECURSIVE_SIZE_NORMAL\n                && tnb < BN_MUL_RECURSIVE_SIZE_NORMAL) {\n                bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n            } else {\n                for (;;) {\n                    i /= 2;\n                    if (i < tna || i < tnb) {\n                        bn_mul_part_recursive(&(r[n2]),\n                                              &(a[n]), &(b[n]),\n                                              i, tna - i, tnb - i, p);\n                        break;\n                    } else if (i == tna || i == tnb) {\n                        bn_mul_recursive(&(r[n2]),\n                                         &(a[n]), &(b[n]),\n                                         i, tna - i, tnb - i, p);\n                        break;\n                    }\n                }\n            }\n        }\n    }\n    c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));\n    if (neg) {\n        c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));\n    } else {\n        c1 += (int)(bn_add_words(&(t[n2]), &(t[n2]), t, n2));\n    }\n    c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));\n    if (c1) {\n        p = &(r[n + n2]);\n        lo = *p;\n        ln = (lo + c1) & BN_MASK2;\n        *p = ln;\n        if (ln < (BN_ULONG)c1) {\n            do {\n                p++;\n                lo = *p;\n                ln = (lo + 1) & BN_MASK2;\n                *p = ln;\n            } while (ln == 0);\n        }\n    }\n}', 'void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)\n{\n    BN_ULONG *rr;\n    if (na < nb) {\n        int itmp;\n        BN_ULONG *ltmp;\n        itmp = na;\n        na = nb;\n        nb = itmp;\n        ltmp = a;\n        a = b;\n        b = ltmp;\n    }\n    rr = &(r[na]);\n    if (nb <= 0) {\n        (void)bn_mul_words(r, a, na, 0);\n        return;\n    } else\n        rr[0] = bn_mul_words(r, a, na, b[0]);\n    for (;;) {\n        if (--nb <= 0)\n            return;\n        rr[1] = bn_mul_add_words(&(r[1]), a, na, b[1]);\n        if (--nb <= 0)\n            return;\n        rr[2] = bn_mul_add_words(&(r[2]), a, na, b[2]);\n        if (--nb <= 0)\n            return;\n        rr[3] = bn_mul_add_words(&(r[3]), a, na, b[3]);\n        if (--nb <= 0)\n            return;\n        rr[4] = bn_mul_add_words(&(r[4]), a, na, b[4]);\n        rr += 4;\n        r += 4;\n        b += 4;\n    }\n}']