Fix formatting in various code to match spacing from coding style

This commit is contained in:
Paul Bakker 2014-06-17 16:39:18 +02:00
parent db20c10423
commit 66d5d076f7
46 changed files with 293 additions and 292 deletions

View File

@ -420,10 +420,10 @@ static void aes_gen_tables( void )
{ {
x = pow[255 - log[i]]; x = pow[255 - log[i]];
y = x; 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; 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; x ^= y ^ 0x63;
FSb[i] = (unsigned char) x; FSb[i] = (unsigned char) x;
@ -504,7 +504,7 @@ int aes_setkey_enc( aes_context *ctx, const unsigned char *key,
return( aesni_setkey_enc( (unsigned char *) ctx->rk, key, keysize ) ); return( aesni_setkey_enc( (unsigned char *) ctx->rk, key, keysize ) );
#endif #endif
for( i = 0; i < (keysize >> 5); i++ ) for( i = 0; i < ( keysize >> 5 ); i++ )
{ {
GET_UINT32_LE( RK[i], key, i << 2 ); GET_UINT32_LE( RK[i], key, i << 2 );
} }
@ -726,7 +726,7 @@ int aes_crypt_ecb( aes_context *ctx,
if( mode == AES_DECRYPT ) 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( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
@ -760,7 +760,7 @@ int aes_crypt_ecb( aes_context *ctx,
} }
else /* AES_ENCRYPT */ 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( Y0, Y1, Y2, Y3, X0, X1, X2, X3 );
AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 );
@ -893,7 +893,7 @@ int aes_crypt_cfb128( aes_context *ctx,
*output++ = (unsigned char)( c ^ iv[n] ); *output++ = (unsigned char)( c ^ iv[n] );
iv[n] = (unsigned char) c; iv[n] = (unsigned char) c;
n = (n + 1) & 0x0F; n = ( n + 1 ) & 0x0F;
} }
} }
else else
@ -905,7 +905,7 @@ int aes_crypt_cfb128( aes_context *ctx,
iv[n] = *output++ = (unsigned char)( iv[n] ^ *input++ ); iv[n] = *output++ = (unsigned char)( iv[n] ^ *input++ );
n = (n + 1) & 0x0F; n = ( n + 1 ) & 0x0F;
} }
} }
@ -930,7 +930,7 @@ int aes_crypt_cfb8( aes_context *ctx,
while( length-- ) while( length-- )
{ {
memcpy(ov, iv, 16); memcpy( ov, iv, 16 );
aes_crypt_ecb( ctx, AES_ENCRYPT, iv, iv ); aes_crypt_ecb( ctx, AES_ENCRYPT, iv, iv );
if( mode == AES_DECRYPT ) if( mode == AES_DECRYPT )
@ -941,7 +941,7 @@ int aes_crypt_cfb8( aes_context *ctx,
if( mode == AES_ENCRYPT ) if( mode == AES_ENCRYPT )
ov[16] = c; ov[16] = c;
memcpy(iv, ov + 1, 16); memcpy( iv, ov + 1, 16 );
} }
return( 0 ); return( 0 );
@ -975,7 +975,7 @@ int aes_crypt_ctr( aes_context *ctx,
c = *input++; c = *input++;
*output++ = (unsigned char)( c ^ stream_block[n] ); *output++ = (unsigned char)( c ^ stream_block[n] );
n = (n + 1) & 0x0F; n = ( n + 1 ) & 0x0F;
} }
*nc_off = n; *nc_off = n;

View File

@ -1,7 +1,7 @@
/* /*
* AES-NI support functions * 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) * This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>

View File

@ -194,7 +194,7 @@ int asn1_get_bitstring( unsigned char **p, const unsigned char *end,
return( ret ); return( ret );
/* Check length, subtract one for actual bit string length */ /* Check length, subtract one for actual bit string length */
if ( bs->len < 1 ) if( bs->len < 1 )
return( POLARSSL_ERR_ASN1_OUT_OF_DATA ); return( POLARSSL_ERR_ASN1_OUT_OF_DATA );
bs->len -= 1; bs->len -= 1;
@ -265,7 +265,7 @@ int asn1_get_sequence_of( unsigned char **p,
*p += buf->len; *p += buf->len;
/* Allocate and assign next pointer */ /* Allocate and assign next pointer */
if (*p < end) if( *p < end )
{ {
cur->next = (asn1_sequence *) polarssl_malloc( cur->next = (asn1_sequence *) polarssl_malloc(
sizeof( asn1_sequence ) ); sizeof( asn1_sequence ) );

View File

@ -118,7 +118,7 @@ int asn1_write_mpi( unsigned char **p, unsigned char *start, mpi *X )
// DER format assumes 2s complement for numbers, so the leftmost bit // DER format assumes 2s complement for numbers, so the leftmost bit
// should be 0 for positive numbers and 1 for negative numbers. // 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 ) if( *p - start < 1 )
return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL ); return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL );
@ -217,7 +217,7 @@ int asn1_write_int( unsigned char **p, unsigned char *start, int val )
len += 1; len += 1;
*--(*p) = val; *--(*p) = val;
if ( val > 0 && **p & 0x80 ) if( val > 0 && **p & 0x80 )
{ {
if( *p - start < 1 ) if( *p - start < 1 )
return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL ); return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL );

View File

@ -87,9 +87,9 @@ int base64_encode( unsigned char *dst, size_t *dlen,
if( slen == 0 ) if( slen == 0 )
return( 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 2: n += 3; break;
case 4: n += 2; break; case 4: n += 2; break;
@ -102,7 +102,7 @@ int base64_encode( unsigned char *dst, size_t *dlen,
return( POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL ); return( POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL );
} }
n = (slen / 3) * 3; n = ( slen / 3 ) * 3;
for( i = 0, p = dst; i < n; i += 3 ) for( i = 0, p = dst; i < n; i += 3 )
{ {
@ -119,12 +119,12 @@ int base64_encode( unsigned char *dst, size_t *dlen,
if( i < slen ) if( i < slen )
{ {
C1 = *src++; 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 >> 2) & 0x3F];
*p++ = base64_enc_map[(((C1 & 3) << 4) + (C2 >> 4)) & 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]; *p++ = base64_enc_map[((C2 & 15) << 2) & 0x3F];
else *p++ = '='; else *p++ = '=';
@ -171,7 +171,7 @@ int base64_decode( unsigned char *dst, size_t *dlen,
if( n == 0 ) if( n == 0 )
return( 0 ); return( 0 );
n = ((n * 6) + 7) >> 3; n = ( ( n * 6 ) + 7 ) >> 3;
if( dst == NULL || *dlen < n ) if( dst == NULL || *dlen < n )
{ {
@ -185,7 +185,7 @@ int base64_decode( unsigned char *dst, size_t *dlen,
continue; continue;
j -= ( base64_dec_map[*src] == 64 ); 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 ) if( ++n == 4 )
{ {

View File

@ -229,13 +229,13 @@ int mpi_safe_cond_assign( mpi *X, const mpi *Y, unsigned char assign )
MPI_CHK( mpi_grow( X, Y->n ) ); 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++ ) 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++ ) for( ; i < X->n; i++ )
X->p[i] *= (1 - assign); X->p[i] *= ( 1 - assign );
cleanup: cleanup:
return( ret ); return( ret );
@ -263,15 +263,15 @@ int mpi_safe_cond_swap( mpi *X, mpi *Y, unsigned char swap )
MPI_CHK( mpi_grow( Y, X->n ) ); MPI_CHK( mpi_grow( Y, X->n ) );
s = X->s; s = X->s;
X->s = X->s * (1 - swap) + Y->s * swap; X->s = X->s * ( 1 - swap ) + Y->s * swap;
Y->s = Y->s * (1 - swap) + s * swap; Y->s = Y->s * ( 1 - swap ) + s * swap;
for( i = 0; i < X->n; i++ ) for( i = 0; i < X->n; i++ )
{ {
tmp = X->p[i]; tmp = X->p[i];
X->p[i] = X->p[i] * (1 - swap) + Y->p[i] * swap; X->p[i] = X->p[i] * ( 1 - swap ) + Y->p[i] * swap;
Y->p[i] = Y->p[i] * (1 - swap) + tmp * swap; Y->p[i] = Y->p[i] * ( 1 - swap ) + tmp * swap;
} }
cleanup: cleanup:
@ -426,7 +426,7 @@ int mpi_read_string( mpi *X, int radix, const char *s )
} }
MPI_CHK( mpi_get_digit( &d, radix, s[i - 1] ) ); 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 else
@ -1226,14 +1226,14 @@ int mpi_div_mpi( mpi *Q, mpi *R, const mpi *A, const mpi *B )
n = X.n - 1; n = X.n - 1;
t = Y.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 ) while( mpi_cmp_mpi( &X, &Y ) >= 0 )
{ {
Z.p[n - t]++; Z.p[n - t]++;
MPI_CHK( mpi_sub_mpi( &X, &X, &Y ) ); 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-- ) for( i = n; i > t ; i-- )
{ {
@ -1257,8 +1257,8 @@ int mpi_div_mpi( mpi *Q, mpi *R, const mpi *A, const mpi *B )
r = (t_udbl) X.p[i] << biL; r = (t_udbl) X.p[i] << biL;
r |= (t_udbl) X.p[i - 1]; r |= (t_udbl) X.p[i - 1];
r /= Y.p[t]; r /= Y.p[t];
if( r > ((t_udbl) 1 << biL) - 1) if( r > ( (t_udbl) 1 << biL ) - 1 )
r = ((t_udbl) 1 << biL) - 1; r = ( (t_udbl) 1 << biL ) - 1;
Z.p[i - t - 1] = (t_uint) r; Z.p[i - t - 1] = (t_uint) r;
#else #else
@ -1310,25 +1310,25 @@ int mpi_div_mpi( mpi *Q, mpi *R, const mpi *A, const mpi *B )
Z.p[i - t - 1]--; Z.p[i - t - 1]--;
MPI_CHK( mpi_lset( &T1, 0 ) ); 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]; T1.p[1] = Y.p[t];
MPI_CHK( mpi_mul_int( &T1, &T1, Z.p[i - t - 1] ) ); MPI_CHK( mpi_mul_int( &T1, &T1, Z.p[i - t - 1] ) );
MPI_CHK( mpi_lset( &T2, 0 ) ); MPI_CHK( mpi_lset( &T2, 0 ) );
T2.p[0] = (i < 2) ? 0 : X.p[i - 2]; T2.p[0] = ( i < 2 ) ? 0 : X.p[i - 2];
T2.p[1] = (i < 1) ? 0 : X.p[i - 1]; T2.p[1] = ( i < 1 ) ? 0 : X.p[i - 1];
T2.p[2] = X.p[i]; T2.p[2] = X.p[i];
} }
while( mpi_cmp_mpi( &T1, &T2 ) > 0 ); while( mpi_cmp_mpi( &T1, &T2 ) > 0 );
MPI_CHK( mpi_mul_int( &T1, &Y, Z.p[i - t - 1] ) ); 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 ) ); MPI_CHK( mpi_sub_mpi( &X, &X, &T1 ) );
if( mpi_cmp_int( &X, 0 ) < 0 ) if( mpi_cmp_int( &X, 0 ) < 0 )
{ {
MPI_CHK( mpi_copy( &T1, &Y ) ); 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 ) ); MPI_CHK( mpi_add_mpi( &X, &X, &T1 ) );
Z.p[i - t - 1]--; Z.p[i - t - 1]--;
} }
@ -1500,7 +1500,7 @@ static void mpi_montmul( mpi *A, const mpi *B, const mpi *N, t_uint mm,
*d++ = u0; d[n + 1] = 0; *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 ) if( mpi_cmp_abs( A, N ) >= 0 )
mpi_sub_hlp( n, N->p, A->p ); mpi_sub_hlp( n, N->p, A->p );
@ -1610,7 +1610,7 @@ int mpi_exp_mod( mpi *X, const mpi *A, const mpi *E, const mpi *N, mpi *_RR )
/* /*
* W[1 << (wsize - 1)] = W[1] ^ (wsize - 1) * 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_grow( &W[j], N->n + 1 ) );
MPI_CHK( mpi_copy( &W[j], &W[1] ) ); MPI_CHK( mpi_copy( &W[j], &W[1] ) );
@ -1621,7 +1621,7 @@ int mpi_exp_mod( mpi *X, const mpi *A, const mpi *E, const mpi *N, mpi *_RR )
/* /*
* W[i] = W[i - 1] * W[1] * 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_grow( &W[i], N->n + 1 ) );
MPI_CHK( mpi_copy( &W[i], &W[i - 1] ) ); MPI_CHK( mpi_copy( &W[i], &W[i - 1] ) );
@ -1673,7 +1673,7 @@ int mpi_exp_mod( mpi *X, const mpi *A, const mpi *E, const mpi *N, mpi *_RR )
state = 2; state = 2;
nbits++; nbits++;
wbits |= (ei << (wsize - nbits)); wbits |= ( ei << ( wsize - nbits ) );
if( nbits == wsize ) if( nbits == wsize )
{ {
@ -1703,7 +1703,7 @@ int mpi_exp_mod( mpi *X, const mpi *A, const mpi *E, const mpi *N, mpi *_RR )
wbits <<= 1; wbits <<= 1;
if( (wbits & (one << wsize)) != 0 ) if( ( wbits & ( one << wsize ) ) != 0 )
mpi_montmul( X, &W[1], N, mm, &T ); mpi_montmul( X, &W[1], N, mm, &T );
} }
@ -1720,7 +1720,7 @@ int mpi_exp_mod( mpi *X, const mpi *A, const mpi *E, const mpi *N, mpi *_RR )
cleanup: 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[i] );
mpi_free( &W[1] ); mpi_free( &T ); mpi_free( &Apos ); mpi_free( &W[1] ); mpi_free( &T ); mpi_free( &Apos );
@ -1748,7 +1748,7 @@ int mpi_gcd( mpi *G, const mpi *A, const mpi *B )
lz = mpi_lsb( &TA ); lz = mpi_lsb( &TA );
lzt = mpi_lsb( &TB ); lzt = mpi_lsb( &TB );
if ( lzt < lz ) if( lzt < lz )
lz = lzt; lz = lzt;
MPI_CHK( mpi_shift_r( &TA, lz ) ); MPI_CHK( mpi_shift_r( &TA, lz ) );
@ -2305,7 +2305,7 @@ int mpi_self_test( int verbose )
if( verbose != 0 ) if( verbose != 0 )
polarssl_printf( " MPI test #5 (simple gcd): " ); 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( &X, gcd_pairs[i][0] ) );
MPI_CHK( mpi_lset( &Y, gcd_pairs[i][1] ) ); MPI_CHK( mpi_lset( &Y, gcd_pairs[i][1] ) );

View File

@ -75,7 +75,7 @@ static const uint32_t P[BLOWFISH_ROUNDS + 2] = {
/* declarations of data at the end of this file */ /* declarations of data at the end of this file */
static const uint32_t S[4][256]; 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; unsigned short a, b, c, d;
uint32_t y; uint32_t y;
@ -94,7 +94,7 @@ static uint32_t F(blowfish_context *ctx, uint32_t x)
return( y ); 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; uint32_t Xl, Xr, temp;
short i; short i;
@ -102,10 +102,10 @@ static void blowfish_enc(blowfish_context *ctx, uint32_t *xl, uint32_t *xr)
Xl = *xl; Xl = *xl;
Xr = *xr; Xr = *xr;
for (i = 0; i < BLOWFISH_ROUNDS; ++i) for( i = 0; i < BLOWFISH_ROUNDS; ++i )
{ {
Xl = Xl ^ ctx->P[i]; Xl = Xl ^ ctx->P[i];
Xr = F(ctx, Xl) ^ Xr; Xr = F( ctx, Xl ) ^ Xr;
temp = Xl; temp = Xl;
Xl = Xr; Xl = Xr;
@ -123,7 +123,7 @@ static void blowfish_enc(blowfish_context *ctx, uint32_t *xl, uint32_t *xr)
*xr = Xr; *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; uint32_t Xl, Xr, temp;
short i; short i;
@ -131,10 +131,10 @@ static void blowfish_dec(blowfish_context *ctx, uint32_t *xl, uint32_t *xr)
Xl = *xl; Xl = *xl;
Xr = *xr; Xr = *xr;
for (i = BLOWFISH_ROUNDS + 1; i > 1; --i) for( i = BLOWFISH_ROUNDS + 1; i > 1; --i )
{ {
Xl = Xl ^ ctx->P[i]; Xl = Xl ^ ctx->P[i];
Xr = F(ctx, Xl) ^ Xr; Xr = F( ctx, Xl ) ^ Xr;
temp = Xl; temp = Xl;
Xl = Xr; Xl = Xr;
@ -225,11 +225,11 @@ int blowfish_crypt_ecb( blowfish_context *ctx,
if( mode == BLOWFISH_DECRYPT ) if( mode == BLOWFISH_DECRYPT )
{ {
blowfish_dec(ctx, &X0, &X1); blowfish_dec( ctx, &X0, &X1 );
} }
else /* BLOWFISH_ENCRYPT */ else /* BLOWFISH_ENCRYPT */
{ {
blowfish_enc(ctx, &X0, &X1); blowfish_enc( ctx, &X0, &X1 );
} }
PUT_UINT32_BE( X0, output, 0 ); PUT_UINT32_BE( X0, output, 0 );
@ -318,7 +318,7 @@ int blowfish_crypt_cfb64( blowfish_context *ctx,
*output++ = (unsigned char)( c ^ iv[n] ); *output++ = (unsigned char)( c ^ iv[n] );
iv[n] = (unsigned char) c; iv[n] = (unsigned char) c;
n = (n + 1) % BLOWFISH_BLOCKSIZE; n = ( n + 1 ) % BLOWFISH_BLOCKSIZE;
} }
} }
else else
@ -330,7 +330,7 @@ int blowfish_crypt_cfb64( blowfish_context *ctx,
iv[n] = *output++ = (unsigned char)( iv[n] ^ *input++ ); iv[n] = *output++ = (unsigned char)( iv[n] ^ *input++ );
n = (n + 1) % BLOWFISH_BLOCKSIZE; n = ( n + 1 ) % BLOWFISH_BLOCKSIZE;
} }
} }
@ -368,7 +368,7 @@ int blowfish_crypt_ctr( blowfish_context *ctx,
c = *input++; c = *input++;
*output++ = (unsigned char)( c ^ stream_block[n] ); *output++ = (unsigned char)( c ^ stream_block[n] );
n = (n + 1) % BLOWFISH_BLOCKSIZE; n = ( n + 1 ) % BLOWFISH_BLOCKSIZE;
} }
*nc_off = n; *nc_off = n;

View File

@ -287,14 +287,14 @@ static const signed char transposes[2][20] =
TK[2] = KC[(OFFSET) * 4 + 2]; \ TK[2] = KC[(OFFSET) * 4 + 2]; \
TK[3] = KC[(OFFSET) * 4 + 3]; \ TK[3] = KC[(OFFSET) * 4 + 3]; \
\ \
for ( i = 1; i <= 4; i++ ) \ for( i = 1; i <= 4; i++ ) \
if (shifts[(INDEX)][(OFFSET)][i -1]) \ if( shifts[(INDEX)][(OFFSET)][i -1] ) \
ROTL(TK + i * 4, TK, (15 * i) % 32); \ ROTL(TK + i * 4, TK, ( 15 * i ) % 32); \
\ \
for ( i = 0; i < 20; i++ ) \ for( i = 0; i < 20; i++ ) \
if (indexes[(INDEX)][(OFFSET)][i] != -1) { \ if( indexes[(INDEX)][(OFFSET)][i] != -1 ) { \
RK[indexes[(INDEX)][(OFFSET)][i]] = TK[ i ]; \ RK[indexes[(INDEX)][(OFFSET)][i]] = TK[ i ]; \
} \ } \
} }
static void camellia_feistel( const uint32_t x[2], const uint32_t k[2], static void camellia_feistel( const uint32_t x[2], const uint32_t k[2],
@ -338,8 +338,8 @@ int camellia_setkey_enc( camellia_context *ctx, const unsigned char *key,
RK = ctx->rk; RK = ctx->rk;
memset(t, 0, 64); memset( t, 0, 64 );
memset(RK, 0, sizeof(ctx->rk)); memset( RK, 0, sizeof(ctx->rk) );
switch( keysize ) switch( keysize )
{ {
@ -349,52 +349,52 @@ int camellia_setkey_enc( camellia_context *ctx, const unsigned char *key,
default : return( POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH ); 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]; t[i] = key[i];
if (keysize == 192) { if( keysize == 192 ) {
for (i = 0; i < 8; i++) for( i = 0; i < 8; i++ )
t[24 + i] = ~t[16 + i]; t[24 + i] = ~t[16 + i];
} }
/* /*
* Prepare SIGMA values * Prepare SIGMA values
*/ */
for (i = 0; i < 6; i++) { for( i = 0; i < 6; i++ ) {
GET_UINT32_BE(SIGMA[i][0], SIGMA_CHARS[i], 0); GET_UINT32_BE( SIGMA[i][0], SIGMA_CHARS[i], 0 );
GET_UINT32_BE(SIGMA[i][1], SIGMA_CHARS[i], 4); GET_UINT32_BE( SIGMA[i][1], SIGMA_CHARS[i], 4 );
} }
/* /*
* Key storage in KC * Key storage in KC
* Order: KL, KR, KA, KB * Order: KL, KR, KA, KB
*/ */
memset(KC, 0, sizeof(KC)); memset( KC, 0, sizeof(KC) );
/* Store KL, KR */ /* Store KL, KR */
for (i = 0; i < 8; i++) for( i = 0; i < 8; i++ )
GET_UINT32_BE(KC[i], t, i * 4); GET_UINT32_BE( KC[i], t, i * 4 );
/* Generate KA */ /* Generate KA */
for( i = 0; i < 4; ++i) for( i = 0; i < 4; ++i )
KC[8 + i] = KC[i] ^ KC[4 + i]; KC[8 + i] = KC[i] ^ KC[4 + i];
camellia_feistel(KC + 8, SIGMA[0], KC + 10); camellia_feistel( KC + 8, SIGMA[0], KC + 10 );
camellia_feistel(KC + 10, SIGMA[1], KC + 8); 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]; KC[8 + i] ^= KC[i];
camellia_feistel(KC + 8, SIGMA[2], KC + 10); camellia_feistel( KC + 8, SIGMA[2], KC + 10 );
camellia_feistel(KC + 10, SIGMA[3], KC + 8); camellia_feistel( KC + 10, SIGMA[3], KC + 8 );
if (keysize > 128) { if( keysize > 128 ) {
/* Generate KB */ /* Generate KB */
for( i = 0; i < 4; ++i) for( i = 0; i < 4; ++i )
KC[12 + i] = KC[4 + i] ^ KC[8 + i]; KC[12 + i] = KC[4 + i] ^ KC[8 + i];
camellia_feistel(KC + 12, SIGMA[4], KC + 14); camellia_feistel( KC + 12, SIGMA[4], KC + 14 );
camellia_feistel(KC + 14, SIGMA[5], KC + 12); camellia_feistel( KC + 14, SIGMA[5], KC + 12 );
} }
/* /*
@ -402,24 +402,24 @@ int camellia_setkey_enc( camellia_context *ctx, const unsigned char *key,
*/ */
/* Manipulating KL */ /* Manipulating KL */
SHIFT_AND_PLACE(idx, 0); SHIFT_AND_PLACE( idx, 0 );
/* Manipulating KR */ /* Manipulating KR */
if (keysize > 128) { if( keysize > 128 ) {
SHIFT_AND_PLACE(idx, 1); SHIFT_AND_PLACE( idx, 1 );
} }
/* Manipulating KA */ /* Manipulating KA */
SHIFT_AND_PLACE(idx, 2); SHIFT_AND_PLACE( idx, 2 );
/* Manipulating KB */ /* Manipulating KB */
if (keysize > 128) { if( keysize > 128 ) {
SHIFT_AND_PLACE(idx, 3); SHIFT_AND_PLACE( idx, 3 );
} }
/* Do transpositions */ /* Do transpositions */
for ( i = 0; i < 20; i++ ) { for( i = 0; i < 20; i++ ) {
if (transposes[idx][i] != -1) { if( transposes[idx][i] != -1 ) {
RK[32 + 12 * idx + i] = RK[transposes[idx][i]]; RK[32 + 12 * idx + i] = RK[transposes[idx][i]];
} }
} }
@ -441,7 +441,7 @@ int camellia_setkey_dec( camellia_context *ctx, const unsigned char *key,
int ret; int ret;
/* Also checks keysize */ /* Also checks keysize */
if( ( ret = camellia_setkey_enc(&cty, key, keysize) ) ) if( ( ret = camellia_setkey_enc( &cty, key, keysize ) ) )
return( ret ); return( ret );
ctx->nr = cty.nr; ctx->nr = cty.nr;
@ -455,7 +455,7 @@ int camellia_setkey_dec( camellia_context *ctx, const unsigned char *key,
*RK++ = *SK++; *RK++ = *SK++;
*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++;
*RK++ = *SK++; *RK++ = *SK++;
@ -499,22 +499,22 @@ int camellia_crypt_ecb( camellia_context *ctx,
X[2] ^= *RK++; X[2] ^= *RK++;
X[3] ^= *RK++; X[3] ^= *RK++;
while (NR) { while( NR ) {
--NR; --NR;
camellia_feistel(X, RK, X + 2); camellia_feistel( X, RK, X + 2 );
RK += 2; RK += 2;
camellia_feistel(X + 2, RK, X); camellia_feistel( X + 2, RK, X );
RK += 2; RK += 2;
camellia_feistel(X, RK, X + 2); camellia_feistel( X, RK, X + 2 );
RK += 2; RK += 2;
camellia_feistel(X + 2, RK, X); camellia_feistel( X + 2, RK, X );
RK += 2; RK += 2;
camellia_feistel(X, RK, X + 2); camellia_feistel( X, RK, X + 2 );
RK += 2; RK += 2;
camellia_feistel(X + 2, RK, X); camellia_feistel( X + 2, RK, X );
RK += 2; RK += 2;
if (NR) { if( NR ) {
FL(X[0], X[1], RK[0], RK[1]); FL(X[0], X[1], RK[0], RK[1]);
RK += 2; RK += 2;
FLInv(X[2], X[3], RK[0], RK[1]); FLInv(X[2], X[3], RK[0], RK[1]);
@ -615,7 +615,7 @@ int camellia_crypt_cfb128( camellia_context *ctx,
*output++ = (unsigned char)( c ^ iv[n] ); *output++ = (unsigned char)( c ^ iv[n] );
iv[n] = (unsigned char) c; iv[n] = (unsigned char) c;
n = (n + 1) & 0x0F; n = ( n + 1 ) & 0x0F;
} }
} }
else else
@ -627,7 +627,7 @@ int camellia_crypt_cfb128( camellia_context *ctx,
iv[n] = *output++ = (unsigned char)( iv[n] ^ *input++ ); iv[n] = *output++ = (unsigned char)( iv[n] ^ *input++ );
n = (n + 1) & 0x0F; n = ( n + 1 ) & 0x0F;
} }
} }
@ -665,7 +665,7 @@ int camellia_crypt_ctr( camellia_context *ctx,
c = *input++; c = *input++;
*output++ = (unsigned char)( c ^ stream_block[n] ); *output++ = (unsigned char)( c ^ stream_block[n] );
n = (n + 1) & 0x0F; n = ( n + 1 ) & 0x0F;
} }
*nc_off = n; *nc_off = n;
@ -897,7 +897,7 @@ int camellia_self_test( int verbose )
memset( key, 0, 32 ); memset( key, 0, 32 );
for (j = 0; j < 6; j++) { for( j = 0; j < 6; j++ ) {
u = j >> 1; u = j >> 1;
v = j & 1; v = j & 1;
@ -905,20 +905,20 @@ int camellia_self_test( int verbose )
polarssl_printf( " CAMELLIA-ECB-%3d (%s): ", 128 + u * 64, polarssl_printf( " CAMELLIA-ECB-%3d (%s): ", 128 + u * 64,
(v == CAMELLIA_DECRYPT) ? "dec" : "enc"); (v == CAMELLIA_DECRYPT) ? "dec" : "enc");
for (i = 0; i < CAMELLIA_TESTS_ECB; i++ ) { for( i = 0; i < CAMELLIA_TESTS_ECB; i++ ) {
memcpy( key, camellia_test_ecb_key[u][i], 16 + 8 * u); memcpy( key, camellia_test_ecb_key[u][i], 16 + 8 * u );
if (v == CAMELLIA_DECRYPT) { if( v == CAMELLIA_DECRYPT ) {
camellia_setkey_dec(&ctx, key, 128 + u * 64); camellia_setkey_dec( &ctx, key, 128 + u * 64 );
memcpy(src, camellia_test_ecb_cipher[u][i], 16); memcpy( src, camellia_test_ecb_cipher[u][i], 16 );
memcpy(dst, camellia_test_ecb_plain[i], 16); memcpy( dst, camellia_test_ecb_plain[i], 16 );
} else { /* CAMELLIA_ENCRYPT */ } else { /* CAMELLIA_ENCRYPT */
camellia_setkey_enc(&ctx, key, 128 + u * 64); camellia_setkey_enc( &ctx, key, 128 + u * 64 );
memcpy(src, camellia_test_ecb_plain[i], 16); memcpy( src, camellia_test_ecb_plain[i], 16 );
memcpy(dst, camellia_test_ecb_cipher[u][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 ) if( memcmp( buf, dst, 16 ) != 0 )
{ {
@ -949,29 +949,29 @@ int camellia_self_test( int verbose )
polarssl_printf( " CAMELLIA-CBC-%3d (%s): ", 128 + u * 64, polarssl_printf( " CAMELLIA-CBC-%3d (%s): ", 128 + u * 64,
( v == CAMELLIA_DECRYPT ) ? "dec" : "enc" ); ( v == CAMELLIA_DECRYPT ) ? "dec" : "enc" );
memcpy( src, camellia_test_cbc_iv, 16); memcpy( src, camellia_test_cbc_iv, 16 );
memcpy( dst, camellia_test_cbc_iv, 16); memcpy( dst, camellia_test_cbc_iv, 16 );
memcpy( key, camellia_test_cbc_key[u], 16 + 8 * u); memcpy( key, camellia_test_cbc_key[u], 16 + 8 * u );
if (v == CAMELLIA_DECRYPT) { if( v == CAMELLIA_DECRYPT ) {
camellia_setkey_dec(&ctx, key, 128 + u * 64); camellia_setkey_dec( &ctx, key, 128 + u * 64 );
} else { } 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( iv , src, 16 );
memcpy(src, camellia_test_cbc_cipher[u][i], 16); memcpy( src, camellia_test_cbc_cipher[u][i], 16 );
memcpy(dst, camellia_test_cbc_plain[i], 16); memcpy( dst, camellia_test_cbc_plain[i], 16 );
} else { /* CAMELLIA_ENCRYPT */ } else { /* CAMELLIA_ENCRYPT */
memcpy( iv , dst, 16 ); memcpy( iv , dst, 16 );
memcpy(src, camellia_test_cbc_plain[i], 16); memcpy( src, camellia_test_cbc_plain[i], 16 );
memcpy(dst, camellia_test_cbc_cipher[u][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 ) if( memcmp( buf, dst, 16 ) != 0 )
{ {

View File

@ -345,7 +345,7 @@ int cipher_update( cipher_context_t *ctx, const unsigned char *input,
{ {
copy_len = ilen % cipher_get_block_size( ctx ); copy_len = ilen % cipher_get_block_size( ctx );
if( copy_len == 0 && ctx->operation == POLARSSL_DECRYPT ) 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] ), memcpy( ctx->unprocessed_data, &( input[ilen - copy_len] ),
copy_len ); copy_len );
@ -459,7 +459,7 @@ static int get_pkcs_padding( unsigned char *input, size_t input_len,
for( i = 0; i < input_len; i++ ) for( i = 0; i < input_len; i++ )
bad |= ( input[i] ^ padding_len ) * ( i >= pad_idx ); 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 */ #endif /* POLARSSL_CIPHER_PADDING_PKCS7 */
@ -497,7 +497,7 @@ static int get_one_and_zeros_padding( unsigned char *input, size_t input_len,
bad &= ( input[i-1] ^ 0x80 ) | ( done == prev_done ); 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 */ #endif /* POLARSSL_CIPHER_PADDING_ONE_AND_ZEROS */
@ -538,7 +538,7 @@ static int get_zeros_and_len_padding( unsigned char *input, size_t input_len,
for( i = 0; i < input_len - 1; i++ ) for( i = 0; i < input_len - 1; i++ )
bad |= input[i] * ( i >= pad_idx ); 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 */ #endif /* POLARSSL_CIPHER_PADDING_ZEROS_AND_LEN */
@ -637,7 +637,7 @@ int cipher_finish( cipher_context_t *ctx,
ctx->add_padding( ctx->unprocessed_data, cipher_get_iv_size( ctx ), ctx->add_padding( ctx->unprocessed_data, cipher_get_iv_size( ctx ),
ctx->unprocessed_len ); 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, * For decrypt operations, expect a full block,

View File

@ -1237,7 +1237,7 @@ static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
unsigned int key_length ) unsigned int key_length )
{ {
/* we get key_length in bits, arc4 expects it in bytes */ /* 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 ); return( POLARSSL_ERR_CIPHER_BAD_INPUT_DATA );
arc4_setup( (arc4_context *) ctx, key, key_length / 8 ); arc4_setup( (arc4_context *) ctx, key, key_length / 8 );

View File

@ -336,7 +336,7 @@ int ctr_drbg_random_with_add( void *p_rng,
*/ */
aes_crypt_ecb( &ctx->aes_ctx, AES_ENCRYPT, ctx->counter, tmp ); 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; output_len;
/* /*
* Copy random block to destination * Copy random block to destination

View File

@ -1,7 +1,7 @@
/* /*
* Debugging routines * 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) * This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@ -229,7 +229,7 @@ void debug_print_mpi( const ssl_context *ssl, int level,
for( k = sizeof( t_uint ) - 1; k >= 0; k-- ) 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; continue;
else else
zeros = 0; zeros = 0;
@ -248,7 +248,7 @@ void debug_print_mpi( const ssl_context *ssl, int level,
} }
idx += snprintf( str + idx, maxlen - idx, " %02x", (unsigned int) idx += snprintf( str + idx, maxlen - idx, " %02x", (unsigned int)
( X->p[i - 1] >> (k << 3) ) & 0xFF ); ( X->p[i - 1] >> ( k << 3 ) ) & 0xFF );
j++; j++;
} }

View File

@ -332,7 +332,7 @@ int des_key_check_key_parity( const unsigned char key[DES_KEY_SIZE] )
int i; int i;
for( i = 0; i < DES_KEY_SIZE; 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( 1 );
return( 0 ); return( 0 );
@ -387,7 +387,7 @@ int des_key_check_weak( const unsigned char key[DES_KEY_SIZE] )
int i; int i;
for( i = 0; i < WEAK_KEY_COUNT; 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( 1 );
return( 0 ); return( 0 );

View File

@ -535,7 +535,7 @@ int dhm_parse_dhmfile( dhm_context *dhm, const char *path )
size_t n; size_t n;
unsigned char *buf; unsigned char *buf;
if ( ( ret = load_file( path, &buf, &n ) ) != 0 ) if( ( ret = load_file( path, &buf, &n ) ) != 0 )
return( ret ); return( ret );
ret = dhm_parse_dhm( dhm, buf, n ); ret = dhm_parse_dhm( dhm, buf, n );

View File

@ -101,13 +101,13 @@ void ecdh_free( ecdh_context *ctx )
return; return;
ecp_group_free( &ctx->grp ); ecp_group_free( &ctx->grp );
mpi_free ( &ctx->d );
ecp_point_free( &ctx->Q ); ecp_point_free( &ctx->Q );
ecp_point_free( &ctx->Qp ); ecp_point_free( &ctx->Qp );
mpi_free ( &ctx->z );
ecp_point_free( &ctx->Vi ); ecp_point_free( &ctx->Vi );
ecp_point_free( &ctx->Vf ); ecp_point_free( &ctx->Vf );
mpi_free ( &ctx->_d ); mpi_free( &ctx->d );
mpi_free( &ctx->z );
mpi_free( &ctx->_d );
} }
/* /*

View File

@ -80,7 +80,7 @@ static int derive_mpi( const ecp_group *grp, mpi *x,
const unsigned char *buf, size_t blen ) const unsigned char *buf, size_t blen )
{ {
int ret; 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; size_t use_size = blen > n_size ? n_size : blen;
MPI_CHK( mpi_read_binary( x, buf, use_size ) ); MPI_CHK( mpi_read_binary( x, buf, use_size ) );
@ -147,7 +147,7 @@ int ecdsa_sign( ecp_group *grp, mpi *r, mpi *s,
blind_tries = 0; blind_tries = 0;
do 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_fill_random( &t, n_size, f_rng, p_rng ) );
MPI_CHK( mpi_shift_r( &t, 8 * n_size - grp->nbits ) ); MPI_CHK( mpi_shift_r( &t, 8 * n_size - grp->nbits ) );

View File

@ -302,7 +302,7 @@ void ecp_group_init( ecp_group *grp )
*/ */
void ecp_keypair_init( ecp_keypair *key ) void ecp_keypair_init( ecp_keypair *key )
{ {
if ( key == NULL ) if( key == NULL )
return; return;
ecp_group_init( &key->grp ); ecp_group_init( &key->grp );
@ -357,7 +357,7 @@ void ecp_group_free( ecp_group *grp )
*/ */
void ecp_keypair_free( ecp_keypair *key ) void ecp_keypair_free( ecp_keypair *key )
{ {
if ( key == NULL ) if( key == NULL )
return; return;
ecp_group_free( &key->grp ); ecp_group_free( &key->grp );
@ -1123,7 +1123,7 @@ static int ecp_randomize_jac( const ecp_group *grp, ecp_point *pt,
{ {
int ret; int ret;
mpi l, ll; mpi l, ll;
size_t p_size = (grp->pbits + 7) / 8; size_t p_size = ( grp->pbits + 7 ) / 8;
int count = 0; int count = 0;
mpi_init( &l ); mpi_init( &ll ); mpi_init( &l ); mpi_init( &ll );
@ -1247,7 +1247,7 @@ static int ecp_precompute_comb( const ecp_group *grp,
MPI_CHK( ecp_copy( &T[0], P ) ); MPI_CHK( ecp_copy( &T[0], P ) );
k = 0; k = 0;
for( i = 1; i < ( 1U << (w-1) ); i <<= 1 ) for( i = 1; i < ( 1U << ( w - 1 ) ); i <<= 1 )
{ {
cur = T + i; cur = T + i;
MPI_CHK( ecp_copy( cur, T + ( i >> 1 ) ) ); MPI_CHK( ecp_copy( cur, T + ( i >> 1 ) ) );
@ -1264,7 +1264,7 @@ static int ecp_precompute_comb( const ecp_group *grp,
* Be careful to update T[2^l] only after using it! * Be careful to update T[2^l] only after using it!
*/ */
k = 0; k = 0;
for( i = 1; i < ( 1U << (w-1) ); i <<= 1 ) for( i = 1; i < ( 1U << ( w - 1 ) ); i <<= 1 )
{ {
j = i; j = i;
while( j-- ) while( j-- )
@ -1508,7 +1508,7 @@ static int ecp_randomize_mxz( const ecp_group *grp, ecp_point *P,
{ {
int ret; int ret;
mpi l; mpi l;
size_t p_size = (grp->pbits + 7) / 8; size_t p_size = ( grp->pbits + 7 ) / 8;
int count = 0; int count = 0;
mpi_init( &l ); mpi_init( &l );
@ -1805,7 +1805,7 @@ int ecp_gen_keypair( ecp_group *grp, mpi *d, ecp_point *Q,
void *p_rng ) void *p_rng )
{ {
int ret; int ret;
size_t n_size = (grp->nbits + 7) / 8; size_t n_size = ( grp->nbits + 7 ) / 8;
#if defined(POLARSSL_ECP_MONTGOMERY) #if defined(POLARSSL_ECP_MONTGOMERY)
if( ecp_get_type( grp ) == POLARSSL_ECP_TYPE_MONTGOMERY ) if( ecp_get_type( grp ) == POLARSSL_ECP_TYPE_MONTGOMERY )

View File

@ -1288,12 +1288,12 @@ static inline int ecp_mod_koblitz( mpi *N, t_uint *Rp, size_t p_limbs,
M.n = p_limbs + adjust; M.n = p_limbs + adjust;
memset( Mp, 0, sizeof Mp ); memset( Mp, 0, sizeof Mp );
memcpy( Mp, N->p + p_limbs - adjust, M.n * sizeof( t_uint ) ); 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 ) ); MPI_CHK( mpi_shift_r( &M, shift ) );
M.n += R.n - adjust; /* Make room for multiplication by R */ M.n += R.n - adjust; /* Make room for multiplication by R */
/* N = A0 */ /* N = A0 */
if (mask != 0 ) if( mask != 0 )
N->p[p_limbs - 1] &= mask; N->p[p_limbs - 1] &= mask;
for( i = p_limbs; i < N->n; i++ ) for( i = p_limbs; i < N->n; i++ )
N->p[i] = 0; N->p[i] = 0;
@ -1310,12 +1310,12 @@ static inline int ecp_mod_koblitz( mpi *N, t_uint *Rp, size_t p_limbs,
M.n = p_limbs + adjust; M.n = p_limbs + adjust;
memset( Mp, 0, sizeof Mp ); memset( Mp, 0, sizeof Mp );
memcpy( Mp, N->p + p_limbs - adjust, M.n * sizeof( t_uint ) ); 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 ) ); MPI_CHK( mpi_shift_r( &M, shift ) );
M.n += R.n - adjust; /* Make room for multiplication by R */ M.n += R.n - adjust; /* Make room for multiplication by R */
/* N = A0 */ /* N = A0 */
if (mask != 0 ) if( mask != 0 )
N->p[p_limbs - 1] &= mask; N->p[p_limbs - 1] &= mask;
for( i = p_limbs; i < N->n; i++ ) for( i = p_limbs; i < N->n; i++ )
N->p[i] = 0; N->p[i] = 0;

View File

@ -196,7 +196,7 @@ static int entropy_gather_internal( entropy_context *ctx )
for( i = 0; i < ctx->source_count; i++ ) for( i = 0; i < ctx->source_count; i++ )
{ {
olen = 0; 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 ) buf, ENTROPY_MAX_GATHER, &olen ) ) != 0 )
{ {
return( ret ); return( ret );

View File

@ -134,7 +134,7 @@ static int gcm_gen_table( gcm_context *ctx )
ctx->HH[i] = vh; 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; uint64_t *HiL = ctx->HL + i, *HiH = ctx->HH + i;
vh = *HiH; vh = *HiH;

View File

@ -149,7 +149,7 @@
*C = (*C >> (15)) ^ (*C << (17)) ^ CLK; \ *C = (*C >> (15)) ^ (*C << (17)) ^ CLK; \
*D = (*D >> (16)) ^ (*D << (16)) ^ CLK; \ *D = (*D >> (16)) ^ (*D << (16)) ^ CLK; \
\ \
PT1 = ( RES[(i - 8) ^ PTX] ^ \ PT1 = ( RES[( i - 8 ) ^ PTX] ^ \
WALK[PT1 ^ PTX ^ 7] ) & (~1); \ WALK[PT1 ^ PTX ^ 7] ) & (~1); \
PT1 ^= (PT2 ^ 0x10) & 0x10; \ PT1 ^= (PT2 ^ 0x10) & 0x10; \
\ \

View File

@ -234,7 +234,7 @@ int md_finish( md_context_t *ctx, unsigned char *output )
int md( const md_info_t *md_info, const unsigned char *input, size_t ilen, int md( const md_info_t *md_info, const unsigned char *input, size_t ilen,
unsigned char *output ) unsigned char *output )
{ {
if ( md_info == NULL ) if( md_info == NULL )
return( POLARSSL_ERR_MD_BAD_INPUT_DATA ); return( POLARSSL_ERR_MD_BAD_INPUT_DATA );
md_info->digest_func( input, ilen, output ); md_info->digest_func( input, ilen, output );
@ -270,7 +270,7 @@ int md_hmac_starts( md_context_t *ctx, const unsigned char *key, size_t keylen )
if( ctx == NULL || ctx->md_info == NULL ) if( ctx == NULL || ctx->md_info == NULL )
return( POLARSSL_ERR_MD_BAD_INPUT_DATA ); 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 ); return( 0 );
} }
@ -285,12 +285,12 @@ int md_hmac_update( md_context_t *ctx, const unsigned char *input, size_t ilen )
return( 0 ); 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 ) if( ctx == NULL || ctx->md_info == NULL )
return( POLARSSL_ERR_MD_BAD_INPUT_DATA ); 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 ); return( 0 );
} }
@ -300,7 +300,7 @@ int md_hmac_reset( md_context_t *ctx )
if( ctx == NULL || ctx->md_info == NULL ) if( ctx == NULL || ctx->md_info == NULL )
return( POLARSSL_ERR_MD_BAD_INPUT_DATA ); 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 ); return( 0 );
} }

View File

@ -306,7 +306,7 @@ static void *buffer_alloc_malloc( size_t len )
#if defined(POLARSSL_MEMORY_DEBUG) #if defined(POLARSSL_MEMORY_DEBUG)
heap.total_used += cur->size; 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; heap.maximum_used = heap.total_used;
#endif #endif
#if defined(POLARSSL_MEMORY_BACKTRACE) #if defined(POLARSSL_MEMORY_BACKTRACE)
@ -361,7 +361,7 @@ static void *buffer_alloc_malloc( size_t len )
if( heap.header_count > heap.maximum_header_count ) if( heap.header_count > heap.maximum_header_count )
heap.maximum_header_count = heap.header_count; heap.maximum_header_count = heap.header_count;
heap.total_used += cur->size; 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; heap.maximum_used = heap.total_used;
#endif #endif
#if defined(POLARSSL_MEMORY_BACKTRACE) #if defined(POLARSSL_MEMORY_BACKTRACE)

View File

@ -130,8 +130,8 @@ typedef UINT32 uint32_t;
(((unsigned long )(n) & 0xFF000000) >> 24)) (((unsigned long )(n) & 0xFF000000) >> 24))
#endif #endif
unsigned short net_htons(unsigned short n); unsigned short net_htons( unsigned short n );
unsigned long net_htonl(unsigned long n); unsigned long net_htonl( unsigned long n );
#define net_htons(n) POLARSSL_HTONS(n) #define net_htons(n) POLARSSL_HTONS(n)
#define net_htonl(n) POLARSSL_HTONL(n) #define net_htonl(n) POLARSSL_HTONL(n)

View File

@ -76,7 +76,7 @@ static const TYPE_T * oid_ ## NAME ## _from_asn1( const asn1_buf *oid ) \
int FN_NAME( const asn1_buf *oid, ATTR1_TYPE * ATTR1 ) \ int FN_NAME( const asn1_buf *oid, ATTR1_TYPE * ATTR1 ) \
{ \ { \
const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1( oid ); \ 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; \ *ATTR1 = data->descriptor.ATTR1; \
return( 0 ); \ return( 0 ); \
} }
@ -89,7 +89,7 @@ int FN_NAME( const asn1_buf *oid, ATTR1_TYPE * ATTR1 ) \
int FN_NAME( const asn1_buf *oid, ATTR1_TYPE * ATTR1 ) \ int FN_NAME( const asn1_buf *oid, ATTR1_TYPE * ATTR1 ) \
{ \ { \
const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1( oid ); \ 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; \ *ATTR1 = data->ATTR1; \
return( 0 ); \ return( 0 ); \
} }
@ -103,7 +103,7 @@ int FN_NAME( const asn1_buf *oid, ATTR1_TYPE * ATTR1 ) \
int FN_NAME( const asn1_buf *oid, ATTR1_TYPE * ATTR1, ATTR2_TYPE * ATTR2 ) \ int FN_NAME( const asn1_buf *oid, ATTR1_TYPE * ATTR1, ATTR2_TYPE * ATTR2 ) \
{ \ { \
const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1( oid ); \ 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; \ *ATTR1 = data->ATTR1; \
*ATTR2 = data->ATTR2; \ *ATTR2 = data->ATTR2; \
return( 0 ); \ return( 0 ); \
@ -609,7 +609,7 @@ FN_OID_GET_ATTR2(oid_get_pkcs12_pbe_alg, oid_pkcs12_pbe_alg_t, pkcs12_pbe_alg, m
* This fuction tries to 'fix' this by at least suggesting enlarging the * This fuction tries to 'fix' this by at least suggesting enlarging the
* size by 20. * 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; va_list ap;
int res = -1; int res = -1;
@ -621,7 +621,7 @@ static int compat_snprintf(char *str, size_t size, const char *format, ...)
va_end( ap ); va_end( ap );
// No quick fix possible // No quick fix possible
if ( res < 0 ) if( res < 0 )
return( (int) size + 20 ); return( (int) size + 20 );
return( res ); return( res );
@ -635,7 +635,7 @@ static int compat_snprintf(char *str, size_t size, const char *format, ...)
if( ret == -1 ) \ if( ret == -1 ) \
return( POLARSSL_ERR_OID_BUF_TOO_SMALL ); \ return( POLARSSL_ERR_OID_BUF_TOO_SMALL ); \
\ \
if ( (unsigned int) ret >= n ) { \ if( (unsigned int) ret >= n ) { \
p[n - 1] = '\0'; \ p[n - 1] = '\0'; \
return( POLARSSL_ERR_OID_BUF_TOO_SMALL ); \ return( POLARSSL_ERR_OID_BUF_TOO_SMALL ); \
} \ } \
@ -667,7 +667,7 @@ int oid_get_numeric_string( char *buf, size_t size,
for( i = 1; i < oid->len; i++ ) for( i = 1; i < oid->len; i++ )
{ {
/* Prevent overflow in value. */ /* Prevent overflow in value. */
if ( ( ( value << 7 ) >> 7 ) != value ) if( ( ( value << 7 ) >> 7 ) != value )
return( POLARSSL_ERR_OID_BUF_TOO_SMALL ); return( POLARSSL_ERR_OID_BUF_TOO_SMALL );
value <<= 7; value <<= 7;

View File

@ -137,9 +137,9 @@ int padlock_xcryptcbc( aes_context *ctx,
memcpy( iw, iv, 16 ); memcpy( iw, iv, 16 );
ctrl = iw + 4; 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" \ asm( "pushfl; popfl \n" \
"movl %%ebx, %0 \n" \ "movl %%ebx, %0 \n" \

View File

@ -6,7 +6,7 @@
* *
* \author Mathias Olsson <mathias@kompetensum.com> * \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) * This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>

View File

@ -1,7 +1,7 @@
/* /*
* Public Key abstraction layer * 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) * This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@ -66,7 +66,7 @@ void pk_init( pk_context *ctx )
*/ */
void pk_free( pk_context *ctx ) void pk_free( pk_context *ctx )
{ {
if( ctx == NULL || ctx->pk_info == NULL) if( ctx == NULL || ctx->pk_info == NULL )
return; return;
ctx->pk_info->ctx_free_func( ctx->pk_ctx ); ctx->pk_info->ctx_free_func( ctx->pk_ctx );

View File

@ -75,7 +75,7 @@ int pkcs11_x509_cert_init( x509_crt *cert, pkcs11h_certificate_t pkcs11_cert )
goto cleanup; 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; ret = 6;
goto cleanup; goto cleanup;
@ -105,7 +105,7 @@ int pkcs11_priv_key_init( pkcs11_context *priv_key,
if( 0 != pkcs11_x509_cert_init( &cert, pkcs11_cert ) ) if( 0 != pkcs11_x509_cert_init( &cert, pkcs11_cert ) )
goto cleanup; goto cleanup;
priv_key->len = pk_get_len(&cert.pk); priv_key->len = pk_get_len( &cert.pk );
priv_key->pkcs11h_cert = pkcs11_cert; priv_key->pkcs11h_cert = pkcs11_cert;
ret = 0; ret = 0;
@ -191,13 +191,13 @@ int pkcs11_sign( pkcs11_context *ctx,
} }
sig_len = ctx->len; sig_len = ctx->len;
if ( hashlen > sig_len || asn_len > sig_len || if( hashlen > sig_len || asn_len > sig_len ||
hashlen + asn_len > sig_len ) hashlen + asn_len > sig_len )
{ {
return( POLARSSL_ERR_RSA_BAD_INPUT_DATA ); return( POLARSSL_ERR_RSA_BAD_INPUT_DATA );
} }
if( md_alg != POLARSSL_MD_NONE) if( md_alg != POLARSSL_MD_NONE )
{ {
/* /*
* DigestInfo ::= SEQUENCE { * DigestInfo ::= SEQUENCE {

View File

@ -93,14 +93,14 @@ static int pkcs12_pbe_derive_key_iv( asn1_buf *pbe_params, md_type_t md_type,
size_t i; size_t i;
unsigned char unipwd[258]; unsigned char unipwd[258];
memset(&salt, 0, sizeof(asn1_buf)); memset( &salt, 0, sizeof(asn1_buf) );
memset(&unipwd, 0, sizeof(unipwd)); memset( &unipwd, 0, sizeof(unipwd) );
if( ( ret = pkcs12_parse_pbe_params( pbe_params, &salt, if( ( ret = pkcs12_parse_pbe_params( pbe_params, &salt,
&iterations ) ) != 0 ) &iterations ) ) != 0 )
return( ret ); return( ret );
for(i = 0; i < pwdlen; i++) for( i = 0; i < pwdlen; i++ )
unipwd[i * 2 + 1] = pwd[i]; unipwd[i * 2 + 1] = pwd[i];
if( ( ret = pkcs12_derivation( key, keylen, unipwd, pwdlen * 2 + 2, if( ( ret = pkcs12_derivation( key, keylen, unipwd, pwdlen * 2 + 2,
@ -252,7 +252,7 @@ int pkcs12_derivation( unsigned char *data, size_t datalen,
if( md_info == NULL ) if( md_info == NULL )
return( POLARSSL_ERR_PKCS12_FEATURE_UNAVAILABLE ); 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 ); return( ret );
hlen = md_get_size( md_info ); hlen = md_get_size( md_info );

View File

@ -168,7 +168,7 @@ int pkcs5_pbes2( asn1_buf *pbe_params, int mode,
return( POLARSSL_ERR_PKCS5_INVALID_FORMAT + ret ); 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 ); return( POLARSSL_ERR_PKCS5_FEATURE_UNAVAILABLE );
cipher_info = cipher_info_from_type( cipher_alg ); cipher_info = cipher_info_from_type( cipher_alg );
@ -188,8 +188,8 @@ int pkcs5_pbes2( asn1_buf *pbe_params, int mode,
if( ( ret = md_init_ctx( &md_ctx, md_info ) ) != 0 ) if( ( ret = md_init_ctx( &md_ctx, md_info ) ) != 0 )
goto exit; goto exit;
if ( ( ret = pkcs5_pbkdf2_hmac( &md_ctx, pwd, pwdlen, salt.p, salt.len, if( ( ret = pkcs5_pbkdf2_hmac( &md_ctx, pwd, pwdlen, salt.p, salt.len,
iterations, keylen, key ) ) != 0 ) iterations, keylen, key ) ) != 0 )
{ {
goto exit; goto exit;
} }
@ -260,7 +260,7 @@ int pkcs5_pbkdf2_hmac( md_context_t *ctx, const unsigned char *password,
memcpy( md1, work, md_size ); memcpy( md1, work, md_size );
for ( i = 1; i < iteration_count; i++ ) for( i = 1; i < iteration_count; i++ )
{ {
// U2 ends up in md1 // U2 ends up in md1
// //

View File

@ -120,7 +120,7 @@ int pk_parse_keyfile( pk_context *ctx,
size_t n; size_t n;
unsigned char *buf; unsigned char *buf;
if ( (ret = load_file( path, &buf, &n ) ) != 0 ) if( ( ret = load_file( path, &buf, &n ) ) != 0 )
return( ret ); return( ret );
if( pwd == NULL ) if( pwd == NULL )
@ -144,7 +144,7 @@ int pk_parse_public_keyfile( pk_context *ctx, const char *path )
size_t n; size_t n;
unsigned char *buf; unsigned char *buf;
if ( (ret = load_file( path, &buf, &n ) ) != 0 ) if( ( ret = load_file( path, &buf, &n ) ) != 0 )
return( ret ); return( ret );
ret = pk_parse_public_key( ctx, buf, n ); ret = pk_parse_public_key( ctx, buf, n );
@ -810,7 +810,7 @@ static int pk_parse_key_sec1_der( ecp_keypair *eck,
return( POLARSSL_ERR_PK_KEY_INVALID_FORMAT ); 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 ); ecp_keypair_free( eck );
return( POLARSSL_ERR_PK_KEY_INVALID_FORMAT + ret ); return( POLARSSL_ERR_PK_KEY_INVALID_FORMAT + ret );

View File

@ -603,7 +603,7 @@ int rsa_rsaes_pkcs1_v15_encrypt( rsa_context *ctx,
// Check if RNG failed to generate data // 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 ); return( POLARSSL_ERR_RSA_RNG_FAILED + ret );
p++; p++;
@ -759,7 +759,7 @@ int rsa_rsaes_oaep_decrypt( rsa_context *ctx,
if( bad != 0 ) if( bad != 0 )
return( POLARSSL_ERR_RSA_INVALID_PADDING ); 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 ); return( POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE );
*olen = ilen - (p - buf); *olen = ilen - (p - buf);
@ -844,7 +844,7 @@ int rsa_rsaes_pkcs1_v15_decrypt( rsa_context *ctx,
if( bad ) if( bad )
return( POLARSSL_ERR_RSA_INVALID_PADDING ); 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 ); return( POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE );
*olen = ilen - (p - buf); *olen = ilen - (p - buf);

View File

@ -118,8 +118,8 @@ void sha1_process( sha1_context *ctx, const unsigned char data[64] )
#define R(t) \ #define R(t) \
( \ ( \
temp = W[(t - 3) & 0x0F] ^ W[(t - 8) & 0x0F] ^ \ temp = W[( t - 3 ) & 0x0F] ^ W[( t - 8 ) & 0x0F] ^ \
W[(t - 14) & 0x0F] ^ W[ t & 0x0F], \ W[( t - 14 ) & 0x0F] ^ W[ t & 0x0F], \
( W[t & 0x0F] = S(temp,1) ) \ ( W[t & 0x0F] = S(temp,1) ) \
) )

View File

@ -71,7 +71,7 @@ static void ssl_write_hostname_ext( ssl_context *ssl,
*olen = 0; *olen = 0;
if ( ssl->hostname == NULL ) if( ssl->hostname == NULL )
return; return;
SSL_DEBUG_MSG( 3, ( "client hello, adding server name extension: %s", SSL_DEBUG_MSG( 3, ( "client hello, adding server name extension: %s",
@ -2470,7 +2470,7 @@ static int ssl_parse_new_session_ticket( ssl_context *ssl )
* Zero-length ticket means the server changed his mind and doesn't want * Zero-length ticket means the server changed his mind and doesn't want
* to send a ticket after all, so just forget it * to send a ticket after all, so just forget it
*/ */
if( ticket_len == 0) if( ticket_len == 0 )
return( 0 ); return( 0 );
polarssl_zeroize( ssl->session_negotiate->ticket, polarssl_zeroize( ssl->session_negotiate->ticket,

View File

@ -211,7 +211,7 @@ static int ssl_write_ticket( ssl_context *ssl, size_t *tlen )
*/ */
state = p + 2; state = p + 2;
if( ssl_save_session( ssl->session_negotiate, state, 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 ) &clear_len ) != 0 )
{ {
return( POLARSSL_ERR_SSL_CERTIFICATE_TOO_LARGE ); return( POLARSSL_ERR_SSL_CERTIFICATE_TOO_LARGE );
@ -2343,7 +2343,7 @@ curve_matching_done:
#endif /* POLARSSL_SSL_PROTO_TLS1_2 */ #endif /* POLARSSL_SSL_PROTO_TLS1_2 */
#if defined(POLARSSL_SSL_PROTO_SSL3) || defined(POLARSSL_SSL_PROTO_TLS1) || \ #if defined(POLARSSL_SSL_PROTO_SSL3) || defined(POLARSSL_SSL_PROTO_TLS1) || \
defined(POLARSSL_SSL_PROTO_TLS1_1) defined(POLARSSL_SSL_PROTO_TLS1_1)
if ( ciphersuite_info->key_exchange == if( ciphersuite_info->key_exchange ==
POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA ) POLARSSL_KEY_EXCHANGE_ECDHE_ECDSA )
{ {
md_alg = POLARSSL_MD_SHA1; md_alg = POLARSSL_MD_SHA1;
@ -2397,6 +2397,7 @@ curve_matching_done:
if( md_alg != POLARSSL_MD_NONE ) if( md_alg != POLARSSL_MD_NONE )
{ {
md_context_t ctx; md_context_t ctx;
const md_info_t *md_info = md_info_from_type( md_alg );
/* Info from md_alg will be used instead */ /* Info from md_alg will be used instead */
hashlen = 0; hashlen = 0;
@ -2408,7 +2409,7 @@ curve_matching_done:
* ServerDHParams params; * 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 ); SSL_DEBUG_RET( 1, "md_init_ctx", ret );
return( ret ); return( ret );

View File

@ -126,18 +126,18 @@ static int ssl_session_copy( ssl_session *dst, const ssl_session *src )
} }
#if defined(POLARSSL_SSL_HW_RECORD_ACCEL) #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, const unsigned char *key_enc, const unsigned char *key_dec,
size_t keylen, size_t keylen,
const unsigned char *iv_enc, const unsigned char *iv_dec, const unsigned char *iv_enc, const unsigned char *iv_dec,
size_t ivlen, size_t ivlen,
const unsigned char *mac_enc, const unsigned char *mac_dec, const unsigned char *mac_enc, const unsigned char *mac_dec,
size_t maclen) = NULL; size_t maclen ) = NULL;
int (*ssl_hw_record_activate)(ssl_context *ssl, int direction) = 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_reset)( ssl_context *ssl ) = NULL;
int (*ssl_hw_record_write)(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_read)( ssl_context *ssl ) = NULL;
int (*ssl_hw_record_finish)(ssl_context *ssl) = NULL; int (*ssl_hw_record_finish)( ssl_context *ssl ) = NULL;
#endif /* POLARSSL_SSL_HW_RECORD_ACCEL */ #endif /* POLARSSL_SSL_HW_RECORD_ACCEL */
/* /*
@ -339,34 +339,34 @@ static int tls_prf_sha384( const unsigned char *secret, size_t slen,
#endif /* POLARSSL_SHA512_C */ #endif /* POLARSSL_SHA512_C */
#endif /* POLARSSL_SSL_PROTO_TLS1_2 */ #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) || \ #if defined(POLARSSL_SSL_PROTO_SSL3) || defined(POLARSSL_SSL_PROTO_TLS1) || \
defined(POLARSSL_SSL_PROTO_TLS1_1) 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 #endif
#if defined(POLARSSL_SSL_PROTO_SSL3) #if defined(POLARSSL_SSL_PROTO_SSL3)
static void ssl_calc_verify_ssl(ssl_context *,unsigned char *); 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_finished_ssl( ssl_context *, unsigned char *, int );
#endif #endif
#if defined(POLARSSL_SSL_PROTO_TLS1) || defined(POLARSSL_SSL_PROTO_TLS1_1) #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_verify_tls( ssl_context *, unsigned char * );
static void ssl_calc_finished_tls(ssl_context *,unsigned char *,int); static void ssl_calc_finished_tls( ssl_context *, unsigned char *, int );
#endif #endif
#if defined(POLARSSL_SSL_PROTO_TLS1_2) #if defined(POLARSSL_SSL_PROTO_TLS1_2)
#if defined(POLARSSL_SHA256_C) #if defined(POLARSSL_SHA256_C)
static void ssl_update_checksum_sha256(ssl_context *, const unsigned char *, size_t); 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_verify_tls_sha256( ssl_context *,unsigned char * );
static void ssl_calc_finished_tls_sha256(ssl_context *,unsigned char *,int); static void ssl_calc_finished_tls_sha256( ssl_context *,unsigned char *, int );
#endif #endif
#if defined(POLARSSL_SHA512_C) #if defined(POLARSSL_SHA512_C)
static void ssl_update_checksum_sha384(ssl_context *, const unsigned char *, size_t); 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_verify_tls_sha384( ssl_context *, unsigned char * );
static void ssl_calc_finished_tls_sha384(ssl_context *,unsigned char *,int); static void ssl_calc_finished_tls_sha384( ssl_context *, unsigned char *, int );
#endif #endif
#endif /* POLARSSL_SSL_PROTO_TLS1_2 */ #endif /* POLARSSL_SSL_PROTO_TLS1_2 */
@ -637,7 +637,7 @@ int ssl_derive_keys( ssl_context *ssl )
} }
#if defined(POLARSSL_SSL_HW_RECORD_ACCEL) #if defined(POLARSSL_SSL_HW_RECORD_ACCEL)
if( ssl_hw_record_init != NULL) if( ssl_hw_record_init != NULL )
{ {
int ret = 0; int ret = 0;
@ -911,7 +911,7 @@ int ssl_psk_derive_premaster( ssl_context *ssl, key_exchange_type_t key_ex )
size_t zlen; size_t zlen;
if( ( ret = ecdh_calc_secret( &ssl->handshake->ecdh_ctx, &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->f_rng, ssl->p_rng ) ) != 0 )
{ {
SSL_DEBUG_RET( 1, "ecdh_calc_secret", ret ); SSL_DEBUG_RET( 1, "ecdh_calc_secret", ret );
@ -1529,7 +1529,7 @@ static int ssl_decrypt_buf( ssl_context *ssl )
correct &= ( pad_count == padlen ); /* Only 1 on correct padding */ correct &= ( pad_count == padlen ); /* Only 1 on correct padding */
#if defined(POLARSSL_SSL_DEBUG_ALL) #if defined(POLARSSL_SSL_DEBUG_ALL)
if( padlen > 0 && correct == 0) if( padlen > 0 && correct == 0 )
SSL_DEBUG_MSG( 1, ( "bad padding byte detected" ) ); SSL_DEBUG_MSG( 1, ( "bad padding byte detected" ) );
#endif #endif
padlen &= correct * 0x1FF; padlen &= correct * 0x1FF;
@ -1879,7 +1879,7 @@ int ssl_write_record( ssl_context *ssl )
#endif /*POLARSSL_ZLIB_SUPPORT */ #endif /*POLARSSL_ZLIB_SUPPORT */
#if defined(POLARSSL_SSL_HW_RECORD_ACCEL) #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()" ) ); SSL_DEBUG_MSG( 2, ( "going for ssl_hw_record_write()" ) );
@ -2077,7 +2077,7 @@ int ssl_read_record( ssl_context *ssl )
ssl->in_hdr, 5 + ssl->in_msglen ); ssl->in_hdr, 5 + ssl->in_msglen );
#if defined(POLARSSL_SSL_HW_RECORD_ACCEL) #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()" ) ); SSL_DEBUG_MSG( 2, ( "going for ssl_hw_record_read()" ) );
@ -3118,7 +3118,7 @@ int ssl_write_finished( ssl_context *ssl )
memset( ssl->out_ctr, 0, 8 ); memset( ssl->out_ctr, 0, 8 );
#if defined(POLARSSL_SSL_HW_RECORD_ACCEL) #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 ) if( ( ret = ssl_hw_record_activate( ssl, SSL_CHANNEL_OUTBOUND ) ) != 0 )
{ {
@ -3170,7 +3170,7 @@ int ssl_parse_finished( ssl_context *ssl )
ssl->in_msg = ssl->in_iv; ssl->in_msg = ssl->in_iv;
#if defined(POLARSSL_SSL_HW_RECORD_ACCEL) #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 ) if( ( ret = ssl_hw_record_activate( ssl, SSL_CHANNEL_INBOUND ) ) != 0 )
{ {
@ -3412,7 +3412,7 @@ int ssl_session_reset( ssl_context *ssl )
memset( ssl->in_ctr, 0, SSL_BUFFER_LEN ); memset( ssl->in_ctr, 0, SSL_BUFFER_LEN );
#if defined(POLARSSL_SSL_HW_RECORD_ACCEL) #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()" ) ); SSL_DEBUG_MSG( 2, ( "going for ssl_hw_record_reset()" ) );
if( ( ret = ssl_hw_record_reset( ssl ) ) != 0 ) if( ( ret = ssl_hw_record_reset( ssl ) ) != 0 )
@ -3777,13 +3777,13 @@ int ssl_set_dh_param_ctx( ssl_context *ssl, dhm_context *dhm_ctx )
{ {
int ret; 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 ); SSL_DEBUG_RET( 1, "mpi_copy", ret );
return( 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 ); SSL_DEBUG_RET( 1, "mpi_copy", ret );
return( ret ); return( ret );
@ -4544,7 +4544,7 @@ void ssl_free( ssl_context *ssl )
#endif #endif
#if defined(POLARSSL_SSL_SERVER_NAME_INDICATION) #if defined(POLARSSL_SSL_SERVER_NAME_INDICATION)
if ( ssl->hostname != NULL ) if( ssl->hostname != NULL )
{ {
polarssl_zeroize( ssl->hostname, ssl->hostname_len ); polarssl_zeroize( ssl->hostname, ssl->hostname_len );
polarssl_free( ssl->hostname ); polarssl_free( ssl->hostname );

View File

@ -1,7 +1,7 @@
/* /*
* Threading abstraction layer * 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) * This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>

View File

@ -66,7 +66,7 @@ struct _hr_time
#endif /* _WIN32 && !EFIX64 && !EFI32 */ #endif /* _WIN32 && !EFIX64 && !EFI32 */
#if !defined(POLARSSL_HAVE_HARDCLOCK) && defined(POLARSSL_HAVE_ASM) && \ #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 #define POLARSSL_HAVE_HARDCLOCK
@ -95,7 +95,7 @@ unsigned long hardclock( void )
__GNUC__ && __i386__ */ __GNUC__ && __i386__ */
#if !defined(POLARSSL_HAVE_HARDCLOCK) && defined(POLARSSL_HAVE_ASM) && \ #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 #define POLARSSL_HAVE_HARDCLOCK
@ -103,13 +103,13 @@ unsigned long hardclock( void )
{ {
unsigned long lo, hi; unsigned long lo, hi;
asm volatile( "rdtsc" : "=a" (lo), "=d" (hi) ); asm volatile( "rdtsc" : "=a" (lo), "=d" (hi) );
return( lo | (hi << 32) ); return( lo | ( hi << 32 ) );
} }
#endif /* !POLARSSL_HAVE_HARDCLOCK && POLARSSL_HAVE_ASM && #endif /* !POLARSSL_HAVE_HARDCLOCK && POLARSSL_HAVE_ASM &&
__GNUC__ && ( __amd64__ || __x86_64__ ) */ __GNUC__ && ( __amd64__ || __x86_64__ ) */
#if !defined(POLARSSL_HAVE_HARDCLOCK) && defined(POLARSSL_HAVE_ASM) && \ #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 #define POLARSSL_HAVE_HARDCLOCK
@ -368,7 +368,7 @@ int timing_self_test( int verbose )
int hardfail; int hardfail;
struct hr_time hires; struct hr_time hires;
if( verbose != 0) if( verbose != 0 )
polarssl_printf( " TIMING tests note: will take some time!\n" ); polarssl_printf( " TIMING tests note: will take some time!\n" );
if( verbose != 0 ) if( verbose != 0 )

View File

@ -483,7 +483,7 @@ int x509_get_time( unsigned char **p, const unsigned char *end,
tag = **p; tag = **p;
if ( tag == ASN1_UTC_TIME ) if( tag == ASN1_UTC_TIME )
{ {
(*p)++; (*p)++;
ret = asn1_get_len( p, end, &len ); ret = asn1_get_len( p, end, &len );
@ -507,7 +507,7 @@ int x509_get_time( unsigned char **p, const unsigned char *end,
return( 0 ); return( 0 );
} }
else if ( tag == ASN1_GENERALIZED_TIME ) else if( tag == ASN1_GENERALIZED_TIME )
{ {
(*p)++; (*p)++;
ret = asn1_get_len( p, end, &len ); ret = asn1_get_len( p, end, &len );
@ -703,7 +703,7 @@ int x509_load_file( const char *path, unsigned char **buf, size_t *n )
* This fuction tries to 'fix' this by at least suggesting enlarging the * This fuction tries to 'fix' this by at least suggesting enlarging the
* size by 20. * 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; va_list ap;
int res = -1; int res = -1;
@ -715,7 +715,7 @@ static int compat_snprintf(char *str, size_t size, const char *format, ...)
va_end( ap ); va_end( ap );
// No quick fix possible // No quick fix possible
if ( res < 0 ) if( res < 0 )
return( (int) size + 20 ); return( (int) size + 20 );
return( res ); return( res );
@ -731,7 +731,7 @@ static int compat_snprintf(char *str, size_t size, const char *format, ...)
if( ret == -1 ) \ if( ret == -1 ) \
return( -1 ); \ return( -1 ); \
\ \
if ( (unsigned int) ret > n ) { \ if( (unsigned int) ret > n ) { \
p[n - 1] = '\0'; \ p[n - 1] = '\0'; \
return( POLARSSL_ERR_DEBUG_BUF_TOO_SMALL ); \ return( POLARSSL_ERR_DEBUG_BUF_TOO_SMALL ); \
} \ } \
@ -930,7 +930,7 @@ static void x509_get_current_time( x509_time *now )
#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) #if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
SYSTEMTIME st; SYSTEMTIME st;
GetSystemTime(&st); GetSystemTime( &st );
now->year = st.wYear; now->year = st.wYear;
now->mon = st.wMonth; now->mon = st.wMonth;
@ -1080,7 +1080,7 @@ int x509_self_test( int verbose )
if( verbose != 0 ) if( verbose != 0 )
polarssl_printf( "failed\n" ); polarssl_printf( "failed\n" );
polarssl_printf("ret = %d, &flags = %04x\n", ret, flags); polarssl_printf( "ret = %d, &flags = %04x\n", ret, flags );
return( ret ); return( ret );
} }

View File

@ -1,7 +1,7 @@
/* /*
* X.509 base functions for creating certificates / CSRs * 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) * This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>

View File

@ -142,7 +142,7 @@ static int x509_get_crl_entry_ext( unsigned char **p,
size_t len = 0; size_t len = 0;
/* OPTIONAL */ /* OPTIONAL */
if (end <= *p) if( end <= *p )
return( 0 ); return( 0 );
ext->tag = **p; ext->tag = **p;
@ -237,7 +237,7 @@ static int x509_get_entries( unsigned char **p,
&cur_entry->entry_ext ) ) != 0 ) &cur_entry->entry_ext ) ) != 0 )
return( ret ); return( ret );
if ( *p < end ) if( *p < end )
{ {
cur_entry->next = polarssl_malloc( sizeof( x509_crl_entry ) ); cur_entry->next = polarssl_malloc( sizeof( x509_crl_entry ) );
@ -285,7 +285,7 @@ int x509_crl_parse( x509_crl *chain, const unsigned char *buf, size_t buflen )
/* /*
* Add new CRL on the end of the chain if needed. * 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 ) ); crl->next = (x509_crl *) polarssl_malloc( sizeof( x509_crl ) );
@ -443,9 +443,9 @@ int x509_crl_parse( x509_crl *chain, const unsigned char *buf, size_t buflen )
if( ( ret = x509_get_time( &p, end, &crl->next_update ) ) != 0 ) 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 ) && POLARSSL_ERR_ASN1_UNEXPECTED_TAG ) &&
ret != ( POLARSSL_ERR_X509_INVALID_DATE + ret != ( POLARSSL_ERR_X509_INVALID_DATE +
POLARSSL_ERR_ASN1_OUT_OF_DATA ) ) POLARSSL_ERR_ASN1_OUT_OF_DATA ) )
{ {
x509_crl_free( crl ); x509_crl_free( crl );
@ -504,7 +504,7 @@ int x509_crl_parse( x509_crl *chain, const unsigned char *buf, size_t buflen )
if( crl->sig_oid1.len != crl->sig_oid2.len || if( crl->sig_oid1.len != crl->sig_oid2.len ||
memcmp( crl->sig_oid1.p, crl->sig_oid2.p, crl->sig_oid1.len ) != 0 || memcmp( crl->sig_oid1.p, crl->sig_oid2.p, crl->sig_oid1.len ) != 0 ||
sig_params1.len != sig_params2.len || 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 ); x509_crl_free( crl );
return( POLARSSL_ERR_X509_SIG_MISMATCH ); return( POLARSSL_ERR_X509_SIG_MISMATCH );
@ -552,7 +552,7 @@ int x509_crl_parse_file( x509_crl *chain, const char *path )
size_t n; size_t n;
unsigned char *buf; unsigned char *buf;
if ( ( ret = x509_load_file( path, &buf, &n ) ) != 0 ) if( ( ret = x509_load_file( path, &buf, &n ) ) != 0 )
return( ret ); return( ret );
ret = x509_crl_parse( chain, buf, n ); ret = x509_crl_parse( chain, buf, n );
@ -579,7 +579,7 @@ int x509_crl_parse_file( x509_crl *chain, const char *path )
* This fuction tries to 'fix' this by at least suggesting enlarging the * This fuction tries to 'fix' this by at least suggesting enlarging the
* size by 20. * 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; va_list ap;
int res = -1; int res = -1;
@ -591,7 +591,7 @@ static int compat_snprintf(char *str, size_t size, const char *format, ...)
va_end( ap ); va_end( ap );
// No quick fix possible // No quick fix possible
if ( res < 0 ) if( res < 0 )
return( (int) size + 20 ); return( (int) size + 20 );
return( res ); return( res );
@ -607,7 +607,7 @@ static int compat_snprintf(char *str, size_t size, const char *format, ...)
if( ret == -1 ) \ if( ret == -1 ) \
return( -1 ); \ return( -1 ); \
\ \
if ( (unsigned int) ret > n ) { \ if( (unsigned int) ret > n ) { \
p[n - 1] = '\0'; \ p[n - 1] = '\0'; \
return( POLARSSL_ERR_DEBUG_BUF_TOO_SMALL ); \ return( POLARSSL_ERR_DEBUG_BUF_TOO_SMALL ); \
} \ } \
@ -670,7 +670,7 @@ int x509_crl_info( char *buf, size_t size, const char *prefix,
prefix ); prefix );
SAFE_SNPRINTF(); SAFE_SNPRINTF();
ret = x509_serial_gets( p, n, &entry->serial); ret = x509_serial_gets( p, n, &entry->serial );
SAFE_SNPRINTF(); SAFE_SNPRINTF();
ret = snprintf( p, n, " revocation date: " \ ret = snprintf( p, n, " revocation date: " \

View File

@ -723,7 +723,7 @@ static int x509_crt_parse_der_core( x509_crt *crt, const unsigned char *buf,
if( crt->version == 3 ) if( crt->version == 3 )
{ {
#endif #endif
ret = x509_get_crt_ext( &p, end, crt); ret = x509_get_crt_ext( &p, end, crt );
if( ret != 0 ) if( ret != 0 )
{ {
x509_crt_free( crt ); x509_crt_free( crt );
@ -758,7 +758,7 @@ static int x509_crt_parse_der_core( x509_crt *crt, const unsigned char *buf,
if( crt->sig_oid1.len != crt->sig_oid2.len || if( crt->sig_oid1.len != crt->sig_oid2.len ||
memcmp( crt->sig_oid1.p, crt->sig_oid2.p, crt->sig_oid1.len ) != 0 || memcmp( crt->sig_oid1.p, crt->sig_oid2.p, crt->sig_oid1.len ) != 0 ||
sig_params1.len != sig_params2.len || 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 ); x509_crt_free( crt );
return( POLARSSL_ERR_X509_SIG_MISMATCH ); return( POLARSSL_ERR_X509_SIG_MISMATCH );
@ -805,7 +805,7 @@ int x509_crt_parse_der( x509_crt *chain, const unsigned char *buf,
/* /*
* Add new certificate on the end of the chain if needed. * 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 ) ); crt->next = (x509_crt *) polarssl_malloc( sizeof( x509_crt ) );
@ -946,7 +946,7 @@ int x509_crt_parse_file( x509_crt *chain, const char *path )
size_t n; size_t n;
unsigned char *buf; unsigned char *buf;
if ( ( ret = x509_load_file( path, &buf, &n ) ) != 0 ) if( ( ret = x509_load_file( path, &buf, &n ) ) != 0 )
return( ret ); return( ret );
ret = x509_crt_parse( chain, buf, n ); ret = x509_crt_parse( chain, buf, n );
@ -988,7 +988,7 @@ int x509_crt_parse_path( x509_crt *chain, const char *path )
MAX_PATH - 3 ); MAX_PATH - 3 );
hFind = FindFirstFileW( szDir, &file_data ); hFind = FindFirstFileW( szDir, &file_data );
if (hFind == INVALID_HANDLE_VALUE) if( hFind == INVALID_HANDLE_VALUE )
return( POLARSSL_ERR_X509_FILE_IO_ERROR ); return( POLARSSL_ERR_X509_FILE_IO_ERROR );
len = MAX_PATH - len; len = MAX_PATH - len;
@ -1000,7 +1000,7 @@ int x509_crt_parse_path( x509_crt *chain, const char *path )
continue; continue;
w_ret = WideCharToMultiByte( CP_ACP, 0, file_data.cFileName, w_ret = WideCharToMultiByte( CP_ACP, 0, file_data.cFileName,
lstrlenW(file_data.cFileName), lstrlenW( file_data.cFileName ),
p, len - 1, p, len - 1,
NULL, NULL ); NULL, NULL );
@ -1012,7 +1012,7 @@ int x509_crt_parse_path( x509_crt *chain, const char *path )
} }
while( FindNextFileW( hFind, &file_data ) != 0 ); 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; ret = POLARSSL_ERR_X509_FILE_IO_ERROR;
FindClose( hFind ); FindClose( hFind );
@ -1023,7 +1023,7 @@ int x509_crt_parse_path( x509_crt *chain, const char *path )
char entry_name[255]; char entry_name[255];
DIR *dir = opendir( path ); DIR *dir = opendir( path );
if( dir == NULL) if( dir == NULL )
return( POLARSSL_ERR_X509_FILE_IO_ERROR ); return( POLARSSL_ERR_X509_FILE_IO_ERROR );
#if defined(POLARSSL_THREADING_PTHREAD) #if defined(POLARSSL_THREADING_PTHREAD)
@ -1082,7 +1082,7 @@ cleanup:
* This fuction tries to 'fix' this by at least suggesting enlarging the * This fuction tries to 'fix' this by at least suggesting enlarging the
* size by 20. * 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; va_list ap;
int res = -1; int res = -1;
@ -1094,7 +1094,7 @@ static int compat_snprintf(char *str, size_t size, const char *format, ...)
va_end( ap ); va_end( ap );
// No quick fix possible // No quick fix possible
if ( res < 0 ) if( res < 0 )
return( (int) size + 20 ); return( (int) size + 20 );
return( res ); return( res );
@ -1110,7 +1110,7 @@ static int compat_snprintf(char *str, size_t size, const char *format, ...)
if( ret == -1 ) \ if( ret == -1 ) \
return( -1 ); \ return( -1 ); \
\ \
if ( (unsigned int) ret > n ) { \ if( (unsigned int) ret > n ) { \
p[n - 1] = '\0'; \ p[n - 1] = '\0'; \
return( POLARSSL_ERR_DEBUG_BUF_TOO_SMALL ); \ return( POLARSSL_ERR_DEBUG_BUF_TOO_SMALL ); \
} \ } \
@ -1269,7 +1269,7 @@ int x509_crt_info( char *buf, size_t size, const char *prefix,
prefix ); prefix );
SAFE_SNPRINTF(); SAFE_SNPRINTF();
ret = x509_serial_gets( p, n, &crt->serial); ret = x509_serial_gets( p, n, &crt->serial );
SAFE_SNPRINTF(); SAFE_SNPRINTF();
ret = snprintf( p, n, "\n%sissuer name : ", prefix ); ret = snprintf( p, n, "\n%sissuer name : ", prefix );
@ -1517,7 +1517,7 @@ static int x509_crt_verifycrl( x509_crt *crt, x509_crt *ca,
/* /*
* Check if certificate is revoked * Check if certificate is revoked
*/ */
if( x509_crt_revoked(crt, crl_list) ) if( x509_crt_revoked( crt, crl_list ) )
{ {
flags |= BADCERT_REVOKED; flags |= BADCERT_REVOKED;
break; break;
@ -1714,7 +1714,7 @@ static int x509_crt_verify_top(
/* Call callback on top cert */ /* Call callback on top cert */
if( NULL != f_vrfy ) 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 ); return( ret );
} }

View File

@ -295,7 +295,7 @@ int x509_csr_parse_file( x509_csr *csr, const char *path )
size_t n; size_t n;
unsigned char *buf; unsigned char *buf;
if ( ( ret = x509_load_file( path, &buf, &n ) ) != 0 ) if( ( ret = x509_load_file( path, &buf, &n ) ) != 0 )
return( ret ); return( ret );
ret = x509_csr_parse( csr, buf, n ); ret = x509_csr_parse( csr, buf, n );
@ -322,7 +322,7 @@ int x509_csr_parse_file( x509_csr *csr, const char *path )
* This fuction tries to 'fix' this by at least suggesting enlarging the * This fuction tries to 'fix' this by at least suggesting enlarging the
* size by 20. * 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; va_list ap;
int res = -1; int res = -1;
@ -334,7 +334,7 @@ static int compat_snprintf(char *str, size_t size, const char *format, ...)
va_end( ap ); va_end( ap );
// No quick fix possible // No quick fix possible
if ( res < 0 ) if( res < 0 )
return( (int) size + 20 ); return( (int) size + 20 );
return( res ); return( res );
@ -350,7 +350,7 @@ static int compat_snprintf(char *str, size_t size, const char *format, ...)
if( ret == -1 ) \ if( ret == -1 ) \
return( -1 ); \ return( -1 ); \
\ \
if ( (unsigned int) ret > n ) { \ if( (unsigned int) ret > n ) { \
p[n - 1] = '\0'; \ p[n - 1] = '\0'; \
return( POLARSSL_ERR_DEBUG_BUF_TOO_SMALL ); \ return( POLARSSL_ERR_DEBUG_BUF_TOO_SMALL ); \
} \ } \

View File

@ -115,8 +115,8 @@ int x509write_crt_set_serial( x509write_cert *ctx, const mpi *serial )
int x509write_crt_set_validity( x509write_cert *ctx, const char *not_before, int x509write_crt_set_validity( x509write_cert *ctx, const char *not_before,
const char *not_after ) const char *not_after )
{ {
if( strlen(not_before) != 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 ) strlen( not_after ) != X509_RFC5280_UTC_TIME_LEN - 1 )
{ {
return( POLARSSL_ERR_X509_BAD_INPUT_DATA ); return( POLARSSL_ERR_X509_BAD_INPUT_DATA );
} }
@ -176,7 +176,7 @@ int x509write_crt_set_subject_key_identifier( x509write_cert *ctx )
unsigned char *c = buf + sizeof(buf); unsigned char *c = buf + sizeof(buf);
size_t len = 0; 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 ) ); ASN1_CHK_ADD( len, pk_write_pubkey( &c, buf, ctx->subject_key ) );
sha1( buf + sizeof(buf) - len, len, buf + sizeof(buf) - 20 ); sha1( buf + sizeof(buf) - len, len, buf + sizeof(buf) - 20 );
@ -198,7 +198,7 @@ int x509write_crt_set_authority_key_identifier( x509write_cert *ctx )
unsigned char *c = buf + sizeof(buf); unsigned char *c = buf + sizeof(buf);
size_t len = 0; 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 ) ); ASN1_CHK_ADD( len, pk_write_pubkey( &c, buf, ctx->issuer_key ) );
sha1( buf + sizeof(buf) - len, len, buf + sizeof(buf) - 20 ); sha1( buf + sizeof(buf) - len, len, buf + sizeof(buf) - 20 );

View File

@ -71,7 +71,7 @@ void xtea_setup( xtea_context *ctx, const unsigned char key[16] )
{ {
int i; int i;
memset(ctx, 0, sizeof(xtea_context)); memset( ctx, 0, sizeof(xtea_context) );
for( i = 0; i < 4; i++ ) for( i = 0; i < 4; i++ )
{ {
@ -142,7 +142,7 @@ int xtea_crypt_cbc( xtea_context *ctx, int mode, size_t length,
memcpy( temp, input, 8 ); memcpy( temp, input, 8 );
xtea_crypt_ecb( ctx, mode, input, output ); 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] ); output[i] = (unsigned char)( output[i] ^ iv[i] );
memcpy( iv, temp, 8 ); memcpy( iv, temp, 8 );