blob: 8e8a27e139c6b6357baf0e253cb26931ba8f5f90 [file] [log] [blame]
Paul Bakker747a83a2014-02-01 22:50:07 +01001/**
2 * \file platform.h
3 *
Rose Zadik332658d2018-01-25 22:02:53 +00004 * \brief The Mbed TLS platform abstraction layer.
Darryl Greena40a1012018-01-05 15:33:17 +00005 */
6/*
Rose Zadik332658d2018-01-25 22:02:53 +00007 * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02008 * SPDX-License-Identifier: Apache-2.0
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
11 * not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
Paul Bakker747a83a2014-02-01 22:50:07 +010021 *
Rose Zadik332658d2018-01-25 22:02:53 +000022 * This file is part of Mbed TLS (https://tls.mbed.org)
Paul Bakker747a83a2014-02-01 22:50:07 +010023 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020024#ifndef MBEDTLS_PLATFORM_H
25#define MBEDTLS_PLATFORM_H
Paul Bakker747a83a2014-02-01 22:50:07 +010026
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020027#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker747a83a2014-02-01 22:50:07 +010028#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020029#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020030#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020031#endif
Paul Bakker747a83a2014-02-01 22:50:07 +010032
Simon Butcherb5b6af22016-07-13 14:46:18 +010033#if defined(MBEDTLS_HAVE_TIME)
34#include "mbedtls/platform_time.h"
35#endif
36
Paul Bakker747a83a2014-02-01 22:50:07 +010037#ifdef __cplusplus
38extern "C" {
39#endif
40
Paul Bakker088c5c52014-04-25 11:11:10 +020041/**
42 * \name SECTION: Module settings
43 *
44 * The configuration options you can set for this module are in this section.
45 * Either change them in config.h or define them on the compiler command line.
46 * \{
47 */
48
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020049#if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS)
Rich Evans00ab4702015-02-06 13:43:58 +000050#include <stdio.h>
Paul Bakkera9066cf2014-02-05 15:13:04 +010051#include <stdlib.h>
Simon Butcher3fe6cd32016-04-26 19:51:29 +010052#include <time.h>
Krzysztof Stachowiak25d34a42018-03-20 16:17:51 +010053#include <stdarg.h>
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020054#if !defined(MBEDTLS_PLATFORM_STD_SNPRINTF)
Manuel Pégourié-Gonnard6c0c8e02015-06-22 10:23:34 +020055#if defined(_WIN32)
Rose Zadik332658d2018-01-25 22:02:53 +000056#define MBEDTLS_PLATFORM_STD_SNPRINTF mbedtls_platform_win32_snprintf /**< The default \c snprintf function to use. */
Manuel Pégourié-Gonnard6c0c8e02015-06-22 10:23:34 +020057#else
Rose Zadik332658d2018-01-25 22:02:53 +000058#define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf /**< The default \c snprintf function to use. */
Rich Evans46b0a8d2015-01-30 10:47:32 +000059#endif
Manuel Pégourié-Gonnard6c0c8e02015-06-22 10:23:34 +020060#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020061#if !defined(MBEDTLS_PLATFORM_STD_PRINTF)
Rose Zadik332658d2018-01-25 22:02:53 +000062#define MBEDTLS_PLATFORM_STD_PRINTF printf /**< The default \c printf function to use. */
Paul Bakker088c5c52014-04-25 11:11:10 +020063#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064#if !defined(MBEDTLS_PLATFORM_STD_FPRINTF)
Rose Zadik332658d2018-01-25 22:02:53 +000065#define MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< The default \c fprintf function to use. */
Paul Bakker088c5c52014-04-25 11:11:10 +020066#endif
Manuel Pégourié-Gonnardb9ef1182015-05-26 16:15:20 +020067#if !defined(MBEDTLS_PLATFORM_STD_CALLOC)
Rose Zadik332658d2018-01-25 22:02:53 +000068#define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< The default \c calloc function to use. */
Paul Bakker088c5c52014-04-25 11:11:10 +020069#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020070#if !defined(MBEDTLS_PLATFORM_STD_FREE)
Rose Zadik332658d2018-01-25 22:02:53 +000071#define MBEDTLS_PLATFORM_STD_FREE free /**< The default \c free function to use. */
Paul Bakker088c5c52014-04-25 11:11:10 +020072#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020073#if !defined(MBEDTLS_PLATFORM_STD_EXIT)
Rose Zadik332658d2018-01-25 22:02:53 +000074#define MBEDTLS_PLATFORM_STD_EXIT exit /**< The default \c exit function to use. */
Janos Follath91947442016-03-18 13:49:27 +000075#endif
SimonBd5800b72016-04-26 07:43:27 +010076#if !defined(MBEDTLS_PLATFORM_STD_TIME)
Rose Zadik332658d2018-01-25 22:02:53 +000077#define MBEDTLS_PLATFORM_STD_TIME time /**< The default \c time function to use. */
SimonBd5800b72016-04-26 07:43:27 +010078#endif
Janos Follath91947442016-03-18 13:49:27 +000079#if !defined(MBEDTLS_PLATFORM_STD_EXIT_SUCCESS)
Rose Zadik332658d2018-01-25 22:02:53 +000080#define MBEDTLS_PLATFORM_STD_EXIT_SUCCESS EXIT_SUCCESS /**< The default exit value to use. */
Janos Follath91947442016-03-18 13:49:27 +000081#endif
82#if !defined(MBEDTLS_PLATFORM_STD_EXIT_FAILURE)
Rose Zadik332658d2018-01-25 22:02:53 +000083#define MBEDTLS_PLATFORM_STD_EXIT_FAILURE EXIT_FAILURE /**< The default exit value to use. */
Rich Evansc39cb492015-01-30 12:01:34 +000084#endif
Paul Bakkera9c321c2016-06-01 11:44:12 +010085#if defined(MBEDTLS_FS_IO)
Paul Bakkere021a4b2016-06-01 11:25:44 +010086#if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_READ)
87#define MBEDTLS_PLATFORM_STD_NV_SEED_READ mbedtls_platform_std_nv_seed_read
88#endif
89#if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_WRITE)
90#define MBEDTLS_PLATFORM_STD_NV_SEED_WRITE mbedtls_platform_std_nv_seed_write
91#endif
92#if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_FILE)
93#define MBEDTLS_PLATFORM_STD_NV_SEED_FILE "seedfile"
94#endif
Paul Bakkera9c321c2016-06-01 11:44:12 +010095#endif /* MBEDTLS_FS_IO */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020096#else /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
97#if defined(MBEDTLS_PLATFORM_STD_MEM_HDR)
98#include MBEDTLS_PLATFORM_STD_MEM_HDR
Manuel Pégourié-Gonnardeb82a742014-04-02 13:43:48 +020099#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200100#endif /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
Paul Bakker088c5c52014-04-25 11:11:10 +0200101
Paul Bakkere021a4b2016-06-01 11:25:44 +0100102
Paul Bakker088c5c52014-04-25 11:11:10 +0200103/* \} name SECTION: Module settings */
Paul Bakker747a83a2014-02-01 22:50:07 +0100104
105/*
Manuel Pégourié-Gonnardb9ef1182015-05-26 16:15:20 +0200106 * The function pointers for calloc and free
Paul Bakker747a83a2014-02-01 22:50:07 +0100107 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200108#if defined(MBEDTLS_PLATFORM_MEMORY)
109#if defined(MBEDTLS_PLATFORM_FREE_MACRO) && \
Manuel Pégourié-Gonnardb9ef1182015-05-26 16:15:20 +0200110 defined(MBEDTLS_PLATFORM_CALLOC_MACRO)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200111#define mbedtls_free MBEDTLS_PLATFORM_FREE_MACRO
Manuel Pégourié-Gonnardb9ef1182015-05-26 16:15:20 +0200112#define mbedtls_calloc MBEDTLS_PLATFORM_CALLOC_MACRO
Rich Evans401bb902015-02-10 12:28:15 +0000113#else
Manuel Pégourié-Gonnard7ee5ddd2015-06-03 10:33:55 +0100114/* For size_t */
115#include <stddef.h>
Manuel Pégourié-Gonnardb9ef1182015-05-26 16:15:20 +0200116extern void * (*mbedtls_calloc)( size_t n, size_t size );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200117extern void (*mbedtls_free)( void *ptr );
Paul Bakkerdefc0ca2014-02-04 17:30:24 +0100118
119/**
Rose Zadik332658d2018-01-25 22:02:53 +0000120 * \brief This function allows configuring custom memory-management functions.
Paul Bakkerdefc0ca2014-02-04 17:30:24 +0100121 *
Rose Zadik332658d2018-01-25 22:02:53 +0000122 * \param calloc_func The \c calloc function implementation.
123 * \param free_func The \c free function implementation.
Paul Bakkerdefc0ca2014-02-04 17:30:24 +0100124 *
Rose Zadik332658d2018-01-25 22:02:53 +0000125 * \return \c 0.
Paul Bakkerdefc0ca2014-02-04 17:30:24 +0100126 */
Manuel Pégourié-Gonnardb9ef1182015-05-26 16:15:20 +0200127int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ),
Paul Bakkerdefc0ca2014-02-04 17:30:24 +0100128 void (*free_func)( void * ) );
Manuel Pégourié-Gonnardb9ef1182015-05-26 16:15:20 +0200129#endif /* MBEDTLS_PLATFORM_FREE_MACRO && MBEDTLS_PLATFORM_CALLOC_MACRO */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200130#else /* !MBEDTLS_PLATFORM_MEMORY */
131#define mbedtls_free free
Manuel Pégourié-Gonnardb9ef1182015-05-26 16:15:20 +0200132#define mbedtls_calloc calloc
133#endif /* MBEDTLS_PLATFORM_MEMORY && !MBEDTLS_PLATFORM_{FREE,CALLOC}_MACRO */
Paul Bakker747a83a2014-02-01 22:50:07 +0100134
135/*
136 * The function pointers for fprintf
137 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200138#if defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
Manuel Pégourié-Gonnard7ee5ddd2015-06-03 10:33:55 +0100139/* We need FILE * */
140#include <stdio.h>
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200141extern int (*mbedtls_fprintf)( FILE *stream, const char *format, ... );
Paul Bakker747a83a2014-02-01 22:50:07 +0100142
Rich Evansc39cb492015-01-30 12:01:34 +0000143/**
Rose Zadik332658d2018-01-25 22:02:53 +0000144 * \brief This function allows configuring a custom \p fprintf function pointer.
Rich Evansc39cb492015-01-30 12:01:34 +0000145 *
Rose Zadik332658d2018-01-25 22:02:53 +0000146 * \param fprintf_func The \c fprintf function implementation.
Rich Evansc39cb492015-01-30 12:01:34 +0000147 *
Rose Zadik332658d2018-01-25 22:02:53 +0000148 * \return \c 0.
Rich Evansc39cb492015-01-30 12:01:34 +0000149 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200150int mbedtls_platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *,
Paul Bakker747a83a2014-02-01 22:50:07 +0100151 ... ) );
152#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200153#if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO)
154#define mbedtls_fprintf MBEDTLS_PLATFORM_FPRINTF_MACRO
Rich Evans16f8cd82015-02-06 16:14:34 +0000155#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200156#define mbedtls_fprintf fprintf
157#endif /* MBEDTLS_PLATFORM_FPRINTF_MACRO */
158#endif /* MBEDTLS_PLATFORM_FPRINTF_ALT */
Rich Evansc39cb492015-01-30 12:01:34 +0000159
160/*
Rich Evans16f8cd82015-02-06 16:14:34 +0000161 * The function pointers for printf
162 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200163#if defined(MBEDTLS_PLATFORM_PRINTF_ALT)
164extern int (*mbedtls_printf)( const char *format, ... );
Rich Evans16f8cd82015-02-06 16:14:34 +0000165
166/**
Rose Zadik332658d2018-01-25 22:02:53 +0000167 * \brief This function allows configuring a custom \c printf function
168 * pointer.
Rich Evans16f8cd82015-02-06 16:14:34 +0000169 *
Rose Zadik332658d2018-01-25 22:02:53 +0000170 * \param printf_func The \c printf function implementation.
Rich Evans16f8cd82015-02-06 16:14:34 +0000171 *
Rose Zadik332658d2018-01-25 22:02:53 +0000172 * \return \c 0 on success.
Rich Evans16f8cd82015-02-06 16:14:34 +0000173 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200174int mbedtls_platform_set_printf( int (*printf_func)( const char *, ... ) );
175#else /* !MBEDTLS_PLATFORM_PRINTF_ALT */
176#if defined(MBEDTLS_PLATFORM_PRINTF_MACRO)
177#define mbedtls_printf MBEDTLS_PLATFORM_PRINTF_MACRO
Rich Evans16f8cd82015-02-06 16:14:34 +0000178#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200179#define mbedtls_printf printf
180#endif /* MBEDTLS_PLATFORM_PRINTF_MACRO */
181#endif /* MBEDTLS_PLATFORM_PRINTF_ALT */
Rich Evans16f8cd82015-02-06 16:14:34 +0000182
183/*
184 * The function pointers for snprintf
Manuel Pégourié-Gonnard6c0c8e02015-06-22 10:23:34 +0200185 *
186 * The snprintf implementation should conform to C99:
187 * - it *must* always correctly zero-terminate the buffer
188 * (except when n == 0, then it must leave the buffer untouched)
189 * - however it is acceptable to return -1 instead of the required length when
190 * the destination buffer is too short.
Rich Evans16f8cd82015-02-06 16:14:34 +0000191 */
Manuel Pégourié-Gonnard6c0c8e02015-06-22 10:23:34 +0200192#if defined(_WIN32)
193/* For Windows (inc. MSYS2), we provide our own fixed implementation */
194int mbedtls_platform_win32_snprintf( char *s, size_t n, const char *fmt, ... );
195#endif
196
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200197#if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
198extern int (*mbedtls_snprintf)( char * s, size_t n, const char * format, ... );
Rich Evans16f8cd82015-02-06 16:14:34 +0000199
200/**
Rose Zadik332658d2018-01-25 22:02:53 +0000201 * \brief This function allows configuring a custom \c snprintf function
202 * pointer.
Rich Evans16f8cd82015-02-06 16:14:34 +0000203 *
Rose Zadik332658d2018-01-25 22:02:53 +0000204 * \param snprintf_func The \c snprintf function implementation.
Rich Evans16f8cd82015-02-06 16:14:34 +0000205 *
Rose Zadik332658d2018-01-25 22:02:53 +0000206 * \return \c 0 on success.
Rich Evans16f8cd82015-02-06 16:14:34 +0000207 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200208int mbedtls_platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
Rich Evans16f8cd82015-02-06 16:14:34 +0000209 const char * format, ... ) );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200210#else /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
211#if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO)
212#define mbedtls_snprintf MBEDTLS_PLATFORM_SNPRINTF_MACRO
Rich Evans16f8cd82015-02-06 16:14:34 +0000213#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200214#define mbedtls_snprintf snprintf
215#endif /* MBEDTLS_PLATFORM_SNPRINTF_MACRO */
216#endif /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
Rich Evans16f8cd82015-02-06 16:14:34 +0000217
218/*
Rich Evansc39cb492015-01-30 12:01:34 +0000219 * The function pointers for exit
220 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200221#if defined(MBEDTLS_PLATFORM_EXIT_ALT)
222extern void (*mbedtls_exit)( int status );
Rich Evansc39cb492015-01-30 12:01:34 +0000223
224/**
Rose Zadik332658d2018-01-25 22:02:53 +0000225 * \brief This function allows configuring a custom \c exit function
226 * pointer.
Rich Evansc39cb492015-01-30 12:01:34 +0000227 *
Rose Zadik332658d2018-01-25 22:02:53 +0000228 * \param exit_func The \c exit function implementation.
Rich Evansc39cb492015-01-30 12:01:34 +0000229 *
Rose Zadik332658d2018-01-25 22:02:53 +0000230 * \return \c 0 on success.
Rich Evansc39cb492015-01-30 12:01:34 +0000231 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200232int mbedtls_platform_set_exit( void (*exit_func)( int status ) );
Rich Evansc39cb492015-01-30 12:01:34 +0000233#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200234#if defined(MBEDTLS_PLATFORM_EXIT_MACRO)
235#define mbedtls_exit MBEDTLS_PLATFORM_EXIT_MACRO
Rich Evans16f8cd82015-02-06 16:14:34 +0000236#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200237#define mbedtls_exit exit
238#endif /* MBEDTLS_PLATFORM_EXIT_MACRO */
239#endif /* MBEDTLS_PLATFORM_EXIT_ALT */
Paul Bakker747a83a2014-02-01 22:50:07 +0100240
Janos Follath91947442016-03-18 13:49:27 +0000241/*
242 * The default exit values
243 */
244#if defined(MBEDTLS_PLATFORM_STD_EXIT_SUCCESS)
245#define MBEDTLS_EXIT_SUCCESS MBEDTLS_PLATFORM_STD_EXIT_SUCCESS
246#else
247#define MBEDTLS_EXIT_SUCCESS 0
248#endif
249#if defined(MBEDTLS_PLATFORM_STD_EXIT_FAILURE)
250#define MBEDTLS_EXIT_FAILURE MBEDTLS_PLATFORM_STD_EXIT_FAILURE
251#else
252#define MBEDTLS_EXIT_FAILURE 1
253#endif
254
SimonBd5800b72016-04-26 07:43:27 +0100255/*
Paul Bakkere021a4b2016-06-01 11:25:44 +0100256 * The function pointers for reading from and writing a seed file to
257 * Non-Volatile storage (NV) in a platform-independent way
258 *
259 * Only enabled when the NV seed entropy source is enabled
260 */
261#if defined(MBEDTLS_ENTROPY_NV_SEED)
262#if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS) && defined(MBEDTLS_FS_IO)
263/* Internal standard platform definitions */
264int mbedtls_platform_std_nv_seed_read( unsigned char *buf, size_t buf_len );
265int mbedtls_platform_std_nv_seed_write( unsigned char *buf, size_t buf_len );
266#endif
267
268#if defined(MBEDTLS_PLATFORM_NV_SEED_ALT)
269extern int (*mbedtls_nv_seed_read)( unsigned char *buf, size_t buf_len );
270extern int (*mbedtls_nv_seed_write)( unsigned char *buf, size_t buf_len );
271
272/**
Rose Zadik332658d2018-01-25 22:02:53 +0000273 * \brief This function allows configuring custom seed file writing and
274 * reading functions.
Paul Bakkere021a4b2016-06-01 11:25:44 +0100275 *
Rose Zadik332658d2018-01-25 22:02:53 +0000276 * \param nv_seed_read_func The seed reading function implementation.
277 * \param nv_seed_write_func The seed writing function implementation.
Paul Bakkere021a4b2016-06-01 11:25:44 +0100278 *
Rose Zadik332658d2018-01-25 22:02:53 +0000279 * \return \c 0 on success.
Paul Bakkere021a4b2016-06-01 11:25:44 +0100280 */
281int mbedtls_platform_set_nv_seed(
282 int (*nv_seed_read_func)( unsigned char *buf, size_t buf_len ),
283 int (*nv_seed_write_func)( unsigned char *buf, size_t buf_len )
284 );
285#else
286#if defined(MBEDTLS_PLATFORM_NV_SEED_READ_MACRO) && \
287 defined(MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO)
288#define mbedtls_nv_seed_read MBEDTLS_PLATFORM_NV_SEED_READ_MACRO
289#define mbedtls_nv_seed_write MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO
290#else
291#define mbedtls_nv_seed_read mbedtls_platform_std_nv_seed_read
292#define mbedtls_nv_seed_write mbedtls_platform_std_nv_seed_write
293#endif
294#endif /* MBEDTLS_PLATFORM_NV_SEED_ALT */
295#endif /* MBEDTLS_ENTROPY_NV_SEED */
296
Andres Amaya Garciad91f99f2017-07-18 10:23:04 +0100297#if !defined(MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT)
Andres Amaya Garcia3c8a39d2017-07-12 11:25:17 +0100298
Andres Amaya Garcia64b02cd2017-07-12 11:32:40 +0100299/**
Rose Zadik332658d2018-01-25 22:02:53 +0000300 * \brief The platform context structure.
Andres Amaya Garcia64b02cd2017-07-12 11:32:40 +0100301 *
302 * \note This structure may be used to assist platform-specific
Rose Zadik332658d2018-01-25 22:02:53 +0000303 * setup or teardown operations.
Andres Amaya Garcia64b02cd2017-07-12 11:32:40 +0100304 */
305typedef struct {
Rose Zadik332658d2018-01-25 22:02:53 +0000306 char dummy; /**< Placeholder member, as empty structs are not portable. */
Andres Amaya Garcia64b02cd2017-07-12 11:32:40 +0100307}
308mbedtls_platform_context;
309
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100310#else
311#include "platform_alt.h"
Andres Amaya Garciad91f99f2017-07-18 10:23:04 +0100312#endif /* !MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT */
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100313
314/**
Rose Zadik332658d2018-01-25 22:02:53 +0000315 * \brief This function performs any platform initialization operations.
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100316 *
Rose Zadik332658d2018-01-25 22:02:53 +0000317 * \param ctx The Mbed TLS context.
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100318 *
Rose Zadik332658d2018-01-25 22:02:53 +0000319 * \return \c 0 on success.
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100320 *
Rose Zadik332658d2018-01-25 22:02:53 +0000321 * \note This function is intended to allow platform-specific initialization,
Simon Butcherd3be27a2017-07-21 02:08:00 +0200322 * and should be called before any other library functions. Its
Rose Zadik332658d2018-01-25 22:02:53 +0000323 * implementation is platform-specific, and unless
324 * platform-specific code is provided, it does nothing.
Simon Butcherd3be27a2017-07-21 02:08:00 +0200325 *
Rose Zadik332658d2018-01-25 22:02:53 +0000326 * Its use and whether it is necessary to call it is dependent on the
Simon Butcherd3be27a2017-07-21 02:08:00 +0200327 * platform.
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100328 */
329int mbedtls_platform_setup( mbedtls_platform_context *ctx );
330/**
Rose Zadik332658d2018-01-25 22:02:53 +0000331 * \brief This function performs any platform teardown operations.
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100332 *
Rose Zadik332658d2018-01-25 22:02:53 +0000333 * \param ctx The Mbed TLS context.
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100334 *
Rose Zadik332658d2018-01-25 22:02:53 +0000335 * \note This function should be called after every other Mbed TLS module
336 * has been correctly freed using the appropriate free function.
337 * Its implementation is platform-specific, and unless
338 * platform-specific code is provided, it does nothing.
Simon Butcherd3be27a2017-07-21 02:08:00 +0200339 *
Rose Zadik332658d2018-01-25 22:02:53 +0000340 * Its use and whether it is necessary to call it is dependent on the
Simon Butcherd3be27a2017-07-21 02:08:00 +0200341 * platform.
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100342 */
343void mbedtls_platform_teardown( mbedtls_platform_context *ctx );
344
Paul Bakker747a83a2014-02-01 22:50:07 +0100345#ifdef __cplusplus
346}
347#endif
348
349#endif /* platform.h */