Commit 015374be authored by Kyungsun Cho's avatar Kyungsun Cho Committed by Randeep

[IOT-977] Renamed |SHA| symbol names on |tinydtls| external library

this commit for resolving |tinydtls-SHA| symbol conflict between
|iotivity-tinydtls| and pre-installed platform library.
this symbol conflict have occurred in applying Iotivity application
on commercialized platform, like Tizen and Android

Jira: https://jira.iotivity.org/browse/IOT-977

Change-Id: I15152078231d82f17d7121b19350deabd3abe356
Signed-off-by: default avatarKyungsun Cho <goodsun.cho@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/6245Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Randeep's avatarRandeep Singh <randeep.s@samsung.com>
parent b9e6cfc0
......@@ -35,24 +35,24 @@
* see http://www.aarongifford.com/ */
#include "sha2/sha2.h"
typedef SHA256_CTX dtls_hash_ctx;
typedef DTLS_SHA256_CTX dtls_hash_ctx;
typedef dtls_hash_ctx *dtls_hash_t;
#define DTLS_HASH_CTX_SIZE sizeof(SHA256_CTX)
#define DTLS_HASH_CTX_SIZE sizeof(DTLS_SHA256_CTX)
static inline void
dtls_hash_init(dtls_hash_t ctx) {
SHA256_Init((SHA256_CTX *)ctx);
DTLS_SHA256_Init((DTLS_SHA256_CTX *)ctx);
}
static inline void
dtls_hash_update(dtls_hash_t ctx, const unsigned char *input, size_t len) {
SHA256_Update((SHA256_CTX *)ctx, input, len);
DTLS_SHA256_Update((DTLS_SHA256_CTX *)ctx, input, len);
}
static inline size_t
dtls_hash_finalize(unsigned char *buf, dtls_hash_t ctx) {
SHA256_Final(buf, (SHA256_CTX *)ctx);
return SHA256_DIGEST_LENGTH;
DTLS_SHA256_Final(buf, (DTLS_SHA256_CTX *)ctx);
return DTLS_SHA256_DIGEST_LENGTH;
}
#endif /* WITH_SHA256 */
......
......@@ -146,7 +146,7 @@ typedef u_int64_t sha2_word64; /* Exactly 8 bytes */
/*** SHA-256/384/512 Various Length Definitions ***********************/
/* NOTE: Most of these are in sha2.h */
#define SHA256_SHORT_BLOCK_LENGTH (SHA256_BLOCK_LENGTH - 8)
#define DTLS_SHA256_SHORT_BLOCK_LENGTH (DTLS_SHA256_BLOCK_LENGTH - 8)
#define SHA384_SHORT_BLOCK_LENGTH (SHA384_BLOCK_LENGTH - 16)
#define SHA512_SHORT_BLOCK_LENGTH (SHA512_BLOCK_LENGTH - 16)
......@@ -246,7 +246,7 @@ typedef u_int64_t sha2_word64; /* Exactly 8 bytes */
* only.
*/
void SHA512_Last(SHA512_CTX*);
void SHA256_Transform(SHA256_CTX*, const sha2_word32*);
void DTLS_SHA256_Transform(DTLS_SHA256_CTX*, const sha2_word32*);
void SHA512_Transform(SHA512_CTX*, const sha2_word64*);
#ifdef WITH_SHA256
......@@ -272,7 +272,7 @@ const static sha2_word32 K256[64] = {
};
/* Initial hash value H for SHA-256: */
const static sha2_word32 sha256_initial_hash_value[8] = {
const static sha2_word32 DTLS_SHA256_initial_hash_value[8] = {
0x6a09e667UL,
0xbb67ae85UL,
0x3c6ef372UL,
......@@ -367,12 +367,12 @@ static const char *sha2_hex_digits = "0123456789abcdef";
/*** SHA-256: *********************************************************/
#ifdef WITH_SHA256
void SHA256_Init(SHA256_CTX* context) {
if (context == (SHA256_CTX*)0) {
void DTLS_SHA256_Init(DTLS_SHA256_CTX* context) {
if (context == (DTLS_SHA256_CTX*)0) {
return;
}
MEMCPY_BCOPY(context->state, sha256_initial_hash_value, SHA256_DIGEST_LENGTH);
MEMSET_BZERO(context->buffer, SHA256_BLOCK_LENGTH);
MEMCPY_BCOPY(context->state, DTLS_SHA256_initial_hash_value, DTLS_SHA256_DIGEST_LENGTH);
MEMSET_BZERO(context->buffer, DTLS_SHA256_BLOCK_LENGTH);
context->bitcount = 0;
}
......@@ -413,7 +413,7 @@ void SHA256_Init(SHA256_CTX* context) {
(h) = T1 + Sigma0_256(a) + Maj((a), (b), (c)); \
j++
void SHA256_Transform(SHA256_CTX* context, const sha2_word32* data) {
void DTLS_SHA256_Transform(DTLS_SHA256_CTX* context, const sha2_word32* data) {
sha2_word32 a, b, c, d, e, f, g, h, s0, s1;
sha2_word32 T1, *W256;
int j;
......@@ -471,7 +471,7 @@ void SHA256_Transform(SHA256_CTX* context, const sha2_word32* data) {
#else /* SHA2_UNROLL_TRANSFORM */
void SHA256_Transform(SHA256_CTX* context, const sha2_word32* data) {
void DTLS_SHA256_Transform(DTLS_SHA256_CTX* context, const sha2_word32* data) {
sha2_word32 a, b, c, d, e, f, g, h, s0, s1;
sha2_word32 T1, T2, *W256;
int j;
......@@ -551,7 +551,7 @@ void SHA256_Transform(SHA256_CTX* context, const sha2_word32* data) {
#endif /* SHA2_UNROLL_TRANSFORM */
void SHA256_Update(SHA256_CTX* context, const sha2_byte *data, size_t len) {
void DTLS_SHA256_Update(DTLS_SHA256_CTX* context, const sha2_byte *data, size_t len) {
unsigned int freespace, usedspace;
if (len == 0) {
......@@ -560,12 +560,12 @@ void SHA256_Update(SHA256_CTX* context, const sha2_byte *data, size_t len) {
}
/* Sanity check: */
assert(context != (SHA256_CTX*)0 && data != (sha2_byte*)0);
assert(context != (DTLS_SHA256_CTX*)0 && data != (sha2_byte*)0);
usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH;
usedspace = (context->bitcount >> 3) % DTLS_SHA256_BLOCK_LENGTH;
if (usedspace > 0) {
/* Calculate how much free space is available in the buffer */
freespace = SHA256_BLOCK_LENGTH - usedspace;
freespace = DTLS_SHA256_BLOCK_LENGTH - usedspace;
if (len >= freespace) {
/* Fill the buffer completely and process it */
......@@ -573,7 +573,7 @@ void SHA256_Update(SHA256_CTX* context, const sha2_byte *data, size_t len) {
context->bitcount += freespace << 3;
len -= freespace;
data += freespace;
SHA256_Transform(context, (sha2_word32*)context->buffer);
DTLS_SHA256_Transform(context, (sha2_word32*)context->buffer);
} else {
/* The buffer is not yet full */
MEMCPY_BCOPY(&context->buffer[usedspace], data, len);
......@@ -583,12 +583,12 @@ void SHA256_Update(SHA256_CTX* context, const sha2_byte *data, size_t len) {
return;
}
}
while (len >= SHA256_BLOCK_LENGTH) {
while (len >= DTLS_SHA256_BLOCK_LENGTH) {
/* Process as many complete blocks as we can */
SHA256_Transform(context, (sha2_word32*)data);
context->bitcount += SHA256_BLOCK_LENGTH << 3;
len -= SHA256_BLOCK_LENGTH;
data += SHA256_BLOCK_LENGTH;
DTLS_SHA256_Transform(context, (sha2_word32*)data);
context->bitcount += DTLS_SHA256_BLOCK_LENGTH << 3;
len -= DTLS_SHA256_BLOCK_LENGTH;
data += DTLS_SHA256_BLOCK_LENGTH;
}
if (len > 0) {
/* There's left-overs, so save 'em */
......@@ -599,16 +599,16 @@ void SHA256_Update(SHA256_CTX* context, const sha2_byte *data, size_t len) {
usedspace = freespace = 0;
}
void SHA256_Final(sha2_byte digest[], SHA256_CTX* context) {
void DTLS_SHA256_Final(sha2_byte digest[], DTLS_SHA256_CTX* context) {
sha2_word32 *d = (sha2_word32*)digest;
unsigned int usedspace;
/* Sanity check: */
assert(context != (SHA256_CTX*)0);
assert(context != (DTLS_SHA256_CTX*)0);
/* If no digest buffer is passed, we don't bother doing this: */
if (digest != (sha2_byte*)0) {
usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH;
usedspace = (context->bitcount >> 3) % DTLS_SHA256_BLOCK_LENGTH;
#if BYTE_ORDER == LITTLE_ENDIAN
/* Convert FROM host byte order */
REVERSE64(context->bitcount,context->bitcount);
......@@ -617,31 +617,31 @@ void SHA256_Final(sha2_byte digest[], SHA256_CTX* context) {
/* Begin padding with a 1 bit: */
context->buffer[usedspace++] = 0x80;
if (usedspace <= SHA256_SHORT_BLOCK_LENGTH) {
if (usedspace <= DTLS_SHA256_SHORT_BLOCK_LENGTH) {
/* Set-up for the last transform: */
MEMSET_BZERO(&context->buffer[usedspace], SHA256_SHORT_BLOCK_LENGTH - usedspace);
MEMSET_BZERO(&context->buffer[usedspace], DTLS_SHA256_SHORT_BLOCK_LENGTH - usedspace);
} else {
if (usedspace < SHA256_BLOCK_LENGTH) {
MEMSET_BZERO(&context->buffer[usedspace], SHA256_BLOCK_LENGTH - usedspace);
if (usedspace < DTLS_SHA256_BLOCK_LENGTH) {
MEMSET_BZERO(&context->buffer[usedspace], DTLS_SHA256_BLOCK_LENGTH - usedspace);
}
/* Do second-to-last transform: */
SHA256_Transform(context, (sha2_word32*)context->buffer);
DTLS_SHA256_Transform(context, (sha2_word32*)context->buffer);
/* And set-up for the last transform: */
MEMSET_BZERO(context->buffer, SHA256_SHORT_BLOCK_LENGTH);
MEMSET_BZERO(context->buffer, DTLS_SHA256_SHORT_BLOCK_LENGTH);
}
} else {
/* Set-up for the last transform: */
MEMSET_BZERO(context->buffer, SHA256_SHORT_BLOCK_LENGTH);
MEMSET_BZERO(context->buffer, DTLS_SHA256_SHORT_BLOCK_LENGTH);
/* Begin padding with a 1 bit: */
*context->buffer = 0x80;
}
/* Set the bit count: */
*(sha2_word64*)&context->buffer[SHA256_SHORT_BLOCK_LENGTH] = context->bitcount;
*(sha2_word64*)&context->buffer[DTLS_SHA256_SHORT_BLOCK_LENGTH] = context->bitcount;
/* Final transform: */
SHA256_Transform(context, (sha2_word32*)context->buffer);
DTLS_SHA256_Transform(context, (sha2_word32*)context->buffer);
#if BYTE_ORDER == LITTLE_ENDIAN
{
......@@ -653,7 +653,7 @@ void SHA256_Final(sha2_byte digest[], SHA256_CTX* context) {
}
}
#else
MEMCPY_BCOPY(d, context->state, SHA256_DIGEST_LENGTH);
MEMCPY_BCOPY(d, context->state, DTLS_SHA256_DIGEST_LENGTH);
#endif
}
......@@ -662,17 +662,17 @@ void SHA256_Final(sha2_byte digest[], SHA256_CTX* context) {
usedspace = 0;
}
char *SHA256_End(SHA256_CTX* context, char buffer[]) {
sha2_byte digest[SHA256_DIGEST_LENGTH], *d = digest;
char *DTLS_SHA256_End(DTLS_SHA256_CTX* context, char buffer[]) {
sha2_byte digest[DTLS_SHA256_DIGEST_LENGTH], *d = digest;
int i;
/* Sanity check: */
assert(context != (SHA256_CTX*)0);
assert(context != (DTLS_SHA256_CTX*)0);
if (buffer != (char*)0) {
SHA256_Final(digest, context);
DTLS_SHA256_Final(digest, context);
for (i = 0; i < SHA256_DIGEST_LENGTH; i++) {
for (i = 0; i < DTLS_SHA256_DIGEST_LENGTH; i++) {
*buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4];
*buffer++ = sha2_hex_digits[*d & 0x0f];
d++;
......@@ -681,16 +681,16 @@ char *SHA256_End(SHA256_CTX* context, char buffer[]) {
} else {
MEMSET_BZERO(context, sizeof(*context));
}
MEMSET_BZERO(digest, SHA256_DIGEST_LENGTH);
MEMSET_BZERO(digest, DTLS_SHA256_DIGEST_LENGTH);
return buffer;
}
char* SHA256_Data(const sha2_byte* data, size_t len, char digest[SHA256_DIGEST_STRING_LENGTH]) {
SHA256_CTX context;
char* DTLS_SHA256_Data(const sha2_byte* data, size_t len, char digest[DTLS_SHA256_DIGEST_STRING_LENGTH]) {
DTLS_SHA256_CTX context;
SHA256_Init(&context);
SHA256_Update(&context, data, len);
return SHA256_End(&context, digest);
DTLS_SHA256_Init(&context);
DTLS_SHA256_Update(&context, data, len);
return DTLS_SHA256_End(&context, digest);
}
#endif
......
......@@ -55,9 +55,9 @@ extern "C" {
/*** SHA-256/384/512 Various Length Definitions ***********************/
#define SHA256_BLOCK_LENGTH 64
#define SHA256_DIGEST_LENGTH 32
#define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
#define DTLS_SHA256_BLOCK_LENGTH 64
#define DTLS_SHA256_DIGEST_LENGTH 32
#define DTLS_SHA256_DIGEST_STRING_LENGTH (DTLS_SHA256_DIGEST_LENGTH * 2 + 1)
#define SHA384_BLOCK_LENGTH 128
#define SHA384_DIGEST_LENGTH 48
#define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1)
......@@ -94,11 +94,11 @@ typedef unsigned long long u_int64_t; /* 8-bytes (64-bits) */
*/
#ifdef SHA2_USE_INTTYPES_H
typedef struct _SHA256_CTX {
typedef struct _DTLS_SHA256_CTX {
uint32_t state[8];
uint64_t bitcount;
uint8_t buffer[SHA256_BLOCK_LENGTH];
} SHA256_CTX;
uint8_t buffer[DTLS_SHA256_BLOCK_LENGTH];
} DTLS_SHA256_CTX;
typedef struct _SHA512_CTX {
uint64_t state[8];
uint64_t bitcount[2];
......@@ -107,11 +107,11 @@ typedef struct _SHA512_CTX {
#else /* SHA2_USE_INTTYPES_H */
typedef struct _SHA256_CTX {
typedef struct _DTLS_SHA256_CTX {
u_int32_t state[8];
u_int64_t bitcount;
u_int8_t buffer[SHA256_BLOCK_LENGTH];
} SHA256_CTX;
u_int8_t buffer[DTLS_SHA256_BLOCK_LENGTH];
} DTLS_SHA256_CTX;
typedef struct _SHA512_CTX {
u_int64_t state[8];
u_int64_t bitcount[2];
......@@ -128,11 +128,11 @@ typedef SHA512_CTX SHA384_CTX;
#ifdef SHA2_USE_INTTYPES_H
#ifdef WITH_SHA256
void SHA256_Init(SHA256_CTX *);
void SHA256_Update(SHA256_CTX*, const uint8_t*, size_t);
void SHA256_Final(uint8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*);
char* SHA256_End(SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]);
char* SHA256_Data(const uint8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]);
void DTLS_SHA256_Init(DTLS_SHA256_CTX *);
void DTLS_SHA256_Update(DTLS_SHA256_CTX*, const uint8_t*, size_t);
void DTLS_SHA256_Final(uint8_t[DTLS_SHA256_DIGEST_LENGTH], DTLS_SHA256_CTX*);
char* DTLS_SHA256_End(DTLS_SHA256_CTX*, char[DTLS_SHA256_DIGEST_STRING_LENGTH]);
char* DTLS_SHA256_Data(const uint8_t*, size_t, char[DTLS_SHA256_DIGEST_STRING_LENGTH]);
#endif
#ifdef WITH_SHA384
......@@ -154,11 +154,11 @@ char* SHA512_Data(const uint8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]);
#else /* SHA2_USE_INTTYPES_H */
#ifdef WITH_SHA256
void SHA256_Init(SHA256_CTX *);
void SHA256_Update(SHA256_CTX*, const u_int8_t*, size_t);
void SHA256_Final(u_int8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*);
char* SHA256_End(SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]);
char* SHA256_Data(const u_int8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]);
void DTLS_SHA256_Init(DTLS_SHA256_CTX *);
void DTLS_SHA256_Update(DTLS_SHA256_CTX*, const u_int8_t*, size_t);
void DTLS_SHA256_Final(u_int8_t[DTLS_SHA256_DIGEST_LENGTH], DTLS_SHA256_CTX*);
char* DTLS_SHA256_End(DTLS_SHA256_CTX*, char[DTLS_SHA256_DIGEST_STRING_LENGTH]);
char* DTLS_SHA256_Data(const u_int8_t*, size_t, char[DTLS_SHA256_DIGEST_STRING_LENGTH]);
#endif
#ifdef WITH_SHA384
......@@ -182,11 +182,11 @@ char* SHA512_Data(const u_int8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]);
#else /* NOPROTO */
#ifdef WITH_SHA256
void SHA256_Init();
void SHA256_Update();
void SHA256_Final();
char* SHA256_End();
char* SHA256_Data();
void DTLS_SHA256_Init();
void DTLS_SHA256_Update();
void DTLS_SHA256_Final();
char* DTLS_SHA256_End();
char* DTLS_SHA256_Data();
#endif
#ifdef WITH_SHA384
......
......@@ -97,18 +97,18 @@ int main(int argc, char **argv) {
ave256 = ave384 = ave512 = 0;
best256 = best384 = best512 = 100000;
for (i = 0; i < rep; i++) {
SHA256_Init(&c256);
SHA384_Init(&c384);
SHA512_Init(&c512);
DTLS_SHA256_Init(&c256);
DTLS_SHA384_Init(&c384);
DTLS_SHA512_Init(&c512);
gettimeofday(&start, (struct timezone*)0);
for (j = 0; j < blocks; j++) {
SHA256_Update(&c256, (unsigned char*)buf, BUFSIZE);
DTLS_SHA256_Update(&c256, (unsigned char*)buf, BUFSIZE);
}
if (bytes % BUFSIZE) {
SHA256_Update(&c256, (unsigned char*)buf, bytes % BUFSIZE);
DTLS_SHA256_Update(&c256, (unsigned char*)buf, bytes % BUFSIZE);
}
SHA256_End(&c256, md);
DTLS_SHA256_End(&c256, md);
gettimeofday(&end, (struct timezone*)0);
t = ((end.tv_sec - start.tv_sec) * 1000000.0 + (end.tv_usec - start.tv_usec)) / 1000000.0;
ave256 += t;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment