summaryrefslogtreecommitdiff
path: root/lib/sha512.h
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2013-12-08 00:05:36 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2013-12-08 00:05:36 -0800
commite9551b12f8c17876a32e1cd075c83af3e7950980 (patch)
treea1130605fdba681c9118c71f5edd4ee2b9ef4c51 /lib/sha512.h
parent02033d491fa708e28bb3568ff85dab4d0ceb076b (diff)
downloademacs-e9551b12f8c17876a32e1cd075c83af3e7950980.tar.gz
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 'lib/sha512.h')
-rw-r--r--lib/sha512.h31
1 files changed, 21 insertions, 10 deletions
diff --git a/lib/sha512.h b/lib/sha512.h
index 2e78a5f9404..1de93da2f8a 100644
--- a/lib/sha512.h
+++ b/lib/sha512.h
@@ -19,13 +19,25 @@
# define SHA512_H 1
# include <stdio.h>
-
# include "u64.h"
+# if HAVE_OPENSSL_SHA512
+# include <openssl/sha.h>
+# endif
+
# ifdef __cplusplus
extern "C" {
# endif
+enum { SHA384_DIGEST_SIZE = 384 / 8 };
+enum { SHA512_DIGEST_SIZE = 512 / 8 };
+
+# if HAVE_OPENSSL_SHA512
+# define GL_OPENSSL_NAME 384
+# include "gl_openssl.h"
+# define GL_OPENSSL_NAME 512
+# include "gl_openssl.h"
+# else
/* Structure to save state of computation between the single steps. */
struct sha512_ctx
{
@@ -36,9 +48,6 @@ struct sha512_ctx
u64 buffer[32];
};
-enum { SHA384_DIGEST_SIZE = 384 / 8 };
-enum { SHA512_DIGEST_SIZE = 512 / 8 };
-
/* Initialize structure containing state of computation. */
extern void sha512_init_ctx (struct sha512_ctx *ctx);
extern void sha384_init_ctx (struct sha512_ctx *ctx);
@@ -75,12 +84,6 @@ extern void *sha512_read_ctx (const struct sha512_ctx *ctx, void *resbuf);
extern void *sha384_read_ctx (const struct sha512_ctx *ctx, void *resbuf);
-/* Compute SHA512 (SHA384) message digest for bytes read from STREAM. The
- resulting message digest number will be written into the 64 (48) bytes
- beginning at RESBLOCK. */
-extern int sha512_stream (FILE *stream, void *resblock);
-extern int sha384_stream (FILE *stream, void *resblock);
-
/* Compute SHA512 (SHA384) message digest for LEN bytes beginning at BUFFER. The
result is always in little endian byte order, so that a byte-wise
output yields to the wanted ASCII representation of the message
@@ -88,6 +91,14 @@ extern int sha384_stream (FILE *stream, void *resblock);
extern void *sha512_buffer (const char *buffer, size_t len, void *resblock);
extern void *sha384_buffer (const char *buffer, size_t len, void *resblock);
+# endif
+/* Compute SHA512 (SHA384) message digest for bytes read from STREAM. The
+ resulting message digest number will be written into the 64 (48) bytes
+ beginning at RESBLOCK. */
+extern int sha512_stream (FILE *stream, void *resblock);
+extern int sha384_stream (FILE *stream, void *resblock);
+
+
# ifdef __cplusplus
}
# endif