- Moved from unsigned long to uint32_t throughout code

diff --git a/include/polarssl/aes.h b/include/polarssl/aes.h
index 80fd6d9..5f6c198 100644
--- a/include/polarssl/aes.h
+++ b/include/polarssl/aes.h
@@ -29,6 +29,13 @@
 
 #include <string.h>
 
+#ifdef _MSC_VER
+#include <basetsd.h>
+typedef UINT32 uint32_t;
+#else
+#include <inttypes.h>
+#endif
+
 #define AES_ENCRYPT     1
 #define AES_DECRYPT     0
 
@@ -41,8 +48,8 @@
 typedef struct
 {
     int nr;                     /*!<  number of rounds  */
-    unsigned long *rk;          /*!<  AES round keys    */
-    unsigned long buf[68];      /*!<  unaligned data    */
+    uint32_t *rk;               /*!<  AES round keys    */
+    uint32_t buf[68];           /*!<  unaligned data    */
 }
 aes_context;
 
diff --git a/include/polarssl/bignum.h b/include/polarssl/bignum.h
index a2039c7..092e185 100644
--- a/include/polarssl/bignum.h
+++ b/include/polarssl/bignum.h
@@ -32,6 +32,16 @@
 
 #include "config.h"
 
+#ifdef _MSC_VER
+#include <basetsd.h>
+typedef  INT16  int16_t;
+typedef UINT16 uint16_t;
+typedef UINT32 uint32_t;
+typedef UINT64 uint64_t;
+#else
+#include <inttypes.h>
+#endif
+
 #define POLARSSL_ERR_MPI_FILE_IO_ERROR                     -0x0002  /**< An error occurred while reading from or writing to a file. */
 #define POLARSSL_ERR_MPI_BAD_INPUT_DATA                    -0x0004  /**< Bad input parameters to function. */
 #define POLARSSL_ERR_MPI_INVALID_CHARACTER                 -0x0006  /**< There is an invalid character in the digit string. */
@@ -97,34 +107,29 @@
 #if defined(POLARSSL_HAVE_INT8)
 typedef   signed char  t_sint;
 typedef unsigned char  t_uint;
-typedef unsigned short t_udbl;
+typedef uint16_t       t_udbl;
 #else
 #if defined(POLARSSL_HAVE_INT16)
-typedef   signed short t_sint;
-typedef unsigned short t_uint;
-typedef unsigned long  t_udbl;
+typedef  int16_t t_sint;
+typedef uint16_t t_uint;
+typedef uint32_t t_udbl;
 #else
-  typedef   signed long t_sint;
-  typedef unsigned long t_uint;
-  #if defined(_MSC_VER) && defined(_M_IX86)
-  typedef unsigned __int64 t_udbl;
-  #else
-    #if defined(__GNUC__) && (                          \
+  typedef  int32_t t_sint;
+  typedef uint32_t t_uint;
+  #if ( defined(_MSC_VER) && defined(_M_IX86) )      || \
+      ( defined(__GNUC__) && (                          \
         defined(__amd64__) || defined(__x86_64__)    || \
         defined(__ppc64__) || defined(__powerpc64__) || \
         defined(__ia64__)  || defined(__alpha__)     || \
         (defined(__sparc__) && defined(__arch64__))  || \
-        defined(__s390x__) )
-    typedef unsigned int t_udbl __attribute__((mode(TI)));
-    #define POLARSSL_HAVE_LONGLONG
-    #else
-      #if defined(POLARSSL_HAVE_LONGLONG)
-      typedef unsigned long long t_udbl;
-      #endif
-    #endif
+        defined(__s390x__) ) )
+      #define POLARSSL_HAVE_INT64
   #endif
-#endif
-#endif
+  #if defined(POLARSSL_HAVE_INT64)
+    typedef uint64_t t_udbl;
+  #endif
+#endif /* POLARSSL_HAVE_INT16 */
+#endif /* POLARSSL_HAVE_INT8  */
 
 /**
  * \brief          MPI structure
diff --git a/include/polarssl/blowfish.h b/include/polarssl/blowfish.h
index dc469d0..7139c18 100644
--- a/include/polarssl/blowfish.h
+++ b/include/polarssl/blowfish.h
@@ -29,6 +29,13 @@
 
 #include <string.h>
 
+#ifdef _MSC_VER
+#include <basetsd.h>
+typedef UINT32 uint32_t;
+#else
+#include <inttypes.h>
+#endif
+
 #define BLOWFISH_ENCRYPT     1
 #define BLOWFISH_DECRYPT     0
 #define BLOWFISH_MAX_KEY     448
@@ -44,8 +51,8 @@
  */
 typedef struct
 {
-    unsigned long P[BLOWFISH_ROUNDS + 2];       /*!<  Blowfish round keys    */
-    unsigned long S[4][256];                    /*!<  key dependent S-boxes  */
+    uint32_t P[BLOWFISH_ROUNDS + 2];    /*!<  Blowfish round keys    */
+    uint32_t S[4][256];                 /*!<  key dependent S-boxes  */
 }
 blowfish_context;
 
diff --git a/include/polarssl/bn_mul.h b/include/polarssl/bn_mul.h
index f57d3a7..06324df 100644
--- a/include/polarssl/bn_mul.h
+++ b/include/polarssl/bn_mul.h
@@ -743,7 +743,7 @@
 #endif /* POLARSSL_HAVE_ASM */
 
 #if !defined(MULADDC_CORE)
-#if defined(POLARSSL_HAVE_LONGLONG)
+#if defined(POLARSSL_HAVE_INT64)
 
 #define MULADDC_INIT                    \
 {                                       \
@@ -751,7 +751,7 @@
     t_uint r0, r1;
 
 #define MULADDC_CORE                    \
-    r   = *(s++) * (t_udbl) b;           \
+    r   = *(s++) * (t_udbl) b;          \
     r0  = r;                            \
     r1  = r >> biL;                     \
     r0 += c;  r1 += (r0 <  c);          \
diff --git a/include/polarssl/config.h b/include/polarssl/config.h
index 543b96c..16257b5 100644
--- a/include/polarssl/config.h
+++ b/include/polarssl/config.h
@@ -61,12 +61,13 @@
  */
 
 /**
- * \def POLARSSL_HAVE_LONGLONG
+ * \def POLARSSL_HAVE_INT64
  *
- * The compiler supports the use of long long.
+ * The compiler supports the use of 64-bit types.
+ * Code automatically enables on known working systems.
  *
- * Uncomment if the compiler supports long long.
-#define POLARSSL_HAVE_LONGLONG
+ * Uncomment if the compiler supports 64-bit data types.
+#define POLARSSL_HAVE_INT64
  */
 
 /**
diff --git a/include/polarssl/des.h b/include/polarssl/des.h
index 653e68b..b649ccf 100644
--- a/include/polarssl/des.h
+++ b/include/polarssl/des.h
@@ -29,6 +29,13 @@
 
 #include <string.h>
 
+#ifdef _MSC_VER
+#include <basetsd.h>
+typedef UINT32 uint32_t;
+#else
+#include <inttypes.h>
+#endif
+
 #define DES_ENCRYPT     1
 #define DES_DECRYPT     0
 
@@ -42,7 +49,7 @@
 typedef struct
 {
     int mode;                   /*!<  encrypt/decrypt   */
-    unsigned long sk[32];       /*!<  DES subkeys       */
+    uint32_t sk[32];            /*!<  DES subkeys       */
 }
 des_context;
 
@@ -52,7 +59,7 @@
 typedef struct
 {
     int mode;                   /*!<  encrypt/decrypt   */
-    unsigned long sk[96];       /*!<  3DES subkeys      */
+    uint32_t sk[96];            /*!<  3DES subkeys      */
 }
 des3_context;
 
diff --git a/include/polarssl/md4.h b/include/polarssl/md4.h
index 2bd35ea..641edf1 100644
--- a/include/polarssl/md4.h
+++ b/include/polarssl/md4.h
@@ -29,6 +29,13 @@
 
 #include <string.h>
 
+#ifdef _MSC_VER
+#include <basetsd.h>
+typedef UINT32 uint32_t;
+#else
+#include <inttypes.h>
+#endif
+
 #define POLARSSL_ERR_MD4_FILE_IO_ERROR                 -0x0072  /**< Read/write error in file. */
 
 /**
@@ -36,8 +43,8 @@
  */
 typedef struct
 {
-    unsigned long total[2];     /*!< number of bytes processed  */
-    unsigned long state[4];     /*!< intermediate digest state  */
+    uint32_t total[2];          /*!< number of bytes processed  */
+    uint32_t state[4];          /*!< intermediate digest state  */
     unsigned char buffer[64];   /*!< data block being processed */
 
     unsigned char ipad[64];     /*!< HMAC: inner padding        */
diff --git a/include/polarssl/md5.h b/include/polarssl/md5.h
index 936e9c9..2e97c2b 100644
--- a/include/polarssl/md5.h
+++ b/include/polarssl/md5.h
@@ -29,6 +29,13 @@
 
 #include <string.h>
 
+#ifdef _MSC_VER
+#include <basetsd.h>
+typedef UINT32 uint32_t;
+#else
+#include <inttypes.h>
+#endif
+
 #define POLARSSL_ERR_MD5_FILE_IO_ERROR                 -0x0074  /**< Read/write error in file. */
 
 /**
@@ -36,8 +43,8 @@
  */
 typedef struct
 {
-    unsigned long total[2];     /*!< number of bytes processed  */
-    unsigned long state[4];     /*!< intermediate digest state  */
+    uint32_t total[2];          /*!< number of bytes processed  */
+    uint32_t state[4];          /*!< intermediate digest state  */
     unsigned char buffer[64];   /*!< data block being processed */
 
     unsigned char ipad[64];     /*!< HMAC: inner padding        */
diff --git a/include/polarssl/padlock.h b/include/polarssl/padlock.h
index ce13570..9df75cc 100644
--- a/include/polarssl/padlock.h
+++ b/include/polarssl/padlock.h
@@ -37,12 +37,20 @@
 #define POLARSSL_HAVE_X86
 #endif
 
+#ifdef _MSC_VER
+#include <basetsd.h>
+typedef INT32 int32_t;
+#else
+#include <inttypes.h>
+#endif
+
+
 #define PADLOCK_RNG 0x000C
 #define PADLOCK_ACE 0x00C0
 #define PADLOCK_PHE 0x0C00
 #define PADLOCK_PMM 0x3000
 
-#define PADLOCK_ALIGN16(x) (unsigned long *) (16 + ((long) x & ~15))
+#define PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) x & ~15))
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/include/polarssl/pbkdf2.h b/include/polarssl/pbkdf2.h
index 5a23150..af84c13 100644
--- a/include/polarssl/pbkdf2.h
+++ b/include/polarssl/pbkdf2.h
@@ -33,6 +33,13 @@
 
 #include "md.h"
 
+#ifdef _MSC_VER
+#include <basetsd.h>
+typedef UINT32 uint32_t;
+#else
+#include <inttypes.h>
+#endif
+
 #define POLARSSL_ERR_PBKDF2_BAD_INPUT_DATA                 -0x007C  /**< Bad input parameters to function. */
 
 #ifdef __cplusplus
@@ -56,7 +63,7 @@
 int pbkdf2_hmac( md_context_t *ctx, const unsigned char *password,
                  size_t plen, const unsigned char *salt, size_t slen,
                  unsigned int iteration_count,
-                 unsigned long key_length, unsigned char *output );
+                 uint32_t key_length, unsigned char *output );
 
 
 /**
diff --git a/include/polarssl/sha1.h b/include/polarssl/sha1.h
index 0d5e67e..45ffadc 100644
--- a/include/polarssl/sha1.h
+++ b/include/polarssl/sha1.h
@@ -29,6 +29,13 @@
 
 #include <string.h>
 
+#ifdef _MSC_VER
+#include <basetsd.h>
+typedef UINT32 uint32_t;
+#else
+#include <inttypes.h>
+#endif
+
 #define POLARSSL_ERR_SHA1_FILE_IO_ERROR                -0x0076  /**< Read/write error in file. */
 
 /**
@@ -36,8 +43,8 @@
  */
 typedef struct
 {
-    unsigned long total[2];     /*!< number of bytes processed  */
-    unsigned long state[5];     /*!< intermediate digest state  */
+    uint32_t total[2];          /*!< number of bytes processed  */
+    uint32_t state[5];          /*!< intermediate digest state  */
     unsigned char buffer[64];   /*!< data block being processed */
 
     unsigned char ipad[64];     /*!< HMAC: inner padding        */
diff --git a/include/polarssl/sha2.h b/include/polarssl/sha2.h
index 811b0fd..054988d 100644
--- a/include/polarssl/sha2.h
+++ b/include/polarssl/sha2.h
@@ -29,6 +29,13 @@
 
 #include <string.h>
 
+#ifdef _MSC_VER
+#include <basetsd.h>
+typedef UINT32 uint32_t;
+#else
+#include <inttypes.h>
+#endif
+
 #define POLARSSL_ERR_SHA2_FILE_IO_ERROR                -0x0078  /**< Read/write error in file. */
 
 /**
@@ -36,8 +43,8 @@
  */
 typedef struct
 {
-    unsigned long total[2];     /*!< number of bytes processed  */
-    unsigned long state[8];     /*!< intermediate digest state  */
+    uint32_t total[2];          /*!< number of bytes processed  */
+    uint32_t state[8];          /*!< intermediate digest state  */
     unsigned char buffer[64];   /*!< data block being processed */
 
     unsigned char ipad[64];     /*!< HMAC: inner padding        */
diff --git a/include/polarssl/sha4.h b/include/polarssl/sha4.h
index dafebec..6aae124 100644
--- a/include/polarssl/sha4.h
+++ b/include/polarssl/sha4.h
@@ -29,23 +29,23 @@
 
 #include <string.h>
 
-#define POLARSSL_ERR_SHA4_FILE_IO_ERROR                -0x007A  /**< Read/write error in file. */
-
 #if defined(_MSC_VER) || defined(__WATCOMC__)
   #define UL64(x) x##ui64
-  #define long64 __int64
+  typedef unsigned __int64 uint64_t;
 #else
+  #include <inttypes.h>
   #define UL64(x) x##ULL
-  #define long64 long long
 #endif
 
+#define POLARSSL_ERR_SHA4_FILE_IO_ERROR                -0x007A  /**< Read/write error in file. */
+
 /**
  * \brief          SHA-512 context structure
  */
 typedef struct
 {
-    unsigned long64 total[2];    /*!< number of bytes processed  */
-    unsigned long64 state[8];    /*!< intermediate digest state  */
+    uint64_t total[2];          /*!< number of bytes processed  */
+    uint64_t state[8];          /*!< intermediate digest state  */
     unsigned char buffer[128];  /*!< data block being processed */
 
     unsigned char ipad[128];    /*!< HMAC: inner padding        */
diff --git a/include/polarssl/ssl.h b/include/polarssl/ssl.h
index d483208..9feacdd 100644
--- a/include/polarssl/ssl.h
+++ b/include/polarssl/ssl.h
@@ -330,8 +330,8 @@
     unsigned char mac_enc[32];          /*!<  MAC (encryption)        */
     unsigned char mac_dec[32];          /*!<  MAC (decryption)        */
 
-    unsigned long ctx_enc[134];         /*!<  encryption context      */
-    unsigned long ctx_dec[134];         /*!<  decryption context      */
+    uint32_t ctx_enc[134];              /*!<  encryption context      */
+    uint32_t ctx_dec[134];              /*!<  decryption context      */
 
     /*
      * Session specific compression layer