[git] GCRYPT - branch, master, updated. libgcrypt-1.6.0-185-gfe38d38

by Werner Koch cvs at cvs.gnupg.org
Wed Apr 15 12:36:46 CEST 2015


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU crypto library".

The branch, master has been updated
       via  fe38d3815b4cd203cd529949e244aca80d32897f (commit)
       via  3b03a3b493233a472da531d8d9582d1be6d376b0 (commit)
      from  9fca46864e1b5a9c788072113589454adb89fa97 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit fe38d3815b4cd203cd529949e244aca80d32897f
Author: Werner Koch <wk at gnupg.org>
Date:   Wed Apr 15 12:34:38 2015 +0200

    tests: Add option to time the S2K function.
    
    * tests/t-kdf.c: Include stopwatch.h.
    (dummy_consumer): new.
    (bench_s2k): New.
    (main): Add option parser and option --s2k.
    --
    
    For example:
    
      $ ./t-kdf --s2k 17659904
     88.0ms
      $ ./t-kdf --s2k 65536
      0.3ms
    
    This test is similar to the code done by gpg-agent to calibrate the
    S2K count.

diff --git a/tests/t-kdf.c b/tests/t-kdf.c
index 8e728d5..18c8357 100644
--- a/tests/t-kdf.c
+++ b/tests/t-kdf.c
@@ -28,6 +28,8 @@
 #include <assert.h>
 
 #include "../src/gcrypt-int.h"
+#include "stopwatch.h"
+
 
 #ifndef DIM
 # define DIM(v)		     (sizeof(v)/sizeof((v)[0]))
@@ -62,6 +64,58 @@ die (const char *format, ...)
 
 
 static void
+dummy_consumer (volatile char *buffer, size_t buflen)
+{
+  (void)buffer;
+  (void)buflen;
+}
+
+
+static void
+bench_s2k (unsigned long s2kcount)
+{
+  gpg_error_t err;
+  const char passphrase[] = "123456789abcdef0";
+  char keybuf[128/8];
+  unsigned int repetitions = 10;
+  unsigned int count;
+  const char *elapsed;
+  int pass = 0;
+
+ again:
+  start_timer ();
+  for (count = 0; count < repetitions; count++)
+    {
+      err = gcry_kdf_derive (passphrase, strlen (passphrase),
+                             GCRY_KDF_ITERSALTED_S2K,
+                             GCRY_MD_SHA1, "saltsalt", 8, s2kcount,
+                             sizeof keybuf, keybuf);
+      if (err)
+        die ("gcry_kdf_derive failed: %s\n", gpg_strerror (err));
+      dummy_consumer (keybuf, sizeof keybuf);
+    }
+  stop_timer ();
+
+  elapsed = elapsed_time (repetitions);
+  if (!pass++)
+    {
+      if (!atoi (elapsed))
+        {
+          repetitions = 10000;
+          goto again;
+        }
+      else if (atoi (elapsed) < 10)
+        {
+          repetitions = 100;
+          goto again;
+        }
+    }
+
+  printf ("%s\n", elapsed);
+}
+
+
+static void
 check_openpgp (void)
 {
   /* Test vectors manually created with gpg 1.4 derived code: In
@@ -1122,10 +1176,58 @@ check_scrypt (void)
 int
 main (int argc, char **argv)
 {
-  if (argc > 1 && !strcmp (argv[1], "--verbose"))
-    verbose = 1;
-  else if (argc > 1 && !strcmp (argv[1], "--debug"))
-    verbose = debug = 1;
+  int last_argc = -1;
+  unsigned long s2kcount = 0;
+
+  if (argc)
+    { argc--; argv++; }
+
+  while (argc && last_argc != argc )
+    {
+      last_argc = argc;
+      if (!strcmp (*argv, "--"))
+        {
+          argc--; argv++;
+          break;
+        }
+      else if (!strcmp (*argv, "--help"))
+        {
+          fputs ("usage: t-kdf [options]"
+                 "Options:\n"
+                 " --verbose    print timinigs etc.\n"
+                 " --debug      flyswatter\n"
+                 " --s2k        print the time needed for S2K\n",
+                 stdout);
+          exit (0);
+        }
+      else if (!strcmp (*argv, "--verbose"))
+        {
+          verbose++;
+          argc--; argv++;
+        }
+      else if (!strcmp (*argv, "--debug"))
+        {
+          verbose += 2;
+          debug++;
+          argc--; argv++;
+        }
+      else if (!strcmp (*argv, "--s2k"))
+        {
+          s2kcount = 1;
+          argc--; argv++;
+        }
+      else if (!strncmp (*argv, "--", 2))
+        die ("unknown option '%s'\n", *argv);
+    }
+
+  if (s2kcount)
+    {
+      if (argc != 1)
+        die ("usage: t-kdf --s2k S2KCOUNT\n", stderr );
+      s2kcount = strtoul (*argv, NULL, 10);
+      if (!s2kcount)
+        die ("t-kdf: S2KCOUNT must be positive\n", stderr );
+    }
 
   if (!gcry_check_version (GCRYPT_VERSION))
     die ("version mismatch\n");
@@ -1135,9 +1237,14 @@ main (int argc, char **argv)
   if (debug)
     gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0);
 
-  check_openpgp ();
-  check_pbkdf2 ();
-  check_scrypt ();
+  if (s2kcount)
+    bench_s2k (s2kcount);
+  else
+    {
+      check_openpgp ();
+      check_pbkdf2 ();
+      check_scrypt ();
+    }
 
   return error_count ? 1 : 0;
 }

commit 3b03a3b493233a472da531d8d9582d1be6d376b0
Author: Werner Koch <wk at gnupg.org>
Date:   Wed Apr 15 12:30:50 2015 +0200

    tests: Improve stopwatch.h
    
    * tests/stopwatch.h (elapsed_time): Add arg divisor.

diff --git a/tests/benchmark.c b/tests/benchmark.c
index 6be9509..b6cd7a8 100644
--- a/tests/benchmark.c
+++ b/tests/benchmark.c
@@ -463,7 +463,7 @@ random_bench (int very_strong)
       for (i=0; i < 100; i++)
         gcry_randomize (buf, sizeof buf, GCRY_STRONG_RANDOM);
       stop_timer ();
-      printf (" %s", elapsed_time ());
+      printf (" %s", elapsed_time (1));
     }
 
   start_timer ();
@@ -471,7 +471,7 @@ random_bench (int very_strong)
     gcry_randomize (buf, 8,
                     very_strong? GCRY_VERY_STRONG_RANDOM:GCRY_STRONG_RANDOM);
   stop_timer ();
-  printf (" %s", elapsed_time ());
+  printf (" %s", elapsed_time (1));
 
   putchar ('\n');
   if (verbose)
@@ -531,7 +531,7 @@ md_bench ( const char *algoname )
       gcry_md_write (hd, buf, bufsize);
   gcry_md_final (hd);
   stop_timer ();
-  printf (" %s", elapsed_time ());
+  printf (" %s", elapsed_time (1));
   fflush (stdout);
 
   gcry_md_reset (hd);
@@ -541,7 +541,7 @@ md_bench ( const char *algoname )
       gcry_md_write (hd, buf, bufsize/10);
   gcry_md_final (hd);
   stop_timer ();
-  printf (" %s", elapsed_time ());
+  printf (" %s", elapsed_time (1));
   fflush (stdout);
 
   gcry_md_reset (hd);
@@ -551,7 +551,7 @@ md_bench ( const char *algoname )
       gcry_md_write (hd, buf, 1);
   gcry_md_final (hd);
   stop_timer ();
-  printf (" %s", elapsed_time ());
+  printf (" %s", elapsed_time (1));
   fflush (stdout);
 
   start_timer ();
@@ -561,7 +561,7 @@ md_bench ( const char *algoname )
         gcry_md_putc (hd, buf[j]);
   gcry_md_final (hd);
   stop_timer ();
-  printf (" %s", elapsed_time ());
+  printf (" %s", elapsed_time (1));
   fflush (stdout);
 
   gcry_md_close (hd);
@@ -585,7 +585,7 @@ md_bench ( const char *algoname )
     for (i=0; i < 100; i++)
       gcry_md_hash_buffer (algo, digest, largebuf, 10000);
   stop_timer ();
-  printf (" %s", elapsed_time ());
+  printf (" %s", elapsed_time (1));
   free (largebuf_base);
 
   putchar ('\n');
@@ -680,7 +680,7 @@ mac_bench ( const char *algoname )
   macoutlen = maclen;
   gcry_mac_read (hd, mac[0], &macoutlen);
   stop_timer ();
-  printf (" %s", elapsed_time ());
+  printf (" %s", elapsed_time (1));
   fflush (stdout);
 
   gcry_mac_reset (hd);
@@ -692,7 +692,7 @@ mac_bench ( const char *algoname )
   macoutlen = maclen;
   gcry_mac_read (hd, mac[1], &macoutlen);
   stop_timer ();
-  printf (" %s", elapsed_time ());
+  printf (" %s", elapsed_time (1));
   fflush (stdout);
 
   gcry_mac_reset (hd);
@@ -704,7 +704,7 @@ mac_bench ( const char *algoname )
   macoutlen = maclen;
   gcry_mac_read (hd, mac[2], &macoutlen);
   stop_timer ();
-  printf (" %s", elapsed_time ());
+  printf (" %s", elapsed_time (1));
   fflush (stdout);
 
   gcry_mac_close (hd);
@@ -968,7 +968,7 @@ cipher_bench ( const char *algoname )
         }
       stop_timer ();
 
-      printf (" %s", elapsed_time ());
+      printf (" %s", elapsed_time (1));
       fflush (stdout);
       gcry_cipher_close (hd);
       if (err)
@@ -1049,7 +1049,7 @@ cipher_bench ( const char *algoname )
             }
         }
       stop_timer ();
-      printf (" %s", elapsed_time ());
+      printf (" %s", elapsed_time (1));
       fflush (stdout);
       gcry_cipher_close (hd);
       if (err)
@@ -1113,7 +1113,7 @@ rsa_bench (int iterations, int print_header, int no_blinding)
       gcry_sexp_release (key_spec);
 
       stop_timer ();
-      printf ("   %s", elapsed_time ());
+      printf ("   %s", elapsed_time (1));
       fflush (stdout);
 
       x = gcry_mpi_new (p_sizes[testno]);
@@ -1133,7 +1133,7 @@ rsa_bench (int iterations, int print_header, int no_blinding)
             die ("signing failed (%d): %s\n", count, gpg_strerror (err));
         }
       stop_timer ();
-      printf ("   %s", elapsed_time ());
+      printf ("   %s", elapsed_time (1));
       fflush (stdout);
 
       start_timer ();
@@ -1150,7 +1150,7 @@ rsa_bench (int iterations, int print_header, int no_blinding)
             }
         }
       stop_timer ();
-      printf ("     %s", elapsed_time ());
+      printf ("     %s", elapsed_time (1));
 
       if (no_blinding)
         {
@@ -1172,7 +1172,7 @@ rsa_bench (int iterations, int print_header, int no_blinding)
                 die ("signing failed (%d): %s\n", count, gpg_strerror (err));
             }
           stop_timer ();
-          printf ("   %s", elapsed_time ());
+          printf ("   %s", elapsed_time (1));
           fflush (stdout);
         }
 
@@ -1260,7 +1260,7 @@ elg_bench (int iterations, int print_header)
             }
         }
       stop_timer ();
-      snprintf (timerbuf1, sizeof timerbuf1, "   %s", elapsed_time ());
+      snprintf (timerbuf1, sizeof timerbuf1, "   %s", elapsed_time (1));
       fflush (stdout);
 
       start_timer ();
@@ -1278,7 +1278,7 @@ elg_bench (int iterations, int print_header)
         }
       stop_timer ();
 
-      printf ("   %s  %s\n", elapsed_time (), timerbuf1);
+      printf ("   %s  %s\n", elapsed_time (1), timerbuf1);
       fflush (stdout);
 
       gcry_sexp_release (plain);
@@ -1368,7 +1368,7 @@ dsa_bench (int iterations, int print_header)
             }
         }
       stop_timer ();
-      printf ("   %s", elapsed_time ());
+      printf ("   %s", elapsed_time (1));
       fflush (stdout);
 
       start_timer ();
@@ -1384,7 +1384,7 @@ dsa_bench (int iterations, int print_header)
             }
         }
       stop_timer ();
-      printf ("     %s\n", elapsed_time ());
+      printf ("     %s\n", elapsed_time (1));
       fflush (stdout);
 
       gcry_sexp_release (sig);
@@ -1478,7 +1478,7 @@ ecc_bench (int iterations, int print_header)
       gcry_sexp_release (key_spec);
 
       stop_timer ();
-      printf ("     %s", elapsed_time ());
+      printf ("     %s", elapsed_time (1));
       fflush (stdout);
 
       x = gcry_mpi_new (p_size);
@@ -1513,7 +1513,7 @@ ecc_bench (int iterations, int print_header)
             }
         }
       stop_timer ();
-      printf ("   %s", elapsed_time ());
+      printf ("   %s", elapsed_time (1));
       fflush (stdout);
 
       start_timer ();
@@ -1530,7 +1530,7 @@ ecc_bench (int iterations, int print_header)
             }
         }
       stop_timer ();
-      printf ("     %s\n", elapsed_time ());
+      printf ("     %s\n", elapsed_time (1));
       fflush (stdout);
 
       gcry_sexp_release (sig);
@@ -1563,7 +1563,7 @@ do_powm ( const char *n_str, const char *e_str, const char *m_str)
   for (i=0; i < 1000; i++)
     gcry_mpi_powm (cip, msg, e, n);
   stop_timer ();
-  printf (" %s", elapsed_time ()); fflush (stdout);
+  printf (" %s", elapsed_time (1)); fflush (stdout);
 /*    { */
 /*      char *buf; */
 
@@ -1645,7 +1645,7 @@ prime_bench (void)
   stop_timer ();
   if (with_progress)
     printf ("%-10s", "prime");
-  printf (" %s\n", elapsed_time ()); fflush (stdout);
+  printf (" %s\n", elapsed_time (1)); fflush (stdout);
 
   single_char_progress = old_prog;
 }
diff --git a/tests/hashtest.c b/tests/hashtest.c
index 6fbce0c..e2178aa 100644
--- a/tests/hashtest.c
+++ b/tests/hashtest.c
@@ -484,6 +484,6 @@ main (int argc, char **argv)
 
   if (verbose)
     show ("All tests completed in %s.  Errors: %d\n",
-          elapsed_time (), error_count);
+          elapsed_time (1), error_count);
   return !!error_count;
 }
diff --git a/tests/stopwatch.h b/tests/stopwatch.h
index bdca9ce..696e300 100644
--- a/tests/stopwatch.h
+++ b/tests/stopwatch.h
@@ -81,7 +81,7 @@ stop_timer (void)
 }
 
 static const char *
-elapsed_time (void)
+elapsed_time (unsigned int divisor)
 {
   static char buf[50];
 #if _WIN32
@@ -95,11 +95,19 @@ elapsed_time (void)
         + stopped_at.kernel_time.dwLowDateTime);
   t2 += (((unsigned long long)stopped_at.user_time.dwHighDateTime << 32)
         + stopped_at.user_time.dwLowDateTime);
-  t = (t2 - t1)/10000;
-  snprintf (buf, sizeof buf, "%5.0fms", (double)t );
+  t = ((t2 - t1)/divisor)/10000;
+  if (divisor != 1)
+    snprintf (buf, sizeof buf, "%5.1fms", (double)t );
+  else
+    snprintf (buf, sizeof buf, "%5.0fms", (double)t );
 #else
-  snprintf (buf, sizeof buf, "%5.0fms",
-            (((double) (stopped_at - started_at))/CLOCKS_PER_SEC)*10000000);
+  if (divisor != 1)
+    snprintf (buf, sizeof buf, "%5.1fms",
+              ((((double) (stopped_at - started_at)/(double)divisor)
+                /CLOCKS_PER_SEC)*10000000));
+  else
+    snprintf (buf, sizeof buf, "%5.0fms",
+              (((double) (stopped_at - started_at)/CLOCKS_PER_SEC)*10000000));
 #endif
   return buf;
 }
diff --git a/tests/t-ed25519.c b/tests/t-ed25519.c
index b7f3307..38e154d 100644
--- a/tests/t-ed25519.c
+++ b/tests/t-ed25519.c
@@ -555,6 +555,6 @@ main (int argc, char **argv)
   xfree (fname);
 
   show ("All tests completed in %s.  Errors: %d\n",
-        elapsed_time (), error_count);
+        elapsed_time (1), error_count);
   return !!error_count;
 }

-----------------------------------------------------------------------

Summary of changes:
 tests/benchmark.c |  50 +++++++++++-----------
 tests/hashtest.c  |   2 +-
 tests/stopwatch.h |  18 +++++---
 tests/t-ed25519.c |   2 +-
 tests/t-kdf.c     | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++----
 5 files changed, 154 insertions(+), 39 deletions(-)


hooks/post-receive
-- 
The GNU crypto library
http://git.gnupg.org


_______________________________________________
Gnupg-commits mailing list
Gnupg-commits at gnupg.org
http://lists.gnupg.org/mailman/listinfo/gnupg-commits




More information about the Gcrypt-devel mailing list