diff -uNr polarssl-1.2.7/include/polarssl/aes.h polarssl.new/include/polarssl/aes.h
--- polarssl-1.2.7/include/polarssl/aes.h	2013-04-13 03:56:17.000000000 -0600
+++ polarssl.new/include/polarssl/aes.h	2013-06-07 17:43:56.000000000 -0600
@@ -29,6 +29,8 @@
 
 #include <string.h>
 
+#include "config.h"
+
 #ifdef _MSC_VER
 #include <basetsd.h>
 typedef UINT32 uint32_t;
@@ -42,6 +44,12 @@
 #define POLARSSL_ERR_AES_INVALID_KEY_LENGTH                -0x0020  /**< Invalid key length. */
 #define POLARSSL_ERR_AES_INVALID_INPUT_LENGTH              -0x0022  /**< Invalid data input length. */
 
+#ifdef POLARSSL_AES_ALT
+
+#include "polarssl/aes_alt.h"
+
+#else
+
 /**
  * \brief          AES context structure
  */
@@ -169,6 +177,17 @@
                        unsigned char stream_block[16],
                        const unsigned char *input,
                        unsigned char *output );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* POLARSSL_AES_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /**
  * \brief          Checkup routine
  *
diff -uNr polarssl-1.2.7/include/polarssl/aes_alt.h polarssl.new/include/polarssl/aes_alt.h
--- polarssl-1.2.7/include/polarssl/aes_alt.h	1969-12-31 17:00:00.000000000 -0700
+++ polarssl.new/include/polarssl/aes_alt.h	2013-06-07 18:18:37.000000000 -0600
@@ -0,0 +1,183 @@
+/*
+ * Use OpenSSL implementation of AES methods to get asm and hardware acceleration.
+ * Don't include this file directly, it is included by aes.h when
+ * POLARSSL_AES_ALT is defined.
+ */
+
+#ifdef _MSC_VER
+#include <basetsd.h>
+typedef UINT32 uint32_t;
+#else
+#include <inttypes.h>
+#endif
+
+#define OPENSSL_AES_BLOCK_SIZE 16
+#define OPENSSL_AES_MAXNR 14
+
+/**
+ * \brief          AES context structure
+ */
+typedef struct
+{
+  uint32_t rd_key[4 * (OPENSSL_AES_MAXNR + 1)];
+  int rounds;
+}
+aes_context;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(POLARSSL_USE_OPENSSL_AES_NI)
+
+int aesni_set_encrypt_key(const unsigned char *userKey, const int bits,
+			  aes_context *key);
+int aesni_set_decrypt_key(const unsigned char *userKey, const int bits,
+			  aes_context *key);
+void aesni_ecb_encrypt(const unsigned char *in, unsigned char *out,
+		       size_t length, const aes_context *key, const int enc);
+void aesni_cbc_encrypt(const unsigned char *in, unsigned char *out,
+		       size_t length, const aes_context *key,
+		       unsigned char *ivec, const int enc);
+
+#define OPENSSL_AES_SET_ENCRYPT_KEY(k,b,c)    aesni_set_encrypt_key(k,b,c)
+#define OPENSSL_AES_SET_DECRYPT_KEY(k,b,c)    aesni_set_decrypt_key(k,b,c)
+#define OPENSSL_AES_ECB_ENCRYPT(i,o,k)        aesni_ecb_encrypt(i,o,16,k,AES_ENCRYPT)
+#define OPENSSL_AES_ECB_DECRYPT(i,o,k)        aesni_ecb_encrypt(i,o,16,k,AES_DECRYPT)
+#define OPENSSL_AES_CBC_ENCRYPT(i,o,l,k,iv,e) aesni_cbc_encrypt(i,o,l,k,iv,e)
+
+#else
+
+int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
+			aes_context *key);
+int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
+			aes_context *key);
+
+void AES_encrypt(const unsigned char *in, unsigned char *out, const aes_context *key);
+void AES_decrypt(const unsigned char *in, unsigned char *out, const aes_context *key);
+
+
+#define OPENSSL_AES_SET_ENCRYPT_KEY(k,b,c)    AES_set_encrypt_key(k,b,c)
+#define OPENSSL_AES_SET_DECRYPT_KEY(k,b,c)    AES_set_decrypt_key(k,b,c)
+#define OPENSSL_AES_ECB_ENCRYPT(i,o,k)        AES_encrypt(i,o,k)
+#define OPENSSL_AES_ECB_DECRYPT(i,o,k)        AES_decrypt(i,o,k)
+
+#endif
+
+/**
+ * \brief          AES key schedule (encryption)
+ *
+ * \param ctx      AES context to be initialized
+ * \param key      encryption key
+ * \param keysize  must be 128, 192 or 256
+ *
+ * \return         0 if successful, or POLARSSL_ERR_AES_INVALID_KEY_LENGTH
+ */
+static inline int aes_setkey_enc( aes_context *ctx, const unsigned char *key, const unsigned int keysize )
+{
+  const int status = OPENSSL_AES_SET_ENCRYPT_KEY(key, keysize, ctx);
+  return status ? POLARSSL_ERR_AES_INVALID_KEY_LENGTH : 0;
+}
+
+/**
+ * \brief          AES key schedule (decryption)
+ *
+ * \param ctx      AES context to be initialized
+ * \param key      decryption key
+ * \param keysize  must be 128, 192 or 256
+ *
+ * \return         0 if successful, or POLARSSL_ERR_AES_INVALID_KEY_LENGTH
+ */
+static inline int aes_setkey_dec( aes_context *ctx, const unsigned char *key, const unsigned int keysize )
+{
+  const int status = OPENSSL_AES_SET_DECRYPT_KEY(key, keysize, ctx);
+  return status ? POLARSSL_ERR_AES_INVALID_KEY_LENGTH : 0;
+}
+
+/**
+ * \brief          AES-ECB block encryption/decryption
+ *
+ * \param ctx      AES context
+ * \param mode     AES_ENCRYPT or AES_DECRYPT
+ * \param input    16-byte input block
+ * \param output   16-byte output block
+ *
+ * \return         0 if successful
+ */
+static inline int aes_crypt_ecb( aes_context *ctx,
+				 const int mode,
+				 const unsigned char input[16],
+				 unsigned char output[16] )
+{
+  if (mode == AES_DECRYPT)
+    OPENSSL_AES_ECB_DECRYPT(input, output, ctx);
+  else
+    OPENSSL_AES_ECB_ENCRYPT(input, output, ctx);
+  return 0;
+}
+
+/**
+ * \brief          AES-CBC buffer encryption/decryption
+ *                 Length should be a multiple of the block
+ *                 size (16 bytes)
+ *
+ * \param ctx      AES context
+ * \param mode     AES_ENCRYPT or AES_DECRYPT
+ * \param length   length of the input data
+ * \param iv       initialization vector (updated after use)
+ * \param input    buffer holding the input data
+ * \param output   buffer holding the output data
+ *
+ * \return         0 if successful, or POLARSSL_ERR_AES_INVALID_INPUT_LENGTH
+ */
+static inline int aes_crypt_cbc( aes_context *ctx,
+				 const int mode,
+				 size_t length,
+				 unsigned char iv[16],
+				 const unsigned char *input,
+				 unsigned char *output )
+{
+#ifdef OPENSSL_AES_CBC_ENCRYPT
+  if (length & (OPENSSL_AES_BLOCK_SIZE-1))
+    return POLARSSL_ERR_AES_INVALID_INPUT_LENGTH;
+  OPENSSL_AES_CBC_ENCRYPT(input, output, length, ctx, iv, mode);
+  return 0;
+#else
+    int i;
+    unsigned char temp[16];
+    if (length & (OPENSSL_AES_BLOCK_SIZE-1))
+      return POLARSSL_ERR_AES_INVALID_INPUT_LENGTH;
+    if( mode == AES_DECRYPT )
+    {
+        while( length > 0 )
+        {
+            memcpy( temp, input, 16 );
+	    OPENSSL_AES_ECB_DECRYPT(input, output, ctx);
+            for( i = 0; i < 16; i++ )
+                output[i] = (unsigned char)( output[i] ^ iv[i] );
+            memcpy( iv, temp, 16 );
+            input  += 16;
+            output += 16;
+            length -= 16;
+        }
+    }
+    else
+    {
+        while( length > 0 )
+        {
+            for( i = 0; i < 16; i++ )
+                output[i] = (unsigned char)( input[i] ^ iv[i] );
+	    OPENSSL_AES_ECB_ENCRYPT(output, output, ctx);
+            memcpy( iv, output, 16 );
+            input  += 16;
+            output += 16;
+            length -= 16;
+        }
+    }
+    return( 0 );
+#endif
+}
+
+#ifdef __cplusplus
+}
+#endif
diff -uNr polarssl-1.2.7/include/polarssl/sha1.h polarssl.new/include/polarssl/sha1.h
--- polarssl-1.2.7/include/polarssl/sha1.h	2013-04-13 03:56:17.000000000 -0600
+++ polarssl.new/include/polarssl/sha1.h	2013-06-07 17:43:56.000000000 -0600
@@ -29,6 +29,8 @@
 
 #include <string.h>
 
+#include "config.h"
+
 #ifdef _MSC_VER
 #include <basetsd.h>
 typedef UINT32 uint32_t;
@@ -38,6 +40,12 @@
 
 #define POLARSSL_ERR_SHA1_FILE_IO_ERROR                -0x0076  /**< Read/write error in file. */
 
+#ifdef POLARSSL_SHA1_ALT
+
+#include "polarssl/sha1_alt.h"
+
+#else
+
 /**
  * \brief          SHA-1 context structure
  */
@@ -80,6 +88,19 @@
  */
 void sha1_finish( sha1_context *ctx, unsigned char output[20] );
 
+/* Internal use */
+void sha1_process( sha1_context *ctx, const unsigned char data[64] );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* POLARSSL_SHA1_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /**
  * \brief          Output = SHA-1( input buffer )
  *
@@ -152,9 +173,6 @@
  */
 int sha1_self_test( int verbose );
 
-/* Internal use */
-void sha1_process( sha1_context *ctx, const unsigned char data[64] );
-
 #ifdef __cplusplus
 }
 #endif
diff -uNr polarssl-1.2.7/include/polarssl/sha1_alt.h polarssl.new/include/polarssl/sha1_alt.h
--- polarssl-1.2.7/include/polarssl/sha1_alt.h	1969-12-31 17:00:00.000000000 -0700
+++ polarssl.new/include/polarssl/sha1_alt.h	2013-06-07 17:43:56.000000000 -0600
@@ -0,0 +1,56 @@
+/*
+ * Use OpenSSL implementation of SHA1 methods to get asm and hardware acceleration.
+ * Don't include this file directly, it is included by sha1.h when
+ * POLARSSL_SHA1_ALT is defined.
+ */
+
+#include "polarssl/sha_openssl.h"
+
+struct openssl_sha_context {
+  SHA_LONG h0,h1,h2,h3,h4;
+  SHA_LONG Nl,Nh;
+  SHA_LONG data[SHA_LBLOCK];
+  unsigned int num;
+};
+
+typedef struct
+{
+  struct openssl_sha_context octx;
+
+  unsigned char ipad[64];     /*!< HMAC: inner padding        */
+  unsigned char opad[64];     /*!< HMAC: outer padding        */
+}
+sha1_context;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int SHA1_Init(struct openssl_sha_context *c);
+int SHA1_Update(struct openssl_sha_context *c, const void *data, size_t len);
+int SHA1_Final(unsigned char *md, struct openssl_sha_context *c);
+void sha1_block_data_order(struct openssl_sha_context *c, const void *p, size_t num);
+
+static inline void sha1_starts( sha1_context *ctx )
+{
+  SHA1_Init(&ctx->octx);
+}
+
+static inline void sha1_update( sha1_context *ctx, const unsigned char *input, size_t ilen )
+{
+  SHA1_Update(&ctx->octx, input, ilen);
+}
+
+static inline void sha1_finish( sha1_context *ctx, unsigned char output[20] )
+{
+  SHA1_Final(output, &ctx->octx);
+}
+
+static inline void sha1_process( sha1_context *ctx, const unsigned char data[64] )
+{
+  sha1_block_data_order(&ctx->octx, data, 1);
+}
+
+#ifdef __cplusplus
+}
+#endif
diff -uNr polarssl-1.2.7/include/polarssl/sha2.h polarssl.new/include/polarssl/sha2.h
--- polarssl-1.2.7/include/polarssl/sha2.h	2013-04-13 03:56:17.000000000 -0600
+++ polarssl.new/include/polarssl/sha2.h	2013-06-07 17:43:56.000000000 -0600
@@ -29,6 +29,8 @@
 
 #include <string.h>
 
+#include "config.h"
+
 #ifdef _MSC_VER
 #include <basetsd.h>
 typedef UINT32 uint32_t;
@@ -38,6 +40,12 @@
 
 #define POLARSSL_ERR_SHA2_FILE_IO_ERROR                -0x0078  /**< Read/write error in file. */
 
+#ifdef POLARSSL_SHA2_ALT
+
+#include "polarssl/sha2_alt.h"
+
+#else
+
 /**
  * \brief          SHA-256 context structure
  */
@@ -82,6 +90,19 @@
  */
 void sha2_finish( sha2_context *ctx, unsigned char output[32] );
 
+/* Internal use */
+void sha2_process( sha2_context *ctx, const unsigned char data[64] );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* POLARSSL_SHA2_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /**
  * \brief          Output = SHA-256( input buffer )
  *
@@ -160,9 +181,6 @@
  */
 int sha2_self_test( int verbose );
 
-/* Internal use */
-void sha2_process( sha2_context *ctx, const unsigned char data[64] );
-
 #ifdef __cplusplus
 }
 #endif
diff -uNr polarssl-1.2.7/include/polarssl/sha2_alt.h polarssl.new/include/polarssl/sha2_alt.h
--- polarssl-1.2.7/include/polarssl/sha2_alt.h	1969-12-31 17:00:00.000000000 -0700
+++ polarssl.new/include/polarssl/sha2_alt.h	2013-06-07 17:43:56.000000000 -0600
@@ -0,0 +1,71 @@
+/*
+ * Use OpenSSL implementation of SHA2 methods to get asm and hardware acceleration.
+ * Don't include this file directly, it is included by sha2.h when
+ * POLARSSL_SHA2_ALT is defined.
+ */
+
+#include "polarssl/sha_openssl.h"
+
+struct openssl_sha2_context {
+  SHA_LONG h[8];
+  SHA_LONG Nl,Nh;
+  SHA_LONG data[SHA_LBLOCK];
+  unsigned int num,md_len;
+};
+
+typedef struct
+{
+  struct openssl_sha2_context octx;
+
+  unsigned char ipad[64];     /*!< HMAC: inner padding        */
+  unsigned char opad[64];     /*!< HMAC: outer padding        */
+  int is224;                  /*!< 0 => SHA-256, else SHA-224 */
+}
+sha2_context;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int SHA224_Init(struct openssl_sha2_context *c);
+int SHA224_Update(struct openssl_sha2_context *c, const void *data, size_t len);
+int SHA224_Final(unsigned char *md, struct openssl_sha2_context *c);
+
+int SHA256_Init(struct openssl_sha2_context *c);
+int SHA256_Update(struct openssl_sha2_context *c, const void *data, size_t len);
+int SHA256_Final(unsigned char *md, struct openssl_sha2_context *c);
+
+void sha256_block_data_order(struct openssl_sha2_context *c, const void *p, size_t num);
+
+static inline void sha2_starts( sha2_context *ctx, int is224 )
+{
+  if ((ctx->is224 = is224))
+    SHA224_Init(&ctx->octx);
+  else
+    SHA256_Init(&ctx->octx);
+}
+
+static inline void sha2_update( sha2_context *ctx, const unsigned char *input, size_t ilen )
+{
+  if (ctx->is224)
+    SHA224_Update(&ctx->octx, input, ilen);
+  else
+    SHA256_Update(&ctx->octx, input, ilen);
+}
+
+static inline void sha2_finish( sha2_context *ctx, unsigned char output[32] )
+{
+  if (ctx->is224)
+    SHA224_Final(output, &ctx->octx);
+  else
+    SHA256_Final(output, &ctx->octx);
+}
+
+static inline void sha2_process( sha2_context *ctx, const unsigned char data[64] )
+{
+  sha256_block_data_order(&ctx->octx, data, 1);
+}
+
+#ifdef __cplusplus
+}
+#endif
diff -uNr polarssl-1.2.7/include/polarssl/sha4.h polarssl.new/include/polarssl/sha4.h
--- polarssl-1.2.7/include/polarssl/sha4.h	2013-04-13 03:56:17.000000000 -0600
+++ polarssl.new/include/polarssl/sha4.h	2013-06-07 17:43:56.000000000 -0600
@@ -29,6 +29,8 @@
 
 #include <string.h>
 
+#include "config.h"
+
 #if defined(_MSC_VER) || defined(__WATCOMC__)
   #define UL64(x) x##ui64
   typedef unsigned __int64 uint64_t;
@@ -39,6 +41,12 @@
 
 #define POLARSSL_ERR_SHA4_FILE_IO_ERROR                -0x007A  /**< Read/write error in file. */
 
+#ifdef POLARSSL_SHA4_ALT
+
+#include "polarssl/sha4_alt.h"
+
+#else
+
 /**
  * \brief          SHA-512 context structure
  */
@@ -83,6 +91,16 @@
  */
 void sha4_finish( sha4_context *ctx, unsigned char output[64] );
 
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* POLARSSL_SHA4_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /**
  * \brief          Output = SHA-512( input buffer )
  *
diff -uNr polarssl-1.2.7/include/polarssl/sha4_alt.h polarssl.new/include/polarssl/sha4_alt.h
--- polarssl-1.2.7/include/polarssl/sha4_alt.h	1969-12-31 17:00:00.000000000 -0700
+++ polarssl.new/include/polarssl/sha4_alt.h	2013-06-07 17:43:56.000000000 -0600
@@ -0,0 +1,67 @@
+/*
+ * Use OpenSSL implementation of SHA4 methods to get asm and hardware acceleration.
+ * Don't include this file directly, it is included by sha4.h when
+ * POLARSSL_SHA4_ALT is defined.
+ */
+
+#include "polarssl/sha_openssl.h"
+
+struct openssl_sha4_context {
+  SHA_LONG64 h[8];
+  SHA_LONG64 Nl,Nh;
+  union {
+    SHA_LONG64 d[SHA_LBLOCK];
+    unsigned char p[SHA512_CBLOCK];
+  } u;
+  unsigned int num,md_len;
+};
+
+typedef struct
+{
+  struct openssl_sha4_context octx;
+
+  unsigned char ipad[128];    /*!< HMAC: inner padding        */
+  unsigned char opad[128];    /*!< HMAC: outer padding        */
+  int is384;                  /*!< 0 => SHA-512, else SHA-384 */
+}
+sha4_context;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int SHA384_Init(struct openssl_sha4_context *c);
+int SHA384_Update(struct openssl_sha4_context *c, const void *data, size_t len);
+int SHA384_Final(unsigned char *md, struct openssl_sha4_context *c);
+
+int SHA512_Init(struct openssl_sha4_context *c);
+int SHA512_Update(struct openssl_sha4_context *c, const void *data, size_t len);
+int SHA512_Final(unsigned char *md, struct openssl_sha4_context *c);
+
+static inline void sha4_starts( sha4_context *ctx, int is384 )
+{
+  if ((ctx->is384 = is384))
+    SHA384_Init(&ctx->octx);
+  else
+    SHA512_Init(&ctx->octx);
+}
+
+static inline void sha4_update( sha4_context *ctx, const unsigned char *input, size_t ilen )
+{
+  if (ctx->is384)
+    SHA384_Update(&ctx->octx, input, ilen);
+  else
+    SHA512_Update(&ctx->octx, input, ilen);
+}
+
+static inline void sha4_finish( sha4_context *ctx, unsigned char output[64] )
+{
+  if (ctx->is384)
+    SHA384_Final(output, &ctx->octx);
+  else
+    SHA512_Final(output, &ctx->octx);
+}
+
+#ifdef __cplusplus
+}
+#endif
diff -uNr polarssl-1.2.7/include/polarssl/sha_openssl.h polarssl.new/include/polarssl/sha_openssl.h
--- polarssl-1.2.7/include/polarssl/sha_openssl.h	1969-12-31 17:00:00.000000000 -0700
+++ polarssl.new/include/polarssl/sha_openssl.h	2013-06-07 17:43:56.000000000 -0600
@@ -0,0 +1,42 @@
+/*
+ * Common header file for all OpenSSL-imported SHA methods
+ */
+
+#ifndef POLARSSL_SHA_OPENSSL_H
+#define POLARSSL_SHA_OPENSSL_H
+
+/*
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ * ! SHA_LONG has to be at least 32 bits wide. If it's wider, then !
+ * ! SHA_LONG_LOG2 has to be defined along.                        !
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ */
+
+#if defined(__LP32__)
+#define SHA_LONG unsigned long
+#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
+#define SHA_LONG unsigned long
+#define SHA_LONG_LOG2 3
+#else
+#define SHA_LONG unsigned int
+#endif
+
+#define SHA_LBLOCK	16
+
+/*
+ * Unlike 32-bit digest algorithms, SHA-512 *relies* on SHA_LONG64
+ * being exactly 64-bit wide. See Implementation Notes in sha512.c
+ * for further details.
+ */
+#define SHA512_CBLOCK	(SHA_LBLOCK*8)	/* SHA-512 treats input data as a
+					 * contiguous array of 64 bit
+					 * wide big-endian values. */
+#if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__)
+#define SHA_LONG64 unsigned __int64
+#elif defined(__arch64__)
+#define SHA_LONG64 unsigned long
+#else
+#define SHA_LONG64 unsigned long long
+#endif
+
+#endif
diff -uNr polarssl-1.2.7/library/aes.c polarssl.new/library/aes.c
--- polarssl-1.2.7/library/aes.c	2013-04-13 03:56:17.000000000 -0600
+++ polarssl.new/library/aes.c	2013-06-07 17:43:56.000000000 -0600
@@ -38,6 +38,8 @@
 #include "polarssl/padlock.h"
 #endif
 
+#ifndef POLARSSL_AES_ALT
+
 /*
  * 32-bit integer manipulation macros (little endian)
  */
@@ -914,6 +916,7 @@
     return( 0 );
 }
 #endif /* POLARSSL_CIPHER_MODE_CTR */
+#endif /* !POLARSSL_AES_ALT */
 
 #if defined(POLARSSL_SELF_TEST)
 
diff -uNr polarssl-1.2.7/library/sha1.c polarssl.new/library/sha1.c
--- polarssl-1.2.7/library/sha1.c	2013-04-13 03:56:17.000000000 -0600
+++ polarssl.new/library/sha1.c	2013-06-07 17:43:56.000000000 -0600
@@ -38,6 +38,8 @@
 #include <stdio.h>
 #endif
 
+#ifndef POLARSSL_SHA1_ALT
+
 /*
  * 32-bit integer manipulation macros (big endian)
  */
@@ -313,6 +315,8 @@
     PUT_UINT32_BE( ctx->state[4], output, 16 );
 }
 
+#endif /* !POLARSSL_SHA1_ALT */
+
 /*
  * output = SHA-1( input buffer )
  */
diff -uNr polarssl-1.2.7/library/sha2.c polarssl.new/library/sha2.c
--- polarssl-1.2.7/library/sha2.c	2013-04-13 03:56:17.000000000 -0600
+++ polarssl.new/library/sha2.c	2013-06-07 17:43:56.000000000 -0600
@@ -38,6 +38,8 @@
 #include <stdio.h>
 #endif
 
+#ifndef POLARSSL_SHA2_ALT
+
 /*
  * 32-bit integer manipulation macros (big endian)
  */
@@ -314,6 +316,8 @@
         PUT_UINT32_BE( ctx->state[7], output, 28 );
 }
 
+#endif /* !POLARSSL_SHA2_ALT */
+
 /*
  * output = SHA-256( input buffer )
  */
diff -uNr polarssl-1.2.7/library/sha4.c polarssl.new/library/sha4.c
--- polarssl-1.2.7/library/sha4.c	2013-04-13 03:56:17.000000000 -0600
+++ polarssl.new/library/sha4.c	2013-06-07 17:43:56.000000000 -0600
@@ -38,6 +38,8 @@
 #include <stdio.h>
 #endif
 
+#ifndef POLARSSL_SHA4_ALT
+
 /*
  * 64-bit integer manipulation macros (big endian)
  */
@@ -312,6 +314,8 @@
     }
 }
 
+#endif /* !POLARSSL_SHA4_ALT */
+
 /*
  * output = SHA-512( input buffer )
  */
diff -uNr polarssl-1.2.7/library/ssl_tls.c polarssl.new/library/ssl_tls.c
--- polarssl-1.2.7/library/ssl_tls.c	2013-04-13 03:56:17.000000000 -0600
+++ polarssl.new/library/ssl_tls.c	2013-06-07 17:43:56.000000000 -0600
@@ -2550,8 +2550,10 @@
     SSL_DEBUG_BUF( 4, "finished  md5 state", (unsigned char *)
                     md5.state, sizeof(  md5.state ) );
 
+#ifndef POLARSSL_SHA1_ALT
     SSL_DEBUG_BUF( 4, "finished sha1 state", (unsigned char *)
                    sha1.state, sizeof( sha1.state ) );
+#endif
 
     sender = ( from == SSL_IS_CLIENT ) ? (char *) "CLNT"
                                        : (char *) "SRVR";
@@ -2621,8 +2623,10 @@
     SSL_DEBUG_BUF( 4, "finished  md5 state", (unsigned char *)
                     md5.state, sizeof(  md5.state ) );
 
+#ifndef POLARSSL_SHA1_ALT
     SSL_DEBUG_BUF( 4, "finished sha1 state", (unsigned char *)
                    sha1.state, sizeof( sha1.state ) );
+#endif
 
     sender = ( from == SSL_IS_CLIENT )
              ? (char *) "client finished"
@@ -2666,8 +2670,10 @@
      *               Hash( handshake ) )[0.11]
      */
 
+#ifndef POLARSSL_SHA2_ALT
     SSL_DEBUG_BUF( 4, "finished sha2 state", (unsigned char *)
                    sha2.state, sizeof( sha2.state ) );
+#endif
 
     sender = ( from == SSL_IS_CLIENT )
              ? (char *) "client finished"
@@ -2710,8 +2716,10 @@
      *               Hash( handshake ) )[0.11]
      */
 
+#ifndef POLARSSL_SHA4_ALT
     SSL_DEBUG_BUF( 4, "finished sha4 state", (unsigned char *)
                    sha4.state, sizeof( sha4.state ) );
+#endif
 
     sender = ( from == SSL_IS_CLIENT )
              ? (char *) "client finished"
diff -uNr polarssl-1.2.7/tests/suites/test_suite_aes.function polarssl.new/tests/suites/test_suite_aes.function
--- polarssl-1.2.7/tests/suites/test_suite_aes.function	2013-04-13 03:56:17.000000000 -0600
+++ polarssl.new/tests/suites/test_suite_aes.function	2013-06-07 17:43:56.000000000 -0600
@@ -1,4 +1,5 @@
 BEGIN_HEADER
+#include <polarssl/config.h>
 #include <polarssl/aes.h>
 END_HEADER
 
diff -uNr polarssl-1.2.7/tests/suites/test_suite_ctr_drbg.function polarssl.new/tests/suites/test_suite_ctr_drbg.function
--- polarssl-1.2.7/tests/suites/test_suite_ctr_drbg.function	2013-04-13 03:56:17.000000000 -0600
+++ polarssl.new/tests/suites/test_suite_ctr_drbg.function	2013-06-07 17:43:56.000000000 -0600
@@ -1,4 +1,5 @@
 BEGIN_HEADER
+#include <polarssl/config.h>
 #include <polarssl/ctr_drbg.h>
 
 int test_offset;
