crypto/bn/bntest.c:1560: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - 1):unsigned32 by call to `BN_mod_exp_recp`.
Showing all 17 steps of the trace


crypto/bn/bntest.c:1518:1: Parameter `ctx->stack.depth`
1516.   	}
1517.   
1518. > int test_kron(BIO *bp, BN_CTX *ctx)
1519.   	{
1520.   	BN_GENCB cb;

crypto/bn/bntest.c:1560:8: Call
1558.   		b->neg=0;
1559.   		
1560.   		if (!BN_mod_exp_recp(r, a, t, b, ctx)) goto err;
               ^
1561.   		b->neg=1;
1562.   

crypto/bn/bn_exp.c:230:1: Parameter `ctx->stack.depth`
  228.   
  229.   
  230. > int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
  231.   		    const BIGNUM *m, BN_CTX *ctx)
  232.   	{

crypto/bn/bn_exp.c:247:2: Call
  245.   		}
  246.   
  247.   	BN_CTX_start(ctx);
          ^
  248.   	if ((aa = BN_CTX_get(ctx)) == NULL) goto err;
  249.   

crypto/bn/bn_ctx.c:254:1: Parameter `ctx->stack.depth`
    252.   	}
    253.   
    254. > void BN_CTX_start(BN_CTX *ctx)
    255.   	{
    256.   	CTXDBG_ENTRY("BN_CTX_start", ctx);

crypto/bn/bn_exp.c:266:7: Call
  264.   	ts=1;
  265.   
  266.   	if (!BN_nnmod(&(val[0]),a,m,ctx)) goto err;		/* 1 */
               ^
  267.   	if (BN_is_zero(&(val[0])))
  268.   		{

crypto/bn/bn_mod.c:127:1: Parameter `ctx->stack.depth`
    125.   
    126.   
    127. > int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)
    128.   	{
    129.   	/* like BN_mod, but returns non-negative remainder

crypto/bn/bn_mod.c:132:8: Call
    130.   	 * (i.e.,  0 <= r < |d|  always holds) */
    131.   
    132.   	if (!(BN_mod(r,m,d,ctx)))
                  ^
    133.   		return 0;
    134.   	if (!r->neg)

crypto/bn/bn_div.c:179:1: Parameter `ctx->stack.depth`
      177.    * If 'dv' or 'rm' is NULL, the respective value is not returned.
      178.    */
      179. > int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
      180.   	   BN_CTX *ctx)
      181.   	{

crypto/bn/bn_div.c:209:2: Call
      207.   		}
      208.   
      209.   	BN_CTX_start(ctx);
              ^
      210.   	tmp=BN_CTX_get(ctx);
      211.   	snum=BN_CTX_get(ctx);

crypto/bn/bn_ctx.c:254:1: Parameter `ctx->stack.depth`
        252.   	}
        253.   
        254. > void BN_CTX_start(BN_CTX *ctx)
        255.   	{
        256.   	CTXDBG_ENTRY("BN_CTX_start", ctx);

crypto/bn/bn_div.c:394:2: Call
      392.   		bn_check_top(rm);
      393.   		}
      394.   	BN_CTX_end(ctx);
              ^
      395.   	return(1);
      396.   err:

crypto/bn/bn_ctx.c:270:1: Parameter `ctx->stack.depth`
        268.   	}
        269.   
        270. > void BN_CTX_end(BN_CTX *ctx)
        271.   	{
        272.   	CTXDBG_ENTRY("BN_CTX_end", ctx);

crypto/bn/bn_ctx.c:277:21: Call
        275.   	else
        276.   		{
        277.   		unsigned int fp = BN_STACK_pop(&ctx->stack);
                                   ^
        278.   		/* Does this stack frame have anything to release? */
        279.   		if(fp < ctx->used)

crypto/bn/bn_ctx.c:351:1: <LHS trace>
349.   	}
350.   
351. > static unsigned int BN_STACK_pop(BN_STACK *st)
352.   	{
353.   	return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:351:1: Parameter `st->depth`
          349.   	}
          350.   
          351. > static unsigned int BN_STACK_pop(BN_STACK *st)
          352.   	{
          353.   	return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:353:9: Binary operation: ([0, +oo] - 1):unsigned32 by call to `BN_mod_exp_recp` 
          351.   static unsigned int BN_STACK_pop(BN_STACK *st)
          352.   	{
          353.   	return st->indexes[--(st->depth)];
                         ^
          354.   	}
          355.   

static unsigned int BN_STACK_pop(BN_STACK *st)
	{
	return st->indexes[--(st->depth)];
	}
['int test_kron(BIO *bp, BN_CTX *ctx)\n\t{\n\tBN_GENCB cb;\n\tBIGNUM *a,*b,*r,*t;\n\tint i;\n\tint legendre, kronecker;\n\tint ret = 0;\n\ta = BN_new();\n\tb = BN_new();\n\tr = BN_new();\n\tt = BN_new();\n\tif (a == NULL || b == NULL || r == NULL || t == NULL) goto err;\n\tBN_GENCB_set(&cb, genprime_cb, NULL);\n\tif (!BN_generate_prime_ex(b, 512, 0, NULL, NULL, &cb)) goto err;\n\tb->neg = rand_neg();\n\tputc(\'\\n\', stderr);\n\tfor (i = 0; i < num0; i++)\n\t\t{\n\t\tif (!BN_bntest_rand(a, 512, 0, 0)) goto err;\n\t\ta->neg = rand_neg();\n\t\tif (!BN_copy(t, b)) goto err;\n\t\tt->neg = 0;\n\t\tif (!BN_sub_word(t, 1)) goto err;\n\t\tif (!BN_rshift1(t, t)) goto err;\n\t\tb->neg=0;\n\t\tif (!BN_mod_exp_recp(r, a, t, b, ctx)) goto err;\n\t\tb->neg=1;\n\t\tif (BN_is_word(r, 1))\n\t\t\tlegendre = 1;\n\t\telse if (BN_is_zero(r))\n\t\t\tlegendre = 0;\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_add_word(r, 1)) goto err;\n\t\t\tif (0 != BN_ucmp(r, b))\n\t\t\t\t{\n\t\t\t\tfprintf(stderr, "Legendre symbol computation failed\\n");\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tlegendre = -1;\n\t\t\t}\n\t\tkronecker = BN_kronecker(a, b, ctx);\n\t\tif (kronecker < -1) goto err;\n\t\tif (a->neg && b->neg)\n\t\t\tkronecker = -kronecker;\n\t\tif (legendre != kronecker)\n\t\t\t{\n\t\t\tfprintf(stderr, "legendre != kronecker; a = ");\n\t\t\tBN_print_fp(stderr, a);\n\t\t\tfprintf(stderr, ", b = ");\n\t\t\tBN_print_fp(stderr, b);\n\t\t\tfprintf(stderr, "\\n");\n\t\t\tgoto err;\n\t\t\t}\n\t\tputc(\'.\', stderr);\n\t\tfflush(stderr);\n\t\t}\n\tputc(\'\\n\', stderr);\n\tfflush(stderr);\n\tret = 1;\n err:\n\tif (a != NULL) BN_free(a);\n\tif (b != NULL) BN_free(b);\n\tif (r != NULL) BN_free(r);\n\tif (t != NULL) BN_free(t);\n\treturn ret;\n\t}', 'int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n\t\t    const BIGNUM *m, BN_CTX *ctx)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue;\n\tint start=1,ts=0;\n\tBIGNUM *aa;\n\tBIGNUM val[TABLE_SIZE];\n\tBN_RECP_CTX recp;\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tret = BN_one(r);\n\t\treturn ret;\n\t\t}\n\tBN_CTX_start(ctx);\n\tif ((aa = BN_CTX_get(ctx)) == NULL) goto err;\n\tBN_RECP_CTX_init(&recp);\n\tif (m->neg)\n\t\t{\n\t\tif (!BN_copy(aa, m)) goto err;\n\t\taa->neg = 0;\n\t\tif (BN_RECP_CTX_set(&recp,aa,ctx) <= 0) goto err;\n\t\t}\n\telse\n\t\t{\n\t\tif (BN_RECP_CTX_set(&recp,m,ctx) <= 0) goto err;\n\t\t}\n\tBN_init(&(val[0]));\n\tts=1;\n\tif (!BN_nnmod(&(val[0]),a,m,ctx)) goto err;\n\tif (BN_is_zero(&(val[0])))\n\t\t{\n\t\tBN_zero(r);\n\t\tret = 1;\n\t\tgoto err;\n\t\t}\n\twindow = BN_window_bits_for_exponent_size(bits);\n\tif (window > 1)\n\t\t{\n\t\tif (!BN_mod_mul_reciprocal(aa,&(val[0]),&(val[0]),&recp,ctx))\n\t\t\tgoto err;\n\t\tj=1<<(window-1);\n\t\tfor (i=1; i<j; i++)\n\t\t\t{\n\t\t\tBN_init(&val[i]);\n\t\t\tif (!BN_mod_mul_reciprocal(&(val[i]),&(val[i-1]),aa,&recp,ctx))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\tts=i;\n\t\t}\n\tstart=1;\n\twvalue=0;\n\twstart=bits-1;\n\twend=0;\n\tif (!BN_one(r)) goto err;\n\tfor (;;)\n\t\t{\n\t\tif (BN_is_bit_set(p,wstart) == 0)\n\t\t\t{\n\t\t\tif (!start)\n\t\t\t\tif (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))\n\t\t\t\tgoto err;\n\t\t\tif (wstart == 0) break;\n\t\t\twstart--;\n\t\t\tcontinue;\n\t\t\t}\n\t\tj=wstart;\n\t\twvalue=1;\n\t\twend=0;\n\t\tfor (i=1; i<window; i++)\n\t\t\t{\n\t\t\tif (wstart-i < 0) break;\n\t\t\tif (BN_is_bit_set(p,wstart-i))\n\t\t\t\t{\n\t\t\t\twvalue<<=(i-wend);\n\t\t\t\twvalue|=1;\n\t\t\t\twend=i;\n\t\t\t\t}\n\t\t\t}\n\t\tj=wend+1;\n\t\tif (!start)\n\t\t\tfor (i=0; i<j; i++)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (!BN_mod_mul_reciprocal(r,r,&(val[wvalue>>1]),&recp,ctx))\n\t\t\tgoto err;\n\t\twstart-=wend+1;\n\t\twvalue=0;\n\t\tstart=0;\n\t\tif (wstart < 0) break;\n\t\t}\n\tret=1;\nerr:\n\tBN_CTX_end(ctx);\n\tfor (i=0; i<ts; i++)\n\t\tBN_clear_free(&(val[i]));\n\tBN_RECP_CTX_free(&recp);\n\tbn_check_top(r);\n\treturn(ret);\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_GET,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n\t{\n\tif (!(BN_mod(r,m,d,ctx)))\n\t\treturn 0;\n\tif (!r->neg)\n\t\treturn 1;\n\treturn (d->neg ? BN_sub : BN_add)(r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n\t   BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tif (dv)\n\t\tbn_check_top(dv);\n\tif (rm)\n\t\tbn_check_top(rm);\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg   = 0;\n\twnum.d     = &(snum->d[loop]);\n\twnum.top   = div_n;\n\twnum.dmax  = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tbn_clear_top2max(&wnum);\n\t\tbn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n\t\t*resp=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h,ql,qh;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q);  qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tif (rm)\n\t\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n\t{\n\treturn st->indexes[--(st->depth)];\n\t}']