Skip to content

Commit

Permalink
Add time functions to measure internal functions
Browse files Browse the repository at this point in the history
  • Loading branch information
perubeanie committed Feb 28, 2024
1 parent 5abd242 commit 035897b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
16 changes: 16 additions & 0 deletions ssl/statem/statem_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ CON_FUNC_RETURN tls_construct_cert_verify(SSL_CONNECTION *s, WPACKET *pkt)
const SIGALG_LOOKUP *lu = s->s3.tmp.sigalg;
SSL_CTX *sctx = SSL_CONNECTION_GET_CTX(s);

struct timeval tv1, tv2;
gettimeofday(&tv1, NULL);

if (lu == NULL ||
#ifndef OPENSSL_NO_VCAUTHTLS
(
Expand Down Expand Up @@ -448,6 +451,11 @@ CON_FUNC_RETURN tls_construct_cert_verify(SSL_CONNECTION *s, WPACKET *pkt)
goto err;
}

gettimeofday(&tv2, NULL);
printf ("Total time construct certificate verify = %f seconds\n\n",
(double) (tv2.tv_usec - tv1.tv_usec) / 1000000 +
(double) (tv2.tv_sec - tv1.tv_sec));

OPENSSL_free(sig);
EVP_MD_CTX_free(mctx);
return CON_FUNC_SUCCESS;
Expand Down Expand Up @@ -475,6 +483,9 @@ MSG_PROCESS_RETURN tls_process_cert_verify(SSL_CONNECTION *s, PACKET *pkt)
EVP_PKEY_CTX *pctx = NULL;
SSL_CTX *sctx = SSL_CONNECTION_GET_CTX(s);

struct timeval tv1, tv2;
gettimeofday(&tv1, NULL);

if (mctx == NULL) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_EVP_LIB);
goto err;
Expand Down Expand Up @@ -604,6 +615,11 @@ MSG_PROCESS_RETURN tls_process_cert_verify(SSL_CONNECTION *s, PACKET *pkt)
goto err;
}
}
gettimeofday(&tv2, NULL);

printf ("Total time process certificate verify = %f seconds\n\n",
(double) (tv2.tv_usec - tv1.tv_usec) / 1000000 +
(double) (tv2.tv_sec - tv1.tv_sec));

/*
* In TLSv1.3 on the client side we make sure we prepare the client
Expand Down
32 changes: 30 additions & 2 deletions ssl/statem/statem_srvr.c
Original file line number Diff line number Diff line change
Expand Up @@ -3731,8 +3731,17 @@ MSG_PROCESS_RETURN tls_process_client_certificate(SSL_CONNECTION *s,
s->rlayer.rrlmethod->set_plain_alerts(s->rlayer.rrl, 0);

#ifndef OPENSSL_NO_VCAUTHTLS
if(s->ext.client_cert_type == TLSEXT_cert_type_vc)
return tls_process_client_vc(s, pkt);
if(s->ext.client_cert_type == TLSEXT_cert_type_vc) {
struct timeval tv1, tv2;
int a;
gettimeofday(&tv1, NULL);
a = tls_process_client_vc(s, pkt);
gettimeofday(&tv2, NULL);
printf ("Total time process client vc = %f seconds\n\n",
(double) (tv2.tv_usec - tv1.tv_usec) / 1000000 +
(double) (tv2.tv_sec - tv1.tv_sec));
return a;
}
#endif

if (s->ext.client_cert_type == TLSEXT_cert_type_rpk)
Expand All @@ -3744,6 +3753,9 @@ MSG_PROCESS_RETURN tls_process_client_certificate(SSL_CONNECTION *s,
goto err;
}

struct timeval tv1, tv2;
gettimeofday(&tv1, NULL);

if ((sk = sk_X509_new_null()) == NULL) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_CRYPTO_LIB);
goto err;
Expand Down Expand Up @@ -3908,6 +3920,11 @@ MSG_PROCESS_RETURN tls_process_client_certificate(SSL_CONNECTION *s,

ret = MSG_PROCESS_CONTINUE_READING;

gettimeofday(&tv2, NULL);
printf ("Total time process client certificate = %f seconds\n\n",
(double) (tv2.tv_usec - tv1.tv_usec) / 1000000 +
(double) (tv2.tv_sec - tv1.tv_sec));

err:
X509_free(x);
OSSL_STACK_OF_X509_free(sk);
Expand Down Expand Up @@ -3953,13 +3970,19 @@ CON_FUNC_RETURN tls_construct_server_certificate(SSL_CONNECTION *s, WPACKET *pkt
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
return CON_FUNC_ERROR;
}
struct timeval tv1, tv2;
switch (s->ext.server_cert_type) {
#ifndef OPENSSL_NO_VCAUTHTLS
case TLSEXT_cert_type_vc:
gettimeofday(&tv1, NULL);
if (!tls_output_vc(s, pkt, vcpk)) {
/* SSLfatal() already called */
return 0;
}
gettimeofday(&tv2, NULL);
printf ("Total time construct server vc = %f seconds\n\n",
(double) (tv2.tv_usec - tv1.tv_usec) / 1000000 +
(double) (tv2.tv_sec - tv1.tv_sec));
break;
#endif
case TLSEXT_cert_type_rpk:
Expand All @@ -3969,10 +3992,15 @@ CON_FUNC_RETURN tls_construct_server_certificate(SSL_CONNECTION *s, WPACKET *pkt
}
break;
case TLSEXT_cert_type_x509:
gettimeofday(&tv1, NULL);
if (!ssl3_output_cert_chain(s, pkt, cpk, 0)) {
/* SSLfatal() already called */
return 0;
}
gettimeofday(&tv2, NULL);
printf ("Total time construct server cert = %f seconds\n\n",
(double) (tv2.tv_usec - tv1.tv_usec) / 1000000 +
(double) (tv2.tv_sec - tv1.tv_sec));
break;
default:
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
Expand Down

0 comments on commit 035897b

Please sign in to comment.