Fix formatting in various code to match spacing from coding style
diff --git a/library/aes.c b/library/aes.c
index 38e5e95..a90ceff 100644
--- a/library/aes.c
+++ b/library/aes.c
@@ -420,10 +420,10 @@
     {
         x = pow[255 - log[i]];
 
-        y  = x; y = ( (y << 1) | (y >> 7) ) & 0xFF;
-        x ^= y; y = ( (y << 1) | (y >> 7) ) & 0xFF;
-        x ^= y; y = ( (y << 1) | (y >> 7) ) & 0xFF;
-        x ^= y; y = ( (y << 1) | (y >> 7) ) & 0xFF;
+        y  = x; y = ( ( y << 1 ) | ( y >> 7 ) ) & 0xFF;
+        x ^= y; y = ( ( y << 1 ) | ( y >> 7 ) ) & 0xFF;
+        x ^= y; y = ( ( y << 1 ) | ( y >> 7 ) ) & 0xFF;
+        x ^= y; y = ( ( y << 1 ) | ( y >> 7 ) ) & 0xFF;
         x ^= y ^ 0x63;
 
         FSb[i] = (unsigned char) x;
@@ -504,7 +504,7 @@
         return( aesni_setkey_enc( (unsigned char *) ctx->rk, key, keysize ) );
 #endif
 
-    for( i = 0; i < (keysize >> 5); i++ )
+    for( i = 0; i < ( keysize >> 5 ); i++ )
     {
         GET_UINT32_LE( RK[i], key, i << 2 );
     }
@@ -726,7 +726,7 @@
 
     if( mode == AES_DECRYPT )
     {
-        for( i = (ctx->nr >> 1) - 1; i > 0; i-- )
+        for( i = ( ctx->nr >> 1 ) - 1; i > 0; i-- )
         {
             AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
             AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
@@ -760,7 +760,7 @@
     }
     else /* AES_ENCRYPT */
     {
-        for( i = (ctx->nr >> 1) - 1; i > 0; i-- )
+        for( i = ( ctx->nr >> 1 ) - 1; i > 0; i-- )
         {
             AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
             AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
@@ -893,7 +893,7 @@
             *output++ = (unsigned char)( c ^ iv[n] );
             iv[n] = (unsigned char) c;
 
-            n = (n + 1) & 0x0F;
+            n = ( n + 1 ) & 0x0F;
         }
     }
     else
@@ -905,7 +905,7 @@
 
             iv[n] = *output++ = (unsigned char)( iv[n] ^ *input++ );
 
-            n = (n + 1) & 0x0F;
+            n = ( n + 1 ) & 0x0F;
         }
     }
 
@@ -930,7 +930,7 @@
 
     while( length-- )
     {
-        memcpy(ov, iv, 16);
+        memcpy( ov, iv, 16 );
         aes_crypt_ecb( ctx, AES_ENCRYPT, iv, iv );
 
         if( mode == AES_DECRYPT )
@@ -941,7 +941,7 @@
         if( mode == AES_ENCRYPT )
             ov[16] = c;
 
-        memcpy(iv, ov + 1, 16);
+        memcpy( iv, ov + 1, 16 );
     }
 
     return( 0 );
@@ -975,7 +975,7 @@
         c = *input++;
         *output++ = (unsigned char)( c ^ stream_block[n] );
 
-        n = (n + 1) & 0x0F;
+        n = ( n + 1 ) & 0x0F;
     }
 
     *nc_off = n;
diff --git a/library/aesni.c b/library/aesni.c
index 9d21c85..9bd780f 100644
--- a/library/aesni.c
+++ b/library/aesni.c
@@ -1,7 +1,7 @@
 /*
  *  AES-NI support functions
  *
- *  Copyright (C) 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>
diff --git a/library/asn1parse.c b/library/asn1parse.c
index 79b2901..9744352 100644
--- a/library/asn1parse.c
+++ b/library/asn1parse.c
@@ -194,7 +194,7 @@
         return( ret );
 
     /* Check length, subtract one for actual bit string length */
-    if ( bs->len < 1 )
+    if( bs->len < 1 )
         return( POLARSSL_ERR_ASN1_OUT_OF_DATA );
     bs->len -= 1;
 
@@ -265,7 +265,7 @@
         *p += buf->len;
 
         /* Allocate and assign next pointer */
-        if (*p < end)
+        if( *p < end )
         {
             cur->next = (asn1_sequence *) polarssl_malloc(
                  sizeof( asn1_sequence ) );
diff --git a/library/asn1write.c b/library/asn1write.c
index b6294bb..ebc0e97 100644
--- a/library/asn1write.c
+++ b/library/asn1write.c
@@ -118,7 +118,7 @@
     // DER format assumes 2s complement for numbers, so the leftmost bit
     // should be 0 for positive numbers and 1 for negative numbers.
     //
-    if ( X->s ==1 && **p & 0x80 )
+    if( X->s ==1 && **p & 0x80 )
     {
         if( *p - start < 1 )
             return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL );
@@ -217,7 +217,7 @@
     len += 1;
     *--(*p) = val;
 
-    if ( val > 0 && **p & 0x80 )
+    if( val > 0 && **p & 0x80 )
     {
         if( *p - start < 1 )
             return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL );
diff --git a/library/base64.c b/library/base64.c
index d7f3642..5b1418b 100644
--- a/library/base64.c
+++ b/library/base64.c
@@ -87,9 +87,9 @@
     if( slen == 0 )
         return( 0 );
 
-    n = (slen << 3) / 6;
+    n = ( slen << 3 ) / 6;
 
-    switch( (slen << 3) - (n * 6) )
+    switch( ( slen << 3 ) - ( n * 6 ) )
     {
         case  2: n += 3; break;
         case  4: n += 2; break;
@@ -102,7 +102,7 @@
         return( POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL );
     }
 
-    n = (slen / 3) * 3;
+    n = ( slen / 3 ) * 3;
 
     for( i = 0, p = dst; i < n; i += 3 )
     {
@@ -119,12 +119,12 @@
     if( i < slen )
     {
         C1 = *src++;
-        C2 = ((i + 1) < slen) ? *src++ : 0;
+        C2 = ( ( i + 1 ) < slen ) ? *src++ : 0;
 
         *p++ = base64_enc_map[(C1 >> 2) & 0x3F];
         *p++ = base64_enc_map[(((C1 & 3) << 4) + (C2 >> 4)) & 0x3F];
 
-        if( (i + 1) < slen )
+        if( ( i + 1 ) < slen )
              *p++ = base64_enc_map[((C2 & 15) << 2) & 0x3F];
         else *p++ = '=';
 
@@ -171,7 +171,7 @@
     if( n == 0 )
         return( 0 );
 
-    n = ((n * 6) + 7) >> 3;
+    n = ( ( n * 6 ) + 7 ) >> 3;
 
     if( dst == NULL || *dlen < n )
     {
@@ -185,7 +185,7 @@
             continue;
 
         j -= ( base64_dec_map[*src] == 64 );
-        x  = (x << 6) | ( base64_dec_map[*src] & 0x3F );
+        x  = ( x << 6 ) | ( base64_dec_map[*src] & 0x3F );
 
         if( ++n == 4 )
         {
diff --git a/library/bignum.c b/library/bignum.c
index 110c3f4..e7b8d6d 100644
--- a/library/bignum.c
+++ b/library/bignum.c
@@ -229,13 +229,13 @@
 
     MPI_CHK( mpi_grow( X, Y->n ) );
 
-    X->s = X->s * (1 - assign) + Y->s * assign;
+    X->s = X->s * ( 1 - assign ) + Y->s * assign;
 
     for( i = 0; i < Y->n; i++ )
-        X->p[i] = X->p[i] * (1 - assign) + Y->p[i] * assign;
+        X->p[i] = X->p[i] * ( 1 - assign ) + Y->p[i] * assign;
 
     for( ; i < X->n; i++ )
-        X->p[i] *= (1 - assign);
+        X->p[i] *= ( 1 - assign );
 
 cleanup:
     return( ret );
@@ -263,15 +263,15 @@
     MPI_CHK( mpi_grow( Y, X->n ) );
 
     s = X->s;
-    X->s = X->s * (1 - swap) + Y->s * swap;
-    Y->s = Y->s * (1 - swap) +    s * swap;
+    X->s = X->s * ( 1 - swap ) + Y->s * swap;
+    Y->s = Y->s * ( 1 - swap ) +    s * swap;
 
 
     for( i = 0; i < X->n; i++ )
     {
         tmp = X->p[i];
-        X->p[i] = X->p[i] * (1 - swap) + Y->p[i] * swap;
-        Y->p[i] = Y->p[i] * (1 - swap) +     tmp * swap;
+        X->p[i] = X->p[i] * ( 1 - swap ) + Y->p[i] * swap;
+        Y->p[i] = Y->p[i] * ( 1 - swap ) +     tmp * swap;
     }
 
 cleanup:
@@ -426,7 +426,7 @@
             }
 
             MPI_CHK( mpi_get_digit( &d, radix, s[i - 1] ) );
-            X->p[j / (2 * ciL)] |= d << ( (j % (2 * ciL)) << 2 );
+            X->p[j / ( 2 * ciL )] |= d << ( ( j % ( 2 * ciL ) ) << 2 );
         }
     }
     else
@@ -1226,14 +1226,14 @@
 
     n = X.n - 1;
     t = Y.n - 1;
-    MPI_CHK( mpi_shift_l( &Y, biL * (n - t) ) );
+    MPI_CHK( mpi_shift_l( &Y, biL * ( n - t ) ) );
 
     while( mpi_cmp_mpi( &X, &Y ) >= 0 )
     {
         Z.p[n - t]++;
         MPI_CHK( mpi_sub_mpi( &X, &X, &Y ) );
     }
-    MPI_CHK( mpi_shift_r( &Y, biL * (n - t) ) );
+    MPI_CHK( mpi_shift_r( &Y, biL * ( n - t ) ) );
 
     for( i = n; i > t ; i-- )
     {
@@ -1257,8 +1257,8 @@
             r  = (t_udbl) X.p[i] << biL;
             r |= (t_udbl) X.p[i - 1];
             r /= Y.p[t];
-            if( r > ((t_udbl) 1 << biL) - 1)
-                r = ((t_udbl) 1 << biL) - 1;
+            if( r > ( (t_udbl) 1 << biL ) - 1 )
+                r = ( (t_udbl) 1 << biL ) - 1;
 
             Z.p[i - t - 1] = (t_uint) r;
 #else
@@ -1310,25 +1310,25 @@
             Z.p[i - t - 1]--;
 
             MPI_CHK( mpi_lset( &T1, 0 ) );
-            T1.p[0] = (t < 1) ? 0 : Y.p[t - 1];
+            T1.p[0] = ( t < 1 ) ? 0 : Y.p[t - 1];
             T1.p[1] = Y.p[t];
             MPI_CHK( mpi_mul_int( &T1, &T1, Z.p[i - t - 1] ) );
 
             MPI_CHK( mpi_lset( &T2, 0 ) );
-            T2.p[0] = (i < 2) ? 0 : X.p[i - 2];
-            T2.p[1] = (i < 1) ? 0 : X.p[i - 1];
+            T2.p[0] = ( i < 2 ) ? 0 : X.p[i - 2];
+            T2.p[1] = ( i < 1 ) ? 0 : X.p[i - 1];
             T2.p[2] = X.p[i];
         }
         while( mpi_cmp_mpi( &T1, &T2 ) > 0 );
 
         MPI_CHK( mpi_mul_int( &T1, &Y, Z.p[i - t - 1] ) );
-        MPI_CHK( mpi_shift_l( &T1,  biL * (i - t - 1) ) );
+        MPI_CHK( mpi_shift_l( &T1,  biL * ( i - t - 1 ) ) );
         MPI_CHK( mpi_sub_mpi( &X, &X, &T1 ) );
 
         if( mpi_cmp_int( &X, 0 ) < 0 )
         {
             MPI_CHK( mpi_copy( &T1, &Y ) );
-            MPI_CHK( mpi_shift_l( &T1, biL * (i - t - 1) ) );
+            MPI_CHK( mpi_shift_l( &T1, biL * ( i - t - 1 ) ) );
             MPI_CHK( mpi_add_mpi( &X, &X, &T1 ) );
             Z.p[i - t - 1]--;
         }
@@ -1500,7 +1500,7 @@
         *d++ = u0; d[n + 1] = 0;
     }
 
-    memcpy( A->p, d, (n + 1) * ciL );
+    memcpy( A->p, d, ( n + 1 ) * ciL );
 
     if( mpi_cmp_abs( A, N ) >= 0 )
         mpi_sub_hlp( n, N->p, A->p );
@@ -1610,7 +1610,7 @@
         /*
          * W[1 << (wsize - 1)] = W[1] ^ (wsize - 1)
          */
-        j =  one << (wsize - 1);
+        j =  one << ( wsize - 1 );
 
         MPI_CHK( mpi_grow( &W[j], N->n + 1 ) );
         MPI_CHK( mpi_copy( &W[j], &W[1]    ) );
@@ -1621,7 +1621,7 @@
         /*
          * W[i] = W[i - 1] * W[1]
          */
-        for( i = j + 1; i < (one << wsize); i++ )
+        for( i = j + 1; i < ( one << wsize ); i++ )
         {
             MPI_CHK( mpi_grow( &W[i], N->n + 1 ) );
             MPI_CHK( mpi_copy( &W[i], &W[i - 1] ) );
@@ -1673,7 +1673,7 @@
         state = 2;
 
         nbits++;
-        wbits |= (ei << (wsize - nbits));
+        wbits |= ( ei << ( wsize - nbits ) );
 
         if( nbits == wsize )
         {
@@ -1703,7 +1703,7 @@
 
         wbits <<= 1;
 
-        if( (wbits & (one << wsize)) != 0 )
+        if( ( wbits & ( one << wsize ) ) != 0 )
             mpi_montmul( X, &W[1], N, mm, &T );
     }
 
@@ -1720,7 +1720,7 @@
 
 cleanup:
 
-    for( i = (one << (wsize - 1)); i < (one << wsize); i++ )
+    for( i = ( one << ( wsize - 1 ) ); i < ( one << wsize ); i++ )
         mpi_free( &W[i] );
 
     mpi_free( &W[1] ); mpi_free( &T ); mpi_free( &Apos );
@@ -1748,7 +1748,7 @@
     lz = mpi_lsb( &TA );
     lzt = mpi_lsb( &TB );
 
-    if ( lzt < lz )
+    if( lzt < lz )
         lz = lzt;
 
     MPI_CHK( mpi_shift_r( &TA, lz ) );
@@ -2305,7 +2305,7 @@
     if( verbose != 0 )
         polarssl_printf( "  MPI test #5 (simple gcd): " );
 
-    for ( i = 0; i < GCD_PAIR_COUNT; i++)
+    for( i = 0; i < GCD_PAIR_COUNT; i++ )
     {
         MPI_CHK( mpi_lset( &X, gcd_pairs[i][0] ) );
         MPI_CHK( mpi_lset( &Y, gcd_pairs[i][1] ) );
diff --git a/library/blowfish.c b/library/blowfish.c
index 1ac01ca..d8b0c36 100644
--- a/library/blowfish.c
+++ b/library/blowfish.c
@@ -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,10 +102,10 @@
     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;
+        Xr = F( ctx, Xl ) ^ Xr;
 
         temp = Xl;
         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,10 +131,10 @@
     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;
+        Xr = F( ctx, Xl ) ^ Xr;
 
         temp = Xl;
         Xl = Xr;
@@ -225,11 +225,11 @@
 
     if( mode == BLOWFISH_DECRYPT )
     {
-        blowfish_dec(ctx, &X0, &X1);
+        blowfish_dec( ctx, &X0, &X1 );
     }
     else /* BLOWFISH_ENCRYPT */
     {
-        blowfish_enc(ctx, &X0, &X1);
+        blowfish_enc( ctx, &X0, &X1 );
     }
 
     PUT_UINT32_BE( X0, output,  0 );
@@ -318,7 +318,7 @@
             *output++ = (unsigned char)( c ^ iv[n] );
             iv[n] = (unsigned char) c;
 
-            n = (n + 1) % BLOWFISH_BLOCKSIZE;
+            n = ( n + 1 ) % BLOWFISH_BLOCKSIZE;
         }
     }
     else
@@ -330,7 +330,7 @@
 
             iv[n] = *output++ = (unsigned char)( iv[n] ^ *input++ );
 
-            n = (n + 1) % BLOWFISH_BLOCKSIZE;
+            n = ( n + 1 ) % BLOWFISH_BLOCKSIZE;
         }
     }
 
@@ -368,7 +368,7 @@
         c = *input++;
         *output++ = (unsigned char)( c ^ stream_block[n] );
 
-        n = (n + 1) % BLOWFISH_BLOCKSIZE;
+        n = ( n + 1 ) % BLOWFISH_BLOCKSIZE;
     }
 
     *nc_off = n;
diff --git a/library/camellia.c b/library/camellia.c
index b5d5ecc..f1d4d6b 100644
--- a/library/camellia.c
+++ b/library/camellia.c
@@ -287,14 +287,14 @@
     TK[2] = KC[(OFFSET) * 4 + 2];                           \
     TK[3] = KC[(OFFSET) * 4 + 3];                           \
                                                             \
-    for ( i = 1; i <= 4; i++ )                              \
-        if (shifts[(INDEX)][(OFFSET)][i -1])                \
-            ROTL(TK + i * 4, TK, (15 * i) % 32);            \
+    for( i = 1; i <= 4; i++ )                               \
+        if( shifts[(INDEX)][(OFFSET)][i -1] )               \
+            ROTL(TK + i * 4, TK, ( 15 * i ) % 32);          \
                                                             \
-    for ( i = 0; i < 20; i++ )                              \
-        if (indexes[(INDEX)][(OFFSET)][i] != -1) {          \
-        RK[indexes[(INDEX)][(OFFSET)][i]] = TK[ i ];        \
-    }                                                       \
+    for( i = 0; i < 20; i++ )                               \
+        if( indexes[(INDEX)][(OFFSET)][i] != -1 ) {         \
+            RK[indexes[(INDEX)][(OFFSET)][i]] = TK[ i ];    \
+        }                                                   \
 }
 
 static void camellia_feistel( const uint32_t x[2], const uint32_t k[2],
@@ -338,8 +338,8 @@
 
     RK = ctx->rk;
 
-    memset(t, 0, 64);
-    memset(RK, 0, sizeof(ctx->rk));
+    memset( t, 0, 64 );
+    memset( RK, 0, sizeof(ctx->rk) );
 
     switch( keysize )
     {
@@ -349,52 +349,52 @@
         default : return( POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH );
     }
 
-    for( i = 0; i < keysize / 8; ++i)
+    for( i = 0; i < keysize / 8; ++i )
         t[i] = key[i];
 
-    if (keysize == 192) {
-        for (i = 0; i < 8; i++)
+    if( keysize == 192 ) {
+        for( i = 0; i < 8; i++ )
             t[24 + i] = ~t[16 + i];
     }
 
     /*
      * Prepare SIGMA values
      */
-    for (i = 0; i < 6; i++) {
-        GET_UINT32_BE(SIGMA[i][0], SIGMA_CHARS[i], 0);
-        GET_UINT32_BE(SIGMA[i][1], SIGMA_CHARS[i], 4);
+    for( i = 0; i < 6; i++ ) {
+        GET_UINT32_BE( SIGMA[i][0], SIGMA_CHARS[i], 0 );
+        GET_UINT32_BE( SIGMA[i][1], SIGMA_CHARS[i], 4 );
     }
 
     /*
      * Key storage in KC
      * Order: KL, KR, KA, KB
      */
-    memset(KC, 0, sizeof(KC));
+    memset( KC, 0, sizeof(KC) );
 
     /* Store KL, KR */
-    for (i = 0; i < 8; i++)
-        GET_UINT32_BE(KC[i], t, i * 4);
+    for( i = 0; i < 8; i++ )
+        GET_UINT32_BE( KC[i], t, i * 4 );
 
     /* Generate KA */
-    for( i = 0; i < 4; ++i)
+    for( i = 0; i < 4; ++i )
         KC[8 + i] = KC[i] ^ KC[4 + i];
 
-    camellia_feistel(KC + 8, SIGMA[0], KC + 10);
-    camellia_feistel(KC + 10, SIGMA[1], KC + 8);
+    camellia_feistel( KC + 8, SIGMA[0], KC + 10 );
+    camellia_feistel( KC + 10, SIGMA[1], KC + 8 );
 
-    for( i = 0; i < 4; ++i)
+    for( i = 0; i < 4; ++i )
         KC[8 + i] ^= KC[i];
 
-    camellia_feistel(KC + 8, SIGMA[2], KC + 10);
-    camellia_feistel(KC + 10, SIGMA[3], KC + 8);
+    camellia_feistel( KC + 8, SIGMA[2], KC + 10 );
+    camellia_feistel( KC + 10, SIGMA[3], KC + 8 );
 
-    if (keysize > 128) {
+    if( keysize > 128 ) {
         /* Generate KB */
-        for( i = 0; i < 4; ++i)
+        for( i = 0; i < 4; ++i )
             KC[12 + i] = KC[4 + i] ^ KC[8 + i];
 
-        camellia_feistel(KC + 12, SIGMA[4], KC + 14);
-        camellia_feistel(KC + 14, SIGMA[5], KC + 12);
+        camellia_feistel( KC + 12, SIGMA[4], KC + 14 );
+        camellia_feistel( KC + 14, SIGMA[5], KC + 12 );
     }
 
     /*
@@ -402,24 +402,24 @@
      */
 
     /* Manipulating KL */
-    SHIFT_AND_PLACE(idx, 0);
+    SHIFT_AND_PLACE( idx, 0 );
 
     /* Manipulating KR */
-    if (keysize > 128) {
-        SHIFT_AND_PLACE(idx, 1);
+    if( keysize > 128 ) {
+        SHIFT_AND_PLACE( idx, 1 );
     }
 
     /* Manipulating KA */
-    SHIFT_AND_PLACE(idx, 2);
+    SHIFT_AND_PLACE( idx, 2 );
 
     /* Manipulating KB */
-    if (keysize > 128) {
-        SHIFT_AND_PLACE(idx, 3);
+    if( keysize > 128 ) {
+        SHIFT_AND_PLACE( idx, 3 );
     }
 
     /* Do transpositions */
-    for ( i = 0; i < 20; i++ ) {
-        if (transposes[idx][i] != -1) {
+    for( i = 0; i < 20; i++ ) {
+        if( transposes[idx][i] != -1 ) {
             RK[32 + 12 * idx + i] = RK[transposes[idx][i]];
         }
     }
@@ -441,7 +441,7 @@
     int ret;
 
     /* Also checks keysize */
-    if( ( ret = camellia_setkey_enc(&cty, key, keysize) ) )
+    if( ( ret = camellia_setkey_enc( &cty, key, keysize ) ) )
         return( ret );
 
     ctx->nr = cty.nr;
@@ -455,7 +455,7 @@
     *RK++ = *SK++;
     *RK++ = *SK++;
 
-    for (i = 22 + 8 * idx, SK -= 6; i > 0; i--, SK -= 4)
+    for( i = 22 + 8 * idx, SK -= 6; i > 0; i--, SK -= 4 )
     {
         *RK++ = *SK++;
         *RK++ = *SK++;
@@ -499,22 +499,22 @@
     X[2] ^= *RK++;
     X[3] ^= *RK++;
 
-    while (NR) {
+    while( NR ) {
         --NR;
-        camellia_feistel(X, RK, X + 2);
+        camellia_feistel( X, RK, X + 2 );
         RK += 2;
-        camellia_feistel(X + 2, RK, X);
+        camellia_feistel( X + 2, RK, X );
         RK += 2;
-        camellia_feistel(X, RK, X + 2);
+        camellia_feistel( X, RK, X + 2 );
         RK += 2;
-        camellia_feistel(X + 2, RK, X);
+        camellia_feistel( X + 2, RK, X );
         RK += 2;
-        camellia_feistel(X, RK, X + 2);
+        camellia_feistel( X, RK, X + 2 );
         RK += 2;
-        camellia_feistel(X + 2, RK, X);
+        camellia_feistel( X + 2, RK, X );
         RK += 2;
 
-        if (NR) {
+        if( NR ) {
             FL(X[0], X[1], RK[0], RK[1]);
             RK += 2;
             FLInv(X[2], X[3], RK[0], RK[1]);
@@ -615,7 +615,7 @@
             *output++ = (unsigned char)( c ^ iv[n] );
             iv[n] = (unsigned char) c;
 
-            n = (n + 1) & 0x0F;
+            n = ( n + 1 ) & 0x0F;
         }
     }
     else
@@ -627,7 +627,7 @@
 
             iv[n] = *output++ = (unsigned char)( iv[n] ^ *input++ );
 
-            n = (n + 1) & 0x0F;
+            n = ( n + 1 ) & 0x0F;
         }
     }
 
@@ -665,7 +665,7 @@
         c = *input++;
         *output++ = (unsigned char)( c ^ stream_block[n] );
 
-        n = (n + 1) & 0x0F;
+        n = ( n + 1 ) & 0x0F;
     }
 
     *nc_off = n;
@@ -897,7 +897,7 @@
 
     memset( key, 0, 32 );
 
-    for (j = 0; j < 6; j++) {
+    for( j = 0; j < 6; j++ ) {
         u = j >> 1;
     v = j & 1;
 
@@ -905,20 +905,20 @@
         polarssl_printf( "  CAMELLIA-ECB-%3d (%s): ", 128 + u * 64,
                          (v == CAMELLIA_DECRYPT) ? "dec" : "enc");
 
-    for (i = 0; i < CAMELLIA_TESTS_ECB; i++ ) {
-        memcpy( key, camellia_test_ecb_key[u][i], 16 + 8 * u);
+    for( i = 0; i < CAMELLIA_TESTS_ECB; i++ ) {
+        memcpy( key, camellia_test_ecb_key[u][i], 16 + 8 * u );
 
-        if (v == CAMELLIA_DECRYPT) {
-            camellia_setkey_dec(&ctx, key, 128 + u * 64);
-            memcpy(src, camellia_test_ecb_cipher[u][i], 16);
-            memcpy(dst, camellia_test_ecb_plain[i], 16);
+        if( v == CAMELLIA_DECRYPT ) {
+            camellia_setkey_dec( &ctx, key, 128 + u * 64 );
+            memcpy( src, camellia_test_ecb_cipher[u][i], 16 );
+            memcpy( dst, camellia_test_ecb_plain[i], 16 );
         } else { /* CAMELLIA_ENCRYPT */
-            camellia_setkey_enc(&ctx, key, 128 + u * 64);
-            memcpy(src, camellia_test_ecb_plain[i], 16);
-            memcpy(dst, camellia_test_ecb_cipher[u][i], 16);
+            camellia_setkey_enc( &ctx, key, 128 + u * 64 );
+            memcpy( src, camellia_test_ecb_plain[i], 16 );
+            memcpy( dst, camellia_test_ecb_cipher[u][i], 16 );
         }
 
-        camellia_crypt_ecb(&ctx, v, src, buf);
+        camellia_crypt_ecb( &ctx, v, src, buf );
 
         if( memcmp( buf, dst, 16 ) != 0 )
         {
@@ -949,29 +949,29 @@
             polarssl_printf( "  CAMELLIA-CBC-%3d (%s): ", 128 + u * 64,
                              ( v == CAMELLIA_DECRYPT ) ? "dec" : "enc" );
 
-    memcpy( src, camellia_test_cbc_iv, 16);
-    memcpy( dst, camellia_test_cbc_iv, 16);
-    memcpy( key, camellia_test_cbc_key[u], 16 + 8 * u);
+    memcpy( src, camellia_test_cbc_iv, 16 );
+    memcpy( dst, camellia_test_cbc_iv, 16 );
+    memcpy( key, camellia_test_cbc_key[u], 16 + 8 * u );
 
-    if (v == CAMELLIA_DECRYPT) {
-        camellia_setkey_dec(&ctx, key, 128 + u * 64);
+    if( v == CAMELLIA_DECRYPT ) {
+        camellia_setkey_dec( &ctx, key, 128 + u * 64 );
     } else {
-        camellia_setkey_enc(&ctx, key, 128 + u * 64);
+        camellia_setkey_enc( &ctx, key, 128 + u * 64 );
     }
 
-    for (i = 0; i < CAMELLIA_TESTS_CBC; i++ ) {
+    for( i = 0; i < CAMELLIA_TESTS_CBC; i++ ) {
 
-        if (v == CAMELLIA_DECRYPT) {
+        if( v == CAMELLIA_DECRYPT ) {
             memcpy( iv , src, 16 );
-            memcpy(src, camellia_test_cbc_cipher[u][i], 16);
-            memcpy(dst, camellia_test_cbc_plain[i], 16);
+            memcpy( src, camellia_test_cbc_cipher[u][i], 16 );
+            memcpy( dst, camellia_test_cbc_plain[i], 16 );
         } else { /* CAMELLIA_ENCRYPT */
             memcpy( iv , dst, 16 );
-            memcpy(src, camellia_test_cbc_plain[i], 16);
-            memcpy(dst, camellia_test_cbc_cipher[u][i], 16);
+            memcpy( src, camellia_test_cbc_plain[i], 16 );
+            memcpy( dst, camellia_test_cbc_cipher[u][i], 16 );
         }
 
-        camellia_crypt_cbc(&ctx, v, 16, iv, src, buf);
+        camellia_crypt_cbc( &ctx, v, 16, iv, src, buf );
 
         if( memcmp( buf, dst, 16 ) != 0 )
         {
diff --git a/library/cipher.c b/library/cipher.c
index 2d0d8d7..edef2f9 100644
--- a/library/cipher.c
+++ b/library/cipher.c
@@ -345,7 +345,7 @@
         {
             copy_len = ilen % cipher_get_block_size( ctx );
             if( copy_len == 0 && ctx->operation == POLARSSL_DECRYPT )
-                copy_len = cipher_get_block_size(ctx);
+                copy_len = cipher_get_block_size( ctx );
 
             memcpy( ctx->unprocessed_data, &( input[ilen - copy_len] ),
                     copy_len );
@@ -459,7 +459,7 @@
     for( i = 0; i < input_len; i++ )
         bad |= ( input[i] ^ padding_len ) * ( i >= pad_idx );
 
-    return( POLARSSL_ERR_CIPHER_INVALID_PADDING * (bad != 0) );
+    return( POLARSSL_ERR_CIPHER_INVALID_PADDING * ( bad != 0 ) );
 }
 #endif /* POLARSSL_CIPHER_PADDING_PKCS7 */
 
@@ -497,7 +497,7 @@
         bad &= ( input[i-1] ^ 0x80 ) | ( done == prev_done );
     }
 
-    return( POLARSSL_ERR_CIPHER_INVALID_PADDING * (bad != 0) );
+    return( POLARSSL_ERR_CIPHER_INVALID_PADDING * ( bad != 0 ) );
 
 }
 #endif /* POLARSSL_CIPHER_PADDING_ONE_AND_ZEROS */
@@ -538,7 +538,7 @@
     for( i = 0; i < input_len - 1; i++ )
         bad |= input[i] * ( i >= pad_idx );
 
-    return( POLARSSL_ERR_CIPHER_INVALID_PADDING * (bad != 0) );
+    return( POLARSSL_ERR_CIPHER_INVALID_PADDING * ( bad != 0 ) );
 }
 #endif /* POLARSSL_CIPHER_PADDING_ZEROS_AND_LEN */
 
@@ -637,7 +637,7 @@
             ctx->add_padding( ctx->unprocessed_data, cipher_get_iv_size( ctx ),
                     ctx->unprocessed_len );
         }
-        else if ( cipher_get_block_size( ctx ) != ctx->unprocessed_len )
+        else if( cipher_get_block_size( ctx ) != ctx->unprocessed_len )
         {
             /*
              * For decrypt operations, expect a full block,
diff --git a/library/cipher_wrap.c b/library/cipher_wrap.c
index ddfb006..efc4d44 100644
--- a/library/cipher_wrap.c
+++ b/library/cipher_wrap.c
@@ -1237,7 +1237,7 @@
                              unsigned int key_length )
 {
     /* we get key_length in bits, arc4 expects it in bytes */
-    if( key_length % 8 != 0)
+    if( key_length % 8 != 0 )
         return( POLARSSL_ERR_CIPHER_BAD_INPUT_DATA );
 
     arc4_setup( (arc4_context *) ctx, key, key_length / 8 );
diff --git a/library/ctr_drbg.c b/library/ctr_drbg.c
index 2b507d2..3db517d 100644
--- a/library/ctr_drbg.c
+++ b/library/ctr_drbg.c
@@ -336,7 +336,7 @@
          */
         aes_crypt_ecb( &ctx->aes_ctx, AES_ENCRYPT, ctx->counter, tmp );
 
-        use_len = (output_len > CTR_DRBG_BLOCKSIZE ) ? CTR_DRBG_BLOCKSIZE :
+        use_len = ( output_len > CTR_DRBG_BLOCKSIZE ) ? CTR_DRBG_BLOCKSIZE :
                                                        output_len;
         /*
          * Copy random block to destination
diff --git a/library/debug.c b/library/debug.c
index b747ddc..a81f502 100644
--- a/library/debug.c
+++ b/library/debug.c
@@ -1,7 +1,7 @@
 /*
  *  Debugging routines
  *
- *  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>
@@ -229,7 +229,7 @@
 
         for( k = sizeof( t_uint ) - 1; k >= 0; k-- )
         {
-            if( zeros && ( ( X->p[i - 1] >> (k << 3) ) & 0xFF ) == 0 )
+            if( zeros && ( ( X->p[i - 1] >> ( k << 3 ) ) & 0xFF ) == 0 )
                 continue;
             else
                 zeros = 0;
@@ -248,7 +248,7 @@
             }
 
             idx += snprintf( str + idx, maxlen - idx, " %02x", (unsigned int)
-                             ( X->p[i - 1] >> (k << 3) ) & 0xFF );
+                             ( X->p[i - 1] >> ( k << 3 ) ) & 0xFF );
 
             j++;
         }
diff --git a/library/des.c b/library/des.c
index a979096..8c156ae 100644
--- a/library/des.c
+++ b/library/des.c
@@ -332,7 +332,7 @@
     int i;
 
     for( i = 0; i < DES_KEY_SIZE; i++ )
-        if ( key[i] != odd_parity_table[key[i] / 2] )
+        if( key[i] != odd_parity_table[key[i] / 2] )
             return( 1 );
 
     return( 0 );
@@ -387,7 +387,7 @@
     int i;
 
     for( i = 0; i < WEAK_KEY_COUNT; i++ )
-        if( memcmp( weak_key_table[i], key, DES_KEY_SIZE) == 0)
+        if( memcmp( weak_key_table[i], key, DES_KEY_SIZE) == 0 )
             return( 1 );
 
     return( 0 );
diff --git a/library/dhm.c b/library/dhm.c
index 362cd1d..5a87e3c 100644
--- a/library/dhm.c
+++ b/library/dhm.c
@@ -535,7 +535,7 @@
     size_t n;
     unsigned char *buf;
 
-    if ( ( ret = load_file( path, &buf, &n ) ) != 0 )
+    if( ( ret = load_file( path, &buf, &n ) ) != 0 )
         return( ret );
 
     ret = dhm_parse_dhm( dhm, buf, n );
diff --git a/library/ecdh.c b/library/ecdh.c
index 738d99f..b93d82e 100644
--- a/library/ecdh.c
+++ b/library/ecdh.c
@@ -101,13 +101,13 @@
         return;
 
     ecp_group_free( &ctx->grp );
-    mpi_free      ( &ctx->d   );
     ecp_point_free( &ctx->Q   );
     ecp_point_free( &ctx->Qp  );
-    mpi_free      ( &ctx->z   );
     ecp_point_free( &ctx->Vi  );
     ecp_point_free( &ctx->Vf  );
-    mpi_free      ( &ctx->_d  );
+    mpi_free( &ctx->d  );
+    mpi_free( &ctx->z  );
+    mpi_free( &ctx->_d );
 }
 
 /*
diff --git a/library/ecdsa.c b/library/ecdsa.c
index 5d4b0d3..5af7f6b 100644
--- a/library/ecdsa.c
+++ b/library/ecdsa.c
@@ -80,7 +80,7 @@
                        const unsigned char *buf, size_t blen )
 {
     int ret;
-    size_t n_size = (grp->nbits + 7) / 8;
+    size_t n_size = ( grp->nbits + 7 ) / 8;
     size_t use_size = blen > n_size ? n_size : blen;
 
     MPI_CHK( mpi_read_binary( x, buf, use_size ) );
@@ -147,7 +147,7 @@
         blind_tries = 0;
         do
         {
-            size_t n_size = (grp->nbits + 7) / 8;
+            size_t n_size = ( grp->nbits + 7 ) / 8;
             MPI_CHK( mpi_fill_random( &t, n_size, f_rng, p_rng ) );
             MPI_CHK( mpi_shift_r( &t, 8 * n_size - grp->nbits ) );
 
diff --git a/library/ecp.c b/library/ecp.c
index 69d393c..f9fb34b 100644
--- a/library/ecp.c
+++ b/library/ecp.c
@@ -302,7 +302,7 @@
  */
 void ecp_keypair_init( ecp_keypair *key )
 {
-    if ( key == NULL )
+    if( key == NULL )
         return;
 
     ecp_group_init( &key->grp );
@@ -357,7 +357,7 @@
  */
 void ecp_keypair_free( ecp_keypair *key )
 {
-    if ( key == NULL )
+    if( key == NULL )
         return;
 
     ecp_group_free( &key->grp );
@@ -1123,7 +1123,7 @@
 {
     int ret;
     mpi l, ll;
-    size_t p_size = (grp->pbits + 7) / 8;
+    size_t p_size = ( grp->pbits + 7 ) / 8;
     int count = 0;
 
     mpi_init( &l ); mpi_init( &ll );
@@ -1247,7 +1247,7 @@
     MPI_CHK( ecp_copy( &T[0], P ) );
 
     k = 0;
-    for( i = 1; i < ( 1U << (w-1) ); i <<= 1 )
+    for( i = 1; i < ( 1U << ( w - 1 ) ); i <<= 1 )
     {
         cur = T + i;
         MPI_CHK( ecp_copy( cur, T + ( i >> 1 ) ) );
@@ -1264,7 +1264,7 @@
      * Be careful to update T[2^l] only after using it!
      */
     k = 0;
-    for( i = 1; i < ( 1U << (w-1) ); i <<= 1 )
+    for( i = 1; i < ( 1U << ( w - 1 ) ); i <<= 1 )
     {
         j = i;
         while( j-- )
@@ -1508,7 +1508,7 @@
 {
     int ret;
     mpi l;
-    size_t p_size = (grp->pbits + 7) / 8;
+    size_t p_size = ( grp->pbits + 7 ) / 8;
     int count = 0;
 
     mpi_init( &l );
@@ -1805,7 +1805,7 @@
                      void *p_rng )
 {
     int ret;
-    size_t n_size = (grp->nbits + 7) / 8;
+    size_t n_size = ( grp->nbits + 7 ) / 8;
 
 #if defined(POLARSSL_ECP_MONTGOMERY)
     if( ecp_get_type( grp ) == POLARSSL_ECP_TYPE_MONTGOMERY )
diff --git a/library/ecp_curves.c b/library/ecp_curves.c
index 5221b9f..4c0018c 100644
--- a/library/ecp_curves.c
+++ b/library/ecp_curves.c
@@ -1288,12 +1288,12 @@
         M.n = p_limbs + adjust;
     memset( Mp, 0, sizeof Mp );
     memcpy( Mp, N->p + p_limbs - adjust, M.n * sizeof( t_uint ) );
-    if (shift != 0 )
+    if( shift != 0 )
         MPI_CHK( mpi_shift_r( &M, shift ) );
     M.n += R.n - adjust; /* Make room for multiplication by R */
 
     /* N = A0 */
-    if (mask != 0 )
+    if( mask != 0 )
         N->p[p_limbs - 1] &= mask;
     for( i = p_limbs; i < N->n; i++ )
         N->p[i] = 0;
@@ -1310,12 +1310,12 @@
         M.n = p_limbs + adjust;
     memset( Mp, 0, sizeof Mp );
     memcpy( Mp, N->p + p_limbs - adjust, M.n * sizeof( t_uint ) );
-    if (shift != 0 )
+    if( shift != 0 )
         MPI_CHK( mpi_shift_r( &M, shift ) );
     M.n += R.n - adjust; /* Make room for multiplication by R */
 
     /* N = A0 */
-    if (mask != 0 )
+    if( mask != 0 )
         N->p[p_limbs - 1] &= mask;
     for( i = p_limbs; i < N->n; i++ )
         N->p[i] = 0;
diff --git a/library/entropy.c b/library/entropy.c
index 068a501..04de07f 100644
--- a/library/entropy.c
+++ b/library/entropy.c
@@ -196,7 +196,7 @@
     for( i = 0; i < ctx->source_count; i++ )
     {
         olen = 0;
-        if ( ( ret = ctx->source[i].f_source( ctx->source[i].p_source,
+        if( ( ret = ctx->source[i].f_source( ctx->source[i].p_source,
                         buf, ENTROPY_MAX_GATHER, &olen ) ) != 0 )
         {
             return( ret );
diff --git a/library/gcm.c b/library/gcm.c
index c96da4e..4e40fbf 100644
--- a/library/gcm.c
+++ b/library/gcm.c
@@ -134,7 +134,7 @@
         ctx->HH[i] = vh;
     }
 
-    for (i = 2; i < 16; i <<= 1 )
+    for( i = 2; i < 16; i <<= 1 )
     {
         uint64_t *HiL = ctx->HL + i, *HiH = ctx->HH + i;
         vh = *HiH;
diff --git a/library/havege.c b/library/havege.c
index c82a24e..de024de 100644
--- a/library/havege.c
+++ b/library/havege.c
@@ -149,7 +149,7 @@
     *C = (*C >> (15)) ^ (*C << (17)) ^ CLK;             \
     *D = (*D >> (16)) ^ (*D << (16)) ^ CLK;             \
                                                         \
-    PT1 = ( RES[(i - 8) ^ PTX] ^                        \
+    PT1 = ( RES[( i - 8 ) ^ PTX] ^                      \
             WALK[PT1 ^ PTX ^ 7] ) & (~1);               \
     PT1 ^= (PT2 ^ 0x10) & 0x10;                         \
                                                         \
diff --git a/library/md.c b/library/md.c
index 51a00c2..55b5635 100644
--- a/library/md.c
+++ b/library/md.c
@@ -234,7 +234,7 @@
 int md( const md_info_t *md_info, const unsigned char *input, size_t ilen,
             unsigned char *output )
 {
-    if ( md_info == NULL )
+    if( md_info == NULL )
         return( POLARSSL_ERR_MD_BAD_INPUT_DATA );
 
     md_info->digest_func( input, ilen, output );
@@ -270,7 +270,7 @@
     if( ctx == NULL || ctx->md_info == NULL )
         return( POLARSSL_ERR_MD_BAD_INPUT_DATA );
 
-    ctx->md_info->hmac_starts_func( ctx->md_ctx, key, keylen);
+    ctx->md_info->hmac_starts_func( ctx->md_ctx, key, keylen );
 
     return( 0 );
 }
@@ -285,12 +285,12 @@
     return( 0 );
 }
 
-int md_hmac_finish( md_context_t *ctx, unsigned char *output)
+int md_hmac_finish( md_context_t *ctx, unsigned char *output )
 {
     if( ctx == NULL || ctx->md_info == NULL )
         return( POLARSSL_ERR_MD_BAD_INPUT_DATA );
 
-    ctx->md_info->hmac_finish_func( ctx->md_ctx, output);
+    ctx->md_info->hmac_finish_func( ctx->md_ctx, output );
 
     return( 0 );
 }
@@ -300,7 +300,7 @@
     if( ctx == NULL || ctx->md_info == NULL )
         return( POLARSSL_ERR_MD_BAD_INPUT_DATA );
 
-    ctx->md_info->hmac_reset_func( ctx->md_ctx);
+    ctx->md_info->hmac_reset_func( ctx->md_ctx );
 
     return( 0 );
 }
diff --git a/library/memory_buffer_alloc.c b/library/memory_buffer_alloc.c
index 1f0c49d..7710ba5 100644
--- a/library/memory_buffer_alloc.c
+++ b/library/memory_buffer_alloc.c
@@ -306,7 +306,7 @@
 
 #if defined(POLARSSL_MEMORY_DEBUG)
         heap.total_used += cur->size;
-        if( heap.total_used > heap.maximum_used)
+        if( heap.total_used > heap.maximum_used )
             heap.maximum_used = heap.total_used;
 #endif
 #if defined(POLARSSL_MEMORY_BACKTRACE)
@@ -361,7 +361,7 @@
     if( heap.header_count > heap.maximum_header_count )
         heap.maximum_header_count = heap.header_count;
     heap.total_used += cur->size;
-    if( heap.total_used > heap.maximum_used)
+    if( heap.total_used > heap.maximum_used )
         heap.maximum_used = heap.total_used;
 #endif
 #if defined(POLARSSL_MEMORY_BACKTRACE)
diff --git a/library/net.c b/library/net.c
index 8ccf120..ad4b892 100644
--- a/library/net.c
+++ b/library/net.c
@@ -130,8 +130,8 @@
                            (((unsigned long )(n) & 0xFF000000) >> 24))
 #endif
 
-unsigned short net_htons(unsigned short n);
-unsigned long  net_htonl(unsigned long  n);
+unsigned short net_htons( unsigned short n );
+unsigned long  net_htonl( unsigned long  n );
 #define net_htons(n) POLARSSL_HTONS(n)
 #define net_htonl(n) POLARSSL_HTONL(n)
 
diff --git a/library/oid.c b/library/oid.c
index 1b5073b..24018d6 100644
--- a/library/oid.c
+++ b/library/oid.c
@@ -76,7 +76,7 @@
 int FN_NAME( const asn1_buf *oid, ATTR1_TYPE * ATTR1 )                  \
 {                                                                       \
     const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1( oid );        \
-    if( data == NULL ) return ( POLARSSL_ERR_OID_NOT_FOUND );           \
+    if( data == NULL ) return( POLARSSL_ERR_OID_NOT_FOUND );            \
     *ATTR1 = data->descriptor.ATTR1;                                    \
     return( 0 );                                                        \
 }
@@ -89,7 +89,7 @@
 int FN_NAME( const asn1_buf *oid, ATTR1_TYPE * ATTR1 )                  \
 {                                                                       \
     const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1( oid );        \
-    if( data == NULL ) return ( POLARSSL_ERR_OID_NOT_FOUND );           \
+    if( data == NULL ) return( POLARSSL_ERR_OID_NOT_FOUND );            \
     *ATTR1 = data->ATTR1;                                               \
     return( 0 );                                                        \
 }
@@ -103,7 +103,7 @@
 int FN_NAME( const asn1_buf *oid, ATTR1_TYPE * ATTR1, ATTR2_TYPE * ATTR2 )  \
 {                                                                           \
     const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1( oid );            \
-    if( data == NULL ) return ( POLARSSL_ERR_OID_NOT_FOUND );               \
+    if( data == NULL ) return( POLARSSL_ERR_OID_NOT_FOUND );                \
     *ATTR1 = data->ATTR1;                                                   \
     *ATTR2 = data->ATTR2;                                                   \
     return( 0 );                                                            \
@@ -609,7 +609,7 @@
  * This fuction tries to 'fix' this by at least suggesting enlarging the
  * size by 20.
  */
-static int compat_snprintf(char *str, size_t size, const char *format, ...)
+static int compat_snprintf( char *str, size_t size, const char *format, ... )
 {
     va_list ap;
     int res = -1;
@@ -621,7 +621,7 @@
     va_end( ap );
 
     // No quick fix possible
-    if ( res < 0 )
+    if( res < 0 )
         return( (int) size + 20 );
 
     return( res );
@@ -635,7 +635,7 @@
     if( ret == -1 )                                 \
         return( POLARSSL_ERR_OID_BUF_TOO_SMALL );   \
                                                     \
-    if ( (unsigned int) ret >= n ) {                \
+    if( (unsigned int) ret >= n ) {                 \
         p[n - 1] = '\0';                            \
         return( POLARSSL_ERR_OID_BUF_TOO_SMALL );   \
     }                                               \
@@ -667,7 +667,7 @@
     for( i = 1; i < oid->len; i++ )
     {
         /* Prevent overflow in value. */
-        if ( ( ( value << 7 ) >> 7 ) != value )
+        if( ( ( value << 7 ) >> 7 ) != value )
             return( POLARSSL_ERR_OID_BUF_TOO_SMALL );
 
         value <<= 7;
diff --git a/library/padlock.c b/library/padlock.c
index ccc477e..d277ccf 100644
--- a/library/padlock.c
+++ b/library/padlock.c
@@ -137,9 +137,9 @@
     memcpy( iw, iv, 16 );
 
      ctrl = iw + 4;
-    *ctrl = 0x80 | ctx->nr | ( ( ctx->nr + (mode^1) - 10 ) << 9 );
+    *ctrl = 0x80 | ctx->nr | ( ( ctx->nr + ( mode ^ 1 ) - 10 ) << 9 );
 
-    count = (length + 15) >> 4;
+    count = ( length + 15 ) >> 4;
 
     asm( "pushfl; popfl         \n"     \
          "movl    %%ebx, %0     \n"     \
diff --git a/library/pbkdf2.c b/library/pbkdf2.c
index 6572274..e76f066 100644
--- a/library/pbkdf2.c
+++ b/library/pbkdf2.c
@@ -6,7 +6,7 @@
  *
  * \author Mathias Olsson <mathias@kompetensum.com>
  *
- *  Copyright (C) 2006-2012, 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>
diff --git a/library/pk.c b/library/pk.c
index 63f27de..11faf3c 100644
--- a/library/pk.c
+++ b/library/pk.c
@@ -1,7 +1,7 @@
 /*
  *  Public Key abstraction layer
  *
- *  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>
@@ -66,7 +66,7 @@
  */
 void pk_free( pk_context *ctx )
 {
-    if( ctx == NULL || ctx->pk_info == NULL)
+    if( ctx == NULL || ctx->pk_info == NULL )
         return;
 
     ctx->pk_info->ctx_free_func( ctx->pk_ctx );
diff --git a/library/pkcs11.c b/library/pkcs11.c
index 409313e..64e7ce3 100644
--- a/library/pkcs11.c
+++ b/library/pkcs11.c
@@ -75,7 +75,7 @@
         goto cleanup;
     }
 
-    if( 0 != x509_crt_parse(cert, cert_blob, cert_blob_size ) )
+    if( 0 != x509_crt_parse( cert, cert_blob, cert_blob_size ) )
     {
         ret = 6;
         goto cleanup;
@@ -105,7 +105,7 @@
     if( 0 != pkcs11_x509_cert_init( &cert, pkcs11_cert ) )
         goto cleanup;
 
-    priv_key->len = pk_get_len(&cert.pk);
+    priv_key->len = pk_get_len( &cert.pk );
     priv_key->pkcs11h_cert = pkcs11_cert;
 
     ret = 0;
@@ -191,13 +191,13 @@
     }
 
     sig_len = ctx->len;
-    if ( hashlen > sig_len || asn_len > sig_len ||
-         hashlen + asn_len > sig_len )
+    if( hashlen > sig_len || asn_len > sig_len ||
+        hashlen + asn_len > sig_len )
     {
         return( POLARSSL_ERR_RSA_BAD_INPUT_DATA );
     }
 
-    if( md_alg != POLARSSL_MD_NONE)
+    if( md_alg != POLARSSL_MD_NONE )
     {
         /*
          * DigestInfo ::= SEQUENCE {
diff --git a/library/pkcs12.c b/library/pkcs12.c
index 2b130a2..c6372a1 100644
--- a/library/pkcs12.c
+++ b/library/pkcs12.c
@@ -93,14 +93,14 @@
     size_t i;
     unsigned char unipwd[258];
 
-    memset(&salt, 0, sizeof(asn1_buf));
-    memset(&unipwd, 0, sizeof(unipwd));
+    memset( &salt, 0, sizeof(asn1_buf) );
+    memset( &unipwd, 0, sizeof(unipwd) );
 
     if( ( ret = pkcs12_parse_pbe_params( pbe_params, &salt,
                                          &iterations ) ) != 0 )
         return( ret );
 
-    for(i = 0; i < pwdlen; i++)
+    for( i = 0; i < pwdlen; i++ )
         unipwd[i * 2 + 1] = pwd[i];
 
     if( ( ret = pkcs12_derivation( key, keylen, unipwd, pwdlen * 2 + 2,
@@ -252,7 +252,7 @@
     if( md_info == NULL )
         return( POLARSSL_ERR_PKCS12_FEATURE_UNAVAILABLE );
 
-    if ( ( ret = md_init_ctx( &md_ctx, md_info ) ) != 0 )
+    if( ( ret = md_init_ctx( &md_ctx, md_info ) ) != 0 )
         return( ret );
     hlen = md_get_size( md_info );
 
diff --git a/library/pkcs5.c b/library/pkcs5.c
index e8642a6..8f6a814 100644
--- a/library/pkcs5.c
+++ b/library/pkcs5.c
@@ -168,7 +168,7 @@
         return( POLARSSL_ERR_PKCS5_INVALID_FORMAT + ret );
     }
 
-    if ( oid_get_cipher_alg( &enc_scheme_oid, &cipher_alg ) != 0 )
+    if( oid_get_cipher_alg( &enc_scheme_oid, &cipher_alg ) != 0 )
         return( POLARSSL_ERR_PKCS5_FEATURE_UNAVAILABLE );
 
     cipher_info = cipher_info_from_type( cipher_alg );
@@ -188,8 +188,8 @@
     if( ( ret = md_init_ctx( &md_ctx, md_info ) ) != 0 )
         goto exit;
 
-    if ( ( ret = pkcs5_pbkdf2_hmac( &md_ctx, pwd, pwdlen, salt.p, salt.len,
-                                    iterations, keylen, key ) ) != 0 )
+    if( ( ret = pkcs5_pbkdf2_hmac( &md_ctx, pwd, pwdlen, salt.p, salt.len,
+                                   iterations, keylen, key ) ) != 0 )
     {
         goto exit;
     }
@@ -260,7 +260,7 @@
 
         memcpy( md1, work, md_size );
 
-        for ( i = 1; i < iteration_count; i++ )
+        for( i = 1; i < iteration_count; i++ )
         {
             // U2 ends up in md1
             //
diff --git a/library/pkparse.c b/library/pkparse.c
index 218f38a..3c8063f 100644
--- a/library/pkparse.c
+++ b/library/pkparse.c
@@ -120,7 +120,7 @@
     size_t n;
     unsigned char *buf;
 
-    if ( (ret = load_file( path, &buf, &n ) ) != 0 )
+    if( ( ret = load_file( path, &buf, &n ) ) != 0 )
         return( ret );
 
     if( pwd == NULL )
@@ -144,7 +144,7 @@
     size_t n;
     unsigned char *buf;
 
-    if ( (ret = load_file( path, &buf, &n ) ) != 0 )
+    if( ( ret = load_file( path, &buf, &n ) ) != 0 )
         return( ret );
 
     ret = pk_parse_public_key( ctx, buf, n );
@@ -810,7 +810,7 @@
                 return( POLARSSL_ERR_PK_KEY_INVALID_FORMAT );
         }
     }
-    else if ( ret != POLARSSL_ERR_ASN1_UNEXPECTED_TAG )
+    else if( ret != POLARSSL_ERR_ASN1_UNEXPECTED_TAG )
     {
         ecp_keypair_free( eck );
         return( POLARSSL_ERR_PK_KEY_INVALID_FORMAT + ret );
diff --git a/library/rsa.c b/library/rsa.c
index abc028d..3cbac66 100644
--- a/library/rsa.c
+++ b/library/rsa.c
@@ -603,7 +603,7 @@
 
             // Check if RNG failed to generate data
             //
-            if( rng_dl == 0 || ret != 0)
+            if( rng_dl == 0 || ret != 0 )
                 return( POLARSSL_ERR_RSA_RNG_FAILED + ret );
 
             p++;
@@ -759,7 +759,7 @@
     if( bad != 0 )
         return( POLARSSL_ERR_RSA_INVALID_PADDING );
 
-    if (ilen - (p - buf) > output_max_len)
+    if( ilen - ( p - buf ) > output_max_len )
         return( POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE );
 
     *olen = ilen - (p - buf);
@@ -844,7 +844,7 @@
     if( bad )
         return( POLARSSL_ERR_RSA_INVALID_PADDING );
 
-    if (ilen - (p - buf) > output_max_len)
+    if( ilen - ( p - buf ) > output_max_len )
         return( POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE );
 
     *olen = ilen - (p - buf);
diff --git a/library/sha1.c b/library/sha1.c
index ce81579..a528d8e 100644
--- a/library/sha1.c
+++ b/library/sha1.c
@@ -118,8 +118,8 @@
 
 #define R(t)                                            \
 (                                                       \
-    temp = W[(t -  3) & 0x0F] ^ W[(t - 8) & 0x0F] ^     \
-           W[(t - 14) & 0x0F] ^ W[ t      & 0x0F],      \
+    temp = W[( t -  3 ) & 0x0F] ^ W[( t - 8 ) & 0x0F] ^ \
+           W[( t - 14 ) & 0x0F] ^ W[  t       & 0x0F],  \
     ( W[t & 0x0F] = S(temp,1) )                         \
 )
 
diff --git a/library/ssl_cli.c b/library/ssl_cli.c
index 19c33a7..fda9ebf 100644
--- a/library/ssl_cli.c
+++ b/library/ssl_cli.c
@@ -71,7 +71,7 @@
 
     *olen = 0;
 
-    if ( ssl->hostname == NULL )
+    if( ssl->hostname == NULL )
         return;
 
     SSL_DEBUG_MSG( 3, ( "client hello, adding server name extension: %s",
@@ -2470,7 +2470,7 @@
      * Zero-length ticket means the server changed his mind and doesn't want
      * to send a ticket after all, so just forget it
      */
-    if( ticket_len == 0)
+    if( ticket_len == 0 )
         return( 0 );
 
     polarssl_zeroize( ssl->session_negotiate->ticket,
diff --git a/library/ssl_srv.c b/library/ssl_srv.c
index 03b8010..dfa7e48 100644
--- a/library/ssl_srv.c
+++ b/library/ssl_srv.c
@@ -211,7 +211,7 @@
      */
     state = p + 2;
     if( ssl_save_session( ssl->session_negotiate, state,
-                          SSL_MAX_CONTENT_LEN - (state - ssl->out_ctr) - 48,
+                          SSL_MAX_CONTENT_LEN - ( state - ssl->out_ctr ) - 48,
                           &clear_len ) != 0 )
     {
         return( POLARSSL_ERR_SSL_CERTIFICATE_TOO_LARGE );
@@ -2343,7 +2343,7 @@
 #endif /* POLARSSL_SSL_PROTO_TLS1_2 */
 #if defined(POLARSSL_SSL_PROTO_SSL3) || defined(POLARSSL_SSL_PROTO_TLS1) || \
     defined(POLARSSL_SSL_PROTO_TLS1_1)
-        if ( ciphersuite_info->key_exchange ==
+        if( ciphersuite_info->key_exchange ==
                   POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA )
         {
             md_alg = POLARSSL_MD_SHA1;
@@ -2397,6 +2397,7 @@
         if( md_alg != POLARSSL_MD_NONE )
         {
             md_context_t ctx;
+            const md_info_t *md_info = md_info_from_type( md_alg );
 
             /* Info from md_alg will be used instead */
             hashlen = 0;
@@ -2408,7 +2409,7 @@
              *     ServerDHParams params;
              * };
              */
-            if( ( ret = md_init_ctx( &ctx, md_info_from_type(md_alg) ) ) != 0 )
+            if( ( ret = md_init_ctx( &ctx, md_info ) ) != 0 )
             {
                 SSL_DEBUG_RET( 1, "md_init_ctx", ret );
                 return( ret );
diff --git a/library/ssl_tls.c b/library/ssl_tls.c
index a6c924c..1c5249c 100644
--- a/library/ssl_tls.c
+++ b/library/ssl_tls.c
@@ -126,18 +126,18 @@
 }
 
 #if defined(POLARSSL_SSL_HW_RECORD_ACCEL)
-int (*ssl_hw_record_init)(ssl_context *ssl,
+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;
-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;
+                     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 /* POLARSSL_SSL_HW_RECORD_ACCEL */
 
 /*
@@ -339,34 +339,34 @@
 #endif /* POLARSSL_SHA512_C */
 #endif /* POLARSSL_SSL_PROTO_TLS1_2 */
 
-static void ssl_update_checksum_start(ssl_context *, const unsigned char *, size_t);
+static void ssl_update_checksum_start( ssl_context *, const unsigned char *, size_t );
 
 #if defined(POLARSSL_SSL_PROTO_SSL3) || defined(POLARSSL_SSL_PROTO_TLS1) || \
     defined(POLARSSL_SSL_PROTO_TLS1_1)
-static void ssl_update_checksum_md5sha1(ssl_context *, const unsigned char *, size_t);
+static void ssl_update_checksum_md5sha1( ssl_context *, const unsigned char *, size_t );
 #endif
 
 #if defined(POLARSSL_SSL_PROTO_SSL3)
-static void ssl_calc_verify_ssl(ssl_context *,unsigned char *);
-static void ssl_calc_finished_ssl(ssl_context *,unsigned char *,int);
+static void ssl_calc_verify_ssl( ssl_context *, unsigned char * );
+static void ssl_calc_finished_ssl( ssl_context *, unsigned char *, int );
 #endif
 
 #if defined(POLARSSL_SSL_PROTO_TLS1) || defined(POLARSSL_SSL_PROTO_TLS1_1)
-static void ssl_calc_verify_tls(ssl_context *,unsigned char *);
-static void ssl_calc_finished_tls(ssl_context *,unsigned char *,int);
+static void ssl_calc_verify_tls( ssl_context *, unsigned char * );
+static void ssl_calc_finished_tls( ssl_context *, unsigned char *, int );
 #endif
 
 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
 #if defined(POLARSSL_SHA256_C)
-static void ssl_update_checksum_sha256(ssl_context *, const unsigned char *, size_t);
-static void ssl_calc_verify_tls_sha256(ssl_context *,unsigned char *);
-static void ssl_calc_finished_tls_sha256(ssl_context *,unsigned char *,int);
+static void ssl_update_checksum_sha256( ssl_context *, const unsigned char *, size_t );
+static void ssl_calc_verify_tls_sha256( ssl_context *,unsigned char * );
+static void ssl_calc_finished_tls_sha256( ssl_context *,unsigned char *, int );
 #endif
 
 #if defined(POLARSSL_SHA512_C)
-static void ssl_update_checksum_sha384(ssl_context *, const unsigned char *, size_t);
-static void ssl_calc_verify_tls_sha384(ssl_context *,unsigned char *);
-static void ssl_calc_finished_tls_sha384(ssl_context *,unsigned char *,int);
+static void ssl_update_checksum_sha384( ssl_context *, const unsigned char *, size_t );
+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 /* POLARSSL_SSL_PROTO_TLS1_2 */
 
@@ -637,7 +637,7 @@
     }
 
 #if defined(POLARSSL_SSL_HW_RECORD_ACCEL)
-    if( ssl_hw_record_init != NULL)
+    if( ssl_hw_record_init != NULL )
     {
         int ret = 0;
 
@@ -911,7 +911,7 @@
         size_t zlen;
 
         if( ( ret = ecdh_calc_secret( &ssl->handshake->ecdh_ctx, &zlen,
-                                       p + 2, end - (p + 2),
+                                       p + 2, end - ( p + 2 ),
                                        ssl->f_rng, ssl->p_rng ) ) != 0 )
         {
             SSL_DEBUG_RET( 1, "ecdh_calc_secret", ret );
@@ -1529,7 +1529,7 @@
             correct &= ( pad_count == padlen ); /* Only 1 on correct padding */
 
 #if defined(POLARSSL_SSL_DEBUG_ALL)
-            if( padlen > 0 && correct == 0)
+            if( padlen > 0 && correct == 0 )
                 SSL_DEBUG_MSG( 1, ( "bad padding byte detected" ) );
 #endif
             padlen &= correct * 0x1FF;
@@ -1879,7 +1879,7 @@
 #endif /*POLARSSL_ZLIB_SUPPORT */
 
 #if defined(POLARSSL_SSL_HW_RECORD_ACCEL)
-    if( ssl_hw_record_write != NULL)
+    if( ssl_hw_record_write != NULL )
     {
         SSL_DEBUG_MSG( 2, ( "going for ssl_hw_record_write()" ) );
 
@@ -2077,7 +2077,7 @@
                    ssl->in_hdr, 5 + ssl->in_msglen );
 
 #if defined(POLARSSL_SSL_HW_RECORD_ACCEL)
-    if( ssl_hw_record_read != NULL)
+    if( ssl_hw_record_read != NULL )
     {
         SSL_DEBUG_MSG( 2, ( "going for ssl_hw_record_read()" ) );
 
@@ -3118,7 +3118,7 @@
     memset( ssl->out_ctr, 0, 8 );
 
 #if defined(POLARSSL_SSL_HW_RECORD_ACCEL)
-    if( ssl_hw_record_activate != NULL)
+    if( ssl_hw_record_activate != NULL )
     {
         if( ( ret = ssl_hw_record_activate( ssl, SSL_CHANNEL_OUTBOUND ) ) != 0 )
         {
@@ -3170,7 +3170,7 @@
         ssl->in_msg = ssl->in_iv;
 
 #if defined(POLARSSL_SSL_HW_RECORD_ACCEL)
-    if( ssl_hw_record_activate != NULL)
+    if( ssl_hw_record_activate != NULL )
     {
         if( ( ret = ssl_hw_record_activate( ssl, SSL_CHANNEL_INBOUND ) ) != 0 )
         {
@@ -3412,7 +3412,7 @@
     memset( ssl->in_ctr, 0, SSL_BUFFER_LEN );
 
 #if defined(POLARSSL_SSL_HW_RECORD_ACCEL)
-    if( ssl_hw_record_reset != NULL)
+    if( ssl_hw_record_reset != NULL )
     {
         SSL_DEBUG_MSG( 2, ( "going for ssl_hw_record_reset()" ) );
         if( ( ret = ssl_hw_record_reset( ssl ) ) != 0 )
@@ -3777,13 +3777,13 @@
 {
     int ret;
 
-    if( ( ret = mpi_copy(&ssl->dhm_P, &dhm_ctx->P) ) != 0 )
+    if( ( ret = mpi_copy( &ssl->dhm_P, &dhm_ctx->P ) ) != 0 )
     {
         SSL_DEBUG_RET( 1, "mpi_copy", ret );
         return( ret );
     }
 
-    if( ( ret = mpi_copy(&ssl->dhm_G, &dhm_ctx->G) ) != 0 )
+    if( ( ret = mpi_copy( &ssl->dhm_G, &dhm_ctx->G ) ) != 0 )
     {
         SSL_DEBUG_RET( 1, "mpi_copy", ret );
         return( ret );
@@ -4544,7 +4544,7 @@
 #endif
 
 #if defined(POLARSSL_SSL_SERVER_NAME_INDICATION)
-    if ( ssl->hostname != NULL )
+    if( ssl->hostname != NULL )
     {
         polarssl_zeroize( ssl->hostname, ssl->hostname_len );
         polarssl_free( ssl->hostname );
diff --git a/library/threading.c b/library/threading.c
index 5b25e01..522c70f 100644
--- a/library/threading.c
+++ b/library/threading.c
@@ -1,7 +1,7 @@
 /*
  *  Threading abstraction layer
  *
- *  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>
diff --git a/library/timing.c b/library/timing.c
index 5437320..6c1dfa4 100644
--- a/library/timing.c
+++ b/library/timing.c
@@ -66,7 +66,7 @@
 #endif /* _WIN32 && !EFIX64 && !EFI32 */
 
 #if !defined(POLARSSL_HAVE_HARDCLOCK) && defined(POLARSSL_HAVE_ASM) &&  \
-    (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
+    ( defined(_MSC_VER) && defined(_M_IX86) ) || defined(__WATCOMC__)
 
 #define POLARSSL_HAVE_HARDCLOCK
 
@@ -95,7 +95,7 @@
           __GNUC__ && __i386__ */
 
 #if !defined(POLARSSL_HAVE_HARDCLOCK) && defined(POLARSSL_HAVE_ASM) &&  \
-    defined(__GNUC__) && (defined(__amd64__) || defined(__x86_64__))
+    defined(__GNUC__) && ( defined(__amd64__) || defined(__x86_64__) )
 
 #define POLARSSL_HAVE_HARDCLOCK
 
@@ -103,13 +103,13 @@
 {
     unsigned long lo, hi;
     asm volatile( "rdtsc" : "=a" (lo), "=d" (hi) );
-    return( lo | (hi << 32) );
+    return( lo | ( hi << 32 ) );
 }
 #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__))
+    defined(__GNUC__) && ( defined(__powerpc__) || defined(__ppc__) )
 
 #define POLARSSL_HAVE_HARDCLOCK
 
@@ -368,7 +368,7 @@
     int hardfail;
     struct hr_time hires;
 
-    if( verbose != 0)
+    if( verbose != 0 )
         polarssl_printf( "  TIMING tests note: will take some time!\n" );
 
     if( verbose != 0 )
diff --git a/library/x509.c b/library/x509.c
index 73e1347..4c54b5b 100644
--- a/library/x509.c
+++ b/library/x509.c
@@ -483,7 +483,7 @@
 
     tag = **p;
 
-    if ( tag == ASN1_UTC_TIME )
+    if( tag == ASN1_UTC_TIME )
     {
         (*p)++;
         ret = asn1_get_len( p, end, &len );
@@ -507,7 +507,7 @@
 
         return( 0 );
     }
-    else if ( tag == ASN1_GENERALIZED_TIME )
+    else if( tag == ASN1_GENERALIZED_TIME )
     {
         (*p)++;
         ret = asn1_get_len( p, end, &len );
@@ -703,7 +703,7 @@
  * This fuction tries to 'fix' this by at least suggesting enlarging the
  * size by 20.
  */
-static int compat_snprintf(char *str, size_t size, const char *format, ...)
+static int compat_snprintf( char *str, size_t size, const char *format, ... )
 {
     va_list ap;
     int res = -1;
@@ -715,7 +715,7 @@
     va_end( ap );
 
     // No quick fix possible
-    if ( res < 0 )
+    if( res < 0 )
         return( (int) size + 20 );
 
     return( res );
@@ -731,7 +731,7 @@
     if( ret == -1 )                                 \
         return( -1 );                               \
                                                     \
-    if ( (unsigned int) ret > n ) {                 \
+    if( (unsigned int) ret > n ) {                  \
         p[n - 1] = '\0';                            \
         return( POLARSSL_ERR_DEBUG_BUF_TOO_SMALL ); \
     }                                               \
@@ -930,7 +930,7 @@
 #if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
     SYSTEMTIME st;
 
-    GetSystemTime(&st);
+    GetSystemTime( &st );
 
     now->year = st.wYear;
     now->mon = st.wMonth;
@@ -1080,7 +1080,7 @@
         if( verbose != 0 )
             polarssl_printf( "failed\n" );
 
-        polarssl_printf("ret = %d, &flags = %04x\n", ret, flags);
+        polarssl_printf( "ret = %d, &flags = %04x\n", ret, flags );
 
         return( ret );
     }
diff --git a/library/x509_create.c b/library/x509_create.c
index 8976c72..96b153b 100644
--- a/library/x509_create.c
+++ b/library/x509_create.c
@@ -1,7 +1,7 @@
 /*
  *  X.509 base functions for creating certificates / CSRs
  *
- *  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>
diff --git a/library/x509_crl.c b/library/x509_crl.c
index c7b1d64..7f8600d 100644
--- a/library/x509_crl.c
+++ b/library/x509_crl.c
@@ -142,7 +142,7 @@
     size_t len = 0;
 
     /* OPTIONAL */
-    if (end <= *p)
+    if( end <= *p )
         return( 0 );
 
     ext->tag = **p;
@@ -237,7 +237,7 @@
                                             &cur_entry->entry_ext ) ) != 0 )
             return( ret );
 
-        if ( *p < end )
+        if( *p < end )
         {
             cur_entry->next = polarssl_malloc( sizeof( x509_crl_entry ) );
 
@@ -285,7 +285,7 @@
     /*
      * Add new CRL on the end of the chain if needed.
      */
-    if ( crl->version != 0 && crl->next == NULL)
+    if( crl->version != 0 && crl->next == NULL )
     {
         crl->next = (x509_crl *) polarssl_malloc( sizeof( x509_crl ) );
 
@@ -443,9 +443,9 @@
 
     if( ( ret = x509_get_time( &p, end, &crl->next_update ) ) != 0 )
     {
-        if ( ret != ( POLARSSL_ERR_X509_INVALID_DATE +
+        if( ret != ( POLARSSL_ERR_X509_INVALID_DATE +
                         POLARSSL_ERR_ASN1_UNEXPECTED_TAG ) &&
-             ret != ( POLARSSL_ERR_X509_INVALID_DATE +
+            ret != ( POLARSSL_ERR_X509_INVALID_DATE +
                         POLARSSL_ERR_ASN1_OUT_OF_DATA ) )
         {
             x509_crl_free( crl );
@@ -504,7 +504,7 @@
     if( crl->sig_oid1.len != crl->sig_oid2.len ||
         memcmp( crl->sig_oid1.p, crl->sig_oid2.p, crl->sig_oid1.len ) != 0 ||
         sig_params1.len != sig_params2.len ||
-        memcmp( sig_params1.p, sig_params2.p, sig_params1.len ) != 0)
+        memcmp( sig_params1.p, sig_params2.p, sig_params1.len ) != 0 )
     {
         x509_crl_free( crl );
         return( POLARSSL_ERR_X509_SIG_MISMATCH );
@@ -552,7 +552,7 @@
     size_t n;
     unsigned char *buf;
 
-    if ( ( ret = x509_load_file( path, &buf, &n ) ) != 0 )
+    if( ( ret = x509_load_file( path, &buf, &n ) ) != 0 )
         return( ret );
 
     ret = x509_crl_parse( chain, buf, n );
@@ -579,7 +579,7 @@
  * This fuction tries to 'fix' this by at least suggesting enlarging the
  * size by 20.
  */
-static int compat_snprintf(char *str, size_t size, const char *format, ...)
+static int compat_snprintf( char *str, size_t size, const char *format, ... )
 {
     va_list ap;
     int res = -1;
@@ -591,7 +591,7 @@
     va_end( ap );
 
     // No quick fix possible
-    if ( res < 0 )
+    if( res < 0 )
         return( (int) size + 20 );
 
     return( res );
@@ -607,7 +607,7 @@
     if( ret == -1 )                                 \
         return( -1 );                               \
                                                     \
-    if ( (unsigned int) ret > n ) {                 \
+    if( (unsigned int) ret > n ) {                  \
         p[n - 1] = '\0';                            \
         return( POLARSSL_ERR_DEBUG_BUF_TOO_SMALL ); \
     }                                               \
@@ -670,7 +670,7 @@
                                prefix );
         SAFE_SNPRINTF();
 
-        ret = x509_serial_gets( p, n, &entry->serial);
+        ret = x509_serial_gets( p, n, &entry->serial );
         SAFE_SNPRINTF();
 
         ret = snprintf( p, n, " revocation date: " \
diff --git a/library/x509_crt.c b/library/x509_crt.c
index 4fc3566..50f92e6 100644
--- a/library/x509_crt.c
+++ b/library/x509_crt.c
@@ -723,7 +723,7 @@
     if( crt->version == 3 )
     {
 #endif
-        ret = x509_get_crt_ext( &p, end, crt);
+        ret = x509_get_crt_ext( &p, end, crt );
         if( ret != 0 )
         {
             x509_crt_free( crt );
@@ -758,7 +758,7 @@
     if( crt->sig_oid1.len != crt->sig_oid2.len ||
         memcmp( crt->sig_oid1.p, crt->sig_oid2.p, crt->sig_oid1.len ) != 0 ||
         sig_params1.len != sig_params2.len ||
-        memcmp( sig_params1.p, sig_params2.p, sig_params1.len ) != 0)
+        memcmp( sig_params1.p, sig_params2.p, sig_params1.len ) != 0 )
     {
         x509_crt_free( crt );
         return( POLARSSL_ERR_X509_SIG_MISMATCH );
@@ -805,7 +805,7 @@
     /*
      * Add new certificate on the end of the chain if needed.
      */
-    if ( crt->version != 0 && crt->next == NULL)
+    if( crt->version != 0 && crt->next == NULL )
     {
         crt->next = (x509_crt *) polarssl_malloc( sizeof( x509_crt ) );
 
@@ -946,7 +946,7 @@
     size_t n;
     unsigned char *buf;
 
-    if ( ( ret = x509_load_file( path, &buf, &n ) ) != 0 )
+    if( ( ret = x509_load_file( path, &buf, &n ) ) != 0 )
         return( ret );
 
     ret = x509_crt_parse( chain, buf, n );
@@ -988,7 +988,7 @@
                                  MAX_PATH - 3 );
 
     hFind = FindFirstFileW( szDir, &file_data );
-    if (hFind == INVALID_HANDLE_VALUE)
+    if( hFind == INVALID_HANDLE_VALUE )
         return( POLARSSL_ERR_X509_FILE_IO_ERROR );
 
     len = MAX_PATH - len;
@@ -1000,7 +1000,7 @@
             continue;
 
         w_ret = WideCharToMultiByte( CP_ACP, 0, file_data.cFileName,
-                                     lstrlenW(file_data.cFileName),
+                                     lstrlenW( file_data.cFileName ),
                                      p, len - 1,
                                      NULL, NULL );
 
@@ -1012,7 +1012,7 @@
     }
     while( FindNextFileW( hFind, &file_data ) != 0 );
 
-    if (GetLastError() != ERROR_NO_MORE_FILES)
+    if( GetLastError() != ERROR_NO_MORE_FILES )
         ret = POLARSSL_ERR_X509_FILE_IO_ERROR;
 
     FindClose( hFind );
@@ -1023,7 +1023,7 @@
     char entry_name[255];
     DIR *dir = opendir( path );
 
-    if( dir == NULL)
+    if( dir == NULL )
         return( POLARSSL_ERR_X509_FILE_IO_ERROR );
 
 #if defined(POLARSSL_THREADING_PTHREAD)
@@ -1082,7 +1082,7 @@
  * This fuction tries to 'fix' this by at least suggesting enlarging the
  * size by 20.
  */
-static int compat_snprintf(char *str, size_t size, const char *format, ...)
+static int compat_snprintf( char *str, size_t size, const char *format, ... )
 {
     va_list ap;
     int res = -1;
@@ -1094,7 +1094,7 @@
     va_end( ap );
 
     // No quick fix possible
-    if ( res < 0 )
+    if( res < 0 )
         return( (int) size + 20 );
 
     return( res );
@@ -1110,7 +1110,7 @@
     if( ret == -1 )                                 \
         return( -1 );                               \
                                                     \
-    if ( (unsigned int) ret > n ) {                 \
+    if( (unsigned int) ret > n ) {                  \
         p[n - 1] = '\0';                            \
         return( POLARSSL_ERR_DEBUG_BUF_TOO_SMALL ); \
     }                                               \
@@ -1269,7 +1269,7 @@
                                prefix );
     SAFE_SNPRINTF();
 
-    ret = x509_serial_gets( p, n, &crt->serial);
+    ret = x509_serial_gets( p, n, &crt->serial );
     SAFE_SNPRINTF();
 
     ret = snprintf( p, n, "\n%sissuer name       : ", prefix );
@@ -1517,7 +1517,7 @@
         /*
          * Check if certificate is revoked
          */
-        if( x509_crt_revoked(crt, crl_list) )
+        if( x509_crt_revoked( crt, crl_list ) )
         {
             flags |= BADCERT_REVOKED;
             break;
@@ -1714,7 +1714,7 @@
     /* Call callback on top cert */
     if( NULL != f_vrfy )
     {
-        if( ( ret = f_vrfy(p_vrfy, child, path_cnt, flags ) ) != 0 )
+        if( ( ret = f_vrfy( p_vrfy, child, path_cnt, flags ) ) != 0 )
             return( ret );
     }
 
diff --git a/library/x509_csr.c b/library/x509_csr.c
index 75e3763..f6d268be 100644
--- a/library/x509_csr.c
+++ b/library/x509_csr.c
@@ -295,7 +295,7 @@
     size_t n;
     unsigned char *buf;
 
-    if ( ( ret = x509_load_file( path, &buf, &n ) ) != 0 )
+    if( ( ret = x509_load_file( path, &buf, &n ) ) != 0 )
         return( ret );
 
     ret = x509_csr_parse( csr, buf, n );
@@ -322,7 +322,7 @@
  * This fuction tries to 'fix' this by at least suggesting enlarging the
  * size by 20.
  */
-static int compat_snprintf(char *str, size_t size, const char *format, ...)
+static int compat_snprintf( char *str, size_t size, const char *format, ... )
 {
     va_list ap;
     int res = -1;
@@ -334,7 +334,7 @@
     va_end( ap );
 
     // No quick fix possible
-    if ( res < 0 )
+    if( res < 0 )
         return( (int) size + 20 );
 
     return( res );
@@ -350,7 +350,7 @@
     if( ret == -1 )                                 \
         return( -1 );                               \
                                                     \
-    if ( (unsigned int) ret > n ) {                 \
+    if( (unsigned int) ret > n ) {                  \
         p[n - 1] = '\0';                            \
         return( POLARSSL_ERR_DEBUG_BUF_TOO_SMALL ); \
     }                                               \
diff --git a/library/x509write_crt.c b/library/x509write_crt.c
index 4b6d75b..e298c24 100644
--- a/library/x509write_crt.c
+++ b/library/x509write_crt.c
@@ -115,8 +115,8 @@
 int x509write_crt_set_validity( x509write_cert *ctx, const char *not_before,
                                 const char *not_after )
 {
-    if( strlen(not_before) != X509_RFC5280_UTC_TIME_LEN - 1 ||
-        strlen(not_after)  != X509_RFC5280_UTC_TIME_LEN - 1 )
+    if( strlen( not_before ) != X509_RFC5280_UTC_TIME_LEN - 1 ||
+        strlen( not_after )  != X509_RFC5280_UTC_TIME_LEN - 1 )
     {
         return( POLARSSL_ERR_X509_BAD_INPUT_DATA );
     }
@@ -176,7 +176,7 @@
     unsigned char *c = buf + sizeof(buf);
     size_t len = 0;
 
-    memset( buf, 0, sizeof(buf));
+    memset( buf, 0, sizeof(buf) );
     ASN1_CHK_ADD( len, pk_write_pubkey( &c, buf, ctx->subject_key ) );
 
     sha1( buf + sizeof(buf) - len, len, buf + sizeof(buf) - 20 );
@@ -198,7 +198,7 @@
     unsigned char *c = buf + sizeof(buf);
     size_t len = 0;
 
-    memset( buf, 0, sizeof(buf));
+    memset( buf, 0, sizeof(buf) );
     ASN1_CHK_ADD( len, pk_write_pubkey( &c, buf, ctx->issuer_key ) );
 
     sha1( buf + sizeof(buf) - len, len, buf + sizeof(buf) - 20 );
diff --git a/library/xtea.c b/library/xtea.c
index 18a4d46..5ff8a04 100644
--- a/library/xtea.c
+++ b/library/xtea.c
@@ -71,7 +71,7 @@
 {
     int i;
 
-    memset(ctx, 0, sizeof(xtea_context));
+    memset( ctx, 0, sizeof(xtea_context) );
 
     for( i = 0; i < 4; i++ )
     {
@@ -142,7 +142,7 @@
             memcpy( temp, input, 8 );
             xtea_crypt_ecb( ctx, mode, input, output );
 
-            for(i = 0; i < 8; i++)
+            for( i = 0; i < 8; i++ )
                 output[i] = (unsigned char)( output[i] ^ iv[i] );
 
             memcpy( iv, temp, 8 );