summaryrefslogtreecommitdiff
path: root/src
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 /src
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.
Diffstat (limited to 'src')
-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
5 files changed, 55 insertions, 18 deletions
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;
}