Fix formatting: remove trailing spaces, #endif with comments (> 10 lines)
diff --git a/include/polarssl/asn1.h b/include/polarssl/asn1.h
index 517cd5b..11f256c 100644
--- a/include/polarssl/asn1.h
+++ b/include/polarssl/asn1.h
@@ -39,15 +39,15 @@
 
 #include <string.h>
 
-/** 
+/**
  * \addtogroup asn1_module
- * \{ 
+ * \{
  */
- 
+
 /**
  * \name ASN1 Error codes
  * These error codes are OR'ed to X509 error codes for
- * higher error granularity. 
+ * higher error granularity.
  * ASN1 is a standard to specify data structures.
  * \{
  */
@@ -274,7 +274,7 @@
 int asn1_get_mpi( unsigned char **p,
                   const unsigned char *end,
                   mpi *X );
-#endif
+#endif /* POLARSSL_BIGNUM_C */
 
 /**
  * \brief       Retrieve an AlgorithmIdentifier ASN.1 sequence.
diff --git a/include/polarssl/asn1write.h b/include/polarssl/asn1write.h
index d7f7b52..9c36030 100644
--- a/include/polarssl/asn1write.h
+++ b/include/polarssl/asn1write.h
@@ -85,7 +85,7 @@
  * \return          the length written or a negative error code
  */
 int asn1_write_mpi( unsigned char **p, unsigned char *start, mpi *X );
-#endif
+#endif /* POLARSSL_BIGNUM_C */
 
 /**
  * \brief           Write a NULL tag (ASN1_NULL) with zero data in ASN.1 format
diff --git a/include/polarssl/bignum.h b/include/polarssl/bignum.h
index bfd4ce0..2c3f4b4 100644
--- a/include/polarssl/bignum.h
+++ b/include/polarssl/bignum.h
@@ -51,7 +51,7 @@
 typedef UINT64 uint64_t;
 #else
 #include <inttypes.h>
-#endif
+#endif /* _MSC_VER && !EFIX64 && !EFI32 */
 
 #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. */
@@ -644,7 +644,7 @@
 /**
  * \brief          Sliding-window exponentiation: X = A^E mod N
  *
- * \param X        Destination MPI 
+ * \param X        Destination MPI
  * \param A        Left-hand MPI
  * \param E        Exponent MPI
  * \param N        Modular MPI
diff --git a/include/polarssl/bn_mul.h b/include/polarssl/bn_mul.h
index 870be37..39dee41 100644
--- a/include/polarssl/bn_mul.h
+++ b/include/polarssl/bn_mul.h
@@ -329,7 +329,7 @@
     );
 
 
-#else
+#else /* __MACH__ && __APPLE__ */
 
 #define MULADDC_INIT                \
     asm(                            \
@@ -369,7 +369,7 @@
         : "r3", "r4", "r5", "r6", "r7", "r8", "r9"  \
     );
 
-#endif
+#endif /* __MACH__ && __APPLE__ */
 
 #else /* PPC32 */
 
@@ -413,7 +413,7 @@
         : "r3", "r4", "r5", "r6", "r7", "r8", "r9"  \
     );
 
-#else
+#else /* __MACH__ && __APPLE__ */
 
 #define MULADDC_INIT                \
     asm(                            \
@@ -453,7 +453,7 @@
         : "r3", "r4", "r5", "r6", "r7", "r8", "r9"  \
     );
 
-#endif
+#endif /* __MACH__ && __APPLE__ */
 
 #endif /* PPC32 */
 #endif /* PPC64 */
diff --git a/include/polarssl/camellia.h b/include/polarssl/camellia.h
index a768c61..9dbdb85 100644
--- a/include/polarssl/camellia.h
+++ b/include/polarssl/camellia.h
@@ -72,7 +72,7 @@
  * \param ctx      CAMELLIA context to be initialized
  * \param key      encryption key
  * \param keysize  must be 128, 192 or 256
- * 
+ *
  * \return         0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH
  */
 int camellia_setkey_enc( camellia_context *ctx, const unsigned char *key, unsigned int keysize );
@@ -83,7 +83,7 @@
  * \param ctx      CAMELLIA context to be initialized
  * \param key      decryption key
  * \param keysize  must be 128, 192 or 256
- * 
+ *
  * \return         0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH
  */
 int camellia_setkey_dec( camellia_context *ctx, const unsigned char *key, unsigned int keysize );
@@ -95,7 +95,7 @@
  * \param mode     CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT
  * \param input    16-byte input block
  * \param output   16-byte output block
- * 
+ *
  * \return         0 if successful
  */
 int camellia_crypt_ecb( camellia_context *ctx,
@@ -115,7 +115,7 @@
  * \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_CAMELLIA_INVALID_INPUT_LENGTH
  */
 int camellia_crypt_cbc( camellia_context *ctx,
diff --git a/include/polarssl/cipher.h b/include/polarssl/cipher.h
index c8b8490..e034fac 100644
--- a/include/polarssl/cipher.h
+++ b/include/polarssl/cipher.h
@@ -1,6 +1,6 @@
 /**
  * \file cipher.h
- * 
+ *
  * \brief Generic cipher wrapper.
  *
  * \author Adriaan de Jong <dejong@fox-it.com>
diff --git a/include/polarssl/cipher_wrap.h b/include/polarssl/cipher_wrap.h
index 49d2661..46bc757 100644
--- a/include/polarssl/cipher_wrap.h
+++ b/include/polarssl/cipher_wrap.h
@@ -1,6 +1,6 @@
 /**
  * \file cipher_wrap.h
- * 
+ *
  * \brief Cipher wrappers.
  *
  * \author Adriaan de Jong <dejong@fox-it.com>
diff --git a/include/polarssl/compat-1.2.h b/include/polarssl/compat-1.2.h
index 7ebc9c1..15b5aa1 100644
--- a/include/polarssl/compat-1.2.h
+++ b/include/polarssl/compat-1.2.h
@@ -171,7 +171,7 @@
 #warning "rsa_pkcs1_verify() prototype changed. Manual change required if used"
 #warning "rsa_pkcs1_decrypt() prototype changed. Manual change required if used"
 #endif
-#endif
+#endif /* POLARSSL_RSA_C */
 
 #if defined(POLARSSL_DHM_C)
 #if defined(SHOW_PROTOTYPE_CHANGE_WARNINGS)
diff --git a/include/polarssl/ctr_drbg.h b/include/polarssl/ctr_drbg.h
index 5673fad..a71b0ff 100644
--- a/include/polarssl/ctr_drbg.h
+++ b/include/polarssl/ctr_drbg.h
@@ -108,7 +108,7 @@
 
 /**
  * \brief               CTR_DRBG initialization
- * 
+ *
  * Note: Personalization data can be provided in addition to the more generic
  *       entropy source to make this instantiation as unique as possible.
  *
@@ -163,7 +163,7 @@
 
 /**
  * \brief               CTR_DRBG reseeding (extracts data from entropy source)
- * 
+ *
  * \param ctx           CTR_DRBG context
  * \param additional    Additional data to add to state (Can be NULL)
  * \param len           Length of additional data
@@ -245,7 +245,7 @@
  *                      POLARSSL_ERR_CTR_DRBG_INPUT_TOO_BIG
  */
 int ctr_drbg_update_seed_file( ctr_drbg_context *ctx, const char *path );
-#endif
+#endif /* POLARSSL_FS_IO */
 
 /**
  * \brief               Checkup routine
diff --git a/include/polarssl/debug.h b/include/polarssl/debug.h
index 7b51cbb..0dd79d5 100644
--- a/include/polarssl/debug.h
+++ b/include/polarssl/debug.h
@@ -81,7 +81,7 @@
     debug_print_crt( ssl, level, __FILE__, __LINE__, text, crt );
 #endif
 
-#else
+#else /* POLARSSL_DEBUG_C */
 
 #define SSL_DEBUG_MSG( level, args )            do { } while( 0 )
 #define SSL_DEBUG_RET( level, text, ret )       do { } while( 0 )
@@ -90,7 +90,7 @@
 #define SSL_DEBUG_ECP( level, text, X )         do { } while( 0 )
 #define SSL_DEBUG_CRT( level, text, crt )       do { } while( 0 )
 
-#endif
+#endif /* POLARSSL_DEBUG_C */
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/include/polarssl/dhm.h b/include/polarssl/dhm.h
index 4665ff9..628cd62 100644
--- a/include/polarssl/dhm.h
+++ b/include/polarssl/dhm.h
@@ -285,4 +285,4 @@
 }
 #endif
 
-#endif
+#endif /* dhm.h */
diff --git a/include/polarssl/ecdh.h b/include/polarssl/ecdh.h
index 3c4800b..9cd0d4f 100644
--- a/include/polarssl/ecdh.h
+++ b/include/polarssl/ecdh.h
@@ -212,4 +212,4 @@
 }
 #endif
 
-#endif
+#endif /* ecdh.h */
diff --git a/include/polarssl/ecdsa.h b/include/polarssl/ecdsa.h
index 4f06328..71e5a0c 100644
--- a/include/polarssl/ecdsa.h
+++ b/include/polarssl/ecdsa.h
@@ -90,7 +90,7 @@
 int ecdsa_sign_det( ecp_group *grp, mpi *r, mpi *s,
                     const mpi *d, const unsigned char *buf, size_t blen,
                     md_type_t md_alg );
-#endif
+#endif /* POLARSSL_ECDSA_DETERMINISTIC */
 
 /**
  * \brief           Verify ECDSA signature of a previously hashed message
@@ -163,7 +163,7 @@
                                const unsigned char *hash, size_t hlen,
                                unsigned char *sig, size_t *slen,
                                md_type_t md_alg );
-#endif
+#endif /* POLARSSL_ECDSA_DETERMINISTIC */
 
 /**
  * \brief           Read and verify an ECDSA signature
@@ -233,4 +233,4 @@
 }
 #endif
 
-#endif
+#endif /* ecdsa.h */
diff --git a/include/polarssl/ecp.h b/include/polarssl/ecp.h
index 2b56d27..333986d 100644
--- a/include/polarssl/ecp.h
+++ b/include/polarssl/ecp.h
@@ -648,4 +648,4 @@
 }
 #endif
 
-#endif
+#endif /* ecp.h */
diff --git a/include/polarssl/entropy.h b/include/polarssl/entropy.h
index 4f4f8f7..784be16 100644
--- a/include/polarssl/entropy.h
+++ b/include/polarssl/entropy.h
@@ -191,7 +191,7 @@
 /**
  * \brief           Add data to the accumulator manually
  *                  (Thread-safe if POLARSSL_THREADING_C is enabled)
- * 
+ *
  * \param ctx       Entropy context
  * \param data      Data to add
  * \param len       Length of data
@@ -227,7 +227,7 @@
  *                      POLARSSL_ERR_ENTROPY_SOURCE_FAILED
  */
 int entropy_update_seed_file( entropy_context *ctx, const char *path );
-#endif
+#endif /* POLARSSL_FS_IO */
 
 #ifdef __cplusplus
 }
diff --git a/include/polarssl/hmac_drbg.h b/include/polarssl/hmac_drbg.h
index 709f25d..2d765d5 100644
--- a/include/polarssl/hmac_drbg.h
+++ b/include/polarssl/hmac_drbg.h
@@ -265,7 +265,7 @@
  *                      POLARSSL_ERR_HMAC_DRBG_INPUT_TOO_BIG
  */
 int hmac_drbg_update_seed_file( hmac_drbg_context *ctx, const char *path );
-#endif
+#endif /* POLARSSL_FS_IO */
 
 
 #if defined(POLARSSL_SELF_TEST)
diff --git a/include/polarssl/md.h b/include/polarssl/md.h
index 2c772b1..796c0df 100644
--- a/include/polarssl/md.h
+++ b/include/polarssl/md.h
@@ -1,6 +1,6 @@
 /**
  * \file md.h
- * 
+ *
  * \brief Generic message digest wrapper
  *
  * \author Adriaan de Jong <dejong@fox-it.com>
diff --git a/include/polarssl/md_wrap.h b/include/polarssl/md_wrap.h
index 634bb7d..eb1db0f 100644
--- a/include/polarssl/md_wrap.h
+++ b/include/polarssl/md_wrap.h
@@ -1,6 +1,6 @@
 /**
  * \file md_wrap.h
- * 
+ *
  * \brief Message digest wrappers.
  *
  * \author Adriaan de Jong <dejong@fox-it.com>
diff --git a/include/polarssl/openssl.h b/include/polarssl/openssl.h
index 0e9de22..b77e7da 100644
--- a/include/polarssl/openssl.h
+++ b/include/polarssl/openssl.h
@@ -98,7 +98,7 @@
 
     memset( rsa, 0, sizeof( rsa_context ) );
 
-    if( ( len ==  94 && 
+    if( ( len ==  94 &&
           mpi_read_binary( &rsa->N, &buffer[ 25],  64 ) == 0 &&
           mpi_read_binary( &rsa->E, &buffer[ 91],   3 ) == 0 ) ||
         ( len == 162 &&
diff --git a/include/polarssl/pkcs11.h b/include/polarssl/pkcs11.h
index 1e4ed38..74859c0 100644
--- a/include/polarssl/pkcs11.h
+++ b/include/polarssl/pkcs11.h
@@ -148,7 +148,7 @@
                            output_max_len );
 }
 
-static inline int ssl_pkcs11_sign( void *ctx, 
+static inline int ssl_pkcs11_sign( void *ctx,
                      int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
                      int mode, md_type_t md_alg, unsigned int hashlen,
                      const unsigned char *hash, unsigned char *sig )
diff --git a/include/polarssl/platform.h b/include/polarssl/platform.h
index fd9b80a..eae887a 100644
--- a/include/polarssl/platform.h
+++ b/include/polarssl/platform.h
@@ -86,10 +86,10 @@
  */
 int platform_set_malloc_free( void * (*malloc_func)( size_t ),
                               void (*free_func)( void * ) );
-#else
+#else /* POLARSSL_PLATFORM_ENTROPY */
 #define polarssl_malloc     malloc
 #define polarssl_free       free
-#endif
+#endif /* POLARSSL_PLATFORM_ENTROPY */
 
 /*
  * The function pointers for printf
@@ -105,9 +105,9 @@
  * \return              0
  */
 int platform_set_printf( int (*printf_func)( const char *, ... ) );
-#else
+#else /* POLARSSL_PLATFORM_PRINTF_ALT */
 #define polarssl_printf     printf
-#endif
+#endif /* POLARSSL_PLATFORM_PRINTF_ALT */
 
 /*
  * The function pointers for fprintf
diff --git a/include/polarssl/ssl.h b/include/polarssl/ssl.h
index 401908a..9cbd512 100644
--- a/include/polarssl/ssl.h
+++ b/include/polarssl/ssl.h
@@ -168,10 +168,10 @@
 #else
 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
 #define SSL_MIN_MINOR_VERSION           SSL_MINOR_VERSION_3
-#endif
-#endif
-#endif
-#endif
+#endif /* POLARSSL_SSL_PROTO_TLS1_2 */
+#endif /* POLARSSL_SSL_PROTO_TLS1_1 */
+#endif /* POLARSSL_SSL_PROTO_TLS1   */
+#endif /* POLARSSL_SSL_PROTO_SSL3   */
 
 /* Determine maximum supported version */
 #define SSL_MAX_MAJOR_VERSION           SSL_MAJOR_VERSION_3
@@ -187,10 +187,10 @@
 #else
 #if defined(POLARSSL_SSL_PROTO_SSL3)
 #define SSL_MAX_MINOR_VERSION           SSL_MINOR_VERSION_0
-#endif
-#endif
-#endif
-#endif
+#endif /* POLARSSL_SSL_PROTO_SSL3   */
+#endif /* POLARSSL_SSL_PROTO_TLS1   */
+#endif /* POLARSSL_SSL_PROTO_TLS1_1 */
+#endif /* POLARSSL_SSL_PROTO_TLS1_2 */
 
 /* RFC 6066 section 4, see also mfl_code_to_length in ssl_tls.c
  * NONE must be zero so that memset()ing structure to zero works */
@@ -395,7 +395,7 @@
  */
 typedef int (*rsa_decrypt_func)( void *ctx, int mode, size_t *olen,
                         const unsigned char *input, unsigned char *output,
-                        size_t output_max_len ); 
+                        size_t output_max_len );
 typedef int (*rsa_sign_func)( void *ctx,
                      int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
                      int mode, md_type_t md_alg, unsigned int hashlen,
@@ -545,7 +545,7 @@
 #if defined(POLARSSL_SSL_SERVER_NAME_INDICATION)
     ssl_key_cert *sni_key_cert;         /*!<  key/cert list from SNI  */
 #endif
-#endif
+#endif /* POLARSSL_X509_CRT_PARSE_C */
 
     /*
      * Checksum contexts
@@ -814,7 +814,7 @@
 extern int (*ssl_hw_record_write)(ssl_context *ssl);
 extern int (*ssl_hw_record_read)(ssl_context *ssl);
 extern int (*ssl_hw_record_finish)(ssl_context *ssl);
-#endif
+#endif /* POLARSSL_SSL_HW_RECORD_ACCEL */
 
 /**
  * \brief Returns the list of ciphersuites supported by the SSL/TLS module.
@@ -1195,7 +1195,7 @@
  * \return         0 if successful
  */
 int ssl_set_dh_param_ctx( ssl_context *ssl, dhm_context *dhm_ctx );
-#endif
+#endif /* POLARSSL_DHM_C */
 
 #if defined(POLARSSL_SSL_SET_CURVES)
 /**
@@ -1217,7 +1217,7 @@
  *                 terminated by POLARSSL_ECP_DP_NONE.
  */
 void ssl_set_curves( ssl_context *ssl, const ecp_group_id *curves );
-#endif
+#endif /* POLARSSL_SSL_SET_CURVES */
 
 #if defined(POLARSSL_SSL_SERVER_NAME_INDICATION)
 /**
@@ -1395,7 +1395,7 @@
 /**
  * \brief          Prevent or allow legacy renegotiation.
  *                 (Default: SSL_LEGACY_NO_RENEGOTIATION)
- *                 
+ *
  *                 SSL_LEGACY_NO_RENEGOTIATION allows connections to
  *                 be established even if the peer does not support
  *                 secure renegotiation, but does not allow renegotiation
diff --git a/library/aes.c b/library/aes.c
index f0a25bc..7fc7af4 100644
--- a/library/aes.c
+++ b/library/aes.c
@@ -346,16 +346,16 @@
     0x0000001B, 0x00000036
 };
 
-#else
+#else /* POLARSSL_AES_ROM_TABLES */
 
 /*
  * Forward S-box & tables
  */
 static unsigned char FSb[256];
-static uint32_t FT0[256]; 
-static uint32_t FT1[256]; 
-static uint32_t FT2[256]; 
-static uint32_t FT3[256]; 
+static uint32_t FT0[256];
+static uint32_t FT1[256];
+static uint32_t FT2[256];
+static uint32_t FT3[256];
 
 /*
  * Reverse S-box & tables
@@ -456,7 +456,7 @@
     }
 }
 
-#endif
+#endif /* POLARSSL_AES_ROM_TABLES */
 
 /*
  * AES key schedule (encryption)
@@ -826,7 +826,7 @@
     {
         if( padlock_xcryptcbc( ctx, mode, length, iv, input, output ) == 0 )
             return( 0 );
-        
+
         // If padlock data misaligned, we just fall back to
         // unaccelerated mode
         //
@@ -1424,6 +1424,6 @@
     return( 0 );
 }
 
-#endif
+#endif /* POLARSSL_SELF_TEST */
 
-#endif
+#endif /* POLARSSL_AES_C */
diff --git a/library/arc4.c b/library/arc4.c
index dbf0c7e..464f800 100644
--- a/library/arc4.c
+++ b/library/arc4.c
@@ -178,6 +178,6 @@
     return( 0 );
 }
 
-#endif
+#endif /* POLARSSL_SELF_TEST */
 
-#endif
+#endif /* POLARSSL_ARC4_C */
diff --git a/library/asn1parse.c b/library/asn1parse.c
index 8b8e2df..ed024de 100644
--- a/library/asn1parse.c
+++ b/library/asn1parse.c
@@ -387,4 +387,4 @@
     return( list );
 }
 
-#endif
+#endif /* POLARSSL_ASN1_PARSE_C */
diff --git a/library/asn1write.c b/library/asn1write.c
index 314c9f9..b6294bb 100644
--- a/library/asn1write.c
+++ b/library/asn1write.c
@@ -363,4 +363,4 @@
 
     return( cur );
 }
-#endif
+#endif /* POLARSSL_ASN1_WRITE_C */
diff --git a/library/base64.c b/library/base64.c
index 103d814..d7f3642 100644
--- a/library/base64.c
+++ b/library/base64.c
@@ -267,6 +267,6 @@
     return( 0 );
 }
 
-#endif
+#endif /* POLARSSL_SELF_TEST */
 
-#endif
+#endif /* POLARSSL_BASE64_C */
diff --git a/library/bignum.c b/library/bignum.c
index b9175f6..5a8d17d 100644
--- a/library/bignum.c
+++ b/library/bignum.c
@@ -313,7 +313,7 @@
 
     if( val != 0 && val != 1 )
         return POLARSSL_ERR_MPI_BAD_INPUT_DATA;
-        
+
     if( X->n * biL <= pos )
     {
         if( val == 0 )
@@ -326,7 +326,7 @@
     X->p[off] |= (t_uint) val << idx;
 
 cleanup:
-    
+
     return( ret );
 }
 
@@ -860,7 +860,7 @@
 
     if( X != A )
         MPI_CHK( mpi_copy( X, A ) );
-   
+
     /*
      * X should always be positive as a result of unsigned additions.
      */
@@ -1083,7 +1083,7 @@
         MULADDC_CORE
         MULADDC_STOP
     }
-#else
+#else /* MULADDC_HUIT */
     for( ; i >= 16; i -= 16 )
     {
         MULADDC_INIT
@@ -1116,7 +1116,7 @@
         MULADDC_CORE
         MULADDC_STOP
     }
-#endif
+#endif /* MULADDC_HUIT */
 
     t++;
 
@@ -2333,6 +2333,6 @@
     return( ret );
 }
 
-#endif
+#endif /* POLARSSL_SELF_TEST */
 
-#endif
+#endif /* POLARSSL_BIGNUM_C */
diff --git a/library/blowfish.c b/library/blowfish.c
index 733c9fa..adbabce 100644
--- a/library/blowfish.c
+++ b/library/blowfish.c
@@ -1,7 +1,7 @@
 /*
  *  Blowfish implementation
  *
- *  Copyright (C) 2012-2013, Brainspark B.V.
+ *  Copyright (C) 2012-2014, Brainspark B.V.
  *
  *  This file is part of PolarSSL (http://www.polarssl.org)
  *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -75,7 +75,7 @@
 /* declarations of data at the end of this file */
 static const uint32_t S[4][256];
 
-static uint32_t F(blowfish_context *ctx, uint32_t x) 
+static uint32_t F(blowfish_context *ctx, uint32_t x)
 {
    unsigned short a, b, c, d;
    uint32_t  y;
@@ -94,7 +94,7 @@
    return y;
 }
 
-static void blowfish_enc(blowfish_context *ctx, uint32_t *xl, uint32_t *xr) 
+static void blowfish_enc(blowfish_context *ctx, uint32_t *xl, uint32_t *xr)
 {
     uint32_t  Xl, Xr, temp;
     short i;
@@ -102,7 +102,7 @@
     Xl = *xl;
     Xr = *xr;
 
-    for (i = 0; i < BLOWFISH_ROUNDS; ++i) 
+    for (i = 0; i < BLOWFISH_ROUNDS; ++i)
     {
         Xl = Xl ^ ctx->P[i];
         Xr = F(ctx, Xl) ^ Xr;
@@ -123,7 +123,7 @@
     *xr = Xr;
 }
 
-static void blowfish_dec(blowfish_context *ctx, uint32_t *xl, uint32_t *xr) 
+static void blowfish_dec(blowfish_context *ctx, uint32_t *xl, uint32_t *xr)
 {
     uint32_t  Xl, Xr, temp;
     short i;
@@ -131,7 +131,7 @@
     Xl = *xl;
     Xr = *xr;
 
-    for (i = BLOWFISH_ROUNDS + 1; i > 1; --i) 
+    for (i = BLOWFISH_ROUNDS + 1; i > 1; --i)
     {
         Xl = Xl ^ ctx->P[i];
         Xr = F(ctx, Xl) ^ Xr;
@@ -161,14 +161,14 @@
     uint32_t data, datal, datar;
 
     if( keysize < BLOWFISH_MIN_KEY || keysize > BLOWFISH_MAX_KEY ||
-        ( keysize % 8 ) ) 
+        ( keysize % 8 ) )
     {
         return POLARSSL_ERR_BLOWFISH_INVALID_KEY_LENGTH;
     }
 
     keysize >>= 3;
 
-    for( i = 0; i < 4; i++ ) 
+    for( i = 0; i < 4; i++ )
     {
         for( j = 0; j < 256; j++ )
             ctx->S[i][j] = S[i][j];
@@ -219,8 +219,8 @@
 {
     uint32_t X0, X1;
 
-    GET_UINT32_BE( X0, input,  0 ); 
-    GET_UINT32_BE( X1, input,  4 ); 
+    GET_UINT32_BE( X0, input,  0 );
+    GET_UINT32_BE( X1, input,  4 );
 
     if( mode == BLOWFISH_DECRYPT )
     {
diff --git a/library/camellia.c b/library/camellia.c
index 4bf0b29..caa2965 100644
--- a/library/camellia.c
+++ b/library/camellia.c
@@ -107,7 +107,7 @@
 #define SBOX3(n) (unsigned char)((FSb[(n)] >> 1 ^ FSb[(n)] << 7) & 0xff)
 #define SBOX4(n) FSb[((n) << 1 ^ (n) >> 7) &0xff]
 
-#else
+#else /* POLARSSL_CAMELLIA_SMALL_MEMORY */
 
 static const unsigned char FSb[256] =
 {
@@ -194,7 +194,7 @@
 #define SBOX3(n) FSb3[(n)]
 #define SBOX4(n) FSb4[(n)]
 
-#endif
+#endif /* POLARSSL_CAMELLIA_SMALL_MEMORY */
 
 static const unsigned char shifts[2][4][4] =
 {
@@ -268,13 +268,13 @@
     (XR) = ((((XL) & (KL)) << 1) | (((XL) & (KL)) >> 31)) ^ (XR);   \
     (XL) = ((XR) | (KR)) ^ (XL);                                    \
 }
-    
+
 #define FLInv(YL, YR, KL, KR)                                       \
 {                                                                   \
     (YL) = ((YR) | (KR)) ^ (YL);                                    \
     (YR) = ((((YL) & (KL)) << 1) | (((YL) & (KL)) >> 31)) ^ (YR);   \
 }
-    
+
 #define SHIFT_AND_PLACE(INDEX, OFFSET)                      \
 {                                                           \
     TK[0] = KC[(OFFSET) * 4 + 0];                           \
@@ -392,7 +392,7 @@
 
     /*
      * Generating subkeys
-     */ 
+     */
 
     /* Manipulating KL */
     SHIFT_AND_PLACE(idx, 0);
@@ -691,14 +691,14 @@
     {
         { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
           0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },
-        { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
     },
     {
         { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
           0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
           0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 },
-        { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
     },
@@ -707,7 +707,7 @@
           0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
           0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
           0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff },
-        { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
@@ -718,7 +718,7 @@
 {
     { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
       0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },
-    { 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 
+    { 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
 };
 
@@ -1048,6 +1048,6 @@
     return ( 0 );
 }
 
-#endif
+#endif /* POLARSSL_SELF_TEST */
 
-#endif
+#endif /* POLARSSL_CAMELLIA_C */
diff --git a/library/certs.c b/library/certs.c
index 982226d..a782bc1 100644
--- a/library/certs.c
+++ b/library/certs.c
@@ -1,7 +1,7 @@
 /*
  *  X.509 test certificates
  *
- *  Copyright (C) 2006-2010, Brainspark B.V.
+ *  Copyright (C) 2006-2014, Brainspark B.V.
  *
  *  This file is part of PolarSSL (http://www.polarssl.org)
  *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -305,6 +305,6 @@
 const char *test_srv_key = test_srv_key_ec;
 const char *test_cli_crt = test_cli_crt_ec;
 const char *test_cli_key = test_cli_key_ec;
-#endif
+#endif /* POLARSSL_RSA_C */
 
 #endif /* POLARSSL_CERTS_C */
diff --git a/library/cipher.c b/library/cipher.c
index 7534b2f..d3687d7 100644
--- a/library/cipher.c
+++ b/library/cipher.c
@@ -376,7 +376,7 @@
 
         return 0;
     }
-#endif
+#endif /* POLARSSL_CIPHER_MODE_CFB */
 
 #if defined(POLARSSL_CIPHER_MODE_CTR)
     if( ctx->cipher_info->mode == POLARSSL_MODE_CTR )
@@ -392,7 +392,7 @@
 
         return 0;
     }
-#endif
+#endif /* POLARSSL_CIPHER_MODE_CTR */
 
 #if defined(POLARSSL_CIPHER_MODE_STREAM)
     if( ctx->cipher_info->mode == POLARSSL_MODE_STREAM )
@@ -407,7 +407,7 @@
 
         return 0;
     }
-#endif
+#endif /* POLARSSL_CIPHER_MODE_STREAM */
 
     return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
 }
@@ -728,7 +728,7 @@
 
     return 0;
 }
- 
+
 int cipher_check_tag( cipher_context_t *ctx,
                       const unsigned char *tag, size_t tag_len )
 {
@@ -765,7 +765,7 @@
 
         return( 0 );
     }
-#endif
+#endif /* POLARSSL_GCM_C */
 
     return( 0 );
 }
@@ -783,6 +783,6 @@
     return( 0 );
 }
 
-#endif
+#endif /* POLARSSL_SELF_TEST */
 
-#endif
+#endif /* POLARSSL_CIPHER_C */
diff --git a/library/cipher_wrap.c b/library/cipher_wrap.c
index 2a79eef..be44371 100644
--- a/library/cipher_wrap.c
+++ b/library/cipher_wrap.c
@@ -1,6 +1,6 @@
 /**
  * \file cipher_wrap.c
- * 
+ *
  * \brief Generic cipher wrapper for PolarSSL
  *
  * \author Adriaan de Jong <dejong@fox-it.com>
@@ -82,7 +82,7 @@
     gcm_free( ctx );
     polarssl_free( ctx );
 }
-#endif
+#endif /* POLARSSL_GCM_C */
 
 #if defined(POLARSSL_AES_C)
 
@@ -124,7 +124,7 @@
     ((void) output);
 
     return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
-#endif
+#endif /* POLARSSL_CIPHER_MODE_CFB */
 }
 
 static int aes_crypt_ctr_wrap( void *ctx, size_t length,
@@ -144,7 +144,7 @@
     ((void) output);
 
     return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
-#endif
+#endif /* POLARSSL_CIPHER_MODE_CTR */
 }
 
 static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
@@ -372,7 +372,7 @@
 };
 #endif /* POLARSSL_GCM_C */
 
-#endif
+#endif /* POLARSSL_AES_C */
 
 #if defined(POLARSSL_CAMELLIA_C)
 
@@ -414,7 +414,7 @@
     ((void) output);
 
     return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
-#endif
+#endif /* POLARSSL_CIPHER_MODE_CFB */
 }
 
 static int camellia_crypt_ctr_wrap( void *ctx, size_t length,
@@ -434,7 +434,7 @@
     ((void) output);
 
     return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
-#endif
+#endif /* POLARSSL_CIPHER_MODE_CTR */
 }
 
 static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
@@ -909,7 +909,7 @@
     &des_ede3_info
 };
 #endif /* POLARSSL_CIPHER_MODE_CBC */
-#endif
+#endif /* POLARSSL_DES_C */
 
 #if defined(POLARSSL_BLOWFISH_C)
 
@@ -951,7 +951,7 @@
     ((void) output);
 
     return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
-#endif
+#endif /* POLARSSL_CIPHER_MODE_CFB */
 }
 
 static int blowfish_crypt_ctr_wrap( void *ctx, size_t length,
@@ -971,7 +971,7 @@
     ((void) output);
 
     return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
-#endif
+#endif /* POLARSSL_CIPHER_MODE_CTR */
 }
 
 static int blowfish_setkey_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
@@ -1254,4 +1254,4 @@
 #define NUM_CIPHERS sizeof cipher_definitions / sizeof cipher_definitions[0]
 int supported_ciphers[NUM_CIPHERS];
 
-#endif
+#endif /* POLARSSL_CIPHER_C */
diff --git a/library/ctr_drbg.c b/library/ctr_drbg.c
index 89b4c4c..6203fce 100644
--- a/library/ctr_drbg.c
+++ b/library/ctr_drbg.c
@@ -286,7 +286,7 @@
 
     return( 0 );
 }
-    
+
 int ctr_drbg_random_with_add( void *p_rng,
                               unsigned char *output, size_t output_len,
                               const unsigned char *additional, size_t add_len )
@@ -524,6 +524,6 @@
 
     return( 0 );
 }
-#endif
+#endif /* POLARSSL_SELF_TEST */
 
-#endif
+#endif /* POLARSSL_CTR_DRBG_C */
diff --git a/library/debug.c b/library/debug.c
index b768e64..92559c2 100644
--- a/library/debug.c
+++ b/library/debug.c
@@ -348,4 +348,4 @@
 }
 #endif /* POLARSSL_X509_CRT_PARSE_C */
 
-#endif
+#endif /* POLARSSL_DEBUG_C */
diff --git a/library/des.c b/library/des.c
index b8bb271..6d20758 100644
--- a/library/des.c
+++ b/library/des.c
@@ -1012,6 +1012,6 @@
     return( 0 );
 }
 
-#endif
+#endif /* POLARSSL_SELF_TEST */
 
-#endif
+#endif /* POLARSSL_DES_C */
diff --git a/library/dhm.c b/library/dhm.c
index 5a38c14..f869456 100644
--- a/library/dhm.c
+++ b/library/dhm.c
@@ -431,7 +431,7 @@
     p = ( ret == 0 ) ? pem.buf : (unsigned char *) dhmin;
 #else
     p = (unsigned char *) dhmin;
-#endif
+#endif /* POLARSSL_PEM_PARSE_C */
     end = p + dhminlen;
 
     /*
@@ -578,9 +578,9 @@
         polarssl_printf( "  DHM parameter load: skipped\n" );
 
     return( 0 );
-#endif
+#endif /* POLARSSL_CERTS_C */
 }
 
-#endif
+#endif /* POLARSSL_SELF_TEST */
 
-#endif
+#endif /* POLARSSL_DHM_C */
diff --git a/library/ecdh.c b/library/ecdh.c
index fa32593..a6bf330 100644
--- a/library/ecdh.c
+++ b/library/ecdh.c
@@ -1,7 +1,7 @@
 /*
  *  Elliptic curve Diffie-Hellman
  *
- *  Copyright (C) 2006-2013, Brainspark B.V.
+ *  Copyright (C) 2006-2014, Brainspark B.V.
  *
  *  This file is part of PolarSSL (http://www.polarssl.org)
  *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -275,6 +275,6 @@
     return( 0 );
 }
 
-#endif
+#endif /* POLARSSL_SELF_TEST */
 
-#endif /* defined(POLARSSL_ECDH_C) */
+#endif /* POLARSSL_ECDH_C */
diff --git a/library/ecdsa.c b/library/ecdsa.c
index e467e37..5d4b0d3 100644
--- a/library/ecdsa.c
+++ b/library/ecdsa.c
@@ -1,7 +1,7 @@
 /*
  *  Elliptic curve DSA
  *
- *  Copyright (C) 2006-2013, Brainspark B.V.
+ *  Copyright (C) 2006-2014, Brainspark B.V.
  *
  *  This file is part of PolarSSL (http://www.polarssl.org)
  *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -70,7 +70,7 @@
 
     return( md_picked );
 }
-#endif
+#endif /* POLARSSL_ECDSA_DETERMINISTIC */
 
 /*
  * Derive a suitable integer for group grp from a buffer of length len
@@ -498,6 +498,6 @@
     return( 0 );
 }
 
-#endif
+#endif /* POLARSSL_SELF_TEST */
 
-#endif /* defined(POLARSSL_ECDSA_C) */
+#endif /* POLARSSL_ECDSA_C */
diff --git a/library/ecp.c b/library/ecp.c
index 7e965d3..ca0ce7e 100644
--- a/library/ecp.c
+++ b/library/ecp.c
@@ -1776,7 +1776,7 @@
         else
             return( 0 );
     }
-#endif
+#endif /* POLARSSL_ECP_MONTGOMERY */
 #if defined(POLARSSL_ECP_SHORT_WEIERSTRASS)
     if( ecp_get_type( grp ) == POLARSSL_ECP_TYPE_SHORT_WEIERSTRASS )
     {
@@ -1787,7 +1787,7 @@
         else
             return( 0 );
     }
-#endif
+#endif /* POLARSSL_ECP_SHORT_WEIERSTRASS */
 
     return( POLARSSL_ERR_ECP_BAD_INPUT_DATA );
 }
@@ -1823,7 +1823,7 @@
         MPI_CHK( mpi_set_bit( d, 2, 0 ) );
     }
     else
-#endif
+#endif /* POLARSSL_ECP_MONTGOMERY */
 #if defined(POLARSSL_ECP_SHORT_WEIERSTRASS)
     if( ecp_get_type( grp ) == POLARSSL_ECP_TYPE_SHORT_WEIERSTRASS )
     {
@@ -1860,7 +1860,7 @@
                mpi_cmp_mpi( d, &grp->N ) >= 0 );
     }
     else
-#endif
+#endif /* POLARSSL_ECP_SHORT_WEIERSTRASS */
         return( POLARSSL_ERR_ECP_BAD_INPUT_DATA );
 
 cleanup:
@@ -2013,6 +2013,6 @@
     return( ret );
 }
 
-#endif
+#endif /* POLARSSL_SELF_TEST */
 
-#endif
+#endif /* POLARSSL_ECP_C */
diff --git a/library/ecp_curves.c b/library/ecp_curves.c
index 7fc07a0..5221b9f 100644
--- a/library/ecp_curves.c
+++ b/library/ecp_curves.c
@@ -1,7 +1,7 @@
 /*
  *  Elliptic curves over GF(p): curve-specific data and functions
  *
- *  Copyright (C) 2006-2013, Brainspark B.V.
+ *  Copyright (C) 2006-2014, Brainspark B.V.
  *
  *  This file is part of PolarSSL (http://www.polarssl.org)
  *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -1377,4 +1377,4 @@
 }
 #endif /* POLARSSL_ECP_DP_SECP256K1_ENABLED */
 
-#endif
+#endif /* POLARSSL_ECP_C */
diff --git a/library/entropy.c b/library/entropy.c
index 238719b..b500491 100644
--- a/library/entropy.c
+++ b/library/entropy.c
@@ -1,7 +1,7 @@
 /*
  *  Entropy accumulator implementation
  *
- *  Copyright (C) 2006-2013, Brainspark B.V.
+ *  Copyright (C) 2006-2014, Brainspark B.V.
  *
  *  This file is part of PolarSSL (http://www.polarssl.org)
  *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -372,4 +372,4 @@
 }
 #endif /* POLARSSL_FS_IO */
 
-#endif
+#endif /* POLARSSL_ENTROPY_C */
diff --git a/library/entropy_poll.c b/library/entropy_poll.c
index 5c1dcc7..42316f3 100644
--- a/library/entropy_poll.c
+++ b/library/entropy_poll.c
@@ -1,7 +1,7 @@
 /*
  *  Platform-specific and custom entropy polling functions
  *
- *  Copyright (C) 2006-2011, Brainspark B.V.
+ *  Copyright (C) 2006-2014, Brainspark B.V.
  *
  *  This file is part of PolarSSL (http://www.polarssl.org)
  *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -71,7 +71,7 @@
 
     return( 0 );
 }
-#else
+#else /* _WIN32 && !EFIX64 && !EFI32 */
 
 #include <stdio.h>
 
@@ -87,7 +87,7 @@
     file = fopen( "/dev/urandom", "rb" );
     if( file == NULL )
         return POLARSSL_ERR_ENTROPY_SOURCE_FAILED;
-    
+
     ret = fread( output, 1, len, file );
     if( ret != len )
     {
@@ -100,8 +100,8 @@
 
     return( 0 );
 }
-#endif
-#endif
+#endif /* _WIN32 && !EFIX64 && !EFI32 */
+#endif /* !POLARSSL_NO_PLATFORM_ENTROPY */
 
 #if defined(POLARSSL_TIMING_C)
 int hardclock_poll( void *data,
@@ -119,7 +119,7 @@
 
     return( 0 );
 }
-#endif
+#endif /* POLARSSL_TIMING_C */
 
 #if defined(POLARSSL_HAVEGE_C)
 int havege_poll( void *data,
@@ -135,6 +135,6 @@
 
     return( 0 );
 }
-#endif
+#endif /* POLARSSL_HAVEGE_C */
 
 #endif /* POLARSSL_ENTROPY_C */
diff --git a/library/gcm.c b/library/gcm.c
index d5918a5..d5761d2 100644
--- a/library/gcm.c
+++ b/library/gcm.c
@@ -211,7 +211,7 @@
         aesni_gcm_mult( output, x, h );
         return;
     }
-#endif
+#endif /* POLARSSL_AESNI_C && POLARSSL_HAVE_X86_64 */
 
     memset( z, 0x00, 16 );
 
@@ -924,4 +924,4 @@
 
 #endif /* POLARSSL_SELF_TEST && POLARSSL_AES_C */
 
-#endif
+#endif /* POLARSSL_GCM_C */
diff --git a/library/havege.c b/library/havege.c
index 42aceda..c82a24e 100644
--- a/library/havege.c
+++ b/library/havege.c
@@ -1,7 +1,7 @@
 /**
  *  \brief HAVEGE: HArdware Volatile Entropy Gathering and Expansion
  *
- *  Copyright (C) 2006-2010, Brainspark B.V.
+ *  Copyright (C) 2006-2014, Brainspark B.V.
  *
  *  This file is part of PolarSSL (http://www.polarssl.org)
  *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -223,7 +223,7 @@
         val ^= hs->pool[hs->offset[1]++];
 
         memcpy( p, &val, use_len );
-        
+
         len -= use_len;
         p += use_len;
     }
@@ -231,4 +231,4 @@
     return( 0 );
 }
 
-#endif
+#endif /* POLARSSL_HAVEGE_C */
diff --git a/library/md.c b/library/md.c
index a05bf34..4a92cd4 100644
--- a/library/md.c
+++ b/library/md.c
@@ -1,11 +1,11 @@
 /**
  * \file md.c
- * 
+ *
  * \brief Generic message digest wrapper for PolarSSL
  *
  * \author Adriaan de Jong <dejong@fox-it.com>
  *
- *  Copyright (C) 2006-2010, Brainspark B.V.
+ *  Copyright (C) 2006-2014, Brainspark B.V.
  *
  *  This file is part of PolarSSL (http://www.polarssl.org)
  *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -256,7 +256,7 @@
     ((void) output);
 
     return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
-#endif
+#endif /* POLARSSL_FS_IO */
 }
 
 int md_hmac_starts( md_context_t *ctx, const unsigned char *key, size_t keylen )
@@ -321,4 +321,4 @@
     return 0;
 }
 
-#endif
+#endif /* POLARSSL_MD_C */
diff --git a/library/md2.c b/library/md2.c
index 1e1691d..af6b595 100644
--- a/library/md2.c
+++ b/library/md2.c
@@ -373,6 +373,6 @@
     return( 0 );
 }
 
-#endif
+#endif /* POLARSSL_SELF_TEST */
 
-#endif
+#endif /* POLARSSL_MD2_C */
diff --git a/library/md4.c b/library/md4.c
index aa5f539..5d3315f 100644
--- a/library/md4.c
+++ b/library/md4.c
@@ -407,7 +407,7 @@
  */
 static const char md4_test_str[7][81] =
 {
-    { "" }, 
+    { "" },
     { "a" },
     { "abc" },
     { "message digest" },
@@ -469,6 +469,6 @@
     return( 0 );
 }
 
-#endif
+#endif /* POLARSSL_SELF_TEST */
 
-#endif
+#endif /* POLARSSL_MD4_C */
diff --git a/library/md5.c b/library/md5.c
index 6ceab8a..cc6567f 100644
--- a/library/md5.c
+++ b/library/md5.c
@@ -161,7 +161,7 @@
     P( B, C, D, A, 12, 20, 0x8D2A4C8A );
 
 #undef F
-    
+
 #define F(x,y,z) (x ^ y ^ z)
 
     P( A, B, C, D,  5,  4, 0xFFFA3942 );
@@ -423,7 +423,7 @@
  */
 static unsigned char md5_test_buf[7][81] =
 {
-    { "" }, 
+    { "" },
     { "a" },
     { "abc" },
     { "message digest" },
@@ -590,6 +590,6 @@
     return( 0 );
 }
 
-#endif
+#endif /* POLARSSL_SELF_TEST */
 
-#endif
+#endif /* POLARSSL_MD5_C */
diff --git a/library/md_wrap.c b/library/md_wrap.c
index 0b091e3..b67b709 100644
--- a/library/md_wrap.c
+++ b/library/md_wrap.c
@@ -158,7 +158,7 @@
     md2_process_wrap,
 };
 
-#endif
+#endif /* POLARSSL_MD2_C */
 
 #if defined(POLARSSL_MD4_C)
 
@@ -242,7 +242,7 @@
     md4_process_wrap,
 };
 
-#endif
+#endif /* POLARSSL_MD4_C */
 
 #if defined(POLARSSL_MD5_C)
 
@@ -326,7 +326,7 @@
     md5_process_wrap,
 };
 
-#endif
+#endif /* POLARSSL_MD5_C */
 
 #if defined(POLARSSL_RIPEMD160_C)
 
@@ -410,7 +410,7 @@
     ripemd160_process_wrap,
 };
 
-#endif
+#endif /* POLARSSL_RIPEMD160_C */
 
 #if defined(POLARSSL_SHA1_C)
 
@@ -494,7 +494,7 @@
     sha1_process_wrap,
 };
 
-#endif
+#endif /* POLARSSL_SHA1_C */
 
 /*
  * Wrappers for generic message digests
@@ -687,7 +687,7 @@
     sha256_process_wrap,
 };
 
-#endif
+#endif /* POLARSSL_SHA256_C */
 
 #if defined(POLARSSL_SHA512_C)
 
@@ -877,6 +877,6 @@
     sha512_process_wrap,
 };
 
-#endif
+#endif /* POLARSSL_SHA512_C */
 
-#endif
+#endif /* POLARSSL_MD_C */
diff --git a/library/memory_buffer_alloc.c b/library/memory_buffer_alloc.c
index 5176176..5409a93 100644
--- a/library/memory_buffer_alloc.c
+++ b/library/memory_buffer_alloc.c
@@ -539,7 +539,7 @@
     buffer_alloc_free( ptr );
     polarssl_mutex_unlock( &heap.mutex );
 }
-#endif
+#endif /* POLARSSL_THREADING_C */
 
 int memory_buffer_alloc_init( unsigned char *buf, size_t len )
 {
diff --git a/library/net.c b/library/net.c
index be4be5e..4a4cf5f 100644
--- a/library/net.c
+++ b/library/net.c
@@ -1,7 +1,7 @@
 /*
  *  TCP networking functions
  *
- *  Copyright (C) 2006-2013, Brainspark B.V.
+ *  Copyright (C) 2006-2014, Brainspark B.V.
  *
  *  This file is part of PolarSSL (http://www.polarssl.org)
  *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -572,4 +572,4 @@
     close( fd );
 }
 
-#endif
+#endif /* POLARSSL_NET_C */
diff --git a/library/oid.c b/library/oid.c
index 2b52935..a931887 100644
--- a/library/oid.c
+++ b/library/oid.c
@@ -3,7 +3,7 @@
  *
  * \brief Object Identifier (OID) database
  *
- *  Copyright (C) 2006-2013, Brainspark B.V.
+ *  Copyright (C) 2006-2014, Brainspark B.V.
  *
  *  This file is part of PolarSSL (http://www.polarssl.org)
  *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -624,7 +624,7 @@
 }
 
 #define snprintf compat_snprintf
-#endif
+#endif /* _MSC_VER && !snprintf && !EFIX64 && !EFI32 */
 
 #define SAFE_SNPRINTF()                         \
 {                                               \
diff --git a/library/padlock.c b/library/padlock.c
index 52b04f0..ccc477e 100644
--- a/library/padlock.c
+++ b/library/padlock.c
@@ -1,7 +1,7 @@
 /*
  *  VIA PadLock support functions
  *
- *  Copyright (C) 2006-2010, Brainspark B.V.
+ *  Copyright (C) 2006-2014, Brainspark B.V.
  *
  *  This file is part of PolarSSL (http://www.polarssl.org)
  *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -161,6 +161,6 @@
     return( 0 );
 }
 
-#endif
+#endif /* POLARSSL_HAVE_X86 */
 
-#endif
+#endif /* POLARSSL_PADLOCK_C */
diff --git a/library/pk_wrap.c b/library/pk_wrap.c
index 513d96d..c0ad10d 100644
--- a/library/pk_wrap.c
+++ b/library/pk_wrap.c
@@ -334,7 +334,7 @@
 
     return( ecdsa_write_signature( (ecdsa_context *) ctx,
                 hash, hash_len, sig, sig_len, f_rng, p_rng ) );
-#endif
+#endif /* POLARSSL_ECDSA_DETERMINISTIC */
 }
 
 static void *ecdsa_alloc_wrap( void )
diff --git a/library/pkcs5.c b/library/pkcs5.c
index 8ba8e50..2271d97 100644
--- a/library/pkcs5.c
+++ b/library/pkcs5.c
@@ -329,7 +329,7 @@
     { 20, 20, 20, 20, 25, 16 };
 
 
-unsigned char result_key[MAX_TESTS][32] = 
+unsigned char result_key[MAX_TESTS][32] =
 {
     { 0x0c, 0x60, 0xc8, 0x0f, 0x96, 0x1f, 0x0e, 0x71,
       0xf3, 0xa9, 0xb5, 0x24, 0xaf, 0x60, 0x12, 0x06,
diff --git a/library/pkparse.c b/library/pkparse.c
index ae8bddf..b3d3b1d 100644
--- a/library/pkparse.c
+++ b/library/pkparse.c
@@ -1,7 +1,7 @@
 /*
  *  Public Key layer for parsing key files and structures
  *
- *  Copyright (C) 2006-2013, Brainspark B.V.
+ *  Copyright (C) 2006-2014, Brainspark B.V.
  *
  *  This file is part of PolarSSL (http://www.polarssl.org)
  *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -1236,7 +1236,7 @@
         pem_free( &pem );
         return( ret );
     }
-#endif
+#endif /* POLARSSL_PEM_PARSE_C */
     p = (unsigned char *) key;
 
     ret = pk_parse_subpubkey( &p, p + keylen, ctx );
diff --git a/library/pkwrite.c b/library/pkwrite.c
index aa04a5a..81ac7fe 100644
--- a/library/pkwrite.c
+++ b/library/pkwrite.c
@@ -221,7 +221,7 @@
         ASN1_CHK_ADD( len, asn1_write_tag( &c, buf, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) );
     }
     else
-#endif
+#endif /* POLARSSL_RSA_C */
 #if defined(POLARSSL_ECP_C)
     if( pk_get_type( key ) == POLARSSL_PK_ECKEY )
     {
@@ -274,7 +274,7 @@
         ASN1_CHK_ADD( len, asn1_write_tag( &c, buf, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) );
     }
     else
-#endif
+#endif /* POLARSSL_ECP_C */
         return( POLARSSL_ERR_PK_FEATURE_UNAVAILABLE );
 
     return( (int) len );
diff --git a/library/ripemd160.c b/library/ripemd160.c
index f0e04a8..73da510 100644
--- a/library/ripemd160.c
+++ b/library/ripemd160.c
@@ -630,6 +630,6 @@
     return( 0 );
 }
 
-#endif
+#endif /* POLARSSL_SELF_TEST */
 
-#endif
+#endif /* POLARSSL_RIPEMD160_C */
diff --git a/library/rsa.c b/library/rsa.c
index 9cfbe2a..e3cac12 100644
--- a/library/rsa.c
+++ b/library/rsa.c
@@ -104,7 +104,7 @@
 
     do
     {
-        MPI_CHK( mpi_gen_prime( &ctx->P, ( nbits + 1 ) >> 1, 0, 
+        MPI_CHK( mpi_gen_prime( &ctx->P, ( nbits + 1 ) >> 1, 0,
                                 f_rng, p_rng ) );
 
         MPI_CHK( mpi_gen_prime( &ctx->Q, ( nbits + 1 ) >> 1, 0,
@@ -153,7 +153,7 @@
     return( 0 );
 }
 
-#endif
+#endif /* POLARSSL_GENPRIME */
 
 /*
  * Check a public RSA key
@@ -329,7 +329,7 @@
 
     return( ret );
 }
-#endif
+#endif /* !POLARSSL_RSA_NO_CRT */
 
 /*
  * Do an RSA private key operation
@@ -361,7 +361,7 @@
     Vi = &ctx->Vi;
     Vf = &ctx->Vf;
 #endif
-#endif
+#endif /* !POLARSSL_RSA_NO_CRT */
 
     mpi_init( &T ); mpi_init( &T1 ); mpi_init( &T2 );
 
@@ -419,7 +419,7 @@
         MPI_CHK( mpi_mul_mpi( &T, &T, Vf ) );
         MPI_CHK( mpi_mod_mpi( &T, &T, &ctx->N ) );
     }
-#endif
+#endif /* POLARSSL_RSA_NO_CRT */
 
     olen = ctx->len;
     MPI_CHK( mpi_write_binary( &T, output, olen ) );
@@ -483,7 +483,7 @@
         dlen -= use_len;
     }
 }
-#endif
+#endif /* POLARSSL_PKCS1_V21 */
 
 #if defined(POLARSSL_PKCS1_V21)
 /*
@@ -1490,7 +1490,7 @@
 
     return( 0 );
 }
-#endif
+#endif /* POLARSSL_PKCS1_V15 */
 
 /*
  * Checkup routine
@@ -1606,6 +1606,6 @@
     return( ret );
 }
 
-#endif
+#endif /* POLARSSL_SELF_TEST */
 
-#endif
+#endif /* POLARSSL_RSA_C */
diff --git a/library/sha1.c b/library/sha1.c
index b89db32..ee5cdc3 100644
--- a/library/sha1.c
+++ b/library/sha1.c
@@ -454,7 +454,7 @@
 /*
  * FIPS-180-1 test vectors
  */
-static unsigned char sha1_test_buf[3][57] = 
+static unsigned char sha1_test_buf[3][57] =
 {
     { "abc" },
     { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
@@ -629,6 +629,6 @@
     return( 0 );
 }
 
-#endif
+#endif /* POLARSSL_SELF_TEST */
 
-#endif
+#endif /* POLARSSL_SHA1_C */
diff --git a/library/sha256.c b/library/sha256.c
index e3d3ea8..064ba3b 100644
--- a/library/sha256.c
+++ b/library/sha256.c
@@ -461,7 +461,7 @@
 /*
  * FIPS-180-2 test vectors
  */
-static unsigned char sha256_test_buf[3][57] = 
+static unsigned char sha256_test_buf[3][57] =
 {
     { "abc" },
     { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
@@ -710,6 +710,6 @@
     return( 0 );
 }
 
-#endif
+#endif /* POLARSSL_SELF_TEST */
 
-#endif
+#endif /* POLARSSL_SHA256_C */
diff --git a/library/sha512.c b/library/sha512.c
index 1d4b977..a55a94b 100644
--- a/library/sha512.c
+++ b/library/sha512.c
@@ -65,7 +65,7 @@
         | ( (uint64_t) (b)[(i) + 6] <<  8 )       \
         | ( (uint64_t) (b)[(i) + 7]       );      \
 }
-#endif
+#endif /* GET_UINT64_BE */
 
 #ifndef PUT_UINT64_BE
 #define PUT_UINT64_BE(n,b,i)                            \
@@ -79,7 +79,7 @@
     (b)[(i) + 6] = (unsigned char) ( (n) >>  8 );       \
     (b)[(i) + 7] = (unsigned char) ( (n)       );       \
 }
-#endif
+#endif /* PUT_UINT64_BE */
 
 /*
  * Round constants
@@ -461,7 +461,7 @@
 /*
  * FIPS-180-2 test vectors
  */
-static unsigned char sha512_test_buf[3][113] = 
+static unsigned char sha512_test_buf[3][113] =
 {
     { "abc" },
     { "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
@@ -765,6 +765,6 @@
     return( 0 );
 }
 
-#endif
+#endif /* POLARSSL_SELF_TEST */
 
-#endif
+#endif /* POLARSSL_SHA512_C */
diff --git a/library/ssl_ciphersuites.c b/library/ssl_ciphersuites.c
index 8018fe7..6688989 100644
--- a/library/ssl_ciphersuites.c
+++ b/library/ssl_ciphersuites.c
@@ -3,7 +3,7 @@
  *
  * \brief SSL ciphersuites for PolarSSL
  *
- *  Copyright (C) 2006-2013, Brainspark B.V.
+ *  Copyright (C) 2006-2014, Brainspark B.V.
  *
  *  This file is part of PolarSSL (http://www.polarssl.org)
  *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -1654,7 +1654,7 @@
             return( POLARSSL_PK_NONE );
     }
 }
-#endif
+#endif /* POLARSSL_PK_C */
 
 #if defined(POLARSSL_ECDH_C) || defined(POLARSSL_ECDSA_C)
 int ssl_ciphersuite_uses_ec( const ssl_ciphersuite_t *info )
@@ -1672,7 +1672,7 @@
             return( 0 );
     }
 }
-#endif
+#endif /* POLARSSL_ECDH_C || POLARSSL_ECDSA_C */
 
 #if defined(POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED)
 int ssl_ciphersuite_uses_psk( const ssl_ciphersuite_t *info )
@@ -1689,6 +1689,6 @@
             return( 0 );
     }
 }
-#endif
+#endif /* POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED */
 
-#endif
+#endif /* POLARSSL_SSL_TLS_C */
diff --git a/library/ssl_cli.c b/library/ssl_cli.c
index 72299ee..b23743b 100644
--- a/library/ssl_cli.c
+++ b/library/ssl_cli.c
@@ -496,7 +496,7 @@
         return( ret );
 
     p += 4;
-#endif
+#endif /* POLARSSL_HAVE_TIME */
 
     if( ( ret = ssl->f_rng( ssl->p_rng, p, 28 ) ) != 0 )
         return( ret );
@@ -607,7 +607,7 @@
 
     *p++ = 1;
     *p++ = SSL_COMPRESS_NULL;
-#endif
+#endif /* POLARSSL_ZLIB_SUPPORT */
 
     // First write extensions, then the total length
     //
@@ -1268,8 +1268,11 @@
 
     return( 0 );
 }
-#endif
-
+#endif /* POLARSSL_KEY_EXCHANGE_ECDHE_RSA_ENABLED ||
+          POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED ||
+          POLARSSL_KEY_EXCHANGE_ECDHE_PSK_ENABLED ||
+          POLARSSL_KEY_EXCHANGE_ECDH_RSA_ENABLED ||
+          POLARSSL_KEY_EXCHANGE_ECDH_ECDSA_ENABLED */
 
 #if defined(POLARSSL_KEY_EXCHANGE_ECDHE_RSA_ENABLED) ||                     \
     defined(POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) ||                   \
@@ -1539,7 +1542,8 @@
     }
     ((void) p);
     ((void) end);
-#endif
+#endif /* POLARSSL_KEY_EXCHANGE_ECDH_RSA_ENABLED ||
+          POLARSSL_KEY_EXCHANGE_ECDH_ECDSA_ENABLED */
 
     if( ( ret = ssl_read_record( ssl ) ) != 0 )
     {
@@ -1661,7 +1665,7 @@
             }
         }
         else
-#endif
+#endif /* POLARSSL_SSL_PROTO_TLS1_2 */
 #if defined(POLARSSL_SSL_PROTO_SSL3) || defined(POLARSSL_SSL_PROTO_TLS1) || \
     defined(POLARSSL_SSL_PROTO_TLS1_1)
         if( ssl->minor_ver < SSL_MINOR_VERSION_3 )
@@ -2608,4 +2612,4 @@
 
     return( ret );
 }
-#endif
+#endif /* POLARSSL_SSL_CLI_C */
diff --git a/library/ssl_srv.c b/library/ssl_srv.c
index 21c4e2b..13057ab 100644
--- a/library/ssl_srv.c
+++ b/library/ssl_srv.c
@@ -491,7 +491,7 @@
             ssl->handshake->sig_alg = SSL_HASH_SHA384;
             break;
         }
-#endif
+#endif /* POLARSSL_SHA512_C */
 #if defined(POLARSSL_SHA256_C)
         if( p[0] == SSL_HASH_SHA256 )
         {
@@ -503,7 +503,7 @@
             ssl->handshake->sig_alg = SSL_HASH_SHA224;
             break;
         }
-#endif
+#endif /* POLARSSL_SHA256_C */
         if( p[0] == SSL_HASH_SHA1 )
         {
             ssl->handshake->sig_alg = SSL_HASH_SHA1;
@@ -552,7 +552,7 @@
     if( ( curves = polarssl_malloc( our_size * sizeof( *curves ) ) ) == NULL )
         return( POLARSSL_ERR_SSL_MALLOC_FAILED );
 
-	/* explicit void pointer cast for buggy MS compiler */
+    /* explicit void pointer cast for buggy MS compiler */
     memset( (void *) curves, 0, our_size * sizeof( *curves ) );
     ssl->handshake->curves = curves;
 
@@ -1798,7 +1798,7 @@
         return( ret );
 
     p += 4;
-#endif
+#endif /* POLARSSL_HAVE_TIME */
 
     if( ( ret = ssl->f_rng( ssl->p_rng, p, 28 ) ) != 0 )
         return( ret );
@@ -1997,7 +1997,7 @@
      *     4  .   4   cert type count
      *     5  .. m-1  cert types
      *     m  .. m+1  sig alg length (TLS 1.2 only)
-     *    m+1 .. n-1  SignatureAndHashAlgorithms (TLS 1.2 only) 
+     *    m+1 .. n-1  SignatureAndHashAlgorithms (TLS 1.2 only)
      *     n  .. n+1  length of all DNs
      *    n+2 .. n+3  length of DN 1
      *    n+4 .. ...  Distinguished Name #1
@@ -3037,7 +3037,8 @@
         }
     }
     else
-#endif
+#endif /* POLARSSL_SSL_PROTO_SSL3 || POLARSSL_SSL_PROTO_TLS1 ||
+          POLARSSL_SSL_PROTO_TLS1_1 */
 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
     if( ssl->minor_ver == SSL_MINOR_VERSION_3 )
     {
@@ -3282,4 +3283,4 @@
 
     return( ret );
 }
-#endif
+#endif /* POLARSSL_SSL_SRV_C */
diff --git a/library/ssl_tls.c b/library/ssl_tls.c
index 057c707..f3e082b 100644
--- a/library/ssl_tls.c
+++ b/library/ssl_tls.c
@@ -122,18 +122,18 @@
 
 #if defined(POLARSSL_SSL_HW_RECORD_ACCEL)
 int (*ssl_hw_record_init)(ssl_context *ssl,
-                       const unsigned char *key_enc, const unsigned char *key_dec,
-                       size_t keylen,
-                       const unsigned char *iv_enc,  const unsigned char *iv_dec,
-                       size_t ivlen,
-                       const unsigned char *mac_enc, const unsigned char *mac_dec,
-                       size_t maclen) = NULL;
+                     const unsigned char *key_enc, const unsigned char *key_dec,
+                     size_t keylen,
+                     const unsigned char *iv_enc,  const unsigned char *iv_dec,
+                     size_t ivlen,
+                     const unsigned char *mac_enc, const unsigned char *mac_dec,
+                     size_t maclen) = NULL;
 int (*ssl_hw_record_activate)(ssl_context *ssl, int direction) = NULL;
 int (*ssl_hw_record_reset)(ssl_context *ssl) = NULL;
 int (*ssl_hw_record_write)(ssl_context *ssl) = NULL;
 int (*ssl_hw_record_read)(ssl_context *ssl) = NULL;
 int (*ssl_hw_record_finish)(ssl_context *ssl) = NULL;
-#endif
+#endif /* POLARSSL_SSL_HW_RECORD_ACCEL */
 
 /*
  * Key material generation
@@ -363,7 +363,7 @@
 static void ssl_calc_verify_tls_sha384(ssl_context *,unsigned char *);
 static void ssl_calc_finished_tls_sha384(ssl_context *,unsigned char *,int);
 #endif
-#endif
+#endif /* POLARSSL_SSL_PROTO_TLS1_2 */
 
 int ssl_derive_keys( ssl_context *ssl )
 {
@@ -441,7 +441,7 @@
     }
     else
 #endif
-#endif
+#endif /* POLARSSL_SSL_PROTO_TLS1_2 */
     {
         SSL_DEBUG_MSG( 1, ( "should never happen" ) );
         return( POLARSSL_ERR_SSL_FEATURE_UNAVAILABLE );
@@ -615,7 +615,7 @@
         memcpy( transform->mac_dec, mac_dec, transform->maclen );
     }
     else
-#endif
+#endif /* POLARSSL_SSL_PROTO_SSL3 */
 #if defined(POLARSSL_SSL_PROTO_TLS1) || defined(POLARSSL_SSL_PROTO_TLS1_1) || \
     defined(POLARSSL_SSL_PROTO_TLS1_2)
     if( ssl->minor_ver >= SSL_MINOR_VERSION_1 )
@@ -647,7 +647,7 @@
             return POLARSSL_ERR_SSL_HW_ACCEL_FAILED;
         }
     }
-#endif
+#endif /* POLARSSL_SSL_HW_RECORD_ACCEL */
 
     if( ( ret = cipher_init_ctx( &transform->cipher_ctx_enc,
                                  cipher_info ) ) != 0 )
@@ -777,7 +777,7 @@
 
     return;
 }
-#endif
+#endif /* POLARSSL_SSL_PROTO_SSL3 */
 
 #if defined(POLARSSL_SSL_PROTO_TLS1) || defined(POLARSSL_SSL_PROTO_TLS1_1)
 void ssl_calc_verify_tls( ssl_context *ssl, unsigned char hash[36] )
@@ -1621,7 +1621,7 @@
             }
         }
         else
-#endif
+#endif /* POLARSSL_SSL_PROTO_SSL3 */
 #if defined(POLARSSL_SSL_PROTO_TLS1) || defined(POLARSSL_SSL_PROTO_TLS1_1) || \
     defined(POLARSSL_SSL_PROTO_TLS1_2)
         if( ssl->minor_ver > SSL_MINOR_VERSION_0 )
@@ -1719,7 +1719,7 @@
              * Process MAC and always update for padlen afterwards to make
              * total time independent of padlen
              *
-             * extra_run compensates MAC check for padlen 
+             * extra_run compensates MAC check for padlen
              *
              * Known timing attacks:
              *  - Lucky Thirteen (http://www.isg.rhul.ac.uk/tls/TLStiming.pdf)
@@ -2021,7 +2021,7 @@
         if( ret == 0 )
             done = 1;
     }
-#endif
+#endif /* POLARSSL_SSL_HW_RECORD_ACCEL */
     if( !done )
     {
         ssl->out_hdr[0] = (unsigned char) ssl->out_msgtype;
@@ -2218,7 +2218,7 @@
         if( ret == 0 )
             done = 1;
     }
-#endif
+#endif /* POLARSSL_SSL_HW_RECORD_ACCEL */
     if( !done && ssl->transform_in != NULL )
     {
         if( ( ret = ssl_decrypt_buf( ssl ) ) != 0 )
@@ -2753,7 +2753,7 @@
                     ret = POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE;
             }
         }
-#endif
+#endif /* POLARSSL_SSL_SET_CURVES */
 
         if( ssl_check_cert_usage( ssl->session_negotiate->peer_cert,
                                   ciphersuite_info,
@@ -4358,7 +4358,7 @@
                         return( ret );
                 }
                 else
-#endif
+#endif /* POLARSSL_SSL_PROTO_SSL3 */
 #if defined(POLARSSL_SSL_PROTO_TLS1) || defined(POLARSSL_SSL_PROTO_TLS1_1) || \
     defined(POLARSSL_SSL_PROTO_TLS1_2)
                 if( ssl->minor_ver >= SSL_MINOR_VERSION_1 )
@@ -4371,7 +4371,8 @@
                     }
                 }
                 else
-#endif
+#endif /* POLARSSL_SSL_PROTO_TLS1 || POLARSSL_SSL_PROTO_TLS1_1 ||
+          POLARSSL_SSL_PROTO_TLS1_2 */
                 {
                     SSL_DEBUG_MSG( 1, ( "should never happen" ) );
                     return( POLARSSL_ERR_SSL_FEATURE_UNAVAILABLE );
@@ -4562,8 +4563,8 @@
 #endif
 
 #if defined(POLARSSL_ECDH_C) || defined(POLARSSL_ECDSA_C)
-	/* explicit void pointer cast for buggy MS compiler */
-	polarssl_free( (void *) handshake->curves );
+    /* explicit void pointer cast for buggy MS compiler */
+    polarssl_free( (void *) handshake->curves );
 #endif
 
 #if defined(POLARSSL_X509_CRT_PARSE_C) && \
@@ -4583,7 +4584,7 @@
             cur = next;
         }
     }
-#endif
+#endif /* POLARSSL_X509_CRT_PARSE_C && POLARSSL_SSL_SERVER_NAME_INDICATION */
 
     memset( handshake, 0, sizeof( ssl_handshake_params ) );
 }
@@ -4736,7 +4737,7 @@
             return( POLARSSL_PK_NONE );
     }
 }
-#endif
+#endif /* POLARSSL_PK_C */
 
 /*
  * Convert between SSL_HASH_XXX and POLARSSL_MD_XXX
@@ -4785,7 +4786,7 @@
 
     return( 0 );
 }
-#endif
+#endif /* POLARSSL_SSL_SET_CURVES */
 
 #if defined(POLARSSL_X509_CRT_PARSE_C)
 int ssl_check_cert_usage( const x509_crt *cert,
diff --git a/library/timing.c b/library/timing.c
index f22591d..4b29d7e 100644
--- a/library/timing.c
+++ b/library/timing.c
@@ -63,7 +63,7 @@
     struct timeval start;
 };
 
-#endif
+#endif /* _WIN32 && !EFIX64 && !EFI32 */
 
 #if !defined(POLARSSL_HAVE_HARDCLOCK) && defined(POLARSSL_HAVE_ASM) &&  \
     (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
@@ -77,7 +77,8 @@
     __asm   mov  [tsc], eax
     return( tsc );
 }
-#endif
+#endif /* !POLARSSL_HAVE_HARDCLOCK && POLARSSL_HAVE_ASM &&
+          ( _MSC_VER && _M_IX86 ) || __WATCOMC__ */
 
 #if !defined(POLARSSL_HAVE_HARDCLOCK) && defined(POLARSSL_HAVE_ASM) &&  \
     defined(__GNUC__) && defined(__i386__)
@@ -90,7 +91,8 @@
     asm volatile( "rdtsc" : "=a" (lo), "=d" (hi) );
     return( lo );
 }
-#endif
+#endif /* !POLARSSL_HAVE_HARDCLOCK && POLARSSL_HAVE_ASM &&
+          __GNUC__ && __i386__ */
 
 #if !defined(POLARSSL_HAVE_HARDCLOCK) && defined(POLARSSL_HAVE_ASM) &&  \
     defined(__GNUC__) && (defined(__amd64__) || defined(__x86_64__))
@@ -103,7 +105,8 @@
     asm volatile( "rdtsc" : "=a" (lo), "=d" (hi) );
     return( lo | (hi << 32) );
 }
-#endif
+#endif /* !POLARSSL_HAVE_HARDCLOCK && POLARSSL_HAVE_ASM &&
+          __GNUC__ && ( __amd64__ || __x86_64__ ) */
 
 #if !defined(POLARSSL_HAVE_HARDCLOCK) && defined(POLARSSL_HAVE_ASM) &&  \
     defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
@@ -124,7 +127,8 @@
 
     return( tbl );
 }
-#endif
+#endif /* !POLARSSL_HAVE_HARDCLOCK && POLARSSL_HAVE_ASM &&
+          __GNUC__ && ( __powerpc__ || __ppc__ ) */
 
 #if !defined(POLARSSL_HAVE_HARDCLOCK) && defined(POLARSSL_HAVE_ASM) &&  \
     defined(__GNUC__) && defined(__sparc64__)
@@ -140,8 +144,9 @@
     asm volatile( "rdpr %%tick, %0;" : "=&r" (tick) );
     return( tick );
 }
-#endif
-#endif
+#endif /* __OpenBSD__ */
+#endif /* !POLARSSL_HAVE_HARDCLOCK && POLARSSL_HAVE_ASM &&
+          __GNUC__ && __sparc64__ */
 
 #if !defined(POLARSSL_HAVE_HARDCLOCK) && defined(POLARSSL_HAVE_ASM) &&  \
     defined(__GNUC__) && defined(__sparc__) && !defined(__sparc64__)
@@ -155,7 +160,8 @@
     asm volatile( "mov   %%g1, %0" : "=r" (tick) );
     return( tick );
 }
-#endif
+#endif /* !POLARSSL_HAVE_HARDCLOCK && POLARSSL_HAVE_ASM &&
+          __GNUC__ && __sparc__ && !__sparc64__ */
 
 #if !defined(POLARSSL_HAVE_HARDCLOCK) && defined(POLARSSL_HAVE_ASM) &&      \
     defined(__GNUC__) && defined(__alpha__)
@@ -168,7 +174,8 @@
     asm volatile( "rpcc %0" : "=r" (cc) );
     return( cc & 0xFFFFFFFF );
 }
-#endif
+#endif /* !POLARSSL_HAVE_HARDCLOCK && POLARSSL_HAVE_ASM &&
+          __GNUC__ && __alpha__ */
 
 #if !defined(POLARSSL_HAVE_HARDCLOCK) && defined(POLARSSL_HAVE_ASM) &&      \
     defined(__GNUC__) && defined(__ia64__)
@@ -181,7 +188,8 @@
     asm volatile( "mov %0 = ar.itc" : "=r" (itc) );
     return( itc );
 }
-#endif
+#endif /* !POLARSSL_HAVE_HARDCLOCK && POLARSSL_HAVE_ASM &&
+          __GNUC__ && __ia64__ */
 
 #if !defined(POLARSSL_HAVE_HARDCLOCK) && defined(_MSC_VER) && \
     !defined(EFIX64) && !defined(EFI32)
@@ -196,7 +204,7 @@
 
     return (unsigned long)( offset.QuadPart );
 }
-#endif
+#endif /* !POLARSSL_HAVE_HARDCLOCK && _MSC_VER && !EFIX64 && !EFI32 */
 
 #if !defined(POLARSSL_HAVE_HARDCLOCK)
 
@@ -219,7 +227,7 @@
     return( ( tv_cur.tv_sec  - tv_init.tv_sec  ) * 1000000
           + ( tv_cur.tv_usec - tv_init.tv_usec ) );
 }
-#endif
+#endif /* !POLARSSL_HAVE_HARDCLOCK */
 
 volatile int alarmed = 0;
 
@@ -461,7 +469,7 @@
 
     if( verbose != 0 )
         polarssl_printf( "passed\n" );
-#endif
+#endif /* POLARSSL_NET_C */
 
     return( 0 );
 }
diff --git a/library/version_features.c b/library/version_features.c
index 5680341..68955c3 100644
--- a/library/version_features.c
+++ b/library/version_features.c
@@ -525,7 +525,7 @@
 #if defined(POLARSSL_XTEA_C)
     "POLARSSL_XTEA_C",
 #endif /* POLARSSL_XTEA_C */
-#endif
+#endif /* POLARSSL_VERSION_FEATURES */
     NULL
 };
 
diff --git a/library/x509.c b/library/x509.c
index 88e75c1..92e52c3 100644
--- a/library/x509.c
+++ b/library/x509.c
@@ -468,7 +468,7 @@
 }
 
 #define snprintf compat_snprintf
-#endif
+#endif /* _MSC_VER && !snprintf && !EFIX64 && !EFI32 */
 
 #define POLARSSL_ERR_DEBUG_BUF_TOO_SMALL    -2
 
@@ -652,7 +652,7 @@
     now->hour = lt.tm_hour;
     now->min = lt.tm_min;
     now->sec = lt.tm_sec;
-#endif
+#endif /* _WIN32 && !EFIX64 && !EFI32 */
 }
 
 /*
@@ -796,9 +796,9 @@
 #else
     ((void) verbose);
     return( POLARSSL_ERR_X509_FEATURE_UNAVAILABLE );
-#endif
+#endif /* POLARSSL_CERTS_C && POLARSSL_SHA1_C */
 }
 
-#endif
+#endif /* POLARSSL_SELF_TEST */
 
 #endif /* POLARSSL_X509_USE_C */
diff --git a/library/x509_crl.c b/library/x509_crl.c
index 6e46e1f..7ab4056 100644
--- a/library/x509_crl.c
+++ b/library/x509_crl.c
@@ -158,7 +158,7 @@
         return( POLARSSL_ERR_X509_INVALID_EXTENSIONS + ret );
     }
 
-	end = *p + ext->len;
+    end = *p + ext->len;
 
     if( end != *p + ext->len )
         return( POLARSSL_ERR_X509_INVALID_EXTENSIONS +
@@ -316,7 +316,7 @@
         return( ret );
     }
     else
-#endif
+#endif /* POLARSSL_PEM_PARSE_C */
     {
         /*
          * nope, copy the raw DER data
@@ -583,7 +583,7 @@
 }
 
 #define snprintf compat_snprintf
-#endif
+#endif /* _MSC_VER && !snprintf && !EFIX64 && !EFI32 */
 
 #define POLARSSL_ERR_DEBUG_BUF_TOO_SMALL    -2
 
@@ -751,4 +751,4 @@
     while( crl_cur != NULL );
 }
 
-#endif
+#endif /* POLARSSL_X509_CRL_PARSE_C */
diff --git a/library/x509_crt.c b/library/x509_crt.c
index d072366..4278d6e 100644
--- a/library/x509_crt.c
+++ b/library/x509_crt.c
@@ -912,7 +912,7 @@
             success = 1;
         }
     }
-#endif
+#endif /* POLARSSL_PEM_PARSE_C */
 
     if( success )
         return( total_failed );
@@ -954,23 +954,23 @@
     int w_ret;
     WCHAR szDir[MAX_PATH];
     char filename[MAX_PATH];
-	char *p;
+    char *p;
     int len = (int) strlen( path );
 
-	WIN32_FIND_DATAW file_data;
+    WIN32_FIND_DATAW file_data;
     HANDLE hFind;
 
     if( len > MAX_PATH - 3 )
         return( POLARSSL_ERR_X509_BAD_INPUT_DATA );
 
-	memset( szDir, 0, sizeof(szDir) );
-	memset( filename, 0, MAX_PATH );
-	memcpy( filename, path, len );
-	filename[len++] = '\\';
-	p = filename + len;
+    memset( szDir, 0, sizeof(szDir) );
+    memset( filename, 0, MAX_PATH );
+    memcpy( filename, path, len );
+    filename[len++] = '\\';
+    p = filename + len;
     filename[len++] = '*';
 
-	w_ret = MultiByteToWideChar( CP_ACP, 0, filename, len, szDir, MAX_PATH - 3 );
+    w_ret = MultiByteToWideChar( CP_ACP, 0, filename, len, szDir, MAX_PATH - 3 );
 
     hFind = FindFirstFileW( szDir, &file_data );
     if (hFind == INVALID_HANDLE_VALUE)
@@ -979,15 +979,15 @@
     len = MAX_PATH - len;
     do
     {
-		memset( p, 0, len );
+        memset( p, 0, len );
 
         if( file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
             continue;
 
-		w_ret = WideCharToMultiByte( CP_ACP, 0, file_data.cFileName,
-									 lstrlenW(file_data.cFileName),
-									 p, len - 1,
-									 NULL, NULL );
+        w_ret = WideCharToMultiByte( CP_ACP, 0, file_data.cFileName,
+                                     lstrlenW(file_data.cFileName),
+                                     p, len - 1,
+                                     NULL, NULL );
 
         w_ret = x509_crt_parse_file( chain, filename );
         if( w_ret < 0 )
@@ -1086,7 +1086,7 @@
 }
 
 #define snprintf compat_snprintf
-#endif
+#endif /* _MSC_VER  && !snprintf && !EFIX64 && !EFI32 */
 
 #define POLARSSL_ERR_DEBUG_BUF_TOO_SMALL    -2
 
@@ -1405,7 +1405,7 @@
 
     return( POLARSSL_ERR_X509_BAD_INPUT_DATA );
 }
-#endif
+#endif /* POLARSSL_X509_CHECK_EXTENDED_KEY_USAGE */
 
 #if defined(POLARSSL_X509_CRL_PARSE_C)
 /*
@@ -1971,4 +1971,4 @@
     while( cert_cur != NULL );
 }
 
-#endif
+#endif /* POLARSSL_X509_CRT_PARSE_C */
diff --git a/library/x509_csr.c b/library/x509_csr.c
index 7213fd2..16e212b 100644
--- a/library/x509_csr.c
+++ b/library/x509_csr.c
@@ -129,7 +129,7 @@
         return( ret );
     }
     else
-#endif
+#endif /* POLARSSL_PEM_PARSE_C */
     {
         /*
          * nope, copy the raw DER data
@@ -332,7 +332,7 @@
 }
 
 #define snprintf compat_snprintf
-#endif
+#endif /* _MSC_VER && !snprintf && !EFIX64 && !EFI32 */
 
 #define POLARSSL_ERR_DEBUG_BUF_TOO_SMALL    -2
 
diff --git a/library/xtea.c b/library/xtea.c
index 58f970c..18a4d46 100644
--- a/library/xtea.c
+++ b/library/xtea.c
@@ -1,7 +1,7 @@
 /*
  *  An 32-bit implementation of the XTEA algorithm
  *
- *  Copyright (C) 2006-2013, Brainspark B.V.
+ *  Copyright (C) 2006-2014, Brainspark B.V.
  *
  *  This file is part of PolarSSL (http://www.polarssl.org)
  *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -255,6 +255,6 @@
     return( 0 );
 }
 
-#endif
+#endif /* POLARSSL_SELF_TEST */
 
-#endif
+#endif /* POLARSSL_XTEA_C */
diff --git a/scripts/data_files/version_features.fmt b/scripts/data_files/version_features.fmt
index 92cd6a2..f1d90cf 100644
--- a/scripts/data_files/version_features.fmt
+++ b/scripts/data_files/version_features.fmt
@@ -43,7 +43,7 @@
 const char *features[] = {
 #if defined(POLARSSL_VERSION_FEATURES)
 FEATURE_DEFINES
-#endif
+#endif /* POLARSSL_VERSION_FEATURES */
     NULL
 };