engines/ccgost/gost_ameth.c:518: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - 1):unsigned64 by call to `gost94_compute_public`.
Showing all 22 steps of the trace


engines/ccgost/gost_ameth.c:513:2: Call
511.   		}	
512.   #define COPYBIGNUM(a,b,x) if (a->x) BN_free(a->x); a->x=BN_dup(b->x);	
513.   	COPYBIGNUM(dto,dfrom,p)
        ^
514.   		COPYBIGNUM(dto,dfrom,q)
515.   		COPYBIGNUM(dto,dfrom,g)

crypto/bn/bn_lib.c:479:1: Parameter `a->top`
  477.   	}
  478.   
  479. > BIGNUM *BN_dup(const BIGNUM *a)
  480.   	{
  481.   	BIGNUM *t;

engines/ccgost/gost_ameth.c:514:3: Call
512.   #define COPYBIGNUM(a,b,x) if (a->x) BN_free(a->x); a->x=BN_dup(b->x);	
513.   	COPYBIGNUM(dto,dfrom,p)
514.   		COPYBIGNUM(dto,dfrom,q)
         ^
515.   		COPYBIGNUM(dto,dfrom,g)
516.   

crypto/bn/bn_lib.c:479:1: Parameter `a->top`
  477.   	}
  478.   
  479. > BIGNUM *BN_dup(const BIGNUM *a)
  480.   	{
  481.   	BIGNUM *t;

engines/ccgost/gost_ameth.c:515:3: Call
513.   	COPYBIGNUM(dto,dfrom,p)
514.   		COPYBIGNUM(dto,dfrom,q)
515.   		COPYBIGNUM(dto,dfrom,g)
         ^
516.   
517.   		if (dto->priv_key) 

crypto/bn/bn_lib.c:479:1: Parameter `a->top`
  477.   	}
  478.   
  479. > BIGNUM *BN_dup(const BIGNUM *a)
  480.   	{
  481.   	BIGNUM *t;

engines/ccgost/gost_ameth.c:518:4: Call
516.   
517.   		if (dto->priv_key) 
518.   			gost94_compute_public(dto);
          ^
519.   	return 1;	
520.   	}

engines/ccgost/gost_sign.c:194:1: Parameter `dsa->g->top`
  192.    *
  193.    */
  194. > int gost94_compute_public(DSA *dsa)
  195.   	{
  196.   	/* Now fill algorithm parameters with correct values */

engines/ccgost/gost_sign.c:205:2: Call
  203.   	/* Compute public key  y = a^x mod p */
  204.   	dsa->pub_key=BN_new();
  205.   	BN_mod_exp(dsa->pub_key, dsa->g,dsa->priv_key,dsa->p,ctx);
          ^
  206.   	BN_CTX_free(ctx);
  207.   	return 1;

crypto/bn/bn_exp.c:163:1: Parameter `a->top`
    161.   
    162.   
    163. > int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
    164.   	       BN_CTX *ctx)
    165.   	{

crypto/bn/bn_exp.c:223:8: Call
    221.   		else
    222.   #  endif
    223.   			ret=BN_mod_exp_mont(r,a,p,m,ctx,NULL);
                  ^
    224.   		}
    225.   	else

crypto/bn/bn_exp.c:371:1: Parameter `a->top`
      369.   
      370.   
      371. > int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
      372.   		    const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)
      373.   	{

crypto/bn/bn_exp.c:384:10: Call
      382.   	if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0)
      383.   		{
      384.   		return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);
                      ^
      385.   		}
      386.   

crypto/bn/bn_exp.c:574:1: Parameter `a->top`
        572.    * http://www.daemonology.net/hyperthreading-considered-harmful/)
        573.    */
        574. > int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
        575.   		    const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)
        576.   	{

crypto/bn/bn_exp.c:650:8: Call
        648.   	if (a->neg || BN_ucmp(a,m) >= 0)
        649.   		{
        650.   		if (!BN_mod(am,a,m,ctx))
                      ^
        651.   			goto err;
        652.   		aa= am;

crypto/bn/bn_div.c:181:1: Parameter `num->top`
          179.   static int BN_div_no_branch(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,
          180.           const BIGNUM *divisor, BN_CTX *ctx);
          181. > int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
          182.   	   BN_CTX *ctx)
          183.   	{

crypto/bn/bn_div.c:204:10: Call
          202.   	if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0))
          203.   		{
          204.   		return BN_div_no_branch(dv, rm, num, divisor, ctx);
                          ^
          205.   		}
          206.   

crypto/bn/bn_div.c:426:1: Parameter `num->top`
            424.    * branches that may leak sensitive information.
            425.    */
            426. > static int BN_div_no_branch(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, 
            427.   	const BIGNUM *divisor, BN_CTX *ctx)
            428.   	{

crypto/bn/bn_div.c:460:8: Call
            458.   	sdiv->neg=0;
            459.   	norm_shift+=BN_BITS2;
            460.   	if (!(BN_lshift(snum,num,norm_shift))) goto err;
                          ^
            461.   	snum->neg=0;
            462.   

crypto/bn/bn_shift.c:132:1: <LHS trace>
130.   	}
131.   
132. > int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
133.   	{
134.   	int i,nw,lb,rb;

crypto/bn/bn_shift.c:132:1: Parameter `a->top`
              130.   	}
              131.   
              132. > int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
              133.   	{
              134.   	int i,nw,lb,rb;

crypto/bn/bn_shift.c:150:8: Binary operation: ([0, +oo] - 1):unsigned64 by call to `gost94_compute_public` 
              148.   	t[a->top+nw]=0;
              149.   	if (lb == 0)
              150.   		for (i=a->top-1; i>=0; i--)
                            ^
              151.   			t[nw+i]=f[i];
              152.   	else

int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
	{
	int i,nw,lb,rb;
	BN_ULONG *t,*f;
	BN_ULONG l;
	bn_check_top(r);
	bn_check_top(a);
	r->neg=a->neg;
	nw=n/BN_BITS2;
	if (bn_wexpand(r,a->top+nw+1) == NULL) return(0);
	lb=n%BN_BITS2;
	rb=BN_BITS2-lb;
	f=a->d;
	t=r->d;
	t[a->top+nw]=0;
	if (lb == 0)
		for (i=a->top-1; i>=0; i--)
			t[nw+i]=f[i];
	else
		for (i=a->top-1; i>=0; i--)
			{
			l=f[i];
			t[nw+i+1]|=(l>>rb)&BN_MASK2;
			t[nw+i]=(l<<lb)&BN_MASK2;
			}
	memset(t,0,nw*sizeof(t[0]));
	r->top=a->top+nw+1;
	bn_correct_top(r);
	bn_check_top(r);
	return(1);
	}
['static int param_copy_gost94(EVP_PKEY *to, const EVP_PKEY *from)\n\t{\n\tconst DSA *dfrom = EVP_PKEY_get0((EVP_PKEY *)from);\n\tDSA *dto = EVP_PKEY_get0(to);\n\tif (EVP_PKEY_base_id(from) != EVP_PKEY_base_id(to))\n\t\t{\n\t\tGOSTerr(GOST_F_PARAM_COPY_GOST94,\n\t\t\tGOST_R_INCOMPATIBLE_ALGORITHMS);\n\t\treturn 0;\n\t\t}\n\tif (!dfrom)\n\t\t{\n\t\tGOSTerr(GOST_F_PARAM_COPY_GOST94,\n\t\t\tGOST_R_KEY_PARAMETERS_MISSING);\n\t\treturn 0;\n\t\t}\n\tif (!dto)\n\t\t{\n\t\tdto = DSA_new();\n\t\tEVP_PKEY_assign(to,EVP_PKEY_base_id(from),dto);\n\t\t}\n#define COPYBIGNUM(a,b,x) if (a->x) BN_free(a->x); a->x=BN_dup(b->x);\n\tCOPYBIGNUM(dto,dfrom,p)\n\t\tCOPYBIGNUM(dto,dfrom,q)\n\t\tCOPYBIGNUM(dto,dfrom,g)\n\t\tif (dto->priv_key)\n\t\t\tgost94_compute_public(dto);\n\treturn 1;\n\t}', 'BIGNUM *BN_dup(const BIGNUM *a)\n\t{\n\tBIGNUM *t;\n\tif (a == NULL) return NULL;\n\tbn_check_top(a);\n\tt = BN_new();\n\tif (t == NULL) return NULL;\n\tif(!BN_copy(t, a))\n\t\t{\n\t\tBN_free(t);\n\t\treturn NULL;\n\t\t}\n\tbn_check_top(t);\n\treturn t;\n\t}', 'int gost94_compute_public(DSA *dsa)\n\t{\n\tBN_CTX *ctx = BN_CTX_new();\n\tif (!dsa->g)\n\t\t{\n\t\tGOSTerr(GOST_F_GOST94_COMPUTE_PUBLIC,GOST_R_KEY_IS_NOT_INITALIZED);\n\t\treturn 0;\n\t\t}\n\tdsa->pub_key=BN_new();\n\tBN_mod_exp(dsa->pub_key, dsa->g,dsa->priv_key,dsa->p,ctx);\n\tBN_CTX_free(ctx);\n\treturn 1;\n\t}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n\t       BN_CTX *ctx)\n\t{\n\tint ret;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n\tif (BN_is_odd(m))\n\t\t{\n#  ifdef MONT_EXP_WORD\n\t\tif (a->top == 1 && !a->neg && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0))\n\t\t\t{\n\t\t\tBN_ULONG A = a->d[0];\n\t\t\tret=BN_mod_exp_mont_word(r,A,p,m,ctx,NULL);\n\t\t\t}\n\t\telse\n#  endif\n\t\t\tret=BN_mod_exp_mont(r,a,p,m,ctx,NULL);\n\t\t}\n\telse\n#endif\n#ifdef RECP_MUL_MOD\n\t\t{ ret=BN_mod_exp_recp(r,a,p,m,ctx); }\n#else\n\t\t{ ret=BN_mod_exp_simple(r,a,p,m,ctx); }\n#endif\n\tbn_check_top(r);\n\treturn(ret);\n\t}', 'int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n\t\t    const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue;\n\tint start=1;\n\tBIGNUM *d,*r;\n\tconst BIGNUM *aa;\n\tBIGNUM *val[TABLE_SIZE];\n\tBN_MONT_CTX *mont=NULL;\n\tif (BN_get_flags(p, BN_FLG_CONSTTIME) != 0)\n\t\t{\n\t\treturn BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);\n\t\t}\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n\tif (!BN_is_odd(m))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);\n\t\treturn(0);\n\t\t}\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tret = BN_one(rr);\n\t\treturn ret;\n\t\t}\n\tBN_CTX_start(ctx);\n\td = BN_CTX_get(ctx);\n\tr = BN_CTX_get(ctx);\n\tval[0] = BN_CTX_get(ctx);\n\tif (!d || !r || !val[0]) goto err;\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\n\t\t{\n\t\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\t\tif (!BN_MONT_CTX_set(mont,m,ctx)) goto err;\n\t\t}\n\tif (a->neg || BN_ucmp(a,m) >= 0)\n\t\t{\n\t\tif (!BN_nnmod(val[0],a,m,ctx))\n\t\t\tgoto err;\n\t\taa= val[0];\n\t\t}\n\telse\n\t\taa=a;\n\tif (BN_is_zero(aa))\n\t\t{\n\t\tBN_zero(rr);\n\t\tret = 1;\n\t\tgoto err;\n\t\t}\n\tif (!BN_to_montgomery(val[0],aa,mont,ctx)) goto err;\n\twindow = BN_window_bits_for_exponent_size(bits);\n\tif (window > 1)\n\t\t{\n\t\tif (!BN_mod_mul_montgomery(d,val[0],val[0],mont,ctx)) goto err;\n\t\tj=1<<(window-1);\n\t\tfor (i=1; i<j; i++)\n\t\t\t{\n\t\t\tif(((val[i] = BN_CTX_get(ctx)) == NULL) ||\n\t\t\t\t\t!BN_mod_mul_montgomery(val[i],val[i-1],\n\t\t\t\t\t\td,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tstart=1;\n\twvalue=0;\n\twstart=bits-1;\n\twend=0;\n\tif (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) 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\t{\n\t\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t\t}\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_montgomery(r,r,r,mont,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (!BN_mod_mul_montgomery(r,r,val[wvalue>>1],mont,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\tif (!BN_from_montgomery(rr,r,mont,ctx)) goto err;\n\tret=1;\nerr:\n\tif ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);\n\tBN_CTX_end(ctx);\n\tbn_check_top(rr);\n\treturn(ret);\n\t}', 'int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n\t\t    const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n\t{\n\tint i,bits,ret=0,idx,window,wvalue;\n\tsize_t top;\n \tBIGNUM *r;\n\tconst BIGNUM *aa;\n\tBN_MONT_CTX *mont=NULL;\n\tint numPowers;\n\tunsigned char *powerbufFree=NULL;\n\tsize_t powerbufLen = 0;\n\tunsigned char *powerbuf=NULL;\n\tBIGNUM *computeTemp=NULL, *am=NULL;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n\ttop = m->top;\n\tif (!(m->d[0] & 1))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME,BN_R_CALLED_WITH_EVEN_MODULUS);\n\t\treturn(0);\n\t\t}\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tret = BN_one(rr);\n\t\treturn ret;\n\t\t}\n\tBN_CTX_start(ctx);\n\tr = BN_CTX_get(ctx);\n\tif (r == NULL) goto err;\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\n\t\t{\n\t\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\t\tif (!BN_MONT_CTX_set(mont,m,ctx)) goto err;\n\t\t}\n\twindow = BN_window_bits_for_ctime_exponent_size(bits);\n\tnumPowers = 1 << window;\n\tpowerbufLen = sizeof(m->d[0])*top*numPowers;\n\tif ((powerbufFree=OPENSSL_malloc(powerbufLen+MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH)) == NULL)\n\t\tgoto err;\n\tpowerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);\n\tmemset(powerbuf, 0, powerbufLen);\n \tif (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;\n\tif (!MOD_EXP_CTIME_COPY_TO_PREBUF(r, top, powerbuf, 0, numPowers)) goto err;\n\tcomputeTemp = BN_CTX_get(ctx);\n\tam = BN_CTX_get(ctx);\n\tif (computeTemp==NULL || am==NULL) goto err;\n\tif (a->neg || BN_ucmp(a,m) >= 0)\n\t\t{\n\t\tif (!BN_mod(am,a,m,ctx))\n\t\t\tgoto err;\n\t\taa= am;\n\t\t}\n\telse\n\t\taa=a;\n\tif (!BN_to_montgomery(am,aa,mont,ctx)) goto err;\n\tif (!BN_copy(computeTemp, am)) goto err;\n\tif (!MOD_EXP_CTIME_COPY_TO_PREBUF(am, top, powerbuf, 1, numPowers)) goto err;\n\tif (window > 1)\n\t\t{\n\t\tfor (i=2; i<numPowers; i++)\n\t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(computeTemp,am,computeTemp,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\tif (!MOD_EXP_CTIME_COPY_TO_PREBUF(computeTemp, top, powerbuf, i, numPowers)) goto err;\n\t\t\t}\n\t\t}\n \tbits = ((bits+window-1)/window)*window;\n \tidx=bits-1;\n \twhile (idx >= 0)\n  \t\t{\n \t\twvalue=0;\n \t\tfor (i=0; i<window; i++,idx--)\n \t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\tgoto err;\n\t\t\twvalue = (wvalue<<1)+BN_is_bit_set(p,idx);\n  \t\t\t}\n\t\tif (!MOD_EXP_CTIME_COPY_FROM_PREBUF(computeTemp, top, powerbuf, wvalue, numPowers)) goto err;\n \t\tif (!BN_mod_mul_montgomery(r,r,computeTemp,mont,ctx)) goto err;\n  \t\t}\n\tif (!BN_from_montgomery(rr,r,mont,ctx)) goto err;\n\tret=1;\nerr:\n\tif ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);\n\tif (powerbuf!=NULL)\n\t\t{\n\t\tOPENSSL_cleanse(powerbuf,powerbufLen);\n\t\tOPENSSL_free(powerbufFree);\n\t\t}\n \tif (am!=NULL) BN_clear(am);\n \tif (computeTemp!=NULL) BN_clear(computeTemp);\n\tBN_CTX_end(ctx);\n\treturn(ret);\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;\n\tsize_t loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tsize_t num_n,div_n;\n\tif (num->top > 0 && num->d[num->top - 1] == 0)\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_NOT_INITIALIZED);\n\t\treturn 0;\n\t\t}\n\tbn_check_top(num);\n\tif ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0))\n\t\t{\n\t\treturn BN_div_no_branch(dv, rm, num, divisor, ctx);\n\t\t}\n\tbn_check_top(dv);\n\tbn_check_top(rm);\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\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg   = 0;\n\twnum.d     = &(snum->d[loop]);\n\twnum.top   = div_n;\n\twnum.dmax  = snum->dmax - loop;\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\tbn_clear_top2max(&wnum);\n\t\tbn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n\t\t*resp=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\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\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\t{\n\t\t\tBN_ULONG ql, qh;\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\t}\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'static int BN_div_no_branch(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,\n\tconst BIGNUM *divisor, BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tsize_t num_n,div_n;\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV_NO_BRANCH,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tif (snum->top <= sdiv->top+1)\n\t\t{\n\t\tif (bn_wexpand(snum, sdiv->top + 2) == NULL) goto err;\n\t\tfor (i = snum->top; i < sdiv->top + 2; i++) snum->d[i] = 0;\n\t\tsnum->top = sdiv->top + 2;\n\t\t}\n\telse\n\t\t{\n\t\tif (bn_wexpand(snum, snum->top + 1) == NULL) goto err;\n\t\tsnum->d[snum->top] = 0;\n\t\tsnum->top ++;\n\t\t}\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg   = 0;\n\twnum.d     = &(snum->d[loop]);\n\twnum.top   = div_n;\n\twnum.dmax  = snum->dmax - loop;\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+1U)) goto err;\n\tres->top=loop-1;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,div_n+1U)) goto err;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\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\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\t{\n\t\t\tBN_ULONG ql, qh;\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\t}\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tbn_correct_top(res);\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)\n\t{\n\tint i,nw,lb,rb;\n\tBN_ULONG *t,*f;\n\tBN_ULONG l;\n\tbn_check_top(r);\n\tbn_check_top(a);\n\tr->neg=a->neg;\n\tnw=n/BN_BITS2;\n\tif (bn_wexpand(r,a->top+nw+1) == NULL) return(0);\n\tlb=n%BN_BITS2;\n\trb=BN_BITS2-lb;\n\tf=a->d;\n\tt=r->d;\n\tt[a->top+nw]=0;\n\tif (lb == 0)\n\t\tfor (i=a->top-1; i>=0; i--)\n\t\t\tt[nw+i]=f[i];\n\telse\n\t\tfor (i=a->top-1; i>=0; i--)\n\t\t\t{\n\t\t\tl=f[i];\n\t\t\tt[nw+i+1]|=(l>>rb)&BN_MASK2;\n\t\t\tt[nw+i]=(l<<lb)&BN_MASK2;\n\t\t\t}\n\tmemset(t,0,nw*sizeof(t[0]));\n\tr->top=a->top+nw+1;\n\tbn_correct_top(r);\n\tbn_check_top(r);\n\treturn(1);\n\t}']