comparison lib/sha256.h @ 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
19 # define SHA256_H 1 19 # define SHA256_H 1
20 20
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 {
31 uint32_t state[8]; 44 uint32_t state[8];
32 45
33 uint32_t total[2]; 46 uint32_t total[2];
34 size_t buflen; 47 size_t buflen;
35 uint32_t buffer[32]; 48 uint32_t buffer[32];
36 }; 49 };
37
38 enum { SHA224_DIGEST_SIZE = 224 / 8 };
39 enum { SHA256_DIGEST_SIZE = 256 / 8 };
40 50
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);
44 54
69 to the wanted ASCII representation of the message digest. */ 79 to the wanted ASCII representation of the message digest. */
70 extern void *sha256_read_ctx (const struct sha256_ctx *ctx, void *resbuf); 80 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
83 digest. */ 87 digest. */
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
90 102
91 #endif 103 #endif