From: Wouter Wijngaards Date: Fri, 11 Jul 2014 16:35:05 +0000 (+0000) Subject: compat for arc4random with openssl 0.9.7 and openssl 0.9.8 X-Git-Tag: release-1.5.0rc1~86 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed2f8b10578e18e2d555c034cf18ec4ff4165dfe;p=thirdparty%2Funbound.git compat for arc4random with openssl 0.9.7 and openssl 0.9.8 git-svn-id: file:///svn/unbound/trunk@3174 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/compat/getentropy_linux.c b/compat/getentropy_linux.c index 78276b3b8..f4a81e5ea 100644 --- a/compat/getentropy_linux.c +++ b/compat/getentropy_linux.c @@ -16,9 +16,12 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "config.h" +/* #define _POSIX_C_SOURCE 199309L #define _GNU_SOURCE 1 +*/ #include #include #include diff --git a/compat/sha512.c b/compat/sha512.c index e5db1c986..ac046abb7 100644 --- a/compat/sha512.c +++ b/compat/sha512.c @@ -45,6 +45,8 @@ #include /* memcpy()/memset() or bcopy()/bzero() */ #include /* assert() */ +/* do we have sha512 header defs */ +#ifndef SHA512_DIGEST_LENGTH #define SHA512_BLOCK_LENGTH 128 #define SHA512_DIGEST_LENGTH 64 #define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1) @@ -53,11 +55,12 @@ typedef struct _SHA512_CTX { uint64_t bitcount[2]; uint8_t buffer[SHA512_BLOCK_LENGTH]; } SHA512_CTX; +#endif /* do we have sha512 header defs */ -void SHA512_init(SHA512_CTX*); -void SHA512_update(SHA512_CTX*, const uint8_t*, size_t); -void SHA512_final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*); -unsigned char *SHA512(unsigned char *data, unsigned int data_len, unsigned char *digest); +void SHA512_Init(SHA512_CTX*); +void SHA512_Update(SHA512_CTX*, void*, size_t); +void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*); +unsigned char *SHA512(void *data, unsigned int data_len, unsigned char *digest); /*** SHA-256/384/512 Machine Architecture Definitions *****************/ @@ -250,6 +253,11 @@ static const sha2_word64 sha512_initial_hash_value[8] = { 0x5be0cd19137e2179ULL }; +typedef union _ldns_sha2_buffer_union { + uint8_t* theChars; + uint64_t* theLongs; +} ldns_sha2_buffer_union; + /*** SHA-512: *********************************************************/ void SHA512_Init(SHA512_CTX* context) { if (context == (SHA512_CTX*)0) { @@ -337,8 +345,9 @@ static void SHA512_Transform(SHA512_CTX* context, a = b = c = d = e = f = g = h = T1 = T2 = 0; } -void SHA512_Update(SHA512_CTX* context, const sha2_byte *data, size_t len) { +void SHA512_Update(SHA512_CTX* context, void *datain, size_t len) { size_t freespace, usedspace; + const sha2_byte* data = (const sha2_byte*)datain; if (len == 0) { /* Calling with no data is valid - we do nothing */ @@ -458,7 +467,7 @@ void SHA512_Final(sha2_byte digest[], SHA512_CTX* context) { } unsigned char * -SHA512(unsigned char *data, unsigned int data_len, unsigned char *digest) +SHA512(void *data, unsigned int data_len, unsigned char *digest) { SHA512_CTX ctx; SHA512_Init(&ctx); diff --git a/config.h.in b/config.h.in index 570f7db60..486f76448 100644 --- a/config.h.in +++ b/config.h.in @@ -907,6 +907,24 @@ void _ARC4_UNLOCK(void); #ifndef HAVE_ARC4RANDOM_UNIFORM uint32_t arc4random_uniform(uint32_t upper_bound); #endif +#ifndef HAVE_SHA512_UPDATE +#ifndef SHA512_DIGEST_LENGTH +#define SHA512_BLOCK_LENGTH 128 +#define SHA512_DIGEST_LENGTH 64 +#define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1) +typedef struct _SHA512_CTX { + uint64_t state[8]; + uint64_t bitcount[2]; + uint8_t buffer[SHA512_BLOCK_LENGTH]; +} SHA512_CTX; +#endif /* SHA512_DIGEST_LENGTH */ +void SHA512_Init(SHA512_CTX*); +void SHA512_Update(SHA512_CTX*, void*, size_t); +void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*); +unsigned char *SHA512(void* data, unsigned int data_len, unsigned char *digest); +#endif /* HAVE_SHA512_UPDATE */ + + #if defined(HAVE_EVENT_H) && !defined(HAVE_EVENT_BASE_ONCE) && !(defined(HAVE_EV_LOOP) || defined(HAVE_EV_DEFAULT_LOOP)) && (defined(HAVE_PTHREAD) || defined(HAVE_SOLARIS_THREADS)) /* using version of libevent that is not threadsafe. */ diff --git a/configure.ac b/configure.ac index 29b8161a1..c5d83a9aa 100644 --- a/configure.ac +++ b/configure.ac @@ -1213,6 +1213,24 @@ void _ARC4_UNLOCK(void); #ifndef HAVE_ARC4RANDOM_UNIFORM uint32_t arc4random_uniform(uint32_t upper_bound); #endif +#ifndef HAVE_SHA512_UPDATE +#ifndef SHA512_DIGEST_LENGTH +#define SHA512_BLOCK_LENGTH 128 +#define SHA512_DIGEST_LENGTH 64 +#define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1) +typedef struct _SHA512_CTX { + uint64_t state[8]; + uint64_t bitcount[2]; + uint8_t buffer[SHA512_BLOCK_LENGTH]; +} SHA512_CTX; +#endif /* SHA512_DIGEST_LENGTH */ +void SHA512_Init(SHA512_CTX*); +void SHA512_Update(SHA512_CTX*, void*, size_t); +void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*); +unsigned char *SHA512(void* data, unsigned int data_len, unsigned char *digest); +#endif /* HAVE_SHA512_UPDATE */ + + #if defined(HAVE_EVENT_H) && !defined(HAVE_EVENT_BASE_ONCE) && !(defined(HAVE_EV_LOOP) || defined(HAVE_EV_DEFAULT_LOOP)) && (defined(HAVE_PTHREAD) || defined(HAVE_SOLARIS_THREADS)) /* using version of libevent that is not threadsafe. */