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