diff options
| author | Paul Eggert | 2013-12-08 00:05:36 -0800 |
|---|---|---|
| committer | Paul Eggert | 2013-12-08 00:05:36 -0800 |
| commit | e9551b12f8c17876a32e1cd075c83af3e7950980 (patch) | |
| tree | a1130605fdba681c9118c71f5edd4ee2b9ef4c51 /lib/sha256.h | |
| parent | 02033d491fa708e28bb3568ff85dab4d0ceb076b (diff) | |
| download | emacs-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.h | 30 |
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 |
| 25 | extern "C" { | 29 | extern "C" { |
| 26 | # endif | 30 | # endif |
| 27 | 31 | ||
| 32 | enum { SHA224_DIGEST_SIZE = 224 / 8 }; | ||
| 33 | enum { 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. */ |
| 29 | struct sha256_ctx | 42 | struct 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 | ||
| 38 | enum { SHA224_DIGEST_SIZE = 224 / 8 }; | ||
| 39 | enum { SHA256_DIGEST_SIZE = 256 / 8 }; | ||
| 40 | |||
| 41 | /* Initialize structure containing state of computation. */ | 51 | /* Initialize structure containing state of computation. */ |
| 42 | extern void sha256_init_ctx (struct sha256_ctx *ctx); | 52 | extern void sha256_init_ctx (struct sha256_ctx *ctx); |
| 43 | extern void sha224_init_ctx (struct sha256_ctx *ctx); | 53 | extern void sha224_init_ctx (struct sha256_ctx *ctx); |
| @@ -71,12 +81,6 @@ extern void *sha256_read_ctx (const struct sha256_ctx *ctx, void *resbuf); | |||
| 71 | extern void *sha224_read_ctx (const struct sha256_ctx *ctx, void *resbuf); | 81 | extern 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. */ | ||
| 77 | extern int sha256_stream (FILE *stream, void *resblock); | ||
| 78 | extern 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); | |||
| 84 | extern void *sha256_buffer (const char *buffer, size_t len, void *resblock); | 88 | extern void *sha256_buffer (const char *buffer, size_t len, void *resblock); |
| 85 | extern void *sha224_buffer (const char *buffer, size_t len, void *resblock); | 89 | extern 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. */ | ||
| 95 | extern int sha256_stream (FILE *stream, void *resblock); | ||
| 96 | extern int sha224_stream (FILE *stream, void *resblock); | ||
| 97 | |||
| 98 | |||
| 87 | # ifdef __cplusplus | 99 | # ifdef __cplusplus |
| 88 | } | 100 | } |
| 89 | # endif | 101 | # endif |