aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sha256.h
diff options
context:
space:
mode:
authorPaul Eggert2013-12-08 00:05:36 -0800
committerPaul Eggert2013-12-08 00:05:36 -0800
commite9551b12f8c17876a32e1cd075c83af3e7950980 (patch)
treea1130605fdba681c9118c71f5edd4ee2b9ef4c51 /lib/sha256.h
parent02033d491fa708e28bb3568ff85dab4d0ceb076b (diff)
downloademacs-e9551b12f8c17876a32e1cd075c83af3e7950980.tar.gz
emacs-e9551b12f8c17876a32e1cd075c83af3e7950980.zip
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/sha256.h')
-rw-r--r--lib/sha256.h30
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/sha256.h b/lib/sha256.h
index 7e6252285bb..6ee326b0466 100644
--- a/lib/sha256.h
+++ b/lib/sha256.h
@@ -21,10 +21,23 @@
21# include <stdio.h> 21# include <stdio.h>
22# include <stdint.h> 22# include <stdint.h>
23 23
24# if HAVE_OPENSSL_SHA256
25# include <openssl/sha.h>
26# endif
27
24# ifdef __cplusplus 28# ifdef __cplusplus
25extern "C" { 29extern "C" {
26# endif 30# endif
27 31
32enum { SHA224_DIGEST_SIZE = 224 / 8 };
33enum { SHA256_DIGEST_SIZE = 256 / 8 };
34
35# if HAVE_OPENSSL_SHA256
36# define GL_OPENSSL_NAME 224
37# include "gl_openssl.h"
38# define GL_OPENSSL_NAME 256
39# include "gl_openssl.h"
40# else
28/* Structure to save state of computation between the single steps. */ 41/* Structure to save state of computation between the single steps. */
29struct sha256_ctx 42struct sha256_ctx
30{ 43{
@@ -35,9 +48,6 @@ struct sha256_ctx
35 uint32_t buffer[32]; 48 uint32_t buffer[32];
36}; 49};
37 50
38enum { SHA224_DIGEST_SIZE = 224 / 8 };
39enum { SHA256_DIGEST_SIZE = 256 / 8 };
40
41/* Initialize structure containing state of computation. */ 51/* Initialize structure containing state of computation. */
42extern void sha256_init_ctx (struct sha256_ctx *ctx); 52extern void sha256_init_ctx (struct sha256_ctx *ctx);
43extern void sha224_init_ctx (struct sha256_ctx *ctx); 53extern void sha224_init_ctx (struct sha256_ctx *ctx);
@@ -71,12 +81,6 @@ extern void *sha256_read_ctx (const struct sha256_ctx *ctx, void *resbuf);
71extern void *sha224_read_ctx (const struct sha256_ctx *ctx, void *resbuf); 81extern void *sha224_read_ctx (const struct sha256_ctx *ctx, void *resbuf);
72 82
73 83
74/* Compute SHA256 (SHA224) message digest for bytes read from STREAM. The
75 resulting message digest number will be written into the 32 (28) bytes
76 beginning at RESBLOCK. */
77extern int sha256_stream (FILE *stream, void *resblock);
78extern int sha224_stream (FILE *stream, void *resblock);
79
80/* Compute SHA256 (SHA224) message digest for LEN bytes beginning at BUFFER. The 84/* Compute SHA256 (SHA224) message digest for LEN bytes beginning at BUFFER. The
81 result is always in little endian byte order, so that a byte-wise 85 result is always in little endian byte order, so that a byte-wise
82 output yields to the wanted ASCII representation of the message 86 output yields to the wanted ASCII representation of the message
@@ -84,6 +88,14 @@ extern int sha224_stream (FILE *stream, void *resblock);
84extern void *sha256_buffer (const char *buffer, size_t len, void *resblock); 88extern void *sha256_buffer (const char *buffer, size_t len, void *resblock);
85extern void *sha224_buffer (const char *buffer, size_t len, void *resblock); 89extern void *sha224_buffer (const char *buffer, size_t len, void *resblock);
86 90
91# endif
92/* Compute SHA256 (SHA224) message digest for bytes read from STREAM. The
93 resulting message digest number will be written into the 32 (28) bytes
94 beginning at RESBLOCK. */
95extern int sha256_stream (FILE *stream, void *resblock);
96extern int sha224_stream (FILE *stream, void *resblock);
97
98
87# ifdef __cplusplus 99# ifdef __cplusplus
88} 100}
89# endif 101# endif