crypto/bn/bn_exp.c:463: error: BUFFER_OVERRUN_L3
  Offset: [3, +oo] (⇐ [1, +oo] + 2) Size: [0, +oo] by call to `BN_mod_mul`.
Showing all 16 steps of the trace


crypto/bn/bn_exp.c:462:7: Call
460.   	BN_init(&(val[0]));
461.   	ts=1;
462.   	if (!BN_mod(&(val[0]),a,m,ctx)) goto err;		/* 1 */
             ^
463.   	if (!BN_mod_mul(d,&(val[0]),&(val[0]),m,ctx))
464.   		goto err;				/* 2 */

crypto/bn/bn_div.c:287:1: Parameter `*rem->d`
  285.   
  286.   /* rem != m */
  287. > int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)
  288.   	{
  289.   #if 0 /* The old slow way */

crypto/bn/bn_div.c:313:9: Call
  311.   	return(1);
  312.   #else
  313.   	return(BN_div(NULL,rem,m,d,ctx));
                 ^
  314.   #endif
  315.   	}

crypto/bn/bn_div.c:121:1: Parameter `*rm->d`
    119.   #else
    120.   
    121. > int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
    122.   	   BN_CTX *ctx)
    123.   	{

crypto/bn/bn_exp.c:463:7: Call
461.   	ts=1;
462.   	if (!BN_mod(&(val[0]),a,m,ctx)) goto err;		/* 1 */
463.   	if (!BN_mod_mul(d,&(val[0]),&(val[0]),m,ctx))
             ^
464.   		goto err;				/* 2 */
465.   

crypto/bn/bn_exp.c:66:1: Parameter `*a->d`
  64.   
  65.   /* slow but works */
  66. > int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx)
  67.   	{
  68.   	BIGNUM *t;

crypto/bn/bn_exp.c:77:10: Call
  75.   	t= &(ctx->bn[ctx->tos++]);
  76.   	if (a == b)
  77.   		{ if (!BN_sqr(t,a,ctx)) goto err; }
                 ^
  78.   	else
  79.   		{ if (!BN_mul(t,a,b,ctx)) goto err; }

crypto/bn/bn_sqr.c:65:1: Parameter `*a->d`
    63.   /* r must not be a */
    64.   /* I've just gone over this and it is now %20 faster on x86 - eay - 27 Jun 96 */
    65. > int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx)
    66.   	{
    67.   	int max,al;

crypto/bn/bn_sqr.c:130:5: Call
    128.   				{
    129.   				if (bn_wexpand(tmp,max) == NULL) return(0);
    130.   				bn_sqr_normal(rr->d,a->d,al,tmp->d);
               ^
    131.   				}
    132.   			}

crypto/bn/bn_sqr.c:146:1: Parameter `*a`
      144.   
      145.   /* tmp must have 2*n words */
      146. > void bn_sqr_normal(BN_ULONG *r, BN_ULONG *a, int n, BN_ULONG *tmp)
      147.   	{
      148.   	int i,j,max;

crypto/bn/bn_sqr.c:152:2: Assignment
      150.   
      151.   	max=n*2;
      152.   	ap=a;
              ^
      153.   	rp=r;
      154.   	rp[0]=rp[max-1]=0;

crypto/bn/bn_sqr.c:168:3: Assignment
      166.   		{
      167.   		j--;
      168.   		ap++;
               ^
      169.   		rp[j]=bn_mul_add_words(rp,ap,j,ap[-1]);
      170.   		rp+=2;

crypto/bn/bn_sqr.c:169:9: Call
      167.   		j--;
      168.   		ap++;
      169.   		rp[j]=bn_mul_add_words(rp,ap,j,ap[-1]);
                     ^
      170.   		rp+=2;
      171.   		}

crypto/bn/bn_asm.c:144:1: <Length trace>
142.   #else
143.   
144. > BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
145.   	{
146.   	BN_ULONG c=0;

crypto/bn/bn_asm.c:144:1: Parameter `*ap`
        142.   #else
        143.   
        144. > BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
        145.   	{
        146.   	BN_ULONG c=0;

crypto/bn/bn_asm.c:161:3: Array access: Offset: [3, +oo] (⇐ [1, +oo] + 2) Size: [0, +oo] by call to `BN_mod_mul` 
        159.   		mul_add(rp[1],ap[1],bl,bh,c);
        160.   		if (--num == 0) break;
        161.   		mul_add(rp[2],ap[2],bl,bh,c);
                 ^
        162.   		if (--num == 0) break;
        163.   		mul_add(rp[3],ap[3],bl,bh,c);

BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
	{
	BN_ULONG c=0;
	BN_ULONG bl,bh;
	bn_check_num(num);
	if (num <= 0) return((BN_ULONG)0);
	bl=LBITS(w);
	bh=HBITS(w);
	for (;;)
		{
		mul_add(rp[0],ap[0],bl,bh,c);
		if (--num == 0) break;
		mul_add(rp[1],ap[1],bl,bh,c);
		if (--num == 0) break;
		mul_add(rp[2],ap[2],bl,bh,c);
		if (--num == 0) break;
		mul_add(rp[3],ap[3],bl,bh,c);
		if (--num == 0) break;
		ap+=4;
		rp+=4;
		}
	return(c);
	}
['int BN_mod_exp_simple(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m,\n\t     BN_CTX *ctx)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue,ts=0;\n\tint start=1;\n\tBIGNUM *d;\n\tBIGNUM val[TABLE_SIZE];\n\td= &(ctx->bn[ctx->tos++]);\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tBN_one(r);\n\t\treturn(1);\n\t\t}\n\tBN_init(&(val[0]));\n\tts=1;\n\tif (!BN_mod(&(val[0]),a,m,ctx)) goto err;\n\tif (!BN_mod_mul(d,&(val[0]),&(val[0]),m,ctx))\n\t\tgoto err;\n\tif (bits <= 17)\n\t\twindow=1;\n\telse if (bits >= 256)\n\t\twindow=5;\n\telse if (bits >= 128)\n\t\twindow=4;\n\telse\n\t\twindow=3;\n\tj=1<<(window-1);\n\tfor (i=1; i<j; i++)\n\t\t{\n\t\tBN_init(&(val[i]));\n\t\tif (!BN_mod_mul(&(val[i]),&(val[i-1]),d,m,ctx))\n\t\t\tgoto err;\n\t\t}\n\tts=i;\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(r,r,r,m,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(r,r,r,m,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (!BN_mod_mul(r,r,&(val[wvalue>>1]),m,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\tctx->tos--;\n\tfor (i=0; i<ts; i++)\n\t\tBN_clear_free(&(val[i]));\n\treturn(ret);\n\t}', 'int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n\t{\n#if 0\n\tint i,nm,nd;\n\tBIGNUM *dv;\n\tif (BN_ucmp(m,d) < 0)\n\t\treturn((BN_copy(rem,m) == NULL)?0:1);\n\tdv= &(ctx->bn[ctx->tos]);\n\tif (!BN_copy(rem,m)) return(0);\n\tnm=BN_num_bits(rem);\n\tnd=BN_num_bits(d);\n\tif (!BN_lshift(dv,d,nm-nd)) return(0);\n\tfor (i=nm-nd; i>=0; i--)\n\t\t{\n\t\tif (BN_cmp(rem,dv) >= 0)\n\t\t\t{\n\t\t\tif (!BN_sub(rem,rem,dv)) return(0);\n\t\t\t}\n\t\tif (!BN_rshift1(dv,dv)) return(0);\n\t\t}\n\treturn(1);\n#else\n\treturn(BN_div(NULL,rem,m,d,ctx));\n#endif\n\t}', '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,j,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\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\ttmp= &(ctx->bn[ctx->tos]);\n\ttmp->neg=0;\n\tsnum= &(ctx->bn[ctx->tos+1]);\n\tsdiv= &(ctx->bn[ctx->tos+2]);\n\tif (dv == NULL)\n\t\tres= &(ctx->bn[ctx->tos+3]);\n\telse\tres=dv;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tBN_lshift(sdiv,divisor,norm_shift);\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tBN_lshift(snum,num,norm_shift);\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\tBN_init(&wnum);\n\twnum.d=\t &(snum->d[loop]);\n\twnum.top= div_n;\n\twnum.max= snum->max+1;\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\tif (!BN_usub(&wnum,&wnum,sdiv)) goto err;\n\t\t*resp=1;\n\t\tres->d[res->top-1]=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tresp--;\n\tfor (i=0; i<loop-1; i++)\n\t\t{\n\t\tBN_ULONG q,n0,n1;\n\t\tBN_ULONG l0;\n\t\twnum.d--; wnum.top++;\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\tq=bn_div_words(n0,n1,d0);\n\t\t{\n#ifdef BN_LLONG\n\t\tBN_ULLONG t1,t2,rem;\n\t\tt1=((BN_ULLONG)n0<<BN_BITS2)|n1;\n\t\tfor (;;)\n\t\t\t{\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\trem=t1-(BN_ULLONG)q*d0;\n\t\t\tif ((rem>>BN_BITS2) ||\n\t\t\t\t(t2 <= ((BN_ULLONG)(rem<<BN_BITS2)+wnump[-2])))\n\t\t\t\tbreak;\n\t\t\tq--;\n\t\t\t}\n#else\n\t\tBN_ULONG t1l,t1h,t2l,t2h,t3l,t3h,ql,qh,t3t;\n\t\tt1h=n0;\n\t\tt1l=n1;\n\t\tfor (;;)\n\t\t\t{\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\t\t\tt3t=LBITS(d0); t3h=HBITS(d0);\n\t\t\tmul64(t3t,t3h,ql,qh);\n\t\t\tt3l=(t1l-t3t)&BN_MASK2;\n\t\t\tif (t3l > t1l) t3h++;\n\t\t\tt3h=(t1h-t3h)&BN_MASK2;\n\t\t\tif (t3h) break;\n\t\t\tif (t2h < t3l) break;\n\t\t\tif ((t2h == t3l) && (t2l <= wnump[-2])) break;\n\t\t\tq--;\n\t\t\t}\n#endif\n\t\t}\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\tfor (j=div_n+1; j>0; j--)\n\t\t\tif (tmp->d[j-1]) break;\n\t\ttmp->top=j;\n\t\tj=wnum.top;\n\t\tBN_sub(&wnum,&wnum,tmp);\n\t\tsnum->top=snum->top+wnum.top-j;\n\t\tif (wnum.neg)\n\t\t\t{\n\t\t\tq--;\n\t\t\tj=wnum.top;\n\t\t\tBN_add(&wnum,&wnum,sdiv);\n\t\t\tsnum->top+=wnum.top-j;\n\t\t\t}\n\t\t*(resp--)=q;\n\t\twnump--;\n\t\t}\n\tif (rm != NULL)\n\t\t{\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\trm->neg=num->neg;\n\t\t}\n\treturn(1);\nerr:\n\treturn(0);\n\t}', 'int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx)\n\t{\n\tBIGNUM *t;\n\tint r=0;\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(m);\n\tt= &(ctx->bn[ctx->tos++]);\n\tif (a == b)\n\t\t{ if (!BN_sqr(t,a,ctx)) goto err; }\n\telse\n\t\t{ if (!BN_mul(t,a,b,ctx)) goto err; }\n\tif (!BN_mod(ret,t,m,ctx)) goto err;\n\tr=1;\nerr:\n\tctx->tos--;\n\treturn(r);\n\t}', 'int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx)\n\t{\n\tint max,al;\n\tBIGNUM *tmp,*rr;\n#ifdef BN_COUNT\nprintf("BN_sqr %d * %d\\n",a->top,a->top);\n#endif\n\tbn_check_top(a);\n\ttmp= &(ctx->bn[ctx->tos]);\n\trr=(a != r)?r: (&ctx->bn[ctx->tos+1]);\n\tal=a->top;\n\tif (al <= 0)\n\t\t{\n\t\tr->top=0;\n\t\treturn(1);\n\t\t}\n\tmax=(al+al);\n\tif (bn_wexpand(rr,max+1) == NULL) return(0);\n\tr->neg=0;\n\tif (al == 4)\n\t\t{\n#ifndef BN_SQR_COMBA\n\t\tBN_ULONG t[8];\n\t\tbn_sqr_normal(rr->d,a->d,4,t);\n#else\n\t\tbn_sqr_comba4(rr->d,a->d);\n#endif\n\t\t}\n\telse if (al == 8)\n\t\t{\n#ifndef BN_SQR_COMBA\n\t\tBN_ULONG t[16];\n\t\tbn_sqr_normal(rr->d,a->d,8,t);\n#else\n\t\tbn_sqr_comba8(rr->d,a->d);\n#endif\n\t\t}\n\telse\n\t\t{\n#if defined(BN_RECURSION)\n\t\tif (al < BN_SQR_RECURSIVE_SIZE_NORMAL)\n\t\t\t{\n\t\t\tBN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL*2];\n\t\t\tbn_sqr_normal(rr->d,a->d,al,t);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tint j,k;\n\t\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\t\tj=1<<(j-1);\n\t\t\tk=j+j;\n\t\t\tif (al == j)\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(a,k*2) == NULL) return(0);\n\t\t\t\tif (bn_wexpand(tmp,k*2) == NULL) return(0);\n\t\t\t\tbn_sqr_recursive(rr->d,a->d,al,tmp->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(tmp,max) == NULL) return(0);\n\t\t\t\tbn_sqr_normal(rr->d,a->d,al,tmp->d);\n\t\t\t\t}\n\t\t\t}\n#else\n\t\tif (bn_wexpand(tmp,max) == NULL) return(0);\n\t\tbn_sqr_normal(rr->d,a->d,al,tmp->d);\n#endif\n\t\t}\n\trr->top=max;\n\tif ((max > 0) && (rr->d[max-1] == 0)) rr->top--;\n\tif (rr != r) BN_copy(r,rr);\n\treturn(1);\n\t}', 'void bn_sqr_normal(BN_ULONG *r, BN_ULONG *a, int n, BN_ULONG *tmp)\n\t{\n\tint i,j,max;\n\tBN_ULONG *ap,*rp;\n\tmax=n*2;\n\tap=a;\n\trp=r;\n\trp[0]=rp[max-1]=0;\n\trp++;\n\tj=n;\n\tif (--j > 0)\n\t\t{\n\t\tap++;\n\t\trp[j]=bn_mul_words(rp,ap,j,ap[-1]);\n\t\trp+=2;\n\t\t}\n\tfor (i=n-2; i>0; i--)\n\t\t{\n\t\tj--;\n\t\tap++;\n\t\trp[j]=bn_mul_add_words(rp,ap,j,ap[-1]);\n\t\trp+=2;\n\t\t}\n\tbn_add_words(r,r,r,max);\n\tbn_sqr_words(tmp,a,n);\n\tbn_add_words(r,r,tmp,max);\n\t}', 'BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)\n\t{\n\tBN_ULONG c=0;\n\tBN_ULONG bl,bh;\n\tbn_check_num(num);\n\tif (num <= 0) return((BN_ULONG)0);\n\tbl=LBITS(w);\n\tbh=HBITS(w);\n\tfor (;;)\n\t\t{\n\t\tmul_add(rp[0],ap[0],bl,bh,c);\n\t\tif (--num == 0) break;\n\t\tmul_add(rp[1],ap[1],bl,bh,c);\n\t\tif (--num == 0) break;\n\t\tmul_add(rp[2],ap[2],bl,bh,c);\n\t\tif (--num == 0) break;\n\t\tmul_add(rp[3],ap[3],bl,bh,c);\n\t\tif (--num == 0) break;\n\t\tap+=4;\n\t\trp+=4;\n\t\t}\n\treturn(c);\n\t}']