mbed TLS library

Dependents:   HTTPClient-SSL WS_SERVER

Committer:
ansond
Date:
Thu Jun 11 03:27:03 2015 +0000
Revision:
0:137634ff4186
initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:137634ff4186 1 /*
ansond 0:137634ff4186 2 * Platform abstraction layer
ansond 0:137634ff4186 3 *
ansond 0:137634ff4186 4 * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
ansond 0:137634ff4186 5 *
ansond 0:137634ff4186 6 * This file is part of mbed TLS (https://tls.mbed.org)
ansond 0:137634ff4186 7 *
ansond 0:137634ff4186 8 * This program is free software; you can redistribute it and/or modify
ansond 0:137634ff4186 9 * it under the terms of the GNU General Public License as published by
ansond 0:137634ff4186 10 * the Free Software Foundation; either version 2 of the License, or
ansond 0:137634ff4186 11 * (at your option) any later version.
ansond 0:137634ff4186 12 *
ansond 0:137634ff4186 13 * This program is distributed in the hope that it will be useful,
ansond 0:137634ff4186 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ansond 0:137634ff4186 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ansond 0:137634ff4186 16 * GNU General Public License for more details.
ansond 0:137634ff4186 17 *
ansond 0:137634ff4186 18 * You should have received a copy of the GNU General Public License along
ansond 0:137634ff4186 19 * with this program; if not, write to the Free Software Foundation, Inc.,
ansond 0:137634ff4186 20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
ansond 0:137634ff4186 21 */
ansond 0:137634ff4186 22
ansond 0:137634ff4186 23 #if !defined(POLARSSL_CONFIG_FILE)
ansond 0:137634ff4186 24 #include "polarssl/config.h"
ansond 0:137634ff4186 25 #else
ansond 0:137634ff4186 26 #include POLARSSL_CONFIG_FILE
ansond 0:137634ff4186 27 #endif
ansond 0:137634ff4186 28
ansond 0:137634ff4186 29 #if defined(POLARSSL_PLATFORM_C)
ansond 0:137634ff4186 30
ansond 0:137634ff4186 31 #include "polarssl/platform.h"
ansond 0:137634ff4186 32
ansond 0:137634ff4186 33 #if defined(POLARSSL_PLATFORM_MEMORY)
ansond 0:137634ff4186 34 #if !defined(POLARSSL_PLATFORM_STD_MALLOC)
ansond 0:137634ff4186 35 static void *platform_malloc_uninit( size_t len )
ansond 0:137634ff4186 36 {
ansond 0:137634ff4186 37 ((void) len);
ansond 0:137634ff4186 38 return( NULL );
ansond 0:137634ff4186 39 }
ansond 0:137634ff4186 40
ansond 0:137634ff4186 41 #define POLARSSL_PLATFORM_STD_MALLOC platform_malloc_uninit
ansond 0:137634ff4186 42 #endif /* !POLARSSL_PLATFORM_STD_MALLOC */
ansond 0:137634ff4186 43
ansond 0:137634ff4186 44 #if !defined(POLARSSL_PLATFORM_STD_FREE)
ansond 0:137634ff4186 45 static void platform_free_uninit( void *ptr )
ansond 0:137634ff4186 46 {
ansond 0:137634ff4186 47 ((void) ptr);
ansond 0:137634ff4186 48 }
ansond 0:137634ff4186 49
ansond 0:137634ff4186 50 #define POLARSSL_PLATFORM_STD_FREE platform_free_uninit
ansond 0:137634ff4186 51 #endif /* !POLARSSL_PLATFORM_STD_FREE */
ansond 0:137634ff4186 52
ansond 0:137634ff4186 53 void * (*polarssl_malloc)( size_t ) = POLARSSL_PLATFORM_STD_MALLOC;
ansond 0:137634ff4186 54 void (*polarssl_free)( void * ) = POLARSSL_PLATFORM_STD_FREE;
ansond 0:137634ff4186 55
ansond 0:137634ff4186 56 int platform_set_malloc_free( void * (*malloc_func)( size_t ),
ansond 0:137634ff4186 57 void (*free_func)( void * ) )
ansond 0:137634ff4186 58 {
ansond 0:137634ff4186 59 polarssl_malloc = malloc_func;
ansond 0:137634ff4186 60 polarssl_free = free_func;
ansond 0:137634ff4186 61 return( 0 );
ansond 0:137634ff4186 62 }
ansond 0:137634ff4186 63 #endif /* POLARSSL_PLATFORM_MEMORY */
ansond 0:137634ff4186 64
ansond 0:137634ff4186 65 #if defined(POLARSSL_PLATFORM_SNPRINTF_ALT)
ansond 0:137634ff4186 66 #if !defined(POLARSSL_PLATFORM_STD_SNPRINTF)
ansond 0:137634ff4186 67 /*
ansond 0:137634ff4186 68 * Make dummy function to prevent NULL pointer dereferences
ansond 0:137634ff4186 69 */
ansond 0:137634ff4186 70 static int platform_snprintf_uninit( char * s, size_t n,
ansond 0:137634ff4186 71 const char * format, ... )
ansond 0:137634ff4186 72 {
ansond 0:137634ff4186 73 ((void) s);
ansond 0:137634ff4186 74 ((void) n);
ansond 0:137634ff4186 75 ((void) format);
ansond 0:137634ff4186 76 return( 0 );
ansond 0:137634ff4186 77 }
ansond 0:137634ff4186 78
ansond 0:137634ff4186 79 #define POLARSSL_PLATFORM_STD_SNPRINTF platform_snprintf_uninit
ansond 0:137634ff4186 80 #endif /* !POLARSSL_PLATFORM_STD_SNPRINTF */
ansond 0:137634ff4186 81
ansond 0:137634ff4186 82 int (*polarssl_snprintf)( char * s, size_t n,
ansond 0:137634ff4186 83 const char * format,
ansond 0:137634ff4186 84 ... ) = POLARSSL_PLATFORM_STD_SNPRINTF;
ansond 0:137634ff4186 85
ansond 0:137634ff4186 86 int platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
ansond 0:137634ff4186 87 const char * format,
ansond 0:137634ff4186 88 ... ) )
ansond 0:137634ff4186 89 {
ansond 0:137634ff4186 90 polarssl_snprintf = snprintf_func;
ansond 0:137634ff4186 91 return( 0 );
ansond 0:137634ff4186 92 }
ansond 0:137634ff4186 93 #endif /* POLARSSL_PLATFORM_SNPRINTF_ALT */
ansond 0:137634ff4186 94
ansond 0:137634ff4186 95 #if defined(POLARSSL_PLATFORM_PRINTF_ALT)
ansond 0:137634ff4186 96 #if !defined(POLARSSL_PLATFORM_STD_PRINTF)
ansond 0:137634ff4186 97 /*
ansond 0:137634ff4186 98 * Make dummy function to prevent NULL pointer dereferences
ansond 0:137634ff4186 99 */
ansond 0:137634ff4186 100 static int platform_printf_uninit( const char *format, ... )
ansond 0:137634ff4186 101 {
ansond 0:137634ff4186 102 ((void) format);
ansond 0:137634ff4186 103 return( 0 );
ansond 0:137634ff4186 104 }
ansond 0:137634ff4186 105
ansond 0:137634ff4186 106 #define POLARSSL_PLATFORM_STD_PRINTF platform_printf_uninit
ansond 0:137634ff4186 107 #endif /* !POLARSSL_PLATFORM_STD_PRINTF */
ansond 0:137634ff4186 108
ansond 0:137634ff4186 109 int (*polarssl_printf)( const char *, ... ) = POLARSSL_PLATFORM_STD_PRINTF;
ansond 0:137634ff4186 110
ansond 0:137634ff4186 111 int platform_set_printf( int (*printf_func)( const char *, ... ) )
ansond 0:137634ff4186 112 {
ansond 0:137634ff4186 113 polarssl_printf = printf_func;
ansond 0:137634ff4186 114 return( 0 );
ansond 0:137634ff4186 115 }
ansond 0:137634ff4186 116 #endif /* POLARSSL_PLATFORM_PRINTF_ALT */
ansond 0:137634ff4186 117
ansond 0:137634ff4186 118 #if defined(POLARSSL_PLATFORM_FPRINTF_ALT)
ansond 0:137634ff4186 119 #if !defined(POLARSSL_PLATFORM_STD_FPRINTF)
ansond 0:137634ff4186 120 /*
ansond 0:137634ff4186 121 * Make dummy function to prevent NULL pointer dereferences
ansond 0:137634ff4186 122 */
ansond 0:137634ff4186 123 static int platform_fprintf_uninit( FILE *stream, const char *format, ... )
ansond 0:137634ff4186 124 {
ansond 0:137634ff4186 125 ((void) stream);
ansond 0:137634ff4186 126 ((void) format);
ansond 0:137634ff4186 127 return( 0 );
ansond 0:137634ff4186 128 }
ansond 0:137634ff4186 129
ansond 0:137634ff4186 130 #define POLARSSL_PLATFORM_STD_FPRINTF platform_fprintf_uninit
ansond 0:137634ff4186 131 #endif /* !POLARSSL_PLATFORM_STD_FPRINTF */
ansond 0:137634ff4186 132
ansond 0:137634ff4186 133 int (*polarssl_fprintf)( FILE *, const char *, ... ) =
ansond 0:137634ff4186 134 POLARSSL_PLATFORM_STD_FPRINTF;
ansond 0:137634ff4186 135
ansond 0:137634ff4186 136 int platform_set_fprintf( int (*fprintf_func)( FILE *, const char *, ... ) )
ansond 0:137634ff4186 137 {
ansond 0:137634ff4186 138 polarssl_fprintf = fprintf_func;
ansond 0:137634ff4186 139 return( 0 );
ansond 0:137634ff4186 140 }
ansond 0:137634ff4186 141 #endif /* POLARSSL_PLATFORM_FPRINTF_ALT */
ansond 0:137634ff4186 142
ansond 0:137634ff4186 143 #if defined(POLARSSL_PLATFORM_EXIT_ALT)
ansond 0:137634ff4186 144 #if !defined(POLARSSL_PLATFORM_STD_EXIT)
ansond 0:137634ff4186 145 /*
ansond 0:137634ff4186 146 * Make dummy function to prevent NULL pointer dereferences
ansond 0:137634ff4186 147 */
ansond 0:137634ff4186 148 static void platform_exit_uninit( int status )
ansond 0:137634ff4186 149 {
ansond 0:137634ff4186 150 ((void) status);
ansond 0:137634ff4186 151 }
ansond 0:137634ff4186 152
ansond 0:137634ff4186 153 #define POLARSSL_PLATFORM_STD_EXIT platform_exit_uninit
ansond 0:137634ff4186 154 #endif /* !POLARSSL_PLATFORM_STD_EXIT */
ansond 0:137634ff4186 155
ansond 0:137634ff4186 156 void (*polarssl_exit)( int status ) = POLARSSL_PLATFORM_STD_EXIT;
ansond 0:137634ff4186 157
ansond 0:137634ff4186 158 int platform_set_exit( void (*exit_func)( int status ) )
ansond 0:137634ff4186 159 {
ansond 0:137634ff4186 160 polarssl_exit = exit_func;
ansond 0:137634ff4186 161 return( 0 );
ansond 0:137634ff4186 162 }
ansond 0:137634ff4186 163 #endif /* POLARSSL_PLATFORM_EXIT_ALT */
ansond 0:137634ff4186 164
ansond 0:137634ff4186 165 #endif /* POLARSSL_PLATFORM_C */
ansond 0:137634ff4186 166