crypto/rsa/rsa_sp800_56b_check.c:377: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - 1):unsigned32 by call to `rsa_check_crt_components`.
Showing all 25 steps of the trace


crypto/rsa/rsa_sp800_56b_check.c:372:14: Call
370.       /* (Step 5): check prime factors p & q */
371.       ret = rsa_check_prime_factor(rsa->p, rsa->e, nbits, ctx)
372.             && rsa_check_prime_factor(rsa->q, rsa->e, nbits, ctx)
                    ^
373.             && (rsa_check_pminusq_diff(r, rsa->p, rsa->q, nbits) > 0)
374.             /* (Step 6): Check the private exponent d */

crypto/rsa/rsa_sp800_56b_check.c:131:9: Call
  129.   
  130.       /* (Steps 5 a-b) prime test */
  131.       if (BN_is_prime_fasttest_ex(p, checks, ctx, 1, NULL) != 1
                 ^
  132.               /* (Step 5c) (√2)(2^(nbits/2 - 1) <= p <= 2^(nbits/2 - 1) */
  133.               || rsa_check_prime_factor_range(p, nbits, ctx) != 1)

crypto/bn/bn_prime.c:190:1: Parameter `ctx_passed->stack.depth`
    188.   
    189.   /* See FIPS 186-4 C.3.1 Miller Rabin Probabilistic Primality Test. */
    190. > int BN_is_prime_fasttest_ex(const BIGNUM *w, int checks, BN_CTX *ctx_passed,
    191.                               int do_trial_division, BN_GENCB *cb)
    192.   {

crypto/rsa/rsa_sp800_56b_check.c:375:14: Call
373.             && (rsa_check_pminusq_diff(r, rsa->p, rsa->q, nbits) > 0)
374.             /* (Step 6): Check the private exponent d */
375.             && rsa_check_private_exponent(rsa, nbits, ctx)
                    ^
376.             /* 6.4.1.2.3 (Step 7): Check the CRT components */
377.             && rsa_check_crt_components(rsa, ctx);

crypto/rsa/rsa_sp800_56b_check.c:157:1: Parameter `ctx->stack.depth`
  155.    *     (Step 6b) 1 = (d*e) mod LCM(p–1, q–1)
  156.    */
  157. > int rsa_check_private_exponent(const RSA *rsa, int nbits, BN_CTX *ctx)
  158.   {
  159.       int ret;

crypto/rsa/rsa_sp800_56b_check.c:377:14: Call
375.             && rsa_check_private_exponent(rsa, nbits, ctx)
376.             /* 6.4.1.2.3 (Step 7): Check the CRT components */
377.             && rsa_check_crt_components(rsa, ctx);
                    ^
378.       if (ret != 1)
379.           RSAerr(RSA_F_RSA_SP800_56B_CHECK_KEYPAIR, RSA_R_INVALID_KEYPAIR);

crypto/rsa/rsa_sp800_56b_check.c:24:1: Parameter `ctx->stack.depth`
  22.    *   6.4.1.3.3: rsakpv2-crt Step 7
  23.    */
  24. > int rsa_check_crt_components(const RSA *rsa, BN_CTX *ctx)
  25.   {
  26.       int ret = 0;

crypto/rsa/rsa_sp800_56b_check.c:36:5: Call
  34.       }
  35.   
  36.       BN_CTX_start(ctx);
            ^
  37.       r = BN_CTX_get(ctx);
  38.       p1 = BN_CTX_get(ctx);

crypto/bn/bn_ctx.c:190:1: Parameter `ctx->stack.depth`
    188.   }
    189.   
    190. > void BN_CTX_start(BN_CTX *ctx)
    191.   {
    192.       CTXDBG("ENTER BN_CTX_start()", ctx);

crypto/rsa/rsa_sp800_56b_check.c:57:14: Call
  55.             && (BN_cmp(rsa->iqmp, rsa->p) < 0)
  56.             /* (d) 1 = (dP . e) mod (p - 1)*/
  57.             && BN_mod_mul(r, rsa->dmp1, rsa->e, p1, ctx)
                     ^
  58.             && BN_is_one(r)
  59.             /* (e) 1 = (dQ . e) mod (q - 1) */

crypto/bn/bn_mod.c:193:1: Parameter `ctx->stack.depth`
    191.   
    192.   /* slow but works */
    193. > int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,
    194.                  BN_CTX *ctx)
    195.   {

crypto/bn/bn_mod.c:203:5: Call
    201.       bn_check_top(m);
    202.   
    203.       BN_CTX_start(ctx);
               ^
    204.       if ((t = BN_CTX_get(ctx)) == NULL)
    205.           goto err;

crypto/bn/bn_ctx.c:190:1: Parameter `ctx->stack.depth`
      188.   }
      189.   
      190. > void BN_CTX_start(BN_CTX *ctx)
      191.   {
      192.       CTXDBG("ENTER BN_CTX_start()", ctx);

crypto/bn/bn_mod.c:207:14: Call
    205.           goto err;
    206.       if (a == b) {
    207.           if (!BN_sqr(t, a, ctx))
                        ^
    208.               goto err;
    209.       } else {

crypto/bn/bn_sqr.c:17:1: Parameter `ctx->stack.depth`
      15.    * I've just gone over this and it is now %20 faster on x86 - eay - 27 Jun 96
      16.    */
      17. > int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
      18.   {
      19.       int ret = bn_sqr_fixed_top(r, a, ctx);

crypto/bn/bn_sqr.c:19:15: Call
      17.   int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
      18.   {
      19.       int ret = bn_sqr_fixed_top(r, a, ctx);
                          ^
      20.   
      21.       bn_correct_top(r);

crypto/bn/bn_sqr.c:27:1: Parameter `ctx->stack.depth`
        25.   }
        26.   
        27. > int bn_sqr_fixed_top(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
        28.   {
        29.       int max, al;

crypto/bn/bn_sqr.c:42:5: Call
        40.       }
        41.   
        42.       BN_CTX_start(ctx);
                  ^
        43.       rr = (a != r) ? r : BN_CTX_get(ctx);
        44.       tmp = BN_CTX_get(ctx);

crypto/bn/bn_ctx.c:190:1: Parameter `ctx->stack.depth`
          188.   }
          189.   
          190. > void BN_CTX_start(BN_CTX *ctx)
          191.   {
          192.       CTXDBG("ENTER BN_CTX_start()", ctx);

crypto/bn/bn_sqr.c:104:5: Call
        102.       bn_check_top(rr);
        103.       bn_check_top(tmp);
        104.       BN_CTX_end(ctx);
                   ^
        105.       return ret;
        106.   }

crypto/bn/bn_ctx.c:204:1: Parameter `ctx->stack.depth`
          202.   }
          203.   
          204. > void BN_CTX_end(BN_CTX *ctx)
          205.   {
          206.       if (ctx == NULL)

crypto/bn/bn_ctx.c:212:27: Call
          210.           ctx->err_stack--;
          211.       else {
          212.           unsigned int fp = BN_STACK_pop(&ctx->stack);
                                           ^
          213.           /* Does this stack frame have anything to release? */
          214.           if (fp < ctx->used)

crypto/bn/bn_ctx.c:294:1: <LHS trace>
292.   }
293.   
294. > static unsigned int BN_STACK_pop(BN_STACK *st)
295.   {
296.       return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:294:1: Parameter `st->depth`
            292.   }
            293.   
            294. > static unsigned int BN_STACK_pop(BN_STACK *st)
            295.   {
            296.       return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:296:12: Binary operation: ([0, +oo] - 1):unsigned32 by call to `rsa_check_crt_components` 
            294.   static unsigned int BN_STACK_pop(BN_STACK *st)
            295.   {
            296.       return st->indexes[--(st->depth)];
                              ^
            297.   }
            298.   

static unsigned int BN_STACK_pop(BN_STACK *st)
{
    return st->indexes[--(st->depth)];
}
['int rsa_sp800_56b_check_keypair(const RSA *rsa, const BIGNUM *efixed,\n                                int strength, int nbits)\n{\n    int ret = 0;\n    BN_CTX *ctx = NULL;\n    BIGNUM *r = NULL;\n    if (rsa->p == NULL\n            || rsa->q == NULL\n            || rsa->e == NULL\n            || rsa->d == NULL\n            || rsa->n == NULL) {\n        RSAerr(RSA_F_RSA_SP800_56B_CHECK_KEYPAIR, RSA_R_INVALID_REQUEST);\n        return 0;\n    }\n    if (!rsa_sp800_56b_validate_strength(nbits, strength))\n        return 0;\n    if (efixed != NULL) {\n        if (BN_cmp(efixed, rsa->e) != 0) {\n            RSAerr(RSA_F_RSA_SP800_56B_CHECK_KEYPAIR, RSA_R_INVALID_REQUEST);\n            return 0;\n        }\n    }\n    if (!rsa_check_public_exponent(rsa->e)) {\n        RSAerr(RSA_F_RSA_SP800_56B_CHECK_KEYPAIR,\n               RSA_R_PUB_EXPONENT_OUT_OF_RANGE);\n        return 0;\n    }\n    if (nbits != BN_num_bits(rsa->n)) {\n        RSAerr(RSA_F_RSA_SP800_56B_CHECK_KEYPAIR, RSA_R_INVALID_KEYPAIR);\n        return 0;\n    }\n    ctx = BN_CTX_new();\n    if (ctx == NULL)\n        return 0;\n    BN_CTX_start(ctx);\n    r = BN_CTX_get(ctx);\n    if (r == NULL || !BN_mul(r, rsa->p, rsa->q, ctx))\n        goto err;\n    if (BN_cmp(rsa->n, r) != 0) {\n        RSAerr(RSA_F_RSA_SP800_56B_CHECK_KEYPAIR, RSA_R_INVALID_REQUEST);\n        goto err;\n    }\n    ret = rsa_check_prime_factor(rsa->p, rsa->e, nbits, ctx)\n          && rsa_check_prime_factor(rsa->q, rsa->e, nbits, ctx)\n          && (rsa_check_pminusq_diff(r, rsa->p, rsa->q, nbits) > 0)\n          && rsa_check_private_exponent(rsa, nbits, ctx)\n          && rsa_check_crt_components(rsa, ctx);\n    if (ret != 1)\n        RSAerr(RSA_F_RSA_SP800_56B_CHECK_KEYPAIR, RSA_R_INVALID_KEYPAIR);\nerr:\n    BN_clear(r);\n    BN_CTX_end(ctx);\n    BN_CTX_free(ctx);\n    return ret;\n}', 'int rsa_check_prime_factor(BIGNUM *p, BIGNUM *e, int nbits, BN_CTX *ctx)\n{\n    int checks = bn_rsa_fips186_4_prime_MR_min_checks(nbits);\n    int ret = 0;\n    BIGNUM *p1 = NULL, *gcd = NULL;\n    if (BN_is_prime_fasttest_ex(p, checks, ctx, 1, NULL) != 1\n            || rsa_check_prime_factor_range(p, nbits, ctx) != 1)\n        return 0;\n    BN_CTX_start(ctx);\n    p1 = BN_CTX_get(ctx);\n    gcd = BN_CTX_get(ctx);\n    ret = (gcd != NULL)\n          && (BN_copy(p1, p) != NULL)\n          && BN_sub_word(p1, 1)\n          && BN_gcd(gcd, p1, e, ctx)\n          && BN_is_one(gcd);\n    BN_clear(p1);\n    BN_CTX_end(ctx);\n    return ret;\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 rsa_check_private_exponent(const RSA *rsa, int nbits, BN_CTX *ctx)\n{\n    int ret;\n    BIGNUM *r, *p1, *q1, *lcm, *p1q1, *gcd;\n    if (BN_num_bits(rsa->d) <= (nbits >> 1))\n        return 0;\n    BN_CTX_start(ctx);\n    r = BN_CTX_get(ctx);\n    p1 = BN_CTX_get(ctx);\n    q1 = BN_CTX_get(ctx);\n    lcm = BN_CTX_get(ctx);\n    p1q1 = BN_CTX_get(ctx);\n    gcd = BN_CTX_get(ctx);\n    ret = (gcd != NULL\n          && (rsa_get_lcm(ctx, rsa->p, rsa->q, lcm, gcd, p1, q1, p1q1) == 1)\n          && (BN_cmp(rsa->d, lcm) < 0)\n          && BN_mod_mul(r, rsa->e, rsa->d, lcm, ctx)\n          && BN_is_one(r));\n    BN_clear(p1);\n    BN_clear(q1);\n    BN_clear(lcm);\n    BN_clear(gcd);\n    BN_CTX_end(ctx);\n    return ret;\n}', 'int rsa_check_crt_components(const RSA *rsa, BN_CTX *ctx)\n{\n    int ret = 0;\n    BIGNUM *r = NULL, *p1 = NULL, *q1 = NULL;\n    if (rsa->dmp1 == NULL || rsa->dmq1 == NULL || rsa->iqmp == NULL) {\n        if (rsa->dmp1 != NULL || rsa->dmq1 != NULL || rsa->iqmp != NULL)\n            return 0;\n        return 1;\n    }\n    BN_CTX_start(ctx);\n    r = BN_CTX_get(ctx);\n    p1 = BN_CTX_get(ctx);\n    q1 = BN_CTX_get(ctx);\n    ret = (q1 != NULL)\n          && (BN_copy(p1, rsa->p) != NULL)\n          && BN_sub_word(p1, 1)\n          && (BN_copy(q1, rsa->q) != NULL)\n          && BN_sub_word(q1, 1)\n          && (BN_cmp(rsa->dmp1, BN_value_one()) > 0)\n          && (BN_cmp(rsa->dmp1, p1) < 0)\n          && (BN_cmp(rsa->dmq1, BN_value_one()) > 0)\n          && (BN_cmp(rsa->dmq1, q1) < 0)\n          && (BN_cmp(rsa->iqmp, BN_value_one()) > 0)\n          && (BN_cmp(rsa->iqmp, rsa->p) < 0)\n          && BN_mod_mul(r, rsa->dmp1, rsa->e, p1, ctx)\n          && BN_is_one(r)\n          && BN_mod_mul(r, rsa->dmq1, rsa->e, q1, ctx)\n          && BN_is_one(r)\n          && BN_mod_mul(r, rsa->iqmp, rsa->q, rsa->p, ctx)\n          && BN_is_one(r);\n    BN_clear(p1);\n    BN_clear(q1);\n    BN_CTX_end(ctx);\n    return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n    CTXDBG("ENTER BN_CTX_start()", ctx);\n    if (ctx->err_stack || ctx->too_many)\n        ctx->err_stack++;\n    else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n        BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n        ctx->err_stack++;\n    }\n    CTXDBG("LEAVE BN_CTX_start()", ctx);\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n               BN_CTX *ctx)\n{\n    BIGNUM *t;\n    int ret = 0;\n    bn_check_top(a);\n    bn_check_top(b);\n    bn_check_top(m);\n    BN_CTX_start(ctx);\n    if ((t = BN_CTX_get(ctx)) == NULL)\n        goto err;\n    if (a == b) {\n        if (!BN_sqr(t, a, ctx))\n            goto err;\n    } else {\n        if (!BN_mul(t, a, b, ctx))\n            goto err;\n    }\n    if (!BN_nnmod(r, t, m, ctx))\n        goto err;\n    bn_check_top(r);\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    return ret;\n}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n    int ret = bn_sqr_fixed_top(r, a, ctx);\n    bn_correct_top(r);\n    bn_check_top(r);\n    return ret;\n}', 'int bn_sqr_fixed_top(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n    int max, al;\n    int ret = 0;\n    BIGNUM *tmp, *rr;\n    bn_check_top(a);\n    al = a->top;\n    if (al <= 0) {\n        r->top = 0;\n        r->neg = 0;\n        return 1;\n    }\n    BN_CTX_start(ctx);\n    rr = (a != r) ? r : BN_CTX_get(ctx);\n    tmp = BN_CTX_get(ctx);\n    if (rr == NULL || tmp == NULL)\n        goto err;\n    max = 2 * al;\n    if (bn_wexpand(rr, max) == NULL)\n        goto err;\n    if (al == 4) {\n#ifndef BN_SQR_COMBA\n        BN_ULONG t[8];\n        bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n        bn_sqr_comba4(rr->d, a->d);\n#endif\n    } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n        BN_ULONG t[16];\n        bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n        bn_sqr_comba8(rr->d, a->d);\n#endif\n    } else {\n#if defined(BN_RECURSION)\n        if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n            BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n            bn_sqr_normal(rr->d, a->d, al, t);\n        } else {\n            int j, k;\n            j = BN_num_bits_word((BN_ULONG)al);\n            j = 1 << (j - 1);\n            k = j + j;\n            if (al == j) {\n                if (bn_wexpand(tmp, k * 2) == NULL)\n                    goto err;\n                bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n            } else {\n                if (bn_wexpand(tmp, max) == NULL)\n                    goto err;\n                bn_sqr_normal(rr->d, a->d, al, tmp->d);\n            }\n        }\n#else\n        if (bn_wexpand(tmp, max) == NULL)\n            goto err;\n        bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n    }\n    rr->neg = 0;\n    rr->top = max;\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(rr);\n    bn_check_top(tmp);\n    BN_CTX_end(ctx);\n    return ret;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n    if (ctx == NULL)\n        return;\n    CTXDBG("ENTER BN_CTX_end()", ctx);\n    if (ctx->err_stack)\n        ctx->err_stack--;\n    else {\n        unsigned int fp = BN_STACK_pop(&ctx->stack);\n        if (fp < ctx->used)\n            BN_POOL_release(&ctx->pool, ctx->used - fp);\n        ctx->used = fp;\n        ctx->too_many = 0;\n    }\n    CTXDBG("LEAVE BN_CTX_end()", ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n    return st->indexes[--(st->depth)];\n}']