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


crypto/rsa/rsa_sp800_56b_check.c:226:15: Call
224.       return BN_sub(p1, p, BN_value_one())    /* p-1 */
225.              && BN_sub(q1, q, BN_value_one()) /* q-1 */
226.              && BN_mul(p1q1, p1, q1, ctx)     /* (p-1)(q-1) */
                     ^
227.              && BN_gcd(gcd, p1, q1, ctx)
228.              && BN_div(lcm, NULL, p1q1, gcd, ctx); /* LCM((p-1, q-1)) */

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 `ctx->pool.used`
    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_sp800_56b_check.c:227:15: Call
225.              && BN_sub(q1, q, BN_value_one()) /* q-1 */
226.              && BN_mul(p1q1, p1, q1, ctx)     /* (p-1)(q-1) */
227.              && BN_gcd(gcd, p1, q1, ctx)
                     ^
228.              && BN_div(lcm, NULL, p1q1, gcd, ctx); /* LCM((p-1, q-1)) */
229.   }

crypto/bn/bn_gcd.c:15:1: Parameter `ctx->pool.used`
  13.   static BIGNUM *euclid(BIGNUM *a, BIGNUM *b);
  14.   
  15. > int BN_gcd(BIGNUM *r, const BIGNUM *in_a, const BIGNUM *in_b, BN_CTX *ctx)
  16.   {
  17.       BIGNUM *a, *b, *t;

crypto/bn/bn_gcd.c:24:9: Call
  22.   
  23.       BN_CTX_start(ctx);
  24.       a = BN_CTX_get(ctx);
                ^
  25.       b = BN_CTX_get(ctx);
  26.       if (b == NULL)

crypto/bn/bn_ctx.c:204:1: Parameter `ctx->pool.used`
    202.   }
    203.   
    204. > BIGNUM *BN_CTX_get(BN_CTX *ctx)
    205.   {
    206.       BIGNUM *ret;

crypto/bn/bn_gcd.c:25:9: Call
  23.       BN_CTX_start(ctx);
  24.       a = BN_CTX_get(ctx);
  25.       b = BN_CTX_get(ctx);
                ^
  26.       if (b == NULL)
  27.           goto err;

crypto/bn/bn_ctx.c:204:1: Parameter `ctx->pool.used`
    202.   }
    203.   
    204. > BIGNUM *BN_CTX_get(BN_CTX *ctx)
    205.   {
    206.       BIGNUM *ret;

crypto/bn/bn_gcd.c:49:5: Call
  47.       ret = 1;
  48.    err:
  49.       BN_CTX_end(ctx);
            ^
  50.       bn_check_top(r);
  51.       return ret;

crypto/bn/bn_ctx.c:185:1: Parameter `ctx->pool.used`
    183.   }
    184.   
    185. > void BN_CTX_end(BN_CTX *ctx)
    186.   {
    187.       if (ctx == NULL)

crypto/bn/bn_ctx.c:196:13: Call
    194.           /* Does this stack frame have anything to release? */
    195.           if (fp < ctx->used)
    196.               BN_POOL_release(&ctx->pool, ctx->used - fp);
                       ^
    197.           ctx->used = fp;
    198.           /* Unjam "too_many" in case "get" had failed */

crypto/bn/bn_ctx.c:340:1: <LHS trace>
338.   }
339.   
340. > static void BN_POOL_release(BN_POOL *p, unsigned int num)
341.   {
342.       unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE;

crypto/bn/bn_ctx.c:340:1: Parameter `p->used`
      338.   }
      339.   
      340. > static void BN_POOL_release(BN_POOL *p, unsigned int num)
      341.   {
      342.       unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE;

crypto/bn/bn_ctx.c:342:5: Binary operation: ([0, +oo] - 1):unsigned32 by call to `BN_gcd` 
      340.   static void BN_POOL_release(BN_POOL *p, unsigned int num)
      341.   {
      342.       unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE;
                 ^
      343.   
      344.       p->used -= num;

static void BN_POOL_release(BN_POOL *p, unsigned int num)
{
    unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE;
    p->used -= num;
    while (num--) {
        bn_check_top(p->current->vals + offset);
        if (offset == 0) {
            offset = BN_CTX_POOL_SIZE - 1;
            p->current = p->current->prev;
        } else
            offset--;
    }
}
['int rsa_get_lcm(BN_CTX *ctx, const BIGNUM *p, const BIGNUM *q,\n                BIGNUM *lcm, BIGNUM *gcd, BIGNUM *p1, BIGNUM *q1,\n                BIGNUM *p1q1)\n{\n    return BN_sub(p1, p, BN_value_one())\n           && BN_sub(q1, q, BN_value_one())\n           && BN_mul(p1q1, p1, q1, ctx)\n           && BN_gcd(gcd, p1, q1, ctx)\n           && BN_div(lcm, NULL, p1q1, gcd, ctx);\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}', 'int BN_gcd(BIGNUM *r, const BIGNUM *in_a, const BIGNUM *in_b, BN_CTX *ctx)\n{\n    BIGNUM *a, *b, *t;\n    int ret = 0;\n    bn_check_top(in_a);\n    bn_check_top(in_b);\n    BN_CTX_start(ctx);\n    a = BN_CTX_get(ctx);\n    b = BN_CTX_get(ctx);\n    if (b == NULL)\n        goto err;\n    if (BN_copy(a, in_a) == NULL)\n        goto err;\n    if (BN_copy(b, in_b) == NULL)\n        goto err;\n    a->neg = 0;\n    b->neg = 0;\n    if (BN_cmp(a, b) < 0) {\n        t = a;\n        a = b;\n        b = t;\n    }\n    t = euclid(a, b);\n    if (t == NULL)\n        goto err;\n    if (BN_copy(r, t) == NULL)\n        goto err;\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    bn_check_top(r);\n    return ret;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n    BIGNUM *ret;\n    CTXDBG("ENTER 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    ret->flags &= (~BN_FLG_CONSTTIME);\n    ctx->used++;\n    CTXDBG("LEAVE BN_CTX_get()", 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 void BN_POOL_release(BN_POOL *p, unsigned int num)\n{\n    unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE;\n    p->used -= num;\n    while (num--) {\n        bn_check_top(p->current->vals + offset);\n        if (offset == 0) {\n            offset = BN_CTX_POOL_SIZE - 1;\n            p->current = p->current->prev;\n        } else\n            offset--;\n    }\n}']