From 7dc4c44267f83ab1a0148047534836d655ee931f Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Sat, 1 Feb 2014 22:50:26 +0100 Subject: [PATCH] Library files moved to use platform layer --- library/aes.c | 56 ++++++++++++++----------- library/arc4.c | 16 ++++--- library/asn1parse.c | 6 +-- library/asn1write.c | 6 +-- library/base64.c | 18 +++++--- library/bignum.c | 43 +++++++++---------- library/camellia.c | 40 ++++++++++-------- library/cipher.c | 11 +---- library/cipher_wrap.c | 6 +-- library/ctr_drbg.c | 28 ++++++++----- library/des.c | 32 ++++++++------ library/dhm.c | 13 +++--- library/ecp.c | 23 +++++----- library/gcm.c | 54 ++++++++++++++---------- library/hmac_drbg.c | 28 ++++++++----- library/md2.c | 16 ++++--- library/md4.c | 16 ++++--- library/md5.c | 24 +++++++---- library/md_wrap.c | 6 +-- library/memory_buffer_alloc.c | 79 +++++++++++++++++++++-------------- library/pem.c | 6 +-- library/pk_wrap.c | 6 +-- library/pkcs11.c | 9 ++-- library/pkcs5.c | 16 ++++--- library/pkparse.c | 4 +- library/pkwrite.c | 6 +-- library/ripemd160.c | 21 ++++++---- library/rsa.c | 32 ++++++++------ library/sha1.c | 24 +++++++---- library/sha256.c | 24 +++++++---- library/sha512.c | 24 +++++++---- library/ssl_cache.c | 6 +-- library/ssl_cli.c | 6 +-- library/ssl_srv.c | 6 +-- library/ssl_tls.c | 6 +-- library/x509.c | 21 +++++----- library/x509_crl.c | 6 +-- library/x509_crt.c | 6 +-- library/x509_csr.c | 6 +-- library/xtea.c | 14 +++++-- 40 files changed, 447 insertions(+), 323 deletions(-) diff --git a/library/aes.c b/library/aes.c index bc4b178ed..f516fba67 100644 --- a/library/aes.c +++ b/library/aes.c @@ -1,7 +1,7 @@ /* * FIPS-197 compliant AES implementation * - * Copyright (C) 2006-2013, Brainspark B.V. + * Copyright (C) 2006-2014, Brainspark B.V. * * This file is part of PolarSSL (http://www.polarssl.org) * Lead Maintainer: Paul Bakker @@ -41,6 +41,12 @@ #include "polarssl/aesni.h" #endif +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" +#else +#define polarssl_printf printf +#endif + #if !defined(POLARSSL_AES_ALT) /* @@ -1191,8 +1197,8 @@ int aes_self_test( int verbose ) v = i & 1; if( verbose != 0 ) - printf( " AES-ECB-%3d (%s): ", 128 + u * 64, - ( v == AES_DECRYPT ) ? "dec" : "enc" ); + polarssl_printf( " AES-ECB-%3d (%s): ", 128 + u * 64, + ( v == AES_DECRYPT ) ? "dec" : "enc" ); memset( buf, 0, 16 ); @@ -1206,7 +1212,7 @@ int aes_self_test( int verbose ) if( memcmp( buf, aes_test_ecb_dec[u], 16 ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } @@ -1221,18 +1227,18 @@ int aes_self_test( int verbose ) if( memcmp( buf, aes_test_ecb_enc[u], 16 ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); } if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); #if defined(POLARSSL_CIPHER_MODE_CBC) /* @@ -1244,8 +1250,8 @@ int aes_self_test( int verbose ) v = i & 1; if( verbose != 0 ) - printf( " AES-CBC-%3d (%s): ", 128 + u * 64, - ( v == AES_DECRYPT ) ? "dec" : "enc" ); + polarssl_printf( " AES-CBC-%3d (%s): ", 128 + u * 64, + ( v == AES_DECRYPT ) ? "dec" : "enc" ); memset( iv , 0, 16 ); memset( prv, 0, 16 ); @@ -1261,7 +1267,7 @@ int aes_self_test( int verbose ) if( memcmp( buf, aes_test_cbc_dec[u], 16 ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } @@ -1284,18 +1290,18 @@ int aes_self_test( int verbose ) if( memcmp( prv, aes_test_cbc_enc[u], 16 ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); } if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); #endif /* POLARSSL_CIPHER_MODE_CBC */ #if defined(POLARSSL_CIPHER_MODE_CFB) @@ -1308,8 +1314,8 @@ int aes_self_test( int verbose ) v = i & 1; if( verbose != 0 ) - printf( " AES-CFB128-%3d (%s): ", 128 + u * 64, - ( v == AES_DECRYPT ) ? "dec" : "enc" ); + polarssl_printf( " AES-CFB128-%3d (%s): ", 128 + u * 64, + ( v == AES_DECRYPT ) ? "dec" : "enc" ); memcpy( iv, aes_test_cfb128_iv, 16 ); memcpy( key, aes_test_cfb128_key[u], 16 + u * 8 ); @@ -1325,7 +1331,7 @@ int aes_self_test( int verbose ) if( memcmp( buf, aes_test_cfb128_pt, 64 ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } @@ -1338,18 +1344,18 @@ int aes_self_test( int verbose ) if( memcmp( buf, aes_test_cfb128_ct[u], 64 ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); } if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); #endif /* POLARSSL_CIPHER_MODE_CFB */ #if defined(POLARSSL_CIPHER_MODE_CTR) @@ -1362,8 +1368,8 @@ int aes_self_test( int verbose ) v = i & 1; if( verbose != 0 ) - printf( " AES-CTR-128 (%s): ", - ( v == AES_DECRYPT ) ? "dec" : "enc" ); + polarssl_printf( " AES-CTR-128 (%s): ", + ( v == AES_DECRYPT ) ? "dec" : "enc" ); memcpy( nonce_counter, aes_test_ctr_nonce_counter[u], 16 ); memcpy( key, aes_test_ctr_key[u], 16 ); @@ -1381,7 +1387,7 @@ int aes_self_test( int verbose ) if( memcmp( buf, aes_test_ctr_pt[u], len ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } @@ -1396,18 +1402,18 @@ int aes_self_test( int verbose ) if( memcmp( buf, aes_test_ctr_ct[u], len ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); } if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); #endif /* POLARSSL_CIPHER_MODE_CTR */ return( 0 ); diff --git a/library/arc4.c b/library/arc4.c index 85b78f5ba..536ea8ccc 100644 --- a/library/arc4.c +++ b/library/arc4.c @@ -1,7 +1,7 @@ /* * An implementation of the ARCFOUR algorithm * - * Copyright (C) 2006-2013, Brainspark B.V. + * Copyright (C) 2006-2014, Brainspark B.V. * * This file is part of PolarSSL (http://www.polarssl.org) * Lead Maintainer: Paul Bakker @@ -34,6 +34,12 @@ #include "polarssl/arc4.h" +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" +#else +#define polarssl_printf printf +#endif + #if !defined(POLARSSL_ARC4_ALT) /* @@ -143,7 +149,7 @@ int arc4_self_test( int verbose ) for( i = 0; i < 3; i++ ) { if( verbose != 0 ) - printf( " ARC4 test #%d: ", i + 1 ); + polarssl_printf( " ARC4 test #%d: ", i + 1 ); memcpy( ibuf, arc4_test_pt[i], 8 ); @@ -153,17 +159,17 @@ int arc4_self_test( int verbose ) if( memcmp( obuf, arc4_test_ct[i], 8 ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); } if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); return( 0 ); } diff --git a/library/asn1parse.c b/library/asn1parse.c index 957359917..c9ce75acc 100644 --- a/library/asn1parse.c +++ b/library/asn1parse.c @@ -1,7 +1,7 @@ /* * Generic ASN.1 parsing * - * 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 @@ -33,8 +33,8 @@ #include "polarssl/bignum.h" #endif -#if defined(POLARSSL_MEMORY_C) -#include "polarssl/memory.h" +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" #else #define polarssl_malloc malloc #define polarssl_free free diff --git a/library/asn1write.c b/library/asn1write.c index 32d1c736f..13f4a394d 100644 --- a/library/asn1write.c +++ b/library/asn1write.c @@ -1,7 +1,7 @@ /* * ASN.1 buffer writing functionality * - * 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 @@ -29,8 +29,8 @@ #include "polarssl/asn1write.h" -#if defined(POLARSSL_MEMORY_C) -#include "polarssl/memory.h" +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" #else #include #define polarssl_malloc malloc diff --git a/library/base64.c b/library/base64.c index 3b4376dac..ee9c05c5d 100644 --- a/library/base64.c +++ b/library/base64.c @@ -1,7 +1,7 @@ /* * RFC 1521 base64 encoding/decoding * - * 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 @@ -36,6 +36,12 @@ typedef UINT32 uint32_t; #include #endif +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" +#else +#define polarssl_printf printf +#endif + static const unsigned char base64_enc_map[64] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', @@ -222,7 +228,7 @@ int base64_self_test( int verbose ) unsigned char buffer[128]; if( verbose != 0 ) - printf( " Base64 encoding test: " ); + polarssl_printf( " Base64 encoding test: " ); len = sizeof( buffer ); src = base64_test_dec; @@ -231,13 +237,13 @@ int base64_self_test( int verbose ) memcmp( base64_test_enc, buffer, 88 ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } if( verbose != 0 ) - printf( "passed\n Base64 decoding test: " ); + polarssl_printf( "passed\n Base64 decoding test: " ); len = sizeof( buffer ); src = base64_test_enc; @@ -246,13 +252,13 @@ int base64_self_test( int verbose ) memcmp( base64_test_dec, buffer, 64 ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } if( verbose != 0 ) - printf( "passed\n\n" ); + polarssl_printf( "passed\n\n" ); return( 0 ); } diff --git a/library/bignum.c b/library/bignum.c index bbd901e83..cb55586ff 100644 --- a/library/bignum.c +++ b/library/bignum.c @@ -1,7 +1,7 @@ /* * Multi-precision integer library * - * 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 @@ -37,9 +37,10 @@ #include "polarssl/bignum.h" #include "polarssl/bn_mul.h" -#if defined(POLARSSL_MEMORY_C) -#include "polarssl/memory.h" +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" #else +#define polarssl_printf printf #define polarssl_malloc malloc #define polarssl_free free #endif @@ -616,7 +617,7 @@ int mpi_write_file( const char *p, const mpi *X, int radix, FILE *fout ) return( POLARSSL_ERR_MPI_FILE_IO_ERROR ); } else - printf( "%s%s", p, s ); + polarssl_printf( "%s%s", p, s ); cleanup: @@ -2189,19 +2190,19 @@ int mpi_self_test( int verbose ) "30879B56C61DE584A0F53A2447A51E" ) ); if( verbose != 0 ) - printf( " MPI test #1 (mul_mpi): " ); + polarssl_printf( " MPI test #1 (mul_mpi): " ); if( mpi_cmp_mpi( &X, &U ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); ret = 1; goto cleanup; } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); MPI_CHK( mpi_div_mpi( &X, &Y, &A, &N ) ); @@ -2214,20 +2215,20 @@ int mpi_self_test( int verbose ) "9EE50D0657C77F374E903CDFA4C642" ) ); if( verbose != 0 ) - printf( " MPI test #2 (div_mpi): " ); + polarssl_printf( " MPI test #2 (div_mpi): " ); if( mpi_cmp_mpi( &X, &U ) != 0 || mpi_cmp_mpi( &Y, &V ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); ret = 1; goto cleanup; } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); MPI_CHK( mpi_exp_mod( &X, &A, &E, &N, NULL ) ); @@ -2237,19 +2238,19 @@ int mpi_self_test( int verbose ) "325D24D6A3C12710F10A09FA08AB87" ) ); if( verbose != 0 ) - printf( " MPI test #3 (exp_mod): " ); + polarssl_printf( " MPI test #3 (exp_mod): " ); if( mpi_cmp_mpi( &X, &U ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); ret = 1; goto cleanup; } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); MPI_CHK( mpi_inv_mod( &X, &A, &N ) ); @@ -2259,22 +2260,22 @@ int mpi_self_test( int verbose ) "C5B8A74DAC4D09E03B5E0BE779F2DF61" ) ); if( verbose != 0 ) - printf( " MPI test #4 (inv_mod): " ); + polarssl_printf( " MPI test #4 (inv_mod): " ); if( mpi_cmp_mpi( &X, &U ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); ret = 1; goto cleanup; } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); if( verbose != 0 ) - printf( " MPI test #5 (simple gcd): " ); + polarssl_printf( " MPI test #5 (simple gcd): " ); for ( i = 0; i < GCD_PAIR_COUNT; i++) { @@ -2286,7 +2287,7 @@ int mpi_self_test( int verbose ) if( mpi_cmp_int( &A, gcd_pairs[i][2] ) != 0 ) { if( verbose != 0 ) - printf( "failed at %d\n", i ); + polarssl_printf( "failed at %d\n", i ); ret = 1; goto cleanup; @@ -2294,18 +2295,18 @@ int mpi_self_test( int verbose ) } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); cleanup: if( ret != 0 && verbose != 0 ) - printf( "Unexpected error, return code = %08X\n", ret ); + polarssl_printf( "Unexpected error, return code = %08X\n", ret ); mpi_free( &A ); mpi_free( &E ); mpi_free( &N ); mpi_free( &X ); mpi_free( &Y ); mpi_free( &U ); mpi_free( &V ); if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); return( ret ); } diff --git a/library/camellia.c b/library/camellia.c index 2366caed6..f007a46a3 100644 --- a/library/camellia.c +++ b/library/camellia.c @@ -1,7 +1,7 @@ /* * Camellia implementation * - * Copyright (C) 2006-2013, Brainspark B.V. + * Copyright (C) 2006-2014, Brainspark B.V. * * This file is part of PolarSSL (http://www.polarssl.org) * Lead Maintainer: Paul Bakker @@ -35,6 +35,12 @@ #include "polarssl/camellia.h" +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" +#else +#define polarssl_printf printf +#endif + #if !defined(POLARSSL_CAMELLIA_ALT) /* @@ -889,8 +895,8 @@ int camellia_self_test( int verbose ) v = j & 1; if( verbose != 0 ) - printf( " CAMELLIA-ECB-%3d (%s): ", 128 + u * 64, - (v == CAMELLIA_DECRYPT) ? "dec" : "enc"); + 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); @@ -910,18 +916,18 @@ int camellia_self_test( int verbose ) if( memcmp( buf, dst, 16 ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); } if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); #if defined(POLARSSL_CIPHER_MODE_CBC) /* @@ -933,8 +939,8 @@ int camellia_self_test( int verbose ) v = j & 1; if( verbose != 0 ) - printf( " CAMELLIA-CBC-%3d (%s): ", 128 + u * 64, - ( v == CAMELLIA_DECRYPT ) ? "dec" : "enc" ); + 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); @@ -963,19 +969,19 @@ int camellia_self_test( int verbose ) if( memcmp( buf, dst, 16 ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); } #endif /* POLARSSL_CIPHER_MODE_CBC */ if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); #if defined(POLARSSL_CIPHER_MODE_CTR) /* @@ -987,8 +993,8 @@ int camellia_self_test( int verbose ) v = i & 1; if( verbose != 0 ) - printf( " CAMELLIA-CTR-128 (%s): ", - ( v == CAMELLIA_DECRYPT ) ? "dec" : "enc" ); + polarssl_printf( " CAMELLIA-CTR-128 (%s): ", + ( v == CAMELLIA_DECRYPT ) ? "dec" : "enc" ); memcpy( nonce_counter, camellia_test_ctr_nonce_counter[u], 16 ); memcpy( key, camellia_test_ctr_key[u], 16 ); @@ -1006,7 +1012,7 @@ int camellia_self_test( int verbose ) if( memcmp( buf, camellia_test_ctr_pt[u], len ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } @@ -1021,18 +1027,18 @@ int camellia_self_test( int verbose ) if( memcmp( buf, camellia_test_ctr_ct[u], len ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); } if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); #endif /* POLARSSL_CIPHER_MODE_CTR */ return ( 0 ); diff --git a/library/cipher.c b/library/cipher.c index bfb229e2f..a103c263f 100644 --- a/library/cipher.c +++ b/library/cipher.c @@ -1,11 +1,11 @@ /** * \file cipher.c - * + * * \brief Generic cipher wrapper for PolarSSL * * \author Adriaan de Jong * - * 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 @@ -769,16 +769,9 @@ int cipher_check_tag( cipher_context_t *ctx, #if defined(POLARSSL_SELF_TEST) -#include - -#define ASSERT(x) if (!(x)) { \ - printf( "failed with %i at %s\n", value, (#x) ); \ - return( 1 ); \ -} /* * Checkup routine */ - int cipher_self_test( int verbose ) { ((void) verbose); diff --git a/library/cipher_wrap.c b/library/cipher_wrap.c index 3020e14e2..23065c4ba 100644 --- a/library/cipher_wrap.c +++ b/library/cipher_wrap.c @@ -5,7 +5,7 @@ * * \author Adriaan de Jong * - * 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 @@ -57,8 +57,8 @@ #include "polarssl/gcm.h" #endif -#if defined(POLARSSL_MEMORY_C) -#include "polarssl/memory.h" +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" #else #define polarssl_malloc malloc #define polarssl_free free diff --git a/library/ctr_drbg.c b/library/ctr_drbg.c index d2b43137c..3be65e102 100644 --- a/library/ctr_drbg.c +++ b/library/ctr_drbg.c @@ -1,7 +1,7 @@ /* * CTR_DRBG implementation based on AES-256 (NIST SP 800-90) * - * 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 @@ -38,6 +38,12 @@ #include #endif +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" +#else +#define polarssl_printf printf +#endif + /* * Non-public function wrapped by ctr_crbg_init(). Necessary to allow NIST * tests to succeed (which require known length fixed entropy) @@ -460,11 +466,11 @@ static int ctr_drbg_self_test_entropy( void *data, unsigned char *buf, return( 0 ); } -#define CHK( c ) if( (c) != 0 ) \ - { \ - if( verbose != 0 ) \ - printf( "failed\n" ); \ - return( 1 ); \ +#define CHK( c ) if( (c) != 0 ) \ + { \ + if( verbose != 0 ) \ + polarssl_printf( "failed\n" ); \ + return( 1 ); \ } /* @@ -479,7 +485,7 @@ int ctr_drbg_self_test( int verbose ) * Based on a NIST CTR_DRBG test vector (PR = True) */ if( verbose != 0 ) - printf( " CTR_DRBG (PR = TRUE) : " ); + polarssl_printf( " CTR_DRBG (PR = TRUE) : " ); test_offset = 0; CHK( ctr_drbg_init_entropy_len( &ctx, ctr_drbg_self_test_entropy, @@ -490,13 +496,13 @@ int ctr_drbg_self_test( int verbose ) CHK( memcmp( buf, result_pr, CTR_DRBG_BLOCKSIZE ) ); if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); /* * Based on a NIST CTR_DRBG test vector (PR = FALSE) */ if( verbose != 0 ) - printf( " CTR_DRBG (PR = FALSE): " ); + polarssl_printf( " CTR_DRBG (PR = FALSE): " ); test_offset = 0; CHK( ctr_drbg_init_entropy_len( &ctx, ctr_drbg_self_test_entropy, @@ -507,10 +513,10 @@ int ctr_drbg_self_test( int verbose ) CHK( memcmp( buf, result_nopr, 16 ) ); if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); return( 0 ); } diff --git a/library/des.c b/library/des.c index 153810d72..6e1523408 100644 --- a/library/des.c +++ b/library/des.c @@ -1,7 +1,7 @@ /* * FIPS-46-3 compliant Triple-DES implementation * - * Copyright (C) 2006-2013, Brainspark B.V. + * Copyright (C) 2006-2014, Brainspark B.V. * * This file is part of PolarSSL (http://www.polarssl.org) * Lead Maintainer: Paul Bakker @@ -35,6 +35,12 @@ #include "polarssl/des.h" +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" +#else +#define polarssl_printf printf +#endif + #if !defined(POLARSSL_DES_ALT) /* @@ -839,9 +845,9 @@ int des_self_test( int verbose ) v = i & 1; if( verbose != 0 ) - printf( " DES%c-ECB-%3d (%s): ", - ( u == 0 ) ? ' ' : '3', 56 + u * 56, - ( v == DES_DECRYPT ) ? "dec" : "enc" ); + polarssl_printf( " DES%c-ECB-%3d (%s): ", + ( u == 0 ) ? ' ' : '3', 56 + u * 56, + ( v == DES_DECRYPT ) ? "dec" : "enc" ); memcpy( buf, des3_test_buf, 8 ); @@ -889,17 +895,17 @@ int des_self_test( int verbose ) memcmp( buf, des3_test_ecb_enc[u], 8 ) != 0 ) ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); } if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); #if defined(POLARSSL_CIPHER_MODE_CBC) /* @@ -911,9 +917,9 @@ int des_self_test( int verbose ) v = i & 1; if( verbose != 0 ) - printf( " DES%c-CBC-%3d (%s): ", - ( u == 0 ) ? ' ' : '3', 56 + u * 56, - ( v == DES_DECRYPT ) ? "dec" : "enc" ); + polarssl_printf( " DES%c-CBC-%3d (%s): ", + ( u == 0 ) ? ' ' : '3', 56 + u * 56, + ( v == DES_DECRYPT ) ? "dec" : "enc" ); memcpy( iv, des3_test_iv, 8 ); memcpy( prv, des3_test_iv, 8 ); @@ -984,18 +990,18 @@ int des_self_test( int verbose ) memcmp( buf, des3_test_cbc_enc[u], 8 ) != 0 ) ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); } #endif /* POLARSSL_CIPHER_MODE_CBC */ if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); return( 0 ); } diff --git a/library/dhm.c b/library/dhm.c index e8aa8191c..9d00d9bbc 100644 --- a/library/dhm.c +++ b/library/dhm.c @@ -1,7 +1,7 @@ /* * Diffie-Hellman-Merkle key exchange * - * 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 @@ -42,10 +42,11 @@ #include "polarssl/asn1.h" #endif -#if defined(POLARSSL_MEMORY_C) -#include "polarssl/memory.h" +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" #else #include +#define polarssl_printf printf #define polarssl_malloc malloc #define polarssl_free free #endif @@ -548,19 +549,19 @@ int dhm_self_test( int verbose ) dhm_context dhm; if( verbose != 0 ) - printf( " DHM parameter load: " ); + polarssl_printf( " DHM parameter load: " ); if( ( ret = dhm_parse_dhm( &dhm, (const unsigned char *) test_dhm_params, strlen( test_dhm_params ) ) ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( ret ); } if( verbose != 0 ) - printf( "passed\n\n" ); + polarssl_printf( "passed\n\n" ); dhm_free( &dhm ); diff --git a/library/ecp.c b/library/ecp.c index ad6e5f586..2577fa745 100644 --- a/library/ecp.c +++ b/library/ecp.c @@ -1,7 +1,7 @@ /* * Elliptic curves over GF(p): generic functions * - * Copyright (C) 2006-2013, Brainspark B.V. + * Copyright (C) 2006-2014, Brainspark B.V. * * This file is part of PolarSSL (http://www.polarssl.org) * Lead Maintainer: Paul Bakker @@ -50,9 +50,10 @@ #include "polarssl/ecp.h" -#if defined(POLARSSL_MEMORY_C) -#include "polarssl/memory.h" +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" #else +#define polarssl_printf printf #define polarssl_malloc malloc #define polarssl_free free #endif @@ -1904,7 +1905,7 @@ int ecp_self_test( int verbose ) #endif if( verbose != 0 ) - printf( " ECP test #1 (constant op_count, base point G): " ); + polarssl_printf( " ECP test #1 (constant op_count, base point G): " ); /* Do a dummy multiplication first to trigger precomputation */ MPI_CHK( mpi_lset( &m, 2 ) ); @@ -1933,7 +1934,7 @@ int ecp_self_test( int verbose ) mul_count != mul_c_prev ) { if( verbose != 0 ) - printf( "failed (%u)\n", (unsigned int) i ); + polarssl_printf( "failed (%u)\n", (unsigned int) i ); ret = 1; goto cleanup; @@ -1941,10 +1942,10 @@ int ecp_self_test( int verbose ) } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); if( verbose != 0 ) - printf( " ECP test #2 (constant op_count, other point): " ); + polarssl_printf( " ECP test #2 (constant op_count, other point): " ); /* We computed P = 2G last time, use it */ add_count = 0; @@ -1970,7 +1971,7 @@ int ecp_self_test( int verbose ) mul_count != mul_c_prev ) { if( verbose != 0 ) - printf( "failed (%u)\n", (unsigned int) i ); + polarssl_printf( "failed (%u)\n", (unsigned int) i ); ret = 1; goto cleanup; @@ -1978,12 +1979,12 @@ int ecp_self_test( int verbose ) } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); cleanup: if( ret < 0 && verbose != 0 ) - printf( "Unexpected error, return code = %08X\n", ret ); + polarssl_printf( "Unexpected error, return code = %08X\n", ret ); ecp_group_free( &grp ); ecp_point_free( &R ); @@ -1991,7 +1992,7 @@ cleanup: mpi_free( &m ); if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); return( ret ); } diff --git a/library/gcm.c b/library/gcm.c index 3e1bc77d6..1c6cf9f93 100644 --- a/library/gcm.c +++ b/library/gcm.c @@ -1,7 +1,7 @@ /* * NIST SP800-38D compliant GCM implementation * - * Copyright (C) 2006-2013, Brainspark B.V. + * Copyright (C) 2006-2014, Brainspark B.V. * * This file is part of PolarSSL (http://www.polarssl.org) * Lead Maintainer: Paul Bakker @@ -43,6 +43,12 @@ #include "polarssl/aesni.h" #endif +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" +#else +#define polarssl_printf printf +#endif + /* * 32-bit integer manipulation macros (big endian) */ @@ -716,7 +722,8 @@ int gcm_self_test( int verbose ) for( i = 0; i < MAX_TESTS; i++ ) { if( verbose != 0 ) - printf( " AES-GCM-%3d #%d (%s): ", key_len, i, "enc" ); + polarssl_printf( " AES-GCM-%3d #%d (%s): ", + key_len, i, "enc" ); gcm_init( &ctx, cipher, key[key_index[i]], key_len ); @@ -731,7 +738,7 @@ int gcm_self_test( int verbose ) memcmp( tag_buf, tag[j * 6 + i], 16 ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } @@ -739,10 +746,11 @@ int gcm_self_test( int verbose ) gcm_free( &ctx ); if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); if( verbose != 0 ) - printf( " AES-GCM-%3d #%d (%s): ", key_len, i, "dec" ); + polarssl_printf( " AES-GCM-%3d #%d (%s): ", + key_len, i, "dec" ); gcm_init( &ctx, cipher, key[key_index[i]], key_len ); @@ -757,7 +765,7 @@ int gcm_self_test( int verbose ) memcmp( tag_buf, tag[j * 6 + i], 16 ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } @@ -765,10 +773,11 @@ int gcm_self_test( int verbose ) gcm_free( &ctx ); if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); if( verbose != 0 ) - printf( " AES-GCM-%3d #%d split (%s): ", key_len, i, "enc" ); + polarssl_printf( " AES-GCM-%3d #%d split (%s): ", + key_len, i, "enc" ); gcm_init( &ctx, cipher, key[key_index[i]], key_len ); @@ -778,7 +787,7 @@ int gcm_self_test( int verbose ) if( ret != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } @@ -790,7 +799,7 @@ int gcm_self_test( int verbose ) if( ret != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } @@ -799,7 +808,7 @@ int gcm_self_test( int verbose ) if( ret != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } @@ -810,7 +819,7 @@ int gcm_self_test( int verbose ) if( ret != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } @@ -822,7 +831,7 @@ int gcm_self_test( int verbose ) memcmp( tag_buf, tag[j * 6 + i], 16 ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } @@ -830,10 +839,11 @@ int gcm_self_test( int verbose ) gcm_free( &ctx ); if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); if( verbose != 0 ) - printf( " AES-GCM-%3d #%d split (%s): ", key_len, i, "dec" ); + polarssl_printf( " AES-GCM-%3d #%d split (%s): ", + key_len, i, "dec" ); gcm_init( &ctx, cipher, key[key_index[i]], key_len ); @@ -843,7 +853,7 @@ int gcm_self_test( int verbose ) if( ret != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } @@ -855,7 +865,7 @@ int gcm_self_test( int verbose ) if( ret != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } @@ -864,7 +874,7 @@ int gcm_self_test( int verbose ) if( ret != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } @@ -875,7 +885,7 @@ int gcm_self_test( int verbose ) if( ret != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } @@ -887,7 +897,7 @@ int gcm_self_test( int verbose ) memcmp( tag_buf, tag[j * 6 + i], 16 ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } @@ -895,13 +905,13 @@ int gcm_self_test( int verbose ) gcm_free( &ctx ); if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); } } if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); return( 0 ); } diff --git a/library/hmac_drbg.c b/library/hmac_drbg.c index 33a20ef9c..7a210925e 100644 --- a/library/hmac_drbg.c +++ b/library/hmac_drbg.c @@ -39,6 +39,12 @@ #include #endif +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" +#else +#define polarssl_printf printf +#endif + /* * HMAC_DRBG update, using optional additional data (10.1.2.2) */ @@ -368,7 +374,7 @@ int hmac_drbg_self_test( int verbose ) { if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); return( 0 ); } @@ -418,11 +424,11 @@ static int hmac_drbg_self_test_entropy( void *data, return( 0 ); } -#define CHK( c ) if( (c) != 0 ) \ - { \ - if( verbose != 0 ) \ - printf( "failed\n" ); \ - return( 1 ); \ +#define CHK( c ) if( (c) != 0 ) \ + { \ + if( verbose != 0 ) \ + polarssl_printf( "failed\n" ); \ + return( 1 ); \ } /* @@ -438,7 +444,7 @@ int hmac_drbg_self_test( int verbose ) * PR = True */ if( verbose != 0 ) - printf( " HMAC_DRBG (PR = True) : " ); + polarssl_printf( " HMAC_DRBG (PR = True) : " ); test_offset = 0; CHK( hmac_drbg_init( &ctx, md_info, @@ -451,13 +457,13 @@ int hmac_drbg_self_test( int verbose ) hmac_drbg_free( &ctx ); if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); /* * PR = False */ if( verbose != 0 ) - printf( " HMAC_DRBG (PR = False) : " ); + polarssl_printf( " HMAC_DRBG (PR = False) : " ); test_offset = 0; CHK( hmac_drbg_init( &ctx, md_info, @@ -470,10 +476,10 @@ int hmac_drbg_self_test( int verbose ) hmac_drbg_free( &ctx ); if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); return( 0 ); } diff --git a/library/md2.c b/library/md2.c index 93e77d2f6..f29877f90 100644 --- a/library/md2.c +++ b/library/md2.c @@ -1,7 +1,7 @@ /* * RFC 1115/1319 compliant MD2 implementation * - * Copyright (C) 2006-2013, Brainspark B.V. + * Copyright (C) 2006-2014, Brainspark B.V. * * This file is part of PolarSSL (http://www.polarssl.org) * Lead Maintainer: Paul Bakker @@ -39,6 +39,12 @@ #include #endif +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" +#else +#define polarssl_printf printf +#endif + #if !defined(POLARSSL_MD2_ALT) static const unsigned char PI_SUBST[256] = @@ -340,7 +346,7 @@ int md2_self_test( int verbose ) for( i = 0; i < 7; i++ ) { if( verbose != 0 ) - printf( " MD2 test #%d: ", i + 1 ); + polarssl_printf( " MD2 test #%d: ", i + 1 ); md2( (unsigned char *) md2_test_str[i], strlen( md2_test_str[i] ), md2sum ); @@ -348,17 +354,17 @@ int md2_self_test( int verbose ) if( memcmp( md2sum, md2_test_sum[i], 16 ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); } if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); return( 0 ); } diff --git a/library/md4.c b/library/md4.c index e14c83dc2..8ac6c0181 100644 --- a/library/md4.c +++ b/library/md4.c @@ -1,7 +1,7 @@ /* * RFC 1186/1320 compliant MD4 implementation * - * Copyright (C) 2006-2013, Brainspark B.V. + * Copyright (C) 2006-2014, Brainspark B.V. * * This file is part of PolarSSL (http://www.polarssl.org) * Lead Maintainer: Paul Bakker @@ -39,6 +39,12 @@ #include #endif +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" +#else +#define polarssl_printf printf +#endif + #if !defined(POLARSSL_MD4_ALT) /* @@ -436,7 +442,7 @@ int md4_self_test( int verbose ) for( i = 0; i < 7; i++ ) { if( verbose != 0 ) - printf( " MD4 test #%d: ", i + 1 ); + polarssl_printf( " MD4 test #%d: ", i + 1 ); md4( (unsigned char *) md4_test_str[i], strlen( md4_test_str[i] ), md4sum ); @@ -444,17 +450,17 @@ int md4_self_test( int verbose ) if( memcmp( md4sum, md4_test_sum[i], 16 ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); } if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); return( 0 ); } diff --git a/library/md5.c b/library/md5.c index b28461e9b..c596e43b2 100644 --- a/library/md5.c +++ b/library/md5.c @@ -1,7 +1,7 @@ /* * RFC 1321 compliant MD5 implementation * - * Copyright (C) 2006-2013, Brainspark B.V. + * Copyright (C) 2006-2014, Brainspark B.V. * * This file is part of PolarSSL (http://www.polarssl.org) * Lead Maintainer: Paul Bakker @@ -38,6 +38,12 @@ #include #endif +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" +#else +#define polarssl_printf printf +#endif + #if !defined(POLARSSL_MD5_ALT) /* @@ -522,29 +528,29 @@ int md5_self_test( int verbose ) for( i = 0; i < 7; i++ ) { if( verbose != 0 ) - printf( " MD5 test #%d: ", i + 1 ); + polarssl_printf( " MD5 test #%d: ", i + 1 ); md5( md5_test_buf[i], md5_test_buflen[i], md5sum ); if( memcmp( md5sum, md5_test_sum[i], 16 ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); } if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); for( i = 0; i < 7; i++ ) { if( verbose != 0 ) - printf( " HMAC-MD5 test #%d: ", i + 1 ); + polarssl_printf( " HMAC-MD5 test #%d: ", i + 1 ); if( i == 5 || i == 6 ) { @@ -565,17 +571,17 @@ int md5_self_test( int verbose ) if( memcmp( md5sum, md5_hmac_test_sum[i], buflen ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); } if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); return( 0 ); } diff --git a/library/md_wrap.c b/library/md_wrap.c index bca5ab2b6..a6c1bacbb 100644 --- a/library/md_wrap.c +++ b/library/md_wrap.c @@ -5,7 +5,7 @@ * * \author Adriaan de Jong * - * 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 @@ -61,8 +61,8 @@ #include "polarssl/sha512.h" #endif -#if defined(POLARSSL_MEMORY_C) -#include "polarssl/memory.h" +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" #else #define polarssl_malloc malloc #define polarssl_free free diff --git a/library/memory_buffer_alloc.c b/library/memory_buffer_alloc.c index 1038c85a9..fef43312f 100644 --- a/library/memory_buffer_alloc.c +++ b/library/memory_buffer_alloc.c @@ -1,7 +1,7 @@ /* * Buffer-based memory allocator * - * 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 @@ -42,6 +42,12 @@ #include "polarssl/threading.h" #endif +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" +#else +#define polarssl_fprintf fprintf +#endif + #define MAGIC1 0xFF00AA55 #define MAGIC2 0xEE119966 #define MAX_BT 20 @@ -94,17 +100,18 @@ static void debug_header( memory_header *hdr ) size_t i; #endif - fprintf( stderr, "HDR: PTR(%10u), PREV(%10u), NEXT(%10u), ALLOC(%u), SIZE(%10u)\n", - (size_t) hdr, (size_t) hdr->prev, (size_t) hdr->next, - hdr->alloc, hdr->size ); - fprintf( stderr, " FPREV(%10u), FNEXT(%10u)\n", - (size_t) hdr->prev_free, (size_t) hdr->next_free ); + polarssl_fprintf( stderr, "HDR: PTR(%10u), PREV(%10u), NEXT(%10u), " + "ALLOC(%u), SIZE(%10u)\n", + (size_t) hdr, (size_t) hdr->prev, (size_t) hdr->next, + hdr->alloc, hdr->size ); + polarssl_fprintf( stderr, " FPREV(%10u), FNEXT(%10u)\n", + (size_t) hdr->prev_free, (size_t) hdr->next_free ); #if defined(POLARSSL_MEMORY_BACKTRACE) - fprintf( stderr, "TRACE: \n" ); + polarssl_fprintf( stderr, "TRACE: \n" ); for( i = 0; i < hdr->trace_count; i++ ) - fprintf( stderr, "%s\n", hdr->trace[i] ); - fprintf( stderr, "\n" ); + polarssl_fprintf( stderr, "%s\n", hdr->trace[i] ); + polarssl_fprintf( stderr, "\n" ); #endif } @@ -112,14 +119,14 @@ static void debug_chain() { memory_header *cur = heap.first; - fprintf( stderr, "\nBlock list\n" ); + polarssl_fprintf( stderr, "\nBlock list\n" ); while( cur != NULL ) { debug_header( cur ); cur = cur->next; } - fprintf( stderr, "Free list\n" ); + polarssl_fprintf( stderr, "Free list\n" ); cur = heap.first_free; while( cur != NULL ) @@ -135,7 +142,7 @@ static int verify_header( memory_header *hdr ) if( hdr->magic1 != MAGIC1 ) { #if defined(POLARSSL_MEMORY_DEBUG) - fprintf( stderr, "FATAL: MAGIC1 mismatch\n" ); + polarssl_fprintf( stderr, "FATAL: MAGIC1 mismatch\n" ); #endif return( 1 ); } @@ -143,7 +150,7 @@ static int verify_header( memory_header *hdr ) if( hdr->magic2 != MAGIC2 ) { #if defined(POLARSSL_MEMORY_DEBUG) - fprintf( stderr, "FATAL: MAGIC2 mismatch\n" ); + polarssl_fprintf( stderr, "FATAL: MAGIC2 mismatch\n" ); #endif return( 1 ); } @@ -151,7 +158,7 @@ static int verify_header( memory_header *hdr ) if( hdr->alloc > 1 ) { #if defined(POLARSSL_MEMORY_DEBUG) - fprintf( stderr, "FATAL: alloc has illegal value\n" ); + polarssl_fprintf( stderr, "FATAL: alloc has illegal value\n" ); #endif return( 1 ); } @@ -159,7 +166,7 @@ static int verify_header( memory_header *hdr ) if( hdr->prev != NULL && hdr->prev == hdr->next ) { #if defined(POLARSSL_MEMORY_DEBUG) - fprintf( stderr, "FATAL: prev == next\n" ); + polarssl_fprintf( stderr, "FATAL: prev == next\n" ); #endif return( 1 ); } @@ -167,7 +174,7 @@ static int verify_header( memory_header *hdr ) if( hdr->prev_free != NULL && hdr->prev_free == hdr->next_free ) { #if defined(POLARSSL_MEMORY_DEBUG) - fprintf( stderr, "FATAL: prev_free == next_free\n" ); + polarssl_fprintf( stderr, "FATAL: prev_free == next_free\n" ); #endif return( 1 ); } @@ -182,7 +189,8 @@ static int verify_chain() if( verify_header( heap.first ) != 0 ) { #if defined(POLARSSL_MEMORY_DEBUG) - fprintf( stderr, "FATAL: verification of first header failed\n" ); + polarssl_fprintf( stderr, "FATAL: verification of first header " + "failed\n" ); #endif return( 1 ); } @@ -190,7 +198,8 @@ static int verify_chain() if( heap.first->prev != NULL ) { #if defined(POLARSSL_MEMORY_DEBUG) - fprintf( stderr, "FATAL: verification failed: first->prev != NULL\n" ); + polarssl_fprintf( stderr, "FATAL: verification failed: " + "first->prev != NULL\n" ); #endif return( 1 ); } @@ -200,7 +209,8 @@ static int verify_chain() if( verify_header( cur ) != 0 ) { #if defined(POLARSSL_MEMORY_DEBUG) - fprintf( stderr, "FATAL: verification of header failed\n" ); + polarssl_fprintf( stderr, "FATAL: verification of header " + "failed\n" ); #endif return( 1 ); } @@ -208,7 +218,8 @@ static int verify_chain() if( cur->prev != prv ) { #if defined(POLARSSL_MEMORY_DEBUG) - fprintf( stderr, "FATAL: verification failed: cur->prev != prv\n" ); + polarssl_fprintf( stderr, "FATAL: verification failed: " + "cur->prev != prv\n" ); #endif return( 1 ); } @@ -254,7 +265,8 @@ static void *buffer_alloc_malloc( size_t len ) if( cur->alloc != 0 ) { #if defined(POLARSSL_MEMORY_DEBUG) - fprintf( stderr, "FATAL: block in free_list but allocated data\n" ); + polarssl_fprintf( stderr, "FATAL: block in free_list but allocated " + "data\n" ); #endif exit( 1 ); } @@ -365,7 +377,8 @@ static void buffer_alloc_free( void *ptr ) if( p < heap.buf || p > heap.buf + heap.len ) { #if defined(POLARSSL_MEMORY_DEBUG) - fprintf( stderr, "FATAL: polarssl_free() outside of managed space\n" ); + polarssl_fprintf( stderr, "FATAL: polarssl_free() outside of managed " + "space\n" ); #endif exit( 1 ); } @@ -379,7 +392,8 @@ static void buffer_alloc_free( void *ptr ) if( hdr->alloc != 1 ) { #if defined(POLARSSL_MEMORY_DEBUG) - fprintf( stderr, "FATAL: polarssl_free() on unallocated data\n" ); + polarssl_fprintf( stderr, "FATAL: polarssl_free() on unallocated " + "data\n" ); #endif exit( 1 ); } @@ -486,19 +500,20 @@ int memory_buffer_alloc_verify() #if defined(POLARSSL_MEMORY_DEBUG) void memory_buffer_alloc_status() { - fprintf( stderr, - "Current use: %u blocks / %u bytes, max: %u blocks / %u bytes (total %u bytes), malloc / free: %u / %u\n", - heap.header_count, heap.total_used, - heap.maximum_header_count, heap.maximum_used, - heap.maximum_header_count * sizeof( memory_header ) - + heap.maximum_used, - heap.malloc_count, heap.free_count ); + polarssl_fprintf( stderr, + "Current use: %u blocks / %u bytes, max: %u blocks / " + "%u bytes (total %u bytes), malloc / free: %u / %u\n", + heap.header_count, heap.total_used, + heap.maximum_header_count, heap.maximum_used, + heap.maximum_header_count * sizeof( memory_header ) + + heap.maximum_used, + heap.malloc_count, heap.free_count ); if( heap.first->next == NULL ) - fprintf( stderr, "All memory de-allocated in stack buffer\n" ); + polarssl_fprintf( stderr, "All memory de-allocated in stack buffer\n" ); else { - fprintf( stderr, "Memory currently allocated:\n" ); + polarssl_fprintf( stderr, "Memory currently allocated:\n" ); debug_chain(); } } diff --git a/library/pem.c b/library/pem.c index d602d8aa2..2c9d10d25 100644 --- a/library/pem.c +++ b/library/pem.c @@ -1,7 +1,7 @@ /* * Privacy Enhanced Mail (PEM) decoding * - * 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 @@ -33,8 +33,8 @@ #include "polarssl/md5.h" #include "polarssl/cipher.h" -#if defined(POLARSSL_MEMORY_C) -#include "polarssl/memory.h" +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" #else #define polarssl_malloc malloc #define polarssl_free free diff --git a/library/pk_wrap.c b/library/pk_wrap.c index 3f05edd97..99535d613 100644 --- a/library/pk_wrap.c +++ b/library/pk_wrap.c @@ -1,7 +1,7 @@ /* * Public Key abstraction layer: wrapper functions * - * Copyright (C) 2006-2013, Brainspark B.V. + * Copyright (C) 2006-2014, Brainspark B.V. * * This file is part of PolarSSL (http://www.polarssl.org) * Lead Maintainer: Paul Bakker @@ -40,8 +40,8 @@ #include "polarssl/ecdsa.h" #endif -#if defined(POLARSSL_MEMORY_C) -#include "polarssl/memory.h" +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" #else #include #define polarssl_malloc malloc diff --git a/library/pkcs11.c b/library/pkcs11.c index 8a99f2871..d758460e3 100644 --- a/library/pkcs11.c +++ b/library/pkcs11.c @@ -5,7 +5,7 @@ * * \author Adriaan de Jong * - * 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 @@ -34,15 +34,14 @@ #include "polarssl/oid.h" #include "polarssl/x509_crt.h" -#if defined(POLARSSL_MEMORY_C) -#include "polarssl/memory.h" +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" #else +#include #define polarssl_malloc malloc #define polarssl_free free #endif -#include - int pkcs11_x509_cert_init( x509_crt *cert, pkcs11h_certificate_t pkcs11_cert ) { int ret = 1; diff --git a/library/pkcs5.c b/library/pkcs5.c index 39aa5b96e..c4cdf0354 100644 --- a/library/pkcs5.c +++ b/library/pkcs5.c @@ -5,7 +5,7 @@ * * \author Mathias Olsson * - * 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 @@ -42,6 +42,12 @@ #include "polarssl/cipher.h" #include "polarssl/oid.h" +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" +#else +#define polarssl_printf printf +#endif + static int pkcs5_parse_pbkdf2_params( asn1_buf *params, asn1_buf *salt, int *iterations, int *keylen, md_type_t *md_type ) @@ -357,7 +363,7 @@ int pkcs5_self_test( int verbose ) for( i = 0; i < MAX_TESTS; i++ ) { - printf( " PBKDF2 (SHA1) #%d: ", i ); + polarssl_printf( " PBKDF2 (SHA1) #%d: ", i ); ret = pkcs5_pbkdf2_hmac( &sha1_ctx, password[i], plen[i], salt[i], slen[i], it_cnt[i], key_len[i], key ); @@ -365,16 +371,16 @@ int pkcs5_self_test( int verbose ) memcmp( result_key[i], key, key_len[i] ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); } - printf( "\n" ); + polarssl_printf( "\n" ); if( ( ret = md_free_ctx( &sha1_ctx ) ) != 0 ) return( 1 ); diff --git a/library/pkparse.c b/library/pkparse.c index a5de20b9f..dcb0f3f91 100644 --- a/library/pkparse.c +++ b/library/pkparse.c @@ -50,8 +50,8 @@ #include "polarssl/pkcs12.h" #endif -#if defined(POLARSSL_MEMORY_C) -#include "polarssl/memory.h" +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" #else #include #define polarssl_malloc malloc diff --git a/library/pkwrite.c b/library/pkwrite.c index 8b6d7356e..4cbba10b7 100644 --- a/library/pkwrite.c +++ b/library/pkwrite.c @@ -1,7 +1,7 @@ /* * Public Key layer for writing key files and structures * - * Copyright (C) 2006-2013, Brainspark B.V. + * Copyright (C) 2006-2014, Brainspark B.V. * * This file is part of PolarSSL (http://www.polarssl.org) * Lead Maintainer: Paul Bakker @@ -44,8 +44,8 @@ #include "polarssl/pem.h" #endif -#if defined(POLARSSL_MEMORY_C) -#include "polarssl/memory.h" +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" #else #include #define polarssl_malloc malloc diff --git a/library/ripemd160.c b/library/ripemd160.c index 569cbdec8..10e60df84 100644 --- a/library/ripemd160.c +++ b/library/ripemd160.c @@ -43,6 +43,12 @@ #include #endif +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" +#else +#define polarssl_printf printf +#endif + /* * 32-bit integer manipulation macros (little endian) */ @@ -573,7 +579,7 @@ int ripemd160_self_test( int verbose ) for( i = 0; i < TESTS; i++ ) { if( verbose != 0 ) - printf( " RIPEMD-160 test #%d: ", i + 1 ); + polarssl_printf( " RIPEMD-160 test #%d: ", i + 1 ); ripemd160( (const unsigned char *) ripemd160_test_input[i], strlen( ripemd160_test_input[i] ), @@ -582,18 +588,19 @@ int ripemd160_self_test( int verbose ) if( memcmp( output, ripemd160_test_md[i], 20 ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); for( j = 0; j < KEYS; j++ ) { if( verbose != 0 ) - printf( " HMAC-RIPEMD-160 test #%d, key #%d: ", i + 1, j + 1 ); + polarssl_printf( " HMAC-RIPEMD-160 test #%d, key #%d: ", + i + 1, j + 1 ); ripemd160_hmac( ripemd160_test_key[j], 20, (const unsigned char *) ripemd160_test_input[i], @@ -603,17 +610,17 @@ int ripemd160_self_test( int verbose ) if( memcmp( output, ripemd160_test_hmac[j][i], 20 ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); } if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); } return( 0 ); diff --git a/library/rsa.c b/library/rsa.c index f4ff2373c..3a1ea355c 100644 --- a/library/rsa.c +++ b/library/rsa.c @@ -1,7 +1,7 @@ /* * The RSA public-key cryptosystem * - * Copyright (C) 2006-2011, Brainspark B.V. + * Copyright (C) 2006-2014, Brainspark B.V. * * This file is part of PolarSSL (http://www.polarssl.org) * Lead Maintainer: Paul Bakker @@ -43,6 +43,12 @@ #include #include +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" +#else +#define polarssl_printf printf +#endif + /* * Initialize an RSA context */ @@ -1495,19 +1501,19 @@ int rsa_self_test( int verbose ) mpi_read_string( &rsa.QP, 16, RSA_QP ); if( verbose != 0 ) - printf( " RSA key validation: " ); + polarssl_printf( " RSA key validation: " ); if( rsa_check_pubkey( &rsa ) != 0 || rsa_check_privkey( &rsa ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } if( verbose != 0 ) - printf( "passed\n PKCS#1 encryption : " ); + polarssl_printf( "passed\n PKCS#1 encryption : " ); memcpy( rsa_plaintext, RSA_PT, PT_LEN ); @@ -1515,20 +1521,20 @@ int rsa_self_test( int verbose ) rsa_plaintext, rsa_ciphertext ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } if( verbose != 0 ) - printf( "passed\n PKCS#1 decryption : " ); + polarssl_printf( "passed\n PKCS#1 decryption : " ); if( rsa_pkcs1_decrypt( &rsa, myrand, NULL, RSA_PRIVATE, &len, rsa_ciphertext, rsa_decrypted, sizeof(rsa_decrypted) ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } @@ -1536,14 +1542,14 @@ int rsa_self_test( int verbose ) if( memcmp( rsa_decrypted, rsa_plaintext, len ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } #if defined(POLARSSL_SHA1_C) if( verbose != 0 ) - printf( "passed\n PKCS#1 data sign : " ); + polarssl_printf( "passed\n PKCS#1 data sign : " ); sha1( rsa_plaintext, PT_LEN, sha1sum ); @@ -1551,25 +1557,25 @@ int rsa_self_test( int verbose ) sha1sum, rsa_ciphertext ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } if( verbose != 0 ) - printf( "passed\n PKCS#1 sig. verify: " ); + polarssl_printf( "passed\n PKCS#1 sig. verify: " ); if( rsa_pkcs1_verify( &rsa, NULL, NULL, RSA_PUBLIC, POLARSSL_MD_SHA1, 0, sha1sum, rsa_ciphertext ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } if( verbose != 0 ) - printf( "passed\n\n" ); + polarssl_printf( "passed\n\n" ); #endif /* POLARSSL_SHA1_C */ rsa_free( &rsa ); diff --git a/library/sha1.c b/library/sha1.c index b301b0979..f02d6e6ef 100644 --- a/library/sha1.c +++ b/library/sha1.c @@ -1,7 +1,7 @@ /* * FIPS-180-1 compliant SHA-1 implementation * - * Copyright (C) 2006-2013, Brainspark B.V. + * Copyright (C) 2006-2014, Brainspark B.V. * * This file is part of PolarSSL (http://www.polarssl.org) * Lead Maintainer: Paul Bakker @@ -38,6 +38,12 @@ #include #endif +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" +#else +#define polarssl_printf printf +#endif + #if !defined(POLARSSL_SHA1_ALT) /* @@ -548,7 +554,7 @@ int sha1_self_test( int verbose ) for( i = 0; i < 3; i++ ) { if( verbose != 0 ) - printf( " SHA-1 test #%d: ", i + 1 ); + polarssl_printf( " SHA-1 test #%d: ", i + 1 ); sha1_starts( &ctx ); @@ -568,22 +574,22 @@ int sha1_self_test( int verbose ) if( memcmp( sha1sum, sha1_test_sum[i], 20 ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); } if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); for( i = 0; i < 7; i++ ) { if( verbose != 0 ) - printf( " HMAC-SHA-1 test #%d: ", i + 1 ); + polarssl_printf( " HMAC-SHA-1 test #%d: ", i + 1 ); if( i == 5 || i == 6 ) { @@ -604,17 +610,17 @@ int sha1_self_test( int verbose ) if( memcmp( sha1sum, sha1_hmac_test_sum[i], buflen ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); } if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); return( 0 ); } diff --git a/library/sha256.c b/library/sha256.c index e4d48427d..638188f53 100644 --- a/library/sha256.c +++ b/library/sha256.c @@ -1,7 +1,7 @@ /* * FIPS-180-2 compliant SHA-256 implementation * - * Copyright (C) 2006-2013, Brainspark B.V. + * Copyright (C) 2006-2014, Brainspark B.V. * * This file is part of PolarSSL (http://www.polarssl.org) * Lead Maintainer: Paul Bakker @@ -38,6 +38,12 @@ #include #endif +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" +#else +#define polarssl_printf printf +#endif + #if !defined(POLARSSL_SHA256_ALT) /* @@ -626,7 +632,7 @@ int sha256_self_test( int verbose ) k = i < 3; if( verbose != 0 ) - printf( " SHA-%d test #%d: ", 256 - k * 32, j + 1 ); + polarssl_printf( " SHA-%d test #%d: ", 256 - k * 32, j + 1 ); sha256_starts( &ctx, k ); @@ -646,17 +652,17 @@ int sha256_self_test( int verbose ) if( memcmp( sha256sum, sha256_test_sum[i], 32 - k * 4 ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); } if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); for( i = 0; i < 14; i++ ) { @@ -664,7 +670,7 @@ int sha256_self_test( int verbose ) k = i < 7; if( verbose != 0 ) - printf( " HMAC-SHA-%d test #%d: ", 256 - k * 32, j + 1 ); + polarssl_printf( " HMAC-SHA-%d test #%d: ", 256 - k * 32, j + 1 ); if( j == 5 || j == 6 ) { @@ -685,17 +691,17 @@ int sha256_self_test( int verbose ) if( memcmp( sha256sum, sha256_hmac_test_sum[i], buflen ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); } if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); return( 0 ); } diff --git a/library/sha512.c b/library/sha512.c index 2366e7c2c..1bef2e90c 100644 --- a/library/sha512.c +++ b/library/sha512.c @@ -1,7 +1,7 @@ /* * FIPS-180-2 compliant SHA-384/512 implementation * - * Copyright (C) 2006-2013, Brainspark B.V. + * Copyright (C) 2006-2014, Brainspark B.V. * * This file is part of PolarSSL (http://www.polarssl.org) * Lead Maintainer: Paul Bakker @@ -38,6 +38,12 @@ #include #endif +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" +#else +#define polarssl_printf printf +#endif + #if !defined(POLARSSL_SHA512_ALT) /* @@ -681,7 +687,7 @@ int sha512_self_test( int verbose ) k = i < 3; if( verbose != 0 ) - printf( " SHA-%d test #%d: ", 512 - k * 128, j + 1 ); + polarssl_printf( " SHA-%d test #%d: ", 512 - k * 128, j + 1 ); sha512_starts( &ctx, k ); @@ -701,17 +707,17 @@ int sha512_self_test( int verbose ) if( memcmp( sha512sum, sha512_test_sum[i], 64 - k * 16 ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); } if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); for( i = 0; i < 14; i++ ) { @@ -719,7 +725,7 @@ int sha512_self_test( int verbose ) k = i < 7; if( verbose != 0 ) - printf( " HMAC-SHA-%d test #%d: ", 512 - k * 128, j + 1 ); + polarssl_printf( " HMAC-SHA-%d test #%d: ", 512 - k * 128, j + 1 ); if( j == 5 || j == 6 ) { @@ -740,17 +746,17 @@ int sha512_self_test( int verbose ) if( memcmp( sha512sum, sha512_hmac_test_sum[i], buflen ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); } if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); return( 0 ); } diff --git a/library/ssl_cache.c b/library/ssl_cache.c index e0847b6dc..6fff54b32 100644 --- a/library/ssl_cache.c +++ b/library/ssl_cache.c @@ -1,7 +1,7 @@ /* * SSL session cache implementation * - * 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 @@ -33,8 +33,8 @@ #include "polarssl/ssl_cache.h" -#if defined(POLARSSL_MEMORY_C) -#include "polarssl/memory.h" +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" #else #define polarssl_malloc malloc #define polarssl_free free diff --git a/library/ssl_cli.c b/library/ssl_cli.c index bdd2d9502..b4ab55043 100644 --- a/library/ssl_cli.c +++ b/library/ssl_cli.c @@ -1,7 +1,7 @@ /* * SSLv3/TLSv1 client-side functions * - * Copyright (C) 2006-2013, Brainspark B.V. + * Copyright (C) 2006-2014, Brainspark B.V. * * This file is part of PolarSSL (http://www.polarssl.org) * Lead Maintainer: Paul Bakker @@ -30,8 +30,8 @@ #include "polarssl/debug.h" #include "polarssl/ssl.h" -#if defined(POLARSSL_MEMORY_C) -#include "polarssl/memory.h" +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" #else #define polarssl_malloc malloc #define polarssl_free free diff --git a/library/ssl_srv.c b/library/ssl_srv.c index e045fdc98..f484cf6a4 100644 --- a/library/ssl_srv.c +++ b/library/ssl_srv.c @@ -1,7 +1,7 @@ /* * SSLv3/TLSv1 server-side functions * - * Copyright (C) 2006-2013, Brainspark B.V. + * Copyright (C) 2006-2014, Brainspark B.V. * * This file is part of PolarSSL (http://www.polarssl.org) * Lead Maintainer: Paul Bakker @@ -33,8 +33,8 @@ #include "polarssl/ecp.h" #endif -#if defined(POLARSSL_MEMORY_C) -#include "polarssl/memory.h" +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" #else #define polarssl_malloc malloc #define polarssl_free free diff --git a/library/ssl_tls.c b/library/ssl_tls.c index a5205836c..4a9211f13 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -1,7 +1,7 @@ /* * SSLv3/TLSv1 shared functions * - * Copyright (C) 2006-2013, Brainspark B.V. + * Copyright (C) 2006-2014, Brainspark B.V. * * This file is part of PolarSSL (http://www.polarssl.org) * Lead Maintainer: Paul Bakker @@ -38,8 +38,8 @@ #include "polarssl/debug.h" #include "polarssl/ssl.h" -#if defined(POLARSSL_MEMORY_C) -#include "polarssl/memory.h" +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" #else #define polarssl_malloc malloc #define polarssl_free free diff --git a/library/x509.c b/library/x509.c index 74a8f8e0d..17e8b4d5e 100644 --- a/library/x509.c +++ b/library/x509.c @@ -1,7 +1,7 @@ /* * X.509 certificate and private key decoding * - * 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 @@ -45,9 +45,10 @@ #include "polarssl/pem.h" #endif -#if defined(POLARSSL_MEMORY_C) -#include "polarssl/memory.h" +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" #else +#define polarssl_printf printf #define polarssl_malloc malloc #define polarssl_free free #endif @@ -991,7 +992,7 @@ int x509_self_test( int verbose ) x509_crt clicert; if( verbose != 0 ) - printf( " X.509 certificate load: " ); + polarssl_printf( " X.509 certificate load: " ); x509_crt_init( &clicert ); @@ -1000,7 +1001,7 @@ int x509_self_test( int verbose ) if( ret != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( ret ); } @@ -1012,27 +1013,27 @@ int x509_self_test( int verbose ) if( ret != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( ret ); } if( verbose != 0 ) - printf( "passed\n X.509 signature verify: "); + polarssl_printf( "passed\n X.509 signature verify: "); ret = x509_crt_verify( &clicert, &cacert, NULL, NULL, &flags, NULL, NULL ); if( ret != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); - printf("ret = %d, &flags = %04x\n", ret, flags); + polarssl_printf("ret = %d, &flags = %04x\n", ret, flags); return( ret ); } if( verbose != 0 ) - printf( "passed\n\n"); + polarssl_printf( "passed\n\n"); x509_crt_free( &cacert ); x509_crt_free( &clicert ); diff --git a/library/x509_crl.c b/library/x509_crl.c index 964aa7e83..92ede6d49 100644 --- a/library/x509_crl.c +++ b/library/x509_crl.c @@ -1,7 +1,7 @@ /* * X.509 certificate and private key decoding * - * 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 @@ -44,8 +44,8 @@ #include "polarssl/pem.h" #endif -#if defined(POLARSSL_MEMORY_C) -#include "polarssl/memory.h" +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" #else #define polarssl_malloc malloc #define polarssl_free free diff --git a/library/x509_crt.c b/library/x509_crt.c index 585972542..4c79a7a6c 100644 --- a/library/x509_crt.c +++ b/library/x509_crt.c @@ -1,7 +1,7 @@ /* * X.509 certificate and private key decoding * - * 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 @@ -44,8 +44,8 @@ #include "polarssl/pem.h" #endif -#if defined(POLARSSL_MEMORY_C) -#include "polarssl/memory.h" +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" #else #define polarssl_malloc malloc #define polarssl_free free diff --git a/library/x509_csr.c b/library/x509_csr.c index a5cef4c30..bdadec3e3 100644 --- a/library/x509_csr.c +++ b/library/x509_csr.c @@ -1,7 +1,7 @@ /* * X.509 Certificate Signing Request (CSR) parsing * - * 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 @@ -44,8 +44,8 @@ #include "polarssl/pem.h" #endif -#if defined(POLARSSL_MEMORY_C) -#include "polarssl/memory.h" +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" #else #define polarssl_malloc malloc #define polarssl_free free diff --git a/library/xtea.c b/library/xtea.c index 2cb2f30d1..1bb6f29dd 100644 --- a/library/xtea.c +++ b/library/xtea.c @@ -29,6 +29,12 @@ #include "polarssl/xtea.h" +#if defined(POLARSSL_PLATFORM_C) +#include "polarssl/platform.h" +#else +#define polarssl_printf printf +#endif + #if !defined(POLARSSL_XTEA_ALT) /* @@ -220,7 +226,7 @@ int xtea_self_test( int verbose ) for( i = 0; i < 6; i++ ) { if( verbose != 0 ) - printf( " XTEA test #%d: ", i + 1 ); + polarssl_printf( " XTEA test #%d: ", i + 1 ); memcpy( buf, xtea_test_pt[i], 8 ); @@ -230,17 +236,17 @@ int xtea_self_test( int verbose ) if( memcmp( buf, xtea_test_ct[i], 8 ) != 0 ) { if( verbose != 0 ) - printf( "failed\n" ); + polarssl_printf( "failed\n" ); return( 1 ); } if( verbose != 0 ) - printf( "passed\n" ); + polarssl_printf( "passed\n" ); } if( verbose != 0 ) - printf( "\n" ); + polarssl_printf( "\n" ); return( 0 ); }