blob: 5cd143ce53fbbdf297b39b946ca77d9e668d9e3c [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.
Rose Zadik9464d7b2018-04-16 15:28:35 +01006 *
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 Green11999bb2018-03-13 15:22:58 +000012 * their platform, which can be statically linked to the library or
Rose Zadik9464d7b2018-04-16 15:28:35 +010013 * dynamically configured at runtime.
Darryl Greena40a1012018-01-05 15:33:17 +000014 */
15/*
Rose Zadik332658d2018-01-25 22:02:53 +000016 * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020017 * SPDX-License-Identifier: Apache-2.0
18 *
19 * Licensed under the Apache License, Version 2.0 (the "License"); you may
20 * not use this file except in compliance with the License.
21 * You may obtain a copy of the License at
22 *
23 * http://www.apache.org/licenses/LICENSE-2.0
24 *
25 * Unless required by applicable law or agreed to in writing, software
26 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
27 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28 * See the License for the specific language governing permissions and
29 * limitations under the License.
Paul Bakker747a83a2014-02-01 22:50:07 +010030 *
Rose Zadik332658d2018-01-25 22:02:53 +000031 * This file is part of Mbed TLS (https://tls.mbed.org)
Paul Bakker747a83a2014-02-01 22:50:07 +010032 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020033#ifndef MBEDTLS_PLATFORM_H
34#define MBEDTLS_PLATFORM_H
Paul Bakker747a83a2014-02-01 22:50:07 +010035
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020036#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker747a83a2014-02-01 22:50:07 +010037#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020038#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020039#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020040#endif
Paul Bakker747a83a2014-02-01 22:50:07 +010041
Simon Butcherb5b6af22016-07-13 14:46:18 +010042#if defined(MBEDTLS_HAVE_TIME)
Ron Eldor6fd941f2017-05-14 16:17:33 +030043#include "platform_time.h"
Simon Butcherb5b6af22016-07-13 14:46:18 +010044#endif
45
Ron Eldor5267b622018-10-15 18:44:42 +030046#define MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED -0x0070 /**< Hardware accelerator failed */
Ron Eldor0ff4e0b2018-08-29 18:53:20 +030047
Paul Bakker747a83a2014-02-01 22:50:07 +010048#ifdef __cplusplus
49extern "C" {
50#endif
51
Paul Bakker088c5c52014-04-25 11:11:10 +020052/**
53 * \name SECTION: Module settings
54 *
55 * The configuration options you can set for this module are in this section.
56 * Either change them in config.h or define them on the compiler command line.
57 * \{
58 */
59
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060#if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS)
Rich Evans00ab4702015-02-06 13:43:58 +000061#include <stdio.h>
Paul Bakkera9066cf2014-02-05 15:13:04 +010062#include <stdlib.h>
Simon Butcher3fe6cd32016-04-26 19:51:29 +010063#include <time.h>
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064#if !defined(MBEDTLS_PLATFORM_STD_SNPRINTF)
Manuel Pégourié-Gonnard6c0c8e02015-06-22 10:23:34 +020065#if defined(_WIN32)
Rose Zadik332658d2018-01-25 22:02:53 +000066#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 +020067#else
Rose Zadik332658d2018-01-25 22:02:53 +000068#define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf /**< The default \c snprintf function to use. */
Rich Evans46b0a8d2015-01-30 10:47:32 +000069#endif
Manuel Pégourié-Gonnard6c0c8e02015-06-22 10:23:34 +020070#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020071#if !defined(MBEDTLS_PLATFORM_STD_PRINTF)
Rose Zadik332658d2018-01-25 22:02:53 +000072#define MBEDTLS_PLATFORM_STD_PRINTF printf /**< The default \c printf function to use. */
Paul Bakker088c5c52014-04-25 11:11:10 +020073#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020074#if !defined(MBEDTLS_PLATFORM_STD_FPRINTF)
Rose Zadik332658d2018-01-25 22:02:53 +000075#define MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< The default \c fprintf function to use. */
Paul Bakker088c5c52014-04-25 11:11:10 +020076#endif
Manuel Pégourié-Gonnardb9ef1182015-05-26 16:15:20 +020077#if !defined(MBEDTLS_PLATFORM_STD_CALLOC)
Rose Zadik332658d2018-01-25 22:02:53 +000078#define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< The default \c calloc function to use. */
Paul Bakker088c5c52014-04-25 11:11:10 +020079#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020080#if !defined(MBEDTLS_PLATFORM_STD_FREE)
Rose Zadik332658d2018-01-25 22:02:53 +000081#define MBEDTLS_PLATFORM_STD_FREE free /**< The default \c free function to use. */
Paul Bakker088c5c52014-04-25 11:11:10 +020082#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020083#if !defined(MBEDTLS_PLATFORM_STD_EXIT)
Rose Zadik332658d2018-01-25 22:02:53 +000084#define MBEDTLS_PLATFORM_STD_EXIT exit /**< The default \c exit function to use. */
Janos Follath91947442016-03-18 13:49:27 +000085#endif
SimonBd5800b72016-04-26 07:43:27 +010086#if !defined(MBEDTLS_PLATFORM_STD_TIME)
Rose Zadik332658d2018-01-25 22:02:53 +000087#define MBEDTLS_PLATFORM_STD_TIME time /**< The default \c time function to use. */
SimonBd5800b72016-04-26 07:43:27 +010088#endif
Janos Follath91947442016-03-18 13:49:27 +000089#if !defined(MBEDTLS_PLATFORM_STD_EXIT_SUCCESS)
Rose Zadik332658d2018-01-25 22:02:53 +000090#define MBEDTLS_PLATFORM_STD_EXIT_SUCCESS EXIT_SUCCESS /**< The default exit value to use. */
Janos Follath91947442016-03-18 13:49:27 +000091#endif
92#if !defined(MBEDTLS_PLATFORM_STD_EXIT_FAILURE)
Rose Zadik332658d2018-01-25 22:02:53 +000093#define MBEDTLS_PLATFORM_STD_EXIT_FAILURE EXIT_FAILURE /**< The default exit value to use. */
Rich Evansc39cb492015-01-30 12:01:34 +000094#endif
Paul Bakkera9c321c2016-06-01 11:44:12 +010095#if defined(MBEDTLS_FS_IO)
Paul Bakkere021a4b2016-06-01 11:25:44 +010096#if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_READ)
97#define MBEDTLS_PLATFORM_STD_NV_SEED_READ mbedtls_platform_std_nv_seed_read
98#endif
99#if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_WRITE)
100#define MBEDTLS_PLATFORM_STD_NV_SEED_WRITE mbedtls_platform_std_nv_seed_write
101#endif
102#if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_FILE)
103#define MBEDTLS_PLATFORM_STD_NV_SEED_FILE "seedfile"
104#endif
Paul Bakkera9c321c2016-06-01 11:44:12 +0100105#endif /* MBEDTLS_FS_IO */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200106#else /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
107#if defined(MBEDTLS_PLATFORM_STD_MEM_HDR)
108#include MBEDTLS_PLATFORM_STD_MEM_HDR
Manuel Pégourié-Gonnardeb82a742014-04-02 13:43:48 +0200109#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200110#endif /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
Paul Bakker088c5c52014-04-25 11:11:10 +0200111
Paul Bakkere021a4b2016-06-01 11:25:44 +0100112
Paul Bakker088c5c52014-04-25 11:11:10 +0200113/* \} name SECTION: Module settings */
Paul Bakker747a83a2014-02-01 22:50:07 +0100114
115/*
Rose Zadik4bca2b02018-03-27 13:12:52 +0100116 * The function pointers for calloc and free.
Paul Bakker747a83a2014-02-01 22:50:07 +0100117 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200118#if defined(MBEDTLS_PLATFORM_MEMORY)
119#if defined(MBEDTLS_PLATFORM_FREE_MACRO) && \
Manuel Pégourié-Gonnardb9ef1182015-05-26 16:15:20 +0200120 defined(MBEDTLS_PLATFORM_CALLOC_MACRO)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200121#define mbedtls_free MBEDTLS_PLATFORM_FREE_MACRO
Manuel Pégourié-Gonnardb9ef1182015-05-26 16:15:20 +0200122#define mbedtls_calloc MBEDTLS_PLATFORM_CALLOC_MACRO
Rich Evans401bb902015-02-10 12:28:15 +0000123#else
Manuel Pégourié-Gonnard7ee5ddd2015-06-03 10:33:55 +0100124/* For size_t */
125#include <stddef.h>
Roberto Vargas7decfe82018-06-04 13:54:09 +0100126extern void *mbedtls_calloc( size_t n, size_t size );
127extern void mbedtls_free( void *ptr );
Paul Bakkerdefc0ca2014-02-04 17:30:24 +0100128
129/**
Rose Zadik9464d7b2018-04-16 15:28:35 +0100130 * \brief This function dynamically sets the memory-management
131 * functions used by the library, during runtime.
Paul Bakkerdefc0ca2014-02-04 17:30:24 +0100132 *
Rose Zadik332658d2018-01-25 22:02:53 +0000133 * \param calloc_func The \c calloc function implementation.
134 * \param free_func The \c free function implementation.
Paul Bakkerdefc0ca2014-02-04 17:30:24 +0100135 *
Rose Zadik332658d2018-01-25 22:02:53 +0000136 * \return \c 0.
Paul Bakkerdefc0ca2014-02-04 17:30:24 +0100137 */
Manuel Pégourié-Gonnardb9ef1182015-05-26 16:15:20 +0200138int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ),
Paul Bakkerdefc0ca2014-02-04 17:30:24 +0100139 void (*free_func)( void * ) );
Manuel Pégourié-Gonnardb9ef1182015-05-26 16:15:20 +0200140#endif /* MBEDTLS_PLATFORM_FREE_MACRO && MBEDTLS_PLATFORM_CALLOC_MACRO */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200141#else /* !MBEDTLS_PLATFORM_MEMORY */
142#define mbedtls_free free
Manuel Pégourié-Gonnardb9ef1182015-05-26 16:15:20 +0200143#define mbedtls_calloc calloc
144#endif /* MBEDTLS_PLATFORM_MEMORY && !MBEDTLS_PLATFORM_{FREE,CALLOC}_MACRO */
Paul Bakker747a83a2014-02-01 22:50:07 +0100145
146/*
147 * The function pointers for fprintf
148 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200149#if defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
Manuel Pégourié-Gonnard7ee5ddd2015-06-03 10:33:55 +0100150/* We need FILE * */
151#include <stdio.h>
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200152extern int (*mbedtls_fprintf)( FILE *stream, const char *format, ... );
Paul Bakker747a83a2014-02-01 22:50:07 +0100153
Rich Evansc39cb492015-01-30 12:01:34 +0000154/**
Rose Zadik9464d7b2018-04-16 15:28:35 +0100155 * \brief This function dynamically configures the fprintf
156 * function that is called when the
157 * mbedtls_fprintf() function is invoked by the library.
Rich Evansc39cb492015-01-30 12:01:34 +0000158 *
Rose Zadik332658d2018-01-25 22:02:53 +0000159 * \param fprintf_func The \c fprintf function implementation.
Rich Evansc39cb492015-01-30 12:01:34 +0000160 *
Rose Zadik332658d2018-01-25 22:02:53 +0000161 * \return \c 0.
Rich Evansc39cb492015-01-30 12:01:34 +0000162 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200163int mbedtls_platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *,
Paul Bakker747a83a2014-02-01 22:50:07 +0100164 ... ) );
165#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200166#if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO)
167#define mbedtls_fprintf MBEDTLS_PLATFORM_FPRINTF_MACRO
Rich Evans16f8cd82015-02-06 16:14:34 +0000168#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200169#define mbedtls_fprintf fprintf
170#endif /* MBEDTLS_PLATFORM_FPRINTF_MACRO */
171#endif /* MBEDTLS_PLATFORM_FPRINTF_ALT */
Rich Evansc39cb492015-01-30 12:01:34 +0000172
173/*
Rich Evans16f8cd82015-02-06 16:14:34 +0000174 * The function pointers for printf
175 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200176#if defined(MBEDTLS_PLATFORM_PRINTF_ALT)
177extern int (*mbedtls_printf)( const char *format, ... );
Rich Evans16f8cd82015-02-06 16:14:34 +0000178
179/**
Rose Zadik9464d7b2018-04-16 15:28:35 +0100180 * \brief This function dynamically configures the snprintf
181 * function that is called when the mbedtls_snprintf()
182 * function is invoked by the library.
Rich Evans16f8cd82015-02-06 16:14:34 +0000183 *
Rose Zadik332658d2018-01-25 22:02:53 +0000184 * \param printf_func The \c printf function implementation.
Rich Evans16f8cd82015-02-06 16:14:34 +0000185 *
Rose Zadik332658d2018-01-25 22:02:53 +0000186 * \return \c 0 on success.
Rich Evans16f8cd82015-02-06 16:14:34 +0000187 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200188int mbedtls_platform_set_printf( int (*printf_func)( const char *, ... ) );
189#else /* !MBEDTLS_PLATFORM_PRINTF_ALT */
190#if defined(MBEDTLS_PLATFORM_PRINTF_MACRO)
191#define mbedtls_printf MBEDTLS_PLATFORM_PRINTF_MACRO
Rich Evans16f8cd82015-02-06 16:14:34 +0000192#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200193#define mbedtls_printf printf
194#endif /* MBEDTLS_PLATFORM_PRINTF_MACRO */
195#endif /* MBEDTLS_PLATFORM_PRINTF_ALT */
Rich Evans16f8cd82015-02-06 16:14:34 +0000196
197/*
198 * The function pointers for snprintf
Manuel Pégourié-Gonnard6c0c8e02015-06-22 10:23:34 +0200199 *
200 * The snprintf implementation should conform to C99:
201 * - it *must* always correctly zero-terminate the buffer
202 * (except when n == 0, then it must leave the buffer untouched)
203 * - however it is acceptable to return -1 instead of the required length when
204 * the destination buffer is too short.
Rich Evans16f8cd82015-02-06 16:14:34 +0000205 */
Manuel Pégourié-Gonnard6c0c8e02015-06-22 10:23:34 +0200206#if defined(_WIN32)
207/* For Windows (inc. MSYS2), we provide our own fixed implementation */
208int mbedtls_platform_win32_snprintf( char *s, size_t n, const char *fmt, ... );
209#endif
210
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200211#if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
212extern int (*mbedtls_snprintf)( char * s, size_t n, const char * format, ... );
Rich Evans16f8cd82015-02-06 16:14:34 +0000213
214/**
Rose Zadik4bca2b02018-03-27 13:12:52 +0100215 * \brief This function allows configuring a custom
216 * \c snprintf function pointer.
Rich Evans16f8cd82015-02-06 16:14:34 +0000217 *
Rose Zadik332658d2018-01-25 22:02:53 +0000218 * \param snprintf_func The \c snprintf function implementation.
Rich Evans16f8cd82015-02-06 16:14:34 +0000219 *
Rose Zadik4bca2b02018-03-27 13:12:52 +0100220 * \return \c 0 on success.
Rich Evans16f8cd82015-02-06 16:14:34 +0000221 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200222int mbedtls_platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
Rich Evans16f8cd82015-02-06 16:14:34 +0000223 const char * format, ... ) );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200224#else /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
225#if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO)
226#define mbedtls_snprintf MBEDTLS_PLATFORM_SNPRINTF_MACRO
Rich Evans16f8cd82015-02-06 16:14:34 +0000227#else
Azim Khan8d54c062018-03-23 18:34:35 +0000228#define mbedtls_snprintf MBEDTLS_PLATFORM_STD_SNPRINTF
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200229#endif /* MBEDTLS_PLATFORM_SNPRINTF_MACRO */
230#endif /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
Rich Evans16f8cd82015-02-06 16:14:34 +0000231
232/*
Rich Evansc39cb492015-01-30 12:01:34 +0000233 * The function pointers for exit
234 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200235#if defined(MBEDTLS_PLATFORM_EXIT_ALT)
236extern void (*mbedtls_exit)( int status );
Rich Evansc39cb492015-01-30 12:01:34 +0000237
238/**
Rose Zadik9464d7b2018-04-16 15:28:35 +0100239 * \brief This function dynamically configures the exit
240 * function that is called when the mbedtls_exit()
241 * function is invoked by the library.
Rich Evansc39cb492015-01-30 12:01:34 +0000242 *
Rose Zadik332658d2018-01-25 22:02:53 +0000243 * \param exit_func The \c exit function implementation.
Rich Evansc39cb492015-01-30 12:01:34 +0000244 *
Rose Zadik4bca2b02018-03-27 13:12:52 +0100245 * \return \c 0 on success.
Rich Evansc39cb492015-01-30 12:01:34 +0000246 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200247int mbedtls_platform_set_exit( void (*exit_func)( int status ) );
Rich Evansc39cb492015-01-30 12:01:34 +0000248#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200249#if defined(MBEDTLS_PLATFORM_EXIT_MACRO)
250#define mbedtls_exit MBEDTLS_PLATFORM_EXIT_MACRO
Rich Evans16f8cd82015-02-06 16:14:34 +0000251#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200252#define mbedtls_exit exit
253#endif /* MBEDTLS_PLATFORM_EXIT_MACRO */
254#endif /* MBEDTLS_PLATFORM_EXIT_ALT */
Paul Bakker747a83a2014-02-01 22:50:07 +0100255
Janos Follath91947442016-03-18 13:49:27 +0000256/*
257 * The default exit values
258 */
259#if defined(MBEDTLS_PLATFORM_STD_EXIT_SUCCESS)
260#define MBEDTLS_EXIT_SUCCESS MBEDTLS_PLATFORM_STD_EXIT_SUCCESS
261#else
262#define MBEDTLS_EXIT_SUCCESS 0
263#endif
264#if defined(MBEDTLS_PLATFORM_STD_EXIT_FAILURE)
265#define MBEDTLS_EXIT_FAILURE MBEDTLS_PLATFORM_STD_EXIT_FAILURE
266#else
267#define MBEDTLS_EXIT_FAILURE 1
268#endif
269
SimonBd5800b72016-04-26 07:43:27 +0100270/*
Paul Bakkere021a4b2016-06-01 11:25:44 +0100271 * The function pointers for reading from and writing a seed file to
272 * Non-Volatile storage (NV) in a platform-independent way
273 *
274 * Only enabled when the NV seed entropy source is enabled
275 */
276#if defined(MBEDTLS_ENTROPY_NV_SEED)
277#if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS) && defined(MBEDTLS_FS_IO)
278/* Internal standard platform definitions */
279int mbedtls_platform_std_nv_seed_read( unsigned char *buf, size_t buf_len );
280int mbedtls_platform_std_nv_seed_write( unsigned char *buf, size_t buf_len );
281#endif
282
283#if defined(MBEDTLS_PLATFORM_NV_SEED_ALT)
284extern int (*mbedtls_nv_seed_read)( unsigned char *buf, size_t buf_len );
285extern int (*mbedtls_nv_seed_write)( unsigned char *buf, size_t buf_len );
286
287/**
Rose Zadik332658d2018-01-25 22:02:53 +0000288 * \brief This function allows configuring custom seed file writing and
289 * reading functions.
Paul Bakkere021a4b2016-06-01 11:25:44 +0100290 *
Rose Zadik332658d2018-01-25 22:02:53 +0000291 * \param nv_seed_read_func The seed reading function implementation.
292 * \param nv_seed_write_func The seed writing function implementation.
Paul Bakkere021a4b2016-06-01 11:25:44 +0100293 *
Rose Zadik332658d2018-01-25 22:02:53 +0000294 * \return \c 0 on success.
Paul Bakkere021a4b2016-06-01 11:25:44 +0100295 */
296int mbedtls_platform_set_nv_seed(
297 int (*nv_seed_read_func)( unsigned char *buf, size_t buf_len ),
298 int (*nv_seed_write_func)( unsigned char *buf, size_t buf_len )
299 );
300#else
301#if defined(MBEDTLS_PLATFORM_NV_SEED_READ_MACRO) && \
302 defined(MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO)
303#define mbedtls_nv_seed_read MBEDTLS_PLATFORM_NV_SEED_READ_MACRO
304#define mbedtls_nv_seed_write MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO
305#else
306#define mbedtls_nv_seed_read mbedtls_platform_std_nv_seed_read
307#define mbedtls_nv_seed_write mbedtls_platform_std_nv_seed_write
308#endif
309#endif /* MBEDTLS_PLATFORM_NV_SEED_ALT */
310#endif /* MBEDTLS_ENTROPY_NV_SEED */
311
Andres Amaya Garciad91f99f2017-07-18 10:23:04 +0100312#if !defined(MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT)
Andres Amaya Garcia3c8a39d2017-07-12 11:25:17 +0100313
Andres Amaya Garcia64b02cd2017-07-12 11:32:40 +0100314/**
Rose Zadik332658d2018-01-25 22:02:53 +0000315 * \brief The platform context structure.
Andres Amaya Garcia64b02cd2017-07-12 11:32:40 +0100316 *
317 * \note This structure may be used to assist platform-specific
Rose Zadik332658d2018-01-25 22:02:53 +0000318 * setup or teardown operations.
Andres Amaya Garcia64b02cd2017-07-12 11:32:40 +0100319 */
Dawid Drozd428cc522018-07-24 10:02:47 +0200320typedef struct mbedtls_platform_context
321{
Rose Zadik4bca2b02018-03-27 13:12:52 +0100322 char dummy; /**< A placeholder member, as empty structs are not portable. */
Andres Amaya Garcia64b02cd2017-07-12 11:32:40 +0100323}
324mbedtls_platform_context;
325
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100326#else
327#include "platform_alt.h"
Andres Amaya Garciad91f99f2017-07-18 10:23:04 +0100328#endif /* !MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT */
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100329
330/**
Rose Zadik9464d7b2018-04-16 15:28:35 +0100331 * \brief This function performs any platform-specific initialization
332 * operations.
Rose Zadik4bca2b02018-03-27 13:12:52 +0100333 *
334 * \note This function should be called before any other library functions.
335 *
336 * Its implementation is platform-specific, and unless
Darryl Green11999bb2018-03-13 15:22:58 +0000337 * platform-specific code is provided, it does nothing.
Rose Zadik4bca2b02018-03-27 13:12:52 +0100338 *
339 * \note The usage and necessity of this function is dependent on the platform.
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100340 *
Rose Zadik9464d7b2018-04-16 15:28:35 +0100341 * \param ctx The platform context.
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100342 *
Rose Zadik332658d2018-01-25 22:02:53 +0000343 * \return \c 0 on success.
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100344 */
345int mbedtls_platform_setup( mbedtls_platform_context *ctx );
346/**
Rose Zadik332658d2018-01-25 22:02:53 +0000347 * \brief This function performs any platform teardown operations.
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100348 *
Rose Zadik332658d2018-01-25 22:02:53 +0000349 * \note This function should be called after every other Mbed TLS module
350 * has been correctly freed using the appropriate free function.
Rose Zadik4bca2b02018-03-27 13:12:52 +0100351 *
Rose Zadik332658d2018-01-25 22:02:53 +0000352 * Its implementation is platform-specific, and unless
353 * platform-specific code is provided, it does nothing.
Simon Butcherd3be27a2017-07-21 02:08:00 +0200354 *
Rose Zadik4bca2b02018-03-27 13:12:52 +0100355 * \note The usage and necessity of this function is dependent on the platform.
356 *
Rose Zadik9464d7b2018-04-16 15:28:35 +0100357 * \param ctx The platform context.
Rose Zadik4bca2b02018-03-27 13:12:52 +0100358 *
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100359 */
360void mbedtls_platform_teardown( mbedtls_platform_context *ctx );
361
Paul Bakker747a83a2014-02-01 22:50:07 +0100362#ifdef __cplusplus
363}
364#endif
365
366#endif /* platform.h */