summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2011-02-16 18:31:31 +0100
committerWerner Koch <wk@gnupg.org>2011-02-16 18:31:31 +0100
commit364799200d1fa8bfa159b6941cb74156bbfa7ec1 (patch)
tree4ca0a2df8d79f33d64c0c912117fc1af92dbe6e8
parentd9795cfdd758e2aa22e7ab8a6790e2915d1f5334 (diff)
downloadlibgcrypt-364799200d1fa8bfa159b6941cb74156bbfa7ec1.tar.gz
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.
-rw-r--r--NEWS1
-rw-r--r--compat/compat.c2
-rw-r--r--doc/gcrypt.texi9
-rw-r--r--src/ChangeLog11
-rw-r--r--src/g10lib.h2
-rw-r--r--src/gcrypt.h.in3
-rw-r--r--src/global.c51
-rw-r--r--src/hwfeatures.c6
-rw-r--r--tests/ChangeLog2
-rw-r--r--tests/benchmark.c11
10 files changed, 79 insertions, 19 deletions
diff --git a/NEWS b/NEWS
index 98484324..fae8ee3c 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 4a38ec7c..076f5201 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 4026621e..03c53633 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.
+@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
+@code{gcry_check_version}.
@end table
diff --git a/src/ChangeLog b/src/ChangeLog
index b150b40c..4f3a4e33 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,14 @@
+2011-02-16 Werner Koch <wk@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@g10code.com>
* g10lib.h (HWF_INTEL_AES): Rename to HWF_INTEL_AESNI.
diff --git a/src/g10lib.h b/src/g10lib.h
index 28c5e936..8d98ae38 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 f8daeb35..54fa9f37 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 35a2ca14..6336fea2 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 5a0a8055..2b3bb2cb 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 c674f121..95cb960b 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,5 +1,7 @@
2011-02-16 Werner Koch <wk@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 536b76a6..cf78c76b 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++;