crypto/bn/bn_prime.c:188: error: BUFFER_OVERRUN_L3
  Offset: [16, +oo] Size: [0, +oo] by call to `witness`.
Showing all 17 steps of the trace


crypto/bn/bn_prime.c:183:7: Call
181.   
182.   	/* Setup the montgomery structure */
183.   	if (!BN_MONT_CTX_set(mont,a,ctx2)) goto err;
             ^
184.   
185.   	for (i=0; i<checks; i++)

crypto/bn/bn_mont.c:301:1: Parameter `*mont->RR.d`
  299.   	}
  300.   
  301. > int BN_MONT_CTX_set(BN_MONT_CTX *mont, BIGNUM *mod, BN_CTX *ctx)
  302.   	{
  303.   	BIGNUM Ri,*R;

crypto/bn/bn_mont.c:319:3: Call
  317.   
  318.   		mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;
  319.   		BN_zero(R);
           ^
  320.   		BN_set_bit(R,BN_BITS2);
  321.   		/* I was bad, this modification of a passed variable was

crypto/bn/bn_lib.c:548:1: Parameter `*a->d`
    546.   	}
    547.   
    548. > int BN_set_word(BIGNUM *a, BN_ULONG w)
    549.   	{
    550.   	int i,n;

crypto/bn/bn_mont.c:320:3: Call
  318.   		mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;
  319.   		BN_zero(R);
  320.   		BN_set_bit(R,BN_BITS2);
           ^
  321.   		/* I was bad, this modification of a passed variable was
  322.   		 * breaking the multithreaded stuff :-(

crypto/bn/bn_lib.c:688:1: Parameter `*a->d`
    686.   	}
    687.   
    688. > int BN_set_bit(BIGNUM *a, int n)
    689.   	{
    690.   	int i,j,k;

crypto/bn/bn_prime.c:188:5: Call
186.   		{
187.   		if (!BN_rand(check,BN_num_bits(a)-1,0,0)) goto err;
188.   		j=witness(check,a,ctx,ctx2,mont);
           ^
189.   		if (j == -1) goto err;
190.   		if (j)

crypto/bn/bn_prime.c:211:1: Parameter `mont->RR.top`
  209.   #define RECP_MUL_MOD
  210.   
  211. > static int witness(BIGNUM *a, BIGNUM *n, BN_CTX *ctx, BN_CTX *ctx2,
  212.   	     BN_MONT_CTX *mont)
  213.   	{

crypto/bn/bn_prime.c:236:7: Call
  234.   	if (!BN_to_montgomery(mont_one,BN_value_one(),mont,ctx2)) goto err;
  235.   	if (!BN_to_montgomery(mont_n1,n1,mont,ctx2)) goto err;
  236.   	if (!BN_to_montgomery(mont_a,a,mont,ctx2)) goto err;
               ^
  237.   
  238.   	BN_copy(d,mont_one);

crypto/bn/bn_mont.c:71:1: Parameter `*b->d`
    69.   #define MONT_WORD
    70.   
    71. > int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_MONT_CTX *mont,
    72.   	     BN_CTX *ctx)
    73.   	{

crypto/bn/bn_mont.c:98:8: Call
    96.   	else
    97.   		{
    98.   		if (!BN_mul(tmp,a,b,ctx)) goto err;
                  ^
    99.   		}
    100.   	/* reduce from aRR to aR */

crypto/bn/bn_mul.c:560:1: <Offset trace>
558.   #endif
559.   
560. > int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
561.   	{
562.   	int top,al,bl;

crypto/bn/bn_mul.c:560:1: Parameter `a->top`
      558.   #endif
      559.   
      560. > int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
      561.   	{
      562.   	int top,al,bl;

crypto/bn/bn_mul.c:577:2: Assignment
      575.   	bn_check_top(r);
      576.   
      577.   	al=a->top;
              ^
      578.   	bl=b->top;
      579.   	r->neg=a->neg^b->neg;

crypto/bn/bn_mul.c:560:1: <Length trace>
558.   #endif
559.   
560. > int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
561.   	{
562.   	int top,al,bl;

crypto/bn/bn_mul.c:560:1: Parameter `*b->d`
      558.   #endif
      559.   
      560. > int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
      561.   	{
      562.   	int top,al,bl;

crypto/bn/bn_mul.c:641:4: Array access: Offset: [16, +oo] Size: [0, +oo] by call to `witness` 
      639.   			{
      640.   			bn_wexpand(b,al);
      641.   			b->d[bl]=0;
                ^
      642.   			bl++;
      643.   			goto symetric;

int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
	{
	int top,al,bl;
	BIGNUM *rr;
#ifdef BN_RECURSION
	BIGNUM *t;
	int i,j,k;
#endif
#ifdef BN_COUNT
printf("BN_mul %d * %d\n",a->top,b->top);
#endif
	bn_check_top(a);
	bn_check_top(b);
	bn_check_top(r);
	al=a->top;
	bl=b->top;
	r->neg=a->neg^b->neg;
	if ((al == 0) || (bl == 0))
		{
		BN_zero(r);
		return(1);
		}
	top=al+bl;
	if ((r == a) || (r == b))
		rr= &(ctx->bn[ctx->tos+1]);
	else
		rr=r;
#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)
	if (al == bl)
		{
#  ifdef BN_MUL_COMBA
  if (al == 8)
			{
			if (bn_wexpand(rr,16) == NULL) return(0);
			r->top=16;
			bn_mul_comba8(rr->d,a->d,b->d);
			goto end;
			}
		else
#  endif
#ifdef BN_RECURSION
		if (al < BN_MULL_SIZE_NORMAL)
#endif
			{
			if (bn_wexpand(rr,top) == NULL) return(0);
			rr->top=top;
			bn_mul_normal(rr->d,a->d,al,b->d,bl);
			goto end;
			}
#  ifdef BN_RECURSION
		goto symetric;
#  endif
		}
#endif
#ifdef BN_RECURSION
	else if ((al < BN_MULL_SIZE_NORMAL) || (bl < BN_MULL_SIZE_NORMAL))
		{
		if (bn_wexpand(rr,top) == NULL) return(0);
		rr->top=top;
		bn_mul_normal(rr->d,a->d,al,b->d,bl);
		goto end;
		}
	else
		{
		i=(al-bl);
		if ((i ==  1) && !BN_get_flags(b,BN_FLG_STATIC_DATA))
			{
			bn_wexpand(b,al);
			b->d[bl]=0;
			bl++;
			goto symetric;
			}
		else if ((i ==  -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA))
			{
			bn_wexpand(a,bl);
			a->d[al]=0;
			al++;
			goto symetric;
			}
		}
#endif
	if (bn_wexpand(rr,top) == NULL) return(0);
	rr->top=top;
	bn_mul_normal(rr->d,a->d,al,b->d,bl);
#ifdef BN_RECURSION
	if (0)
		{
symetric:
		j=BN_num_bits_word((BN_ULONG)al);
		j=1<<(j-1);
		k=j+j;
		t= &(ctx->bn[ctx->tos]);
		if (al == j)
			{
			bn_wexpand(t,k*2);
			bn_wexpand(rr,k*2);
			bn_mul_recursive(rr->d,a->d,b->d,al,t->d);
			}
		else
			{
			bn_wexpand(a,k);
			bn_wexpand(b,k);
			bn_wexpand(t,k*4);
			bn_wexpand(rr,k*4);
			for (i=a->top; i<k; i++)
				a->d[i]=0;
			for (i=b->top; i<k; i++)
				b->d[i]=0;
			bn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);
			}
		rr->top=top;
		}
#endif
#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)
end:
#endif
	bn_fix_top(rr);
	if (r != rr) BN_copy(r,rr);
	return(1);
	}
['int BN_is_prime(BIGNUM *a, int checks, void (*callback)(P_I_I_P),\n\t     BN_CTX *ctx_passed, char *cb_arg)\n\t{\n\tint i,j,c2=0,ret= -1;\n\tBIGNUM *check;\n\tBN_CTX *ctx=NULL,*ctx2=NULL;\n\tBN_MONT_CTX *mont=NULL;\n\tif (!BN_is_odd(a))\n\t\treturn(0);\n\tif (ctx_passed != NULL)\n\t\tctx=ctx_passed;\n\telse\n\t\tif ((ctx=BN_CTX_new()) == NULL) goto err;\n\tif ((ctx2=BN_CTX_new()) == NULL) goto err;\n\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\tcheck= &(ctx->bn[ctx->tos++]);\n\tif (!BN_MONT_CTX_set(mont,a,ctx2)) goto err;\n\tfor (i=0; i<checks; i++)\n\t\t{\n\t\tif (!BN_rand(check,BN_num_bits(a)-1,0,0)) goto err;\n\t\tj=witness(check,a,ctx,ctx2,mont);\n\t\tif (j == -1) goto err;\n\t\tif (j)\n\t\t\t{\n\t\t\tret=0;\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (callback != NULL) callback(1,c2++,cb_arg);\n\t\t}\n\tret=1;\nerr:\n\tctx->tos--;\n\tif ((ctx_passed == NULL) && (ctx != NULL))\n\t\tBN_CTX_free(ctx);\n\tif (ctx2 != NULL)\n\t\tBN_CTX_free(ctx2);\n\tif (mont != NULL) BN_MONT_CTX_free(mont);\n\treturn(ret);\n\t}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, BIGNUM *mod, BN_CTX *ctx)\n\t{\n\tBIGNUM Ri,*R;\n\tBN_init(&Ri);\n\tR= &(mont->RR);\n\tBN_copy(&(mont->N),mod);\n#ifdef BN_RECURSION_MONT\n\tif (mont->N.top < BN_MONT_CTX_SET_SIZE_WORD)\n#endif\n\t\t{\n\t\tBIGNUM tmod;\n\t\tBN_ULONG buf[2];\n\t\tmont->use_word=1;\n\t\tmont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;\n\t\tBN_zero(R);\n\t\tBN_set_bit(R,BN_BITS2);\n\t\tbuf[0]=mod->d[0];\n\t\tbuf[1]=0;\n\t\ttmod.d=buf;\n\t\ttmod.top=1;\n\t\ttmod.max=mod->max;\n\t\ttmod.neg=mod->neg;\n\t\tif ((BN_mod_inverse(&Ri,R,&tmod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tBN_lshift(&Ri,&Ri,BN_BITS2);\n\t\tif (!BN_is_zero(&Ri))\n\t\t\t{\n#if 1\n\t\t\tBN_sub_word(&Ri,1);\n#else\n\t\t\tBN_usub(&Ri,&Ri,BN_value_one());\n#endif\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tBN_set_word(&Ri,BN_MASK2);\n\t\t\t}\n\t\tBN_div(&Ri,NULL,&Ri,&tmod,ctx);\n\t\tmont->n0=Ri.d[0];\n\t\tBN_free(&Ri);\n\t\t}\n#ifdef BN_RECURSION_MONT\n\telse\n\t\t{\n\t\tmont->use_word=0;\n\t\tmont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;\n#if 1\n\t\tBN_zero(R);\n\t\tBN_set_bit(R,mont->ri);\n#else\n\t\tBN_lshift(R,BN_value_one(),mont->ri);\n#endif\n\t\tif ((BN_mod_inverse(&Ri,R,mod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tBN_lshift(&Ri,&Ri,mont->ri);\n#if 1\n\t\tBN_sub_word(&Ri,1);\n#else\n\t\tBN_usub(&Ri,&Ri,BN_value_one());\n#endif\n\t\tBN_div(&(mont->Ni),NULL,&Ri,mod,ctx);\n\t\tBN_free(&Ri);\n\t\t}\n#endif\n#if 1\n\tBN_zero(&(mont->RR));\n\tBN_set_bit(&(mont->RR),mont->ri*2);\n#else\n\tBN_lshift(mont->RR,BN_value_one(),mont->ri*2);\n#endif\n\tBN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx);\n\treturn(1);\nerr:\n\treturn(0);\n\t}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n\t{\n\tint i,n;\n\tif (bn_expand(a,sizeof(BN_ULONG)*8) == NULL) return(0);\n\tn=sizeof(BN_ULONG)/BN_BYTES;\n\ta->neg=0;\n\ta->top=0;\n\ta->d[0]=(BN_ULONG)w&BN_MASK2;\n\tif (a->d[0] != 0) a->top=1;\n\tfor (i=1; i<n; i++)\n\t\t{\n#ifndef SIXTY_FOUR_BIT\n\t\tw>>=BN_BITS4;\n\t\tw>>=BN_BITS4;\n#endif\n\t\ta->d[i]=(BN_ULONG)w&BN_MASK2;\n\t\tif (a->d[i] != 0) a->top=i+1;\n\t\t}\n\treturn(1);\n\t}', 'int BN_set_bit(BIGNUM *a, int n)\n\t{\n\tint i,j,k;\n\ti=n/BN_BITS2;\n\tj=n%BN_BITS2;\n\tif (a->top <= i)\n\t\t{\n\t\tif (bn_wexpand(a,i+1) == NULL) return(0);\n\t\tfor(k=a->top; k<i+1; k++)\n\t\t\ta->d[k]=0;\n\t\ta->top=i+1;\n\t\t}\n\ta->d[i]|=(1L<<j);\n\treturn(1);\n\t}', 'static int witness(BIGNUM *a, BIGNUM *n, BN_CTX *ctx, BN_CTX *ctx2,\n\t     BN_MONT_CTX *mont)\n\t{\n\tint k,i,ret= -1,good;\n\tBIGNUM *d,*dd,*tmp,*d1,*d2,*n1;\n\tBIGNUM *mont_one,*mont_n1,*mont_a;\n\td1= &(ctx->bn[ctx->tos]);\n\td2= &(ctx->bn[ctx->tos+1]);\n\tn1= &(ctx->bn[ctx->tos+2]);\n\tctx->tos+=3;\n\tmont_one= &(ctx2->bn[ctx2->tos]);\n\tmont_n1= &(ctx2->bn[ctx2->tos+1]);\n\tmont_a= &(ctx2->bn[ctx2->tos+2]);\n\tctx2->tos+=3;\n\td=d1;\n\tdd=d2;\n\tif (!BN_one(d)) goto err;\n\tif (!BN_sub(n1,n,d)) goto err;\n\tk=BN_num_bits(n1);\n\tif (!BN_to_montgomery(mont_one,BN_value_one(),mont,ctx2)) goto err;\n\tif (!BN_to_montgomery(mont_n1,n1,mont,ctx2)) goto err;\n\tif (!BN_to_montgomery(mont_a,a,mont,ctx2)) goto err;\n\tBN_copy(d,mont_one);\n\tfor (i=k-1; i>=0; i--)\n\t\t{\n\t\tif (\t(BN_cmp(d,mont_one) != 0) &&\n\t\t\t(BN_cmp(d,mont_n1) != 0))\n\t\t\tgood=1;\n\t\telse\n\t\t\tgood=0;\n\t\tBN_mod_mul_montgomery(dd,d,d,mont,ctx2);\n\t\tif (good && (BN_cmp(dd,mont_one) == 0))\n\t\t\t{\n\t\t\tret=1;\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (BN_is_bit_set(n1,i))\n\t\t\t{\n\t\t\tBN_mod_mul_montgomery(d,dd,mont_a,mont,ctx2);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\ttmp=d;\n\t\t\td=dd;\n\t\t\tdd=tmp;\n\t\t\t}\n\t\t}\n\tif (BN_cmp(d,mont_one) == 0)\n\t\ti=0;\n\telse\ti=1;\n\tret=i;\nerr:\n\tctx->tos-=3;\n\tctx2->tos-=3;\n\treturn(ret);\n\t}', 'int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_MONT_CTX *mont,\n\t     BN_CTX *ctx)\n\t{\n\tBIGNUM *tmp,*tmp2;\n        tmp= &(ctx->bn[ctx->tos]);\n        tmp2= &(ctx->bn[ctx->tos]);\n\tctx->tos+=2;\n\tbn_check_top(tmp);\n\tbn_check_top(tmp2);\n\tif (a == b)\n\t\t{\n#if 0\n\t\tbn_wexpand(tmp,a->top*2);\n\t\tbn_wexpand(tmp2,a->top*4);\n\t\tbn_sqr_recursive(tmp->d,a->d,a->top,tmp2->d);\n\t\ttmp->top=a->top*2;\n\t\tif (tmp->d[tmp->top-1] == 0)\n\t\t\ttmp->top--;\n#else\n\t\tif (!BN_sqr(tmp,a,ctx)) goto err;\n#endif\n\t\t}\n\telse\n\t\t{\n\t\tif (!BN_mul(tmp,a,b,ctx)) goto err;\n\t\t}\n\tif (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;\n\tctx->tos-=2;\n\treturn(1);\nerr:\n\treturn(0);\n\t}', 'int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint top,al,bl;\n\tBIGNUM *rr;\n#ifdef BN_RECURSION\n\tBIGNUM *t;\n\tint i,j,k;\n#endif\n#ifdef BN_COUNT\nprintf("BN_mul %d * %d\\n",a->top,b->top);\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(r);\n\tal=a->top;\n\tbl=b->top;\n\tr->neg=a->neg^b->neg;\n\tif ((al == 0) || (bl == 0))\n\t\t{\n\t\tBN_zero(r);\n\t\treturn(1);\n\t\t}\n\ttop=al+bl;\n\tif ((r == a) || (r == b))\n\t\trr= &(ctx->bn[ctx->tos+1]);\n\telse\n\t\trr=r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\tif (al == bl)\n\t\t{\n#  ifdef BN_MUL_COMBA\n  if (al == 8)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,16) == NULL) return(0);\n\t\t\tr->top=16;\n\t\t\tbn_mul_comba8(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n#  endif\n#ifdef BN_RECURSION\n\t\tif (al < BN_MULL_SIZE_NORMAL)\n#endif\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,top) == NULL) return(0);\n\t\t\trr->top=top;\n\t\t\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n\t\t\tgoto end;\n\t\t\t}\n#  ifdef BN_RECURSION\n\t\tgoto symetric;\n#  endif\n\t\t}\n#endif\n#ifdef BN_RECURSION\n\telse if ((al < BN_MULL_SIZE_NORMAL) || (bl < BN_MULL_SIZE_NORMAL))\n\t\t{\n\t\tif (bn_wexpand(rr,top) == NULL) return(0);\n\t\trr->top=top;\n\t\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n\t\tgoto end;\n\t\t}\n\telse\n\t\t{\n\t\ti=(al-bl);\n\t\tif ((i ==  1) && !BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(b,al);\n\t\t\tb->d[bl]=0;\n\t\t\tbl++;\n\t\t\tgoto symetric;\n\t\t\t}\n\t\telse if ((i ==  -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(a,bl);\n\t\t\ta->d[al]=0;\n\t\t\tal++;\n\t\t\tgoto symetric;\n\t\t\t}\n\t\t}\n#endif\n\tif (bn_wexpand(rr,top) == NULL) return(0);\n\trr->top=top;\n\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n#ifdef BN_RECURSION\n\tif (0)\n\t\t{\nsymetric:\n\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\tj=1<<(j-1);\n\t\tk=j+j;\n\t\tt= &(ctx->bn[ctx->tos]);\n\t\tif (al == j)\n\t\t\t{\n\t\t\tbn_wexpand(t,k*2);\n\t\t\tbn_wexpand(rr,k*2);\n\t\t\tbn_mul_recursive(rr->d,a->d,b->d,al,t->d);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tbn_wexpand(a,k);\n\t\t\tbn_wexpand(b,k);\n\t\t\tbn_wexpand(t,k*4);\n\t\t\tbn_wexpand(rr,k*4);\n\t\t\tfor (i=a->top; i<k; i++)\n\t\t\t\ta->d[i]=0;\n\t\t\tfor (i=b->top; i<k; i++)\n\t\t\t\tb->d[i]=0;\n\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);\n\t\t\t}\n\t\trr->top=top;\n\t\t}\n#endif\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\nend:\n#endif\n\tbn_fix_top(rr);\n\tif (r != rr) BN_copy(r,rr);\n\treturn(1);\n\t}']