Merged platform compatibility layer
diff --git a/ChangeLog b/ChangeLog
index b46c847..06f1036 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,10 @@
* Option to set the Curve preference order
* Support for RSASSA-PSS keys and signatures in certificates, CSRs
and CRLs
+ * Single Platform compatilibity layer (for memory / printf / fprintf)
+
+Changes
+ * Deprecated the Memory layer
Bugfix
* ecp_gen_keypair() does more tries to prevent failure because of
diff --git a/include/polarssl/config.h b/include/polarssl/config.h
index dd172ce..cff5741 100644
--- a/include/polarssl/config.h
+++ b/include/polarssl/config.h
@@ -3,7 +3,7 @@
*
* \brief Configuration options (set of defines)
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2014, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -113,6 +113,42 @@
* Comment if your system does not support the IPv6 socket interface
*/
#define POLARSSL_HAVE_IPV6
+
+/**
+ * \def POLARSSL_PLATFORM_MEMORY
+ *
+ * Enable the memory allocation layer.
+ *
+ * By default PolarSSL uses the system-provided malloc() and free().
+ * This allows different allocators (self-implemented or provided) to be
+ * provided to the platform abstraction layer.
+ *
+ * Enabling POLARSSL_PLATFORM_MEMORY will provide "platform_set_malloc_free()"
+ * to allow you to set an alternative malloc() and free() function pointer.
+ *
+ * Requires: POLARSSL_PLATFORM_C
+ *
+ * Enable this layer to allow use of alternative memory allocators.
+ */
+//#define POLARSSL_PLATFORM_MEMORY
+
+/**
+ * \def POLARSSL_PLATFORM_XXX_ALT
+ *
+ * Uncomment a macro to let PolarSSL support the function in the platform
+ * abstraction layer.
+ *
+ * Example: In case you uncomment POLARSSL_PLATFORM_PRINTF_ALT, PolarSSL will
+ * provide a function "platform_set_printf()" that allows you to set an
+ * alternative printf function pointer.
+ *
+ * All these define require POLARSSL_PLATFORM_C to be defined!
+ *
+ * Uncomment a macro to enable alternate implementation of specific base
+ * platform function
+ */
+//#define POLARSSL_PLATFORM_PRINTF_ALT
+//#define POLARSSL_PLATFORM_FPRINTF_ALT
/* \} name SECTION: System support */
/**
@@ -624,7 +660,6 @@
* function for 'debug output' of allocated memory.
*
* Requires: POLARSSL_MEMORY_BUFFER_ALLOC_C
- * fprintf()
*
* Uncomment this macro to let the buffer allocator print out error messages.
*/
@@ -1408,15 +1443,7 @@
/**
* \def POLARSSL_MEMORY_C
- *
- * Enable the memory allocation layer.
- * By default PolarSSL uses the system-provided malloc() and free().
- * (As long as POLARSSL_MEMORY_STDMALLOC and POLARSSL_MEMORY_STDFREE
- * are defined and unmodified)
- *
- * This allows different allocators (self-implemented or provided)
- *
- * Enable this layer to allow use of alternative memory allocators.
+ * Deprecated since 1.3.5. Please use POLARSSL_PLATFORM_MEMORY instead.
*/
//#define POLARSSL_MEMORY_C
@@ -1429,7 +1456,8 @@
*
* Module: library/memory_buffer_alloc.c
*
- * Requires: POLARSSL_MEMORY_C
+ * Requires: POLARSSL_PLATFORM_C
+ * POLARSSL_PLATFORM_MEMORY (to use it within PolarSSL)
*
* Enable this module to enable the buffer memory allocator.
*/
@@ -1621,6 +1649,19 @@
#define POLARSSL_PKCS12_C
/**
+ * \def POLARSSL_PLATFORM_C
+ *
+ * Enable the platform abstraction layer that allows you to re-assign
+ * functions like malloc(), free(), printf(), fprintf()
+ *
+ * Module: library/platform.c
+ * Caller: Most other .c files
+ *
+ * This module enables abstraction of common (libc) functions.
+ */
+#define POLARSSL_PLATFORM_C
+
+/**
* \def POLARSSL_RIPEMD160_C
*
* Enable the RIPEMD-160 hash algorithm.
@@ -1964,10 +2005,14 @@
#define ENTROPY_MAX_SOURCES 20 /**< Maximum number of sources supported */
#define ENTROPY_MAX_GATHER 128 /**< Maximum amount requested from entropy sources */
-// Memory options
+// Memory buffer allocator options
#define MEMORY_ALIGN_MULTIPLE 4 /**< Align on multiples of this value */
-#define POLARSSL_MEMORY_STDMALLOC malloc /**< Default allocator to use, can be undefined */
-#define POLARSSL_MEMORY_STDFREE free /**< Default free to use, can be undefined */
+
+// Platform options
+#define POLARSSL_PLATFORM_STD_MALLOC malloc /**< Default allocator to use, can be undefined */
+#define POLARSSL_PLATFORM_STD_FREE free /**< Default free to use, can be undefined */
+#define POLARSSL_PLATFORM_STD_PRINTF printf /**< Default printf to use, can be undefined */
+#define POLARSSL_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use, can be undefined */
// SSL Cache options
//
@@ -2108,7 +2153,8 @@
#error "POLARSSL_KEY_EXCHANGE_RSA_ENABLED defined, but not all prerequisites"
#endif
-#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C) && !defined(POLARSSL_MEMORY_C)
+#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C) && \
+ ( !defined(POLARSSL_PLATFORM_C) || !defined(POLARSSL_PLATFORM_MEMORY) )
#error "POLARSSL_MEMORY_BUFFER_ALLOC_C defined, but not all prerequisites"
#endif
diff --git a/include/polarssl/memory.h b/include/polarssl/memory.h
index 6a3dab9..64690be 100644
--- a/include/polarssl/memory.h
+++ b/include/polarssl/memory.h
@@ -1,9 +1,9 @@
/**
* \file memory.h
*
- * \brief Memory allocation layer
+ * \brief Memory allocation layer (Deprecated to platform layer)
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2014, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -31,101 +31,18 @@
#include <stdlib.h>
-#if !defined(POLARSSL_CONFIG_OPTIONS)
-#define POLARSSL_MEMORY_ALIGN_MULTIPLE 4 /**< Align on multiples of this value */
-
-#define POLARSSL_MEMORY_STDMALLOC malloc /**< Default allocator to use, can be undefined */
-#define POLARSSL_MEMORY_STDFREE free /**< Default free to use, can be undefined */
-#endif /* POLARSSL_CONFIG_OPTIONS */
-
-#define MEMORY_VERIFY_NONE 0
-#define MEMORY_VERIFY_ALLOC (1 << 0)
-#define MEMORY_VERIFY_FREE (1 << 1)
-#define MEMORY_VERIFY_ALWAYS (MEMORY_VERIFY_ALLOC | MEMORY_VERIFY_FREE)
-
-#ifdef __cplusplus
-extern "C" {
+#if defined(POLARSSL_MEMORY_C) && !defined(POLARSSL_PLATFORM_MEMORY)
+#define POLARSSL_PLATFORM_MEMORY
#endif
-/*
- * The function pointers for malloc and free
- */
-extern void * (*polarssl_malloc)( size_t len );
-extern void (*polarssl_free)( void *ptr );
+#include "platform.h"
+#include "memory_buffer_alloc.h"
-/**
- * \brief Set your own memory implementation function pointers
- *
- * \param malloc_func the malloc function implementation
- * \param free_func the free function implementation
- *
- * \return 0 if successful
- */
int memory_set_own( void * (*malloc_func)( size_t ),
- void (*free_func)( void * ) );
-
-#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
-/**
- * \brief Initialize use of stack-based memory allocator.
- * The stack-based allocator does memory management inside the
- * presented buffer and does not call malloc() and free().
- * It sets the global polarssl_malloc() and polarssl_free() pointers
- * to its own functions.
- * (Provided polarssl_malloc() and polarssl_free() are thread-safe if
- * POLARSSL_THREADING_C is defined)
- *
- * \note This code is not optimized and provides a straight-forward
- * implementation of a stack-based memory allocator.
- *
- * \param buf buffer to use as heap
- * \param len size of the buffer
- *
- * \return 0 if successful
- */
-int memory_buffer_alloc_init( unsigned char *buf, size_t len );
-
-/**
- * \brief Free the mutex for thread-safety and clear remaining memory
- */
-void memory_buffer_alloc_free();
-
-/**
- * \brief Determine when the allocator should automatically verify the state
- * of the entire chain of headers / meta-data.
- * (Default: MEMORY_VERIFY_NONE)
- *
- * \param verify One of MEMORY_VERIFY_NONE, MEMORY_VERIFY_ALLOC,
- * MEMORY_VERIFY_FREE or MEMORY_VERIFY_ALWAYS
- */
-void memory_buffer_set_verify( int verify );
-
-#if defined(POLARSSL_MEMORY_DEBUG)
-/**
- * \brief Print out the status of the allocated memory (primarily for use
- * after a program should have de-allocated all memory)
- * Prints out a list of 'still allocated' blocks and their stack
- * trace if POLARSSL_MEMORY_BACKTRACE is defined.
- */
-void memory_buffer_alloc_status();
-#endif /* POLARSSL_MEMORY_DEBUG */
-
-/**
- * \brief Verifies that all headers in the memory buffer are correct
- * and contain sane values. Helps debug buffer-overflow errors.
- *
- * Prints out first failure if POLARSSL_MEMORY_DEBUG is defined.
- * Prints out full header information if POLARSSL_MEMORY_DEBUG_HEADERS
- * is defined. (Includes stack trace information for each block if
- * POLARSSL_MEMORY_BACKTRACE is defined as well).
- *
- * \returns 0 if verified, 1 otherwise
- */
-int memory_buffer_alloc_verify();
-
-#endif /* POLARSSL_MEMORY_BUFFER_ALLOC_C */
-
-#ifdef __cplusplus
+ void (*free_func)( void * ) )
+{
+ return platform_set_malloc_free( malloc_func, free_func );
}
-#endif
+
#endif /* memory.h */
diff --git a/include/polarssl/memory_buffer_alloc.h b/include/polarssl/memory_buffer_alloc.h
new file mode 100644
index 0000000..ccddc00
--- /dev/null
+++ b/include/polarssl/memory_buffer_alloc.h
@@ -0,0 +1,108 @@
+/**
+ * \file memory_buffer_alloc.h
+ *
+ * \brief Buffer-based memory allocator
+ *
+ * Copyright (C) 2006-2014, Brainspark B.V.
+ *
+ * This file is part of PolarSSL (http://www.polarssl.org)
+ * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef POLARSSL_MEMORY_BUFFER_ALLOC_H
+#define POLARSSL_MEMORY_BUFFER_ALLOC_H
+
+#include "config.h"
+
+#include <stdlib.h>
+
+#if !defined(POLARSSL_CONFIG_OPTIONS)
+#define POLARSSL_MEMORY_ALIGN_MULTIPLE 4 /**< Align on multiples of this value */
+#endif /* POLARSSL_CONFIG_OPTIONS */
+
+#define MEMORY_VERIFY_NONE 0
+#define MEMORY_VERIFY_ALLOC (1 << 0)
+#define MEMORY_VERIFY_FREE (1 << 1)
+#define MEMORY_VERIFY_ALWAYS (MEMORY_VERIFY_ALLOC | MEMORY_VERIFY_FREE)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Initialize use of stack-based memory allocator.
+ * The stack-based allocator does memory management inside the
+ * presented buffer and does not call malloc() and free().
+ * It sets the global polarssl_malloc() and polarssl_free() pointers
+ * to its own functions.
+ * (Provided polarssl_malloc() and polarssl_free() are thread-safe if
+ * POLARSSL_THREADING_C is defined)
+ *
+ * \note This code is not optimized and provides a straight-forward
+ * implementation of a stack-based memory allocator.
+ *
+ * \param buf buffer to use as heap
+ * \param len size of the buffer
+ *
+ * \return 0 if successful
+ */
+int memory_buffer_alloc_init( unsigned char *buf, size_t len );
+
+/**
+ * \brief Free the mutex for thread-safety and clear remaining memory
+ */
+void memory_buffer_alloc_free( void );
+
+/**
+ * \brief Determine when the allocator should automatically verify the state
+ * of the entire chain of headers / meta-data.
+ * (Default: MEMORY_VERIFY_NONE)
+ *
+ * \param verify One of MEMORY_VERIFY_NONE, MEMORY_VERIFY_ALLOC,
+ * MEMORY_VERIFY_FREE or MEMORY_VERIFY_ALWAYS
+ */
+void memory_buffer_set_verify( int verify );
+
+#if defined(POLARSSL_MEMORY_DEBUG)
+/**
+ * \brief Print out the status of the allocated memory (primarily for use
+ * after a program should have de-allocated all memory)
+ * Prints out a list of 'still allocated' blocks and their stack
+ * trace if POLARSSL_MEMORY_BACKTRACE is defined.
+ */
+void memory_buffer_alloc_status( void );
+#endif /* POLARSSL_MEMORY_DEBUG */
+
+/**
+ * \brief Verifies that all headers in the memory buffer are correct
+ * and contain sane values. Helps debug buffer-overflow errors.
+ *
+ * Prints out first failure if POLARSSL_MEMORY_DEBUG is defined.
+ * Prints out full header information if POLARSSL_MEMORY_DEBUG_HEADERS
+ * is defined. (Includes stack trace information for each block if
+ * POLARSSL_MEMORY_BACKTRACE is defined as well).
+ *
+ * \returns 0 if verified, 1 otherwise
+ */
+int memory_buffer_alloc_verify( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* memory_buffer_alloc.h */
diff --git a/include/polarssl/platform.h b/include/polarssl/platform.h
new file mode 100644
index 0000000..b5dd4d1
--- /dev/null
+++ b/include/polarssl/platform.h
@@ -0,0 +1,102 @@
+/**
+ * \file platform.h
+ *
+ * \brief PolarSSL Platform abstraction layer
+ *
+ * Copyright (C) 2006-2014, Brainspark B.V.
+ *
+ * This file is part of PolarSSL (http://www.polarssl.org)
+ * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef POLARSSL_PLATFORM_H
+#define POLARSSL_PLATFORM_H
+
+#include "config.h"
+
+#include <stdio.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if !defined(POLARSSL_CONFIG_OPTIONS)
+#include <stdlib.h>
+#define POLARSSL_PLATFORM_STD_PRINTF printf /**< Default printf to use */
+#define POLARSSL_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use */
+#define POLARSSL_PLATFORM_STD_MALLOC malloc /**< Default allocator to use */
+#define POLARSSL_PLATFORM_STD_FREE free /**< Default free to use */
+#endif /* POLARSSL_CONFIG_OPTIONS */
+
+/*
+ * The function pointers for malloc and free
+ */
+#if defined(POLARSSL_PLATFORM_MEMORY)
+extern void * (*polarssl_malloc)( size_t len );
+extern void (*polarssl_free)( void *ptr );
+
+/**
+ * \brief Set your own memory implementation function pointers
+ *
+ * \param malloc_func the malloc function implementation
+ * \param free_func the free function implementation
+ *
+ * \return 0 if successful
+ */
+int platform_set_malloc_free( void * (*malloc_func)( size_t ),
+ void (*free_func)( void * ) );
+#else
+#define polarssl_malloc malloc
+#define polarssl_free free
+#endif
+
+/*
+ * The function pointers for printf
+ */
+#if defined(POLARSSL_PLATFORM_PRINTF_ALT)
+extern int (*polarssl_printf)( const char *format, ... );
+
+/**
+ * \brief Set your own printf function pointer
+ *
+ * \param printf_func the printf function implementation
+ *
+ * \return 0
+ */
+int platform_set_printf( int (*printf_func)( const char *, ... ) );
+#else
+#define polarssl_printf printf
+#endif
+
+/*
+ * The function pointers for fprintf
+ */
+#if defined(POLARSSL_PLATFORM_FPRINTF_ALT)
+extern int (*polarssl_fprintf)( FILE *stream, const char *format, ... );
+
+int platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *,
+ ... ) );
+#else
+#define polarssl_fprintf fprintf
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* platform.h */
diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt
index 77aac20..2d74559 100644
--- a/library/CMakeLists.txt
+++ b/library/CMakeLists.txt
@@ -32,7 +32,6 @@
md2.c
md4.c
md5.c
- memory.c
memory_buffer_alloc.c
net.c
oid.c
@@ -46,6 +45,7 @@
pk_wrap.c
pkparse.c
pkwrite.c
+ platform.c
ripemd160.c
rsa.c
sha1.c
diff --git a/library/Makefile b/library/Makefile
index 311e316..a4a3ce7 100644
--- a/library/Makefile
+++ b/library/Makefile
@@ -46,13 +46,13 @@
error.o gcm.o havege.o \
hmac_drbg.o \
md.o md_wrap.o md2.o \
- md4.o md5.o memory.o \
+ md4.o md5.o \
memory_buffer_alloc.o net.o \
oid.o \
padlock.o pbkdf2.o pem.o \
pkcs5.o pkcs11.o pkcs12.o \
pk.o pk_wrap.o pkparse.o \
- pkwrite.o ripemd160.o \
+ pkwrite.o platform.o ripemd160.o \
rsa.o sha1.o sha256.o \
sha512.o ssl_cache.o ssl_cli.o \
ssl_srv.o ssl_ciphersuites.o \
diff --git a/library/aes.c b/library/aes.c
index bc4b178..f516fba 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 <polarssl_maintainer at polarssl.org>
@@ -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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 85b78f5..536ea8c 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 <polarssl_maintainer at polarssl.org>
@@ -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 @@
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 @@
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 9573599..c9ce75a 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 <polarssl_maintainer at polarssl.org>
@@ -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 32d1c73..13f4a39 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 <polarssl_maintainer at polarssl.org>
@@ -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 <stdlib.h>
#define polarssl_malloc malloc
diff --git a/library/base64.c b/library/base64.c
index 3b4376d..ee9c05c 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 <polarssl_maintainer at polarssl.org>
@@ -36,6 +36,12 @@
#include <inttypes.h>
#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 @@
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 @@
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 @@
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 bbd901e..cb55586 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 <polarssl_maintainer at polarssl.org>
@@ -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 @@
return( POLARSSL_ERR_MPI_FILE_IO_ERROR );
}
else
- printf( "%s%s", p, s );
+ polarssl_printf( "%s%s", p, s );
cleanup:
@@ -2189,19 +2190,19 @@
"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 @@
"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 @@
"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 @@
"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 @@
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 @@
}
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 2366cae..f007a46 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 <polarssl_maintainer at polarssl.org>
@@ -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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 bfb229e..a103c26 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 <dejong@fox-it.com>
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2014, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -769,16 +769,9 @@
#if defined(POLARSSL_SELF_TEST)
-#include <stdio.h>
-
-#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 3020e14..23065c4 100644
--- a/library/cipher_wrap.c
+++ b/library/cipher_wrap.c
@@ -5,7 +5,7 @@
*
* \author Adriaan de Jong <dejong@fox-it.com>
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2014, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -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 d2b4313..3be65e1 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 <polarssl_maintainer at polarssl.org>
@@ -38,6 +38,12 @@
#include <stdio.h>
#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 @@
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 @@
* 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 @@
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 @@
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 153810d..6e15234 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 <polarssl_maintainer at polarssl.org>
@@ -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 @@
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 @@
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 @@
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 @@
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 e8aa819..9d00d9b 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 <polarssl_maintainer at polarssl.org>
@@ -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 <stdlib.h>
+#define polarssl_printf printf
#define polarssl_malloc malloc
#define polarssl_free free
#endif
@@ -548,19 +549,19 @@
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 ad6e5f5..2577fa7 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 <polarssl_maintainer at polarssl.org>
@@ -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 @@
#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 @@
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 @@
}
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 @@
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 @@
}
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 @@
mpi_free( &m );
if( verbose != 0 )
- printf( "\n" );
+ polarssl_printf( "\n" );
return( ret );
}
diff --git a/library/gcm.c b/library/gcm.c
index 3e1bc77..1c6cf9f 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 <polarssl_maintainer at polarssl.org>
@@ -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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
if( ret != 0 )
{
if( verbose != 0 )
- printf( "failed\n" );
+ polarssl_printf( "failed\n" );
return( 1 );
}
@@ -790,7 +799,7 @@
if( ret != 0 )
{
if( verbose != 0 )
- printf( "failed\n" );
+ polarssl_printf( "failed\n" );
return( 1 );
}
@@ -799,7 +808,7 @@
if( ret != 0 )
{
if( verbose != 0 )
- printf( "failed\n" );
+ polarssl_printf( "failed\n" );
return( 1 );
}
@@ -810,7 +819,7 @@
if( ret != 0 )
{
if( verbose != 0 )
- printf( "failed\n" );
+ polarssl_printf( "failed\n" );
return( 1 );
}
@@ -822,7 +831,7 @@
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 @@
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 @@
if( ret != 0 )
{
if( verbose != 0 )
- printf( "failed\n" );
+ polarssl_printf( "failed\n" );
return( 1 );
}
@@ -855,7 +865,7 @@
if( ret != 0 )
{
if( verbose != 0 )
- printf( "failed\n" );
+ polarssl_printf( "failed\n" );
return( 1 );
}
@@ -864,7 +874,7 @@
if( ret != 0 )
{
if( verbose != 0 )
- printf( "failed\n" );
+ polarssl_printf( "failed\n" );
return( 1 );
}
@@ -875,7 +885,7 @@
if( ret != 0 )
{
if( verbose != 0 )
- printf( "failed\n" );
+ polarssl_printf( "failed\n" );
return( 1 );
}
@@ -887,7 +897,7 @@
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 @@
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 33a20ef..7a21092 100644
--- a/library/hmac_drbg.c
+++ b/library/hmac_drbg.c
@@ -39,6 +39,12 @@
#include <stdio.h>
#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 @@
{
if( verbose != 0 )
- printf( "\n" );
+ polarssl_printf( "\n" );
return( 0 );
}
@@ -418,11 +424,11 @@
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 @@
* 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 @@
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 @@
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 93e77d2..f29877f 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 <polarssl_maintainer at polarssl.org>
@@ -39,6 +39,12 @@
#include <stdio.h>
#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 @@
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 @@
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 e14c83d..8ac6c01 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 <polarssl_maintainer at polarssl.org>
@@ -39,6 +39,12 @@
#include <stdio.h>
#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 @@
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 @@
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 b28461e..c596e43 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 <polarssl_maintainer at polarssl.org>
@@ -38,6 +38,12 @@
#include <stdio.h>
#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 @@
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 @@
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 bca5ab2..a6c1bac 100644
--- a/library/md_wrap.c
+++ b/library/md_wrap.c
@@ -5,7 +5,7 @@
*
* \author Adriaan de Jong <dejong@fox-it.com>
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2014, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -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.c b/library/memory.c
deleted file mode 100644
index 93ca379..0000000
--- a/library/memory.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Memory allocation layer
- *
- * Copyright (C) 2006-2013, Brainspark B.V.
- *
- * This file is part of PolarSSL (http://www.polarssl.org)
- * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
- *
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include "polarssl/config.h"
-
-#if defined(POLARSSL_MEMORY_C)
-
-#include "polarssl/memory.h"
-
-#if !defined(POLARSSL_MEMORY_STDMALLOC)
-static void *memory_malloc_uninit( size_t len )
-{
- ((void) len);
- return( NULL );
-}
-
-#define POLARSSL_MEMORY_STDMALLOC memory_malloc_uninit
-#endif /* !POLARSSL_MEMORY_STDMALLOC */
-
-#if !defined(POLARSSL_MEMORY_STDFREE)
-static void memory_free_uninit( void *ptr )
-{
- ((void) ptr);
-}
-
-#define POLARSSL_MEMORY_STDFREE memory_free_uninit
-#endif /* !POLARSSL_MEMORY_STDFREE */
-
-void * (*polarssl_malloc)( size_t ) = POLARSSL_MEMORY_STDMALLOC;
-void (*polarssl_free)( void * ) = POLARSSL_MEMORY_STDFREE;
-
-int memory_set_own( void * (*malloc_func)( size_t ),
- void (*free_func)( void * ) )
-{
- polarssl_malloc = malloc_func;
- polarssl_free = free_func;
-
- return( 0 );
-}
-
-#endif /* POLARSSL_MEMORY_C */
diff --git a/library/memory_buffer_alloc.c b/library/memory_buffer_alloc.c
index 1038c85..33ab5ac 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 <polarssl_maintainer at polarssl.org>
@@ -25,9 +25,9 @@
#include "polarssl/config.h"
-#if defined(POLARSSL_MEMORY_C) && defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
+#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
-#include "polarssl/memory.h"
+#include "polarssl/memory_buffer_alloc.h"
#include <string.h>
@@ -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 @@
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 @@
{
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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,23 +500,24 @@
#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();
}
}
-#endif /* POLARSSL_MEMORY_BUFFER_ALLOC_DEBUG */
+#endif /* POLARSSL_MEMORY_DEBUG */
#if defined(POLARSSL_THREADING_C)
static void *buffer_alloc_malloc_mutexed( size_t len )
@@ -529,11 +544,10 @@
#if defined(POLARSSL_THREADING_C)
polarssl_mutex_init( &heap.mutex );
- polarssl_malloc = buffer_alloc_malloc_mutexed;
- polarssl_free = buffer_alloc_free_mutexed;
+ platform_set_malloc_free( buffer_alloc_malloc_mutexed,
+ buffer_alloc_free_mutexed );
#else
- polarssl_malloc = buffer_alloc_malloc;
- polarssl_free = buffer_alloc_free;
+ platform_set_malloc_free( buffer_alloc_malloc, buffer_alloc_free );
#endif
heap.buf = buf;
@@ -555,4 +569,4 @@
memset( &heap, 0, sizeof(buffer_alloc_ctx) );
}
-#endif /* POLARSSL_MEMORY_C && POLARSSL_MEMORY_BUFFER_ALLOC_C */
+#endif /* POLARSSL_MEMORY_BUFFER_ALLOC_C */
diff --git a/library/pem.c b/library/pem.c
index d602d8a..2c9d10d 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 <polarssl_maintainer at polarssl.org>
@@ -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 3f05edd..99535d6 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 <polarssl_maintainer at polarssl.org>
@@ -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 <stdlib.h>
#define polarssl_malloc malloc
diff --git a/library/pkcs11.c b/library/pkcs11.c
index 8a99f28..d758460 100644
--- a/library/pkcs11.c
+++ b/library/pkcs11.c
@@ -5,7 +5,7 @@
*
* \author Adriaan de Jong <dejong@fox-it.com>
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2014, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -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 <stdlib.h>
#define polarssl_malloc malloc
#define polarssl_free free
#endif
-#include <stdlib.h>
-
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 39aa5b9..c4cdf03 100644
--- a/library/pkcs5.c
+++ b/library/pkcs5.c
@@ -5,7 +5,7 @@
*
* \author Mathias Olsson <mathias@kompetensum.com>
*
- * Copyright (C) 2006-2013, Brainspark B.V.
+ * Copyright (C) 2006-2014, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@@ -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 @@
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 @@
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 a5de20b..dcb0f3f 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 <stdlib.h>
#define polarssl_malloc malloc
diff --git a/library/pkwrite.c b/library/pkwrite.c
index 8b6d735..4cbba10 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 <polarssl_maintainer at polarssl.org>
@@ -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 <stdlib.h>
#define polarssl_malloc malloc
diff --git a/library/platform.c b/library/platform.c
new file mode 100644
index 0000000..823b17d
--- /dev/null
+++ b/library/platform.c
@@ -0,0 +1,112 @@
+/*
+ * Platform abstraction layer
+ *
+ * Copyright (C) 2006-2014, Brainspark B.V.
+ *
+ * This file is part of PolarSSL (http://www.polarssl.org)
+ * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "polarssl/config.h"
+
+#if defined(POLARSSL_PLATFORM_C)
+
+#include "polarssl/platform.h"
+
+#if defined(POLARSSL_PLATFORM_MEMORY)
+#if !defined(POLARSSL_PLATFORM_STD_MALLOC)
+static void *platform_malloc_uninit( size_t len )
+{
+ ((void) len);
+ return( NULL );
+}
+
+#define POLARSSL_PLATFORM_STD_MALLOC memory_malloc_uninit
+#endif /* !POLARSSL_PLATFORM_STD_MALLOC */
+
+#if !defined(POLARSSL_PLATFORM_STD_FREE)
+static void platform_free_uninit( void *ptr )
+{
+ ((void) ptr);
+}
+
+#define POLARSSL_PLATFORM_STD_FREE memory_free_uninit
+#endif /* !POLARSSL_PLATFORM_STD_FREE */
+
+void * (*polarssl_malloc)( size_t ) = POLARSSL_PLATFORM_STD_MALLOC;
+void (*polarssl_free)( void * ) = POLARSSL_PLATFORM_STD_FREE;
+
+int platform_set_malloc_free( void * (*malloc_func)( size_t ),
+ void (*free_func)( void * ) )
+{
+ polarssl_malloc = malloc_func;
+ polarssl_free = free_func;
+ return( 0 );
+}
+#endif /* POLARSSL_PLATFORM_MEMORY */
+
+#if defined(POLARSSL_PLATFORM_PRINTF_ALT)
+#if !defined(POLARSSL_PLATFORM_STD_PRINTF)
+/*
+ * Make dummy function to prevent NULL pointer dereferences
+ */
+static int platform_printf_uninit( const char *format, ... )
+{
+ ((void) format);
+ return( 0 );
+}
+
+#define POLARSSL_PLATFORM_STD_PRINTF platform_printf_uninit
+#endif /* !POLARSSL_PLATFORM_STD_PRINTF */
+
+int (*polarssl_printf)( const char *, ... ) = POLARSSL_PLATFORM_STD_PRINTF;
+
+int platform_set_printf( int (*printf_func)( const char *, ... ) )
+{
+ polarssl_printf = printf_func;
+ return( 0 );
+}
+#endif /* POLARSSL_PLATFORM_PRINTF_ALT */
+
+#if defined(POLARSSL_PLATFORM_FPRINTF_ALT)
+#if !defined(POLARSSL_PLATFORM_STD_FPRINTF)
+/*
+ * Make dummy function to prevent NULL pointer dereferences
+ */
+static int platform_fprintf_uninit( FILE *stream, const char *format, ... )
+{
+ ((void) stream);
+ ((void) format);
+ return( 0 );
+}
+
+#define POLARSSL_PLATFORM_STD_fPRINTF platform_fprintf_uninit
+#endif /* !POLARSSL_PLATFORM_STD_FPRINTF */
+
+int (*polarssl_fprintf)( FILE *, const char *, ... ) =
+ POLARSSL_PLATFORM_STD_FPRINTF;
+
+int platform_set_fprintf( int (*fprintf_func)( FILE *, const char *, ... ) )
+{
+ polarssl_fprintf = fprintf_func;
+ return( 0 );
+}
+#endif /* POLARSSL_PLATFORM_FPRINTF_ALT */
+
+#endif /* POLARSSL_PLATFORM_C */
diff --git a/library/ripemd160.c b/library/ripemd160.c
index 569cbde..10e60df 100644
--- a/library/ripemd160.c
+++ b/library/ripemd160.c
@@ -43,6 +43,12 @@
#include <string.h>
#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 @@
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 @@
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 @@
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 f4ff237..3a1ea35 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 <polarssl_maintainer at polarssl.org>
@@ -43,6 +43,12 @@
#include <stdlib.h>
#include <stdio.h>
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
/*
* Initialize an RSA context
*/
@@ -1495,19 +1501,19 @@
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 @@
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 @@
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 @@
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 b301b09..f02d6e6 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 <polarssl_maintainer at polarssl.org>
@@ -38,6 +38,12 @@
#include <stdio.h>
#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 @@
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 @@
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 @@
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 e4d4842..638188f 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 <polarssl_maintainer at polarssl.org>
@@ -38,6 +38,12 @@
#include <stdio.h>
#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 @@
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 @@
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 @@
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 @@
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 2366e7c..1bef2e9 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 <polarssl_maintainer at polarssl.org>
@@ -38,6 +38,12 @@
#include <stdio.h>
#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 @@
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 @@
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 @@
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 @@
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 e0847b6..6fff54b 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 <polarssl_maintainer at polarssl.org>
@@ -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 fe2103b..4e42c0b 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 <polarssl_maintainer at polarssl.org>
@@ -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 e045fdc..f484cf6 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 <polarssl_maintainer at polarssl.org>
@@ -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 a520583..4a9211f 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 <polarssl_maintainer at polarssl.org>
@@ -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 74a8f8e..17e8b4d 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 <polarssl_maintainer at polarssl.org>
@@ -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 @@
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 @@
if( ret != 0 )
{
if( verbose != 0 )
- printf( "failed\n" );
+ polarssl_printf( "failed\n" );
return( ret );
}
@@ -1012,27 +1013,27 @@
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 964aa7e..92ede6d 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 <polarssl_maintainer at polarssl.org>
@@ -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 5859725..4c79a7a 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 <polarssl_maintainer at polarssl.org>
@@ -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 a5cef4c..bdadec3 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 <polarssl_maintainer at polarssl.org>
@@ -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 2cb2f30..1bb6f29 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 @@
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 @@
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 );
}