Merge branch 'origin/develop'

This merge does a cleanup of accidentally diverged histories of master
and develop branch.
diff --git a/hmac.h b/hmac.h
index 81a058d..8a43e2d 100644
--- a/hmac.h
+++ b/hmac.h
@@ -27,24 +27,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 */
 
diff --git a/sha2/sha2.c b/sha2/sha2.c
index 2578f17..c42c993 100644
--- a/sha2/sha2.c
+++ b/sha2/sha2.c
@@ -146,9 +146,9 @@
 
 /*** 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 SHA384_SHORT_BLOCK_LENGTH	(SHA384_BLOCK_LENGTH - 16)
-#define SHA512_SHORT_BLOCK_LENGTH	(SHA512_BLOCK_LENGTH - 16)
+#define DTLS_SHA256_SHORT_BLOCK_LENGTH	(DTLS_SHA256_BLOCK_LENGTH - 8)
+#define DTLS_SHA384_SHORT_BLOCK_LENGTH	(DTLS_SHA384_BLOCK_LENGTH - 16)
+#define DTLS_SHA512_SHORT_BLOCK_LENGTH	(DTLS_SHA512_BLOCK_LENGTH - 16)
 
 
 /*** ENDIAN REVERSAL MACROS *******************************************/
@@ -245,9 +245,9 @@
  * library -- they are intended for private internal visibility/use
  * only.
  */
-void SHA512_Last(SHA512_CTX*);
-void SHA256_Transform(SHA256_CTX*, const sha2_word32*);
-void SHA512_Transform(SHA512_CTX*, const sha2_word64*);
+void dtls_sha512_last(dtls_sha512_ctx*);
+void dtls_sha256_transform(dtls_sha256_ctx*, const sha2_word32*);
+void dtls_sha512_transform(dtls_sha512_ctx*, const sha2_word64*);
 
 #ifdef WITH_SHA256
 /*** SHA-XYZ INITIAL HASH VALUES AND CONSTANTS ************************/
@@ -367,12 +367,12 @@
 
 /*** 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, sha256_initial_hash_value, DTLS_SHA256_DIGEST_LENGTH);
+	MEMSET_BZERO(context->buffer, DTLS_SHA256_BLOCK_LENGTH);
 	context->bitcount = 0;
 }
 
@@ -413,7 +413,7 @@
 	(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 @@
 
 #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 @@
 
 #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 @@
 	}
 
 	/* 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 @@
 			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 @@
 			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 @@
 	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 @@
 			/* 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 @@
 			}
 		}
 #else
-		MEMCPY_BCOPY(d, context->state, SHA256_DIGEST_LENGTH);
+		MEMCPY_BCOPY(d, context->state, DTLS_SHA256_DIGEST_LENGTH);
 #endif
 	}
 
@@ -662,17 +662,17 @@
 	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,27 +681,27 @@
 	} 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
 
 /*** SHA-512: *********************************************************/
 #ifdef WITH_SHA512
-void SHA512_Init(SHA512_CTX* context) {
-	if (context == (SHA512_CTX*)0) {
+void dtls_sha512_init(dtls_sha512_ctx* context) {
+	if (context == (dtls_sha512_ctx*)0) {
 		return;
 	}
-	MEMCPY_BCOPY(context->state, sha512_initial_hash_value, SHA512_DIGEST_LENGTH);
-	MEMSET_BZERO(context->buffer, SHA512_BLOCK_LENGTH);
+	MEMCPY_BCOPY(context->state, sha512_initial_hash_value, DTLS_SHA512_DIGEST_LENGTH);
+	MEMSET_BZERO(context->buffer, DTLS_SHA512_BLOCK_LENGTH);
 	context->bitcount[0] = context->bitcount[1] =  0;
 }
 
@@ -741,7 +741,7 @@
 	(h) = T1 + Sigma0_512(a) + Maj((a), (b), (c)); \
 	j++
 
-void SHA512_Transform(SHA512_CTX* context, const sha2_word64* data) {
+void dtls_sha512_transform(dtls_sha512_ctx* context, const sha2_word64* data) {
 	sha2_word64	a, b, c, d, e, f, g, h, s0, s1;
 	sha2_word64	T1, *W512 = (sha2_word64*)context->buffer;
 	int		j;
@@ -796,7 +796,7 @@
 
 #else /* SHA2_UNROLL_TRANSFORM */
 
-void SHA512_Transform(SHA512_CTX* context, const sha2_word64* data) {
+void dtls_sha512_transform(dtls_sha512_ctx* context, const sha2_word64* data) {
 	sha2_word64	a, b, c, d, e, f, g, h, s0, s1;
 	sha2_word64	T1, T2, *W512 = (sha2_word64*)context->buffer;
 	int		j;
@@ -874,7 +874,7 @@
 
 #endif /* SHA2_UNROLL_TRANSFORM */
 
-void SHA512_Update(SHA512_CTX* context, const sha2_byte *data, size_t len) {
+void dtls_sha512_update(dtls_sha512_ctx* context, const sha2_byte *data, size_t len) {
 	unsigned int	freespace, usedspace;
 
 	if (len == 0) {
@@ -883,12 +883,12 @@
 	}
 
 	/* Sanity check: */
-	assert(context != (SHA512_CTX*)0 && data != (sha2_byte*)0);
+	assert(context != (dtls_sha512_ctx*)0 && data != (sha2_byte*)0);
 
-	usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH;
+	usedspace = (context->bitcount[0] >> 3) % DTLS_SHA512_BLOCK_LENGTH;
 	if (usedspace > 0) {
 		/* Calculate how much free space is available in the buffer */
-		freespace = SHA512_BLOCK_LENGTH - usedspace;
+		freespace = DTLS_SHA512_BLOCK_LENGTH - usedspace;
 
 		if (len >= freespace) {
 			/* Fill the buffer completely and process it */
@@ -896,7 +896,7 @@
 			ADDINC128(context->bitcount, freespace << 3);
 			len -= freespace;
 			data += freespace;
-			SHA512_Transform(context, (sha2_word64*)context->buffer);
+			dtls_sha512_transform(context, (sha2_word64*)context->buffer);
 		} else {
 			/* The buffer is not yet full */
 			MEMCPY_BCOPY(&context->buffer[usedspace], data, len);
@@ -906,12 +906,12 @@
 			return;
 		}
 	}
-	while (len >= SHA512_BLOCK_LENGTH) {
+	while (len >= DTLS_SHA512_BLOCK_LENGTH) {
 		/* Process as many complete blocks as we can */
-		SHA512_Transform(context, (sha2_word64*)data);
-		ADDINC128(context->bitcount, SHA512_BLOCK_LENGTH << 3);
-		len -= SHA512_BLOCK_LENGTH;
-		data += SHA512_BLOCK_LENGTH;
+		dtls_sha512_transform(context, (sha2_word64*)data);
+		ADDINC128(context->bitcount, DTLS_SHA512_BLOCK_LENGTH << 3);
+		len -= DTLS_SHA512_BLOCK_LENGTH;
+		data += DTLS_SHA512_BLOCK_LENGTH;
 	}
 	if (len > 0) {
 		/* There's left-overs, so save 'em */
@@ -922,10 +922,10 @@
 	usedspace = freespace = 0;
 }
 
-void SHA512_Last(SHA512_CTX* context) {
+void dtls_sha512_last(dtls_sha512_ctx* context) {
 	unsigned int	usedspace;
 
-	usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH;
+	usedspace = (context->bitcount[0] >> 3) % DTLS_SHA512_BLOCK_LENGTH;
 #if BYTE_ORDER == LITTLE_ENDIAN
 	/* Convert FROM host byte order */
 	REVERSE64(context->bitcount[0],context->bitcount[0]);
@@ -935,43 +935,43 @@
 		/* Begin padding with a 1 bit: */
 		context->buffer[usedspace++] = 0x80;
 
-		if (usedspace <= SHA512_SHORT_BLOCK_LENGTH) {
+		if (usedspace <= DTLS_SHA512_SHORT_BLOCK_LENGTH) {
 			/* Set-up for the last transform: */
-			MEMSET_BZERO(&context->buffer[usedspace], SHA512_SHORT_BLOCK_LENGTH - usedspace);
+			MEMSET_BZERO(&context->buffer[usedspace], DTLS_SHA512_SHORT_BLOCK_LENGTH - usedspace);
 		} else {
-			if (usedspace < SHA512_BLOCK_LENGTH) {
-				MEMSET_BZERO(&context->buffer[usedspace], SHA512_BLOCK_LENGTH - usedspace);
+			if (usedspace < DTLS_SHA512_BLOCK_LENGTH) {
+				MEMSET_BZERO(&context->buffer[usedspace], DTLS_SHA512_BLOCK_LENGTH - usedspace);
 			}
 			/* Do second-to-last transform: */
-			SHA512_Transform(context, (sha2_word64*)context->buffer);
+			dtls_sha512_transform(context, (sha2_word64*)context->buffer);
 
 			/* And set-up for the last transform: */
-			MEMSET_BZERO(context->buffer, SHA512_BLOCK_LENGTH - 2);
+			MEMSET_BZERO(context->buffer, DTLS_SHA512_BLOCK_LENGTH - 2);
 		}
 	} else {
 		/* Prepare for final transform: */
-		MEMSET_BZERO(context->buffer, SHA512_SHORT_BLOCK_LENGTH);
+		MEMSET_BZERO(context->buffer, DTLS_SHA512_SHORT_BLOCK_LENGTH);
 
 		/* Begin padding with a 1 bit: */
 		*context->buffer = 0x80;
 	}
 	/* Store the length of input data (in bits): */
-	*(sha2_word64*)&context->buffer[SHA512_SHORT_BLOCK_LENGTH] = context->bitcount[1];
-	*(sha2_word64*)&context->buffer[SHA512_SHORT_BLOCK_LENGTH+8] = context->bitcount[0];
+	*(sha2_word64*)&context->buffer[DTLS_SHA512_SHORT_BLOCK_LENGTH] = context->bitcount[1];
+	*(sha2_word64*)&context->buffer[DTLS_SHA512_SHORT_BLOCK_LENGTH+8] = context->bitcount[0];
 
 	/* Final transform: */
-	SHA512_Transform(context, (sha2_word64*)context->buffer);
+	dtls_sha512_transform(context, (sha2_word64*)context->buffer);
 }
 
-void SHA512_Final(sha2_byte digest[], SHA512_CTX* context) {
+void dtls_sha512_final(sha2_byte digest[], dtls_sha512_ctx* context) {
 	sha2_word64	*d = (sha2_word64*)digest;
 
 	/* Sanity check: */
-	assert(context != (SHA512_CTX*)0);
+	assert(context != (dtls_sha512_ctx*)0);
 
 	/* If no digest buffer is passed, we don't bother doing this: */
 	if (digest != (sha2_byte*)0) {
-		SHA512_Last(context);
+		dtls_sha512_last(context);
 
 		/* Save the hash data for output: */
 #if BYTE_ORDER == LITTLE_ENDIAN
@@ -984,7 +984,7 @@
 			}
 		}
 #else
-		MEMCPY_BCOPY(d, context->state, SHA512_DIGEST_LENGTH);
+		MEMCPY_BCOPY(d, context->state, DTLS_SHA512_DIGEST_LENGTH);
 #endif
 	}
 
@@ -992,17 +992,17 @@
 	MEMSET_BZERO(context, sizeof(context));
 }
 
-char *SHA512_End(SHA512_CTX* context, char buffer[]) {
-	sha2_byte	digest[SHA512_DIGEST_LENGTH], *d = digest;
+char *dtls_sha512_end(dtls_sha512_ctx* context, char buffer[]) {
+	sha2_byte	digest[DTLS_SHA512_DIGEST_LENGTH], *d = digest;
 	int		i;
 
 	/* Sanity check: */
-	assert(context != (SHA512_CTX*)0);
+	assert(context != (dtls_sha512_ctx*)0);
 
 	if (buffer != (char*)0) {
-		SHA512_Final(digest, context);
+		dtls_sha512_final(digest, context);
 
-		for (i = 0; i < SHA512_DIGEST_LENGTH; i++) {
+		for (i = 0; i < DTLS_SHA512_DIGEST_LENGTH; i++) {
 			*buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4];
 			*buffer++ = sha2_hex_digits[*d & 0x0f];
 			d++;
@@ -1011,43 +1011,43 @@
 	} else {
 		MEMSET_BZERO(context, sizeof(context));
 	}
-	MEMSET_BZERO(digest, SHA512_DIGEST_LENGTH);
+	MEMSET_BZERO(digest, DTLS_SHA512_DIGEST_LENGTH);
 	return buffer;
 }
 
-char* SHA512_Data(const sha2_byte* data, size_t len, char digest[SHA512_DIGEST_STRING_LENGTH]) {
-	SHA512_CTX	context;
+char* dtls_sha512_data(const sha2_byte* data, size_t len, char digest[DTLS_SHA512_DIGEST_STRING_LENGTH]) {
+	dtls_sha512_ctx	context;
 
-	SHA512_Init(&context);
-	SHA512_Update(&context, data, len);
-	return SHA512_End(&context, digest);
+	dtls_sha512_init(&context);
+	dtls_sha512_update(&context, data, len);
+	return dtls_sha512_end(&context, digest);
 }
 #endif
 
 /*** SHA-384: *********************************************************/
 #ifdef WITH_SHA384
-void SHA384_Init(SHA384_CTX* context) {
-	if (context == (SHA384_CTX*)0) {
+void dtls_sha384_init(dtls_sha384_ctx* context) {
+	if (context == (dtls_sha384_ctx*)0) {
 		return;
 	}
-	MEMCPY_BCOPY(context->state, sha384_initial_hash_value, SHA512_DIGEST_LENGTH);
-	MEMSET_BZERO(context->buffer, SHA384_BLOCK_LENGTH);
+	MEMCPY_BCOPY(context->state, sha384_initial_hash_value, DTLS_SHA512_DIGEST_LENGTH);
+	MEMSET_BZERO(context->buffer, DTLS_SHA384_BLOCK_LENGTH);
 	context->bitcount[0] = context->bitcount[1] = 0;
 }
 
-void SHA384_Update(SHA384_CTX* context, const sha2_byte* data, size_t len) {
-	SHA512_Update((SHA512_CTX*)context, data, len);
+void dtls_sha384_update(dtls_sha384_ctx* context, const sha2_byte* data, size_t len) {
+	dtls_sha512_update((dtls_sha512_ctx*)context, data, len);
 }
 
-void SHA384_Final(sha2_byte digest[], SHA384_CTX* context) {
+void dtls_sha384_final(sha2_byte digest[], dtls_sha384_ctx* context) {
 	sha2_word64	*d = (sha2_word64*)digest;
 
 	/* Sanity check: */
-	assert(context != (SHA384_CTX*)0);
+	assert(context != (dtls_sha384_ctx*)0);
 
 	/* If no digest buffer is passed, we don't bother doing this: */
 	if (digest != (sha2_byte*)0) {
-		SHA512_Last((SHA512_CTX*)context);
+		dtls_sha512_last((dtls_sha512_ctx*)context);
 
 		/* Save the hash data for output: */
 #if BYTE_ORDER == LITTLE_ENDIAN
@@ -1060,7 +1060,7 @@
 			}
 		}
 #else
-		MEMCPY_BCOPY(d, context->state, SHA384_DIGEST_LENGTH);
+		MEMCPY_BCOPY(d, context->state, DTLS_SHA384_DIGEST_LENGTH);
 #endif
 	}
 
@@ -1068,17 +1068,17 @@
 	MEMSET_BZERO(context, sizeof(context));
 }
 
-char *SHA384_End(SHA384_CTX* context, char buffer[]) {
-	sha2_byte	digest[SHA384_DIGEST_LENGTH], *d = digest;
+char *dtls_sha384_end(dtls_sha384_ctx* context, char buffer[]) {
+	sha2_byte	digest[DTLS_SHA384_DIGEST_LENGTH], *d = digest;
 	int		i;
 
 	/* Sanity check: */
-	assert(context != (SHA384_CTX*)0);
+	assert(context != (dtls_sha384_ctx*)0);
 
 	if (buffer != (char*)0) {
-		SHA384_Final(digest, context);
+		dtls_sha384_final(digest, context);
 
-		for (i = 0; i < SHA384_DIGEST_LENGTH; i++) {
+		for (i = 0; i < DTLS_SHA384_DIGEST_LENGTH; i++) {
 			*buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4];
 			*buffer++ = sha2_hex_digits[*d & 0x0f];
 			d++;
@@ -1087,15 +1087,15 @@
 	} else {
 		MEMSET_BZERO(context, sizeof(context));
 	}
-	MEMSET_BZERO(digest, SHA384_DIGEST_LENGTH);
+	MEMSET_BZERO(digest, DTLS_SHA384_DIGEST_LENGTH);
 	return buffer;
 }
 
-char* SHA384_Data(const sha2_byte* data, size_t len, char digest[SHA384_DIGEST_STRING_LENGTH]) {
-	SHA384_CTX	context;
+char* dtls_sha384_data(const sha2_byte* data, size_t len, char digest[DTLS_SHA384_DIGEST_STRING_LENGTH]) {
+	dtls_sha384_ctx	context;
 
-	SHA384_Init(&context);
-	SHA384_Update(&context, data, len);
-	return SHA384_End(&context, digest);
+	dtls_sha384_init(&context);
+	dtls_sha384_update(&context, data, len);
+	return dtls_sha384_end(&context, digest);
 }
 #endif
diff --git a/sha2/sha2.h b/sha2/sha2.h
index 709fc80..c56b42a 100644
--- a/sha2/sha2.h
+++ b/sha2/sha2.h
@@ -55,15 +55,15 @@
 
 
 /*** 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 SHA384_BLOCK_LENGTH		128
-#define SHA384_DIGEST_LENGTH		48
-#define SHA384_DIGEST_STRING_LENGTH	(SHA384_DIGEST_LENGTH * 2 + 1)
-#define SHA512_BLOCK_LENGTH		128
-#define SHA512_DIGEST_LENGTH		64
-#define SHA512_DIGEST_STRING_LENGTH	(SHA512_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 DTLS_SHA384_BLOCK_LENGTH		128
+#define DTLS_SHA384_DIGEST_LENGTH		48
+#define DTLS_SHA384_DIGEST_STRING_LENGTH	(DTLS_SHA384_DIGEST_LENGTH * 2 + 1)
+#define DTLS_SHA512_BLOCK_LENGTH		128
+#define DTLS_SHA512_DIGEST_LENGTH		64
+#define DTLS_SHA512_DIGEST_STRING_LENGTH	(DTLS_SHA512_DIGEST_LENGTH * 2 + 1)
 
 
 /*** SHA-256/384/512 Context Structures *******************************/
@@ -94,33 +94,33 @@
  */
 #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;
-typedef struct _SHA512_CTX {
+	uint8_t	buffer[DTLS_SHA256_BLOCK_LENGTH];
+} dtls_sha256_ctx;
+typedef struct _dtls_sha512_ctx {
 	uint64_t	state[8];
 	uint64_t	bitcount[2];
-	uint8_t	buffer[SHA512_BLOCK_LENGTH];
-} SHA512_CTX;
+	uint8_t	buffer[DTLS_SHA512_BLOCK_LENGTH];
+} dtls_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;
-typedef struct _SHA512_CTX {
+	u_int8_t	buffer[DTLS_SHA256_BLOCK_LENGTH];
+} dtls_sha256_ctx;
+typedef struct _dtls_sha512_ctx {
 	u_int64_t	state[8];
 	u_int64_t	bitcount[2];
-	u_int8_t	buffer[SHA512_BLOCK_LENGTH];
-} SHA512_CTX;
+	u_int8_t	buffer[DTLS_SHA512_BLOCK_LENGTH];
+} dtls_sha512_ctx;
 
 #endif /* SHA2_USE_INTTYPES_H */
 
-typedef SHA512_CTX SHA384_CTX;
+typedef dtls_sha512_ctx dtls_sha384_ctx;
 
 
 /*** SHA-256/384/512 Function Prototypes ******************************/
@@ -128,53 +128,53 @@
 #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
-void SHA384_Init(SHA384_CTX*);
-void SHA384_Update(SHA384_CTX*, const uint8_t*, size_t);
-void SHA384_Final(uint8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*);
-char* SHA384_End(SHA384_CTX*, char[SHA384_DIGEST_STRING_LENGTH]);
-char* SHA384_Data(const uint8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH]);
+void dtls_sha384_init(dtls_sha384_ctx*);
+void dtls_sha384_update(dtls_sha384_ctx*, const uint8_t*, size_t);
+void dtls_sha384_final(uint8_t[DTLS_SHA384_DIGEST_LENGTH], SHA384_CTX*);
+char* dtls_sha384_end(dtls_sha384_ctx*, char[DTLS_SHA384_DIGEST_STRING_LENGTH]);
+char* dtls_sha384_data(const uint8_t*, size_t, char[DTLS_SHA384_DIGEST_STRING_LENGTH]);
 #endif
 
 #ifdef WITH_SHA512
-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*);
-char* SHA512_End(SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]);
-char* SHA512_Data(const uint8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]);
+void dtls_sha512_init(dtls_sha512_ctx*);
+void dtls_sha512_update(dtls_sha512_ctx*, const uint8_t*, size_t);
+void dtls_sha512_final(uint8_t[DTLS_SHA512_DIGEST_LENGTH], dtls_sha512_ctx*);
+char* dtls_sha512_end(dtls_sha512_ctx*, char[DTLS_SHA512_DIGEST_STRING_LENGTH]);
+char* dtls_sha512_data(const uint8_t*, size_t, char[DTLS_SHA512_DIGEST_STRING_LENGTH]);
 #endif
 
 #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
-void SHA384_Init(SHA384_CTX*);
-void SHA384_Update(SHA384_CTX*, const u_int8_t*, size_t);
-void SHA384_Final(u_int8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*);
-char* SHA384_End(SHA384_CTX*, char[SHA384_DIGEST_STRING_LENGTH]);
-char* SHA384_Data(const u_int8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH]);
+void dtls_sha384_init(dtls_sha384_ctx*);
+void dtls_sha384_update(dtls_sha384_ctx*, const u_int8_t*, size_t);
+void dtls_sha384_final(u_int8_t[DTLS_SHA384_DIGEST_LENGTH], dtls_sha384_ctx*);
+char* dtls_sha384_end(dtls_sha384_ctx*, char[DTLS_SHA384_DIGEST_STRING_LENGTH]);
+char* dtls_sha384_data(const u_int8_t*, size_t, char[DTLS_SHA384_DIGEST_STRING_LENGTH]);
 #endif
 
 #ifdef WITH_SHA512
-void SHA512_Init(SHA512_CTX*);
-void SHA512_Update(SHA512_CTX*, const u_int8_t*, size_t);
-void SHA512_Final(u_int8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*);
-char* SHA512_End(SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]);
-char* SHA512_Data(const u_int8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]);
+void dtls_sha512_init(dtls_sha512_ctx*);
+void dtls_sha512_update(dtls_sha512_ctx*, const u_int8_t*, size_t);
+void dtls_sha512_final(u_int8_t[DTLS_SHA512_DIGEST_LENGTH], dtls_sha512_ctx*);
+char* dtls_sha512_end(dtls_sha512_ctx*, char[DTLS_SHA512_DIGEST_STRING_LENGTH]);
+char* dtls_sha512_data(const u_int8_t*, size_t, char[DTLS_SHA512_DIGEST_STRING_LENGTH]);
 #endif
 
 #endif /* SHA2_USE_INTTYPES_H */
@@ -182,27 +182,27 @@
 #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
-void SHA384_Init();
-void SHA384_Update();
-void SHA384_Final();
-char* SHA384_End();
-char* SHA384_Data();
+void dtls_sha384_init();
+void dtls_sha384_update();
+void dtls_sha384_final();
+char* dtls_sha384_end();
+char* dtls_sha384_data();
 #endif
 
 #ifdef WITH_SHA512
-void SHA512_Init();
-void SHA512_Update();
-void SHA512_Final();
-char* SHA512_End();
-char* SHA512_Data();
+void dtls_sha512_init();
+void dtls_sha512_update();
+void dtls_sha512_final();
+char* dtls_sha512_end();
+char* dtls_sha512_data();
 #endif
 
 #endif /* NOPROTO */
diff --git a/sha2/sha2prog.c b/sha2/sha2prog.c
index 8d9d6ae..6ac6796 100644
--- a/sha2/sha2prog.c
+++ b/sha2/sha2prog.c
@@ -52,14 +52,14 @@
 	int		quiet = 0, hash = 0;
 	char		*av, *file = (char*)0;
 	FILE		*IN = (FILE*)0;
-	SHA256_CTX	ctx256;
-	SHA384_CTX	ctx384;
-	SHA512_CTX	ctx512;
+	dtls_sha256_ctx	ctx256;
+	dtls_sha384_ctx	ctx384;
+	dtls_sha512_ctx	ctx512;
 	unsigned char	buf[BUFLEN];
 
-	SHA256_Init(&ctx256);
-	SHA384_Init(&ctx384);
-	SHA512_Init(&ctx512);
+	dtls_sha256_init(&ctx256);
+	dtls_sha384_init(&ctx384);
+	dtls_sha512_init(&ctx512);
 
 	/* Read data from STDIN by default */
 	fd = fileno(stdin);
@@ -100,28 +100,28 @@
 	kl = 0;
 	while ((l = read(fd,buf,BUFLEN)) > 0) {
 		kl += l;
-		SHA256_Update(&ctx256, (unsigned char*)buf, l);
-		SHA384_Update(&ctx384, (unsigned char*)buf, l);
-		SHA512_Update(&ctx512, (unsigned char*)buf, l);
+		dtls_sha256_update(&ctx256, (unsigned char*)buf, l);
+		dtls_sha384_update(&ctx384, (unsigned char*)buf, l);
+		dtls_sha512_update(&ctx512, (unsigned char*)buf, l);
 	}
 	if (file) {
 		fclose(IN);
 	}
 
 	if (hash & 1) {
-		SHA256_End(&ctx256, buf);
+		dtls_sha256_end(&ctx256, buf);
 		if (!quiet)
 			printf("SHA-256 (%s) = ", file);
 		printf("%s\n", buf);
 	}
 	if (hash & 2) {
-		SHA384_End(&ctx384, buf);
+		dtls_sha384_end(&ctx384, buf);
 		if (!quiet)
 			printf("SHA-384 (%s) = ", file);
 		printf("%s\n", buf);
 	}
 	if (hash & 4) {
-		SHA512_End(&ctx512, buf);
+		dtls_sha512_end(&ctx512, buf);
 		if (!quiet)
 			printf("SHA-512 (%s) = ", file);
 		printf("%s\n", buf);
diff --git a/sha2/sha2speed.c b/sha2/sha2speed.c
index 2e13575..77d17af 100644
--- a/sha2/sha2speed.c
+++ b/sha2/sha2speed.c
@@ -60,11 +60,11 @@
 
 
 int main(int argc, char **argv) {
-	SHA256_CTX	c256;
-	SHA384_CTX	c384;
-	SHA512_CTX	c512;
+	dtls_sha256_ctx	c256;
+	dtls_sha384_ctx	c384;
+	dtls_sha512_ctx	c512;
 	char		buf[BUFSIZE];
-	char		md[SHA512_DIGEST_STRING_LENGTH];
+	char		md[DTLS_SHA512_DIGEST_STRING_LENGTH];
 	int		bytes, blocks, rep, i, j;
 	struct timeval	start, end;
 	double		t, ave256, ave384, ave512;
@@ -97,18 +97,18 @@
 	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;
@@ -119,12 +119,12 @@
 
 		gettimeofday(&start, (struct timezone*)0);
 		for (j = 0; j < blocks; j++) {
-			SHA384_Update(&c384, (unsigned char*)buf, BUFSIZE);
+			dtls_sha384_update(&c384, (unsigned char*)buf, BUFSIZE);
 		}
 		if (bytes % BUFSIZE) {
-			SHA384_Update(&c384, (unsigned char*)buf, bytes % BUFSIZE);
+			dtls_sha384_update(&c384, (unsigned char*)buf, bytes % BUFSIZE);
 		}
-		SHA384_End(&c384, md);
+		dtls_sha384_end(&c384, md);
 		gettimeofday(&end, (struct timezone*)0);
 		t = ((end.tv_sec - start.tv_sec) * 1000000.0 + (end.tv_usec - start.tv_usec)) / 1000000.0;
 		ave384 += t;
@@ -135,12 +135,12 @@
 
 		gettimeofday(&start, (struct timezone*)0);
 		for (j = 0; j < blocks; j++) {
-			SHA512_Update(&c512, (unsigned char*)buf, BUFSIZE);
+			dtls_sha512_update(&c512, (unsigned char*)buf, BUFSIZE);
 		}
 		if (bytes % BUFSIZE) {
-			SHA512_Update(&c512, (unsigned char*)buf, bytes % BUFSIZE);
+			dtls_sha512_update(&c512, (unsigned char*)buf, bytes % BUFSIZE);
 		}
-		SHA512_End(&c512, md);
+		dtls_sha512_end(&c512, md);
 		gettimeofday(&end, (struct timezone*)0);
 		t = ((end.tv_sec - start.tv_sec) * 1000000.0 + (end.tv_usec - start.tv_usec)) / 1000000.0;
 		ave512 += t;
diff --git a/tests/pcap.c b/tests/pcap.c
index c49197c..90f7f18 100644
--- a/tests/pcap.c
+++ b/tests/pcap.c
@@ -44,7 +44,7 @@
 #if DTLS_VERSION == 0xfeff
   unsigned char statebuf[sizeof(md5_state_t) + sizeof(SHA_CTX)];
 #elif DTLS_VERSION == 0xfefd
-  unsigned char statebuf[sizeof(SHA256_CTX)];
+  unsigned char statebuf[sizeof(dtls_sha256_ctx)];
 #endif
 
   if (!hs_hash[0])
@@ -213,7 +213,7 @@
 #endif
   uint8 hash_buf[16 + SHA1_DIGEST_LENGTH];
 #elif DTLS_VERSION == 0xfefd
-  uint8 hash_buf[SHA256_DIGEST_LENGTH];
+  uint8 hash_buf[DTLS_SHA256_DIGEST_LENGTH];
 #endif
 #define verify_data_length 12
   int is_client;