[git] GCRYPT - branch, master, updated. libgcrypt-1.6.0-46-g5d23e7b

by Dmitry Eremin-Solenikov cvs at cvs.gnupg.org
Mon Jan 27 14:28:26 CET 2014


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  5d23e7b9a77421f3ebfda4a84c459a8729f3bb41 (commit)
       via  f7df906171854b6b6506b82d4fee2c2ebb0327ea (commit)
       via  79da0358fd555361e1ce4202f55494a8918eb8ae (commit)
       via  bf34bfa5c458ee5ece91f25e3b4194d768498ab6 (commit)
       via  ff91ec934ed52294cddcd7dcfacc04721a0487bf (commit)
       via  24e65d715812cea28732397870cb1585b8435521 (commit)
      from  4ad3417acab5021db1f722c314314ce4b781833a (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 5d23e7b9a77421f3ebfda4a84c459a8729f3bb41
Author: Dmitry Eremin-Solenikov <dbaryshkov at gmail.com>
Date:   Fri Jan 24 15:02:14 2014 +0400

    Fix number of blocks passed used in _gcry_rmd160_mixblock
    
    * cipher/rmd160.c (_gcry_rmd160_mixblock): pass 1 to transform
    
    --
    Currently _gcry_rmd160_mixblock() passes 64 as nblocks to transform()
    function, while passing only one block of data. This causes acess after
    the allocated data and tons of errors on each valgrind invokation.
    
    Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov at gmail.com>
    
    This fixes commit 50b8c834.

diff --git a/cipher/rmd160.c b/cipher/rmd160.c
index 1a58ba6..2aba0fe 100644
--- a/cipher/rmd160.c
+++ b/cipher/rmd160.c
@@ -421,7 +421,7 @@ _gcry_rmd160_mixblock ( RMD160_CONTEXT *hd, void *blockof64byte )
 {
   char *p = blockof64byte;
 
-  transform ( hd, blockof64byte, 64 );
+  transform ( hd, blockof64byte, 1 );
 #define X(a) do { *(u32*)p = hd->h##a ; p += 4; } while(0)
   X(0);
   X(1);

commit f7df906171854b6b6506b82d4fee2c2ebb0327ea
Author: Werner Koch <wk at gnupg.org>
Date:   Thu Jan 9 19:14:09 2014 +0100

    Small Windows build tweaks.
    
    * configure.ac (HAVE_PTHREAD): Do test when building for Windows.
    
    * tests/basic.c: Replace "%zi" by "%z" and a cast to make it work
    under Windows.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/configure.ac b/configure.ac
index 4d16fc6..6254453 100644
--- a/configure.ac
+++ b/configure.ac
@@ -729,9 +729,11 @@ AC_SUBST(PTH_LIBS)
 #
 # Check whether pthreads is available
 #
-AC_CHECK_LIB(pthread,pthread_create,have_pthread=yes)
-if test "$have_pthread" = yes; then
-   AC_DEFINE(HAVE_PTHREAD, 1 ,[Define if we have pthread.])
+if test "$have_w32_system" != yes; then
+  AC_CHECK_LIB(pthread,pthread_create,have_pthread=yes)
+  if test "$have_pthread" = yes; then
+    AC_DEFINE(HAVE_PTHREAD, 1 ,[Define if we have pthread.])
+  fi
 fi
 
 
diff --git a/tests/basic.c b/tests/basic.c
index 5fd7131..e85e4e1 100644
--- a/tests/basic.c
+++ b/tests/basic.c
@@ -4063,11 +4063,11 @@ check_digests (void)
           continue;
         }
       if (verbose)
-	fprintf (stderr, "  checking %s [%i] for length %zi\n",
+	fprintf (stderr, "  checking %s [%i] for length %d\n",
 		 gcry_md_algo_name (algos[i].md),
 		 algos[i].md,
                  !strcmp (algos[i].data, "!")?
-                 1000000 : strlen(algos[i].data));
+                 1000000 : (int)strlen(algos[i].data));
 
       check_one_md (algos[i].md, algos[i].data, strlen (algos[i].data),
 		    algos[i].expect);
@@ -4488,10 +4488,10 @@ check_hmac (void)
         }
       if (verbose)
 	fprintf (stderr,
-                 "  checking %s [%i] for %zi byte key and %zi byte data\n",
+                 "  checking %s [%i] for %d byte key and %d byte data\n",
 		 gcry_md_algo_name (algos[i].md),
 		 algos[i].md,
-		 strlen(algos[i].key), strlen(algos[i].data));
+		 (int)strlen(algos[i].key), (int)strlen(algos[i].data));
 
       check_one_hmac (algos[i].md, algos[i].data, strlen (algos[i].data),
 		      algos[i].key, strlen(algos[i].key),
@@ -5091,10 +5091,10 @@ check_mac (void)
         }
       if (verbose)
 	fprintf (stderr,
-                 "  checking %s [%i] for %zi byte key and %zi byte data\n",
+                 "  checking %s [%i] for %d byte key and %d byte data\n",
 		 gcry_mac_algo_name (algos[i].algo),
 		 algos[i].algo,
-		 strlen(algos[i].key), strlen(algos[i].data));
+		 (int)strlen(algos[i].key), (int)strlen(algos[i].data));
 
       check_one_mac (algos[i].algo, algos[i].data, strlen (algos[i].data),
 		     algos[i].key, strlen(algos[i].key), algos[i].iv,

commit 79da0358fd555361e1ce4202f55494a8918eb8ae
Author: Werner Koch <wk at gnupg.org>
Date:   Thu Jan 9 19:14:09 2014 +0100

    Update gpg-error autoconf macros to fix threading problems.
    
    * m4/gpg-error.m4: Update to version 2014-01-24.
    * tests/Makefile.am (t_lock_LDADD): Use MT Libs.

diff --git a/m4/gpg-error.m4 b/m4/gpg-error.m4
index eb5d7c4..053eceb 100644
--- a/m4/gpg-error.m4
+++ b/m4/gpg-error.m4
@@ -1,5 +1,5 @@
 # gpg-error.m4 - autoconf macro to detect libgpg-error.
-# Copyright (C) 2002, 2003, 2004 g10 Code GmbH
+# Copyright (C) 2002, 2003, 2004, 2011, 2014 g10 Code GmbH
 #
 # This file is free software; as a special exception the author gives
 # unlimited permission to copy and/or distribute it, with or without
@@ -8,26 +8,33 @@
 # This file is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+#
+# Last-changed: 2014-01-24
+
 
 dnl AM_PATH_GPG_ERROR([MINIMUM-VERSION,
 dnl                   [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
-dnl Test for libgpg-error and define GPG_ERROR_CFLAGS and GPG_ERROR_LIBS
+dnl
+dnl Test for libgpg-error and define GPG_ERROR_CFLAGS, GPG_ERROR_LIBS,
+dnl GPG_ERROR_MT_CFLAGS, and GPG_ERROR_MT_LIBS.  The _MT_ variants are
+dnl used for programs requireding real multi thread support.
 dnl
 AC_DEFUN([AM_PATH_GPG_ERROR],
-[
+[ AC_REQUIRE([AC_CANONICAL_HOST])
+  gpg_error_config_prefix=""
   dnl --with-libgpg-error-prefix=PFX is the preferred name for this option,
   dnl since that is consistent with how our three siblings use the directory/
   dnl package name in --with-$dir_name-prefix=PFX.
   AC_ARG_WITH(libgpg-error-prefix,
-            AC_HELP_STRING([--with-libgpg-error-prefix=PFX],
-                           [prefix where GPG Error is installed (optional)]),
-     gpg_error_config_prefix="$withval", gpg_error_config_prefix="")
+              AC_HELP_STRING([--with-libgpg-error-prefix=PFX],
+                             [prefix where GPG Error is installed (optional)]),
+              [gpg_error_config_prefix="$withval"])
 
   dnl Accept --with-gpg-error-prefix and make it work the same as
   dnl --with-libgpg-error-prefix above, for backwards compatibility,
   dnl but do not document this old, inconsistently-named option.
   AC_ARG_WITH(gpg-error-prefix,,
-     gpg_error_config_prefix="$withval", gpg_error_config_prefix="")
+              [gpg_error_config_prefix="$withval"])
 
   if test x$gpg_error_config_prefix != x ; then
      if test x${GPG_ERROR_CONFIG+set} != xset ; then
@@ -39,7 +46,8 @@ AC_DEFUN([AM_PATH_GPG_ERROR],
   min_gpg_error_version=ifelse([$1], ,0.0,$1)
   AC_MSG_CHECKING(for GPG Error - version >= $min_gpg_error_version)
   ok=no
-  if test "$GPG_ERROR_CONFIG" != "no" ; then
+  if test "$GPG_ERROR_CONFIG" != "no" \
+     && test -f "$GPG_ERROR_CONFIG" ; then
     req_major=`echo $min_gpg_error_version | \
                sed 's/\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
     req_minor=`echo $min_gpg_error_version | \
@@ -62,12 +70,13 @@ AC_DEFUN([AM_PATH_GPG_ERROR],
   if test $ok = yes; then
     GPG_ERROR_CFLAGS=`$GPG_ERROR_CONFIG $gpg_error_config_args --cflags`
     GPG_ERROR_LIBS=`$GPG_ERROR_CONFIG $gpg_error_config_args --libs`
+    GPG_ERROR_MT_CFLAGS=`$GPG_ERROR_CONFIG $gpg_error_config_args --mt --cflags 2>/dev/null`
+    GPG_ERROR_MT_LIBS=`$GPG_ERROR_CONFIG $gpg_error_config_args --mt --libs 2>/dev/null`
     AC_MSG_RESULT([yes ($gpg_error_config_version)])
     ifelse([$2], , :, [$2])
-    if test x"$host" != x ; then
-      gpg_error_config_host=`$GPG_ERROR_CONFIG $gpg_error_config_args --host 2>/dev/null || echo none`
-      if test x"$gpg_error_config_host" != xnone ; then
-        if test x"$gpg_error_config_host" != x"$host" ; then
+    gpg_error_config_host=`$GPG_ERROR_CONFIG $gpg_error_config_args --host 2>/dev/null || echo none`
+    if test x"$gpg_error_config_host" != xnone ; then
+      if test x"$gpg_error_config_host" != x"$host" ; then
   AC_MSG_WARN([[
 ***
 *** The config script $GPG_ERROR_CONFIG was
@@ -76,15 +85,18 @@ AC_DEFUN([AM_PATH_GPG_ERROR],
 *** You may want to use the configure option --with-gpg-error-prefix
 *** to specify a matching config script.
 ***]])
-        fi
       fi
     fi
   else
     GPG_ERROR_CFLAGS=""
     GPG_ERROR_LIBS=""
+    GPG_ERROR_MT_CFLAGS=""
+    GPG_ERROR_MT_LIBS=""
     AC_MSG_RESULT(no)
     ifelse([$3], , :, [$3])
   fi
   AC_SUBST(GPG_ERROR_CFLAGS)
   AC_SUBST(GPG_ERROR_LIBS)
+  AC_SUBST(GPG_ERROR_MT_CFLAGS)
+  AC_SUBST(GPG_ERROR_MT_LIBS)
 ])
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ac5ab70..4cf7a44 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -46,9 +46,9 @@ AM_CPPFLAGS = -I../src -I$(top_srcdir)/src
 AM_CFLAGS = $(GPG_ERROR_CFLAGS)
 AM_LDFLAGS = -no-install
 
-default_ldadd = \
+standard_ldadd = \
 	../src/libgcrypt.la $(DL_LIBS) \
-        ../compat/libcompat.la $(GPG_ERROR_LIBS)
+        ../compat/libcompat.la
 
 EXTRA_PROGRAMS = testapi pkbench
 noinst_PROGRAMS = $(tests_bin) $(tests_bin_last) fipsdrv rsacvt genhashdata
@@ -58,5 +58,6 @@ EXTRA_DIST = README rsa-16k.key cavs_tests.sh cavs_driver.pl \
 	     pkcs1v2-oaep.h pkcs1v2-pss.h pkcs1v2-v15c.h pkcs1v2-v15s.h \
 	     t-ed25519.inp stopwatch.h hashtest-256g.in
 
-LDADD = $(default_ldadd)
-t_lock_LDADD = $(default_ldadd) $(LIBMULTITHREAD)
+LDADD = $(standard_ldadd) $(GPG_ERROR_LIBS)
+t_lock_LDADD = $(standard_ldadd) $(GPG_ERROR_MT_LIBS)
+t_lock_CFLAGS = $(GPG_ERROR_MT_CFLAGS)

commit bf34bfa5c458ee5ece91f25e3b4194d768498ab6
Author: Dmitry Eremin-Solenikov <dbaryshkov at gmail.com>
Date:   Fri Jan 24 15:02:15 2014 +0400

    tests: Pass -no-install to libtool
    
    * tests/Makefile.am: add AM_LDFLAGS = -no-install
    
    --
    There is little point building tests with support for installation.
    Passing -no-install stops libtool from building wrapper scripts,
    thus allowing direct gdb/valgrind invocation on programs in tests/
    subdirectory.
    
    Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov at gmail.com>

diff --git a/tests/Makefile.am b/tests/Makefile.am
index f0a4633..ac5ab70 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -44,6 +44,7 @@ TESTS_ENVIRONMENT = GCRYPT_IN_REGRESSION_TEST=1
 # a built header.
 AM_CPPFLAGS = -I../src -I$(top_srcdir)/src
 AM_CFLAGS = $(GPG_ERROR_CFLAGS)
+AM_LDFLAGS = -no-install
 
 default_ldadd = \
 	../src/libgcrypt.la $(DL_LIBS) \

commit ff91ec934ed52294cddcd7dcfacc04721a0487bf
Author: Werner Koch <wk at gnupg.org>
Date:   Thu Jan 9 19:14:09 2014 +0100

    tests: Add a test for the internal locking
    
    * src/global.c (external_lock_test): New.
    (_gcry_vcontrol): Call new function with formerly reserved code 61.
    
    * tests/t-common.h: New. Taken from current libgpg-error.
    * tests/t-lock.c: New.  Based on t-lock.c from libgpg-error.
    * configure.ac (HAVE_PTHREAD): Set macro to 1 if defined.
    (AC_CHECK_FUNCS): Check for flockfile.
    * tests/Makefile.am (tests_bin): Add t-lock.
    (noinst_HEADERS): Add t-common.h
    (LDADD): Move value to ...
    (default_ldadd): new.
    (t_lock_LDADD): New.
    --
    
    Signed-off-by: Werner Koch <wk at gnupg.org>
    (cherry picked from commit fa42c61a84996b6a7574c32233dfd8d9f254d93a)
    
    Resolved conflicts:
    	* src/ath.c: Remove as not anymore used in 1.7.
    	* tests/Makefile.am: Merge.
    
    Changes:
    
            * src/global.c (external_lock_test): Use the gpgrt function
              for locking.
    
            Changed subject because here we are only adding the test case.

diff --git a/configure.ac b/configure.ac
index 1d5027a..4d16fc6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -731,7 +731,7 @@ AC_SUBST(PTH_LIBS)
 #
 AC_CHECK_LIB(pthread,pthread_create,have_pthread=yes)
 if test "$have_pthread" = yes; then
-   AC_DEFINE(HAVE_PTHREAD, ,[Define if we have pthread.])
+   AC_DEFINE(HAVE_PTHREAD, 1 ,[Define if we have pthread.])
 fi
 
 
@@ -1364,7 +1364,7 @@ AC_CHECK_FUNCS(strtoul memmove stricmp atexit raise)
 # Other checks
 AC_CHECK_FUNCS(strerror rand mmap getpagesize sysconf waitpid wait4)
 AC_CHECK_FUNCS(gettimeofday getrusage gethrtime clock_gettime syslog)
-AC_CHECK_FUNCS(fcntl ftruncate)
+AC_CHECK_FUNCS(fcntl ftruncate flockfile)
 
 GNUPG_CHECK_MLOCK
 
diff --git a/src/global.c b/src/global.c
index b2b1de6..ec0cc3f 100644
--- a/src/global.c
+++ b/src/global.c
@@ -66,6 +66,8 @@ static gcry_handler_no_mem_t outofcore_handler;
 static void *outofcore_handler_value;
 static int no_secure_memory;
 
+/* Prototypes.  */
+static gpg_err_code_t external_lock_test (int cmd);
 
 
 
@@ -607,7 +609,8 @@ _gcry_vcontrol (enum gcry_ctl_cmds cmd, va_list arg_ptr)
         _gcry_random_deinit_external_test (ctx);
       }
       break;
-    case 61:  /* RFU */
+    case 61:  /* Run external lock test */
+      rc = external_lock_test (va_arg (arg_ptr, int));
       break;
     case 62:  /* RFU */
       break;
@@ -1108,3 +1111,48 @@ _gcry_set_progress_handler (void (*cb)(void *,const char*,int, int, int),
   _gcry_register_primegen_progress (cb, cb_data);
   _gcry_register_random_progress (cb, cb_data);
 }
+
+
+
+/* This is a helper for the regression test suite to test Libgcrypt's locks.
+   It works using a one test lock with CMD controlling what to do:
+
+     30111 - Allocate and init lock
+     30112 - Take lock
+     30113 - Release lock
+     30114 - Destroy lock.
+
+   This function is used by tests/t-lock.c - it is not part of the
+   public API!
+ */
+static gpg_err_code_t
+external_lock_test (int cmd)
+{
+  GPGRT_LOCK_DEFINE (testlock);
+  gpg_err_code_t rc = 0;
+
+  switch (cmd)
+    {
+    case 30111:  /* Init Lock.  */
+      rc = gpgrt_lock_init (&testlock);
+      break;
+
+    case 30112:  /* Take Lock.  */
+      rc = gpgrt_lock_lock (&testlock);
+      break;
+
+    case 30113:  /* Release Lock.  */
+      rc = gpgrt_lock_unlock (&testlock);
+      break;
+
+    case 30114:  /* Destroy Lock.  */
+      rc = gpgrt_lock_destroy (&testlock);
+      break;
+
+    default:
+      rc = GPG_ERR_INV_OP;
+      break;
+    }
+
+  return rc;
+}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 884fb3d..f0a4633 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -20,7 +20,7 @@
 
 tests_bin = \
         version mpitests t-sexp t-convert \
-	t-mpi-bit t-mpi-point curves \
+	t-mpi-bit t-mpi-point curves t-lock \
 	prime basic keygen pubkey hmac hashtest t-kdf keygrip \
 	fips186-dsa aeswrap pkcs1v2 random dsa-rfc6979 t-ed25519
 
@@ -45,11 +45,17 @@ TESTS_ENVIRONMENT = GCRYPT_IN_REGRESSION_TEST=1
 AM_CPPFLAGS = -I../src -I$(top_srcdir)/src
 AM_CFLAGS = $(GPG_ERROR_CFLAGS)
 
-LDADD = ../src/libgcrypt.la $(DL_LIBS) ../compat/libcompat.la $(GPG_ERROR_LIBS)
+default_ldadd = \
+	../src/libgcrypt.la $(DL_LIBS) \
+        ../compat/libcompat.la $(GPG_ERROR_LIBS)
 
 EXTRA_PROGRAMS = testapi pkbench
 noinst_PROGRAMS = $(tests_bin) $(tests_bin_last) fipsdrv rsacvt genhashdata
+noinst_HEADERS = t-common.h
 
 EXTRA_DIST = README rsa-16k.key cavs_tests.sh cavs_driver.pl \
 	     pkcs1v2-oaep.h pkcs1v2-pss.h pkcs1v2-v15c.h pkcs1v2-v15s.h \
 	     t-ed25519.inp stopwatch.h hashtest-256g.in
+
+LDADD = $(default_ldadd)
+t_lock_LDADD = $(default_ldadd) $(LIBMULTITHREAD)
diff --git a/tests/t-common.h b/tests/t-common.h
new file mode 100644
index 0000000..288963d
--- /dev/null
+++ b/tests/t-common.h
@@ -0,0 +1,99 @@
+/* t-common.h - Common code for the tests.
+ * Copyright (C) 2013 g10 Code GmbH
+ *
+ * This file is part of libgpg-error.
+ *
+ * libgpg-error is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * libgpg-error is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdarg.h>
+
+#include "../src/gcrypt.h"
+
+#ifndef PGM
+# error Macro PGM not defined.
+#endif
+
+
+static int verbose;
+static int debug;
+static int errorcount;
+
+
+static void
+die (const char *format, ...)
+{
+  va_list arg_ptr ;
+
+  fflush (stdout);
+#ifdef HAVE_FLOCKFILE
+  flockfile (stderr);
+#endif
+  fprintf (stderr, "%s: ", PGM);
+  va_start (arg_ptr, format) ;
+  vfprintf (stderr, format, arg_ptr);
+  va_end (arg_ptr);
+  if (*format && format[strlen(format)-1] != '\n')
+    putc ('\n', stderr);
+#ifdef HAVE_FLOCKFILE
+  funlockfile (stderr);
+#endif
+  exit (1);
+}
+
+
+static void
+fail (const char *format, ...)
+{
+  va_list arg_ptr;
+
+  fflush (stdout);
+#ifdef HAVE_FLOCKFILE
+  flockfile (stderr);
+#endif
+  fprintf (stderr, "%s: ", PGM);
+  va_start (arg_ptr, format);
+  vfprintf (stderr, format, arg_ptr);
+  va_end (arg_ptr);
+  if (*format && format[strlen(format)-1] != '\n')
+    putc ('\n', stderr);
+#ifdef HAVE_FLOCKFILE
+  funlockfile (stderr);
+#endif
+  errorcount++;
+  if (errorcount >= 50)
+    die ("stopped after 50 errors.");
+}
+
+
+static void
+show (const char *format, ...)
+{
+  va_list arg_ptr;
+
+  if (!verbose)
+    return;
+#ifdef HAVE_FLOCKFILE
+  flockfile (stderr);
+#endif
+  fprintf (stderr, "%s: ", PGM);
+  va_start (arg_ptr, format);
+  vfprintf (stderr, format, arg_ptr);
+  if (*format && format[strlen(format)-1] != '\n')
+    putc ('\n', stderr);
+  va_end (arg_ptr);
+#ifdef HAVE_FLOCKFILE
+  funlockfile (stderr);
+#endif
+}
diff --git a/tests/t-lock.c b/tests/t-lock.c
new file mode 100644
index 0000000..c6c1e41
--- /dev/null
+++ b/tests/t-lock.c
@@ -0,0 +1,460 @@
+/* t-lock.c - Check the lock functions
+ * Copyright (C) 2014 g10 Code GmbH
+ *
+ * This file is part of Libgcrypt.
+ *
+ * Libgcrypt is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * Libgcrypt is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <errno.h>
+#include <unistd.h>
+#if HAVE_PTHREAD
+# include <pthread.h>
+#endif
+
+#define PGM "t-lock"
+
+#include "t-common.h"
+
+/* Mingw requires us to include windows.h after winsock2.h which is
+   included by gcrypt.h.  */
+#ifdef _WIN32
+# include <windows.h>
+#endif
+
+#ifdef _WIN32
+# define THREAD_RET_TYPE  DWORD WINAPI
+# define THREAD_RET_VALUE 0
+#else
+# define THREAD_RET_TYPE  void *
+# define THREAD_RET_VALUE NULL
+#endif
+
+#define PRIV_CTL_EXTERNAL_LOCK_TEST   61
+#define EXTERNAL_LOCK_TEST_INIT       30111
+#define EXTERNAL_LOCK_TEST_LOCK       30112
+#define EXTERNAL_LOCK_TEST_UNLOCK     30113
+#define EXTERNAL_LOCK_TEST_DESTROY    30114
+
+
+/* Number of threads to run.  */
+#define N_NONCE_THREADS 8
+/* Number of interations.  */
+#define N_NONCE_ITERATIONS 1000
+/* Requested nonce size.  */
+#define NONCE_SIZE  11
+
+
+/* This tests works by having a a couple of accountant threads which do
+   random transactions between accounts and a revision threads which
+   checks that the balance of all accounts is invariant.  The idea for
+   this check is due to Bruno Haible.  */
+#define N_ACCOUNT 8
+#define ACCOUNT_VALUE 42
+static int account[N_ACCOUNT];
+
+/* Number of transactions done by each accountant.  */
+#define N_TRANSACTIONS 1000
+
+/* Number of accountants to run.  */
+#define N_ACCOUNTANTS 5
+
+/* Maximum transaction value.  A quite low value is used so that we
+   would get an integer overflow.  */
+#define MAX_TRANSACTION_VALUE 50
+
+/* Flag to tell the revision thread to finish.  */
+static volatile int stop_revision_thread;
+
+
+struct thread_arg_s
+{
+  int no;
+};
+
+
+
+
+/* Wrapper functions to access Libgcrypt's internal test lock.  */
+static void
+external_lock_test_init (int line)
+{
+  gpg_error_t err;
+
+  err = gcry_control (PRIV_CTL_EXTERNAL_LOCK_TEST, EXTERNAL_LOCK_TEST_INIT);
+  if (err)
+    fail ("init lock failed at %d: %s", line, gpg_strerror (err));
+}
+
+static void
+external_lock_test_lock (int line)
+{
+  gpg_error_t err;
+
+  err = gcry_control (PRIV_CTL_EXTERNAL_LOCK_TEST, EXTERNAL_LOCK_TEST_LOCK);
+  if (err)
+    fail ("taking lock failed at %d: %s", line, gpg_strerror (err));
+}
+
+static void
+external_lock_test_unlock (int line)
+{
+  gpg_error_t err;
+
+  err = gcry_control (PRIV_CTL_EXTERNAL_LOCK_TEST, EXTERNAL_LOCK_TEST_UNLOCK);
+  if (err)
+    fail ("releasing lock failed at %d: %s", line, gpg_strerror (err));
+
+}
+
+static void
+external_lock_test_destroy (int line)
+{
+  gpg_error_t err;
+
+  err = gcry_control (PRIV_CTL_EXTERNAL_LOCK_TEST, EXTERNAL_LOCK_TEST_DESTROY);
+  if (err)
+    fail ("destroying lock failed at %d: %s", line, gpg_strerror (err));
+}
+
+
+
+
+/* The nonce thread.  We simply request a couple of nonces and
+   return.  */
+static THREAD_RET_TYPE
+nonce_thread (void *argarg)
+{
+  struct thread_arg_s *arg = argarg;
+  int i;
+  char nonce[NONCE_SIZE];
+
+  for (i = 0; i < N_NONCE_ITERATIONS; i++)
+    {
+      gcry_create_nonce (nonce, sizeof nonce);
+      if (i && !(i%100))
+        show ("thread %d created %d nonces so far", arg->no, i);
+    }
+
+  gcry_free (arg);
+  return THREAD_RET_VALUE;
+}
+
+
+/* To check our locking function we run several threads all accessing
+   the nonce functions.  If this function returns we know that there
+   are no obvious deadlocks or failed lock initialization.  */
+static void
+check_nonce_lock (void)
+{
+  struct thread_arg_s *arg;
+#ifdef _WIN32
+  HANDLE threads[N_NONCE_THREADS];
+  int i;
+  int rc;
+
+  for (i=0; i < N_NONCE_THREADS; i++)
+    {
+      arg = gcry_xmalloc (sizeof *arg);
+      arg->no = i;
+      threads[i] = CreateThread (NULL, 0, nonce_thread, arg, 0, NULL);
+      if (!threads[i])
+        die ("error creating nonce thread %d: rc=%d",
+             i, (int)GetLastError ());
+    }
+
+  for (i=0; i < N_NONCE_THREADS; i++)
+    {
+      rc = WaitForSingleObject (threads[i], INFINITE);
+      if (rc == WAIT_OBJECT_0)
+        show ("nonce thread %d has terminated", i);
+      else
+        fail ("waiting for nonce thread %d failed: %d",
+              i, (int)GetLastError ());
+      CloseHandle (threads[i]);
+    }
+
+#elif HAVE_PTHREAD
+  pthread_t threads[N_NONCE_THREADS];
+  int rc, i;
+
+  for (i=0; i < N_NONCE_THREADS; i++)
+    {
+      arg = gcry_xmalloc (sizeof *arg);
+      arg->no = i;
+      pthread_create (&threads[i], NULL, nonce_thread, arg);
+    }
+
+  for (i=0; i < N_NONCE_THREADS; i++)
+    {
+      rc = pthread_join (threads[i], NULL);
+      if (rc)
+        fail ("pthread_join failed for nonce thread %d: %s",
+              i, strerror (errno));
+      else
+        show ("nonce thread %d has terminated", i);
+    }
+
+#endif /*!_WIN32*/
+}
+
+
+/* Initialze all accounts.  */
+static void
+init_accounts (void)
+{
+  int i;
+
+  for (i=0; i < N_ACCOUNT; i++)
+    account[i] = ACCOUNT_VALUE;
+}
+
+
+/* Check that the sum of all accounts matches the intial sum.  */
+static void
+check_accounts (void)
+{
+  int i, sum;
+
+  sum = 0;
+  for (i = 0; i < N_ACCOUNT; i++)
+    sum += account[i];
+  if (sum != N_ACCOUNT * ACCOUNT_VALUE)
+    die ("accounts out of balance");
+}
+
+
+static void
+print_accounts (void)
+{
+  int i;
+
+  for (i=0; i < N_ACCOUNT; i++)
+    printf ("account %d: %6d\n", i, account[i]);
+}
+
+
+/* Get a a random integer value in the range 0 to HIGH.  */
+static unsigned int
+get_rand (int high)
+{
+  return (unsigned int)(1+(int)((double)(high+1)*rand ()/(RAND_MAX+1.0))) - 1;
+}
+
+
+/* Pick a random account.  Note that this fucntion is not
+   thread-safe. */
+static int
+pick_account (void)
+{
+  return get_rand (N_ACCOUNT - 1);
+}
+
+
+/* Pick a random value for a transaction.  This is not thread-safe.  */
+static int
+pick_value (void)
+{
+  return get_rand (MAX_TRANSACTION_VALUE);
+}
+
+
+/* This is the revision department.  */
+static THREAD_RET_TYPE
+revision_thread (void *arg)
+{
+  (void)arg;
+
+  while (!stop_revision_thread)
+    {
+      external_lock_test_lock (__LINE__);
+      check_accounts ();
+      external_lock_test_unlock (__LINE__);
+    }
+  return THREAD_RET_VALUE;
+}
+
+
+/* This is one of our accountants.  */
+static THREAD_RET_TYPE
+accountant_thread (void *arg)
+{
+  int i;
+  int acc1, acc2;
+  int value;
+
+  (void)arg;
+
+  for (i = 0; i < N_TRANSACTIONS; i++)
+    {
+      external_lock_test_lock (__LINE__);
+      acc1 = pick_account ();
+      acc2 = pick_account ();
+      value = pick_value ();
+      account[acc1] += value;
+      account[acc2] -= value;
+      external_lock_test_unlock (__LINE__);
+    }
+  return THREAD_RET_VALUE;
+}
+
+
+static void
+run_test (void)
+{
+#ifdef _WIN32
+  HANDLE rthread;
+  HANDLE athreads[N_ACCOUNTANTS];
+  int i;
+  int rc;
+
+  external_lock_test_init (__LINE__);
+  stop_revision_thread = 0;
+  rthread = CreateThread (NULL, 0, revision_thread, NULL, 0, NULL);
+  if (!rthread)
+    die ("error creating revision thread: rc=%d", (int)GetLastError ());
+
+  for (i=0; i < N_ACCOUNTANTS; i++)
+    {
+      athreads[i] = CreateThread (NULL, 0, accountant_thread, NULL, 0, NULL);
+      if (!athreads[i])
+        die ("error creating accountant thread %d: rc=%d",
+             i, (int)GetLastError ());
+    }
+
+  for (i=0; i < N_ACCOUNTANTS; i++)
+    {
+      rc = WaitForSingleObject (athreads[i], INFINITE);
+      if (rc == WAIT_OBJECT_0)
+        show ("accountant thread %d has terminated", i);
+      else
+        fail ("waiting for accountant thread %d failed: %d",
+              i, (int)GetLastError ());
+      CloseHandle (athreads[i]);
+    }
+  stop_revision_thread = 1;
+
+  rc = WaitForSingleObject (rthread, INFINITE);
+  if (rc == WAIT_OBJECT_0)
+    show ("revision thread has terminated");
+  else
+    fail ("waiting for revision thread failed: %d", (int)GetLastError ());
+  CloseHandle (rthread);
+
+#else /*!_WIN32*/
+  pthread_t rthread;
+  pthread_t athreads[N_ACCOUNTANTS];
+  int rc, i;
+
+  external_lock_test_init (__LINE__);
+  stop_revision_thread = 0;
+  pthread_create (&rthread, NULL, revision_thread, NULL);
+
+  for (i=0; i < N_ACCOUNTANTS; i++)
+    pthread_create (&athreads[i], NULL, accountant_thread, NULL);
+
+  for (i=0; i < N_ACCOUNTANTS; i++)
+    {
+      rc = pthread_join (athreads[i], NULL);
+      if (rc)
+        fail ("pthread_join failed for accountant thread %d: %s",
+              i, strerror (errno));
+      else
+        show ("accountant thread %d has terminated", i);
+    }
+
+  stop_revision_thread = 1;
+  rc = pthread_join (rthread, NULL);
+  if (rc)
+    fail ("pthread_join failed for the revision thread: %s", strerror (errno));
+  else
+    show ("revision thread has terminated");
+
+#endif /*!_WIN32*/
+
+  external_lock_test_destroy (__LINE__);
+}
+
+
+
+int
+main (int argc, char **argv)
+{
+  int last_argc = -1;
+
+  if (argc)
+    {
+      argc--; argv++;
+    }
+  while (argc && last_argc != argc )
+    {
+      last_argc = argc;
+      if (!strcmp (*argv, "--help"))
+        {
+          puts (
+"usage: ./t-lock [options]\n"
+"\n"
+"Options:\n"
+"  --verbose      Show what is going on\n"
+"  --debug        Flyswatter\n"
+);
+          exit (0);
+        }
+      if (!strcmp (*argv, "--verbose"))
+        {
+          verbose = 1;
+          argc--; argv++;
+        }
+      else if (!strcmp (*argv, "--debug"))
+        {
+          verbose = debug = 1;
+          argc--; argv++;
+        }
+    }
+
+  srand (time(NULL)*getpid());
+
+  if (debug)
+    gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0);
+  gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
+  if (!gcry_check_version (GCRYPT_VERSION))
+    die ("version mismatch");
+  gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
+  gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
+
+  check_nonce_lock ();
+
+  init_accounts ();
+  check_accounts ();
+
+  run_test ();
+  check_accounts ();
+
+  /* Run a second time to check deinit code.  */
+  run_test ();
+  check_accounts ();
+
+  if (verbose)
+    print_accounts ();
+
+  return errorcount ? 1 : 0;
+}

commit 24e65d715812cea28732397870cb1585b8435521
Author: Werner Koch <wk at gnupg.org>
Date:   Thu Jan 9 19:14:09 2014 +0100

    Check compiler features only for the relevant platform.
    
    * mpi/config.links (mpi_cpu_arch): Always set for ARM.  Set for HPPA.
    Set to "undefined" for unknown platforms.
    (try_asm_modules): Act upon only after having detected the CPU.
    * configure.ac: Move the call to config.links before the platform
    specific compiler checks.  Check platform specific features only if
    the platform is targeted.
    --
    
    There is no need to check x86 options if we are targeting ARM and vice
    versa.  This may only introduce build problems.  With this patch the
    summary output at the end of the compiler also shows more reasonable
    messages.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>
    (cherry picked from commit 04d478d9b0f92d80105ddaf2c011f40ae8260cfb)

diff --git a/configure.ac b/configure.ac
index c3ab96f..1d5027a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -575,10 +575,6 @@ AC_ARG_ENABLE(padlock-support,
        	         [Disable support for the PadLock Engine of VIA processors]),
 	      padlocksupport=$enableval,padlocksupport=yes)
 AC_MSG_RESULT($padlocksupport)
-if test x"$padlocksupport" = xyes ; then
-  AC_DEFINE(ENABLE_PADLOCK_SUPPORT, 1,
-            [Enable support for the PadLock engine.])
-fi
 
 # Implementation of the --disable-aesni-support switch.
 AC_MSG_CHECKING([whether AESNI support is requested])
@@ -603,10 +599,6 @@ AC_ARG_ENABLE(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-avx-support switch.
 AC_MSG_CHECKING([whether AVX support is requested])
@@ -995,19 +987,121 @@ fi
 
 
 #
+# Check whether GCC assembler supports features needed for our ARM
+# implementations.  This needs to be done before setting up the
+# assembler stuff.
+#
+AC_CACHE_CHECK([whether GCC assembler is compatible for ARM assembly implementations],
+       [gcry_cv_gcc_arm_platform_as_ok],
+       [gcry_cv_gcc_arm_platform_as_ok=no
+        AC_COMPILE_IFELSE([AC_LANG_SOURCE(
+          [[__asm__(
+                /* Test if assembler supports UAL syntax.  */
+                ".syntax unified\n\t"
+                ".arm\n\t" /* our assembly code is in ARM mode  */
+                /* Following causes error if assembler ignored '.syntax unified'.  */
+                "asmfunc:\n\t"
+                "add %r0, %r0, %r4, ror #12;\n\t"
+
+                /* Test if '.type' and '.size' are supported.  */
+                ".size asmfunc,.-asmfunc;\n\t"
+                ".type asmfunc,%function;\n\t"
+            );]])],
+          [gcry_cv_gcc_arm_platform_as_ok=yes])])
+if test "$gcry_cv_gcc_arm_platform_as_ok" = "yes" ; then
+   AC_DEFINE(HAVE_COMPATIBLE_GCC_ARM_PLATFORM_AS,1,
+     [Defined if underlying assembler is compatible with ARM assembly implementations])
+fi
+
+
+#
+# Check whether underscores in symbols are required.  This needs to be
+# done before setting up the assembler stuff.
+#
+GNUPG_SYS_SYMBOL_UNDERSCORE()
+
+
+#################################
+####                         ####
+#### Setup assembler stuff.  ####
+#### Define mpi_cpu_arch.    ####
+####                         ####
+#################################
+AC_ARG_ENABLE(mpi-path,
+              AC_HELP_STRING([--enable-mpi-path=EXTRA_PATH],
+	      [prepend EXTRA_PATH to list of CPU specific optimizations]),
+	      mpi_extra_path="$enableval",mpi_extra_path="")
+AC_MSG_CHECKING(architecture and mpi assembler functions)
+if test -f $srcdir/mpi/config.links ; then
+    . $srcdir/mpi/config.links
+    AC_CONFIG_LINKS("$mpi_ln_list")
+    ac_cv_mpi_sflags="$mpi_sflags"
+    AC_MSG_RESULT($mpi_cpu_arch)
+else
+    AC_MSG_RESULT(failed)
+    AC_MSG_ERROR([mpi/config.links missing!])
+fi
+MPI_SFLAGS="$ac_cv_mpi_sflags"
+AC_SUBST(MPI_SFLAGS)
+
+AM_CONDITIONAL(MPI_MOD_ASM_MPIH_ADD1, test "$mpi_mod_asm_mpih_add1" = yes)
+AM_CONDITIONAL(MPI_MOD_ASM_MPIH_SUB1, test "$mpi_mod_asm_mpih_sub1" = yes)
+AM_CONDITIONAL(MPI_MOD_ASM_MPIH_MUL1, test "$mpi_mod_asm_mpih_mul1" = yes)
+AM_CONDITIONAL(MPI_MOD_ASM_MPIH_MUL2, test "$mpi_mod_asm_mpih_mul2" = yes)
+AM_CONDITIONAL(MPI_MOD_ASM_MPIH_MUL3, test "$mpi_mod_asm_mpih_mul3" = yes)
+AM_CONDITIONAL(MPI_MOD_ASM_MPIH_LSHIFT, test "$mpi_mod_asm_mpih_lshift" = yes)
+AM_CONDITIONAL(MPI_MOD_ASM_MPIH_RSHIFT, test "$mpi_mod_asm_mpih_rshift" = yes)
+AM_CONDITIONAL(MPI_MOD_ASM_UDIV, test "$mpi_mod_asm_udiv" = yes)
+AM_CONDITIONAL(MPI_MOD_ASM_UDIV_QRNND, test "$mpi_mod_asm_udiv_qrnnd" = yes)
+AM_CONDITIONAL(MPI_MOD_C_MPIH_ADD1, test "$mpi_mod_c_mpih_add1" = yes)
+AM_CONDITIONAL(MPI_MOD_C_MPIH_SUB1, test "$mpi_mod_c_mpih_sub1" = yes)
+AM_CONDITIONAL(MPI_MOD_C_MPIH_MUL1, test "$mpi_mod_c_mpih_mul1" = yes)
+AM_CONDITIONAL(MPI_MOD_C_MPIH_MUL2, test "$mpi_mod_c_mpih_mul2" = yes)
+AM_CONDITIONAL(MPI_MOD_C_MPIH_MUL3, test "$mpi_mod_c_mpih_mul3" = yes)
+AM_CONDITIONAL(MPI_MOD_C_MPIH_LSHIFT, test "$mpi_mod_c_mpih_lshift" = yes)
+AM_CONDITIONAL(MPI_MOD_C_MPIH_RSHIFT, test "$mpi_mod_c_mpih_rshift" = yes)
+AM_CONDITIONAL(MPI_MOD_C_UDIV, test "$mpi_mod_c_udiv" = yes)
+AM_CONDITIONAL(MPI_MOD_C_UDIV_QRNND, test "$mpi_mod_c_udiv_qrnnd" = yes)
+
+# Reset non applicable feature flags.
+if test "$mpi_cpu_arch" != "x86" ; then
+   aesnisupport="n/a"
+   pclmulsupport="n/a"
+   avxsupport="n/a"
+   avx2support="n/a"
+   padlocksupport="n/a"
+   drngsupport="n/a"
+fi
+
+if test "$mpi_cpu_arch" != "arm" ; then
+   neonsupport="n/a"
+fi
+
+
+#############################################
+####                                     ####
+#### Platform specific compiler checks.  ####
+####                                     ####
+#############################################
+
+#
 # Check whether GCC inline assembler supports SSSE3 instructions
 # This is required for the AES-NI instructions.
 #
 AC_CACHE_CHECK([whether GCC inline assembler supports SSSE3 instructions],
        [gcry_cv_gcc_inline_asm_ssse3],
-       [gcry_cv_gcc_inline_asm_ssse3=no
-        AC_COMPILE_IFELSE([AC_LANG_SOURCE(
+       [if test "$mpi_cpu_arch" != "x86" ; then
+          gcry_cv_gcc_inline_asm_ssse3="n/a"
+        else
+          gcry_cv_gcc_inline_asm_ssse3=no
+          AC_COMPILE_IFELSE([AC_LANG_SOURCE(
           [[static unsigned char be_mask[16] __attribute__ ((aligned (16))) =
               { 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
             void a(void) {
               __asm__("pshufb %[mask], %%xmm2\n\t"::[mask]"m"(*be_mask):);
             }]])],
-          [gcry_cv_gcc_inline_asm_ssse3=yes])])
+          [gcry_cv_gcc_inline_asm_ssse3=yes])
+        fi])
 if test "$gcry_cv_gcc_inline_asm_ssse3" = "yes" ; then
    AC_DEFINE(HAVE_GCC_INLINE_ASM_SSSE3,1,
      [Defined if inline assembler supports SSSE3 instructions])
@@ -1019,12 +1113,16 @@ fi
 #
 AC_CACHE_CHECK([whether GCC inline assembler supports PCLMUL instructions],
        [gcry_cv_gcc_inline_asm_pclmul],
-       [gcry_cv_gcc_inline_asm_pclmul=no
-        AC_COMPILE_IFELSE([AC_LANG_SOURCE(
+       [if test "$mpi_cpu_arch" != "x86" ; then
+          gcry_cv_gcc_inline_asm_pclmul="n/a"
+        else
+          gcry_cv_gcc_inline_asm_pclmul=no
+          AC_COMPILE_IFELSE([AC_LANG_SOURCE(
           [[void a(void) {
               __asm__("pclmulqdq \$0, %%xmm1, %%xmm3\n\t":::"cc");
             }]])],
-          [gcry_cv_gcc_inline_asm_pclmul=yes])])
+          [gcry_cv_gcc_inline_asm_pclmul=yes])
+        fi])
 if test "$gcry_cv_gcc_inline_asm_pclmul" = "yes" ; then
    AC_DEFINE(HAVE_GCC_INLINE_ASM_PCLMUL,1,
      [Defined if inline assembler supports PCLMUL instructions])
@@ -1036,12 +1134,16 @@ fi
 #
 AC_CACHE_CHECK([whether GCC inline assembler supports AVX instructions],
        [gcry_cv_gcc_inline_asm_avx],
-       [gcry_cv_gcc_inline_asm_avx=no
-        AC_COMPILE_IFELSE([AC_LANG_SOURCE(
+       [if test "$mpi_cpu_arch" != "x86" ; then
+          gcry_cv_gcc_inline_asm_avx="n/a"
+        else
+          gcry_cv_gcc_inline_asm_avx=no
+          AC_COMPILE_IFELSE([AC_LANG_SOURCE(
           [[void a(void) {
               __asm__("xgetbv; vaesdeclast (%[mem]),%%xmm0,%%xmm7\n\t"::[mem]"r"(0):);
             }]])],
-          [gcry_cv_gcc_inline_asm_avx=yes])])
+          [gcry_cv_gcc_inline_asm_avx=yes])
+        fi])
 if test "$gcry_cv_gcc_inline_asm_avx" = "yes" ; then
    AC_DEFINE(HAVE_GCC_INLINE_ASM_AVX,1,
      [Defined if inline assembler supports AVX instructions])
@@ -1053,12 +1155,16 @@ fi
 #
 AC_CACHE_CHECK([whether GCC inline assembler supports AVX2 instructions],
        [gcry_cv_gcc_inline_asm_avx2],
-       [gcry_cv_gcc_inline_asm_avx2=no
-        AC_COMPILE_IFELSE([AC_LANG_SOURCE(
+       [if test "$mpi_cpu_arch" != "x86" ; then
+          gcry_cv_gcc_inline_asm_avx2="n/a"
+        else
+          gcry_cv_gcc_inline_asm_avx2=no
+          AC_COMPILE_IFELSE([AC_LANG_SOURCE(
           [[void a(void) {
               __asm__("xgetbv; vpbroadcastb %%xmm7,%%ymm1\n\t":::"cc");
             }]])],
-          [gcry_cv_gcc_inline_asm_avx2=yes])])
+          [gcry_cv_gcc_inline_asm_avx2=yes])
+        fi])
 if test "$gcry_cv_gcc_inline_asm_avx2" = "yes" ; then
    AC_DEFINE(HAVE_GCC_INLINE_ASM_AVX2,1,
      [Defined if inline assembler supports AVX2 instructions])
@@ -1070,12 +1176,16 @@ fi
 #
 AC_CACHE_CHECK([whether GCC inline assembler supports BMI2 instructions],
        [gcry_cv_gcc_inline_asm_bmi2],
-       [gcry_cv_gcc_inline_asm_bmi2=no
-        AC_COMPILE_IFELSE([AC_LANG_SOURCE(
+       [if test "$mpi_cpu_arch" != "x86" ; then
+          gcry_cv_gcc_inline_asm_bmi2="n/a"
+        else
+          gcry_cv_gcc_inline_asm_bmi2=no
+          AC_COMPILE_IFELSE([AC_LANG_SOURCE(
           [[void a(void) {
               __asm__("rorxl \$23, %%eax, %%edx\\n\\t":::"memory");
             }]])],
-          [gcry_cv_gcc_inline_asm_bmi2=yes])])
+          [gcry_cv_gcc_inline_asm_bmi2=yes])
+        fi])
 if test "$gcry_cv_gcc_inline_asm_bmi2" = "yes" ; then
    AC_DEFINE(HAVE_GCC_INLINE_ASM_BMI2,1,
      [Defined if inline assembler supports BMI2 instructions])
@@ -1120,8 +1230,11 @@ fi
 if test $amd64_as_feature_detection = yes; then
   AC_CACHE_CHECK([whether GCC assembler is compatible for amd64 assembly implementations],
        [gcry_cv_gcc_amd64_platform_as_ok],
-       [gcry_cv_gcc_amd64_platform_as_ok=no
-        AC_COMPILE_IFELSE([AC_LANG_SOURCE(
+       [if test "$mpi_cpu_arch" != "x86" ; then
+          gcry_cv_gcc_amd64_platform_as_ok="n/a"
+        else
+          gcry_cv_gcc_amd64_platform_as_ok=no
+          AC_COMPILE_IFELSE([AC_LANG_SOURCE(
           [[__asm__(
                 /* Test if '.type' and '.size' are supported.  */
                 /* These work only on ELF targets. */
@@ -1137,7 +1250,8 @@ if test $amd64_as_feature_detection = yes; then
 		 * to be disable on this machine. */
 		"xorl \$(123456789/12345678), %ebp;\n\t"
             );]])],
-          [gcry_cv_gcc_amd64_platform_as_ok=yes])])
+          [gcry_cv_gcc_amd64_platform_as_ok=yes])
+        fi])
   if test "$gcry_cv_gcc_amd64_platform_as_ok" = "yes" ; then
      AC_DEFINE(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS,1,
               [Defined if underlying assembler is compatible with amd64 assembly implementations])
@@ -1151,8 +1265,11 @@ fi
 #
 AC_CACHE_CHECK([whether GCC assembler is compatible for Intel syntax assembly implementations],
        [gcry_cv_gcc_platform_as_ok_for_intel_syntax],
-       [gcry_cv_gcc_platform_as_ok_for_intel_syntax=no
-        AC_COMPILE_IFELSE([AC_LANG_SOURCE(
+       [if test "$mpi_cpu_arch" != "x86" ; then
+          gcry_cv_gcc_platform_as_ok_for_intel_syntax="n/a"
+        else
+          gcry_cv_gcc_platform_as_ok_for_intel_syntax=no
+          AC_COMPILE_IFELSE([AC_LANG_SOURCE(
           [[__asm__(
                 ".intel_syntax noprefix\n\t"
                 "pxor xmm1, xmm7;\n\t"
@@ -1172,7 +1289,8 @@ AC_CACHE_CHECK([whether GCC assembler is compatible for Intel syntax assembly im
                 "add VAL_A, VAL_B;\n\t"
                 "add VAL_B, 0b10101;\n\t"
             );]])],
-          [gcry_cv_gcc_platform_as_ok_for_intel_syntax=yes])])
+          [gcry_cv_gcc_platform_as_ok_for_intel_syntax=yes])
+        fi])
 if test "$gcry_cv_gcc_platform_as_ok_for_intel_syntax" = "yes" ; then
   AC_DEFINE(HAVE_INTEL_SYNTAX_PLATFORM_AS,1,
             [Defined if underlying assembler is compatible with Intel syntax assembly implementations])
@@ -1184,7 +1302,10 @@ fi
 #
 AC_CACHE_CHECK([whether compiler is configured for ARMv6 or newer architecture],
        [gcry_cv_cc_arm_arch_is_v6],
-       [AC_EGREP_CPP(yes,
+       [if test "$mpi_cpu_arch" != "arm" ; then
+          gcry_cv_cc_arm_arch_is_v6="n/a"
+        else
+          AC_EGREP_CPP(yes,
           [#if defined(__arm__) && \
              ((defined(__ARM_ARCH) && __ARM_ARCH >= 6) \
              || defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \
@@ -1195,7 +1316,8 @@ AC_CACHE_CHECK([whether compiler is configured for ARMv6 or newer architecture],
              || defined(__ARM_ARCH_7EM__))
             yes
            #endif
-          ], gcry_cv_cc_arm_arch_is_v6=yes, gcry_cv_cc_arm_arch_is_v6=no)])
+          ], gcry_cv_cc_arm_arch_is_v6=yes, gcry_cv_cc_arm_arch_is_v6=no)
+        fi])
 if test "$gcry_cv_cc_arm_arch_is_v6" = "yes" ; then
    AC_DEFINE(HAVE_ARM_ARCH_V6,1,
      [Defined if ARM architecture is v6 or newer])
@@ -1207,8 +1329,11 @@ fi
 #
 AC_CACHE_CHECK([whether GCC inline assembler supports NEON instructions],
        [gcry_cv_gcc_inline_asm_neon],
-       [gcry_cv_gcc_inline_asm_neon=no
-        AC_COMPILE_IFELSE([AC_LANG_SOURCE(
+       [if test "$mpi_cpu_arch" != "arm" ; then
+          gcry_cv_gcc_inline_asm_neon="n/a"
+        else
+          gcry_cv_gcc_inline_asm_neon=no
+          AC_COMPILE_IFELSE([AC_LANG_SOURCE(
           [[__asm__(
                 ".syntax unified\n\t"
                 ".thumb\n\t"
@@ -1219,40 +1344,14 @@ AC_CACHE_CHECK([whether GCC inline assembler supports NEON instructions],
                 "vadd.s64 %d3, %d2, %d3;\n\t"
                 );
             ]])],
-          [gcry_cv_gcc_inline_asm_neon=yes])])
+          [gcry_cv_gcc_inline_asm_neon=yes])
+        fi])
 if test "$gcry_cv_gcc_inline_asm_neon" = "yes" ; then
    AC_DEFINE(HAVE_GCC_INLINE_ASM_NEON,1,
      [Defined if inline assembler supports NEON instructions])
 fi
 
 
-#
-# Check whether GCC assembler supports features needed for our ARM
-# implementations
-#
-AC_CACHE_CHECK([whether GCC assembler is compatible for ARM assembly implementations],
-       [gcry_cv_gcc_arm_platform_as_ok],
-       [gcry_cv_gcc_arm_platform_as_ok=no
-        AC_COMPILE_IFELSE([AC_LANG_SOURCE(
-          [[__asm__(
-                /* Test if assembler supports UAL syntax.  */
-                ".syntax unified\n\t"
-                ".arm\n\t" /* our assembly code is in ARM mode  */
-                /* Following causes error if assembler ignored '.syntax unified'.  */
-                "asmfunc:\n\t"
-                "add %r0, %r0, %r4, ror #12;\n\t"
-
-                /* Test if '.type' and '.size' are supported.  */
-                ".size asmfunc,.-asmfunc;\n\t"
-                ".type asmfunc,%function;\n\t"
-            );]])],
-          [gcry_cv_gcc_arm_platform_as_ok=yes])])
-if test "$gcry_cv_gcc_arm_platform_as_ok" = "yes" ; then
-   AC_DEFINE(HAVE_COMPATIBLE_GCC_ARM_PLATFORM_AS,1,
-     [Defined if underlying assembler is compatible with ARM assembly implementations])
-fi
-
-
 #######################################
 #### Checks for library functions. ####
 #######################################
@@ -1368,48 +1467,8 @@ fi
 
 
 #
-# Setup assembler stuff.
-#
-# Note that config.links also defines mpi_cpu_arch, which is required
-# later on.
+# Other defines
 #
-GNUPG_SYS_SYMBOL_UNDERSCORE()
-AC_ARG_ENABLE(mpi-path,
-              AC_HELP_STRING([--enable-mpi-path=EXTRA_PATH],
-	      [prepend EXTRA_PATH to list of CPU specific optimizations]),
-	      mpi_extra_path="$enableval",mpi_extra_path="")
-AC_MSG_CHECKING(for mpi assembler functions)
-if test -f $srcdir/mpi/config.links ; then
-    . $srcdir/mpi/config.links
-    AC_CONFIG_LINKS("$mpi_ln_list")
-    ac_cv_mpi_sflags="$mpi_sflags"
-    AC_MSG_RESULT(done)
-else
-    AC_MSG_RESULT(failed)
-    AC_MSG_ERROR([mpi/config.links missing!])
-fi
-MPI_SFLAGS="$ac_cv_mpi_sflags"
-AC_SUBST(MPI_SFLAGS)
-
-AM_CONDITIONAL(MPI_MOD_ASM_MPIH_ADD1, test "$mpi_mod_asm_mpih_add1" = yes)
-AM_CONDITIONAL(MPI_MOD_ASM_MPIH_SUB1, test "$mpi_mod_asm_mpih_sub1" = yes)
-AM_CONDITIONAL(MPI_MOD_ASM_MPIH_MUL1, test "$mpi_mod_asm_mpih_mul1" = yes)
-AM_CONDITIONAL(MPI_MOD_ASM_MPIH_MUL2, test "$mpi_mod_asm_mpih_mul2" = yes)
-AM_CONDITIONAL(MPI_MOD_ASM_MPIH_MUL3, test "$mpi_mod_asm_mpih_mul3" = yes)
-AM_CONDITIONAL(MPI_MOD_ASM_MPIH_LSHIFT, test "$mpi_mod_asm_mpih_lshift" = yes)
-AM_CONDITIONAL(MPI_MOD_ASM_MPIH_RSHIFT, test "$mpi_mod_asm_mpih_rshift" = yes)
-AM_CONDITIONAL(MPI_MOD_ASM_UDIV, test "$mpi_mod_asm_udiv" = yes)
-AM_CONDITIONAL(MPI_MOD_ASM_UDIV_QRNND, test "$mpi_mod_asm_udiv_qrnnd" = yes)
-AM_CONDITIONAL(MPI_MOD_C_MPIH_ADD1, test "$mpi_mod_c_mpih_add1" = yes)
-AM_CONDITIONAL(MPI_MOD_C_MPIH_SUB1, test "$mpi_mod_c_mpih_sub1" = yes)
-AM_CONDITIONAL(MPI_MOD_C_MPIH_MUL1, test "$mpi_mod_c_mpih_mul1" = yes)
-AM_CONDITIONAL(MPI_MOD_C_MPIH_MUL2, test "$mpi_mod_c_mpih_mul2" = yes)
-AM_CONDITIONAL(MPI_MOD_C_MPIH_MUL3, test "$mpi_mod_c_mpih_mul3" = yes)
-AM_CONDITIONAL(MPI_MOD_C_MPIH_LSHIFT, test "$mpi_mod_c_mpih_lshift" = yes)
-AM_CONDITIONAL(MPI_MOD_C_MPIH_RSHIFT, test "$mpi_mod_c_mpih_rshift" = yes)
-AM_CONDITIONAL(MPI_MOD_C_UDIV, test "$mpi_mod_c_udiv" = yes)
-AM_CONDITIONAL(MPI_MOD_C_UDIV_QRNND, test "$mpi_mod_c_udiv_qrnnd" = yes)
-
 if test mym4_isgit = "yes"; then
     AC_DEFINE(IS_DEVELOPMENT_VERSION,1,
               [Defined if this is not a regular release])
@@ -1538,6 +1597,14 @@ if test x"$neonsupport" = xyes ; then
   AC_DEFINE(ENABLE_NEON_SUPPORT,1,
             [Enable support for ARM NEON instructions.])
 fi
+if test x"$padlocksupport" = xyes ; then
+  AC_DEFINE(ENABLE_PADLOCK_SUPPORT, 1,
+            [Enable support for the PadLock engine.])
+fi
+if test x"$drngsupport" = xyes ; then
+  AC_DEFINE(ENABLE_DRNG_SUPPORT, 1,
+            [Enable support for Intel DRNG (RDRAND instruction).])
+fi
 
 
 # Define conditional sources and config.h symbols depending on the
diff --git a/mpi/config.links b/mpi/config.links
index a79b03b..57e6c2a 100644
--- a/mpi/config.links
+++ b/mpi/config.links
@@ -21,6 +21,10 @@
 # sourced by ../configure to get the list of files to link
 # this should set $mpi_ln_list.
 # Note: this is called from the above directory.
+#
+# Reguired variables:
+#  $ac_cv_sys_symbol_underscore
+#  $gcry_cv_gcc_arm_platform_as_ok
 
 mpi_sflags=
 mpi_extra_modules=
@@ -39,7 +43,6 @@ mpi_optional_modules=`$AWK '/^#BEGIN_ASM_LIST/,/^#END_ASM_LIST/ {
 echo '/* created by config.links - do not edit */' >./mpi/asm-syntax.h
 echo "/* Host: ${host} */" >>./mpi/asm-syntax.h
 
-if test "$try_asm_modules" = "yes" ; then
 case "${host}" in
     powerpc-apple-darwin*          | \
     i[34567]86*-*-openbsd[12]*     | \
@@ -142,10 +145,10 @@ case "${host}" in
 	mpi_cpu_arch="aarch64"
 	;;
     arm*-*-*)
+	mpi_cpu_arch="arm"
 	if test "$gcry_cv_gcc_arm_platform_as_ok" = "yes" ; then
 	  echo '/* configured for arm */' >>./mpi/asm-syntax.h
 	  path="arm"
-	  mpi_cpu_arch="arm"
 	else
 	  echo '/* No assembler modules configured */' >>./mpi/asm-syntax.h
 	  path=""
@@ -155,16 +158,19 @@ case "${host}" in
 	echo '/* configured for HPPA (pa7000) */' >>./mpi/asm-syntax.h
 	path="hppa1.1 hppa"
 	mpi_extra_modules="udiv-qrnnd"
+	mpi_cpu_arch="hppa"
 	;;
     hppa1.0*-*-*)
 	echo '/* configured for HPPA 1.0 */' >>./mpi/asm-syntax.h
 	path="hppa"
 	mpi_extra_modules="udiv-qrnnd"
+	mpi_cpu_arch="hppa"
 	;;
     hppa*-*-*)	# assume pa7100
 	echo '/* configured for HPPA (pa7100) */' >>./mpi/asm-syntax.h
 	path="pa7100 hppa1.1 hppa"
 	mpi_extra_modules="udiv-qrnnd"
+	mpi_cpu_arch="hppa"
 	;;
     sparc64-*-linux-gnu)
         echo '/* No working assembler modules available */' >>./mpi/asm-syntax.h
@@ -300,6 +306,7 @@ case "${host}" in
 	mpi_sflags="-Wa,-mpwr"
 	path="power"
 	mpi_extra_modules="udiv-w-sdiv"
+	mpi_cpu_arch="ppc"
 	;;
     rs6000-*-* | \
     power-*-*  | \
@@ -333,13 +340,23 @@ case "${host}" in
         mpi_cpu_arch="ppc"
 	;;
     *)
-	echo '/* No assembler modules configured */' >>./mpi/asm-syntax.h
+	echo '/* Platform not known */' >>./mpi/asm-syntax.h
 	path=""
 	;;
 esac
-else
-    echo '/* Assembler modules disabled on request */' >>./mpi/asm-syntax.h
+
+# If asm modules are disabled reset the found variables but keep
+# mpi_cpu_arch.
+if test "$try_asm_modules" != "yes" ; then
+    echo '/* Assembler modules disabled on request */' >./mpi/asm-syntax.h
     path=""
+    mpi_sflags=""
+    mpi_extra_modules=""
+fi
+
+# Make sure that mpi_cpu_arch is not the empty string.
+if test x"$mpi_cpu_arch" = x ; then
+    mpi_cpu_arch="unknown"
 fi
 
 

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

Summary of changes:
 cipher/rmd160.c   |    2 +-
 configure.ac      |  281 ++++++++++++++++++++------------
 m4/gpg-error.m4   |   38 +++--
 mpi/config.links  |   27 +++-
 src/global.c      |   50 +++++-
 tests/Makefile.am |   12 +-
 tests/basic.c     |   12 +-
 tests/t-common.h  |   99 ++++++++++++
 tests/t-lock.c    |  460 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 847 insertions(+), 134 deletions(-)
 create mode 100644 tests/t-common.h
 create mode 100644 tests/t-lock.c


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