ssl/d1_clnt.c:294: error: INTEGER_OVERFLOW_L2
  ([0, `s->session->sess_cert->peer_pkeys[*].x509->cert_info->key->pkey->pkey.rsa->n->top`] - 1):unsigned64 by call to `ssl3_get_key_exchange`.
Showing all 13 steps of the trace


ssl/d1_clnt.c:144:1: Parameter `s->session->sess_cert->peer_pkeys[*].x509->cert_info->key->pkey->pkey.rsa->n->top`
142.   			dtls1_get_client_method)
143.   
144. > int dtls1_connect(SSL *s)
145.   	{
146.   	BUF_MEM *buf=NULL;

ssl/d1_clnt.c:294:8: Call
292.   		case SSL3_ST_CR_KEY_EXCH_A:
293.   		case SSL3_ST_CR_KEY_EXCH_B:
294.   			ret=ssl3_get_key_exchange(s);
              ^
295.   			if (ret <= 0) goto end;
296.   			s->state=SSL3_ST_CR_CERT_REQ_A;

ssl/s3_clnt.c:1104:1: Parameter `s->session->sess_cert->peer_pkeys[*].x509->cert_info->key->pkey->pkey.rsa->n->top`
  1102.   	}
  1103.   
  1104. > int ssl3_get_key_exchange(SSL *s)
  1105.   	{
  1106.   #ifndef OPENSSL_NO_RSA

ssl/s3_clnt.c:1513:6: Call
  1511.   				j+=i;
  1512.   				}
  1513.   			i=RSA_verify(NID_md5_sha1, md_buf, j, p, n,
               ^
  1514.   								pkey->pkey.rsa);
  1515.   			if (i < 0)

crypto/rsa/rsa_sign.c:273:1: Parameter `rsa->n->top`
    271.   	}
    272.   
    273. > int RSA_verify(int dtype, const unsigned char *m, unsigned int m_len,
    274.   		const unsigned char *sigbuf, unsigned int siglen,
    275.   		RSA *rsa)

crypto/rsa/rsa_sign.c:284:9: Call
    282.   		}
    283.   
    284.   	return int_rsa_verify(dtype, m, m_len, NULL, NULL, sigbuf, siglen, rsa);
                   ^
    285.   	}

crypto/rsa/rsa_sign.c:146:1: Parameter `rsa->n->top`
      144.   	}
      145.   
      146. > int int_rsa_verify(int dtype, const unsigned char *m,
      147.   			  unsigned int m_len,
      148.   			  unsigned char *rm, size_t *prm_len,

crypto/rsa/rsa_sign.c:156:30: Call
      154.   	X509_SIG *sig=NULL;
      155.   
      156.   	if (siglen != (unsigned int)RSA_size(rsa))
                                          ^
      157.   		{
      158.   		RSAerr(RSA_F_INT_RSA_VERIFY,RSA_R_WRONG_SIGNATURE_LENGTH);

crypto/rsa/rsa_lib.c:274:1: Parameter `r->n->top`
        272.   	}
        273.   
        274. > int RSA_size(const RSA *r)
        275.   	{
        276.   	return(BN_num_bytes(r->n));

crypto/rsa/rsa_lib.c:276:9: Call
        274.   int RSA_size(const RSA *r)
        275.   	{
        276.   	return(BN_num_bytes(r->n));
                       ^
        277.   	}
        278.   

crypto/bn/bn_lib.c:248:1: <LHS trace>
246.   	}
247.   
248. > int BN_num_bits(const BIGNUM *a)
249.   	{
250.   	int i = a->top - 1;

crypto/bn/bn_lib.c:248:1: Parameter `a->top`
          246.   	}
          247.   
          248. > int BN_num_bits(const BIGNUM *a)
          249.   	{
          250.   	int i = a->top - 1;

crypto/bn/bn_lib.c:250:2: Binary operation: ([0, s->session->sess_cert->peer_pkeys[*].x509->cert_info->key->pkey->pkey.rsa->n->top] - 1):unsigned64 by call to `ssl3_get_key_exchange` 
          248.   int BN_num_bits(const BIGNUM *a)
          249.   	{
          250.   	int i = a->top - 1;
                  ^
          251.   	bn_check_top(a);
          252.   

int BN_num_bits(const BIGNUM *a)
	{
	int i = a->top - 1;
	bn_check_top(a);
	if (BN_is_zero(a)) return 0;
	return ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));
	}
['int dtls1_connect(SSL *s)\n\t{\n\tBUF_MEM *buf=NULL;\n\tunsigned long Time=(unsigned long)time(NULL);\n\tlong num1;\n\tvoid (*cb)(const SSL *ssl,int type,int val)=NULL;\n\tint ret= -1;\n\tint new_state,state,skip=0;;\n\tRAND_add(&Time,sizeof(Time),0);\n\tERR_clear_error();\n\tclear_sys_error();\n\tif (s->info_callback != NULL)\n\t\tcb=s->info_callback;\n\telse if (s->ctx->info_callback != NULL)\n\t\tcb=s->ctx->info_callback;\n\ts->in_handshake++;\n\tif (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);\n\tfor (;;)\n\t\t{\n\t\tstate=s->state;\n\t\tswitch(s->state)\n\t\t\t{\n\t\tcase SSL_ST_RENEGOTIATE:\n\t\t\ts->new_session=1;\n\t\t\ts->state=SSL_ST_CONNECT;\n\t\t\ts->ctx->stats.sess_connect_renegotiate++;\n\t\tcase SSL_ST_BEFORE:\n\t\tcase SSL_ST_CONNECT:\n\t\tcase SSL_ST_BEFORE|SSL_ST_CONNECT:\n\t\tcase SSL_ST_OK|SSL_ST_CONNECT:\n\t\t\ts->server=0;\n\t\t\tif (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);\n\t\t\tif ((s->version & 0xff00 ) != (DTLS1_VERSION & 0xff00))\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_DTLS1_CONNECT, ERR_R_INTERNAL_ERROR);\n\t\t\t\tret = -1;\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\ts->type=SSL_ST_CONNECT;\n\t\t\tif (s->init_buf == NULL)\n\t\t\t\t{\n\t\t\t\tif ((buf=BUF_MEM_new()) == NULL)\n\t\t\t\t\t{\n\t\t\t\t\tret= -1;\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\tif (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH))\n\t\t\t\t\t{\n\t\t\t\t\tret= -1;\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\ts->init_buf=buf;\n\t\t\t\tbuf=NULL;\n\t\t\t\t}\n\t\t\tif (!ssl3_setup_buffers(s)) { ret= -1; goto end; }\n\t\t\tif (!ssl_init_wbio_buffer(s,0)) { ret= -1; goto end; }\n\t\t\ts->state=SSL3_ST_CW_CLNT_HELLO_A;\n\t\t\ts->ctx->stats.sess_connect++;\n\t\t\ts->init_num=0;\n\t\t\tmemset(s->s3->client_random,0,sizeof(s->s3->client_random));\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_CLNT_HELLO_A:\n\t\tcase SSL3_ST_CW_CLNT_HELLO_B:\n\t\t\ts->shutdown=0;\n\t\t\tssl3_init_finished_mac(s);\n\t\t\tret=dtls1_client_hello(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\tif ( s->d1->send_cookie)\n\t\t\t\t{\n\t\t\t\ts->state=SSL3_ST_CW_FLUSH;\n\t\t\t\ts->s3->tmp.next_state=SSL3_ST_CR_SRVR_HELLO_A;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\ts->state=SSL3_ST_CR_SRVR_HELLO_A;\n\t\t\ts->init_num=0;\n\t\t\tif (s->bbio != s->wbio)\n\t\t\t\ts->wbio=BIO_push(s->bbio,s->wbio);\n\t\t\tbreak;\n\t\tcase SSL3_ST_CR_SRVR_HELLO_A:\n\t\tcase SSL3_ST_CR_SRVR_HELLO_B:\n\t\t\tret=ssl3_get_server_hello(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (s->hit)\n\t\t\t\t\ts->state=SSL3_ST_CR_FINISHED_A;\n\t\t\t\telse\n\t\t\t\t\ts->state=DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A;\n\t\t\t\t}\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:\n\t\tcase DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B:\n\t\t\tret = dtls1_get_hello_verify(s);\n\t\t\tif ( ret <= 0)\n\t\t\t\tgoto end;\n\t\t\tif ( s->d1->send_cookie)\n\t\t\t\ts->state=SSL3_ST_CW_CLNT_HELLO_A;\n\t\t\telse\n\t\t\t\ts->state = SSL3_ST_CR_CERT_A;\n\t\t\ts->init_num = 0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CR_CERT_A:\n\t\tcase SSL3_ST_CR_CERT_B:\n\t\t\tif (!(s->s3->tmp.new_cipher->algorithm_auth & SSL_aNULL))\n\t\t\t\t{\n\t\t\t\tret=ssl3_get_server_certificate(s);\n\t\t\t\tif (ret <= 0) goto end;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tskip=1;\n\t\t\ts->state=SSL3_ST_CR_KEY_EXCH_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CR_KEY_EXCH_A:\n\t\tcase SSL3_ST_CR_KEY_EXCH_B:\n\t\t\tret=ssl3_get_key_exchange(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CR_CERT_REQ_A;\n\t\t\ts->init_num=0;\n\t\t\tif (!ssl3_check_cert_and_algorithm(s))\n\t\t\t\t{\n\t\t\t\tret= -1;\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tbreak;\n\t\tcase SSL3_ST_CR_CERT_REQ_A:\n\t\tcase SSL3_ST_CR_CERT_REQ_B:\n\t\t\tret=ssl3_get_certificate_request(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CR_SRVR_DONE_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CR_SRVR_DONE_A:\n\t\tcase SSL3_ST_CR_SRVR_DONE_B:\n\t\t\tret=ssl3_get_server_done(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\tif (s->s3->tmp.cert_req)\n\t\t\t\ts->state=SSL3_ST_CW_CERT_A;\n\t\t\telse\n\t\t\t\ts->state=SSL3_ST_CW_KEY_EXCH_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_CERT_A:\n\t\tcase SSL3_ST_CW_CERT_B:\n\t\tcase SSL3_ST_CW_CERT_C:\n\t\tcase SSL3_ST_CW_CERT_D:\n\t\t\tret=dtls1_send_client_certificate(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CW_KEY_EXCH_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_KEY_EXCH_A:\n\t\tcase SSL3_ST_CW_KEY_EXCH_B:\n\t\t\tret=dtls1_send_client_key_exchange(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\tif (s->s3->tmp.cert_req == 1)\n\t\t\t\t{\n\t\t\t\ts->state=SSL3_ST_CW_CERT_VRFY_A;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\ts->state=SSL3_ST_CW_CHANGE_A;\n\t\t\t\ts->s3->change_cipher_spec=0;\n\t\t\t\t}\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_CERT_VRFY_A:\n\t\tcase SSL3_ST_CW_CERT_VRFY_B:\n\t\t\tret=dtls1_send_client_verify(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CW_CHANGE_A;\n\t\t\ts->init_num=0;\n\t\t\ts->s3->change_cipher_spec=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_CHANGE_A:\n\t\tcase SSL3_ST_CW_CHANGE_B:\n\t\t\tret=dtls1_send_change_cipher_spec(s,\n\t\t\t\tSSL3_ST_CW_CHANGE_A,SSL3_ST_CW_CHANGE_B);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CW_FINISHED_A;\n\t\t\ts->init_num=0;\n\t\t\ts->session->cipher=s->s3->tmp.new_cipher;\n#ifdef OPENSSL_NO_COMP\n\t\t\ts->session->compress_meth=0;\n#else\n\t\t\tif (s->s3->tmp.new_compression == NULL)\n\t\t\t\ts->session->compress_meth=0;\n\t\t\telse\n\t\t\t\ts->session->compress_meth=\n\t\t\t\t\ts->s3->tmp.new_compression->id;\n#endif\n\t\t\tif (!s->method->ssl3_enc->setup_key_block(s))\n\t\t\t\t{\n\t\t\t\tret= -1;\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tif (!s->method->ssl3_enc->change_cipher_state(s,\n\t\t\t\tSSL3_CHANGE_CIPHER_CLIENT_WRITE))\n\t\t\t\t{\n\t\t\t\tret= -1;\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tdtls1_reset_seq_numbers(s, SSL3_CC_WRITE);\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_FINISHED_A:\n\t\tcase SSL3_ST_CW_FINISHED_B:\n\t\t\tret=dtls1_send_finished(s,\n\t\t\t\tSSL3_ST_CW_FINISHED_A,SSL3_ST_CW_FINISHED_B,\n\t\t\t\ts->method->ssl3_enc->client_finished_label,\n\t\t\t\ts->method->ssl3_enc->client_finished_label_len);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CW_FLUSH;\n\t\t\ts->s3->flags&= ~SSL3_FLAGS_POP_BUFFER;\n\t\t\tif (s->hit)\n\t\t\t\t{\n\t\t\t\ts->s3->tmp.next_state=SSL_ST_OK;\n\t\t\t\tif (s->s3->flags & SSL3_FLAGS_DELAY_CLIENT_FINISHED)\n\t\t\t\t\t{\n\t\t\t\t\ts->state=SSL_ST_OK;\n\t\t\t\t\ts->s3->flags|=SSL3_FLAGS_POP_BUFFER;\n\t\t\t\t\ts->s3->delay_buf_pop_ret=0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\ts->s3->tmp.next_state=SSL3_ST_CR_FINISHED_A;\n\t\t\t\t}\n\t\t\ts->init_num=0;\n\t\t\tmemset (s->s3->client_random,0,sizeof(s->s3->client_random));\n\t\t\tbreak;\n\t\tcase SSL3_ST_CR_FINISHED_A:\n\t\tcase SSL3_ST_CR_FINISHED_B:\n\t\t\tret=ssl3_get_finished(s,SSL3_ST_CR_FINISHED_A,\n\t\t\t\tSSL3_ST_CR_FINISHED_B);\n\t\t\tif (ret <= 0) goto end;\n\t\t\tif (s->hit)\n\t\t\t\ts->state=SSL3_ST_CW_CHANGE_A;\n\t\t\telse\n\t\t\t\ts->state=SSL_ST_OK;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_FLUSH:\n\t\t\tnum1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL);\n\t\t\tif (num1 > 0)\n\t\t\t\t{\n\t\t\t\ts->rwstate=SSL_WRITING;\n\t\t\t\tnum1=BIO_flush(s->wbio);\n\t\t\t\tif (num1 <= 0) { ret= -1; goto end; }\n\t\t\t\ts->rwstate=SSL_NOTHING;\n\t\t\t\t}\n\t\t\ts->state=s->s3->tmp.next_state;\n\t\t\tbreak;\n\t\tcase SSL_ST_OK:\n\t\t\tssl3_cleanup_key_block(s);\n#if 0\n\t\t\tif (s->init_buf != NULL)\n\t\t\t\t{\n\t\t\t\tBUF_MEM_free(s->init_buf);\n\t\t\t\ts->init_buf=NULL;\n\t\t\t\t}\n#endif\n\t\t\tif (!(s->s3->flags & SSL3_FLAGS_POP_BUFFER))\n\t\t\t\tssl_free_wbio_buffer(s);\n\t\t\ts->init_num=0;\n\t\t\ts->new_session=0;\n\t\t\tssl_update_cache(s,SSL_SESS_CACHE_CLIENT);\n\t\t\tif (s->hit) s->ctx->stats.sess_hit++;\n\t\t\tret=1;\n\t\t\ts->handshake_func=dtls1_connect;\n\t\t\ts->ctx->stats.sess_connect_good++;\n\t\t\tif (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1);\n\t\t\ts->d1->handshake_read_seq  = 0;\n\t\t\tgoto end;\n\t\tdefault:\n\t\t\tSSLerr(SSL_F_DTLS1_CONNECT,SSL_R_UNKNOWN_STATE);\n\t\t\tret= -1;\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (!s->s3->tmp.reuse_message && !skip)\n\t\t\t{\n\t\t\tif (s->debug)\n\t\t\t\t{\n\t\t\t\tif ((ret=BIO_flush(s->wbio)) <= 0)\n\t\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tif ((cb != NULL) && (s->state != state))\n\t\t\t\t{\n\t\t\t\tnew_state=s->state;\n\t\t\t\ts->state=state;\n\t\t\t\tcb(s,SSL_CB_CONNECT_LOOP,1);\n\t\t\t\ts->state=new_state;\n\t\t\t\t}\n\t\t\t}\n\t\tskip=0;\n\t\t}\nend:\n\ts->in_handshake--;\n\tif (buf != NULL)\n\t\tBUF_MEM_free(buf);\n\tif (cb != NULL)\n\t\tcb(s,SSL_CB_CONNECT_EXIT,ret);\n\treturn(ret);\n\t}', 'int ssl3_get_key_exchange(SSL *s)\n\t{\n#ifndef OPENSSL_NO_RSA\n\tunsigned char *q,md_buf[EVP_MAX_MD_SIZE*2];\n#endif\n\tEVP_MD_CTX md_ctx;\n\tunsigned char *param,*p;\n\tint al,i,j,param_len,ok;\n\tlong n,alg_k,alg_a;\n\tEVP_PKEY *pkey=NULL;\n#ifndef OPENSSL_NO_RSA\n\tRSA *rsa=NULL;\n#endif\n#ifndef OPENSSL_NO_DH\n\tDH *dh=NULL;\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tEC_KEY *ecdh = NULL;\n\tBN_CTX *bn_ctx = NULL;\n\tEC_POINT *srvr_ecpoint = NULL;\n\tint curve_nid = 0;\n\tint encoded_pt_len = 0;\n#endif\n\tn=s->method->ssl_get_message(s,\n\t\tSSL3_ST_CR_KEY_EXCH_A,\n\t\tSSL3_ST_CR_KEY_EXCH_B,\n\t\t-1,\n\t\ts->max_cert_list,\n\t\t&ok);\n\tif (!ok) return((int)n);\n\tif (s->s3->tmp.message_type != SSL3_MT_SERVER_KEY_EXCHANGE)\n\t\t{\n#ifndef OPENSSL_NO_PSK\n\t\tif (s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK)\n\t\t\t{\n\t\t\ts->session->sess_cert=ssl_sess_cert_new();\n\t\t\tif (s->ctx->psk_identity_hint)\n\t\t\t\tOPENSSL_free(s->ctx->psk_identity_hint);\n\t\t\ts->ctx->psk_identity_hint = NULL;\n\t\t\t}\n#endif\n\t\ts->s3->tmp.reuse_message=1;\n\t\treturn(1);\n\t\t}\n\tparam=p=(unsigned char *)s->init_msg;\n\tif (s->session->sess_cert != NULL)\n\t\t{\n#ifndef OPENSSL_NO_RSA\n\t\tif (s->session->sess_cert->peer_rsa_tmp != NULL)\n\t\t\t{\n\t\t\tRSA_free(s->session->sess_cert->peer_rsa_tmp);\n\t\t\ts->session->sess_cert->peer_rsa_tmp=NULL;\n\t\t\t}\n#endif\n#ifndef OPENSSL_NO_DH\n\t\tif (s->session->sess_cert->peer_dh_tmp)\n\t\t\t{\n\t\t\tDH_free(s->session->sess_cert->peer_dh_tmp);\n\t\t\ts->session->sess_cert->peer_dh_tmp=NULL;\n\t\t\t}\n#endif\n#ifndef OPENSSL_NO_ECDH\n\t\tif (s->session->sess_cert->peer_ecdh_tmp)\n\t\t\t{\n\t\t\tEC_KEY_free(s->session->sess_cert->peer_ecdh_tmp);\n\t\t\ts->session->sess_cert->peer_ecdh_tmp=NULL;\n\t\t\t}\n#endif\n\t\t}\n\telse\n\t\t{\n\t\ts->session->sess_cert=ssl_sess_cert_new();\n\t\t}\n\tparam_len=0;\n\talg_k=s->s3->tmp.new_cipher->algorithm_mkey;\n\talg_a=s->s3->tmp.new_cipher->algorithm_auth;\n\tEVP_MD_CTX_init(&md_ctx);\n#ifndef OPENSSL_NO_PSK\n\tif (alg_k & SSL_kPSK)\n\t\t{\n\t\tchar tmp_id_hint[PSK_MAX_IDENTITY_LEN+1];\n\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\tn2s(p,i);\n\t\tparam_len=i+2;\n\t\tif (i > PSK_MAX_IDENTITY_LEN)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,\n\t\t\t\tSSL_R_DATA_LENGTH_TOO_LONG);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (param_len > n)\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,\n\t\t\t\tSSL_R_BAD_PSK_IDENTITY_HINT_LENGTH);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tmemcpy(tmp_id_hint, p, i);\n\t\tmemset(tmp_id_hint+i, 0, PSK_MAX_IDENTITY_LEN+1-i);\n\t\tif (s->ctx->psk_identity_hint != NULL)\n\t\t\tOPENSSL_free(s->ctx->psk_identity_hint);\n\t\ts->ctx->psk_identity_hint = BUF_strdup(tmp_id_hint);\n\t\tif (s->ctx->psk_identity_hint == NULL)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tp+=i;\n\t\tn-=param_len;\n\t\t}\n\telse\n#endif\n#ifndef OPENSSL_NO_RSA\n\tif (alg_k & SSL_kRSA)\n\t\t{\n\t\tif ((rsa=RSA_new()) == NULL)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE);\n\t\t\tgoto err;\n\t\t\t}\n\t\tn2s(p,i);\n\t\tparam_len=i+2;\n\t\tif (param_len > n)\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_MODULUS_LENGTH);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (!(rsa->n=BN_bin2bn(p,i,rsa->n)))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tp+=i;\n\t\tn2s(p,i);\n\t\tparam_len+=i+2;\n\t\tif (param_len > n)\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_E_LENGTH);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (!(rsa->e=BN_bin2bn(p,i,rsa->e)))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tp+=i;\n\t\tn-=param_len;\n\t\tif (alg_a & SSL_aRSA)\n\t\t\tpkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509);\n\t\telse\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_INTERNAL_ERROR);\n\t\t\tgoto err;\n\t\t\t}\n\t\ts->session->sess_cert->peer_rsa_tmp=rsa;\n\t\trsa=NULL;\n\t\t}\n#else\n\tif (0)\n\t\t;\n#endif\n#ifndef OPENSSL_NO_DH\n\telse if (alg_k & SSL_kEDH)\n\t\t{\n\t\tif ((dh=DH_new()) == NULL)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_DH_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tn2s(p,i);\n\t\tparam_len=i+2;\n\t\tif (param_len > n)\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_P_LENGTH);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (!(dh->p=BN_bin2bn(p,i,NULL)))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tp+=i;\n\t\tn2s(p,i);\n\t\tparam_len+=i+2;\n\t\tif (param_len > n)\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_G_LENGTH);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (!(dh->g=BN_bin2bn(p,i,NULL)))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tp+=i;\n\t\tn2s(p,i);\n\t\tparam_len+=i+2;\n\t\tif (param_len > n)\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_PUB_KEY_LENGTH);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (!(dh->pub_key=BN_bin2bn(p,i,NULL)))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tp+=i;\n\t\tn-=param_len;\n#ifndef OPENSSL_NO_RSA\n\t\tif (alg_a & SSL_aRSA)\n\t\t\tpkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509);\n#else\n\t\tif (0)\n\t\t\t;\n#endif\n#ifndef OPENSSL_NO_DSA\n\t\telse if (alg_a & SSL_aDSS)\n\t\t\tpkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_DSA_SIGN].x509);\n#endif\n\t\ts->session->sess_cert->peer_dh_tmp=dh;\n\t\tdh=NULL;\n\t\t}\n\telse if ((alg_k & SSL_kDHr) || (alg_k & SSL_kDHd))\n\t\t{\n\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER);\n\t\tgoto f_err;\n\t\t}\n#endif\n#ifndef OPENSSL_NO_ECDH\n\telse if (alg_k & SSL_kEECDH)\n\t\t{\n\t\tEC_GROUP *ngroup;\n\t\tconst EC_GROUP *group;\n\t\tif ((ecdh=EC_KEY_new()) == NULL)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE);\n\t\t\tgoto err;\n\t\t\t}\n\t\tparam_len=3;\n\t\tif ((param_len > n) ||\n\t\t    (*p != NAMED_CURVE_TYPE) ||\n\t\t    ((curve_nid = tls1_ec_curve_id2nid(*(p + 2))) == 0))\n\t\t\t{\n\t\t\tal=SSL_AD_INTERNAL_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_UNABLE_TO_FIND_ECDH_PARAMETERS);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tngroup = EC_GROUP_new_by_curve_name(curve_nid);\n\t\tif (ngroup == NULL)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_EC_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (EC_KEY_set_group(ecdh, ngroup) == 0)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_EC_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tEC_GROUP_free(ngroup);\n\t\tgroup = EC_KEY_get0_group(ecdh);\n\t\tif (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) &&\n\t\t    (EC_GROUP_get_degree(group) > 163))\n\t\t\t{\n\t\t\tal=SSL_AD_EXPORT_RESTRICTION;\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_ECGROUP_TOO_LARGE_FOR_CIPHER);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tp+=3;\n\t\tif (((srvr_ecpoint = EC_POINT_new(group)) == NULL) ||\n\t\t    ((bn_ctx = BN_CTX_new()) == NULL))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE);\n\t\t\tgoto err;\n\t\t\t}\n\t\tencoded_pt_len = *p;\n\t\tp+=1;\n\t\tparam_len += (1 + encoded_pt_len);\n\t\tif ((param_len > n) ||\n\t\t    (EC_POINT_oct2point(group, srvr_ecpoint,\n\t\t\tp, encoded_pt_len, bn_ctx) == 0))\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_ECPOINT);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tn-=param_len;\n\t\tp+=encoded_pt_len;\n\t\tif (0) ;\n#ifndef OPENSSL_NO_RSA\n\t\telse if (alg_a & SSL_aRSA)\n\t\t\tpkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509);\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\t\telse if (alg_a & SSL_aECDSA)\n\t\t\tpkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_ECC].x509);\n#endif\n\t\tEC_KEY_set_public_key(ecdh, srvr_ecpoint);\n\t\ts->session->sess_cert->peer_ecdh_tmp=ecdh;\n\t\tecdh=NULL;\n\t\tBN_CTX_free(bn_ctx);\n\t\tEC_POINT_free(srvr_ecpoint);\n\t\tsrvr_ecpoint = NULL;\n\t\t}\n\telse if (alg_k)\n\t\t{\n\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_UNEXPECTED_MESSAGE);\n\t\tgoto f_err;\n\t\t}\n#endif\n\tif (pkey != NULL)\n\t\t{\n\t\tn2s(p,i);\n\t\tn-=2;\n\t\tj=EVP_PKEY_size(pkey);\n\t\tif ((i != n) || (n > j) || (n <= 0))\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_WRONG_SIGNATURE_LENGTH);\n\t\t\tgoto f_err;\n\t\t\t}\n#ifndef OPENSSL_NO_RSA\n\t\tif (pkey->type == EVP_PKEY_RSA)\n\t\t\t{\n\t\t\tint num;\n\t\t\tj=0;\n\t\t\tq=md_buf;\n\t\t\tfor (num=2; num > 0; num--)\n\t\t\t\t{\n\t\t\t\tEVP_DigestInit_ex(&md_ctx,(num == 2)\n\t\t\t\t\t?s->ctx->md5:s->ctx->sha1, NULL);\n\t\t\t\tEVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);\n\t\t\t\tEVP_DigestUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);\n\t\t\t\tEVP_DigestUpdate(&md_ctx,param,param_len);\n\t\t\t\tEVP_DigestFinal_ex(&md_ctx,q,(unsigned int *)&i);\n\t\t\t\tq+=i;\n\t\t\t\tj+=i;\n\t\t\t\t}\n\t\t\ti=RSA_verify(NID_md5_sha1, md_buf, j, p, n,\n\t\t\t\t\t\t\t\tpkey->pkey.rsa);\n\t\t\tif (i < 0)\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_DECRYPT_ERROR;\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\tif (i == 0)\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_DECRYPT_ERROR;\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_SIGNATURE);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_DSA\n\t\t\tif (pkey->type == EVP_PKEY_DSA)\n\t\t\t{\n\t\t\tEVP_VerifyInit_ex(&md_ctx,EVP_dss1(), NULL);\n\t\t\tEVP_VerifyUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);\n\t\t\tEVP_VerifyUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);\n\t\t\tEVP_VerifyUpdate(&md_ctx,param,param_len);\n\t\t\tif (!EVP_VerifyFinal(&md_ctx,p,(int)n,pkey))\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_DECRYPT_ERROR;\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_SIGNATURE);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\t\t\tif (pkey->type == EVP_PKEY_EC)\n\t\t\t{\n\t\t\tEVP_VerifyInit_ex(&md_ctx,EVP_ecdsa(), NULL);\n\t\t\tEVP_VerifyUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);\n\t\t\tEVP_VerifyUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);\n\t\t\tEVP_VerifyUpdate(&md_ctx,param,param_len);\n\t\t\tif (!EVP_VerifyFinal(&md_ctx,p,(int)n,pkey))\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_DECRYPT_ERROR;\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_SIGNATURE);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\t}\n\t\telse\n#endif\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_INTERNAL_ERROR);\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tif (!(alg_a & SSL_aNULL) && !(alg_k & SSL_kPSK))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_INTERNAL_ERROR);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (n != 0)\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_EXTRA_DATA_IN_MESSAGE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\t}\n\tEVP_PKEY_free(pkey);\n\tEVP_MD_CTX_cleanup(&md_ctx);\n\treturn(1);\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\nerr:\n\tEVP_PKEY_free(pkey);\n#ifndef OPENSSL_NO_RSA\n\tif (rsa != NULL)\n\t\tRSA_free(rsa);\n#endif\n#ifndef OPENSSL_NO_DH\n\tif (dh != NULL)\n\t\tDH_free(dh);\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tBN_CTX_free(bn_ctx);\n\tEC_POINT_free(srvr_ecpoint);\n\tif (ecdh != NULL)\n\t\tEC_KEY_free(ecdh);\n#endif\n\tEVP_MD_CTX_cleanup(&md_ctx);\n\treturn(-1);\n\t}', 'int RSA_verify(int dtype, const unsigned char *m, unsigned int m_len,\n\t\tconst unsigned char *sigbuf, unsigned int siglen,\n\t\tRSA *rsa)\n\t{\n\tif((rsa->flags & RSA_FLAG_SIGN_VER) && rsa->meth->rsa_verify)\n\t\t{\n\t\treturn rsa->meth->rsa_verify(dtype, m, m_len,\n\t\t\tsigbuf, siglen, rsa);\n\t\t}\n\treturn int_rsa_verify(dtype, m, m_len, NULL, NULL, sigbuf, siglen, rsa);\n\t}', 'int int_rsa_verify(int dtype, const unsigned char *m,\n\t\t\t  unsigned int m_len,\n\t\t\t  unsigned char *rm, size_t *prm_len,\n\t\t\t  const unsigned char *sigbuf, size_t siglen,\n\t\t\t  RSA *rsa)\n\t{\n\tint i,ret=0,sigtype;\n\tunsigned char *s;\n\tX509_SIG *sig=NULL;\n\tif (siglen != (unsigned int)RSA_size(rsa))\n\t\t{\n\t\tRSAerr(RSA_F_INT_RSA_VERIFY,RSA_R_WRONG_SIGNATURE_LENGTH);\n\t\treturn(0);\n\t\t}\n\tif((dtype == NID_md5_sha1) && rm)\n\t\t{\n\t\ti = RSA_public_decrypt((int)siglen,\n\t\t\t\t\tsigbuf,rm,rsa,RSA_PKCS1_PADDING);\n\t\tif (i <= 0)\n\t\t\treturn 0;\n\t\t*prm_len = i;\n\t\treturn 1;\n\t\t}\n\ts=(unsigned char *)OPENSSL_malloc((unsigned int)siglen);\n\tif (s == NULL)\n\t\t{\n\t\tRSAerr(RSA_F_INT_RSA_VERIFY,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tif((dtype == NID_md5_sha1) && (m_len != SSL_SIG_LENGTH) ) {\n\t\t\tRSAerr(RSA_F_INT_RSA_VERIFY,RSA_R_INVALID_MESSAGE_LENGTH);\n\t\t\tgoto err;\n\t}\n\ti=RSA_public_decrypt((int)siglen,sigbuf,s,rsa,RSA_PKCS1_PADDING);\n\tif (i <= 0) goto err;\n\tif(dtype == NID_md5_sha1) {\n\t\tif((i != SSL_SIG_LENGTH) || memcmp(s, m, SSL_SIG_LENGTH))\n\t\t\t\tRSAerr(RSA_F_INT_RSA_VERIFY,RSA_R_BAD_SIGNATURE);\n\t\telse ret = 1;\n\t} else {\n\t\tconst unsigned char *p=s;\n\t\tsig=d2i_X509_SIG(NULL,&p,(long)i);\n\t\tif (sig == NULL) goto err;\n\t\tif(p != s+i)\n\t\t\t{\n\t\t\tRSAerr(RSA_F_INT_RSA_VERIFY,RSA_R_BAD_SIGNATURE);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif(sig->algor->parameter\n\t\t   && ASN1_TYPE_get(sig->algor->parameter) != V_ASN1_NULL)\n\t\t\t{\n\t\t\tRSAerr(RSA_F_INT_RSA_VERIFY,RSA_R_BAD_SIGNATURE);\n\t\t\tgoto err;\n\t\t\t}\n\t\tsigtype=OBJ_obj2nid(sig->algor->algorithm);\n\t#ifdef RSA_DEBUG\n\t\tfprintf(stderr,"in(%s) expect(%s)\\n",OBJ_nid2ln(sigtype),\n\t\t\tOBJ_nid2ln(dtype));\n\t#endif\n\t\tif (sigtype != dtype)\n\t\t\t{\n\t\t\tif (((dtype == NID_md5) &&\n\t\t\t\t(sigtype == NID_md5WithRSAEncryption)) ||\n\t\t\t\t((dtype == NID_md2) &&\n\t\t\t\t(sigtype == NID_md2WithRSAEncryption)))\n\t\t\t\t{\n#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)\n\t\t\t\tfprintf(stderr,"signature has problems, re-make with post SSLeay045\\n");\n#endif\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tRSAerr(RSA_F_INT_RSA_VERIFY,\n\t\t\t\t\t\tRSA_R_ALGORITHM_MISMATCH);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n\t\tif (rm)\n\t\t\t{\n\t\t\tconst EVP_MD *md;\n\t\t\tmd = EVP_get_digestbynid(dtype);\n\t\t\tif (md && (EVP_MD_size(md) != sig->digest->length))\n\t\t\t\tRSAerr(RSA_F_INT_RSA_VERIFY,\n\t\t\t\t\t\tRSA_R_INVALID_DIGEST_LENGTH);\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tmemcpy(rm, sig->digest->data,\n\t\t\t\t\t\t\tsig->digest->length);\n\t\t\t\t*prm_len = sig->digest->length;\n\t\t\t\tret = 1;\n\t\t\t\t}\n\t\t\t}\n\t\telse if (((unsigned int)sig->digest->length != m_len) ||\n\t\t\t(memcmp(m,sig->digest->data,m_len) != 0))\n\t\t\t{\n\t\t\tRSAerr(RSA_F_INT_RSA_VERIFY,RSA_R_BAD_SIGNATURE);\n\t\t\t}\n\t\telse\n\t\t\tret=1;\n\t}\nerr:\n\tif (sig != NULL) X509_SIG_free(sig);\n\tif (s != NULL)\n\t\t{\n\t\tOPENSSL_cleanse(s,(unsigned int)siglen);\n\t\tOPENSSL_free(s);\n\t\t}\n\treturn(ret);\n\t}', 'int RSA_size(const RSA *r)\n\t{\n\treturn(BN_num_bytes(r->n));\n\t}', 'int BN_num_bits(const BIGNUM *a)\n\t{\n\tint i = a->top - 1;\n\tbn_check_top(a);\n\tif (BN_is_zero(a)) return 0;\n\treturn ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));\n\t}']