crypto/bn/bntest.c:438: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - 1):unsigned64 by call to `BN_div_recp`.
Showing all 13 steps of the trace


crypto/bn/bntest.c:429:4: Call
427.   			{
428.   			BN_bntest_rand(&a,400,0,0);
429.   			BN_copy(&b,&a);
          ^
430.   			BN_lshift(&a,&a,i);
431.   			BN_add_word(&a,i);

crypto/bn/bn_lib.c:472:1: Parameter `*a->d`
  470.   	}
  471.   
  472. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
  473.   	{
  474.   	int i;

crypto/bn/bntest.c:438:3: Call
436.   		b.neg=rand_neg();
437.   		BN_RECP_CTX_set(&recp,&b,ctx);
438.   		BN_div_recp(&d,&c,&a,&recp,ctx);
         ^
439.   		if (bp != NULL)
440.   			{

crypto/bn/bn_recp.c:129:1: Parameter `*m->d`
  127.   	}
  128.   
  129. > int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,
  130.   	BN_RECP_CTX *recp, BN_CTX *ctx)
  131.   	{

crypto/bn/bn_recp.c:148:6: Call
  146.   	if (a == NULL || b == NULL || d == NULL || r == NULL) goto err;
  147.   
  148.   	if (BN_ucmp(m,&(recp->N)) < 0)
              ^
  149.   		{
  150.   		if (!BN_zero(d)) return 0;

crypto/bn/bn_lib.c:648:1: Parameter `*a->d`
    646.   	}
    647.   
    648. > int BN_ucmp(const BIGNUM *a, const BIGNUM *b)
    649.   	{
    650.   	int i;

crypto/bn/bn_recp.c:163:4: Call
  161.   
  162.   	/* i := max(BN_num_bits(m), 2*BN_num_bits(N)) */
  163.   	i=BN_num_bits(m);
            ^
  164.   	j=recp->num_bits<<1;
  165.   	if (j>i) i=j;

crypto/bn/bn_lib.c:245:1: Parameter `*a->d`
    243.   	}
    244.   
    245. > int BN_num_bits(const BIGNUM *a)
    246.   	{
    247.   	BN_ULONG l;

crypto/bn/bn_recp.c:184:7: Call
  182.   
  183.   	if (!BN_mul(b,&(recp->N),d,ctx)) goto err;
  184.   	if (!BN_usub(r,m,b)) goto err;
               ^
  185.   	r->neg=0;
  186.   

crypto/bn/bn_add.c:168:1: <LHS trace>
166.   
167.   /* unsigned subtraction of b from a, a must be larger than b. */
168. > int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
169.   	{
170.   	int max,min;

crypto/bn/bn_add.c:168:1: Parameter `*a->d`
    166.   
    167.   /* unsigned subtraction of b from a, a must be larger than b. */
    168. > int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
    169.   	{
    170.   	int max,min;

crypto/bn/bn_add.c:227:4: Assignment
    225.   			{
    226.   			i++;
    227.   			t1= *(ap++);
              ^
    228.   			t2=(t1-1)&BN_MASK2;
    229.   			*(rp++)=t2;

crypto/bn/bn_add.c:228:4: Binary operation: ([0, +oo] - 1):unsigned64 by call to `BN_div_recp` 
    226.   			i++;
    227.   			t1= *(ap++);
    228.   			t2=(t1-1)&BN_MASK2;
              ^
    229.   			*(rp++)=t2;
    230.   			if (t1 > t2) break;

int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
	{
	int max,min;
	register BN_ULONG t1,t2,*ap,*bp,*rp;
	int i,carry;
#if defined(IRIX_CC_BUG) && !defined(LINT)
	int dummy;
#endif
	bn_check_top(a);
	bn_check_top(b);
	if (a->top < b->top)
		{
		BNerr(BN_F_BN_USUB,BN_R_ARG2_LT_ARG3);
		return(0);
		}
	max=a->top;
	min=b->top;
	if (bn_wexpand(r,max) == NULL) return(0);
	ap=a->d;
	bp=b->d;
	rp=r->d;
#if 1
	carry=0;
	for (i=0; i<min; i++)
		{
		t1= *(ap++);
		t2= *(bp++);
		if (carry)
			{
			carry=(t1 <= t2);
			t1=(t1-t2-1)&BN_MASK2;
			}
		else
			{
			carry=(t1 < t2);
			t1=(t1-t2)&BN_MASK2;
			}
#if defined(IRIX_CC_BUG) && !defined(LINT)
		dummy=t1;
#endif
		*(rp++)=t1&BN_MASK2;
		}
#else
	carry=bn_sub_words(rp,ap,bp,min);
	ap+=min;
	bp+=min;
	rp+=min;
	i=min;
#endif
	if (carry)
		{
		while (i < max)
			{
			i++;
			t1= *(ap++);
			t2=(t1-1)&BN_MASK2;
			*(rp++)=t2;
			if (t1 > t2) break;
			}
		}
#if 0
	memcpy(rp,ap,sizeof(*rp)*(max-i));
#else
	if (rp != ap)
		{
		for (;;)
			{
			if (i++ >= max) break;
			rp[0]=ap[0];
			if (i++ >= max) break;
			rp[1]=ap[1];
			if (i++ >= max) break;
			rp[2]=ap[2];
			if (i++ >= max) break;
			rp[3]=ap[3];
			rp+=4;
			ap+=4;
			}
		}
#endif
	r->top=max;
	r->neg=0;
	bn_fix_top(r);
	return(1);
	}
['int test_div_recp(BIO *bp, BN_CTX *ctx)\n\t{\n\tBIGNUM a,b,c,d,e;\n\tBN_RECP_CTX recp;\n\tint i;\n\tBN_RECP_CTX_init(&recp);\n\tBN_init(&a);\n\tBN_init(&b);\n\tBN_init(&c);\n\tBN_init(&d);\n\tBN_init(&e);\n\tfor (i=0; i<num0+num1; i++)\n\t\t{\n\t\tif (i < num1)\n\t\t\t{\n\t\t\tBN_bntest_rand(&a,400,0,0);\n\t\t\tBN_copy(&b,&a);\n\t\t\tBN_lshift(&a,&a,i);\n\t\t\tBN_add_word(&a,i);\n\t\t\t}\n\t\telse\n\t\t\tBN_bntest_rand(&b,50+3*(i-num1),0,0);\n\t\ta.neg=rand_neg();\n\t\tb.neg=rand_neg();\n\t\tBN_RECP_CTX_set(&recp,&b,ctx);\n\t\tBN_div_recp(&d,&c,&a,&recp,ctx);\n\t\tif (bp != NULL)\n\t\t\t{\n\t\t\tif (!results)\n\t\t\t\t{\n\t\t\t\tBN_print(bp,&a);\n\t\t\t\tBIO_puts(bp," / ");\n\t\t\t\tBN_print(bp,&b);\n\t\t\t\tBIO_puts(bp," - ");\n\t\t\t\t}\n\t\t\tBN_print(bp,&d);\n\t\t\tBIO_puts(bp,"\\n");\n\t\t\tif (!results)\n\t\t\t\t{\n\t\t\t\tBN_print(bp,&a);\n\t\t\t\tBIO_puts(bp," % ");\n\t\t\t\tBN_print(bp,&b);\n\t\t\t\tBIO_puts(bp," - ");\n\t\t\t\t}\n\t\t\tBN_print(bp,&c);\n\t\t\tBIO_puts(bp,"\\n");\n\t\t\t}\n\t\tBN_mul(&e,&d,&b,ctx);\n\t\tBN_add(&d,&e,&c);\n\t\tBN_sub(&d,&d,&a);\n\t\tif(!BN_is_zero(&d))\n\t\t    {\n\t\t    fprintf(stderr,"Reciprocal division test failed!\\n");\n\t\t    fprintf(stderr,"a=");\n\t\t    BN_print_fp(stderr,&a);\n\t\t    fprintf(stderr,"\\nb=");\n\t\t    BN_print_fp(stderr,&b);\n\t\t    fprintf(stderr,"\\n");\n\t\t    return 0;\n\t\t    }\n\t\t}\n\tBN_free(&a);\n\tBN_free(&b);\n\tBN_free(&c);\n\tBN_free(&d);\n\tBN_free(&e);\n\tBN_RECP_CTX_free(&recp);\n\treturn(1);\n\t}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n\t{\n\tint i;\n\tBN_ULONG *A;\n\tconst BN_ULONG *B;\n\tbn_check_top(b);\n\tif (a == b) return(a);\n\tif (bn_wexpand(a,b->top) == NULL) return(NULL);\n#if 1\n\tA=a->d;\n\tB=b->d;\n\tfor (i=b->top>>2; i>0; i--,A+=4,B+=4)\n\t\t{\n\t\tBN_ULONG a0,a1,a2,a3;\n\t\ta0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];\n\t\tA[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;\n\t\t}\n\tswitch (b->top&3)\n\t\t{\n\t\tcase 3: A[2]=B[2];\n\t\tcase 2: A[1]=B[1];\n\t\tcase 1: A[0]=B[0];\n\t\tcase 0: ;\n\t\t}\n#else\n\tmemcpy(a->d,b->d,sizeof(b->d[0])*b->top);\n#endif\n\ta->top=b->top;\n\tif ((a->top == 0) && (a->d != NULL))\n\t\ta->d[0]=0;\n\ta->neg=b->neg;\n\treturn(a);\n\t}', 'int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,\n\tBN_RECP_CTX *recp, BN_CTX *ctx)\n\t{\n\tint i,j,ret=0;\n\tBIGNUM *a,*b,*d,*r;\n\tBN_CTX_start(ctx);\n\ta=BN_CTX_get(ctx);\n\tb=BN_CTX_get(ctx);\n\tif (dv != NULL)\n\t\td=dv;\n\telse\n\t\td=BN_CTX_get(ctx);\n\tif (rem != NULL)\n\t\tr=rem;\n\telse\n\t\tr=BN_CTX_get(ctx);\n\tif (a == NULL || b == NULL || d == NULL || r == NULL) goto err;\n\tif (BN_ucmp(m,&(recp->N)) < 0)\n\t\t{\n\t\tif (!BN_zero(d)) return 0;\n\t\tif (!BN_copy(r,m)) return 0;\n\t\tBN_CTX_end(ctx);\n\t\treturn(1);\n\t\t}\n\ti=BN_num_bits(m);\n\tj=recp->num_bits<<1;\n\tif (j>i) i=j;\n\tif (i != recp->shift)\n\t\trecp->shift=BN_reciprocal(&(recp->Nr),&(recp->N),\n\t\t\ti,ctx);\n\tif (recp->shift == -1) goto err;\n\tif (!BN_rshift(a,m,recp->num_bits)) goto err;\n\tif (!BN_mul(b,a,&(recp->Nr),ctx)) goto err;\n\tif (!BN_rshift(d,b,i-recp->num_bits)) goto err;\n\td->neg=0;\n\tif (!BN_mul(b,&(recp->N),d,ctx)) goto err;\n\tif (!BN_usub(r,m,b)) goto err;\n\tr->neg=0;\n#if 1\n\tj=0;\n\twhile (BN_ucmp(r,&(recp->N)) >= 0)\n\t\t{\n\t\tif (j++ > 2)\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_MOD_MUL_RECIPROCAL,BN_R_BAD_RECIPROCAL);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (!BN_usub(r,r,&(recp->N))) goto err;\n\t\tif (!BN_add_word(d,1)) goto err;\n\t\t}\n#endif\n\tr->neg=BN_is_zero(r)?0:m->neg;\n\td->neg=m->neg^recp->N.neg;\n\tret=1;\nerr:\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'int BN_ucmp(const BIGNUM *a, const BIGNUM *b)\n\t{\n\tint i;\n\tBN_ULONG t1,t2,*ap,*bp;\n\tbn_check_top(a);\n\tbn_check_top(b);\n\ti=a->top-b->top;\n\tif (i != 0) return(i);\n\tap=a->d;\n\tbp=b->d;\n\tfor (i=a->top-1; i>=0; i--)\n\t\t{\n\t\tt1= ap[i];\n\t\tt2= bp[i];\n\t\tif (t1 != t2)\n\t\t\treturn(t1 > t2?1:-1);\n\t\t}\n\treturn(0);\n\t}', 'int BN_num_bits(const BIGNUM *a)\n\t{\n\tBN_ULONG l;\n\tint i;\n\tbn_check_top(a);\n\tif (a->top == 0) return(0);\n\tl=a->d[a->top-1];\n\tassert(l != 0);\n\ti=(a->top-1)*BN_BITS2;\n\treturn(i+BN_num_bits_word(l));\n\t}', 'int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n\t{\n\tint max,min;\n\tregister BN_ULONG t1,t2,*ap,*bp,*rp;\n\tint i,carry;\n#if defined(IRIX_CC_BUG) && !defined(LINT)\n\tint dummy;\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tif (a->top < b->top)\n\t\t{\n\t\tBNerr(BN_F_BN_USUB,BN_R_ARG2_LT_ARG3);\n\t\treturn(0);\n\t\t}\n\tmax=a->top;\n\tmin=b->top;\n\tif (bn_wexpand(r,max) == NULL) return(0);\n\tap=a->d;\n\tbp=b->d;\n\trp=r->d;\n#if 1\n\tcarry=0;\n\tfor (i=0; i<min; i++)\n\t\t{\n\t\tt1= *(ap++);\n\t\tt2= *(bp++);\n\t\tif (carry)\n\t\t\t{\n\t\t\tcarry=(t1 <= t2);\n\t\t\tt1=(t1-t2-1)&BN_MASK2;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tcarry=(t1 < t2);\n\t\t\tt1=(t1-t2)&BN_MASK2;\n\t\t\t}\n#if defined(IRIX_CC_BUG) && !defined(LINT)\n\t\tdummy=t1;\n#endif\n\t\t*(rp++)=t1&BN_MASK2;\n\t\t}\n#else\n\tcarry=bn_sub_words(rp,ap,bp,min);\n\tap+=min;\n\tbp+=min;\n\trp+=min;\n\ti=min;\n#endif\n\tif (carry)\n\t\t{\n\t\twhile (i < max)\n\t\t\t{\n\t\t\ti++;\n\t\t\tt1= *(ap++);\n\t\t\tt2=(t1-1)&BN_MASK2;\n\t\t\t*(rp++)=t2;\n\t\t\tif (t1 > t2) break;\n\t\t\t}\n\t\t}\n#if 0\n\tmemcpy(rp,ap,sizeof(*rp)*(max-i));\n#else\n\tif (rp != ap)\n\t\t{\n\t\tfor (;;)\n\t\t\t{\n\t\t\tif (i++ >= max) break;\n\t\t\trp[0]=ap[0];\n\t\t\tif (i++ >= max) break;\n\t\t\trp[1]=ap[1];\n\t\t\tif (i++ >= max) break;\n\t\t\trp[2]=ap[2];\n\t\t\tif (i++ >= max) break;\n\t\t\trp[3]=ap[3];\n\t\t\trp+=4;\n\t\t\tap+=4;\n\t\t\t}\n\t\t}\n#endif\n\tr->top=max;\n\tr->neg=0;\n\tbn_fix_top(r);\n\treturn(1);\n\t}']