Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file platform.h |
| 3 | * |
Rose Zadik | 4bca2b0 | 2018-03-27 13:12:52 +0100 | [diff] [blame] | 4 | * \brief This file contains the definitions and functions of the |
| 5 | * Mbed TLS platform abstraction layer. |
Rose Zadik | 9464d7b | 2018-04-16 15:28:35 +0100 | [diff] [blame] | 6 | * |
| 7 | * The platform abstraction layer removes the need for the library |
| 8 | * to directly link to standard C library functions or operating |
| 9 | * system services, making the library easier to port and embed. |
| 10 | * Application developers and users of the library can provide their own |
| 11 | * implementations of these functions, or implementations specific to |
Darryl Green | 11999bb | 2018-03-13 15:22:58 +0000 | [diff] [blame] | 12 | * their platform, which can be statically linked to the library or |
Rose Zadik | 9464d7b | 2018-04-16 15:28:35 +0100 | [diff] [blame] | 13 | * dynamically configured at runtime. |
Gilles Peskine | 04e4c19 | 2022-09-15 20:19:01 +0200 | [diff] [blame] | 14 | * |
| 15 | * When all compilation options related to platform abstraction are |
| 16 | * disabled, this header just defines `mbedtls_xxx` function names |
| 17 | * as aliases to the standard `xxx` function. |
| 18 | * |
| 19 | * Most modules in the library and example programs are expected to |
| 20 | * include this header. |
Darryl Green | a40a101 | 2018-01-05 15:33:17 +0000 | [diff] [blame] | 21 | */ |
| 22 | /* |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 23 | * Copyright The Mbed TLS Contributors |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 24 | * SPDX-License-Identifier: Apache-2.0 |
| 25 | * |
| 26 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 27 | * not use this file except in compliance with the License. |
| 28 | * You may obtain a copy of the License at |
| 29 | * |
| 30 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 31 | * |
| 32 | * Unless required by applicable law or agreed to in writing, software |
| 33 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 34 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 35 | * See the License for the specific language governing permissions and |
| 36 | * limitations under the License. |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 37 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 38 | #ifndef MBEDTLS_PLATFORM_H |
| 39 | #define MBEDTLS_PLATFORM_H |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 40 | #include "mbedtls/private_access.h" |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 41 | |
Bence Szépkúti | c662b36 | 2021-05-27 11:25:03 +0200 | [diff] [blame] | 42 | #include "mbedtls/build_info.h" |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 43 | |
Simon Butcher | b5b6af2 | 2016-07-13 14:46:18 +0100 | [diff] [blame] | 44 | #if defined(MBEDTLS_HAVE_TIME) |
Jaeden Amero | c49fbbf | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 45 | #include "mbedtls/platform_time.h" |
Simon Butcher | b5b6af2 | 2016-07-13 14:46:18 +0100 | [diff] [blame] | 46 | #endif |
| 47 | |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 48 | #ifdef __cplusplus |
| 49 | extern "C" { |
| 50 | #endif |
| 51 | |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 52 | /** |
| 53 | * \name SECTION: Module settings |
| 54 | * |
| 55 | * The configuration options you can set for this module are in this section. |
Bence Szépkúti | bb0cfeb | 2021-05-28 09:42:25 +0200 | [diff] [blame] | 56 | * Either change them in mbedtls_config.h or define them on the compiler command line. |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 57 | * \{ |
| 58 | */ |
| 59 | |
k-stachowiak | 723f867 | 2018-07-16 14:27:07 +0200 | [diff] [blame] | 60 | /* The older Microsoft Windows common runtime provides non-conforming |
| 61 | * implementations of some standard library functions, including snprintf |
| 62 | * and vsnprintf. This affects MSVC and MinGW builds. |
| 63 | */ |
Krzysztof Stachowiak | 2cdb6b4 | 2018-10-22 10:43:56 +0200 | [diff] [blame] | 64 | #if defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER <= 1900) |
k-stachowiak | 723f867 | 2018-07-16 14:27:07 +0200 | [diff] [blame] | 65 | #define MBEDTLS_PLATFORM_HAS_NON_CONFORMING_SNPRINTF |
| 66 | #define MBEDTLS_PLATFORM_HAS_NON_CONFORMING_VSNPRINTF |
| 67 | #endif |
| 68 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 69 | #if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS) |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 70 | #include <stdio.h> |
Paul Bakker | a9066cf | 2014-02-05 15:13:04 +0100 | [diff] [blame] | 71 | #include <stdlib.h> |
Daniel Axtens | f071024 | 2020-05-28 11:43:41 +1000 | [diff] [blame] | 72 | #if defined(MBEDTLS_HAVE_TIME) |
Simon Butcher | 3fe6cd3 | 2016-04-26 19:51:29 +0100 | [diff] [blame] | 73 | #include <time.h> |
Daniel Axtens | f071024 | 2020-05-28 11:43:41 +1000 | [diff] [blame] | 74 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 75 | #if !defined(MBEDTLS_PLATFORM_STD_SNPRINTF) |
k-stachowiak | 723f867 | 2018-07-16 14:27:07 +0200 | [diff] [blame] | 76 | #if defined(MBEDTLS_PLATFORM_HAS_NON_CONFORMING_SNPRINTF) |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 77 | #define MBEDTLS_PLATFORM_STD_SNPRINTF mbedtls_platform_win32_snprintf /**< The default \c snprintf function to use. */ |
Manuel Pégourié-Gonnard | 6c0c8e0 | 2015-06-22 10:23:34 +0200 | [diff] [blame] | 78 | #else |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 79 | #define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf /**< The default \c snprintf function to use. */ |
Rich Evans | 46b0a8d | 2015-01-30 10:47:32 +0000 | [diff] [blame] | 80 | #endif |
Manuel Pégourié-Gonnard | 6c0c8e0 | 2015-06-22 10:23:34 +0200 | [diff] [blame] | 81 | #endif |
k-stachowiak | 723f867 | 2018-07-16 14:27:07 +0200 | [diff] [blame] | 82 | #if !defined(MBEDTLS_PLATFORM_STD_VSNPRINTF) |
| 83 | #if defined(MBEDTLS_PLATFORM_HAS_NON_CONFORMING_VSNPRINTF) |
| 84 | #define MBEDTLS_PLATFORM_STD_VSNPRINTF mbedtls_platform_win32_vsnprintf /**< The default \c vsnprintf function to use. */ |
| 85 | #else |
| 86 | #define MBEDTLS_PLATFORM_STD_VSNPRINTF vsnprintf /**< The default \c vsnprintf function to use. */ |
| 87 | #endif |
| 88 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 89 | #if !defined(MBEDTLS_PLATFORM_STD_PRINTF) |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 90 | #define MBEDTLS_PLATFORM_STD_PRINTF printf /**< The default \c printf function to use. */ |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 91 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 92 | #if !defined(MBEDTLS_PLATFORM_STD_FPRINTF) |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 93 | #define MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< The default \c fprintf function to use. */ |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 94 | #endif |
Manuel Pégourié-Gonnard | b9ef118 | 2015-05-26 16:15:20 +0200 | [diff] [blame] | 95 | #if !defined(MBEDTLS_PLATFORM_STD_CALLOC) |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 96 | #define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< The default \c calloc function to use. */ |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 97 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 98 | #if !defined(MBEDTLS_PLATFORM_STD_FREE) |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 99 | #define MBEDTLS_PLATFORM_STD_FREE free /**< The default \c free function to use. */ |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 100 | #endif |
Gilles Peskine | 6497b5a | 2022-06-30 17:01:40 +0200 | [diff] [blame] | 101 | #if !defined(MBEDTLS_PLATFORM_STD_SETBUF) |
| 102 | #define MBEDTLS_PLATFORM_STD_SETBUF setbuf /**< The default \c setbuf function to use. */ |
| 103 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 104 | #if !defined(MBEDTLS_PLATFORM_STD_EXIT) |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 105 | #define MBEDTLS_PLATFORM_STD_EXIT exit /**< The default \c exit function to use. */ |
Janos Follath | 9194744 | 2016-03-18 13:49:27 +0000 | [diff] [blame] | 106 | #endif |
SimonB | d5800b7 | 2016-04-26 07:43:27 +0100 | [diff] [blame] | 107 | #if !defined(MBEDTLS_PLATFORM_STD_TIME) |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 108 | #define MBEDTLS_PLATFORM_STD_TIME time /**< The default \c time function to use. */ |
SimonB | d5800b7 | 2016-04-26 07:43:27 +0100 | [diff] [blame] | 109 | #endif |
Janos Follath | 9194744 | 2016-03-18 13:49:27 +0000 | [diff] [blame] | 110 | #if !defined(MBEDTLS_PLATFORM_STD_EXIT_SUCCESS) |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 111 | #define MBEDTLS_PLATFORM_STD_EXIT_SUCCESS EXIT_SUCCESS /**< The default exit value to use. */ |
Janos Follath | 9194744 | 2016-03-18 13:49:27 +0000 | [diff] [blame] | 112 | #endif |
| 113 | #if !defined(MBEDTLS_PLATFORM_STD_EXIT_FAILURE) |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 114 | #define MBEDTLS_PLATFORM_STD_EXIT_FAILURE EXIT_FAILURE /**< The default exit value to use. */ |
Rich Evans | c39cb49 | 2015-01-30 12:01:34 +0000 | [diff] [blame] | 115 | #endif |
Paul Bakker | a9c321c | 2016-06-01 11:44:12 +0100 | [diff] [blame] | 116 | #if defined(MBEDTLS_FS_IO) |
Paul Bakker | e021a4b | 2016-06-01 11:25:44 +0100 | [diff] [blame] | 117 | #if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_READ) |
| 118 | #define MBEDTLS_PLATFORM_STD_NV_SEED_READ mbedtls_platform_std_nv_seed_read |
| 119 | #endif |
| 120 | #if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_WRITE) |
| 121 | #define MBEDTLS_PLATFORM_STD_NV_SEED_WRITE mbedtls_platform_std_nv_seed_write |
| 122 | #endif |
| 123 | #if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_FILE) |
| 124 | #define MBEDTLS_PLATFORM_STD_NV_SEED_FILE "seedfile" |
| 125 | #endif |
Paul Bakker | a9c321c | 2016-06-01 11:44:12 +0100 | [diff] [blame] | 126 | #endif /* MBEDTLS_FS_IO */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 127 | #else /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */ |
| 128 | #if defined(MBEDTLS_PLATFORM_STD_MEM_HDR) |
| 129 | #include MBEDTLS_PLATFORM_STD_MEM_HDR |
Manuel Pégourié-Gonnard | eb82a74 | 2014-04-02 13:43:48 +0200 | [diff] [blame] | 130 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 131 | #endif /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */ |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 132 | |
Andrzej Kurek | 2b3c06e | 2023-07-03 06:52:37 -0400 | [diff] [blame^] | 133 | /* Enable certain documented defines only when generating doxygen to avoid |
| 134 | * an "unrecognized define" error. */ |
| 135 | #if defined(__DOXYGEN__) && !defined(MBEDTLS_PLATFORM_STD_CALLOC) |
| 136 | #define MBEDTLS_PLATFORM_STD_CALLOC |
| 137 | #endif |
| 138 | |
| 139 | #if defined(__DOXYGEN__) && !defined(MBEDTLS_PLATFORM_STD_FREE) |
| 140 | #define MBEDTLS_PLATFORM_STD_FREE |
| 141 | #endif |
Paul Bakker | e021a4b | 2016-06-01 11:25:44 +0100 | [diff] [blame] | 142 | |
Andrzej Kurek | 38d4fdd | 2021-12-28 16:22:52 +0100 | [diff] [blame] | 143 | /** \} name SECTION: Module settings */ |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 144 | |
| 145 | /* |
Rose Zadik | 4bca2b0 | 2018-03-27 13:12:52 +0100 | [diff] [blame] | 146 | * The function pointers for calloc and free. |
Andrzej Kurek | ecaf6fb | 2023-05-04 17:07:57 -0400 | [diff] [blame] | 147 | * Please see MBEDTLS_PLATFORM_STD_CALLOC and MBEDTLS_PLATFORM_STD_FREE |
Andrzej Kurek | 2d981f0 | 2023-04-27 09:19:35 -0400 | [diff] [blame] | 148 | * in mbedtls_config.h for more information about behaviour and requirements. |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 149 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 150 | #if defined(MBEDTLS_PLATFORM_MEMORY) |
| 151 | #if defined(MBEDTLS_PLATFORM_FREE_MACRO) && \ |
Manuel Pégourié-Gonnard | b9ef118 | 2015-05-26 16:15:20 +0200 | [diff] [blame] | 152 | defined(MBEDTLS_PLATFORM_CALLOC_MACRO) |
Aaron M. Ucko | 5e4a01b | 2023-01-17 13:26:35 -0500 | [diff] [blame] | 153 | #undef mbedtls_free |
| 154 | #undef mbedtls_calloc |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 155 | #define mbedtls_free MBEDTLS_PLATFORM_FREE_MACRO |
Manuel Pégourié-Gonnard | b9ef118 | 2015-05-26 16:15:20 +0200 | [diff] [blame] | 156 | #define mbedtls_calloc MBEDTLS_PLATFORM_CALLOC_MACRO |
Rich Evans | 401bb90 | 2015-02-10 12:28:15 +0000 | [diff] [blame] | 157 | #else |
Manuel Pégourié-Gonnard | 7ee5ddd | 2015-06-03 10:33:55 +0100 | [diff] [blame] | 158 | /* For size_t */ |
| 159 | #include <stddef.h> |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 160 | extern void *mbedtls_calloc(size_t n, size_t size); |
| 161 | extern void mbedtls_free(void *ptr); |
Paul Bakker | defc0ca | 2014-02-04 17:30:24 +0100 | [diff] [blame] | 162 | |
| 163 | /** |
Rose Zadik | 9464d7b | 2018-04-16 15:28:35 +0100 | [diff] [blame] | 164 | * \brief This function dynamically sets the memory-management |
| 165 | * functions used by the library, during runtime. |
Paul Bakker | defc0ca | 2014-02-04 17:30:24 +0100 | [diff] [blame] | 166 | * |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 167 | * \param calloc_func The \c calloc function implementation. |
| 168 | * \param free_func The \c free function implementation. |
Paul Bakker | defc0ca | 2014-02-04 17:30:24 +0100 | [diff] [blame] | 169 | * |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 170 | * \return \c 0. |
Paul Bakker | defc0ca | 2014-02-04 17:30:24 +0100 | [diff] [blame] | 171 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 172 | int mbedtls_platform_set_calloc_free(void *(*calloc_func)(size_t, size_t), |
| 173 | void (*free_func)(void *)); |
Manuel Pégourié-Gonnard | b9ef118 | 2015-05-26 16:15:20 +0200 | [diff] [blame] | 174 | #endif /* MBEDTLS_PLATFORM_FREE_MACRO && MBEDTLS_PLATFORM_CALLOC_MACRO */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 175 | #else /* !MBEDTLS_PLATFORM_MEMORY */ |
Aaron M. Ucko | 5e4a01b | 2023-01-17 13:26:35 -0500 | [diff] [blame] | 176 | #undef mbedtls_free |
| 177 | #undef mbedtls_calloc |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 178 | #define mbedtls_free free |
Manuel Pégourié-Gonnard | b9ef118 | 2015-05-26 16:15:20 +0200 | [diff] [blame] | 179 | #define mbedtls_calloc calloc |
| 180 | #endif /* MBEDTLS_PLATFORM_MEMORY && !MBEDTLS_PLATFORM_{FREE,CALLOC}_MACRO */ |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 181 | |
| 182 | /* |
| 183 | * The function pointers for fprintf |
| 184 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 185 | #if defined(MBEDTLS_PLATFORM_FPRINTF_ALT) |
Manuel Pégourié-Gonnard | 7ee5ddd | 2015-06-03 10:33:55 +0100 | [diff] [blame] | 186 | /* We need FILE * */ |
| 187 | #include <stdio.h> |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 188 | extern int (*mbedtls_fprintf)(FILE *stream, const char *format, ...); |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 189 | |
Rich Evans | c39cb49 | 2015-01-30 12:01:34 +0000 | [diff] [blame] | 190 | /** |
Rose Zadik | 9464d7b | 2018-04-16 15:28:35 +0100 | [diff] [blame] | 191 | * \brief This function dynamically configures the fprintf |
| 192 | * function that is called when the |
| 193 | * mbedtls_fprintf() function is invoked by the library. |
Rich Evans | c39cb49 | 2015-01-30 12:01:34 +0000 | [diff] [blame] | 194 | * |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 195 | * \param fprintf_func The \c fprintf function implementation. |
Rich Evans | c39cb49 | 2015-01-30 12:01:34 +0000 | [diff] [blame] | 196 | * |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 197 | * \return \c 0. |
Rich Evans | c39cb49 | 2015-01-30 12:01:34 +0000 | [diff] [blame] | 198 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 199 | int mbedtls_platform_set_fprintf(int (*fprintf_func)(FILE *stream, const char *, |
| 200 | ...)); |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 201 | #else |
Aaron M. Ucko | 5e4a01b | 2023-01-17 13:26:35 -0500 | [diff] [blame] | 202 | #undef mbedtls_fprintf |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 203 | #if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO) |
| 204 | #define mbedtls_fprintf MBEDTLS_PLATFORM_FPRINTF_MACRO |
Rich Evans | 16f8cd8 | 2015-02-06 16:14:34 +0000 | [diff] [blame] | 205 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 206 | #define mbedtls_fprintf fprintf |
| 207 | #endif /* MBEDTLS_PLATFORM_FPRINTF_MACRO */ |
| 208 | #endif /* MBEDTLS_PLATFORM_FPRINTF_ALT */ |
Rich Evans | c39cb49 | 2015-01-30 12:01:34 +0000 | [diff] [blame] | 209 | |
| 210 | /* |
Rich Evans | 16f8cd8 | 2015-02-06 16:14:34 +0000 | [diff] [blame] | 211 | * The function pointers for printf |
| 212 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 213 | #if defined(MBEDTLS_PLATFORM_PRINTF_ALT) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 214 | extern int (*mbedtls_printf)(const char *format, ...); |
Rich Evans | 16f8cd8 | 2015-02-06 16:14:34 +0000 | [diff] [blame] | 215 | |
| 216 | /** |
Rose Zadik | 9464d7b | 2018-04-16 15:28:35 +0100 | [diff] [blame] | 217 | * \brief This function dynamically configures the snprintf |
| 218 | * function that is called when the mbedtls_snprintf() |
| 219 | * function is invoked by the library. |
Rich Evans | 16f8cd8 | 2015-02-06 16:14:34 +0000 | [diff] [blame] | 220 | * |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 221 | * \param printf_func The \c printf function implementation. |
Rich Evans | 16f8cd8 | 2015-02-06 16:14:34 +0000 | [diff] [blame] | 222 | * |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 223 | * \return \c 0 on success. |
Rich Evans | 16f8cd8 | 2015-02-06 16:14:34 +0000 | [diff] [blame] | 224 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 225 | int mbedtls_platform_set_printf(int (*printf_func)(const char *, ...)); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 226 | #else /* !MBEDTLS_PLATFORM_PRINTF_ALT */ |
Aaron M. Ucko | 5e4a01b | 2023-01-17 13:26:35 -0500 | [diff] [blame] | 227 | #undef mbedtls_printf |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 228 | #if defined(MBEDTLS_PLATFORM_PRINTF_MACRO) |
| 229 | #define mbedtls_printf MBEDTLS_PLATFORM_PRINTF_MACRO |
Rich Evans | 16f8cd8 | 2015-02-06 16:14:34 +0000 | [diff] [blame] | 230 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 231 | #define mbedtls_printf printf |
| 232 | #endif /* MBEDTLS_PLATFORM_PRINTF_MACRO */ |
| 233 | #endif /* MBEDTLS_PLATFORM_PRINTF_ALT */ |
Rich Evans | 16f8cd8 | 2015-02-06 16:14:34 +0000 | [diff] [blame] | 234 | |
| 235 | /* |
| 236 | * The function pointers for snprintf |
Manuel Pégourié-Gonnard | 6c0c8e0 | 2015-06-22 10:23:34 +0200 | [diff] [blame] | 237 | * |
| 238 | * The snprintf implementation should conform to C99: |
| 239 | * - it *must* always correctly zero-terminate the buffer |
| 240 | * (except when n == 0, then it must leave the buffer untouched) |
| 241 | * - however it is acceptable to return -1 instead of the required length when |
| 242 | * the destination buffer is too short. |
Rich Evans | 16f8cd8 | 2015-02-06 16:14:34 +0000 | [diff] [blame] | 243 | */ |
k-stachowiak | 723f867 | 2018-07-16 14:27:07 +0200 | [diff] [blame] | 244 | #if defined(MBEDTLS_PLATFORM_HAS_NON_CONFORMING_SNPRINTF) |
Manuel Pégourié-Gonnard | 6c0c8e0 | 2015-06-22 10:23:34 +0200 | [diff] [blame] | 245 | /* For Windows (inc. MSYS2), we provide our own fixed implementation */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 246 | int mbedtls_platform_win32_snprintf(char *s, size_t n, const char *fmt, ...); |
Manuel Pégourié-Gonnard | 6c0c8e0 | 2015-06-22 10:23:34 +0200 | [diff] [blame] | 247 | #endif |
| 248 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 249 | #if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 250 | extern int (*mbedtls_snprintf)(char *s, size_t n, const char *format, ...); |
Rich Evans | 16f8cd8 | 2015-02-06 16:14:34 +0000 | [diff] [blame] | 251 | |
| 252 | /** |
Rose Zadik | 4bca2b0 | 2018-03-27 13:12:52 +0100 | [diff] [blame] | 253 | * \brief This function allows configuring a custom |
| 254 | * \c snprintf function pointer. |
Rich Evans | 16f8cd8 | 2015-02-06 16:14:34 +0000 | [diff] [blame] | 255 | * |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 256 | * \param snprintf_func The \c snprintf function implementation. |
Rich Evans | 16f8cd8 | 2015-02-06 16:14:34 +0000 | [diff] [blame] | 257 | * |
Rose Zadik | 4bca2b0 | 2018-03-27 13:12:52 +0100 | [diff] [blame] | 258 | * \return \c 0 on success. |
Rich Evans | 16f8cd8 | 2015-02-06 16:14:34 +0000 | [diff] [blame] | 259 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 260 | int mbedtls_platform_set_snprintf(int (*snprintf_func)(char *s, size_t n, |
| 261 | const char *format, ...)); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 262 | #else /* MBEDTLS_PLATFORM_SNPRINTF_ALT */ |
Aaron M. Ucko | 5e4a01b | 2023-01-17 13:26:35 -0500 | [diff] [blame] | 263 | #undef mbedtls_snprintf |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 264 | #if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO) |
| 265 | #define mbedtls_snprintf MBEDTLS_PLATFORM_SNPRINTF_MACRO |
Rich Evans | 16f8cd8 | 2015-02-06 16:14:34 +0000 | [diff] [blame] | 266 | #else |
Azim Khan | 8d54c06 | 2018-03-23 18:34:35 +0000 | [diff] [blame] | 267 | #define mbedtls_snprintf MBEDTLS_PLATFORM_STD_SNPRINTF |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 268 | #endif /* MBEDTLS_PLATFORM_SNPRINTF_MACRO */ |
| 269 | #endif /* MBEDTLS_PLATFORM_SNPRINTF_ALT */ |
Rich Evans | 16f8cd8 | 2015-02-06 16:14:34 +0000 | [diff] [blame] | 270 | |
| 271 | /* |
k-stachowiak | 723f867 | 2018-07-16 14:27:07 +0200 | [diff] [blame] | 272 | * The function pointers for vsnprintf |
| 273 | * |
| 274 | * The vsnprintf implementation should conform to C99: |
| 275 | * - it *must* always correctly zero-terminate the buffer |
| 276 | * (except when n == 0, then it must leave the buffer untouched) |
| 277 | * - however it is acceptable to return -1 instead of the required length when |
| 278 | * the destination buffer is too short. |
| 279 | */ |
| 280 | #if defined(MBEDTLS_PLATFORM_HAS_NON_CONFORMING_VSNPRINTF) |
Jaeden Amero | 32eb58f | 2019-05-30 13:18:24 +0100 | [diff] [blame] | 281 | #include <stdarg.h> |
k-stachowiak | 723f867 | 2018-07-16 14:27:07 +0200 | [diff] [blame] | 282 | /* For Older Windows (inc. MSYS2), we provide our own fixed implementation */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 283 | int mbedtls_platform_win32_vsnprintf(char *s, size_t n, const char *fmt, va_list arg); |
k-stachowiak | 723f867 | 2018-07-16 14:27:07 +0200 | [diff] [blame] | 284 | #endif |
| 285 | |
| 286 | #if defined(MBEDTLS_PLATFORM_VSNPRINTF_ALT) |
| 287 | #include <stdarg.h> |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 288 | extern int (*mbedtls_vsnprintf)(char *s, size_t n, const char *format, va_list arg); |
k-stachowiak | 723f867 | 2018-07-16 14:27:07 +0200 | [diff] [blame] | 289 | |
| 290 | /** |
| 291 | * \brief Set your own snprintf function pointer |
| 292 | * |
Krzysztof Stachowiak | 1555716 | 2018-09-24 14:15:46 +0200 | [diff] [blame] | 293 | * \param vsnprintf_func The \c vsnprintf function implementation |
k-stachowiak | 723f867 | 2018-07-16 14:27:07 +0200 | [diff] [blame] | 294 | * |
Krzysztof Stachowiak | 1555716 | 2018-09-24 14:15:46 +0200 | [diff] [blame] | 295 | * \return \c 0 |
k-stachowiak | 723f867 | 2018-07-16 14:27:07 +0200 | [diff] [blame] | 296 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 297 | int mbedtls_platform_set_vsnprintf(int (*vsnprintf_func)(char *s, size_t n, |
| 298 | const char *format, va_list arg)); |
k-stachowiak | 723f867 | 2018-07-16 14:27:07 +0200 | [diff] [blame] | 299 | #else /* MBEDTLS_PLATFORM_VSNPRINTF_ALT */ |
Aaron M. Ucko | 5e4a01b | 2023-01-17 13:26:35 -0500 | [diff] [blame] | 300 | #undef mbedtls_vsnprintf |
k-stachowiak | 723f867 | 2018-07-16 14:27:07 +0200 | [diff] [blame] | 301 | #if defined(MBEDTLS_PLATFORM_VSNPRINTF_MACRO) |
| 302 | #define mbedtls_vsnprintf MBEDTLS_PLATFORM_VSNPRINTF_MACRO |
| 303 | #else |
| 304 | #define mbedtls_vsnprintf vsnprintf |
| 305 | #endif /* MBEDTLS_PLATFORM_VSNPRINTF_MACRO */ |
| 306 | #endif /* MBEDTLS_PLATFORM_VSNPRINTF_ALT */ |
| 307 | |
| 308 | /* |
Gilles Peskine | 6497b5a | 2022-06-30 17:01:40 +0200 | [diff] [blame] | 309 | * The function pointers for setbuf |
| 310 | */ |
| 311 | #if defined(MBEDTLS_PLATFORM_SETBUF_ALT) |
| 312 | #include <stdio.h> |
| 313 | /** |
| 314 | * \brief Function pointer to call for `setbuf()` functionality |
| 315 | * (changing the internal buffering on stdio calls). |
| 316 | * |
| 317 | * \note The library calls this function to disable |
| 318 | * buffering when reading or writing sensitive data, |
| 319 | * to avoid having extra copies of sensitive data |
| 320 | * remaining in stdio buffers after the file is |
| 321 | * closed. If this is not a concern, for example if |
| 322 | * your platform's stdio doesn't have any buffering, |
| 323 | * you can set mbedtls_setbuf to a function that |
| 324 | * does nothing. |
| 325 | * |
Gilles Peskine | 0bd76ee | 2022-06-30 19:32:02 +0200 | [diff] [blame] | 326 | * The library always calls this function with |
| 327 | * `buf` equal to `NULL`. |
Gilles Peskine | 6497b5a | 2022-06-30 17:01:40 +0200 | [diff] [blame] | 328 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 329 | extern void (*mbedtls_setbuf)(FILE *stream, char *buf); |
Gilles Peskine | 6497b5a | 2022-06-30 17:01:40 +0200 | [diff] [blame] | 330 | |
| 331 | /** |
| 332 | * \brief Dynamically configure the function that is called |
| 333 | * when the mbedtls_setbuf() function is called by the |
| 334 | * library. |
| 335 | * |
| 336 | * \param setbuf_func The \c setbuf function implementation |
| 337 | * |
| 338 | * \return \c 0 |
| 339 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 340 | int mbedtls_platform_set_setbuf(void (*setbuf_func)( |
| 341 | FILE *stream, char *buf)); |
Aaron M. Ucko | 5e4a01b | 2023-01-17 13:26:35 -0500 | [diff] [blame] | 342 | #else |
| 343 | #undef mbedtls_setbuf |
| 344 | #if defined(MBEDTLS_PLATFORM_SETBUF_MACRO) |
Gilles Peskine | 6497b5a | 2022-06-30 17:01:40 +0200 | [diff] [blame] | 345 | /** |
| 346 | * \brief Macro defining the function for the library to |
| 347 | * call for `setbuf` functionality (changing the |
| 348 | * internal buffering on stdio calls). |
| 349 | * |
| 350 | * \note See extra comments on the mbedtls_setbuf() function |
| 351 | * pointer above. |
| 352 | * |
| 353 | * \return \c 0 on success, negative on error. |
| 354 | */ |
| 355 | #define mbedtls_setbuf MBEDTLS_PLATFORM_SETBUF_MACRO |
| 356 | #else |
| 357 | #define mbedtls_setbuf setbuf |
Aaron M. Ucko | 5e4a01b | 2023-01-17 13:26:35 -0500 | [diff] [blame] | 358 | #endif /* MBEDTLS_PLATFORM_SETBUF_MACRO */ |
| 359 | #endif /* MBEDTLS_PLATFORM_SETBUF_ALT */ |
Gilles Peskine | 6497b5a | 2022-06-30 17:01:40 +0200 | [diff] [blame] | 360 | |
| 361 | /* |
Rich Evans | c39cb49 | 2015-01-30 12:01:34 +0000 | [diff] [blame] | 362 | * The function pointers for exit |
| 363 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 364 | #if defined(MBEDTLS_PLATFORM_EXIT_ALT) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 365 | extern void (*mbedtls_exit)(int status); |
Rich Evans | c39cb49 | 2015-01-30 12:01:34 +0000 | [diff] [blame] | 366 | |
| 367 | /** |
Rose Zadik | 9464d7b | 2018-04-16 15:28:35 +0100 | [diff] [blame] | 368 | * \brief This function dynamically configures the exit |
| 369 | * function that is called when the mbedtls_exit() |
| 370 | * function is invoked by the library. |
Rich Evans | c39cb49 | 2015-01-30 12:01:34 +0000 | [diff] [blame] | 371 | * |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 372 | * \param exit_func The \c exit function implementation. |
Rich Evans | c39cb49 | 2015-01-30 12:01:34 +0000 | [diff] [blame] | 373 | * |
Rose Zadik | 4bca2b0 | 2018-03-27 13:12:52 +0100 | [diff] [blame] | 374 | * \return \c 0 on success. |
Rich Evans | c39cb49 | 2015-01-30 12:01:34 +0000 | [diff] [blame] | 375 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 376 | int mbedtls_platform_set_exit(void (*exit_func)(int status)); |
Rich Evans | c39cb49 | 2015-01-30 12:01:34 +0000 | [diff] [blame] | 377 | #else |
Aaron M. Ucko | 5e4a01b | 2023-01-17 13:26:35 -0500 | [diff] [blame] | 378 | #undef mbedtls_exit |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 379 | #if defined(MBEDTLS_PLATFORM_EXIT_MACRO) |
| 380 | #define mbedtls_exit MBEDTLS_PLATFORM_EXIT_MACRO |
Rich Evans | 16f8cd8 | 2015-02-06 16:14:34 +0000 | [diff] [blame] | 381 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 382 | #define mbedtls_exit exit |
| 383 | #endif /* MBEDTLS_PLATFORM_EXIT_MACRO */ |
| 384 | #endif /* MBEDTLS_PLATFORM_EXIT_ALT */ |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 385 | |
Janos Follath | 9194744 | 2016-03-18 13:49:27 +0000 | [diff] [blame] | 386 | /* |
| 387 | * The default exit values |
| 388 | */ |
| 389 | #if defined(MBEDTLS_PLATFORM_STD_EXIT_SUCCESS) |
| 390 | #define MBEDTLS_EXIT_SUCCESS MBEDTLS_PLATFORM_STD_EXIT_SUCCESS |
| 391 | #else |
| 392 | #define MBEDTLS_EXIT_SUCCESS 0 |
| 393 | #endif |
| 394 | #if defined(MBEDTLS_PLATFORM_STD_EXIT_FAILURE) |
| 395 | #define MBEDTLS_EXIT_FAILURE MBEDTLS_PLATFORM_STD_EXIT_FAILURE |
| 396 | #else |
| 397 | #define MBEDTLS_EXIT_FAILURE 1 |
| 398 | #endif |
| 399 | |
SimonB | d5800b7 | 2016-04-26 07:43:27 +0100 | [diff] [blame] | 400 | /* |
Paul Bakker | e021a4b | 2016-06-01 11:25:44 +0100 | [diff] [blame] | 401 | * The function pointers for reading from and writing a seed file to |
| 402 | * Non-Volatile storage (NV) in a platform-independent way |
| 403 | * |
| 404 | * Only enabled when the NV seed entropy source is enabled |
| 405 | */ |
| 406 | #if defined(MBEDTLS_ENTROPY_NV_SEED) |
| 407 | #if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS) && defined(MBEDTLS_FS_IO) |
| 408 | /* Internal standard platform definitions */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 409 | int mbedtls_platform_std_nv_seed_read(unsigned char *buf, size_t buf_len); |
| 410 | int mbedtls_platform_std_nv_seed_write(unsigned char *buf, size_t buf_len); |
Paul Bakker | e021a4b | 2016-06-01 11:25:44 +0100 | [diff] [blame] | 411 | #endif |
| 412 | |
| 413 | #if defined(MBEDTLS_PLATFORM_NV_SEED_ALT) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 414 | extern int (*mbedtls_nv_seed_read)(unsigned char *buf, size_t buf_len); |
| 415 | extern int (*mbedtls_nv_seed_write)(unsigned char *buf, size_t buf_len); |
Paul Bakker | e021a4b | 2016-06-01 11:25:44 +0100 | [diff] [blame] | 416 | |
| 417 | /** |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 418 | * \brief This function allows configuring custom seed file writing and |
| 419 | * reading functions. |
Paul Bakker | e021a4b | 2016-06-01 11:25:44 +0100 | [diff] [blame] | 420 | * |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 421 | * \param nv_seed_read_func The seed reading function implementation. |
| 422 | * \param nv_seed_write_func The seed writing function implementation. |
Paul Bakker | e021a4b | 2016-06-01 11:25:44 +0100 | [diff] [blame] | 423 | * |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 424 | * \return \c 0 on success. |
Paul Bakker | e021a4b | 2016-06-01 11:25:44 +0100 | [diff] [blame] | 425 | */ |
| 426 | int mbedtls_platform_set_nv_seed( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 427 | int (*nv_seed_read_func)(unsigned char *buf, size_t buf_len), |
| 428 | int (*nv_seed_write_func)(unsigned char *buf, size_t buf_len) |
| 429 | ); |
Paul Bakker | e021a4b | 2016-06-01 11:25:44 +0100 | [diff] [blame] | 430 | #else |
Aaron M. Ucko | 5e4a01b | 2023-01-17 13:26:35 -0500 | [diff] [blame] | 431 | #undef mbedtls_nv_seed_read |
| 432 | #undef mbedtls_nv_seed_write |
Paul Bakker | e021a4b | 2016-06-01 11:25:44 +0100 | [diff] [blame] | 433 | #if defined(MBEDTLS_PLATFORM_NV_SEED_READ_MACRO) && \ |
| 434 | defined(MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO) |
| 435 | #define mbedtls_nv_seed_read MBEDTLS_PLATFORM_NV_SEED_READ_MACRO |
| 436 | #define mbedtls_nv_seed_write MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO |
| 437 | #else |
| 438 | #define mbedtls_nv_seed_read mbedtls_platform_std_nv_seed_read |
| 439 | #define mbedtls_nv_seed_write mbedtls_platform_std_nv_seed_write |
| 440 | #endif |
| 441 | #endif /* MBEDTLS_PLATFORM_NV_SEED_ALT */ |
| 442 | #endif /* MBEDTLS_ENTROPY_NV_SEED */ |
| 443 | |
Andres Amaya Garcia | d91f99f | 2017-07-18 10:23:04 +0100 | [diff] [blame] | 444 | #if !defined(MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT) |
Andres Amaya Garcia | 3c8a39d | 2017-07-12 11:25:17 +0100 | [diff] [blame] | 445 | |
Andres Amaya Garcia | 64b02cd | 2017-07-12 11:32:40 +0100 | [diff] [blame] | 446 | /** |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 447 | * \brief The platform context structure. |
Andres Amaya Garcia | 64b02cd | 2017-07-12 11:32:40 +0100 | [diff] [blame] | 448 | * |
| 449 | * \note This structure may be used to assist platform-specific |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 450 | * setup or teardown operations. |
Andres Amaya Garcia | 64b02cd | 2017-07-12 11:32:40 +0100 | [diff] [blame] | 451 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 452 | typedef struct mbedtls_platform_context { |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 453 | char MBEDTLS_PRIVATE(dummy); /**< A placeholder member, as empty structs are not portable. */ |
Andres Amaya Garcia | 64b02cd | 2017-07-12 11:32:40 +0100 | [diff] [blame] | 454 | } |
| 455 | mbedtls_platform_context; |
| 456 | |
Andres Amaya Garcia | 2a6f39c | 2017-07-07 13:03:23 +0100 | [diff] [blame] | 457 | #else |
| 458 | #include "platform_alt.h" |
Andres Amaya Garcia | d91f99f | 2017-07-18 10:23:04 +0100 | [diff] [blame] | 459 | #endif /* !MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT */ |
Andres Amaya Garcia | 2a6f39c | 2017-07-07 13:03:23 +0100 | [diff] [blame] | 460 | |
| 461 | /** |
Rose Zadik | 9464d7b | 2018-04-16 15:28:35 +0100 | [diff] [blame] | 462 | * \brief This function performs any platform-specific initialization |
| 463 | * operations. |
Rose Zadik | 4bca2b0 | 2018-03-27 13:12:52 +0100 | [diff] [blame] | 464 | * |
| 465 | * \note This function should be called before any other library functions. |
| 466 | * |
| 467 | * Its implementation is platform-specific, and unless |
Darryl Green | 11999bb | 2018-03-13 15:22:58 +0000 | [diff] [blame] | 468 | * platform-specific code is provided, it does nothing. |
Rose Zadik | 4bca2b0 | 2018-03-27 13:12:52 +0100 | [diff] [blame] | 469 | * |
| 470 | * \note The usage and necessity of this function is dependent on the platform. |
Andres Amaya Garcia | 2a6f39c | 2017-07-07 13:03:23 +0100 | [diff] [blame] | 471 | * |
Rose Zadik | 9464d7b | 2018-04-16 15:28:35 +0100 | [diff] [blame] | 472 | * \param ctx The platform context. |
Andres Amaya Garcia | 2a6f39c | 2017-07-07 13:03:23 +0100 | [diff] [blame] | 473 | * |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 474 | * \return \c 0 on success. |
Andres Amaya Garcia | 2a6f39c | 2017-07-07 13:03:23 +0100 | [diff] [blame] | 475 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 476 | int mbedtls_platform_setup(mbedtls_platform_context *ctx); |
Andres Amaya Garcia | 2a6f39c | 2017-07-07 13:03:23 +0100 | [diff] [blame] | 477 | /** |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 478 | * \brief This function performs any platform teardown operations. |
Andres Amaya Garcia | 2a6f39c | 2017-07-07 13:03:23 +0100 | [diff] [blame] | 479 | * |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 480 | * \note This function should be called after every other Mbed TLS module |
| 481 | * has been correctly freed using the appropriate free function. |
Rose Zadik | 4bca2b0 | 2018-03-27 13:12:52 +0100 | [diff] [blame] | 482 | * |
Rose Zadik | 332658d | 2018-01-25 22:02:53 +0000 | [diff] [blame] | 483 | * Its implementation is platform-specific, and unless |
| 484 | * platform-specific code is provided, it does nothing. |
Simon Butcher | d3be27a | 2017-07-21 02:08:00 +0200 | [diff] [blame] | 485 | * |
Rose Zadik | 4bca2b0 | 2018-03-27 13:12:52 +0100 | [diff] [blame] | 486 | * \note The usage and necessity of this function is dependent on the platform. |
| 487 | * |
Rose Zadik | 9464d7b | 2018-04-16 15:28:35 +0100 | [diff] [blame] | 488 | * \param ctx The platform context. |
Rose Zadik | 4bca2b0 | 2018-03-27 13:12:52 +0100 | [diff] [blame] | 489 | * |
Andres Amaya Garcia | 2a6f39c | 2017-07-07 13:03:23 +0100 | [diff] [blame] | 490 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 491 | void mbedtls_platform_teardown(mbedtls_platform_context *ctx); |
Andres Amaya Garcia | 2a6f39c | 2017-07-07 13:03:23 +0100 | [diff] [blame] | 492 | |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 493 | #ifdef __cplusplus |
| 494 | } |
| 495 | #endif |
| 496 | |
| 497 | #endif /* platform.h */ |