[git] GCRYPT - branch, master, updated. post-nuke-of-trailing-ws-9-g3647992

by Werner Koch cvs at cvs.gnupg.org
Wed Feb 16 18:58:47 CET 2011


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  364799200d1fa8bfa159b6941cb74156bbfa7ec1 (commit)
      from  d9795cfdd758e2aa22e7ab8a6790e2915d1f5334 (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 364799200d1fa8bfa159b6941cb74156bbfa7ec1
Author: Werner Koch <wk at gnupg.org>
Date:   Wed Feb 16 18:31:31 2011 +0100

    Add GCRYCTL_DISABLE_HWF
    
    This option is useful to disable detected hardware features. It has
    been implemented in benchmark, so that it is now possible to run
    
      tests/benchmark --disable-hwf intel-aesni  cipher aes aes192 aes256
    
    to compare the use of AES-NI insns to the pure C code.

diff --git a/NEWS b/NEWS
index 9848432..fae8ee3 100644
--- a/NEWS
+++ b/NEWS
@@ -37,6 +37,7 @@ Noteworthy changes in version 1.5.x (unreleased)
  GCRY_MD_TIGER2             NEW.
  gcry_pk_get_curve          NEW.
  gcry_pk_get_param          NEW.
+ GCRYCTL_DISABLE_HWF        NEW.
 
 
 Noteworthy changes in version 1.4.4 (2009-01-22)
diff --git a/compat/compat.c b/compat/compat.c
index 4a38ec7..076f520 100644
--- a/compat/compat.c
+++ b/compat/compat.c
@@ -29,7 +29,7 @@ _gcry_compat_identification (void)
     "\n\n"
     "This is Libgcrypt - The GNU Crypto Library\n"
     "Copyright 2000, 2002, 2003, 2004, 2007, 2008, 2009,\n"
-    "          2010 Free Software Foundation, Inc.\n"
+    "          2010, 2011 Free Software Foundation, Inc.\n"
     "\n\n";
   return blurb;
 }
diff --git a/doc/gcrypt.texi b/doc/gcrypt.texi
index 4026621..03c5363 100644
--- a/doc/gcrypt.texi
+++ b/doc/gcrypt.texi
@@ -814,6 +814,15 @@ This may be used at anytime to have the library run all implemented
 self-tests.  It works in standard and in FIPS mode.  Returns 0 on
 success or an error code on failure.
 
+ at item GCRYCTL_DISABLE_HWF; Arguments: const char *name
+
+Libgcrypt detects certain features of the CPU at startup time.  For
+performace tests it is sometimes required not to use such a feature.
+This option may be used to disabale a certain feature; i.e. Libgcrypt
+behaves as if this feature has not been detected.  Note that the
+detection code might be run if the feature has been disabled.  This
+command must be used at initialization time; i.e. before calling
+ at code{gcry_check_version}.
 
 @end table
 
diff --git a/src/ChangeLog b/src/ChangeLog
index b150b40..4f3a4e3 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,14 @@
+2011-02-16  Werner Koch  <wk at g10code.com>
+
+	* gcrypt.h.in (GCRYCTL_DISABLE_HWF): New.
+	* global.c (_gcry_vcontrol): Support new control code.
+	(print_config): Factor list of hwfeatures out to ...
+	(hwflist): new.
+	(disabled_hw_features): New.
+	(global_init): Pass new variable to _gcry_detect_hw_features.
+	* hwfeatures.c (_gcry_detect_hw_features): Add arg
+	DISABLED_FEATURES and disable detected features.
+
 2011-02-11  Werner Koch  <wk at g10code.com>
 
 	* g10lib.h (HWF_INTEL_AES): Rename to HWF_INTEL_AESNI.
diff --git a/src/g10lib.h b/src/g10lib.h
index 28c5e93..8d98ae3 100644
--- a/src/g10lib.h
+++ b/src/g10lib.h
@@ -152,7 +152,7 @@ int _gcry_log_verbosity( int level );
 
 
 unsigned int _gcry_get_hw_features (void);
-void _gcry_detect_hw_features (void);
+void _gcry_detect_hw_features (unsigned int);
 
 
 /*-- mpi/mpiutil.c --*/
diff --git a/src/gcrypt.h.in b/src/gcrypt.h.in
index f8daeb3..54fa9f3 100644
--- a/src/gcrypt.h.in
+++ b/src/gcrypt.h.in
@@ -414,8 +414,9 @@ enum gcry_ctl_cmds
     GCRYCTL_OPERATIONAL_P = 54,
     GCRYCTL_FIPS_MODE_P = 55,
     GCRYCTL_FORCE_FIPS_MODE = 56,
-    GCRYCTL_SELFTEST = 57
+    GCRYCTL_SELFTEST = 57,
     /* Note: 58 .. 62 are used internally.  */
+    GCRYCTL_DISABLE_HWF = 63
   };
 
 /* Perform various operations defined by CMD. */
diff --git a/src/global.c b/src/global.c
index 35a2ca1..6336fea 100644
--- a/src/global.c
+++ b/src/global.c
@@ -1,6 +1,6 @@
 /* global.c  -	global control functions
  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003
- *               2004, 2005, 2006, 2008  Free Software Foundation, Inc.
+ *               2004, 2005, 2006, 2008, 2011  Free Software Foundation, Inc.
  *
  * This file is part of Libgcrypt.
  *
@@ -53,6 +53,24 @@ static int force_fips_mode;
 /* Controlled by global_init().  */
 static int any_init_done;
 
+/* A table to map hardware features to a string.  */
+static struct
+{
+  unsigned int flag;
+  const char *desc;
+} hwflist[] =
+  {
+    { HWF_PADLOCK_RNG, "padlock-rng" },
+    { HWF_PADLOCK_AES, "padlock-aes" },
+    { HWF_PADLOCK_SHA, "padlock-sha" },
+    { HWF_PADLOCK_MMUL,"padlock-mmul"},
+    { HWF_INTEL_AESNI, "intel-aesni" },
+    { 0, NULL}
+  };
+
+/* A bit vector with the hardware features which shall not be used.
+   This variable must be set prior to any initialization.  */
+static unsigned int disabled_hw_features;
 
 
 /* Memory management. */
@@ -94,7 +112,7 @@ global_init (void)
 
   /* Before we do any other initialization we need to test available
      hardware features.  */
-  _gcry_detect_hw_features ();
+  _gcry_detect_hw_features (disabled_hw_features);
 
   err = _gcry_cipher_init ();
   if (err)
@@ -258,16 +276,6 @@ static void
 print_config ( int (*fnc)(FILE *fp, const char *format, ...), FILE *fp)
 {
   unsigned int hwf;
-  struct {
-    unsigned int flag;
-    const char *desc;
-  } hwflist[] = {
-    { HWF_PADLOCK_RNG, "padlock-rng" },
-    { HWF_PADLOCK_AES, "padlock-aes" },
-    { HWF_PADLOCK_SHA, "padlock-sha" },
-    { HWF_INTEL_AESNI, "intel-aesni" },
-    { 0, NULL}
-  };
   int i;
 
   fnc (fp, "version:%s:\n", VERSION);
@@ -292,8 +300,8 @@ print_config ( int (*fnc)(FILE *fp, const char *format, ...), FILE *fp)
   hwf = _gcry_get_hw_features ();
   fnc (fp, "hwflist:");
   for (i=0; hwflist[i].desc; i++)
-  if ( (hwf & hwflist[i].flag) )
-    fnc (fp, "%s:", hwflist[i].desc);
+    if ( (hwf & hwflist[i].flag) )
+      fnc (fp, "%s:", hwflist[i].desc);
   fnc (fp, "\n");
   /* We use y/n instead of 1/0 for the simple reason that Emacsen's
      compile error parser would accidently flag that line when printed
@@ -565,6 +573,21 @@ _gcry_vcontrol (enum gcry_ctl_cmds cmd, va_list arg_ptr)
       }
       break;
 
+    case GCRYCTL_DISABLE_HWF:
+      {
+        const char *name = va_arg (arg_ptr, const char *);
+        int i;
+
+        for (i=0; hwflist[i].desc; i++)
+          if (!strcmp (hwflist[i].desc, name))
+            {
+              disabled_hw_features |= hwflist[i].flag;
+              break;
+            }
+        if (!hwflist[i].desc)
+          err = GPG_ERR_INV_NAME;
+      }
+      break;
 
     default:
       /* A call to make sure that the dummy code is linked in.  */
diff --git a/src/hwfeatures.c b/src/hwfeatures.c
index 5a0a805..2b3bb2c 100644
--- a/src/hwfeatures.c
+++ b/src/hwfeatures.c
@@ -1,5 +1,5 @@
 /* hwfeatures.c - Detect hardware features.
- * Copyright (C) 2007  Free Software Foundation, Inc.
+ * Copyright (C) 2007, 2011  Free Software Foundation, Inc.
  *
  * This file is part of Libgcrypt.
  *
@@ -172,7 +172,7 @@ detect_ia32_gnuc (void)
    once right at startup and we assume that no other threads are
    running.  */
 void
-_gcry_detect_hw_features (void)
+_gcry_detect_hw_features (unsigned int disabled_features)
 {
   hw_features = 0;
 
@@ -187,4 +187,6 @@ _gcry_detect_hw_features (void)
 #ifdef __GNUC__
 #endif
 #endif
+
+  hw_features &= ~disabled_features;
 }
diff --git a/tests/ChangeLog b/tests/ChangeLog
index c674f12..95cb960 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,5 +1,7 @@
 2011-02-16  Werner Koch  <wk at g10code.com>
 
+	* benchmark.c (main): Add option --disable-hwf.
+
 	* basic.c (DIM): New.
 	(check_bulk_cipher_modes): New.
 	(main): Run new test.
diff --git a/tests/benchmark.c b/tests/benchmark.c
index 536b76a..cf78c76 100644
--- a/tests/benchmark.c
+++ b/tests/benchmark.c
@@ -1177,6 +1177,17 @@ main( int argc, char **argv )
               argc--; argv++;
             }
         }
+      else if (!strcmp (*argv, "--disable-hwf"))
+        {
+          argc--; argv++;
+          if (argc)
+            {
+              if (gcry_control (GCRYCTL_DISABLE_HWF, *argv, NULL))
+                fprintf (stderr, PGM ": unknown hardware feature `%s'"
+                         " - option ignored\n", *argv);
+              argc--; argv++;
+            }
+        }
       else if (!strcmp (*argv, "--fips"))
         {
           argc--; argv++;

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

Summary of changes:
 NEWS              |    1 +
 compat/compat.c   |    2 +-
 doc/gcrypt.texi   |    9 +++++++++
 src/ChangeLog     |   11 +++++++++++
 src/g10lib.h      |    2 +-
 src/gcrypt.h.in   |    3 ++-
 src/global.c      |   51 +++++++++++++++++++++++++++++++++++++--------------
 src/hwfeatures.c  |    6 ++++--
 tests/ChangeLog   |    2 ++
 tests/benchmark.c |   11 +++++++++++
 10 files changed, 79 insertions(+), 19 deletions(-)


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




More information about the Gnupg-commits mailing list