]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
updates to benchmarks.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 21 May 2011 06:15:15 +0000 (08:15 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 21 May 2011 06:30:49 +0000 (08:30 +0200)
src/Makefile.am
src/benchmark-cipher.c
src/benchmark-tls.c
src/benchmark.c
src/benchmark.h

index cc7881eb129245035828d3f21944652cb1ac7040..3cfbc08c9282881a2f5642659eab1b6dce93cf64 100644 (file)
@@ -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
index 0af831cd1cff3271b7d24084a3d6e1b3d2a96dd6..a69dd24cf23fb4dab27642c24e5d887fadcf0fdf 100644 (file)
@@ -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);
 }
index cc0c7a134172c3fd77f4279e21addd63c026e614..c8bd66d1eacbd60ba8be9c1388e0a8bc58793cee 100644 (file)
@@ -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 ();
 }
index 0e4787907ebc26a45b5fca10a52d6df6787d0a13..befc81f34985c57d4b2352a15b5f6039a547f4b8 100644 (file)
@@ -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;
 }
index 826ed20f22e3e55dc5a7a1d8ed146a24c77a6f72..b5a7f86a4fbd25a9e1591fad51d3d49cc060a4dc 100644 (file)
@@ -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);