apps/dh.c:266: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - 1):unsigned64 by call to `DH_check`.
Showing all 10 steps of the trace


apps/dh.c:252:3: Call
250.   	if (text)
251.   		{
252.   		DHparams_print(out,dh);
         ^
253.   #ifdef undef
254.   		printf("p=");

crypto/dh/dh_ameth.c:464:1: Parameter `x->pub_key->top`
  462.   	}
  463.   
  464. > int DHparams_print(BIO *bp, const DH *x)
  465.   	{
  466.   	return do_dh_print(bp, x, 4, NULL, 0);

crypto/dh/dh_ameth.c:466:9: Call
  464.   int DHparams_print(BIO *bp, const DH *x)
  465.   	{
  466.   	return do_dh_print(bp, x, 4, NULL, 0);
                 ^
  467.   	}
  468.   

crypto/dh/dh_ameth.c:316:1: Parameter `x->pub_key->top`
    314.   	}
    315.   
    316. > static int do_dh_print(BIO *bp, const DH *x, int indent,
    317.   						ASN1_PCTX *ctx, int ptype)
    318.   	{

apps/dh.c:266:8: Call
264.   	if (check)
265.   		{
266.   		if (!DH_check(dh,&i))
              ^
267.   			{
268.   			ERR_print_errors(bio_err);

crypto/dh/dh_check.c:73:1: Parameter `dh->p->top`
  71.    */
  72.   
  73. > int DH_check(const DH *dh, int *ret)
  74.   	{
  75.   	int ok=0;

crypto/dh/dh_check.c:88:5: Call
  86.   	if (BN_is_word(dh->g,DH_GENERATOR_2))
  87.   		{
  88.   		l=BN_mod_word(dh->p,24);
            ^
  89.   		if (l != 11) *ret|=DH_NOT_SUITABLE_GENERATOR;
  90.   		}

crypto/bn/bn_word.c:63:1: <LHS trace>
61.   #include "bn_lcl.h"
62.   
63. > BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w)
64.   	{
65.   #ifndef BN_LLONG

crypto/bn/bn_word.c:63:1: Parameter `a->top`
    61.   #include "bn_lcl.h"
    62.   
    63. > BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w)
    64.   	{
    65.   #ifndef BN_LLONG

crypto/bn/bn_word.c:77:7: Binary operation: ([0, +oo] - 1):unsigned64 by call to `DH_check` 
    75.   	bn_check_top(a);
    76.   	w&=BN_MASK2;
    77.   	for (i=a->top-1; i>=0; i--)
                ^
    78.   		{
    79.   #ifndef BN_LLONG

BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w)
	{
#ifndef BN_LLONG
	BN_ULONG ret=0;
#else
	BN_ULLONG ret=0;
#endif
	int i;
	if (w == 0)
		return (BN_ULONG)-1;
	bn_check_top(a);
	w&=BN_MASK2;
	for (i=a->top-1; i>=0; i--)
		{
#ifndef BN_LLONG
		ret=((ret<<BN_BITS4)|((a->d[i]>>BN_BITS4)&BN_MASK2l))%w;
		ret=((ret<<BN_BITS4)|(a->d[i]&BN_MASK2l))%w;
#else
		ret=(BN_ULLONG)(((ret<<(BN_ULLONG)BN_BITS2)|a->d[i])%
			(BN_ULLONG)w);
#endif
		}
	return((BN_ULONG)ret);
	}
['int MAIN(int argc, char **argv)\n\t{\n#ifndef OPENSSL_NO_ENGINE\n\tENGINE *e = NULL;\n#endif\n\tDH *dh=NULL;\n\tint i,badops=0,text=0;\n\tBIO *in=NULL,*out=NULL;\n\tint informat,outformat,check=0,noout=0,C=0,ret=1;\n\tchar *infile,*outfile,*prog;\n#ifndef OPENSSL_NO_ENGINE\n\tchar *engine;\n#endif\n\tapps_startup();\n\tif (bio_err == NULL)\n\t\tif ((bio_err=BIO_new(BIO_s_file())) != NULL)\n\t\t\tBIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);\n\tif (!load_config(bio_err, NULL))\n\t\tgoto end;\n#ifndef OPENSSL_NO_ENGINE\n\tengine=NULL;\n#endif\n\tinfile=NULL;\n\toutfile=NULL;\n\tinformat=FORMAT_PEM;\n\toutformat=FORMAT_PEM;\n\tprog=argv[0];\n\targc--;\n\targv++;\n\twhile (argc >= 1)\n\t\t{\n\t\tif \t(strcmp(*argv,"-inform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tinformat=str2fmt(*(++argv));\n\t\t\t}\n\t\telse if (strcmp(*argv,"-outform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\toutformat=str2fmt(*(++argv));\n\t\t\t}\n\t\telse if (strcmp(*argv,"-in") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tinfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-out") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\toutfile= *(++argv);\n\t\t\t}\n#ifndef OPENSSL_NO_ENGINE\n\t\telse if (strcmp(*argv,"-engine") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tengine= *(++argv);\n\t\t\t}\n#endif\n\t\telse if (strcmp(*argv,"-check") == 0)\n\t\t\tcheck=1;\n\t\telse if (strcmp(*argv,"-text") == 0)\n\t\t\ttext=1;\n\t\telse if (strcmp(*argv,"-C") == 0)\n\t\t\tC=1;\n\t\telse if (strcmp(*argv,"-noout") == 0)\n\t\t\tnoout=1;\n\t\telse\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unknown option %s\\n",*argv);\n\t\t\tbadops=1;\n\t\t\tbreak;\n\t\t\t}\n\t\targc--;\n\t\targv++;\n\t\t}\n\tif (badops)\n\t\t{\nbad:\n\t\tBIO_printf(bio_err,"%s [options] <infile >outfile\\n",prog);\n\t\tBIO_printf(bio_err,"where options are\\n");\n\t\tBIO_printf(bio_err," -inform arg   input format - one of DER PEM\\n");\n\t\tBIO_printf(bio_err," -outform arg  output format - one of DER PEM\\n");\n\t\tBIO_printf(bio_err," -in arg       input file\\n");\n\t\tBIO_printf(bio_err," -out arg      output file\\n");\n\t\tBIO_printf(bio_err," -check        check the DH parameters\\n");\n\t\tBIO_printf(bio_err," -text         print a text form of the DH parameters\\n");\n\t\tBIO_printf(bio_err," -C            Output C code\\n");\n\t\tBIO_printf(bio_err," -noout        no output\\n");\n#ifndef OPENSSL_NO_ENGINE\n\t\tBIO_printf(bio_err," -engine e     use engine e, possibly a hardware device.\\n");\n#endif\n\t\tgoto end;\n\t\t}\n\tERR_load_crypto_strings();\n#ifndef OPENSSL_NO_ENGINE\n        e = setup_engine(bio_err, engine, 0);\n#endif\n\tin=BIO_new(BIO_s_file());\n\tout=BIO_new(BIO_s_file());\n\tif ((in == NULL) || (out == NULL))\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tif (infile == NULL)\n\t\tBIO_set_fp(in,stdin,BIO_NOCLOSE);\n\telse\n\t\t{\n\t\tif (BIO_read_filename(in,infile) <= 0)\n\t\t\t{\n\t\t\tperror(infile);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tif (outfile == NULL)\n\t\t{\n\t\tBIO_set_fp(out,stdout,BIO_NOCLOSE);\n#ifdef OPENSSL_SYS_VMS\n\t\t{\n\t\tBIO *tmpbio = BIO_new(BIO_f_linebuffer());\n\t\tout = BIO_push(tmpbio, out);\n\t\t}\n#endif\n\t\t}\n\telse\n\t\t{\n\t\tif (BIO_write_filename(out,outfile) <= 0)\n\t\t\t{\n\t\t\tperror(outfile);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tif\t(informat == FORMAT_ASN1)\n\t\tdh=d2i_DHparams_bio(in,NULL);\n\telse if (informat == FORMAT_PEM)\n\t\tdh=PEM_read_bio_DHparams(in,NULL,NULL,NULL);\n\telse\n\t\t{\n\t\tBIO_printf(bio_err,"bad input format specified\\n");\n\t\tgoto end;\n\t\t}\n\tif (dh == NULL)\n\t\t{\n\t\tBIO_printf(bio_err,"unable to load DH parameters\\n");\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tif (text)\n\t\t{\n\t\tDHparams_print(out,dh);\n#ifdef undef\n\t\tprintf("p=");\n\t\tBN_print(stdout,dh->p);\n\t\tprintf("\\ng=");\n\t\tBN_print(stdout,dh->g);\n\t\tprintf("\\n");\n\t\tif (dh->length != 0)\n\t\t\tprintf("recommended private length=%ld\\n",dh->length);\n#endif\n\t\t}\n\tif (check)\n\t\t{\n\t\tif (!DH_check(dh,&i))\n\t\t\t{\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (i & DH_CHECK_P_NOT_PRIME)\n\t\t\tprintf("p value is not prime\\n");\n\t\tif (i & DH_CHECK_P_NOT_SAFE_PRIME)\n\t\t\tprintf("p value is not a safe prime\\n");\n\t\tif (i & DH_UNABLE_TO_CHECK_GENERATOR)\n\t\t\tprintf("unable to check the generator value\\n");\n\t\tif (i & DH_NOT_SUITABLE_GENERATOR)\n\t\t\tprintf("the g value is not a generator\\n");\n\t\tif (i == 0)\n\t\t\tprintf("DH parameters appear to be ok.\\n");\n\t\t}\n\tif (C)\n\t\t{\n\t\tunsigned char *data;\n\t\tint len,l,bits;\n\t\tlen=BN_num_bytes(dh->p);\n\t\tbits=BN_num_bits(dh->p);\n\t\tdata=(unsigned char *)OPENSSL_malloc(len);\n\t\tif (data == NULL)\n\t\t\t{\n\t\t\tperror("OPENSSL_malloc");\n\t\t\tgoto end;\n\t\t\t}\n\t\tl=BN_bn2bin(dh->p,data);\n\t\tprintf("static unsigned char dh%d_p[]={",bits);\n\t\tfor (i=0; i<l; i++)\n\t\t\t{\n\t\t\tif ((i%12) == 0) printf("\\n\\t");\n\t\t\tprintf("0x%02X,",data[i]);\n\t\t\t}\n\t\tprintf("\\n\\t};\\n");\n\t\tl=BN_bn2bin(dh->g,data);\n\t\tprintf("static unsigned char dh%d_g[]={",bits);\n\t\tfor (i=0; i<l; i++)\n\t\t\t{\n\t\t\tif ((i%12) == 0) printf("\\n\\t");\n\t\t\tprintf("0x%02X,",data[i]);\n\t\t\t}\n\t\tprintf("\\n\\t};\\n\\n");\n\t\tprintf("DH *get_dh%d()\\n\\t{\\n",bits);\n\t\tprintf("\\tDH *dh;\\n\\n");\n\t\tprintf("\\tif ((dh=DH_new()) == NULL) return(NULL);\\n");\n\t\tprintf("\\tdh->p=BN_bin2bn(dh%d_p,sizeof(dh%d_p),NULL);\\n",\n\t\t\tbits,bits);\n\t\tprintf("\\tdh->g=BN_bin2bn(dh%d_g,sizeof(dh%d_g),NULL);\\n",\n\t\t\tbits,bits);\n\t\tprintf("\\tif ((dh->p == NULL) || (dh->g == NULL))\\n");\n\t\tprintf("\\t\\treturn(NULL);\\n");\n\t\tprintf("\\treturn(dh);\\n\\t}\\n");\n\t\tOPENSSL_free(data);\n\t\t}\n\tif (!noout)\n\t\t{\n\t\tif \t(outformat == FORMAT_ASN1)\n\t\t\ti=i2d_DHparams_bio(out,dh);\n\t\telse if (outformat == FORMAT_PEM)\n\t\t\ti=PEM_write_bio_DHparams(out,dh);\n\t\telse\t{\n\t\t\tBIO_printf(bio_err,"bad output format specified for outfile\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (!i)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unable to write DH parameters\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tret=0;\nend:\n\tif (in != NULL) BIO_free(in);\n\tif (out != NULL) BIO_free_all(out);\n\tif (dh != NULL) DH_free(dh);\n\tapps_shutdown();\n\tOPENSSL_EXIT(ret);\n\t}', 'int DHparams_print(BIO *bp, const DH *x)\n\t{\n\treturn do_dh_print(bp, x, 4, NULL, 0);\n\t}', 'static int do_dh_print(BIO *bp, const DH *x, int indent,\n\t\t\t\t\t\tASN1_PCTX *ctx, int ptype)\n\t{\n\tunsigned char *m=NULL;\n\tint reason=ERR_R_BUF_LIB,ret=0;\n\tsize_t buf_len=0;\n\tconst char *ktype = NULL;\n\tBIGNUM *priv_key, *pub_key;\n\tif (ptype == 2)\n\t\tpriv_key = x->priv_key;\n\telse\n\t\tpriv_key = NULL;\n\tif (ptype > 0)\n\t\tpub_key = x->pub_key;\n\telse\n\t\tpub_key = NULL;\n\tupdate_buflen(x->p, &buf_len);\n\tif (buf_len == 0)\n\t\t{\n\t\treason = ERR_R_PASSED_NULL_PARAMETER;\n\t\tgoto err;\n\t\t}\n\tupdate_buflen(x->g, &buf_len);\n\tupdate_buflen(pub_key, &buf_len);\n\tupdate_buflen(priv_key, &buf_len);\n\tif (ptype == 2)\n\t\tktype = "PKCS#3 DH Private-Key";\n\telse if (ptype == 1)\n\t\tktype = "PKCS#3 DH Public-Key";\n\telse\n\t\tktype = "PKCS#3 DH Parameters";\n\tm= OPENSSL_malloc(buf_len+10);\n\tif (m == NULL)\n\t\t{\n\t\treason=ERR_R_MALLOC_FAILURE;\n\t\tgoto err;\n\t\t}\n\tBIO_indent(bp, indent, 128);\n\tif (BIO_printf(bp,"%s: (%d bit)\\n", ktype, BN_num_bits(x->p)) <= 0)\n\t\tgoto err;\n\tindent += 4;\n\tif (!ASN1_bn_print(bp,"private-key:",priv_key,m,indent)) goto err;\n\tif (!ASN1_bn_print(bp,"public-key:",pub_key,m,indent)) goto err;\n\tif (!ASN1_bn_print(bp,"prime:",x->p,m,indent)) goto err;\n\tif (!ASN1_bn_print(bp,"generator:",x->g,m,indent)) goto err;\n\tif (x->length != 0)\n\t\t{\n\t\tBIO_indent(bp, indent, 128);\n\t\tif (BIO_printf(bp,"recommended-private-length: %d bits\\n",\n\t\t\t(int)x->length) <= 0) goto err;\n\t\t}\n\tret=1;\n\tif (0)\n\t\t{\nerr:\n\t\tDHerr(DH_F_DO_DH_PRINT,reason);\n\t\t}\n\tif (m != NULL) OPENSSL_free(m);\n\treturn(ret);\n\t}', 'int DH_check(const DH *dh, int *ret)\n\t{\n\tint ok=0;\n\tBN_CTX *ctx=NULL;\n\tBN_ULONG l;\n\tBIGNUM *q=NULL;\n\t*ret=0;\n\tctx=BN_CTX_new();\n\tif (ctx == NULL) goto err;\n\tq=BN_new();\n\tif (q == NULL) goto err;\n\tif (BN_is_word(dh->g,DH_GENERATOR_2))\n\t\t{\n\t\tl=BN_mod_word(dh->p,24);\n\t\tif (l != 11) *ret|=DH_NOT_SUITABLE_GENERATOR;\n\t\t}\n#if 0\n\telse if (BN_is_word(dh->g,DH_GENERATOR_3))\n\t\t{\n\t\tl=BN_mod_word(dh->p,12);\n\t\tif (l != 5) *ret|=DH_NOT_SUITABLE_GENERATOR;\n\t\t}\n#endif\n\telse if (BN_is_word(dh->g,DH_GENERATOR_5))\n\t\t{\n\t\tl=BN_mod_word(dh->p,10);\n\t\tif ((l != 3) && (l != 7))\n\t\t\t*ret|=DH_NOT_SUITABLE_GENERATOR;\n\t\t}\n\telse\n\t\t*ret|=DH_UNABLE_TO_CHECK_GENERATOR;\n\tif (!BN_is_prime_ex(dh->p,BN_prime_checks,ctx,NULL))\n\t\t*ret|=DH_CHECK_P_NOT_PRIME;\n\telse\n\t\t{\n\t\tif (!BN_rshift1(q,dh->p)) goto err;\n\t\tif (!BN_is_prime_ex(q,BN_prime_checks,ctx,NULL))\n\t\t\t*ret|=DH_CHECK_P_NOT_SAFE_PRIME;\n\t\t}\n\tok=1;\nerr:\n\tif (ctx != NULL) BN_CTX_free(ctx);\n\tif (q != NULL) BN_free(q);\n\treturn(ok);\n\t}', 'BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w)\n\t{\n#ifndef BN_LLONG\n\tBN_ULONG ret=0;\n#else\n\tBN_ULLONG ret=0;\n#endif\n\tint i;\n\tif (w == 0)\n\t\treturn (BN_ULONG)-1;\n\tbn_check_top(a);\n\tw&=BN_MASK2;\n\tfor (i=a->top-1; i>=0; i--)\n\t\t{\n#ifndef BN_LLONG\n\t\tret=((ret<<BN_BITS4)|((a->d[i]>>BN_BITS4)&BN_MASK2l))%w;\n\t\tret=((ret<<BN_BITS4)|(a->d[i]&BN_MASK2l))%w;\n#else\n\t\tret=(BN_ULLONG)(((ret<<(BN_ULLONG)BN_BITS2)|a->d[i])%\n\t\t\t(BN_ULLONG)w);\n#endif\n\t\t}\n\treturn((BN_ULONG)ret);\n\t}']