BN_ULONG bn_sub_part_words(BN_ULONG *r,
	const BN_ULONG *a, const BN_ULONG *b,
	int cl, int dl)
	{
	BN_ULONG c, t;
	assert(cl >= 0);
	c = bn_sub_words(r, a, b, cl);
	if (dl == 0)
		return c;
	r += cl;
	a += cl;
	b += cl;
	if (dl < 0)
		{
#ifdef BN_COUNT
		fprintf(stderr, "  bn_sub_part_words %d + %d (dl < 0, c = %d)\n", cl, dl, c);
#endif
		for (;;)
			{
			t = b[0];
			r[0] = (0-t-c)&BN_MASK2;
			if (t != 0) c=1;
			if (++dl >= 0) break;
			t = b[1];
			r[1] = (0-t-c)&BN_MASK2;
			if (t != 0) c=1;
			if (++dl >= 0) break;
			t = b[2];
			r[2] = (0-t-c)&BN_MASK2;
			if (t != 0) c=1;
			if (++dl >= 0) break;
			t = b[3];
			r[3] = (0-t-c)&BN_MASK2;
			if (t != 0) c=1;
			if (++dl >= 0) break;
			b += 4;
			r += 4;
			}
		}
	else
		{
		int save_dl = dl;
#ifdef BN_COUNT
		fprintf(stderr, "  bn_sub_part_words %d + %d (dl > 0, c = %d)\n", cl, dl, c);
#endif
		while(c)
			{
			t = a[0];
			r[0] = (t-c)&BN_MASK2;
			if (t != 0) c=0;
			if (--dl <= 0) break;
			t = a[1];
			r[1] = (t-c)&BN_MASK2;
			if (t != 0) c=0;
			if (--dl <= 0) break;
			t = a[2];
			r[2] = (t-c)&BN_MASK2;
			if (t != 0) c=0;
			if (--dl <= 0) break;
			t = a[3];
			r[3] = (t-c)&BN_MASK2;
			if (t != 0) c=0;
			if (--dl <= 0) break;
			save_dl = dl;
			a += 4;
			r += 4;
			}
		if (dl > 0)
			{
#ifdef BN_COUNT
			fprintf(stderr, "  bn_sub_part_words %d + %d (dl > 0, c == 0)\n", cl, dl);
#endif
			if (save_dl > dl)
				{
				switch (save_dl - dl)
					{
				case 1:
					r[1] = a[1];
					if (--dl <= 0) break;
				case 2:
					r[2] = a[2];
					if (--dl <= 0) break;
				case 3:
					r[3] = a[3];
					if (--dl <= 0) break;
					}
				a += 4;
				r += 4;
				}
			}
		if (dl > 0)
			{
#ifdef BN_COUNT
			fprintf(stderr, "  bn_sub_part_words %d + %d (dl > 0, copy)\n", cl, dl);
#endif
			for(;;)
				{
				r[0] = a[0];
				if (--dl <= 0) break;
				r[1] = a[1];
				if (--dl <= 0) break;
				r[2] = a[2];
				if (--dl <= 0) break;
				r[3] = a[3];
				if (--dl <= 0) break;
				a += 4;
				r += 4;
				}
			}
		}
	return c;
	}
['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,window,wvalue;\n\tint top;\n\tBN_MONT_CTX *mont=NULL;\n\tint numPowers;\n\tunsigned char *powerbufFree=NULL;\n\tint powerbufLen = 0;\n\tunsigned char *powerbuf=NULL;\n\tBIGNUM tmp, am;\n#if defined(OPENSSL_BN_ASM_MONT) && (defined(__sparc__) || defined(__sparc))\n\tunsigned int t4=0;\n#endif\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\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#if defined(OPENSSL_BN_ASM_MONT) && (defined(__sparc__) || defined(__sparc))\n\tif (window>=5 && (top&15)==0 && top<=64 &&\n\t    (OPENSSL_sparcv9cap_P[1]&(CFR_MONTMUL|CFR_MONTSQR))==\n\t    \t\t\t     (CFR_MONTMUL|CFR_MONTSQR) &&\n\t    (t4=OPENSSL_sparcv9cap_P[0]))\n\t\twindow=5;\n\telse\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n\tif (window==6 && bits<=1024) window=5;\n#endif\n\t(void)0;\n\tnumPowers = 1 << window;\n\tpowerbufLen = sizeof(m->d[0])*(top*numPowers +\n\t\t\t\t((2*top)>numPowers?(2*top):numPowers));\n#ifdef alloca\n\tif (powerbufLen < 3072)\n\t\tpowerbufFree = alloca(powerbufLen+MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH);\n\telse\n#endif\n\tif ((powerbufFree=(unsigned char*)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#ifdef alloca\n\tif (powerbufLen < 3072)\n\t\tpowerbufFree = NULL;\n#endif\n\ttmp.d     = (BN_ULONG *)(powerbuf + sizeof(m->d[0])*top*numPowers);\n\tam.d      = tmp.d + top;\n\ttmp.top   = am.top  = 0;\n\ttmp.dmax  = am.dmax = top;\n\ttmp.neg   = am.neg  = 0;\n\ttmp.flags = am.flags = BN_FLG_STATIC_DATA;\n#if 1\n\ttmp.d[0] = (0-m->d[0])&BN_MASK2;\n\tfor (i=1;i<top;i++)\n\t\ttmp.d[i] = (~m->d[i])&BN_MASK2;\n\ttmp.top = top;\n#else\n \tif (!BN_to_montgomery(&tmp,BN_value_one(),mont,ctx))\tgoto err;\n#endif\n\tif (a->neg || BN_ucmp(a,m) >= 0)\n\t\t{\n\t\tif (!BN_mod(&am,a,m,ctx))\t\t\tgoto err;\n\t\tif (!BN_to_montgomery(&am,&am,mont,ctx))\tgoto err;\n\t\t}\n\telse\tif (!BN_to_montgomery(&am,a,mont,ctx))\t\tgoto err;\n#if defined(OPENSSL_BN_ASM_MONT) && (defined(__sparc__) || defined(__sparc))\n    if (t4)\n\t{\n\ttypedef int (*bn_pwr5_mont_f)(BN_ULONG *tp,const BN_ULONG *np,\n\t\t\tconst BN_ULONG *n0,const void *table,int power,int bits);\n\tint bn_pwr5_mont_t4_8(BN_ULONG *tp,const BN_ULONG *np,\n\t\t\tconst BN_ULONG *n0,const void *table,int power,int bits);\n\tint bn_pwr5_mont_t4_16(BN_ULONG *tp,const BN_ULONG *np,\n\t\t\tconst BN_ULONG *n0,const void *table,int power,int bits);\n\tint bn_pwr5_mont_t4_24(BN_ULONG *tp,const BN_ULONG *np,\n\t\t\tconst BN_ULONG *n0,const void *table,int power,int bits);\n\tint bn_pwr5_mont_t4_32(BN_ULONG *tp,const BN_ULONG *np,\n\t\t\tconst BN_ULONG *n0,const void *table,int power,int bits);\n\tstatic const bn_pwr5_mont_f pwr5_funcs[4] = {\n\t\t\tbn_pwr5_mont_t4_8,\tbn_pwr5_mont_t4_16,\n\t\t\tbn_pwr5_mont_t4_24,\tbn_pwr5_mont_t4_32 };\n\tbn_pwr5_mont_f pwr5_worker = pwr5_funcs[top/16-1];\n\ttypedef int (*bn_mul_mont_f)(BN_ULONG *rp,const BN_ULONG *ap,\n\t\t\tconst void *bp,const BN_ULONG *np,const BN_ULONG *n0);\n\tint bn_mul_mont_t4_8(BN_ULONG *rp,const BN_ULONG *ap,\n\t\t\tconst void *bp,const BN_ULONG *np,const BN_ULONG *n0);\n\tint bn_mul_mont_t4_16(BN_ULONG *rp,const BN_ULONG *ap,\n\t\t\tconst void *bp,const BN_ULONG *np,const BN_ULONG *n0);\n\tint bn_mul_mont_t4_24(BN_ULONG *rp,const BN_ULONG *ap,\n\t\t\tconst void *bp,const BN_ULONG *np,const BN_ULONG *n0);\n\tint bn_mul_mont_t4_32(BN_ULONG *rp,const BN_ULONG *ap,\n\t\t\tconst void *bp,const BN_ULONG *np,const BN_ULONG *n0);\n\tstatic const bn_mul_mont_f mul_funcs[4] = {\n\t\t\tbn_mul_mont_t4_8,\tbn_mul_mont_t4_16,\n\t\t\tbn_mul_mont_t4_24,\tbn_mul_mont_t4_32 };\n\tbn_mul_mont_f mul_worker = mul_funcs[top/16-1];\n\tvoid bn_mul_mont_vis3(BN_ULONG *rp,const BN_ULONG *ap,\n\t\t\tconst void *bp,const BN_ULONG *np,\n\t\t\tconst BN_ULONG *n0,int num);\n\tvoid bn_mul_mont_t4(BN_ULONG *rp,const BN_ULONG *ap,\n\t\t\tconst void *bp,const BN_ULONG *np,\n\t\t\tconst BN_ULONG *n0,int num);\n\tvoid bn_mul_mont_gather5_t4(BN_ULONG *rp,const BN_ULONG *ap,\n\t\t\tconst void *table,const BN_ULONG *np,\n\t\t\tconst BN_ULONG *n0,int num,int power);\n\tvoid bn_flip_n_scatter5_t4(const BN_ULONG *inp,size_t num,\n\t\t\tvoid *table,size_t power);\n\tvoid bn_gather5_t4(BN_ULONG *out,size_t num,\n\t\t\tvoid *table,size_t power);\n\tvoid bn_flip_t4(BN_ULONG *dst,BN_ULONG *src,size_t num);\n\tBN_ULONG *np=mont->N.d, *n0=mont->n0;\n\tint stride = 5*(6-(top/16-1));\n\tfor (i=am.top; i<top; i++)\tam.d[i]=0;\n\tfor (i=tmp.top; i<top; i++)\ttmp.d[i]=0;\n\tbn_flip_n_scatter5_t4(tmp.d,top,powerbuf,0);\n\tbn_flip_n_scatter5_t4(am.d,top,powerbuf,1);\n\tif (!(*mul_worker)(tmp.d,am.d,am.d,np,n0) &&\n\t    !(*mul_worker)(tmp.d,am.d,am.d,np,n0))\n\t\tbn_mul_mont_vis3(tmp.d,am.d,am.d,np,n0,top);\n\tbn_flip_n_scatter5_t4(tmp.d,top,powerbuf,2);\n\tfor (i=3; i<32; i++)\n\t\t{\n\t\tif (!(*mul_worker)(tmp.d,tmp.d,am.d,np,n0) &&\n\t\t    !(*mul_worker)(tmp.d,tmp.d,am.d,np,n0))\n\t\t\tbn_mul_mont_vis3(tmp.d,tmp.d,am.d,np,n0,top);\n\t\tbn_flip_n_scatter5_t4(tmp.d,top,powerbuf,i);\n\t\t}\n\tnp = alloca(top*sizeof(BN_ULONG));\n\ttop /= 2;\n\tbn_flip_t4(np,mont->N.d,top);\n\tbits--;\n\tfor (wvalue=0, i=bits%5; i>=0; i--,bits--)\n\t\twvalue = (wvalue<<1)+BN_is_bit_set(p,bits);\n\tbn_gather5_t4(tmp.d,top,powerbuf,wvalue);\n\twhile (bits >= 0)\n\t\t{\n\t\tif (bits < stride) stride = bits+1;\n\t\tbits -= stride;\n\t\twvalue = bn_get_bits(p,bits+1);\n\t\tif ((*pwr5_worker)(tmp.d,np,n0,powerbuf,wvalue,stride)) continue;\n\t\tif ((*pwr5_worker)(tmp.d,np,n0,powerbuf,wvalue,stride)) continue;\n\t\tbits += stride-5;\n\t\twvalue >>= stride-5;\n\t\twvalue &= 31;\n\t\tbn_mul_mont_t4(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_mul_mont_t4(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_mul_mont_t4(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_mul_mont_t4(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_mul_mont_t4(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_mul_mont_gather5_t4(tmp.d,tmp.d,powerbuf,np,n0,top,wvalue);\n\t\t}\n\tbn_flip_t4(tmp.d,tmp.d,top);\n\ttop *= 2;\n\ttmp.top=top;\n\tbn_correct_top(&tmp);\n\tOPENSSL_cleanse(np,top*sizeof(BN_ULONG));\n\t}\n    else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n    if (window==5)\n\t{\n\tvoid bn_mul_mont_gather5(BN_ULONG *rp,const BN_ULONG *ap,\n\t\t\tconst void *table,const BN_ULONG *np,\n\t\t\tconst BN_ULONG *n0,int num,int power);\n\tvoid bn_scatter5(const BN_ULONG *inp,size_t num,\n\t\t\tvoid *table,size_t power);\n\tvoid bn_gather5(BN_ULONG *out,size_t num,\n\t\t\tvoid *table,size_t power);\n\tBN_ULONG *np=mont->N.d, *n0=mont->n0;\n\tfor (i=am.top; i<top; i++)\tam.d[i]=0;\n\tfor (i=tmp.top; i<top; i++)\ttmp.d[i]=0;\n\tbn_scatter5(tmp.d,top,powerbuf,0);\n\tbn_scatter5(am.d,am.top,powerbuf,1);\n\tbn_mul_mont(tmp.d,am.d,am.d,np,n0,top);\n\tbn_scatter5(tmp.d,top,powerbuf,2);\n#if 0\n\tfor (i=3; i<32; i++)\n\t\t{\n\t\tbn_mul_mont_gather5(tmp.d,am.d,powerbuf,np,n0,top,i-1);\n\t\tbn_scatter5(tmp.d,top,powerbuf,i);\n\t\t}\n#else\n\tfor (i=4; i<32; i*=2)\n\t\t{\n\t\tbn_mul_mont(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_scatter5(tmp.d,top,powerbuf,i);\n\t\t}\n\tfor (i=3; i<8; i+=2)\n\t\t{\n\t\tint j;\n\t\tbn_mul_mont_gather5(tmp.d,am.d,powerbuf,np,n0,top,i-1);\n\t\tbn_scatter5(tmp.d,top,powerbuf,i);\n\t\tfor (j=2*i; j<32; j*=2)\n\t\t\t{\n\t\t\tbn_mul_mont(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\t\tbn_scatter5(tmp.d,top,powerbuf,j);\n\t\t\t}\n\t\t}\n\tfor (; i<16; i+=2)\n\t\t{\n\t\tbn_mul_mont_gather5(tmp.d,am.d,powerbuf,np,n0,top,i-1);\n\t\tbn_scatter5(tmp.d,top,powerbuf,i);\n\t\tbn_mul_mont(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_scatter5(tmp.d,top,powerbuf,2*i);\n\t\t}\n\tfor (; i<32; i+=2)\n\t\t{\n\t\tbn_mul_mont_gather5(tmp.d,am.d,powerbuf,np,n0,top,i-1);\n\t\tbn_scatter5(tmp.d,top,powerbuf,i);\n\t\t}\n#endif\n\tbits--;\n\tfor (wvalue=0, i=bits%5; i>=0; i--,bits--)\n\t\twvalue = (wvalue<<1)+BN_is_bit_set(p,bits);\n\tbn_gather5(tmp.d,top,powerbuf,wvalue);\n\twhile (bits >= 0)\n\t\t{\n\t\tfor (wvalue=0, i=0; i<5; i++,bits--)\n\t\t\twvalue = (wvalue<<1)+BN_is_bit_set(p,bits);\n\t\tbn_mul_mont(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_mul_mont(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_mul_mont(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_mul_mont(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_mul_mont(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_mul_mont_gather5(tmp.d,tmp.d,powerbuf,np,n0,top,wvalue);\n\t\t}\n\ttmp.top=top;\n\tbn_correct_top(&tmp);\n\t}\n    else\n#endif\n\t{\n\tif (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 0, numPowers)) 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\tif (!BN_mod_mul_montgomery(&tmp,&am,&am,mont,ctx))\tgoto err;\n\t\tif (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 2, numPowers)) goto err;\n\t\tfor (i=3; i<numPowers; i++)\n\t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(&tmp,&am,&tmp,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\tif (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, i, numPowers)) goto err;\n\t\t\t}\n\t\t}\n\tbits--;\n\tfor (wvalue=0, i=bits%window; i>=0; i--,bits--)\n\t\twvalue = (wvalue<<1)+BN_is_bit_set(p,bits);\n\tif (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&tmp,top,powerbuf,wvalue,numPowers)) goto err;\n \twhile (bits >= 0)\n  \t\t{\n \t\twvalue=0;\n \t\tfor (i=0; i<window; i++,bits--)\n \t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(&tmp,&tmp,&tmp,mont,ctx))\tgoto err;\n\t\t\twvalue = (wvalue<<1)+BN_is_bit_set(p,bits);\n  \t\t\t}\n\t\tif (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&am, top, powerbuf, wvalue, numPowers)) goto err;\n \t\tif (!BN_mod_mul_montgomery(&tmp,&tmp,&am,mont,ctx)) goto err;\n  \t\t}\n\t}\n#if defined(OPENSSL_BN_ASM_MONT) && (defined(__sparc__) || defined(__sparc))\n\tif (OPENSSL_sparcv9cap_P[0]&(SPARCV9_VIS3|SPARCV9_PREFER_FPU))\n\t\t{\n\t\tam.d[0] = 1;\n\t\tfor (i=1;i<top;i++) am.d[i] = 0;\n\t\tif (!BN_mod_mul_montgomery(rr,&tmp,&am,mont,ctx)) goto err;\n\t\t}\n\telse\n#endif\n\tif (!BN_from_montgomery(rr,&tmp,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\tif (powerbufFree) OPENSSL_free(powerbufFree);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n\t\t\t  BN_MONT_CTX *mont, BN_CTX *ctx)\n\t{\n\tBIGNUM *tmp;\n\tint ret=0;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n\tint num = mont->N.top;\n\tif (num>1 && a->top==num && b->top==num)\n\t\t{\n\t\tif (bn_wexpand(r,num) == NULL) return(0);\n\t\tif (bn_mul_mont(r->d,a->d,b->d,mont->N.d,mont->n0,num))\n\t\t\t{\n\t\t\tr->neg = a->neg^b->neg;\n\t\t\tr->top = num;\n\t\t\tbn_correct_top(r);\n\t\t\treturn(1);\n\t\t\t}\n\t\t}\n#endif\n\tBN_CTX_start(ctx);\n\ttmp = BN_CTX_get(ctx);\n\tif (tmp == NULL) goto err;\n\tbn_check_top(tmp);\n\tif (a == b)\n\t\t{\n\t\tif (!BN_sqr(tmp,a,ctx)) goto err;\n\t\t}\n\telse\n\t\t{\n\t\tif (!BN_mul(tmp,a,b,ctx)) goto err;\n\t\t}\n#ifdef MONT_WORD\n\tif (!BN_from_montgomery_word(r,tmp,mont)) goto err;\n#else\n\tif (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;\n#endif\n\tbn_check_top(r);\n\tret=1;\nerr:\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint ret=0;\n\tint top,al,bl;\n\tBIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\tint i;\n#endif\n#ifdef BN_RECURSION\n\tBIGNUM *t=NULL;\n\tint j=0,k;\n#endif\n#ifdef BN_COUNT\n\tfprintf(stderr,"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\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\tBN_CTX_start(ctx);\n\tif ((r == a) || (r == b))\n\t\t{\n\t\tif ((rr = BN_CTX_get(ctx)) == NULL) goto err;\n\t\t}\n\telse\n\t\trr = r;\n\trr->neg=a->neg^b->neg;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\ti = al-bl;\n#endif\n#ifdef BN_MUL_COMBA\n\tif (i == 0)\n\t\t{\n# if 0\n\t\tif (al == 4)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,8) == NULL) goto err;\n\t\t\trr->top=8;\n\t\t\tbn_mul_comba4(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n# endif\n\t\tif (al == 8)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,16) == NULL) goto err;\n\t\t\trr->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\t}\n#endif\n#ifdef BN_RECURSION\n\tif ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL))\n\t\t{\n\t\tif (i >= -1 && i <= 1)\n\t\t\t{\n\t\t\tif (i >= 0)\n\t\t\t\t{\n\t\t\t\tj = BN_num_bits_word((BN_ULONG)al);\n\t\t\t\t}\n\t\t\tif (i == -1)\n\t\t\t\t{\n\t\t\t\tj = BN_num_bits_word((BN_ULONG)bl);\n\t\t\t\t}\n\t\t\tj = 1<<(j-1);\n\t\t\tassert(j <= al || j <= bl);\n\t\t\tk = j+j;\n\t\t\tt = BN_CTX_get(ctx);\n\t\t\tif (t == NULL)\n\t\t\t\tgoto err;\n\t\t\tif (al > j || bl > j)\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(t,k*4) == NULL) goto err;\n\t\t\t\tif (bn_wexpand(rr,k*4) == NULL) goto err;\n\t\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,\n\t\t\t\t\tj,al-j,bl-j,t->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(t,k*2) == NULL) goto err;\n\t\t\t\tif (bn_wexpand(rr,k*2) == NULL) goto err;\n\t\t\t\tbn_mul_recursive(rr->d,a->d,b->d,\n\t\t\t\t\tj,al-j,bl-j,t->d);\n\t\t\t\t}\n\t\t\trr->top=top;\n\t\t\tgoto end;\n\t\t\t}\n#if 0\n\t\tif (i == 1 && !BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBIGNUM *tmp_bn = (BIGNUM *)b;\n\t\t\tif (bn_wexpand(tmp_bn,al) == NULL) goto err;\n\t\t\ttmp_bn->d[bl]=0;\n\t\t\tbl++;\n\t\t\ti--;\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\tBIGNUM *tmp_bn = (BIGNUM *)a;\n\t\t\tif (bn_wexpand(tmp_bn,bl) == NULL) goto err;\n\t\t\ttmp_bn->d[al]=0;\n\t\t\tal++;\n\t\t\ti++;\n\t\t\t}\n\t\tif (i == 0)\n\t\t\t{\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\tt = BN_CTX_get(ctx);\n\t\t\tif (al == j)\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(t,k*2) == NULL) goto err;\n\t\t\t\tif (bn_wexpand(rr,k*2) == NULL) goto err;\n\t\t\t\tbn_mul_recursive(rr->d,a->d,b->d,al,t->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(t,k*4) == NULL) goto err;\n\t\t\t\tif (bn_wexpand(rr,k*4) == NULL) goto err;\n\t\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);\n\t\t\t\t}\n\t\t\trr->top=top;\n\t\t\tgoto end;\n\t\t\t}\n#endif\n\t\t}\n#endif\n\tif (bn_wexpand(rr,top) == NULL) goto err;\n\trr->top=top;\n\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\nend:\n#endif\n\tbn_correct_top(rr);\n\tif (r != rr) BN_copy(r,rr);\n\tret=1;\nerr:\n\tbn_check_top(r);\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,\n\t     int tna, int tnb, BN_ULONG *t)\n\t{\n\tint i,j,n2=n*2;\n\tint c1,c2,neg;\n\tBN_ULONG ln,lo,*p;\n# ifdef BN_COUNT\n\tfprintf(stderr," bn_mul_part_recursive (%d%+d) * (%d%+d)\\n",\n\t\tn, tna, n, tnb);\n# endif\n\tif (n < 8)\n\t\t{\n\t\tbn_mul_normal(r,a,n+tna,b,n+tnb);\n\t\treturn;\n\t\t}\n\tc1=bn_cmp_part_words(a,&(a[n]),tna,n-tna);\n\tc2=bn_cmp_part_words(&(b[n]),b,tnb,tnb-n);\n\tneg=0;\n\tswitch (c1*3+c2)\n\t\t{\n\tcase -4:\n\t\tbn_sub_part_words(t,      &(a[n]),a,      tna,tna-n);\n\t\tbn_sub_part_words(&(t[n]),b,      &(b[n]),tnb,n-tnb);\n\t\tbreak;\n\tcase -3:\n\tcase -2:\n\t\tbn_sub_part_words(t,      &(a[n]),a,      tna,tna-n);\n\t\tbn_sub_part_words(&(t[n]),&(b[n]),b,      tnb,tnb-n);\n\t\tneg=1;\n\t\tbreak;\n\tcase -1:\n\tcase 0:\n\tcase 1:\n\tcase 2:\n\t\tbn_sub_part_words(t,      a,      &(a[n]),tna,n-tna);\n\t\tbn_sub_part_words(&(t[n]),b,      &(b[n]),tnb,n-tnb);\n\t\tneg=1;\n\t\tbreak;\n\tcase 3:\n\tcase 4:\n\t\tbn_sub_part_words(t,      a,      &(a[n]),tna,n-tna);\n\t\tbn_sub_part_words(&(t[n]),&(b[n]),b,      tnb,tnb-n);\n\t\tbreak;\n\t\t}\n# if 0\n\tif (n == 4)\n\t\t{\n\t\tbn_mul_comba4(&(t[n2]),t,&(t[n]));\n\t\tbn_mul_comba4(r,a,b);\n\t\tbn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);\n\t\tmemset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2));\n\t\t}\n\telse\n# endif\n\tif (n == 8)\n\t\t{\n\t\tbn_mul_comba8(&(t[n2]),t,&(t[n]));\n\t\tbn_mul_comba8(r,a,b);\n\t\tbn_mul_normal(&(r[n2]),&(a[n]),tna,&(b[n]),tnb);\n\t\tmemset(&(r[n2+tna+tnb]),0,sizeof(BN_ULONG)*(n2-tna-tnb));\n\t\t}\n\telse\n\t\t{\n\t\tp= &(t[n2*2]);\n\t\tbn_mul_recursive(&(t[n2]),t,&(t[n]),n,0,0,p);\n\t\tbn_mul_recursive(r,a,b,n,0,0,p);\n\t\ti=n/2;\n\t\tif (tna > tnb)\n\t\t\tj = tna - i;\n\t\telse\n\t\t\tj = tnb - i;\n\t\tif (j == 0)\n\t\t\t{\n\t\t\tbn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),\n\t\t\t\ti,tna-i,tnb-i,p);\n\t\t\tmemset(&(r[n2+i*2]),0,sizeof(BN_ULONG)*(n2-i*2));\n\t\t\t}\n\t\telse if (j > 0)\n\t\t\t\t{\n\t\t\t\tbn_mul_part_recursive(&(r[n2]),&(a[n]),&(b[n]),\n\t\t\t\t\ti,tna-i,tnb-i,p);\n\t\t\t\tmemset(&(r[n2+tna+tnb]),0,\n\t\t\t\t\tsizeof(BN_ULONG)*(n2-tna-tnb));\n\t\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tmemset(&(r[n2]),0,sizeof(BN_ULONG)*n2);\n\t\t\tif (tna < BN_MUL_RECURSIVE_SIZE_NORMAL\n\t\t\t\t&& tnb < BN_MUL_RECURSIVE_SIZE_NORMAL)\n\t\t\t\t{\n\t\t\t\tbn_mul_normal(&(r[n2]),&(a[n]),tna,&(b[n]),tnb);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tfor (;;)\n\t\t\t\t\t{\n\t\t\t\t\ti/=2;\n\t\t\t\t\tif (i < tna || i < tnb)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tbn_mul_part_recursive(&(r[n2]),\n\t\t\t\t\t\t\t&(a[n]),&(b[n]),\n\t\t\t\t\t\t\ti,tna-i,tnb-i,p);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\telse if (i == tna || i == tnb)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tbn_mul_recursive(&(r[n2]),\n\t\t\t\t\t\t\t&(a[n]),&(b[n]),\n\t\t\t\t\t\t\ti,tna-i,tnb-i,p);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tc1=(int)(bn_add_words(t,r,&(r[n2]),n2));\n\tif (neg)\n\t\t{\n\t\tc1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));\n\t\t}\n\telse\n\t\t{\n\t\tc1+=(int)(bn_add_words(&(t[n2]),&(t[n2]),t,n2));\n\t\t}\n\tc1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2));\n\tif (c1)\n\t\t{\n\t\tp= &(r[n+n2]);\n\t\tlo= *p;\n\t\tln=(lo+c1)&BN_MASK2;\n\t\t*p=ln;\n\t\tif (ln < (BN_ULONG)c1)\n\t\t\t{\n\t\t\tdo\t{\n\t\t\t\tp++;\n\t\t\t\tlo= *p;\n\t\t\t\tln=(lo+1)&BN_MASK2;\n\t\t\t\t*p=ln;\n\t\t\t\t} while (ln == 0);\n\t\t\t}\n\t\t}\n\t}', 'int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b,\n\tint cl, int dl)\n\t{\n\tint n,i;\n\tn = cl-1;\n\tif (dl < 0)\n\t\t{\n\t\tfor (i=dl; i<0; i++)\n\t\t\t{\n\t\t\tif (b[n-i] != 0)\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n\tif (dl > 0)\n\t\t{\n\t\tfor (i=dl; i>0; i--)\n\t\t\t{\n\t\t\tif (a[n+i] != 0)\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t}\n\treturn bn_cmp_words(a,b,cl);\n\t}', 'BN_ULONG bn_sub_part_words(BN_ULONG *r,\n\tconst BN_ULONG *a, const BN_ULONG *b,\n\tint cl, int dl)\n\t{\n\tBN_ULONG c, t;\n\tassert(cl >= 0);\n\tc = bn_sub_words(r, a, b, cl);\n\tif (dl == 0)\n\t\treturn c;\n\tr += cl;\n\ta += cl;\n\tb += cl;\n\tif (dl < 0)\n\t\t{\n#ifdef BN_COUNT\n\t\tfprintf(stderr, "  bn_sub_part_words %d + %d (dl < 0, c = %d)\\n", cl, dl, c);\n#endif\n\t\tfor (;;)\n\t\t\t{\n\t\t\tt = b[0];\n\t\t\tr[0] = (0-t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=1;\n\t\t\tif (++dl >= 0) break;\n\t\t\tt = b[1];\n\t\t\tr[1] = (0-t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=1;\n\t\t\tif (++dl >= 0) break;\n\t\t\tt = b[2];\n\t\t\tr[2] = (0-t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=1;\n\t\t\tif (++dl >= 0) break;\n\t\t\tt = b[3];\n\t\t\tr[3] = (0-t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=1;\n\t\t\tif (++dl >= 0) break;\n\t\t\tb += 4;\n\t\t\tr += 4;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tint save_dl = dl;\n#ifdef BN_COUNT\n\t\tfprintf(stderr, "  bn_sub_part_words %d + %d (dl > 0, c = %d)\\n", cl, dl, c);\n#endif\n\t\twhile(c)\n\t\t\t{\n\t\t\tt = a[0];\n\t\t\tr[0] = (t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=0;\n\t\t\tif (--dl <= 0) break;\n\t\t\tt = a[1];\n\t\t\tr[1] = (t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=0;\n\t\t\tif (--dl <= 0) break;\n\t\t\tt = a[2];\n\t\t\tr[2] = (t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=0;\n\t\t\tif (--dl <= 0) break;\n\t\t\tt = a[3];\n\t\t\tr[3] = (t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=0;\n\t\t\tif (--dl <= 0) break;\n\t\t\tsave_dl = dl;\n\t\t\ta += 4;\n\t\t\tr += 4;\n\t\t\t}\n\t\tif (dl > 0)\n\t\t\t{\n#ifdef BN_COUNT\n\t\t\tfprintf(stderr, "  bn_sub_part_words %d + %d (dl > 0, c == 0)\\n", cl, dl);\n#endif\n\t\t\tif (save_dl > dl)\n\t\t\t\t{\n\t\t\t\tswitch (save_dl - dl)\n\t\t\t\t\t{\n\t\t\t\tcase 1:\n\t\t\t\t\tr[1] = a[1];\n\t\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tcase 2:\n\t\t\t\t\tr[2] = a[2];\n\t\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tcase 3:\n\t\t\t\t\tr[3] = a[3];\n\t\t\t\t\tif (--dl <= 0) break;\n\t\t\t\t\t}\n\t\t\t\ta += 4;\n\t\t\t\tr += 4;\n\t\t\t\t}\n\t\t\t}\n\t\tif (dl > 0)\n\t\t\t{\n#ifdef BN_COUNT\n\t\t\tfprintf(stderr, "  bn_sub_part_words %d + %d (dl > 0, copy)\\n", cl, dl);\n#endif\n\t\t\tfor(;;)\n\t\t\t\t{\n\t\t\t\tr[0] = a[0];\n\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tr[1] = a[1];\n\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tr[2] = a[2];\n\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tr[3] = a[3];\n\t\t\t\tif (--dl <= 0) break;\n\t\t\t\ta += 4;\n\t\t\t\tr += 4;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\treturn c;\n\t}', 'BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)\n        {\n\tBN_ULONG t1,t2;\n\tint c=0;\n\tassert(n >= 0);\n\tif (n <= 0) return((BN_ULONG)0);\n#ifndef OPENSSL_SMALL_FOOTPRINT\n\twhile (n&~3)\n\t\t{\n\t\tt1=a[0]; t2=b[0];\n\t\tr[0]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\tt1=a[1]; t2=b[1];\n\t\tr[1]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\tt1=a[2]; t2=b[2];\n\t\tr[2]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\tt1=a[3]; t2=b[3];\n\t\tr[3]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\ta+=4; b+=4; r+=4; n-=4;\n\t\t}\n#endif\n\twhile (n)\n\t\t{\n\t\tt1=a[0]; t2=b[0];\n\t\tr[0]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\ta++; b++; r++; n--;\n\t\t}\n\treturn(c);\n\t}']