Merge remote-tracking branch 'rich/platform' into development

* rich/platform:
  Remove dependency on sscanf in lib x509
  Fix extra guard in memory_buffer_alloc
  rebase from development
  implemented macro overriding for polarssl_* library functions
  fix bug introduced by the addition of snprintf and assert macro which caused tests to fail without polarssl_platform_c defined
  add initial symbols to config and checks to check_config to allow use of macros to define standard functions
  reformat and arrange additions to config alphabetically
  add missing checks to check_config
  add macro definition of assert using polarssl_exit
  modify library/memory_buffer_alloc.c, benchmark.c and the tests main code to use polarssl_exit
  add POLARSSL_PLATFORM_EXIT_ALT
  modify scripts/* and tests/* to use polarssl_snprintf
  modify programs/*.c to use polarssl_snprintf
  modify library/debug.c to use polarssl_snprintf
  modify library/x509*.c to use polarssl_snprintf
  modify library/net.c to use polarssl_snprintf
  modify oid.c to use polarssl_snprintf
  add platform_set_snprintf

Conflicts:
	library/memory_buffer_alloc.c
	programs/pkey/pk_sign.c
	programs/pkey/pk_verify.c
	programs/pkey/rsa_sign_pss.c
	programs/pkey/rsa_verify_pss.c
	programs/ssl/ssl_client2.c
	programs/ssl/ssl_pthread_server.c
	programs/test/benchmark.c
	programs/test/ssl_cert_test.c
This commit is contained in:
Manuel Pégourié-Gonnard 2015-02-13 15:11:24 +00:00
commit ac1f76c362
25 changed files with 528 additions and 175 deletions

View file

@ -198,6 +198,136 @@
#error "POLARSSL_PKCS11_C defined, but not all prerequisites"
#endif
#if defined(POLARSSL_PLATFORM_EXIT_ALT) && !defined(POLARSSL_PLATFORM_C)
#error "POLARSSL_PLATFORM_EXIT_ALT defined, but not all prerequisites"
#endif
#if defined(POLARSSL_PLATFORM_EXIT_MACRO) && !defined(POLARSSL_PLATFORM_C)
#error "POLARSSL_PLATFORM_EXIT_MACRO defined, but not all prerequisites"
#endif
#if defined(POLARSSL_PLATFORM_EXIT_MACRO) &&\
( defined(POLARSSL_PLATFORM_STD_EXIT) ||\
defined(POLARSSL_PLATFORM_EXIT_ALT) )
#error "POLARSSL_PLATFORM_EXIT_MACRO and POLARSSL_PLATFORM_STD_EXIT/POLARSSL_PLATFORM_EXIT_ALT cannot be defined simultaneously"
#endif
#if defined(POLARSSL_PLATFORM_FPRINTF_ALT) && !defined(POLARSSL_PLATFORM_C)
#error "POLARSSL_PLATFORM_FPRINTF_ALT defined, but not all prerequisites"
#endif
#if defined(POLARSSL_PLATFORM_FPRINTF_MACRO) && !defined(POLARSSL_PLATFORM_C)
#error "POLARSSL_PLATFORM_FPRINTF_MACRO defined, but not all prerequisites"
#endif
#if defined(POLARSSL_PLATFORM_FPRINTF_MACRO) &&\
( defined(POLARSSL_PLATFORM_STD_FPRINTF) ||\
defined(POLARSSL_PLATFORM_FPRINTF_ALT) )
#error "POLARSSL_PLATFORM_FPRINTF_MACRO and POLARSSL_PLATFORM_STD_FPRINTF/POLARSSL_PLATFORM_FPRINTF_ALT cannot be defined simultaneously"
#endif
#if defined(POLARSSL_PLATFORM_FREE_MACRO) &&\
( !defined(POLARSSL_PLATFORM_C) || !defined(POLARSSL_PLATFORM_MEMORY) )
#error "POLARSSL_PLATFORM_FREE_MACRO defined, but not all prerequisites"
#endif
#if defined(POLARSSL_PLATFORM_FREE_MACRO) &&\
defined(POLARSSL_PLATFORM_STD_FREE)
#error "POLARSSL_PLATFORM_FREE_MACRO and POLARSSL_PLATFORM_STD_FREE cannot be defined simultaneously"
#endif
#if defined(POLARSSL_PLATFORM_FREE_MACRO) && !defined(POLARSSL_PLATFORM_MALLOC_MACRO)
#error "POLARSSL_PLATFORM_MALLOC_MACRO must be defined if POLARSSL_PLATFORM_FREE_MACRO is"
#endif
#if defined(POLARSSL_PLATFORM_MALLOC_MACRO) &&\
( !defined(POLARSSL_PLATFORM_C) || !defined(POLARSSL_PLATFORM_MEMORY) )
#error "POLARSSL_PLATFORM_MALLOC_MACRO defined, but not all prerequisites"
#endif
#if defined(POLARSSL_PLATFORM_MALLOC_MACRO) &&\
defined(POLARSSL_PLATFORM_STD_MALLOC)
#error "POLARSSL_PLATFORM_MALLOC_MACRO and POLARSSL_PLATFORM_STD_MALLOC cannot be defined simultaneously"
#endif
#if defined(POLARSSL_PLATFORM_MALLOC_MACRO) && !defined(POLARSSL_PLATFORM_FREE_MACRO)
#error "POLARSSL_PLATFORM_FREE_MACRO must be defined if POLARSSL_PLATFORM_MALLOC_MACRO is"
#endif
#if defined(POLARSSL_PLATFORM_MEMORY) && !defined(POLARSSL_PLATFORM_C)
#error "POLARSSL_PLATFORM_MEMORY defined, but not all prerequisites"
#endif
#if defined(POLARSSL_PLATFORM_PRINTF_ALT) && !defined(POLARSSL_PLATFORM_C)
#error "POLARSSL_PLATFORM_PRINTF_ALT defined, but not all prerequisites"
#endif
#if defined(POLARSSL_PLATFORM_PRINTF_MACRO) && !defined(POLARSSL_PLATFORM_C)
#error "POLARSSL_PLATFORM_PRINTF_MACRO defined, but not all prerequisites"
#endif
#if defined(POLARSSL_PLATFORM_PRINTF_MACRO) &&\
( defined(POLARSSL_PLATFORM_STD_PRINTF) ||\
defined(POLARSSL_PLATFORM_PRINTF_ALT) )
#error "POLARSSL_PLATFORM_PRINTF_MACRO and POLARSSL_PLATFORM_STD_PRINTF/POLARSSL_PLATFORM_PRINTF_ALT cannot be defined simultaneously"
#endif
#if defined(POLARSSL_PLATFORM_SNPRINTF_ALT) && !defined(POLARSSL_PLATFORM_C)
#error "POLARSSL_PLATFORM_SNPRINTF_ALT defined, but not all prerequisites"
#endif
#if defined(POLARSSL_PLATFORM_SNPRINTF_ALT) && ( defined(_WIN32)\
&& !defined(EFIX64) && !defined(EFI32) )
#error "POLARSSL_PLATFORM_SNPRINTF_ALT defined but not available on Windows"
#endif
#if defined(POLARSSL_PLATFORM_SNPRINTF_MACRO) && !defined(POLARSSL_PLATFORM_C)
#error "POLARSSL_PLATFORM_SNPRINTF_MACRO defined, but not all prerequisites"
#endif
#if defined(POLARSSL_PLATFORM_SNPRINTF_MACRO) &&\
( defined(POLARSSL_PLATFORM_STD_SNPRINTF) ||\
defined(POLARSSL_PLATFORM_SNPRINTF_ALT) )
#error "POLARSSL_PLATFORM_SNPRINTF_MACRO and POLARSSL_PLATFORM_STD_SNPRINTF/POLARSSL_PLATFORM_SNPRINTF_ALT cannot be defined simultaneously"
#endif
#if defined(POLARSSL_PLATFORM_STD_MEM_HDR) &&\
!defined(POLARSSL_PLATFORM_NO_STD_FUNCTIONS)
#error "POLARSSL_PLATFORM_STD_MEM_HDR defined, but not all prerequisites"
#endif
#if defined(POLARSSL_PLATFORM_STD_MALLOC) && !defined(POLARSSL_PLATFORM_MEMORY)
#error "POLARSSL_PLATFORM_STD_MALLOC defined, but not all prerequisites"
#endif
#if defined(POLARSSL_PLATFORM_STD_MALLOC) && !defined(POLARSSL_PLATFORM_MEMORY)
#error "POLARSSL_PLATFORM_STD_MALLOC defined, but not all prerequisites"
#endif
#if defined(POLARSSL_PLATFORM_STD_FREE) && !defined(POLARSSL_PLATFORM_MEMORY)
#error "POLARSSL_PLATFORM_STD_FREE defined, but not all prerequisites"
#endif
#if defined(POLARSSL_PLATFORM_STD_EXIT) &&\
!defined(POLARSSL_PLATFORM_EXIT_ALT)
#error "POLARSSL_PLATFORM_STD_EXIT defined, but not all prerequisites"
#endif
#if defined(POLARSSL_PLATFORM_STD_FPRINTF) &&\
!defined(POLARSSL_PLATFORM_FPRINTF_ALT)
#error "POLARSSL_PLATFORM_STD_FPRINTF defined, but not all prerequisites"
#endif
#if defined(POLARSSL_PLATFORM_STD_PRINTF) &&\
!defined(POLARSSL_PLATFORM_PRINTF_ALT)
#error "POLARSSL_PLATFORM_STD_PRINTF defined, but not all prerequisites"
#endif
#if defined(POLARSSL_PLATFORM_STD_SNPRINTF) &&\
!defined(POLARSSL_PLATFORM_SNPRINTF_ALT)
#error "POLARSSL_PLATFORM_STD_SNPRINTF defined, but not all prerequisites"
#endif
#if defined(POLARSSL_RSA_C) && ( !defined(POLARSSL_BIGNUM_C) || \
!defined(POLARSSL_OID_C) )
#error "POLARSSL_RSA_C defined, but not all prerequisites"

View file

@ -120,8 +120,14 @@
* 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.
* Enabling POLARSSL_PLATFORM_MEMORY without the
* POLARSSL_PLATFORM_{FREE,MALLOC}_MACROs will provide
* "platform_set_malloc_free()" allowing you to set an alternative malloc() and
* free() function pointer at runtime.
*
* Enabling POLARSSL_PLATFORM_MEMORY and specifying
* POLARSSL_PLATFORM_{MALLOC,FREE}_MACROs will allow you to specify the
* alternate function at compile time.
*
* Requires: POLARSSL_PLATFORM_C
*
@ -138,7 +144,8 @@
* This makes sure there are no linking errors on platforms that do not support
* these functions. You will HAVE to provide alternatives, either at runtime
* via the platform_set_xxx() functions or at compile time by setting
* the POLARSSL_PLATFORM_STD_XXX defines.
* the POLARSSL_PLATFORM_STD_XXX defines, or enabling a
* POLARSSL_PLATFORM_XXX_MACRO.
*
* Requires: POLARSSL_PLATFORM_C
*
@ -159,11 +166,19 @@
*
* All these define require POLARSSL_PLATFORM_C to be defined!
*
* WARNING: POLARSSL_PLATFORM_SNPRINTF_ALT is not available on Windows
* for compatibility reasons.
*
* WARNING: POLARSSL_PLATFORM_XXX_ALT cannot be defined at the same time as
* POLARSSL_PLATFORM_XXX_MACRO!
*
* Uncomment a macro to enable alternate implementation of specific base
* platform function
*/
//#define POLARSSL_PLATFORM_PRINTF_ALT
//#define POLARSSL_PLATFORM_EXIT_ALT
//#define POLARSSL_PLATFORM_FPRINTF_ALT
//#define POLARSSL_PLATFORM_PRINTF_ALT
//#define POLARSSL_PLATFORM_SNPRINTF_ALT
/* \} name SECTION: System support */
/**
@ -1890,7 +1905,11 @@
* \def POLARSSL_PLATFORM_C
*
* Enable the platform abstraction layer that allows you to re-assign
* functions like malloc(), free(), printf(), fprintf()
* functions like malloc(), free(), snprintf(), printf(), fprintf(), exit()
*
* Enabling POLARSSL_PLATFORM_C enables to use of POLARSSL_PLATFORM_XXX_ALT
* or POLARSSL_PLATFORM_XXX_MACRO directives, allowing the functions mentioned
* above to be specified at runtime or compile time respectively.
*
* Module: library/platform.c
* Caller: Most other .c files
@ -2235,11 +2254,22 @@
//#define POLARSSL_MEMORY_ALIGN_MULTIPLE 4 /**< Align on multiples of this value */
/* Platform options */
//#define POLARSSL_PLATFORM_STD_MEM_HDR <stdlib.h> /**< Header to include if POLARSSL_PLATFORM_NO_STD_FUNCTIONS is defined. Don't define if no header is needed. */
//#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 */
//#define POLARSSL_PLATFORM_STD_MEM_HDR <stdlib.h> /**< Header to include if POLARSSL_PLATFORM_NO_STD_FUNCTIONS is defined. Don't define if no header is needed. */
//#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_EXIT exit /**< Default exit to use, can be undefined */
//#define POLARSSL_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use, can be undefined */
//#define POLARSSL_PLATFORM_STD_PRINTF printf /**< Default printf to use, can be undefined */
//#define POLARSSL_PLATFORM_STD_SNPRINTF snprintf /**< Default snprintf to use, can be undefined */
/* To Use Function Macros POLARSSL_PLATFORM_C must be enabled */
/* POLARSSL_PLATFORM_XXX_MACRO and POLARSSL_PLATFORM_XXX_ALT cannot both be defined */
//#define POLARSSL_PLATFORM_MALLOC_MACRO malloc /**< Default allocator macro to use, can be undefined */
//#define POLARSSL_PLATFORM_FREE_MACRO free /**< Default free macro to use, can be undefined */
//#define POLARSSL_PLATFORM_EXIT_MACRO exit /**< Default exit macro to use, can be undefined */
//#define POLARSSL_PLATFORM_FPRINTF_MACRO fprintf /**< Default fprintf macro to use, can be undefined */
//#define POLARSSL_PLATFORM_PRINTF_MACRO printf /**< Default printf macro to use, can be undefined */
//#define POLARSSL_PLATFORM_SNPRINTF_MACRO snprintf /**< Default snprintf macro to use, can be undefined */
/* SSL Cache options */
//#define SSL_CACHE_DEFAULT_TIMEOUT 86400 /**< 1 day */

View file

@ -50,6 +50,9 @@ extern "C" {
#if !defined(POLARSSL_PLATFORM_NO_STD_FUNCTIONS)
#include <stdio.h>
#include <stdlib.h>
#if !defined(POLARSSL_PLATFORM_STD_SNPRINTF)
#define POLARSSL_PLATFORM_STD_SNPRINTF snprintf /**< Default snprintf to use */
#endif
#if !defined(POLARSSL_PLATFORM_STD_PRINTF)
#define POLARSSL_PLATFORM_STD_PRINTF printf /**< Default printf to use */
#endif
@ -62,6 +65,9 @@ extern "C" {
#if !defined(POLARSSL_PLATFORM_STD_FREE)
#define POLARSSL_PLATFORM_STD_FREE free /**< Default free to use */
#endif
#if !defined(POLARSSL_PLATFORM_STD_EXIT)
#define POLARSSL_PLATFORM_STD_EXIT exit /**< Default free to use */
#endif
#else /* POLARSSL_PLATFORM_NO_STD_FUNCTIONS */
#if defined(POLARSSL_PLATFORM_STD_MEM_HDR)
#include POLARSSL_PLATFORM_STD_MEM_HDR
@ -74,6 +80,11 @@ extern "C" {
* The function pointers for malloc and free
*/
#if defined(POLARSSL_PLATFORM_MEMORY)
#if defined(POLARSSL_PLATFORM_FREE_MACRO) &&\
defined(POLARSSL_PLATFORM_MALLOC_MACRO)
#define polarssl_free POLARSSL_PLATFORM_FREE_MACRO
#define polarssl_malloc POLARSSL_PLATFORM_MALLOC_MACRO
#else
extern void * (*polarssl_malloc)( size_t len );
extern void (*polarssl_free)( void *ptr );
@ -87,10 +98,34 @@ extern void (*polarssl_free)( void *ptr );
*/
int platform_set_malloc_free( void * (*malloc_func)( size_t ),
void (*free_func)( void * ) );
#endif /* POLARSSL_PLATFORM_FREE_MACRO && POLARSSL_PLATFORM_MALLOC_MACRO */
#else /* !POLARSSL_PLATFORM_MEMORY */
#define polarssl_malloc malloc
#define polarssl_free free
#endif /* POLARSSL_PLATFORM_MEMORY */
#define polarssl_free free
#define polarssl_malloc malloc
#endif /* POLARSSL_PLATFORM_MEMORY && !POLARSSL_PLATFORM_{FREE,MALLOC}_MACRO */
/*
* The function pointers for fprintf
*/
#if defined(POLARSSL_PLATFORM_FPRINTF_ALT)
extern int (*polarssl_fprintf)( FILE *stream, const char *format, ... );
/**
* \brief Set your own fprintf function pointer
*
* \param fprintf_func the fprintf function implementation
*
* \return 0
*/
int platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *,
... ) );
#else
#if defined(POLARSSL_PLATFORM_FPRINTF_MACRO)
#define polarssl_fprintf POLARSSL_PLATFORM_FPRINTF_MACRO
#else
#define polarssl_fprintf fprintf
#endif /* POLARSSL_PLATFORM_FPRINTF_MACRO */
#endif /* POLARSSL_PLATFORM_FPRINTF_ALT */
/*
* The function pointers for printf
@ -106,21 +141,58 @@ extern int (*polarssl_printf)( const char *format, ... );
* \return 0
*/
int platform_set_printf( int (*printf_func)( const char *, ... ) );
#else /* POLARSSL_PLATFORM_PRINTF_ALT */
#else /* !POLARSSL_PLATFORM_PRINTF_ALT */
#if defined(POLARSSL_PLATFORM_PRINTF_MACRO)
#define polarssl_printf POLARSSL_PLATFORM_PRINTF_MACRO
#else
#define polarssl_printf printf
#endif /* POLARSSL_PLATFORM_PRINTF_MACRO */
#endif /* POLARSSL_PLATFORM_PRINTF_ALT */
/*
* The function pointers for fprintf
* The function pointers for snprintf
*/
#if defined(POLARSSL_PLATFORM_FPRINTF_ALT)
extern int (*polarssl_fprintf)( FILE *stream, const char *format, ... );
#if defined(POLARSSL_PLATFORM_SNPRINTF_ALT)
extern int (*polarssl_snprintf)( char * s, size_t n, const char * format, ... );
int platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *,
... ) );
/**
* \brief Set your own snprintf function pointer
*
* \param snprintf_func the snprintf function implementation
*
* \return 0
*/
int platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
const char * format, ... ) );
#else /* POLARSSL_PLATFORM_SNPRINTF_ALT */
#if defined(POLARSSL_PLATFORM_SNPRINTF_MACRO)
#define polarssl_snprintf POLARSSL_PLATFORM_SNPRINTF_MACRO
#else
#define polarssl_fprintf fprintf
#endif
#define polarssl_snprintf snprintf
#endif /* POLARSSL_PLATFORM_SNPRINTF_MACRO */
#endif /* POLARSSL_PLATFORM_SNPRINTF_ALT */
/*
* The function pointers for exit
*/
#if defined(POLARSSL_PLATFORM_EXIT_ALT)
extern void (*polarssl_exit)( int status );
/**
* \brief Set your own exit function pointer
*
* \param exit_func the exit function implementation
*
* \return 0
*/
int platform_set_exit( void (*exit_func)( int status ) );
#else
#if defined(POLARSSL_PLATFORM_EXIT_MACRO)
#define polarssl_exit POLARSSL_PLATFORM_EXIT_MACRO
#else
#define polarssl_exit exit
#endif /* POLARSSL_PLATFORM_EXIT_MACRO */
#endif /* POLARSSL_PLATFORM_EXIT_ALT */
#ifdef __cplusplus
}