Pinned to some recent date

Committer:
Simon Cooksey
Date:
Thu Nov 17 16:43:53 2016 +0000
Revision:
0:fb7af294d5d9
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Simon Cooksey 0:fb7af294d5d9 1 /*
Simon Cooksey 0:fb7af294d5d9 2 * Platform abstraction layer
Simon Cooksey 0:fb7af294d5d9 3 *
Simon Cooksey 0:fb7af294d5d9 4 * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
Simon Cooksey 0:fb7af294d5d9 5 * SPDX-License-Identifier: Apache-2.0
Simon Cooksey 0:fb7af294d5d9 6 *
Simon Cooksey 0:fb7af294d5d9 7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
Simon Cooksey 0:fb7af294d5d9 8 * not use this file except in compliance with the License.
Simon Cooksey 0:fb7af294d5d9 9 * You may obtain a copy of the License at
Simon Cooksey 0:fb7af294d5d9 10 *
Simon Cooksey 0:fb7af294d5d9 11 * http://www.apache.org/licenses/LICENSE-2.0
Simon Cooksey 0:fb7af294d5d9 12 *
Simon Cooksey 0:fb7af294d5d9 13 * Unless required by applicable law or agreed to in writing, software
Simon Cooksey 0:fb7af294d5d9 14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
Simon Cooksey 0:fb7af294d5d9 15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Simon Cooksey 0:fb7af294d5d9 16 * See the License for the specific language governing permissions and
Simon Cooksey 0:fb7af294d5d9 17 * limitations under the License.
Simon Cooksey 0:fb7af294d5d9 18 *
Simon Cooksey 0:fb7af294d5d9 19 * This file is part of mbed TLS (https://tls.mbed.org)
Simon Cooksey 0:fb7af294d5d9 20 */
Simon Cooksey 0:fb7af294d5d9 21
Simon Cooksey 0:fb7af294d5d9 22 #if !defined(MBEDTLS_CONFIG_FILE)
Simon Cooksey 0:fb7af294d5d9 23 #include "mbedtls/config.h"
Simon Cooksey 0:fb7af294d5d9 24 #else
Simon Cooksey 0:fb7af294d5d9 25 #include MBEDTLS_CONFIG_FILE
Simon Cooksey 0:fb7af294d5d9 26 #endif
Simon Cooksey 0:fb7af294d5d9 27
Simon Cooksey 0:fb7af294d5d9 28 #if defined(MBEDTLS_PLATFORM_C)
Simon Cooksey 0:fb7af294d5d9 29
Simon Cooksey 0:fb7af294d5d9 30 #include "mbedtls/platform.h"
Simon Cooksey 0:fb7af294d5d9 31
Simon Cooksey 0:fb7af294d5d9 32 #if defined(MBEDTLS_PLATFORM_MEMORY)
Simon Cooksey 0:fb7af294d5d9 33 #if !defined(MBEDTLS_PLATFORM_STD_CALLOC)
Simon Cooksey 0:fb7af294d5d9 34 static void *platform_calloc_uninit( size_t n, size_t size )
Simon Cooksey 0:fb7af294d5d9 35 {
Simon Cooksey 0:fb7af294d5d9 36 ((void) n);
Simon Cooksey 0:fb7af294d5d9 37 ((void) size);
Simon Cooksey 0:fb7af294d5d9 38 return( NULL );
Simon Cooksey 0:fb7af294d5d9 39 }
Simon Cooksey 0:fb7af294d5d9 40
Simon Cooksey 0:fb7af294d5d9 41 #define MBEDTLS_PLATFORM_STD_CALLOC platform_calloc_uninit
Simon Cooksey 0:fb7af294d5d9 42 #endif /* !MBEDTLS_PLATFORM_STD_CALLOC */
Simon Cooksey 0:fb7af294d5d9 43
Simon Cooksey 0:fb7af294d5d9 44 #if !defined(MBEDTLS_PLATFORM_STD_FREE)
Simon Cooksey 0:fb7af294d5d9 45 static void platform_free_uninit( void *ptr )
Simon Cooksey 0:fb7af294d5d9 46 {
Simon Cooksey 0:fb7af294d5d9 47 ((void) ptr);
Simon Cooksey 0:fb7af294d5d9 48 }
Simon Cooksey 0:fb7af294d5d9 49
Simon Cooksey 0:fb7af294d5d9 50 #define MBEDTLS_PLATFORM_STD_FREE platform_free_uninit
Simon Cooksey 0:fb7af294d5d9 51 #endif /* !MBEDTLS_PLATFORM_STD_FREE */
Simon Cooksey 0:fb7af294d5d9 52
Simon Cooksey 0:fb7af294d5d9 53 void * (*mbedtls_calloc)( size_t, size_t ) = MBEDTLS_PLATFORM_STD_CALLOC;
Simon Cooksey 0:fb7af294d5d9 54 void (*mbedtls_free)( void * ) = MBEDTLS_PLATFORM_STD_FREE;
Simon Cooksey 0:fb7af294d5d9 55
Simon Cooksey 0:fb7af294d5d9 56 int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ),
Simon Cooksey 0:fb7af294d5d9 57 void (*free_func)( void * ) )
Simon Cooksey 0:fb7af294d5d9 58 {
Simon Cooksey 0:fb7af294d5d9 59 mbedtls_calloc = calloc_func;
Simon Cooksey 0:fb7af294d5d9 60 mbedtls_free = free_func;
Simon Cooksey 0:fb7af294d5d9 61 return( 0 );
Simon Cooksey 0:fb7af294d5d9 62 }
Simon Cooksey 0:fb7af294d5d9 63 #endif /* MBEDTLS_PLATFORM_MEMORY */
Simon Cooksey 0:fb7af294d5d9 64
Simon Cooksey 0:fb7af294d5d9 65 #if defined(_WIN32)
Simon Cooksey 0:fb7af294d5d9 66 #include <stdarg.h>
Simon Cooksey 0:fb7af294d5d9 67 int mbedtls_platform_win32_snprintf( char *s, size_t n, const char *fmt, ... )
Simon Cooksey 0:fb7af294d5d9 68 {
Simon Cooksey 0:fb7af294d5d9 69 int ret;
Simon Cooksey 0:fb7af294d5d9 70 va_list argp;
Simon Cooksey 0:fb7af294d5d9 71
Simon Cooksey 0:fb7af294d5d9 72 /* Avoid calling the invalid parameter handler by checking ourselves */
Simon Cooksey 0:fb7af294d5d9 73 if( s == NULL || n == 0 || fmt == NULL )
Simon Cooksey 0:fb7af294d5d9 74 return( -1 );
Simon Cooksey 0:fb7af294d5d9 75
Simon Cooksey 0:fb7af294d5d9 76 va_start( argp, fmt );
Simon Cooksey 0:fb7af294d5d9 77 #if defined(_TRUNCATE)
Simon Cooksey 0:fb7af294d5d9 78 ret = _vsnprintf_s( s, n, _TRUNCATE, fmt, argp );
Simon Cooksey 0:fb7af294d5d9 79 #else
Simon Cooksey 0:fb7af294d5d9 80 ret = _vsnprintf( s, n, fmt, argp );
Simon Cooksey 0:fb7af294d5d9 81 if( ret < 0 || (size_t) ret == n )
Simon Cooksey 0:fb7af294d5d9 82 {
Simon Cooksey 0:fb7af294d5d9 83 s[n-1] = '\0';
Simon Cooksey 0:fb7af294d5d9 84 ret = -1;
Simon Cooksey 0:fb7af294d5d9 85 }
Simon Cooksey 0:fb7af294d5d9 86 #endif
Simon Cooksey 0:fb7af294d5d9 87 va_end( argp );
Simon Cooksey 0:fb7af294d5d9 88
Simon Cooksey 0:fb7af294d5d9 89 return( ret );
Simon Cooksey 0:fb7af294d5d9 90 }
Simon Cooksey 0:fb7af294d5d9 91 #endif
Simon Cooksey 0:fb7af294d5d9 92
Simon Cooksey 0:fb7af294d5d9 93 #if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
Simon Cooksey 0:fb7af294d5d9 94 #if !defined(MBEDTLS_PLATFORM_STD_SNPRINTF)
Simon Cooksey 0:fb7af294d5d9 95 /*
Simon Cooksey 0:fb7af294d5d9 96 * Make dummy function to prevent NULL pointer dereferences
Simon Cooksey 0:fb7af294d5d9 97 */
Simon Cooksey 0:fb7af294d5d9 98 static int platform_snprintf_uninit( char * s, size_t n,
Simon Cooksey 0:fb7af294d5d9 99 const char * format, ... )
Simon Cooksey 0:fb7af294d5d9 100 {
Simon Cooksey 0:fb7af294d5d9 101 ((void) s);
Simon Cooksey 0:fb7af294d5d9 102 ((void) n);
Simon Cooksey 0:fb7af294d5d9 103 ((void) format);
Simon Cooksey 0:fb7af294d5d9 104 return( 0 );
Simon Cooksey 0:fb7af294d5d9 105 }
Simon Cooksey 0:fb7af294d5d9 106
Simon Cooksey 0:fb7af294d5d9 107 #define MBEDTLS_PLATFORM_STD_SNPRINTF platform_snprintf_uninit
Simon Cooksey 0:fb7af294d5d9 108 #endif /* !MBEDTLS_PLATFORM_STD_SNPRINTF */
Simon Cooksey 0:fb7af294d5d9 109
Simon Cooksey 0:fb7af294d5d9 110 int (*mbedtls_snprintf)( char * s, size_t n,
Simon Cooksey 0:fb7af294d5d9 111 const char * format,
Simon Cooksey 0:fb7af294d5d9 112 ... ) = MBEDTLS_PLATFORM_STD_SNPRINTF;
Simon Cooksey 0:fb7af294d5d9 113
Simon Cooksey 0:fb7af294d5d9 114 int mbedtls_platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
Simon Cooksey 0:fb7af294d5d9 115 const char * format,
Simon Cooksey 0:fb7af294d5d9 116 ... ) )
Simon Cooksey 0:fb7af294d5d9 117 {
Simon Cooksey 0:fb7af294d5d9 118 mbedtls_snprintf = snprintf_func;
Simon Cooksey 0:fb7af294d5d9 119 return( 0 );
Simon Cooksey 0:fb7af294d5d9 120 }
Simon Cooksey 0:fb7af294d5d9 121 #endif /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
Simon Cooksey 0:fb7af294d5d9 122
Simon Cooksey 0:fb7af294d5d9 123 #if defined(MBEDTLS_PLATFORM_PRINTF_ALT)
Simon Cooksey 0:fb7af294d5d9 124 #if !defined(MBEDTLS_PLATFORM_STD_PRINTF)
Simon Cooksey 0:fb7af294d5d9 125 /*
Simon Cooksey 0:fb7af294d5d9 126 * Make dummy function to prevent NULL pointer dereferences
Simon Cooksey 0:fb7af294d5d9 127 */
Simon Cooksey 0:fb7af294d5d9 128 static int platform_printf_uninit( const char *format, ... )
Simon Cooksey 0:fb7af294d5d9 129 {
Simon Cooksey 0:fb7af294d5d9 130 ((void) format);
Simon Cooksey 0:fb7af294d5d9 131 return( 0 );
Simon Cooksey 0:fb7af294d5d9 132 }
Simon Cooksey 0:fb7af294d5d9 133
Simon Cooksey 0:fb7af294d5d9 134 #define MBEDTLS_PLATFORM_STD_PRINTF platform_printf_uninit
Simon Cooksey 0:fb7af294d5d9 135 #endif /* !MBEDTLS_PLATFORM_STD_PRINTF */
Simon Cooksey 0:fb7af294d5d9 136
Simon Cooksey 0:fb7af294d5d9 137 int (*mbedtls_printf)( const char *, ... ) = MBEDTLS_PLATFORM_STD_PRINTF;
Simon Cooksey 0:fb7af294d5d9 138
Simon Cooksey 0:fb7af294d5d9 139 int mbedtls_platform_set_printf( int (*printf_func)( const char *, ... ) )
Simon Cooksey 0:fb7af294d5d9 140 {
Simon Cooksey 0:fb7af294d5d9 141 mbedtls_printf = printf_func;
Simon Cooksey 0:fb7af294d5d9 142 return( 0 );
Simon Cooksey 0:fb7af294d5d9 143 }
Simon Cooksey 0:fb7af294d5d9 144 #endif /* MBEDTLS_PLATFORM_PRINTF_ALT */
Simon Cooksey 0:fb7af294d5d9 145
Simon Cooksey 0:fb7af294d5d9 146 #if defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
Simon Cooksey 0:fb7af294d5d9 147 #if !defined(MBEDTLS_PLATFORM_STD_FPRINTF)
Simon Cooksey 0:fb7af294d5d9 148 /*
Simon Cooksey 0:fb7af294d5d9 149 * Make dummy function to prevent NULL pointer dereferences
Simon Cooksey 0:fb7af294d5d9 150 */
Simon Cooksey 0:fb7af294d5d9 151 static int platform_fprintf_uninit( FILE *stream, const char *format, ... )
Simon Cooksey 0:fb7af294d5d9 152 {
Simon Cooksey 0:fb7af294d5d9 153 ((void) stream);
Simon Cooksey 0:fb7af294d5d9 154 ((void) format);
Simon Cooksey 0:fb7af294d5d9 155 return( 0 );
Simon Cooksey 0:fb7af294d5d9 156 }
Simon Cooksey 0:fb7af294d5d9 157
Simon Cooksey 0:fb7af294d5d9 158 #define MBEDTLS_PLATFORM_STD_FPRINTF platform_fprintf_uninit
Simon Cooksey 0:fb7af294d5d9 159 #endif /* !MBEDTLS_PLATFORM_STD_FPRINTF */
Simon Cooksey 0:fb7af294d5d9 160
Simon Cooksey 0:fb7af294d5d9 161 int (*mbedtls_fprintf)( FILE *, const char *, ... ) =
Simon Cooksey 0:fb7af294d5d9 162 MBEDTLS_PLATFORM_STD_FPRINTF;
Simon Cooksey 0:fb7af294d5d9 163
Simon Cooksey 0:fb7af294d5d9 164 int mbedtls_platform_set_fprintf( int (*fprintf_func)( FILE *, const char *, ... ) )
Simon Cooksey 0:fb7af294d5d9 165 {
Simon Cooksey 0:fb7af294d5d9 166 mbedtls_fprintf = fprintf_func;
Simon Cooksey 0:fb7af294d5d9 167 return( 0 );
Simon Cooksey 0:fb7af294d5d9 168 }
Simon Cooksey 0:fb7af294d5d9 169 #endif /* MBEDTLS_PLATFORM_FPRINTF_ALT */
Simon Cooksey 0:fb7af294d5d9 170
Simon Cooksey 0:fb7af294d5d9 171 #if defined(MBEDTLS_PLATFORM_EXIT_ALT)
Simon Cooksey 0:fb7af294d5d9 172 #if !defined(MBEDTLS_PLATFORM_STD_EXIT)
Simon Cooksey 0:fb7af294d5d9 173 /*
Simon Cooksey 0:fb7af294d5d9 174 * Make dummy function to prevent NULL pointer dereferences
Simon Cooksey 0:fb7af294d5d9 175 */
Simon Cooksey 0:fb7af294d5d9 176 static void platform_exit_uninit( int status )
Simon Cooksey 0:fb7af294d5d9 177 {
Simon Cooksey 0:fb7af294d5d9 178 ((void) status);
Simon Cooksey 0:fb7af294d5d9 179 }
Simon Cooksey 0:fb7af294d5d9 180
Simon Cooksey 0:fb7af294d5d9 181 #define MBEDTLS_PLATFORM_STD_EXIT platform_exit_uninit
Simon Cooksey 0:fb7af294d5d9 182 #endif /* !MBEDTLS_PLATFORM_STD_EXIT */
Simon Cooksey 0:fb7af294d5d9 183
Simon Cooksey 0:fb7af294d5d9 184 void (*mbedtls_exit)( int status ) = MBEDTLS_PLATFORM_STD_EXIT;
Simon Cooksey 0:fb7af294d5d9 185
Simon Cooksey 0:fb7af294d5d9 186 int mbedtls_platform_set_exit( void (*exit_func)( int status ) )
Simon Cooksey 0:fb7af294d5d9 187 {
Simon Cooksey 0:fb7af294d5d9 188 mbedtls_exit = exit_func;
Simon Cooksey 0:fb7af294d5d9 189 return( 0 );
Simon Cooksey 0:fb7af294d5d9 190 }
Simon Cooksey 0:fb7af294d5d9 191 #endif /* MBEDTLS_PLATFORM_EXIT_ALT */
Simon Cooksey 0:fb7af294d5d9 192
Simon Cooksey 0:fb7af294d5d9 193 #if defined(MBEDTLS_HAVE_TIME)
Simon Cooksey 0:fb7af294d5d9 194
Simon Cooksey 0:fb7af294d5d9 195 #if defined(MBEDTLS_PLATFORM_TIME_ALT)
Simon Cooksey 0:fb7af294d5d9 196 #if !defined(MBEDTLS_PLATFORM_STD_TIME)
Simon Cooksey 0:fb7af294d5d9 197 /*
Simon Cooksey 0:fb7af294d5d9 198 * Make dummy function to prevent NULL pointer dereferences
Simon Cooksey 0:fb7af294d5d9 199 */
Simon Cooksey 0:fb7af294d5d9 200 static mbedtls_time_t platform_time_uninit( mbedtls_time_t* timer )
Simon Cooksey 0:fb7af294d5d9 201 {
Simon Cooksey 0:fb7af294d5d9 202 ((void) timer);
Simon Cooksey 0:fb7af294d5d9 203 return( 0 );
Simon Cooksey 0:fb7af294d5d9 204 }
Simon Cooksey 0:fb7af294d5d9 205
Simon Cooksey 0:fb7af294d5d9 206 #define MBEDTLS_PLATFORM_STD_TIME platform_time_uninit
Simon Cooksey 0:fb7af294d5d9 207 #endif /* !MBEDTLS_PLATFORM_STD_TIME */
Simon Cooksey 0:fb7af294d5d9 208
Simon Cooksey 0:fb7af294d5d9 209 mbedtls_time_t (*mbedtls_time)( mbedtls_time_t* timer ) = MBEDTLS_PLATFORM_STD_TIME;
Simon Cooksey 0:fb7af294d5d9 210
Simon Cooksey 0:fb7af294d5d9 211 int mbedtls_platform_set_time( mbedtls_time_t (*time_func)( mbedtls_time_t* timer ) )
Simon Cooksey 0:fb7af294d5d9 212 {
Simon Cooksey 0:fb7af294d5d9 213 mbedtls_time = time_func;
Simon Cooksey 0:fb7af294d5d9 214 return( 0 );
Simon Cooksey 0:fb7af294d5d9 215 }
Simon Cooksey 0:fb7af294d5d9 216 #endif /* MBEDTLS_PLATFORM_TIME_ALT */
Simon Cooksey 0:fb7af294d5d9 217
Simon Cooksey 0:fb7af294d5d9 218 #endif /* MBEDTLS_HAVE_TIME */
Simon Cooksey 0:fb7af294d5d9 219
Simon Cooksey 0:fb7af294d5d9 220 #if defined(MBEDTLS_ENTROPY_NV_SEED)
Simon Cooksey 0:fb7af294d5d9 221 #if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS) && defined(MBEDTLS_FS_IO)
Simon Cooksey 0:fb7af294d5d9 222 /* Default implementations for the platform independent seed functions use
Simon Cooksey 0:fb7af294d5d9 223 * standard libc file functions to read from and write to a pre-defined filename
Simon Cooksey 0:fb7af294d5d9 224 */
Simon Cooksey 0:fb7af294d5d9 225 int mbedtls_platform_std_nv_seed_read( unsigned char *buf, size_t buf_len )
Simon Cooksey 0:fb7af294d5d9 226 {
Simon Cooksey 0:fb7af294d5d9 227 FILE *file;
Simon Cooksey 0:fb7af294d5d9 228 size_t n;
Simon Cooksey 0:fb7af294d5d9 229
Simon Cooksey 0:fb7af294d5d9 230 if( ( file = fopen( MBEDTLS_PLATFORM_STD_NV_SEED_FILE, "rb" ) ) == NULL )
Simon Cooksey 0:fb7af294d5d9 231 return -1;
Simon Cooksey 0:fb7af294d5d9 232
Simon Cooksey 0:fb7af294d5d9 233 if( ( n = fread( buf, 1, buf_len, file ) ) != buf_len )
Simon Cooksey 0:fb7af294d5d9 234 {
Simon Cooksey 0:fb7af294d5d9 235 fclose( file );
Simon Cooksey 0:fb7af294d5d9 236 return -1;
Simon Cooksey 0:fb7af294d5d9 237 }
Simon Cooksey 0:fb7af294d5d9 238
Simon Cooksey 0:fb7af294d5d9 239 fclose( file );
Simon Cooksey 0:fb7af294d5d9 240 return( n );
Simon Cooksey 0:fb7af294d5d9 241 }
Simon Cooksey 0:fb7af294d5d9 242
Simon Cooksey 0:fb7af294d5d9 243 int mbedtls_platform_std_nv_seed_write( unsigned char *buf, size_t buf_len )
Simon Cooksey 0:fb7af294d5d9 244 {
Simon Cooksey 0:fb7af294d5d9 245 FILE *file;
Simon Cooksey 0:fb7af294d5d9 246 size_t n;
Simon Cooksey 0:fb7af294d5d9 247
Simon Cooksey 0:fb7af294d5d9 248 if( ( file = fopen( MBEDTLS_PLATFORM_STD_NV_SEED_FILE, "w" ) ) == NULL )
Simon Cooksey 0:fb7af294d5d9 249 return -1;
Simon Cooksey 0:fb7af294d5d9 250
Simon Cooksey 0:fb7af294d5d9 251 if( ( n = fwrite( buf, 1, buf_len, file ) ) != buf_len )
Simon Cooksey 0:fb7af294d5d9 252 {
Simon Cooksey 0:fb7af294d5d9 253 fclose( file );
Simon Cooksey 0:fb7af294d5d9 254 return -1;
Simon Cooksey 0:fb7af294d5d9 255 }
Simon Cooksey 0:fb7af294d5d9 256
Simon Cooksey 0:fb7af294d5d9 257 fclose( file );
Simon Cooksey 0:fb7af294d5d9 258 return( n );
Simon Cooksey 0:fb7af294d5d9 259 }
Simon Cooksey 0:fb7af294d5d9 260 #endif /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
Simon Cooksey 0:fb7af294d5d9 261
Simon Cooksey 0:fb7af294d5d9 262 #if defined(MBEDTLS_PLATFORM_NV_SEED_ALT)
Simon Cooksey 0:fb7af294d5d9 263 #if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_READ)
Simon Cooksey 0:fb7af294d5d9 264 /*
Simon Cooksey 0:fb7af294d5d9 265 * Make dummy function to prevent NULL pointer dereferences
Simon Cooksey 0:fb7af294d5d9 266 */
Simon Cooksey 0:fb7af294d5d9 267 static int platform_nv_seed_read_uninit( unsigned char *buf, size_t buf_len )
Simon Cooksey 0:fb7af294d5d9 268 {
Simon Cooksey 0:fb7af294d5d9 269 ((void) buf);
Simon Cooksey 0:fb7af294d5d9 270 ((void) buf_len);
Simon Cooksey 0:fb7af294d5d9 271 return( -1 );
Simon Cooksey 0:fb7af294d5d9 272 }
Simon Cooksey 0:fb7af294d5d9 273
Simon Cooksey 0:fb7af294d5d9 274 #define MBEDTLS_PLATFORM_STD_NV_SEED_READ platform_nv_seed_read_uninit
Simon Cooksey 0:fb7af294d5d9 275 #endif /* !MBEDTLS_PLATFORM_STD_NV_SEED_READ */
Simon Cooksey 0:fb7af294d5d9 276
Simon Cooksey 0:fb7af294d5d9 277 #if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_WRITE)
Simon Cooksey 0:fb7af294d5d9 278 /*
Simon Cooksey 0:fb7af294d5d9 279 * Make dummy function to prevent NULL pointer dereferences
Simon Cooksey 0:fb7af294d5d9 280 */
Simon Cooksey 0:fb7af294d5d9 281 static int platform_nv_seed_write_uninit( unsigned char *buf, size_t buf_len )
Simon Cooksey 0:fb7af294d5d9 282 {
Simon Cooksey 0:fb7af294d5d9 283 ((void) buf);
Simon Cooksey 0:fb7af294d5d9 284 ((void) buf_len);
Simon Cooksey 0:fb7af294d5d9 285 return( -1 );
Simon Cooksey 0:fb7af294d5d9 286 }
Simon Cooksey 0:fb7af294d5d9 287
Simon Cooksey 0:fb7af294d5d9 288 #define MBEDTLS_PLATFORM_STD_NV_SEED_WRITE platform_nv_seed_write_uninit
Simon Cooksey 0:fb7af294d5d9 289 #endif /* !MBEDTLS_PLATFORM_STD_NV_SEED_WRITE */
Simon Cooksey 0:fb7af294d5d9 290
Simon Cooksey 0:fb7af294d5d9 291 int (*mbedtls_nv_seed_read)( unsigned char *buf, size_t buf_len ) =
Simon Cooksey 0:fb7af294d5d9 292 MBEDTLS_PLATFORM_STD_NV_SEED_READ;
Simon Cooksey 0:fb7af294d5d9 293 int (*mbedtls_nv_seed_write)( unsigned char *buf, size_t buf_len ) =
Simon Cooksey 0:fb7af294d5d9 294 MBEDTLS_PLATFORM_STD_NV_SEED_WRITE;
Simon Cooksey 0:fb7af294d5d9 295
Simon Cooksey 0:fb7af294d5d9 296 int mbedtls_platform_set_nv_seed(
Simon Cooksey 0:fb7af294d5d9 297 int (*nv_seed_read_func)( unsigned char *buf, size_t buf_len ),
Simon Cooksey 0:fb7af294d5d9 298 int (*nv_seed_write_func)( unsigned char *buf, size_t buf_len ) )
Simon Cooksey 0:fb7af294d5d9 299 {
Simon Cooksey 0:fb7af294d5d9 300 mbedtls_nv_seed_read = nv_seed_read_func;
Simon Cooksey 0:fb7af294d5d9 301 mbedtls_nv_seed_write = nv_seed_write_func;
Simon Cooksey 0:fb7af294d5d9 302 return( 0 );
Simon Cooksey 0:fb7af294d5d9 303 }
Simon Cooksey 0:fb7af294d5d9 304 #endif /* MBEDTLS_PLATFORM_NV_SEED_ALT */
Simon Cooksey 0:fb7af294d5d9 305 #endif /* MBEDTLS_ENTROPY_NV_SEED */
Simon Cooksey 0:fb7af294d5d9 306
Simon Cooksey 0:fb7af294d5d9 307 #endif /* MBEDTLS_PLATFORM_C */