comparison lib/sha1.c @ 37245:135e82dafbea

md5, sha1, sha256, sha512: use openssl routines if available --with-openssl the libcrypto md5, sha1, sha224, sha256, sha384, sha256 routines will be used if available, requiring apps to link @LIB_CRYPTO@ * lib/gl_openssl.h: Provide wrappers for specified openssl hash. * m4/gl-openssl.m4 (gl_CRYPTO_CHECK): New function to lookup libcrypto in the standard system location. * m4/sha1.m4: Call gl_CRYPTO_CHECK() for SHA1. * m4/sha256.m4: Likewise with SHA256. * m4/sha512.m4: Likewise with SHA512. * m4/md5.m4: Likewise with MD5. * m4/gc.m4: Ensure @LIB_CRYPTO@ set for tests. * lib/sha1.h: Include wrappers if HAVE_OPENSSL_SHA1. * lib/sha256.h: Likewise with SHA256. * lib/sha512.h: Likewise with SHA512. * lib/md5.h: Likewise with MD5. * lib/sha1.c: Exlude functionality if HAVE_OPENSSL_SHA1. * lib/sha256.c: Likewise with SHA256. * lib/sha512.c: Likewise with SHA512. * lib/md5.c: Likewise with MD5. * modules/crypto/sha1 (Link:): Add the new optional lib. (Depends-on:): Add dependency on extern-inline. * modules/crypto/sha256: Likewise. * modules/crypto/sha512: Likewise. * modules/crypto/md5: Likewise. * modules/crypto/sha1-tests: Reference the lib here too. * modules/crypto/md5-tests: Likewise. * modules/crypto/gc-des-tests: Likewise. * modules/crypto/gc-hmac-md5-tests: Likewise. * modules/crypto/gc-hmac-sha1-tests: Likewise. * modules/crypto/gc-hmac-sha256-tests: Likewise. * modules/crypto/gc-hmac-sha512-tests: Likewise. * modules/crypto/gc-md5-tests: Likewise. * modules/crypto/gc-pbkdf2-sha1-tests: Likewise. * modules/crypto/gc-sha1-tests: Likewise. * modules/crypto/gc-tests: Likewise. * modules/crypto/hmac-md5-tests: Likewise. * modules/crypto/hmac-sha1-tests: Likewise. * modules/crypto/hmac-sha256-tests: Likewise. * modules/crypto/hmac-sha512-tests: Likewise.
author Pádraig Brady <P@draigBrady.com>
date Sat, 30 Nov 2013 05:19:32 +0000
parents c741bc27922a
children 344018b6e5d7
comparison
equal deleted inserted replaced
37244:1ded04c3e4bb 37245:135e82dafbea
21 Robert Klep <robert@ilse.nl> -- Expansion function fix 21 Robert Klep <robert@ilse.nl> -- Expansion function fix
22 */ 22 */
23 23
24 #include <config.h> 24 #include <config.h>
25 25
26 #if HAVE_OPENSSL_SHA1
27 # define GL_OPENSSL_INLINE _GL_EXTERN_INLINE
28 #endif
26 #include "sha1.h" 29 #include "sha1.h"
27 30
28 #include <stdalign.h> 31 #include <stdalign.h>
29 #include <stdint.h> 32 #include <stdint.h>
30 #include <stdlib.h> 33 #include <stdlib.h>
44 #define BLOCKSIZE 32768 47 #define BLOCKSIZE 32768
45 #if BLOCKSIZE % 64 != 0 48 #if BLOCKSIZE % 64 != 0
46 # error "invalid BLOCKSIZE" 49 # error "invalid BLOCKSIZE"
47 #endif 50 #endif
48 51
52 #if ! HAVE_OPENSSL_SHA1
49 /* This array contains the bytes used to pad the buffer to the next 53 /* This array contains the bytes used to pad the buffer to the next
50 64-byte boundary. (RFC 1321, 3.1: Step 1) */ 54 64-byte boundary. (RFC 1321, 3.1: Step 1) */
51 static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ }; 55 static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ };
52 56
53 57
114 /* Process last bytes. */ 118 /* Process last bytes. */
115 sha1_process_block (ctx->buffer, size * 4, ctx); 119 sha1_process_block (ctx->buffer, size * 4, ctx);
116 120
117 return sha1_read_ctx (ctx, resbuf); 121 return sha1_read_ctx (ctx, resbuf);
118 } 122 }
123 #endif
119 124
120 /* Compute SHA1 message digest for bytes read from STREAM. The 125 /* Compute SHA1 message digest for bytes read from STREAM. The
121 resulting message digest number will be written into the 16 bytes 126 resulting message digest number will be written into the 16 bytes
122 beginning at RESBLOCK. */ 127 beginning at RESBLOCK. */
123 int 128 int
188 sha1_finish_ctx (&ctx, resblock); 193 sha1_finish_ctx (&ctx, resblock);
189 free (buffer); 194 free (buffer);
190 return 0; 195 return 0;
191 } 196 }
192 197
198 #if ! HAVE_OPENSSL_SHA1
193 /* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The 199 /* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The
194 result is always in little endian byte order, so that a byte-wise 200 result is always in little endian byte order, so that a byte-wise
195 output yields to the wanted ASCII representation of the message 201 output yields to the wanted ASCII representation of the message
196 digest. */ 202 digest. */
197 void * 203 void *
422 c = ctx->C += c; 428 c = ctx->C += c;
423 d = ctx->D += d; 429 d = ctx->D += d;
424 e = ctx->E += e; 430 e = ctx->E += e;
425 } 431 }
426 } 432 }
433 #endif