blob: 65ae85c190b908c4d871222a1899d0d367180897 [file] [log] [blame]
Paul Bakker747a83a2014-02-01 22:50:07 +01001/**
2 * \file platform.h
3 *
Rose Zadik4bca2b02018-03-27 13:12:52 +01004 * \brief This file contains the definitions and functions of the
5 * Mbed TLS platform abstraction layer.
Darryl Greena40a1012018-01-05 15:33:17 +00006 */
7/*
Rose Zadik332658d2018-01-25 22:02:53 +00008 * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02009 * SPDX-License-Identifier: Apache-2.0
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License"); you may
12 * not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
19 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
Paul Bakker747a83a2014-02-01 22:50:07 +010022 *
Rose Zadik332658d2018-01-25 22:02:53 +000023 * This file is part of Mbed TLS (https://tls.mbed.org)
Paul Bakker747a83a2014-02-01 22:50:07 +010024 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020025#ifndef MBEDTLS_PLATFORM_H
26#define MBEDTLS_PLATFORM_H
Paul Bakker747a83a2014-02-01 22:50:07 +010027
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020028#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker747a83a2014-02-01 22:50:07 +010029#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020030#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020031#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020032#endif
Paul Bakker747a83a2014-02-01 22:50:07 +010033
Simon Butcherb5b6af22016-07-13 14:46:18 +010034#if defined(MBEDTLS_HAVE_TIME)
35#include "mbedtls/platform_time.h"
36#endif
37
Paul Bakker747a83a2014-02-01 22:50:07 +010038#ifdef __cplusplus
39extern "C" {
40#endif
41
Paul Bakker088c5c52014-04-25 11:11:10 +020042/**
43 * \name SECTION: Module settings
44 *
45 * The configuration options you can set for this module are in this section.
46 * Either change them in config.h or define them on the compiler command line.
47 * \{
48 */
49
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020050#if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS)
Rich Evans00ab4702015-02-06 13:43:58 +000051#include <stdio.h>
Paul Bakkera9066cf2014-02-05 15:13:04 +010052#include <stdlib.h>
Simon Butcher3fe6cd32016-04-26 19:51:29 +010053#include <time.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/*
Rose Zadik4bca2b02018-03-27 13:12:52 +0100106 * 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 Zadik4bca2b02018-03-27 13:12:52 +0100120 * \brief This function allows configuring custom
121 * memory-management functions.
Paul Bakkerdefc0ca2014-02-04 17:30:24 +0100122 *
Rose Zadik332658d2018-01-25 22:02:53 +0000123 * \param calloc_func The \c calloc function implementation.
124 * \param free_func The \c free function implementation.
Paul Bakkerdefc0ca2014-02-04 17:30:24 +0100125 *
Rose Zadik332658d2018-01-25 22:02:53 +0000126 * \return \c 0.
Paul Bakkerdefc0ca2014-02-04 17:30:24 +0100127 */
Manuel Pégourié-Gonnardb9ef1182015-05-26 16:15:20 +0200128int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ),
Paul Bakkerdefc0ca2014-02-04 17:30:24 +0100129 void (*free_func)( void * ) );
Manuel Pégourié-Gonnardb9ef1182015-05-26 16:15:20 +0200130#endif /* MBEDTLS_PLATFORM_FREE_MACRO && MBEDTLS_PLATFORM_CALLOC_MACRO */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200131#else /* !MBEDTLS_PLATFORM_MEMORY */
132#define mbedtls_free free
Manuel Pégourié-Gonnardb9ef1182015-05-26 16:15:20 +0200133#define mbedtls_calloc calloc
134#endif /* MBEDTLS_PLATFORM_MEMORY && !MBEDTLS_PLATFORM_{FREE,CALLOC}_MACRO */
Paul Bakker747a83a2014-02-01 22:50:07 +0100135
136/*
137 * The function pointers for fprintf
138 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200139#if defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
Manuel Pégourié-Gonnard7ee5ddd2015-06-03 10:33:55 +0100140/* We need FILE * */
141#include <stdio.h>
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200142extern int (*mbedtls_fprintf)( FILE *stream, const char *format, ... );
Paul Bakker747a83a2014-02-01 22:50:07 +0100143
Rich Evansc39cb492015-01-30 12:01:34 +0000144/**
Rose Zadik4bca2b02018-03-27 13:12:52 +0100145 * \brief This function allows configuring a custom
146 * \p fprintf function pointer.
Rich Evansc39cb492015-01-30 12:01:34 +0000147 *
Rose Zadik332658d2018-01-25 22:02:53 +0000148 * \param fprintf_func The \c fprintf function implementation.
Rich Evansc39cb492015-01-30 12:01:34 +0000149 *
Rose Zadik332658d2018-01-25 22:02:53 +0000150 * \return \c 0.
Rich Evansc39cb492015-01-30 12:01:34 +0000151 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200152int mbedtls_platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *,
Paul Bakker747a83a2014-02-01 22:50:07 +0100153 ... ) );
154#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200155#if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO)
156#define mbedtls_fprintf MBEDTLS_PLATFORM_FPRINTF_MACRO
Rich Evans16f8cd82015-02-06 16:14:34 +0000157#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200158#define mbedtls_fprintf fprintf
159#endif /* MBEDTLS_PLATFORM_FPRINTF_MACRO */
160#endif /* MBEDTLS_PLATFORM_FPRINTF_ALT */
Rich Evansc39cb492015-01-30 12:01:34 +0000161
162/*
Rich Evans16f8cd82015-02-06 16:14:34 +0000163 * The function pointers for printf
164 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200165#if defined(MBEDTLS_PLATFORM_PRINTF_ALT)
166extern int (*mbedtls_printf)( const char *format, ... );
Rich Evans16f8cd82015-02-06 16:14:34 +0000167
168/**
Rose Zadik4bca2b02018-03-27 13:12:52 +0100169 * \brief This function allows configuring a custom \c printf
170 * function pointer.
Rich Evans16f8cd82015-02-06 16:14:34 +0000171 *
Rose Zadik332658d2018-01-25 22:02:53 +0000172 * \param printf_func The \c printf function implementation.
Rich Evans16f8cd82015-02-06 16:14:34 +0000173 *
Rose Zadik332658d2018-01-25 22:02:53 +0000174 * \return \c 0 on success.
Rich Evans16f8cd82015-02-06 16:14:34 +0000175 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200176int mbedtls_platform_set_printf( int (*printf_func)( const char *, ... ) );
177#else /* !MBEDTLS_PLATFORM_PRINTF_ALT */
178#if defined(MBEDTLS_PLATFORM_PRINTF_MACRO)
179#define mbedtls_printf MBEDTLS_PLATFORM_PRINTF_MACRO
Rich Evans16f8cd82015-02-06 16:14:34 +0000180#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200181#define mbedtls_printf printf
182#endif /* MBEDTLS_PLATFORM_PRINTF_MACRO */
183#endif /* MBEDTLS_PLATFORM_PRINTF_ALT */
Rich Evans16f8cd82015-02-06 16:14:34 +0000184
185/*
186 * The function pointers for snprintf
Manuel Pégourié-Gonnard6c0c8e02015-06-22 10:23:34 +0200187 *
188 * The snprintf implementation should conform to C99:
189 * - it *must* always correctly zero-terminate the buffer
190 * (except when n == 0, then it must leave the buffer untouched)
191 * - however it is acceptable to return -1 instead of the required length when
192 * the destination buffer is too short.
Rich Evans16f8cd82015-02-06 16:14:34 +0000193 */
Manuel Pégourié-Gonnard6c0c8e02015-06-22 10:23:34 +0200194#if defined(_WIN32)
195/* For Windows (inc. MSYS2), we provide our own fixed implementation */
196int mbedtls_platform_win32_snprintf( char *s, size_t n, const char *fmt, ... );
197#endif
198
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200199#if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
200extern int (*mbedtls_snprintf)( char * s, size_t n, const char * format, ... );
Rich Evans16f8cd82015-02-06 16:14:34 +0000201
202/**
Rose Zadik4bca2b02018-03-27 13:12:52 +0100203 * \brief This function allows configuring a custom
204 * \c snprintf function pointer.
Rich Evans16f8cd82015-02-06 16:14:34 +0000205 *
Rose Zadik332658d2018-01-25 22:02:53 +0000206 * \param snprintf_func The \c snprintf function implementation.
Rich Evans16f8cd82015-02-06 16:14:34 +0000207 *
Rose Zadik4bca2b02018-03-27 13:12:52 +0100208 * \return \c 0 on success.
Rich Evans16f8cd82015-02-06 16:14:34 +0000209 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200210int mbedtls_platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
Rich Evans16f8cd82015-02-06 16:14:34 +0000211 const char * format, ... ) );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200212#else /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
213#if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO)
214#define mbedtls_snprintf MBEDTLS_PLATFORM_SNPRINTF_MACRO
Rich Evans16f8cd82015-02-06 16:14:34 +0000215#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200216#define mbedtls_snprintf snprintf
217#endif /* MBEDTLS_PLATFORM_SNPRINTF_MACRO */
218#endif /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
Rich Evans16f8cd82015-02-06 16:14:34 +0000219
220/*
Rich Evansc39cb492015-01-30 12:01:34 +0000221 * The function pointers for exit
222 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200223#if defined(MBEDTLS_PLATFORM_EXIT_ALT)
224extern void (*mbedtls_exit)( int status );
Rich Evansc39cb492015-01-30 12:01:34 +0000225
226/**
Rose Zadik4bca2b02018-03-27 13:12:52 +0100227 * \brief This function allows configuring a custom
228 * \c exit function pointer.
Rich Evansc39cb492015-01-30 12:01:34 +0000229 *
Rose Zadik332658d2018-01-25 22:02:53 +0000230 * \param exit_func The \c exit function implementation.
Rich Evansc39cb492015-01-30 12:01:34 +0000231 *
Rose Zadik4bca2b02018-03-27 13:12:52 +0100232 * \return \c 0 on success.
Rich Evansc39cb492015-01-30 12:01:34 +0000233 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200234int mbedtls_platform_set_exit( void (*exit_func)( int status ) );
Rich Evansc39cb492015-01-30 12:01:34 +0000235#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200236#if defined(MBEDTLS_PLATFORM_EXIT_MACRO)
237#define mbedtls_exit MBEDTLS_PLATFORM_EXIT_MACRO
Rich Evans16f8cd82015-02-06 16:14:34 +0000238#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200239#define mbedtls_exit exit
240#endif /* MBEDTLS_PLATFORM_EXIT_MACRO */
241#endif /* MBEDTLS_PLATFORM_EXIT_ALT */
Paul Bakker747a83a2014-02-01 22:50:07 +0100242
Janos Follath91947442016-03-18 13:49:27 +0000243/*
244 * The default exit values
245 */
246#if defined(MBEDTLS_PLATFORM_STD_EXIT_SUCCESS)
247#define MBEDTLS_EXIT_SUCCESS MBEDTLS_PLATFORM_STD_EXIT_SUCCESS
248#else
249#define MBEDTLS_EXIT_SUCCESS 0
250#endif
251#if defined(MBEDTLS_PLATFORM_STD_EXIT_FAILURE)
252#define MBEDTLS_EXIT_FAILURE MBEDTLS_PLATFORM_STD_EXIT_FAILURE
253#else
254#define MBEDTLS_EXIT_FAILURE 1
255#endif
256
SimonBd5800b72016-04-26 07:43:27 +0100257/*
Paul Bakkere021a4b2016-06-01 11:25:44 +0100258 * The function pointers for reading from and writing a seed file to
259 * Non-Volatile storage (NV) in a platform-independent way
260 *
261 * Only enabled when the NV seed entropy source is enabled
262 */
263#if defined(MBEDTLS_ENTROPY_NV_SEED)
264#if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS) && defined(MBEDTLS_FS_IO)
265/* Internal standard platform definitions */
266int mbedtls_platform_std_nv_seed_read( unsigned char *buf, size_t buf_len );
267int mbedtls_platform_std_nv_seed_write( unsigned char *buf, size_t buf_len );
268#endif
269
270#if defined(MBEDTLS_PLATFORM_NV_SEED_ALT)
271extern int (*mbedtls_nv_seed_read)( unsigned char *buf, size_t buf_len );
272extern int (*mbedtls_nv_seed_write)( unsigned char *buf, size_t buf_len );
273
274/**
Rose Zadik332658d2018-01-25 22:02:53 +0000275 * \brief This function allows configuring custom seed file writing and
276 * reading functions.
Paul Bakkere021a4b2016-06-01 11:25:44 +0100277 *
Rose Zadik332658d2018-01-25 22:02:53 +0000278 * \param nv_seed_read_func The seed reading function implementation.
279 * \param nv_seed_write_func The seed writing function implementation.
Paul Bakkere021a4b2016-06-01 11:25:44 +0100280 *
Rose Zadik332658d2018-01-25 22:02:53 +0000281 * \return \c 0 on success.
Paul Bakkere021a4b2016-06-01 11:25:44 +0100282 */
283int mbedtls_platform_set_nv_seed(
284 int (*nv_seed_read_func)( unsigned char *buf, size_t buf_len ),
285 int (*nv_seed_write_func)( unsigned char *buf, size_t buf_len )
286 );
287#else
288#if defined(MBEDTLS_PLATFORM_NV_SEED_READ_MACRO) && \
289 defined(MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO)
290#define mbedtls_nv_seed_read MBEDTLS_PLATFORM_NV_SEED_READ_MACRO
291#define mbedtls_nv_seed_write MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO
292#else
293#define mbedtls_nv_seed_read mbedtls_platform_std_nv_seed_read
294#define mbedtls_nv_seed_write mbedtls_platform_std_nv_seed_write
295#endif
296#endif /* MBEDTLS_PLATFORM_NV_SEED_ALT */
297#endif /* MBEDTLS_ENTROPY_NV_SEED */
298
Andres Amaya Garciad91f99f2017-07-18 10:23:04 +0100299#if !defined(MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT)
Andres Amaya Garcia3c8a39d2017-07-12 11:25:17 +0100300
Andres Amaya Garcia64b02cd2017-07-12 11:32:40 +0100301/**
Rose Zadik332658d2018-01-25 22:02:53 +0000302 * \brief The platform context structure.
Andres Amaya Garcia64b02cd2017-07-12 11:32:40 +0100303 *
304 * \note This structure may be used to assist platform-specific
Rose Zadik332658d2018-01-25 22:02:53 +0000305 * setup or teardown operations.
Andres Amaya Garcia64b02cd2017-07-12 11:32:40 +0100306 */
307typedef struct {
Rose Zadik4bca2b02018-03-27 13:12:52 +0100308 char dummy; /**< A placeholder member, as empty structs are not portable. */
Andres Amaya Garcia64b02cd2017-07-12 11:32:40 +0100309}
310mbedtls_platform_context;
311
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100312#else
313#include "platform_alt.h"
Andres Amaya Garciad91f99f2017-07-18 10:23:04 +0100314#endif /* !MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT */
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100315
316/**
Rose Zadik4bca2b02018-03-27 13:12:52 +0100317 * \brief This function performs any platform-specific initialization operations.
318 *
319 * \note This function should be called before any other library functions.
320 *
321 * Its implementation is platform-specific, and unless
322 * platform-specific code is provided, it does nothing.
323 *
324 * \note The usage and necessity of this function is dependent on the platform.
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100325 *
Rose Zadik332658d2018-01-25 22:02:53 +0000326 * \param ctx The Mbed TLS context.
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100327 *
Rose Zadik332658d2018-01-25 22:02:53 +0000328 * \return \c 0 on success.
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100329 */
330int mbedtls_platform_setup( mbedtls_platform_context *ctx );
331/**
Rose Zadik332658d2018-01-25 22:02:53 +0000332 * \brief This function performs any platform teardown operations.
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100333 *
Rose Zadik332658d2018-01-25 22:02:53 +0000334 * \note This function should be called after every other Mbed TLS module
335 * has been correctly freed using the appropriate free function.
Rose Zadik4bca2b02018-03-27 13:12:52 +0100336 *
Rose Zadik332658d2018-01-25 22:02:53 +0000337 * 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 Zadik4bca2b02018-03-27 13:12:52 +0100340 * \note The usage and necessity of this function is dependent on the platform.
341 *
342 * \param ctx The Mbed TLS context.
343 *
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100344 */
345void mbedtls_platform_teardown( mbedtls_platform_context *ctx );
346
Paul Bakker747a83a2014-02-01 22:50:07 +0100347#ifdef __cplusplus
348}
349#endif
350
351#endif /* platform.h */