ssl/s3_srvr.c:1333: error: BUFFER_OVERRUN_L3
  Offset: [10, +oo] (⇐ [8, +oo] + 2) Size: [0, +oo] by call to `DH_compute_key`.
Showing all 16 steps of the trace


ssl/s3_srvr.c:1326:7: Call
1324.   			}
1325.   
1326.   		pub=BN_bin2bn(p,i,NULL);
              ^
1327.   		if (pub == NULL)
1328.   			{

crypto/bn/bn_lib.c:595:1: Parameter `*ret->d`
  593.   
  594.   /* ignore negative */
  595. > BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
  596.   	{
  597.   	unsigned int i,m;

ssl/s3_srvr.c:1333:5: Call
1331.   			}
1332.   
1333.   		i=DH_compute_key(p,pub,dh_srvr);
            ^
1334.   
1335.   		if (i <= 0)

crypto/dh/dh_key.c:121:1: Parameter `*pub_key->d`
  119.   	}
  120.   
  121. > int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh)
  122.   	{
  123.   	BN_CTX ctx;

crypto/dh/dh_key.c:144:7: Call
  142.   
  143.   	mont=(BN_MONT_CTX *)dh->method_mont_p;
  144.   	if (!BN_mod_exp_mont(tmp,pub_key,dh->priv_key,dh->p,&ctx,mont))
               ^
  145.   		{
  146.   		DHerr(DH_F_DH_COMPUTE_KEY,ERR_R_BN_LIB);

crypto/bn/bn_exp.c:299:1: Parameter `*a->d`
    297.   
    298.   /* #ifdef MONT_MUL_MOD */
    299. > int BN_mod_exp_mont(BIGNUM *rr, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx,
    300.   	     BN_MONT_CTX *in_mont)
    301.   	{

crypto/bn/bn_exp.c:348:7: Call
    346.   	else
    347.   		aa=a;
    348.   	if (!BN_to_montgomery(&(val[0]),aa,mont,ctx)) goto err; /* 1 */
                 ^
    349.   	if (!BN_mod_mul_montgomery(d,&(val[0]),&(val[0]),mont,ctx)) goto err; /* 2 */
    350.   

crypto/bn/bn_mont.c:71:1: Parameter `*a->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: Parameter `*a->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:686:4: Call
        684.   			for (i=b->top; i<k; i++)
        685.   				b->d[i]=0;
        686.   			bn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);
                  ^
        687.   			}
        688.   		rr->top=top;

crypto/bn/bn_mul.c:218:1: Parameter `n`
          216.   /* n+tn is the word length
          217.    * t needs to be n*4 is size, as does r */
          218. > void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int tn,
          219.   	     int n, BN_ULONG *t)
          220.   	{

crypto/bn/bn_mul.c:236:2: Call
          234.   
          235.   	/* r=(a[0]-a[1])*(b[1]-b[0]) */
          236.   	bn_sub_words(t,      a,      &(a[n]),n); /* + */
                  ^
          237.   	bn_sub_words(&(t[n]),b,      &(b[n]),n); /* - */
          238.   

crypto/bn/bn_asm.c:390:1: <Length trace>
388.   #endif
389.   
390. > BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
391.           {
392.   	BN_ULONG t1,t2;

crypto/bn/bn_asm.c:390:1: Parameter `*b`
            388.   #endif
            389.   
            390. > BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
            391.           {
            392.   	BN_ULONG t1,t2;

crypto/bn/bn_asm.c:410:15: Array access: Offset: [10, +oo] (⇐ [8, +oo] + 2) Size: [0, +oo] by call to `DH_compute_key` 
            408.   		if (--n <= 0) break;
            409.   
            410.   		t1=a[2]; t2=b[2];
                                 ^
            411.   		r[2]=(t1-t2-c)&BN_MASK2;
            412.   		if (t1 != t2) c=(t1 < t2);

BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
        {
	BN_ULONG t1,t2;
	int c=0;
	bn_check_num(n);
	if (n <= 0) return((BN_ULONG)0);
	for (;;)
		{
		t1=a[0]; t2=b[0];
		r[0]=(t1-t2-c)&BN_MASK2;
		if (t1 != t2) c=(t1 < t2);
		if (--n <= 0) break;
		t1=a[1]; t2=b[1];
		r[1]=(t1-t2-c)&BN_MASK2;
		if (t1 != t2) c=(t1 < t2);
		if (--n <= 0) break;
		t1=a[2]; t2=b[2];
		r[2]=(t1-t2-c)&BN_MASK2;
		if (t1 != t2) c=(t1 < t2);
		if (--n <= 0) break;
		t1=a[3]; t2=b[3];
		r[3]=(t1-t2-c)&BN_MASK2;
		if (t1 != t2) c=(t1 < t2);
		if (--n <= 0) break;
		a+=4;
		b+=4;
		r+=4;
		}
	return(c);
	}
['static int ssl3_get_client_key_exchange(SSL *s)\n\t{\n\tint i,al,ok;\n\tlong n;\n\tunsigned long l;\n\tunsigned char *p;\n#ifndef NO_RSA\n\tRSA *rsa=NULL;\n\tEVP_PKEY *pkey=NULL;\n#endif\n#ifndef NO_DH\n\tBIGNUM *pub=NULL;\n\tDH *dh_srvr;\n#endif\n\tn=ssl3_get_message(s,\n\t\tSSL3_ST_SR_KEY_EXCH_A,\n\t\tSSL3_ST_SR_KEY_EXCH_B,\n\t\tSSL3_MT_CLIENT_KEY_EXCHANGE,\n\t\t400,\n\t\t&ok);\n\tif (!ok) return((int)n);\n\tp=(unsigned char *)s->init_buf->data;\n\tl=s->s3->tmp.new_cipher->algorithms;\n#ifndef NO_RSA\n\tif (l & SSL_kRSA)\n\t\t{\n\t\tif (s->s3->tmp.use_rsa_tmp)\n\t\t\t{\n\t\t\tif ((s->cert != NULL) && (s->cert->rsa_tmp != NULL))\n\t\t\t\trsa=s->cert->rsa_tmp;\n\t\t\tif (rsa == NULL)\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_RSA_PKEY);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tpkey=s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey;\n\t\t\tif (\t(pkey == NULL) ||\n\t\t\t\t(pkey->type != EVP_PKEY_RSA) ||\n\t\t\t\t(pkey->pkey.rsa == NULL))\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_RSA_CERTIFICATE);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\trsa=pkey->pkey.rsa;\n\t\t\t}\n\t\tif (s->version > SSL3_VERSION)\n\t\t\t{\n\t\t\tn2s(p,i);\n\t\t\tif (n != i+2)\n\t\t\t\t{\n\t\t\t\tif (!(s->options & SSL_OP_TLS_D5_BUG))\n\t\t\t\t\t{\n\t\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG);\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\tp-=2;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tn=i;\n\t\t\t}\n\t\ti=RSA_private_decrypt((int)n,p,p,rsa,RSA_PKCS1_PADDING);\n#if 1\n\t\tif ((i != SSL_MAX_MASTER_KEY_LENGTH) ||\n\t\t\t((p[0] != (s->client_version>>8)) ||\n\t\t\t (p[1] != (s->client_version & 0xff))))\n\t\t\t{\n\t\t\tint bad=1;\n\t\t\tif ((i == SSL_MAX_MASTER_KEY_LENGTH) &&\n\t\t\t\t(p[0] == (s->version>>8)) &&\n\t\t\t\t(p[1] == 0))\n\t\t\t\t{\n\t\t\t\tif (s->options & SSL_OP_TLS_ROLLBACK_BUG)\n\t\t\t\t\tbad=0;\n\t\t\t\t}\n\t\t\tif (bad)\n\t\t\t\t{\n\t\t\t\tp[0]=(s->version>>8);\n\t\t\t\tp[1]=(s->version & 0xff);\n\t\t\t\tRAND_bytes(&(p[2]),SSL_MAX_MASTER_KEY_LENGTH-2);\n\t\t\t\ti=SSL_MAX_MASTER_KEY_LENGTH;\n\t\t\t\t}\n\t\t\t}\n#else\n\t\tif (i != SSL_MAX_MASTER_KEY_LENGTH)\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif ((p[0] != (s->version>>8)) || (p[1] != (s->version & 0xff)))\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_PROTOCOL_VERSION_NUMBER);\n\t\t\tgoto f_err;\n\t\t\t}\n#endif\n\t\ts->session->master_key_length=\n\t\t\ts->method->ssl3_enc->generate_master_secret(s,\n\t\t\t\ts->session->master_key,\n\t\t\t\tp,i);\n\t\tmemset(p,0,i);\n\t\t}\n\telse\n#endif\n#ifndef NO_DH\n\t\tif (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd))\n\t\t{\n\t\tn2s(p,i);\n\t\tif (n != i+2)\n\t\t\t{\n\t\t\tif (!(s->options & SSL_OP_SSLEAY_080_CLIENT_DH_BUG))\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tp-=2;\n\t\t\t\ti=(int)n;\n\t\t\t\t}\n\t\t\t}\n\t\tif (n == 0L)\n\t\t\t{\n\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_UNABLE_TO_DECODE_DH_CERTS);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (s->s3->tmp.dh == NULL)\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_DH_KEY);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tdh_srvr=s->s3->tmp.dh;\n\t\t\t}\n\t\tpub=BN_bin2bn(p,i,NULL);\n\t\tif (pub == NULL)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BN_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\ti=DH_compute_key(p,pub,dh_srvr);\n\t\tif (i <= 0)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tDH_free(s->s3->tmp.dh);\n\t\ts->s3->tmp.dh=NULL;\n\t\tBN_clear_free(pub);\n\t\tpub=NULL;\n\t\ts->session->master_key_length=\n\t\t\ts->method->ssl3_enc->generate_master_secret(s,\n\t\t\t\ts->session->master_key,p,i);\n\t\t}\n\telse\n#endif\n\t\t{\n\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_UNKNOWN_CIPHER_TYPE);\n\t\tgoto f_err;\n\t\t}\n\treturn(1);\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\n#if !defined(NO_DH) || !defined(NO_RSA)\nerr:\n#endif\n\treturn(-1);\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\tif (ret == NULL) ret=BN_new();\n\tif (ret == NULL) return(NULL);\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\tif (bn_expand(ret,(int)(n+2)*8) == NULL)\n\t\treturn(NULL);\n\ti=((n-1)/BN_BYTES)+1;\n\tm=((n-1)%(BN_BYTES));\n\tret->top=i;\n\twhile (n-- > 0)\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_fix_top(ret);\n\treturn(ret);\n\t}', 'int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh)\n\t{\n\tBN_CTX ctx;\n\tBN_MONT_CTX *mont;\n\tBIGNUM *tmp;\n\tint ret= -1;\n\tBN_CTX_init(&ctx);\n\ttmp= &(ctx.bn[ctx.tos++]);\n\tif (dh->priv_key == NULL)\n\t\t{\n\t\tDHerr(DH_F_DH_COMPUTE_KEY,DH_R_NO_PRIVATE_VALUE);\n\t\tgoto err;\n\t\t}\n\tif ((dh->method_mont_p == NULL) && (dh->flags & DH_FLAG_CACHE_MONT_P))\n\t\t{\n\t\tif ((dh->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)\n\t\t\tif (!BN_MONT_CTX_set((BN_MONT_CTX *)dh->method_mont_p,\n\t\t\t\tdh->p,&ctx)) goto err;\n\t\t}\n\tmont=(BN_MONT_CTX *)dh->method_mont_p;\n\tif (!BN_mod_exp_mont(tmp,pub_key,dh->priv_key,dh->p,&ctx,mont))\n\t\t{\n\t\tDHerr(DH_F_DH_COMPUTE_KEY,ERR_R_BN_LIB);\n\t\tgoto err;\n\t\t}\n\tret=BN_bn2bin(tmp,key);\nerr:\n\tBN_CTX_free(&ctx);\n\treturn(ret);\n\t}', 'int BN_mod_exp_mont(BIGNUM *rr, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx,\n\t     BN_MONT_CTX *in_mont)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue;\n\tint start=1,ts=0;\n\tBIGNUM *d,*aa,*r;\n\tBIGNUM val[TABLE_SIZE];\n\tBN_MONT_CTX *mont=NULL;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n\tif (!(m->d[0] & 1))\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\td= &(ctx->bn[ctx->tos++]);\n\tr= &(ctx->bn[ctx->tos++]);\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tBN_one(r);\n\t\treturn(1);\n\t\t}\n#if 1\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\n#endif\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\tBN_init(&val[0]);\n\tts=1;\n\tif (BN_ucmp(a,m) >= 0)\n\t\t{\n\t\tBN_mod(&(val[0]),a,m,ctx);\n\t\taa= &(val[0]);\n\t\t}\n\telse\n\t\taa=a;\n\tif (!BN_to_montgomery(&(val[0]),aa,mont,ctx)) goto err;\n\tif (!BN_mod_mul_montgomery(d,&(val[0]),&(val[0]),mont,ctx)) goto err;\n\tif (bits <= 20)\n\t\twindow=1;\n\telse if (bits >= 256)\n\t\twindow=5;\n\telse if (bits >= 128)\n\t\twindow=4;\n\telse\n\t\twindow=3;\n\tj=1<<(window-1);\n\tfor (i=1; i<j; i++)\n\t\t{\n\t\tBN_init(&(val[i]));\n\t\tif (!BN_mod_mul_montgomery(&(val[i]),&(val[i-1]),d,mont,ctx))\n\t\t\tgoto err;\n\t\t}\n\tts=i;\n\tstart=1;\n\twvalue=0;\n\twstart=bits-1;\n\twend=0;\n        if (!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\tBN_from_montgomery(rr,r,mont,ctx);\n\tret=1;\nerr:\n\tif ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);\n\tctx->tos-=2;\n\tfor (i=0; i<ts; i++)\n\t\tBN_clear_free(&(val[i]));\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}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int tn,\n\t     int n, BN_ULONG *t)\n\t{\n\tint i,j,n2=n*2;\n\tunsigned int c1;\n\tBN_ULONG ln,lo,*p;\n#ifdef BN_COUNT\nprintf(" bn_mul_part_recursive %d * %d\\n",tn+n,tn+n);\n#endif\n\tif (n < 8)\n\t\t{\n\t\ti=tn+n;\n\t\tbn_mul_normal(r,a,i,b,i);\n\t\treturn;\n\t\t}\n\tbn_sub_words(t,      a,      &(a[n]),n);\n\tbn_sub_words(&(t[n]),b,      &(b[n]),n);\n  if (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]),tn,&(b[n]),tn);\n\t\tmemset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2));\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,p);\n\t\tbn_mul_recursive(r,a,b,n,p);\n\t\ti=n/2;\n\t\tj=tn-i;\n\t\tif (j == 0)\n\t\t\t{\n\t\t\tbn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),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\tj,i,p);\n\t\t\t\tmemset(&(r[n2+tn*2]),0,\n\t\t\t\t\tsizeof(BN_ULONG)*(n2-tn*2));\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 (tn < BN_MUL_RECURSIVE_SIZE_NORMAL)\n\t\t\t\t{\n\t\t\t\tbn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);\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 < tn)\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\ttn-i,i,p);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\telse if (i == tn)\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,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\tc1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));\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 < 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}', 'BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)\n        {\n\tBN_ULONG t1,t2;\n\tint c=0;\n\tbn_check_num(n);\n\tif (n <= 0) return((BN_ULONG)0);\n\tfor (;;)\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\tif (--n <= 0) break;\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\tif (--n <= 0) break;\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\tif (--n <= 0) break;\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\tif (--n <= 0) break;\n\t\ta+=4;\n\t\tb+=4;\n\t\tr+=4;\n\t\t}\n\treturn(c);\n\t}']