From 1fc5fd0e14031393be1f777541846d50d9e12363 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 15 Nov 2006 00:15:38 +0000 Subject: [PATCH] inherited 64bit bug curses to unsigned long git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3374 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- libs/libdingaling/.update | 2 +- libs/libdingaling/src/libdingaling.c | 9 ++++---- libs/libdingaling/src/sha1.c | 12 +++++----- libs/libdingaling/src/sha1.h | 33 ++++++++++++++++++++++++---- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/libs/libdingaling/.update b/libs/libdingaling/.update index 0cb694f1e7..80d100818f 100644 --- a/libs/libdingaling/.update +++ b/libs/libdingaling/.update @@ -1 +1 @@ -Tue Oct 24 13:51:01 CDT 2006 +Tue Nov 14 19:14:29 EST 2006 diff --git a/libs/libdingaling/src/libdingaling.c b/libs/libdingaling/src/libdingaling.c index 3d96b36950..42a5b01f5e 100644 --- a/libs/libdingaling/src/libdingaling.c +++ b/libs/libdingaling/src/libdingaling.c @@ -973,7 +973,7 @@ static void sha1_hash(char *out, char *in) sha_context_t sha; char *p; int x; - unsigned char digest[20]; + unsigned char digest[20] = ""; SHA1Init(&sha); @@ -995,9 +995,10 @@ static int on_stream_component(ldl_handle_t *handle, int type, iks *node) switch (type) { case IKS_NODE_START: if (handle->state == CS_NEW) { - char secret[256]; - char hash[256]; - char handshake[512]; + char secret[256] = ""; + char hash[256] = ""; + char handshake[512] = ""; + snprintf(secret, sizeof(secret), "%s%s", pak->id, handle->password); sha1_hash(hash, secret); snprintf(handshake, sizeof(handshake), "%s", hash); diff --git a/libs/libdingaling/src/sha1.c b/libs/libdingaling/src/sha1.c index 91cd4afecd..f7aa534538 100644 --- a/libs/libdingaling/src/sha1.c +++ b/libs/libdingaling/src/sha1.c @@ -92,12 +92,12 @@ A million repetitions of "a" /* Hash a single 512-bit block. This is the core of the algorithm. */ -void SHA1Transform(unsigned long state[5], unsigned char buffer[64]) +void SHA1Transform(uint32_t state[5], unsigned char buffer[64]) { -unsigned long a, b, c, d, e; +uint32_t a, b, c, d, e; typedef union { unsigned char c[64]; - unsigned long l[16]; + uint32_t l[16]; } CHAR64LONG16; CHAR64LONG16* block; #ifdef SHA1HANDSOFF @@ -161,9 +161,9 @@ void SHA1Init(sha_context_t* context) /* Run your data through this. */ -void SHA1Update(sha_context_t* context, unsigned char* data, unsigned int len) +void SHA1Update(sha_context_t* context, unsigned char* data, uint32_t len) { -unsigned int i, j; +uint32_t i, j; j = (context->count[0] >> 3) & 63; if ((context->count[0] += len << 3) < (len << 3)) context->count[1]++; @@ -185,7 +185,7 @@ unsigned int i, j; void SHA1Final(unsigned char digest[20], sha_context_t* context) { -unsigned long i, j; +uint32_t i, j; unsigned char finalcount[8]; for (i = 0; i < 8; i++) { diff --git a/libs/libdingaling/src/sha1.h b/libs/libdingaling/src/sha1.h index 4376808145..b32c3ffe92 100644 --- a/libs/libdingaling/src/sha1.h +++ b/libs/libdingaling/src/sha1.h @@ -41,15 +41,40 @@ extern "C" { } #endif +#undef inline +#define inline __inline + +#ifndef uint32_t +#ifdef WIN32 +typedef unsigned __int8 uint8_t; +typedef unsigned __int16 uint16_t; +typedef unsigned __int32 uint32_t; +typedef unsigned __int64 uint64_t; +typedef __int8 int8_t; +typedef __int16 int16_t; +typedef __int32 int32_t; +typedef __int64 int64_t; +typedef unsigned long in_addr_t; +#else +#include +#include +#include +#include +#include +#include +#include +#endif +#endif + typedef struct { - unsigned long state[5]; - unsigned long count[2]; + uint32_t state[5]; + uint32_t count[2]; unsigned char buffer[64]; } sha_context_t; -void SHA1Transform(unsigned long state[5], unsigned char buffer[64]); +void SHA1Transform(uint32_t state[5], unsigned char buffer[64]); void SHA1Init(sha_context_t* context); -void SHA1Update(sha_context_t* context, unsigned char* data, unsigned int len); +void SHA1Update(sha_context_t* context, unsigned char* data, uint32_t len); void SHA1Final(unsigned char digest[20], sha_context_t* context); #ifdef __cplusplus