From: Nikos Mavrogiannopoulos Date: Sat, 21 May 2011 06:15:15 +0000 (+0200) Subject: updates to benchmarks. X-Git-Tag: gnutls_2_99_2~61 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e03cc3039f45368e9971f117367ca4a56fe364cc;p=thirdparty%2Fgnutls.git updates to benchmarks. --- diff --git a/src/Makefile.am b/src/Makefile.am index cc7881eb12..3cfbc08c92 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -28,7 +28,7 @@ AM_CPPFLAGS = \ -I$(srcdir)/../libextra/includes \ -I$(srcdir)/cfg -noinst_PROGRAMS = benchmark benchmark-tls +noinst_PROGRAMS = benchmark-cipher benchmark-tls bin_PROGRAMS = gnutls-serv gnutls-cli psktool gnutls-cli-debug if ENABLE_PKI bin_PROGRAMS += certtool p11tool @@ -65,10 +65,10 @@ noinst_LTLIBRARIES += libcmd-psk.la libcmd_psk_la_CFLAGS = libcmd_psk_la_SOURCES = psk.gaa psk-gaa.h psk-gaa.c -benchmark_SOURCES = benchmark.c benchmark-common.c benchmark.h -benchmark_LDADD = ../lib/libgnutls.la ../gl/libgnu.la $(LIB_CLOCK_GETTIME) +benchmark_cipher_SOURCES = benchmark-cipher.c benchmark.c benchmark.h +benchmark_cipher_LDADD = ../lib/libgnutls.la ../gl/libgnu.la $(LIB_CLOCK_GETTIME) -benchmark_tls_SOURCES = benchmark-tls.c benchmark-common.c benchmark.h +benchmark_tls_SOURCES = benchmark-tls.c benchmark.c benchmark.h benchmark_tls_LDADD = ../lib/libgnutls.la ../gl/libgnu.la $(LIB_CLOCK_GETTIME) gnutls_cli_SOURCES = cli.c common.h common.c p11common.c p11common.h diff --git a/src/benchmark-cipher.c b/src/benchmark-cipher.c index 0af831cd1c..a69dd24cf2 100644 --- a/src/benchmark-cipher.c +++ b/src/benchmark-cipher.c @@ -103,7 +103,7 @@ cipher_mac_bench (int algo, int mac_algo, int size) gnutls_cipher_deinit (ctx); gnutls_hmac_deinit(mac_ctx, NULL); - stop_benchmark (&st); + stop_benchmark (&st, NULL); leave: free (_key); @@ -166,7 +166,7 @@ cipher_bench (int algo, int size, int aead) gnutls_cipher_deinit (ctx); - stop_benchmark(&st); + stop_benchmark(&st, NULL); leave: free (_key); @@ -198,7 +198,7 @@ mac_bench (int algo, int size) } while (benchmark_must_finish == 0); - stop_benchmark(&st); + stop_benchmark(&st, NULL); free (_key); } diff --git a/src/benchmark-tls.c b/src/benchmark-tls.c index cc0c7a1341..c8bd66d1ea 100644 --- a/src/benchmark-tls.c +++ b/src/benchmark-tls.c @@ -40,6 +40,9 @@ #include "../tests/eagain-common.h" #include "benchmark.h" +#define PRIO_DH "NONE:+VERS-TLS1.0:+AES-128-CBC:+SHA1:+SIGN-ALL:+COMP-NULL:+ANON-DH" +#define PRIO_ECDH "NONE:+VERS-TLS1.0:+AES-128-CBC:+SHA1:+SIGN-ALL:+COMP-NULL:+ANON-ECDH" + #define PRIO_AES_CBC_SHA1 "NONE:+VERS-TLS1.0:+AES-128-CBC:+SHA1:+SIGN-ALL:+COMP-NULL:+ANON-DH" #define PRIO_CAMELLIA_CBC_SHA1 "NONE:+VERS-TLS1.0:+CAMELLIA-128-CBC:+SHA1:+SIGN-ALL:+COMP-NULL:+ANON-DH" @@ -150,7 +153,7 @@ test_ciphersuite (const char* cipher_prio, int size) } while (benchmark_must_finish == 0); - stop_benchmark (&st); + stop_benchmark (&st, NULL); gnutls_bye (client, GNUTLS_SHUT_WR); gnutls_bye (server, GNUTLS_SHUT_WR); @@ -165,6 +168,85 @@ test_ciphersuite (const char* cipher_prio, int size) } +static void +test_ciphersuite_kx (const char* cipher_prio) +{ + /* Server stuff. */ + gnutls_anon_server_credentials_t s_anoncred; + const gnutls_datum_t p3 = { (char *) pkcs3, strlen (pkcs3) }; + static gnutls_dh_params_t dh_params; + gnutls_session_t server; + int sret, cret; + const char *str; + const char* suite=NULL; + /* Client stuff. */ + gnutls_anon_client_credentials_t c_anoncred; + gnutls_session_t client; + /* Need to enable anonymous KX specifically. */ + int ret; + struct benchmark_st st; + + /* Init server */ + gnutls_anon_allocate_server_credentials (&s_anoncred); + gnutls_dh_params_init (&dh_params); + gnutls_dh_params_import_pkcs3 (dh_params, &p3, GNUTLS_X509_FMT_PEM); + gnutls_anon_set_server_dh_params (s_anoncred, dh_params); + + start_benchmark (&st); + + do + { + gnutls_init (&server, GNUTLS_SERVER); + ret = gnutls_priority_set_direct (server, cipher_prio, &str); + if (ret < 0) + { + fprintf (stderr, "Error in %s\n", str); + exit (1); + } + gnutls_credentials_set (server, GNUTLS_CRD_ANON, s_anoncred); + gnutls_transport_set_push_function (server, server_push); + gnutls_transport_set_pull_function (server, server_pull); + gnutls_transport_set_ptr (server, (gnutls_transport_ptr_t) server); + reset_buffers(); + + /* Init client */ + gnutls_anon_allocate_client_credentials (&c_anoncred); + gnutls_init (&client, GNUTLS_CLIENT); + + ret = gnutls_priority_set_direct (client, cipher_prio, &str); + if (ret < 0) + { + fprintf (stderr, "Error in %s\n", str); + exit (1); + } + gnutls_credentials_set (client, GNUTLS_CRD_ANON, c_anoncred); + gnutls_transport_set_push_function (client, client_push); + gnutls_transport_set_pull_function (client, client_pull); + gnutls_transport_set_ptr (client, (gnutls_transport_ptr_t) client); + + HANDSHAKE (client, server); + + if (suite==NULL) + suite = gnutls_cipher_suite_get_name(gnutls_kx_get(server), + gnutls_cipher_get(server), gnutls_mac_get(server)); + + gnutls_deinit (client); + gnutls_deinit (server); + + st.size += 1; + } + while (benchmark_must_finish == 0); + + fprintf (stdout, "Tested %s: ", suite); + stop_benchmark (&st, "transactions"); + + gnutls_anon_free_client_credentials (c_anoncred); + gnutls_anon_free_server_credentials (s_anoncred); + + gnutls_dh_params_deinit (dh_params); + +} + int main (int argc, char **argv) { @@ -175,6 +257,9 @@ main (int argc, char **argv) } gnutls_global_init (); + test_ciphersuite_kx (PRIO_DH); + test_ciphersuite_kx (PRIO_ECDH); + test_ciphersuite (PRIO_AES_CBC_SHA1, 1024); test_ciphersuite (PRIO_AES_CBC_SHA1, 4096); test_ciphersuite (PRIO_AES_CBC_SHA1, 8*1024); @@ -185,5 +270,6 @@ main (int argc, char **argv) test_ciphersuite (PRIO_CAMELLIA_CBC_SHA1, 8*1024); test_ciphersuite (PRIO_CAMELLIA_CBC_SHA1, 15*1024); + gnutls_global_deinit (); } diff --git a/src/benchmark.c b/src/benchmark.c index 0e4787907e..befc81f349 100644 --- a/src/benchmark.c +++ b/src/benchmark.c @@ -65,6 +65,7 @@ void start_benchmark(struct benchmark_st * st) memset(st, 0, sizeof(st)); st->old_handler = signal (SIGALRM, alarm_handler); gettime (&st->start); + benchmark_must_finish = 0; #if defined(_WIN32) st->wtimer = CreateWaitableTimer (NULL, TRUE, NULL); @@ -93,12 +94,12 @@ void start_benchmark(struct benchmark_st * st) } /* returns the elapsed time */ -double stop_benchmark(struct benchmark_st * st) +double stop_benchmark(struct benchmark_st * st, const char* metric) { double secs; struct timespec stop; double dspeed, ddata; - char metric[16]; + char imetric[16]; #if defined(_WIN32) if (st->wtimer != NULL) @@ -115,9 +116,19 @@ double stop_benchmark(struct benchmark_st * st) (st->start.tv_sec * 1000 + st->start.tv_nsec / (1000 * 1000))); secs /= 1000; - value2human (st->size, secs, &ddata, &dspeed, metric); - printf ("Processed %.2f %s in %.2f secs: ", ddata, metric, secs); - printf ("%.2f %s/sec\n", dspeed, metric); + if (metric == NULL) + { /* assume bytes/sec */ + value2human (st->size, secs, &ddata, &dspeed, imetric); + printf ("Processed %.2f %s in %.2f secs: ", ddata, imetric, secs); + printf ("%.2f %s/sec\n", dspeed, imetric); + } + else + { + ddata = (double) st->size; + dspeed = ddata / secs; + printf ("Processed %.2f %s in %.2f secs: ", ddata, metric, secs); + printf ("%.2f %s/sec\n", dspeed, metric); + } return secs; } diff --git a/src/benchmark.h b/src/benchmark.h index 826ed20f22..b5a7f86a4f 100644 --- a/src/benchmark.h +++ b/src/benchmark.h @@ -20,5 +20,5 @@ struct benchmark_st extern int benchmark_must_finish; void start_benchmark(struct benchmark_st * st); -double stop_benchmark(struct benchmark_st * st); +double stop_benchmark(struct benchmark_st * st, const char* metric);