[git] GCRYPT - branch, master, updated. libgcrypt-1.5.0-79-gefd7002

by Dmitry Kasatkin cvs at cvs.gnupg.org
Tue Dec 18 19:38:22 CET 2012


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  efd7002188e6d50013e4d9a920a8b9afa9d210e5 (commit)
       via  bfe4dc11bb822cbc5bf2b425e5a5a2867a904518 (commit)
      from  6d20c1fab7f6005b34103de40c9707411b047f07 (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 efd7002188e6d50013e4d9a920a8b9afa9d210e5
Author: Dmitry Kasatkin <dmitry.kasatkin at intel.com>
Date:   Tue Dec 18 14:56:48 2012 +0200

    Add support for using DRNG random number generator
    
    * configure.ac: Add option --disable-drng-support.
    (ENABLE_DRNG_SUPPORT): New.
    * random/rndhw.c (USE_DRNG): New.
    (rdrand_long, rdrand_nlong, poll_drng): New.
    (_gcry_rndhw_poll_fast, _gcry_rndhw_poll_slow): Call poll function.
    * src/g10lib.h (HWF_INTEL_RDRAND): New.
    * src/global.c (hwflist): Add "intel-rdrand".
    * src/hwfeatures.c (detect_x86_64_gnuc) [ENABLE_DRNG_SUPPORT]: Detect
    RDRAND.
    (detect_ia32_gnuc) [ENABLE_DRNG_SUPPORT]: Detect RDRAND.
    --
    
    This patch provides support for using Digital Random Number Generator (DRNG)
    engine, which is available on the latest Intel's CPUs. DRNG engine is
    accesible via new the RDRAND instruction.
    
    This patch adds the following:
    - support for disabling using of rdrand instruction
    - checking for RDRAND instruction support using cpuid
    - RDRAND usage implementation
    
    Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin at intel.com>
    
    ChangeLog and editorial changes by wk.

diff --git a/configure.ac b/configure.ac
index ff07dda..7d162a2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -544,6 +544,18 @@ if test x"$aesnisupport" = xyes ; then
             [Enable support for Intel AES-NI instructions.])
 fi
 
+# Implementation of the --disable-drng-support switch.
+AC_MSG_CHECKING([whether DRNG support is requested])
+AC_ARG_ENABLE(drng-support,
+              AC_HELP_STRING([--disable-drng-support],
+                 [Disable support for the Intel DRNG (RDRAND instruction)]),
+	      drngsupport=$enableval,drngsupport=yes)
+AC_MSG_RESULT($drngsupport)
+if test x"$drngsupport" = xyes ; then
+  AC_DEFINE(ENABLE_DRNG_SUPPORT, 1,
+            [Enable support for Intel DRNG (RDRAND instruction).])
+fi
+
 # Implementation of the --disable-O-flag-munging switch.
 AC_MSG_CHECKING([whether a -O flag munging is requested])
 AC_ARG_ENABLE([O-flag-munging],
@@ -1304,6 +1316,7 @@ echo "
         Using linux capabilities:  $use_capabilities
         Try using Padlock crypto:  $padlocksupport
         Try using AES-NI crypto:   $aesnisupport
+        Try using DRNG (RDRAND):   $drngsupport
 "
 
 if test "$print_egd_notice" = "yes"; then
diff --git a/random/rndhw.c b/random/rndhw.c
index 775d90f..cbb28d1 100644
--- a/random/rndhw.c
+++ b/random/rndhw.c
@@ -1,5 +1,6 @@
 /* rndhw.c  - Access to the external random daemon
  * Copyright (C) 2007  Free Software Foundation, Inc.
+ * Copyright (C) 2012  Dmitry Kasatkin
  *
  * This file is part of Libgcrypt.
  *
@@ -34,6 +35,16 @@
 # endif
 #endif /*ENABLE_PADLOCK_SUPPORT*/
 
+#undef USE_DRNG
+#ifdef ENABLE_DRNG_SUPPORT
+# ifdef HAVE_GCC_ATTRIBUTE_ALIGNED
+#  if (defined (__i386__) && SIZEOF_UNSIGNED_LONG == 4) || defined(__x86_64__)
+#   define USE_DRNG 1
+#  endif
+# endif
+#endif /*ENABLE_RDRAND_SUPPORT*/
+
+typedef void (*add_fn_t)(const void*, size_t, enum random_origins);
 
 /* Keep track on whether the RNG has problems.  */
 static volatile int rng_failed;
@@ -109,6 +120,55 @@ poll_padlock (void (*add)(const void*, size_t, enum random_origins),
 #endif /*USE_PADLOCK*/
 
 
+#ifdef USE_DRNG
+# define RDRAND_RETRY_LOOPS	10
+# define RDRAND_INT	".byte 0x0f,0xc7,0xf0"
+# ifdef __x86_64__
+#  define RDRAND_LONG	".byte 0x48,0x0f,0xc7,0xf0"
+# else
+#  define RDRAND_LONG	RDRAND_INT
+# endif
+static inline int
+rdrand_long (unsigned long *v)
+{
+  int ok;
+  asm volatile ("1: " RDRAND_LONG "\n\t"
+                "jc 2f\n\t"
+                "decl %0\n\t"
+                "jnz 1b\n\t"
+                "2:"
+                : "=r" (ok), "=a" (*v)
+                : "0" (RDRAND_RETRY_LOOPS));
+  return ok;
+}
+
+
+static inline int
+rdrand_nlong (unsigned long *v, int count)
+{
+  while (count--)
+    if (!rdrand_long(v++))
+      return 0;
+  return 1;
+}
+
+
+static size_t
+poll_drng (add_fn_t add, enum random_origins origin, int fast)
+{
+  volatile char buffer[64] __attribute__ ((aligned (8)));
+  unsigned int nbytes = sizeof (buffer);
+
+  (void)fast;
+
+  if (!rdrand_nlong ((unsigned long *)buffer, sizeof(buffer)/sizeof(long)))
+    return 0;
+  (*add)((void *)buffer, nbytes, origin);
+  return nbytes;
+}
+#endif /*USE_DRNG*/
+
+
 int
 _gcry_rndhw_failed_p (void)
 {
@@ -125,6 +185,10 @@ _gcry_rndhw_poll_fast (void (*add)(const void*, size_t, enum random_origins),
   (void)add;
   (void)origin;
 
+#ifdef USE_DRNG
+  if ((_gcry_get_hw_features () & HWF_INTEL_RDRAND))
+    poll_drng (add, origin, 1);
+#endif
 #ifdef USE_PADLOCK
   if ((_gcry_get_hw_features () & HWF_PADLOCK_RNG))
     poll_padlock (add, origin, 1);
@@ -143,6 +207,10 @@ _gcry_rndhw_poll_slow (void (*add)(const void*, size_t, enum random_origins),
   (void)add;
   (void)origin;
 
+#ifdef USE_DRNG
+  if ((_gcry_get_hw_features () & HWF_INTEL_RDRAND))
+    nbytes += poll_drng (add, origin, 0);
+#endif
 #ifdef USE_PADLOCK
   if ((_gcry_get_hw_features () & HWF_PADLOCK_RNG))
     nbytes += poll_padlock (add, origin, 0);
diff --git a/src/g10lib.h b/src/g10lib.h
index f1af399..5e99c46 100644
--- a/src/g10lib.h
+++ b/src/g10lib.h
@@ -151,6 +151,7 @@ int _gcry_log_verbosity( int level );
 #define HWF_PADLOCK_MMUL 8
 
 #define HWF_INTEL_AESNI  256
+#define HWF_INTEL_RDRAND 512
 
 
 unsigned int _gcry_get_hw_features (void);
diff --git a/src/global.c b/src/global.c
index f280a7b..2428e21 100644
--- a/src/global.c
+++ b/src/global.c
@@ -66,6 +66,7 @@ static struct
     { HWF_PADLOCK_SHA, "padlock-sha" },
     { HWF_PADLOCK_MMUL,"padlock-mmul"},
     { HWF_INTEL_AESNI, "intel-aesni" },
+    { HWF_INTEL_RDRAND,"intel-rdrand" },
     { 0, NULL}
   };
 
diff --git a/src/hwfeatures.c b/src/hwfeatures.c
index 82c435b..e89c825 100644
--- a/src/hwfeatures.c
+++ b/src/hwfeatures.c
@@ -134,6 +134,20 @@ detect_x86_64_gnuc (void)
      : "%eax", "%ebx", "%ecx", "%edx", "cc"
      );
 #endif /*#ifdef ENABLE_AESNI_SUPPORT*/
+#ifdef ENABLE_DRNG_SUPPORT
+  asm volatile
+    ("movl $1, %%eax\n\t"           /* Get CPU info and feature flags.  */
+     "cpuid\n"
+     "testl $0x40000000, %%ecx\n\t" /* Test bit 30.  */
+     "jz .Lno_rdrand%=\n\t"         /* No RDRAND support.  */
+     "orl $512, %0\n"               /* Set our HWF_INTEL_RDRAND bit.  */
+
+     ".Lno_rdrand%=:\n"
+     : "+r" (hw_features)
+     :
+     : "%eax", "%ebx", "%ecx", "%edx", "cc"
+     );
+#endif /* #ifdef ENABLE_DRNG_SUPPORT */
 
 }
 #endif /* __x86_64__ && __GNUC__ */
@@ -267,6 +281,22 @@ detect_ia32_gnuc (void)
      : "%eax", "%ecx", "%edx", "cc"
      );
 #endif /*ENABLE_AESNI_SUPPORT*/
+#ifdef ENABLE_DRNG_SUPPORT
+  asm volatile
+    ("pushl %%ebx\n\t"	        /* Save GOT register.  */
+     "movl $1, %%eax\n\t"           /* Get CPU info and feature flags.  */
+     "cpuid\n"
+     "popl %%ebx\n\t"	        /* Restore GOT register. */
+     "testl $0x40000000, %%ecx\n\t" /* Test bit 30.  */
+     "jz .Lno_rdrand%=\n\t"         /* No RDRAND support.  */
+     "orl $512, %0\n"               /* Set our HWF_INTEL_RDRAND bit.  */
+
+     ".Lno_rdrand%=:\n"
+     : "+r" (hw_features)
+     :
+     : "%eax", "%ecx", "%edx", "cc"
+     );
+#endif /*ENABLE_DRNG_SUPPORT*/
 
 }
 #endif /* __i386__ && SIZEOF_UNSIGNED_LONG == 4 && __GNUC__ */

commit bfe4dc11bb822cbc5bf2b425e5a5a2867a904518
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Dec 18 18:42:23 2012 +0100

    doc: Add Dmitry to AUTHORS
    
    --

diff --git a/AUTHORS b/AUTHORS
index 8f385f8..a2c36da 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -111,6 +111,7 @@ DCO:2012-04-16:Tomáš Mráz <tm at t8m.info>
 DCO:2012-04-20:Rafaël Carré <funman at videolan.org>
 DCO:2012-11-14:Jussi Kivilinna <jussi.kivilinna at mbnet.fi>
 DCO:2012-12-05:Werner Koch <wk at gnupg.org>
+DCO:2012-12-14:Dmitry Kasatkin <dmitry.kasatkin at intel.com>
 
 
 More credits

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

Summary of changes:
 AUTHORS          |    1 +
 configure.ac     |   13 ++++++++++
 random/rndhw.c   |   68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/g10lib.h     |    1 +
 src/global.c     |    1 +
 src/hwfeatures.c |   30 +++++++++++++++++++++++
 6 files changed, 114 insertions(+), 0 deletions(-)


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




More information about the Gnupg-commits mailing list