diff options
author | Paul Eggert <[email protected]> | 2013-12-08 00:05:36 -0800 |
---|---|---|
committer | Paul Eggert <[email protected]> | 2013-12-08 00:05:36 -0800 |
commit | e9551b12f8c17876a32e1cd075c83af3e7950980 (patch) | |
tree | a1130605fdba681c9118c71f5edd4ee2b9ef4c51 /m4 | |
parent | 02033d491fa708e28bb3568ff85dab4d0ceb076b (diff) |
Use libcrypto's checksum implementations if available, for speed.
On commonly used platform libcrypto uses architecture-specific
assembly code, which is significantly faster than the C code we
were using. See Pádraig Brady's note in
<http://lists.gnu.org/archive/html/bug-gnulib/2013-12/msg00000.html>.
Merge from gnulib, incorporating:
2013-12-07 md5, sha1, sha256, sha512: add gl_SET_CRYPTO_CHECK_DEFAULT
2013-12-07 md5, sha1, sha256, sha512: add 'auto', and set-default method
2013-12-04 include_next: minimize code duplication
2013-12-03 md5, sha1, sha256, sha512: support mandating use of openssl
2013-12-02 md5, sha1, sha256, sha512: use openssl routines if available
* configure.ac (--without-all): Set with_openssl_default too.
Use gl_SET_CRYPTO_CHECK_DEFAULT to default to 'auto'.
(HAVE_LIB_CRYPTO): New var.
Say whether Emacs is configured to use a crypto library.
* lib/gl_openssl.h, m4/absolute-header.m4, m4/gl-openssl.m4:
New files, copied from gnulib.
* lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate.
* lib/md5.c, lib/md5.h, lib/sha1.c, lib/sha1.h:
* lib/sha256.c, lib/sha256.h, lib/sha512.c, lib/sha512.h:
* m4/include_next.m4, m4/md5.m4, m4/sha1.m4, m4/sha256.m4, m4/sha512.m4:
Update from gnulib.
* src/Makefile.in (LIB_CRYPTO): New macro.
(LIBES): Use it.
Diffstat (limited to 'm4')
-rw-r--r-- | m4/absolute-header.m4 | 102 | ||||
-rw-r--r-- | m4/gl-openssl.m4 | 48 | ||||
-rw-r--r-- | m4/gnulib-comp.m4 | 4 | ||||
-rw-r--r-- | m4/include_next.m4 | 53 | ||||
-rw-r--r-- | m4/md5.m4 | 6 | ||||
-rw-r--r-- | m4/sha1.m4 | 6 | ||||
-rw-r--r-- | m4/sha256.m4 | 6 | ||||
-rw-r--r-- | m4/sha512.m4 | 6 |
8 files changed, 173 insertions, 58 deletions
diff --git a/m4/absolute-header.m4 b/m4/absolute-header.m4 new file mode 100644 index 0000000000..89ff5beb65 --- /dev/null +++ b/m4/absolute-header.m4 @@ -0,0 +1,102 @@ +# absolute-header.m4 serial 16 +dnl Copyright (C) 2006-2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Derek Price. + +# gl_ABSOLUTE_HEADER(HEADER1 HEADER2 ...) +# --------------------------------------- +# Find the absolute name of a header file, testing first if the header exists. +# If the header were sys/inttypes.h, this macro would define +# ABSOLUTE_SYS_INTTYPES_H to the '""' quoted absolute name of sys/inttypes.h +# in config.h +# (e.g. '#define ABSOLUTE_SYS_INTTYPES_H "///usr/include/sys/inttypes.h"'). +# The three "///" are to pacify Sun C 5.8, which otherwise would say +# "warning: #include of /usr/include/... may be non-portable". +# Use '""', not '<>', so that the /// cannot be confused with a C99 comment. +# Note: This macro assumes that the header file is not empty after +# preprocessing, i.e. it does not only define preprocessor macros but also +# provides some type/enum definitions or function/variable declarations. +AC_DEFUN([gl_ABSOLUTE_HEADER], +[AC_REQUIRE([AC_CANONICAL_HOST]) +AC_LANG_PREPROC_REQUIRE()dnl +dnl FIXME: gl_absolute_header and ac_header_exists must be used unquoted +dnl until we can assume autoconf 2.64 or newer. +m4_foreach_w([gl_HEADER_NAME], [$1], + [AS_VAR_PUSHDEF([gl_absolute_header], + [gl_cv_absolute_]m4_defn([gl_HEADER_NAME]))dnl + AC_CACHE_CHECK([absolute name of <]m4_defn([gl_HEADER_NAME])[>], + m4_defn([gl_absolute_header]), + [AS_VAR_PUSHDEF([ac_header_exists], + [ac_cv_header_]m4_defn([gl_HEADER_NAME]))dnl + AC_CHECK_HEADERS_ONCE(m4_defn([gl_HEADER_NAME]))dnl + if test AS_VAR_GET(ac_header_exists) = yes; then + gl_ABSOLUTE_HEADER_ONE(m4_defn([gl_HEADER_NAME])) + fi + AS_VAR_POPDEF([ac_header_exists])dnl + ])dnl + AC_DEFINE_UNQUOTED(AS_TR_CPP([ABSOLUTE_]m4_defn([gl_HEADER_NAME])), + ["AS_VAR_GET(gl_absolute_header)"], + [Define this to an absolute name of <]m4_defn([gl_HEADER_NAME])[>.]) + AS_VAR_POPDEF([gl_absolute_header])dnl +])dnl +])# gl_ABSOLUTE_HEADER + +# gl_ABSOLUTE_HEADER_ONE(HEADER) +# ------------------------------ +# Like gl_ABSOLUTE_HEADER, except that: +# - it assumes that the header exists, +# - it uses the current CPPFLAGS, +# - it does not cache the result, +# - it is silent. +AC_DEFUN([gl_ABSOLUTE_HEADER_ONE], +[ + AC_REQUIRE([AC_CANONICAL_HOST]) + AC_LANG_CONFTEST([AC_LANG_SOURCE([[#include <]]m4_dquote([$1])[[>]])]) + dnl AIX "xlc -E" and "cc -E" omit #line directives for header files + dnl that contain only a #include of other header files and no + dnl non-comment tokens of their own. This leads to a failure to + dnl detect the absolute name of <dirent.h>, <signal.h>, <poll.h> + dnl and others. The workaround is to force preservation of comments + dnl through option -C. This ensures all necessary #line directives + dnl are present. GCC supports option -C as well. + case "$host_os" in + aix*) gl_absname_cpp="$ac_cpp -C" ;; + *) gl_absname_cpp="$ac_cpp" ;; + esac +changequote(,) + case "$host_os" in + mingw*) + dnl For the sake of native Windows compilers (excluding gcc), + dnl treat backslash as a directory separator, like /. + dnl Actually, these compilers use a double-backslash as + dnl directory separator, inside the + dnl # line "filename" + dnl directives. + gl_dirsep_regex='[/\\]' + ;; + *) + gl_dirsep_regex='\/' + ;; + esac + dnl A sed expression that turns a string into a basic regular + dnl expression, for use within "/.../". + gl_make_literal_regex_sed='s,[]$^\\.*/[],\\&,g' + gl_header_literal_regex=`echo '$1' \ + | sed -e "$gl_make_literal_regex_sed"` + gl_absolute_header_sed="/${gl_dirsep_regex}${gl_header_literal_regex}/"'{ + s/.*"\(.*'"${gl_dirsep_regex}${gl_header_literal_regex}"'\)".*/\1/ + s|^/[^/]|//&| + p + q + }' +changequote([,]) + dnl eval is necessary to expand gl_absname_cpp. + dnl Ultrix and Pyramid sh refuse to redirect output of eval, + dnl so use subshell. + AS_VAR_SET([gl_cv_absolute_]AS_TR_SH([[$1]]), +[`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD | + sed -n "$gl_absolute_header_sed"`]) +]) diff --git a/m4/gl-openssl.m4 b/m4/gl-openssl.m4 new file mode 100644 index 0000000000..c8f9dd95e6 --- /dev/null +++ b/m4/gl-openssl.m4 @@ -0,0 +1,48 @@ +# gl-openssl.m4 serial 3 +dnl Copyright (C) 2013 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_SET_CRYPTO_CHECK_DEFAULT], +[ + m4_define([gl_CRYPTO_CHECK_DEFAULT], [$1]) +]) +gl_SET_CRYPTO_CHECK_DEFAULT([no]) + +AC_DEFUN([gl_CRYPTO_CHECK], +[ + m4_divert_once([DEFAULTS], [with_openssl_default='gl_CRYPTO_CHECK_DEFAULT']) + + AC_ARG_WITH([openssl], + [AS_HELP_STRING([--with-openssl], + [use libcrypto hash routines. Valid ARGs are: + 'yes', 'no', 'auto' => use if available, + 'optional' => use if available and warn if not available; + default is ']gl_CRYPTO_CHECK_DEFAULT['])], + [], + [with_openssl=$with_openssl_default]) + + if test "x$1" = xMD5; then + ALG_header=md5.h + else + ALG_header=sha.h + fi + + LIB_CRYPTO= + AC_SUBST([LIB_CRYPTO]) + if test "x$with_openssl" != xno; then + AC_CHECK_LIB([crypto], [$1], + [AC_CHECK_HEADERS([openssl/$ALG_header], + [LIB_CRYPTO=-lcrypto + AC_DEFINE([HAVE_OPENSSL_$1], [1], + [Define to 1 if libcrypto is used for $1.])])]) + if test "x$LIB_CRYPTO" = x; then + if test "x$with_openssl" = xyes; then + AC_MSG_ERROR([openssl development library not found for $1]) + elif test "x$with_openssl" = xoptional; then + AC_MSG_WARN([openssl development library not found for $1]) + fi + fi + fi +]) diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4 index c707e34993..3a04c84ac9 100644 --- a/m4/gnulib-comp.m4 +++ b/m4/gnulib-comp.m4 @@ -38,6 +38,7 @@ AC_DEFUN([gl_EARLY], m4_pattern_allow([^gl_LIBOBJS$])dnl a variable m4_pattern_allow([^gl_LTLIBOBJS$])dnl a variable AC_REQUIRE([gl_PROG_AR_RANLIB]) + # Code from module absolute-header: # Code from module alloca-opt: # Code from module allocator: # Code from module at-internal: @@ -847,6 +848,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/gettext.h lib/gettime.c lib/gettimeofday.c + lib/gl_openssl.h lib/group-member.c lib/intprops.h lib/inttypes.in.h @@ -921,6 +923,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/verify.h lib/xalloc-oversized.h m4/00gnulib.m4 + m4/absolute-header.m4 m4/acl.m4 m4/alloca.m4 m4/byteswap.m4 @@ -953,6 +956,7 @@ AC_DEFUN([gl_FILE_LIST], [ m4/getopt.m4 m4/gettime.m4 m4/gettimeofday.m4 + m4/gl-openssl.m4 m4/gnulib-common.m4 m4/group-member.m4 m4/include_next.m4 diff --git a/m4/include_next.m4 b/m4/include_next.m4 index 108d945677..f09dbe6639 100644 --- a/m4/include_next.m4 +++ b/m4/include_next.m4 @@ -192,56 +192,9 @@ dnl until we can assume autoconf 2.64 or newer. if test AS_VAR_GET(gl_header_exists) = yes; then AS_VAR_POPDEF([gl_header_exists]) ]) - AC_LANG_CONFTEST( - [AC_LANG_SOURCE( - [[#include <]]m4_dquote(m4_defn([gl_HEADER_NAME]))[[>]] - )]) - dnl AIX "xlc -E" and "cc -E" omit #line directives for header - dnl files that contain only a #include of other header files and - dnl no non-comment tokens of their own. This leads to a failure - dnl to detect the absolute name of <dirent.h>, <signal.h>, - dnl <poll.h> and others. The workaround is to force preservation - dnl of comments through option -C. This ensures all necessary - dnl #line directives are present. GCC supports option -C as well. - case "$host_os" in - aix*) gl_absname_cpp="$ac_cpp -C" ;; - *) gl_absname_cpp="$ac_cpp" ;; - esac -changequote(,) - case "$host_os" in - mingw*) - dnl For the sake of native Windows compilers (excluding gcc), - dnl treat backslash as a directory separator, like /. - dnl Actually, these compilers use a double-backslash as - dnl directory separator, inside the - dnl # line "filename" - dnl directives. - gl_dirsep_regex='[/\\]' - ;; - *) - gl_dirsep_regex='\/' - ;; - esac - dnl A sed expression that turns a string into a basic regular - dnl expression, for use within "/.../". - gl_make_literal_regex_sed='s,[]$^\\.*/[],\\&,g' -changequote([,]) - gl_header_literal_regex=`echo ']m4_defn([gl_HEADER_NAME])[' \ - | sed -e "$gl_make_literal_regex_sed"` - gl_absolute_header_sed="/${gl_dirsep_regex}${gl_header_literal_regex}/"'{ - s/.*"\(.*'"${gl_dirsep_regex}${gl_header_literal_regex}"'\)".*/\1/ -changequote(,)dnl - s|^/[^/]|//&| -changequote([,])dnl - p - q - }' - dnl eval is necessary to expand gl_absname_cpp. - dnl Ultrix and Pyramid sh refuse to redirect output of eval, - dnl so use subshell. - AS_VAR_SET(gl_next_header, - ['"'`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD | - sed -n "$gl_absolute_header_sed"`'"']) + gl_ABSOLUTE_HEADER_ONE(gl_HEADER_NAME) + AS_VAR_COPY([gl_header], [gl_cv_absolute_]AS_TR_SH(gl_HEADER_NAME)) + AS_VAR_SET(gl_next_header, ['"'$gl_header'"']) m4_if([$2], [check], [else AS_VAR_SET(gl_next_header, ['<'gl_HEADER_NAME'>']) @@ -1,4 +1,4 @@ -# md5.m4 serial 13 +# md5.m4 serial 14 dnl Copyright (C) 2002-2006, 2008-2013 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -8,5 +8,7 @@ AC_DEFUN([gl_MD5], [ dnl Prerequisites of lib/md5.c. AC_REQUIRE([gl_BIGENDIAN]) - : + + dnl Determine HAVE_OPENSSL_MD5 and LIB_CRYPTO + gl_CRYPTO_CHECK([MD5]) ]) diff --git a/m4/sha1.m4 b/m4/sha1.m4 index 21c775e364..57d5256652 100644 --- a/m4/sha1.m4 +++ b/m4/sha1.m4 @@ -1,4 +1,4 @@ -# sha1.m4 serial 11 +# sha1.m4 serial 12 dnl Copyright (C) 2002-2006, 2008-2013 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -8,5 +8,7 @@ AC_DEFUN([gl_SHA1], [ dnl Prerequisites of lib/sha1.c. AC_REQUIRE([gl_BIGENDIAN]) - : + + dnl Determine HAVE_OPENSSL_SHA1 and LIB_CRYPTO + gl_CRYPTO_CHECK([SHA1]) ]) diff --git a/m4/sha256.m4 b/m4/sha256.m4 index cbbd17a644..3a19467469 100644 --- a/m4/sha256.m4 +++ b/m4/sha256.m4 @@ -1,4 +1,4 @@ -# sha256.m4 serial 7 +# sha256.m4 serial 8 dnl Copyright (C) 2005, 2008-2013 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -8,5 +8,7 @@ AC_DEFUN([gl_SHA256], [ dnl Prerequisites of lib/sha256.c. AC_REQUIRE([gl_BIGENDIAN]) - : + + dnl Determine HAVE_OPENSSL_SHA256 and LIB_CRYPTO + gl_CRYPTO_CHECK([SHA256]) ]) diff --git a/m4/sha512.m4 b/m4/sha512.m4 index f4a6bf13ba..d929195e9a 100644 --- a/m4/sha512.m4 +++ b/m4/sha512.m4 @@ -1,4 +1,4 @@ -# sha512.m4 serial 8 +# sha512.m4 serial 9 dnl Copyright (C) 2005-2006, 2008-2013 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -8,5 +8,7 @@ AC_DEFUN([gl_SHA512], [ dnl Prerequisites of lib/sha512.c. AC_REQUIRE([gl_BIGENDIAN]) - : + + dnl Determine HAVE_OPENSSL_SHA512 and LIB_CRYPTO + gl_CRYPTO_CHECK([SHA512]) ]) |