crypto/dsa/dsa_gen.c:578: error: INTEGER_OVERFLOW_L2
  ([0, `N`] - 1):unsigned32 by call to `BN_bin2bn`.
Showing all 7 steps of the trace


crypto/dsa/dsa_gen.c:453:1: Parameter `N`
451.    */
452.   
453. > int dsa_builtin_paramgen2(DSA *ret, size_t L, size_t N,
454.   	const EVP_MD *evpmd, const unsigned char *seed_in, size_t seed_len,
455.   	int idx, unsigned char *seed_out,

crypto/dsa/dsa_gen.c:465:2: Assignment
463.   	BIGNUM *g=NULL,*q=NULL,*p=NULL;
464.   	BN_MONT_CTX *mont=NULL;
465.   	int i, k, n=0, m=0, qsize = N >> 3;
        ^
466.   	int counter=0;
467.   	int r=0;

crypto/dsa/dsa_gen.c:578:9: Call
576.   			pmd[0] |= 0x80;
577.   			pmd[qsize-1] |= 0x01;
578.   			if (!BN_bin2bn(pmd, qsize, q))
               ^
579.   				goto err;
580.   

crypto/bn/bn_lib.c:580:1: <LHS trace>
578.   	}
579.   
580. > BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
581.   	{
582.   	unsigned int i,m;

crypto/bn/bn_lib.c:580:1: Parameter `len`
  578.   	}
  579.   
  580. > BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
  581.   	{
  582.   	unsigned int i,m;

crypto/bn/bn_lib.c:592:2: Assignment
  590.   	bn_check_top(ret);
  591.   	l=0;
  592.   	n=len;
          ^
  593.   	if (n == 0)
  594.   		{

crypto/bn/bn_lib.c:598:2: Binary operation: ([0, N] - 1):unsigned32 by call to `BN_bin2bn` 
  596.   		return(ret);
  597.   		}
  598.   	i=((n-1)/BN_BYTES)+1;
          ^
  599.   	m=((n-1)%(BN_BYTES));
  600.   	if (bn_wexpand(ret, (int)i) == NULL)

BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
	{
	unsigned int i,m;
	unsigned int n;
	BN_ULONG l;
	BIGNUM  *bn = NULL;
	if (ret == NULL)
		ret = bn = BN_new();
	if (ret == NULL) return(NULL);
	bn_check_top(ret);
	l=0;
	n=len;
	if (n == 0)
		{
		ret->top=0;
		return(ret);
		}
	i=((n-1)/BN_BYTES)+1;
	m=((n-1)%(BN_BYTES));
	if (bn_wexpand(ret, (int)i) == NULL)
		{
		if (bn) BN_free(bn);
		return NULL;
		}
	ret->top=i;
	ret->neg=0;
	while (n--)
		{
		l=(l<<8L)| *(s++);
		if (m-- == 0)
			{
			ret->d[--i]=l;
			l=0;
			m=BN_BYTES-1;
			}
		}
	bn_correct_top(ret);
	return(ret);
	}
['int dsa_builtin_paramgen2(DSA *ret, size_t L, size_t N,\n\tconst EVP_MD *evpmd, const unsigned char *seed_in, size_t seed_len,\n\tint idx, unsigned char *seed_out,\n\tint *counter_ret, unsigned long *h_ret, BN_GENCB *cb)\n\t{\n\tint ok=-1;\n\tunsigned char *seed = NULL, *seed_tmp = NULL;\n\tunsigned char md[EVP_MAX_MD_SIZE];\n\tint mdsize;\n\tBIGNUM *r0,*W,*X,*c,*test;\n\tBIGNUM *g=NULL,*q=NULL,*p=NULL;\n\tBN_MONT_CTX *mont=NULL;\n\tint i, k, n=0, m=0, qsize = N >> 3;\n\tint counter=0;\n\tint r=0;\n\tBN_CTX *ctx=NULL;\n\tEVP_MD_CTX mctx;\n\tunsigned int h=2;\n\tEVP_MD_CTX_init(&mctx);\n#ifdef OPENSSL_FIPS\n\tif(FIPS_selftest_failed())\n\t    {\n\t    FIPSerr(FIPS_F_DSA_BUILTIN_PARAMGEN2,\n\t\t    FIPS_R_FIPS_SELFTEST_FAILED);\n\t    goto err;\n\t    }\n\tif (!fips_check_dsa_prng(ret, L, N))\n\t\tgoto err;\n#endif\n\tif (evpmd == NULL)\n\t\t{\n\t\tif (N == 160)\n\t\t\tevpmd = EVP_sha1();\n\t\telse if (N == 224)\n\t\t\tevpmd = EVP_sha224();\n\t\telse\n\t\t\tevpmd = EVP_sha256();\n\t\t}\n\tmdsize = M_EVP_MD_size(evpmd);\n\tif (!ret->p || !ret->q || idx >= 0)\n\t\t{\n\t\tif (seed_len == 0)\n\t\t\tseed_len = mdsize;\n\t\tseed = OPENSSL_malloc(seed_len);\n\t\tif (seed_out)\n\t\t\tseed_tmp = seed_out;\n\t\telse\n\t\t\tseed_tmp = OPENSSL_malloc(seed_len);\n\t\tif (!seed || !seed_tmp)\n\t\t\tgoto err;\n\t\tif (seed_in)\n\t\t\tmemcpy(seed, seed_in, seed_len);\n\t\t}\n\tif ((ctx=BN_CTX_new()) == NULL)\n\t\tgoto err;\n\tif ((mont=BN_MONT_CTX_new()) == NULL)\n\t\tgoto err;\n\tBN_CTX_start(ctx);\n\tr0 = BN_CTX_get(ctx);\n\tg = BN_CTX_get(ctx);\n\tW = BN_CTX_get(ctx);\n\tX = BN_CTX_get(ctx);\n\tc = BN_CTX_get(ctx);\n\ttest = BN_CTX_get(ctx);\n\tif (ret->p && ret->q)\n\t\t{\n\t\tp = ret->p;\n\t\tq = ret->q;\n\t\tif (idx >= 0)\n\t\t\tmemcpy(seed_tmp, seed, seed_len);\n\t\tgoto g_only;\n\t\t}\n\telse\n\t\t{\n\t\tp = BN_CTX_get(ctx);\n\t\tq = BN_CTX_get(ctx);\n\t\t}\n\tif (!BN_lshift(test,BN_value_one(),L-1))\n\t\tgoto err;\n\tfor (;;)\n\t\t{\n\t\tfor (;;)\n\t\t\t{\n\t\t\tunsigned char *pmd;\n\t\t\tif(!BN_GENCB_call(cb, 0, m++))\n\t\t\t\tgoto err;\n\t\t\tif (!seed_in)\n\t\t\t\t{\n\t\t\t\tif (RAND_pseudo_bytes(seed, seed_len) < 0)\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tif (!EVP_Digest(seed, seed_len, md, NULL, evpmd, NULL))\n\t\t\t\tgoto err;\n\t\t\tif (mdsize > qsize)\n\t\t\t\tpmd = md + mdsize - qsize;\n\t\t\telse\n\t\t\t\tpmd = md;\n\t\t\tif (mdsize < qsize)\n\t\t\t\tmemset(md + mdsize, 0, qsize - mdsize);\n\t\t\tpmd[0] |= 0x80;\n\t\t\tpmd[qsize-1] |= 0x01;\n\t\t\tif (!BN_bin2bn(pmd, qsize, q))\n\t\t\t\tgoto err;\n\t\t\tr = BN_is_prime_fasttest_ex(q, DSS_prime_checks, ctx,\n\t\t\t\t\tseed_in ? 1 : 0, cb);\n\t\t\tif (r > 0)\n\t\t\t\tbreak;\n\t\t\tif (r != 0)\n\t\t\t\tgoto err;\n\t\t\tif (seed_in)\n\t\t\t\t{\n\t\t\t\tok = 0;\n\t\t\t\tDSAerr(DSA_F_DSA_BUILTIN_PARAMGEN2, DSA_R_Q_NOT_PRIME);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n\t\tif (seed_out)\n\t\t\tmemcpy(seed_out, seed, seed_len);\n\t\tif(!BN_GENCB_call(cb, 2, 0)) goto err;\n\t\tif(!BN_GENCB_call(cb, 3, 0)) goto err;\n\t\tcounter=0;\n\t\tn=(L-1)/(mdsize << 3);\n\t\tfor (;;)\n\t\t\t{\n\t\t\tif ((counter != 0) && !BN_GENCB_call(cb, 0, counter))\n\t\t\t\tgoto err;\n\t\t\tBN_zero(W);\n\t\t\tfor (k=0; k<=n; k++)\n\t\t\t\t{\n\t\t\t\tfor (i = seed_len-1; i >= 0; i--)\n\t\t\t\t\t{\n\t\t\t\t\tseed[i]++;\n\t\t\t\t\tif (seed[i] != 0)\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\tif (!EVP_Digest(seed, seed_len, md ,NULL, evpmd,\n\t\t\t\t\t\t\t\t\tNULL))\n\t\t\t\t\tgoto err;\n\t\t\t\tif (!BN_bin2bn(md, mdsize, r0))\n\t\t\t\t\tgoto err;\n\t\t\t\tif (!BN_lshift(r0,r0,(mdsize << 3)*k)) goto err;\n\t\t\t\tif (!BN_add(W,W,r0)) goto err;\n\t\t\t\t}\n\t\t\tif (!BN_mask_bits(W,L-1)) goto err;\n\t\t\tif (!BN_copy(X,W)) goto err;\n\t\t\tif (!BN_add(X,X,test)) goto err;\n\t\t\tif (!BN_lshift1(r0,q)) goto err;\n\t\t\tif (!BN_mod(c,X,r0,ctx)) goto err;\n\t\t\tif (!BN_sub(r0,c,BN_value_one())) goto err;\n\t\t\tif (!BN_sub(p,X,r0)) goto err;\n\t\t\tif (BN_cmp(p,test) >= 0)\n\t\t\t\t{\n\t\t\t\tr = BN_is_prime_fasttest_ex(p, DSS_prime_checks,\n\t\t\t\t\t\tctx, 1, cb);\n\t\t\t\tif (r > 0)\n\t\t\t\t\t\tgoto end;\n\t\t\t\tif (r != 0)\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tcounter++;\n\t\t\tif (counter >= 4096) break;\n\t\t\t}\n\t\t}\nend:\n\tif(!BN_GENCB_call(cb, 2, 1))\n\t\tgoto err;\n\tg_only:\n\tif (!BN_sub(test,p,BN_value_one())) goto err;\n\tif (!BN_div(r0,NULL,test,q,ctx)) goto err;\n\tif (idx < 0)\n\t\t{\n\t\tif (!BN_set_word(test,h))\n\t\t\tgoto err;\n\t\t}\n\telse\n\t\th = 1;\n\tif (!BN_MONT_CTX_set(mont,p,ctx)) goto err;\n\tfor (;;)\n\t\t{\n\t\tstatic const unsigned char ggen[4] = {0x67,0x67,0x65,0x6e};\n\t\tif (idx >= 0)\n\t\t\t{\n\t\t\tmd[0] = idx & 0xff;\n\t\t\tmd[1] = (h >> 8) & 0xff;\n\t\t\tmd[2] = h & 0xff;\n\t\t\tif (!EVP_DigestInit_ex(&mctx, evpmd, NULL))\n\t\t\t\tgoto err;\n\t\t\tif (!EVP_DigestUpdate(&mctx, seed_tmp, seed_len))\n\t\t\t\tgoto err;\n\t\t\tif (!EVP_DigestUpdate(&mctx, ggen, sizeof(ggen)))\n\t\t\t\tgoto err;\n\t\t\tif (!EVP_DigestUpdate(&mctx, md, 3))\n\t\t\t\tgoto err;\n\t\t\tif (!EVP_DigestFinal_ex(&mctx, md, NULL))\n\t\t\t\tgoto err;\n\t\t\tif (!BN_bin2bn(md, mdsize, test))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\tif (!BN_mod_exp_mont(g,test,r0,p,ctx,mont)) goto err;\n\t\tif (!BN_is_one(g)) break;\n\t\tif (idx < 0 && !BN_add(test,test,BN_value_one())) goto err;\n\t\th++;\n\t\tif ( idx >= 0 && h > 0xffff)\n\t\t\tgoto err;\n\t\t}\n\tif(!BN_GENCB_call(cb, 3, 1))\n\t\tgoto err;\n\tok=1;\nerr:\n\tif (ok == 1)\n\t\t{\n\t\tif (p != ret->p)\n\t\t\t{\n\t\t\tif(ret->p) BN_free(ret->p);\n\t\t\tret->p=BN_dup(p);\n\t\t\t}\n\t\tif (q != ret->q)\n\t\t\t{\n\t\t\tif(ret->q) BN_free(ret->q);\n\t\t\tret->q=BN_dup(q);\n\t\t\t}\n\t\tif(ret->g) BN_free(ret->g);\n\t\tret->g=BN_dup(g);\n\t\tif (ret->p == NULL || ret->q == NULL || ret->g == NULL)\n\t\t\t{\n\t\t\tok=-1;\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (counter_ret != NULL) *counter_ret=counter;\n\t\tif (h_ret != NULL) *h_ret=h;\n\t\t}\n\tif (seed)\n\t\tOPENSSL_free(seed);\n\tif (seed_out != seed_tmp)\n\t\tOPENSSL_free(seed_tmp);\n\tif(ctx)\n\t\t{\n\t\tBN_CTX_end(ctx);\n\t\tBN_CTX_free(ctx);\n\t\t}\n\tif (mont != NULL) BN_MONT_CTX_free(mont);\n\tEVP_MD_CTX_cleanup(&mctx);\n\treturn ok;\n\t}', 'BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)\n\t{\n\tunsigned int i,m;\n\tunsigned int n;\n\tBN_ULONG l;\n\tBIGNUM  *bn = NULL;\n\tif (ret == NULL)\n\t\tret = bn = BN_new();\n\tif (ret == NULL) return(NULL);\n\tbn_check_top(ret);\n\tl=0;\n\tn=len;\n\tif (n == 0)\n\t\t{\n\t\tret->top=0;\n\t\treturn(ret);\n\t\t}\n\ti=((n-1)/BN_BYTES)+1;\n\tm=((n-1)%(BN_BYTES));\n\tif (bn_wexpand(ret, (int)i) == NULL)\n\t\t{\n\t\tif (bn) BN_free(bn);\n\t\treturn NULL;\n\t\t}\n\tret->top=i;\n\tret->neg=0;\n\twhile (n--)\n\t\t{\n\t\tl=(l<<8L)| *(s++);\n\t\tif (m-- == 0)\n\t\t\t{\n\t\t\tret->d[--i]=l;\n\t\t\tl=0;\n\t\t\tm=BN_BYTES-1;\n\t\t\t}\n\t\t}\n\tbn_correct_top(ret);\n\treturn(ret);\n\t}']