blob: 4eaad53c469f363d7e212215699d54d47379ac55 [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/*
Bence Szépkúti44bfbe32020-08-19 16:54:51 +02007 * Copyright The Mbed TLS Contributors
Bence Szépkúti4e9f7122020-06-05 13:02:18 +02008 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9 *
10 * This file is provided under the Apache License 2.0, or the
11 * GNU General Public License v2.0 or later.
12 *
13 * **********
14 * Apache License 2.0:
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020015 *
16 * Licensed under the Apache License, Version 2.0 (the "License"); you may
17 * not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
19 *
20 * http://www.apache.org/licenses/LICENSE-2.0
21 *
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
Paul Bakker747a83a2014-02-01 22:50:07 +010027 *
Bence Szépkúti4e9f7122020-06-05 13:02:18 +020028 * **********
29 *
30 * **********
31 * GNU General Public License v2.0 or later:
32 *
33 * This program is free software; you can redistribute it and/or modify
34 * it under the terms of the GNU General Public License as published by
35 * the Free Software Foundation; either version 2 of the License, or
36 * (at your option) any later version.
37 *
38 * This program is distributed in the hope that it will be useful,
39 * but WITHOUT ANY WARRANTY; without even the implied warranty of
40 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41 * GNU General Public License for more details.
42 *
43 * You should have received a copy of the GNU General Public License along
44 * with this program; if not, write to the Free Software Foundation, Inc.,
45 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
46 *
47 * **********
Paul Bakker747a83a2014-02-01 22:50:07 +010048 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020049#ifndef MBEDTLS_PLATFORM_H
50#define MBEDTLS_PLATFORM_H
Paul Bakker747a83a2014-02-01 22:50:07 +010051
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020052#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker747a83a2014-02-01 22:50:07 +010053#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020054#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020055#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020056#endif
Paul Bakker747a83a2014-02-01 22:50:07 +010057
Simon Butcherb5b6af22016-07-13 14:46:18 +010058#if defined(MBEDTLS_HAVE_TIME)
Ron Eldordf9b93e2017-05-14 16:17:33 +030059#include "platform_time.h"
Simon Butcherb5b6af22016-07-13 14:46:18 +010060#endif
61
Paul Bakker747a83a2014-02-01 22:50:07 +010062#ifdef __cplusplus
63extern "C" {
64#endif
65
Paul Bakker088c5c52014-04-25 11:11:10 +020066/**
67 * \name SECTION: Module settings
68 *
69 * The configuration options you can set for this module are in this section.
70 * Either change them in config.h or define them on the compiler command line.
71 * \{
72 */
73
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020074#if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS)
Rich Evans00ab4702015-02-06 13:43:58 +000075#include <stdio.h>
Paul Bakkera9066cf2014-02-05 15:13:04 +010076#include <stdlib.h>
Simon Butcher3fe6cd32016-04-26 19:51:29 +010077#include <time.h>
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020078#if !defined(MBEDTLS_PLATFORM_STD_SNPRINTF)
Manuel Pégourié-Gonnard6c0c8e02015-06-22 10:23:34 +020079#if defined(_WIN32)
Rose Zadik332658d2018-01-25 22:02:53 +000080#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 +020081#else
Rose Zadik332658d2018-01-25 22:02:53 +000082#define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf /**< The default \c snprintf function to use. */
Rich Evans46b0a8d2015-01-30 10:47:32 +000083#endif
Manuel Pégourié-Gonnard6c0c8e02015-06-22 10:23:34 +020084#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020085#if !defined(MBEDTLS_PLATFORM_STD_PRINTF)
Rose Zadik332658d2018-01-25 22:02:53 +000086#define MBEDTLS_PLATFORM_STD_PRINTF printf /**< The default \c printf function to use. */
Paul Bakker088c5c52014-04-25 11:11:10 +020087#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020088#if !defined(MBEDTLS_PLATFORM_STD_FPRINTF)
Rose Zadik332658d2018-01-25 22:02:53 +000089#define MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< The default \c fprintf function to use. */
Paul Bakker088c5c52014-04-25 11:11:10 +020090#endif
Manuel Pégourié-Gonnardb9ef1182015-05-26 16:15:20 +020091#if !defined(MBEDTLS_PLATFORM_STD_CALLOC)
Rose Zadik332658d2018-01-25 22:02:53 +000092#define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< The default \c calloc function to use. */
Paul Bakker088c5c52014-04-25 11:11:10 +020093#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020094#if !defined(MBEDTLS_PLATFORM_STD_FREE)
Rose Zadik332658d2018-01-25 22:02:53 +000095#define MBEDTLS_PLATFORM_STD_FREE free /**< The default \c free function to use. */
Paul Bakker088c5c52014-04-25 11:11:10 +020096#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020097#if !defined(MBEDTLS_PLATFORM_STD_EXIT)
Rose Zadik332658d2018-01-25 22:02:53 +000098#define MBEDTLS_PLATFORM_STD_EXIT exit /**< The default \c exit function to use. */
Janos Follath91947442016-03-18 13:49:27 +000099#endif
SimonBd5800b72016-04-26 07:43:27 +0100100#if !defined(MBEDTLS_PLATFORM_STD_TIME)
Rose Zadik332658d2018-01-25 22:02:53 +0000101#define MBEDTLS_PLATFORM_STD_TIME time /**< The default \c time function to use. */
SimonBd5800b72016-04-26 07:43:27 +0100102#endif
Janos Follath91947442016-03-18 13:49:27 +0000103#if !defined(MBEDTLS_PLATFORM_STD_EXIT_SUCCESS)
Rose Zadik332658d2018-01-25 22:02:53 +0000104#define MBEDTLS_PLATFORM_STD_EXIT_SUCCESS EXIT_SUCCESS /**< The default exit value to use. */
Janos Follath91947442016-03-18 13:49:27 +0000105#endif
106#if !defined(MBEDTLS_PLATFORM_STD_EXIT_FAILURE)
Rose Zadik332658d2018-01-25 22:02:53 +0000107#define MBEDTLS_PLATFORM_STD_EXIT_FAILURE EXIT_FAILURE /**< The default exit value to use. */
Rich Evansc39cb492015-01-30 12:01:34 +0000108#endif
Paul Bakkera9c321c2016-06-01 11:44:12 +0100109#if defined(MBEDTLS_FS_IO)
Paul Bakkere021a4b2016-06-01 11:25:44 +0100110#if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_READ)
111#define MBEDTLS_PLATFORM_STD_NV_SEED_READ mbedtls_platform_std_nv_seed_read
112#endif
113#if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_WRITE)
114#define MBEDTLS_PLATFORM_STD_NV_SEED_WRITE mbedtls_platform_std_nv_seed_write
115#endif
116#if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_FILE)
117#define MBEDTLS_PLATFORM_STD_NV_SEED_FILE "seedfile"
118#endif
Paul Bakkera9c321c2016-06-01 11:44:12 +0100119#endif /* MBEDTLS_FS_IO */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200120#else /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
121#if defined(MBEDTLS_PLATFORM_STD_MEM_HDR)
122#include MBEDTLS_PLATFORM_STD_MEM_HDR
Manuel Pégourié-Gonnardeb82a742014-04-02 13:43:48 +0200123#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200124#endif /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
Paul Bakker088c5c52014-04-25 11:11:10 +0200125
Paul Bakkere021a4b2016-06-01 11:25:44 +0100126
Paul Bakker088c5c52014-04-25 11:11:10 +0200127/* \} name SECTION: Module settings */
Paul Bakker747a83a2014-02-01 22:50:07 +0100128
129/*
Manuel Pégourié-Gonnardb9ef1182015-05-26 16:15:20 +0200130 * The function pointers for calloc and free
Paul Bakker747a83a2014-02-01 22:50:07 +0100131 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200132#if defined(MBEDTLS_PLATFORM_MEMORY)
133#if defined(MBEDTLS_PLATFORM_FREE_MACRO) && \
Manuel Pégourié-Gonnardb9ef1182015-05-26 16:15:20 +0200134 defined(MBEDTLS_PLATFORM_CALLOC_MACRO)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200135#define mbedtls_free MBEDTLS_PLATFORM_FREE_MACRO
Manuel Pégourié-Gonnardb9ef1182015-05-26 16:15:20 +0200136#define mbedtls_calloc MBEDTLS_PLATFORM_CALLOC_MACRO
Rich Evans401bb902015-02-10 12:28:15 +0000137#else
Manuel Pégourié-Gonnard7ee5ddd2015-06-03 10:33:55 +0100138/* For size_t */
139#include <stddef.h>
Manuel Pégourié-Gonnardb9ef1182015-05-26 16:15:20 +0200140extern void * (*mbedtls_calloc)( size_t n, size_t size );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200141extern void (*mbedtls_free)( void *ptr );
Paul Bakkerdefc0ca2014-02-04 17:30:24 +0100142
143/**
Rose Zadik332658d2018-01-25 22:02:53 +0000144 * \brief This function allows configuring custom memory-management functions.
Paul Bakkerdefc0ca2014-02-04 17:30:24 +0100145 *
Rose Zadik332658d2018-01-25 22:02:53 +0000146 * \param calloc_func The \c calloc function implementation.
147 * \param free_func The \c free function implementation.
Paul Bakkerdefc0ca2014-02-04 17:30:24 +0100148 *
Rose Zadik332658d2018-01-25 22:02:53 +0000149 * \return \c 0.
Paul Bakkerdefc0ca2014-02-04 17:30:24 +0100150 */
Manuel Pégourié-Gonnardb9ef1182015-05-26 16:15:20 +0200151int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ),
Paul Bakkerdefc0ca2014-02-04 17:30:24 +0100152 void (*free_func)( void * ) );
Manuel Pégourié-Gonnardb9ef1182015-05-26 16:15:20 +0200153#endif /* MBEDTLS_PLATFORM_FREE_MACRO && MBEDTLS_PLATFORM_CALLOC_MACRO */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200154#else /* !MBEDTLS_PLATFORM_MEMORY */
155#define mbedtls_free free
Manuel Pégourié-Gonnardb9ef1182015-05-26 16:15:20 +0200156#define mbedtls_calloc calloc
157#endif /* MBEDTLS_PLATFORM_MEMORY && !MBEDTLS_PLATFORM_{FREE,CALLOC}_MACRO */
Paul Bakker747a83a2014-02-01 22:50:07 +0100158
159/*
160 * The function pointers for fprintf
161 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200162#if defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
Manuel Pégourié-Gonnard7ee5ddd2015-06-03 10:33:55 +0100163/* We need FILE * */
164#include <stdio.h>
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200165extern int (*mbedtls_fprintf)( FILE *stream, const char *format, ... );
Paul Bakker747a83a2014-02-01 22:50:07 +0100166
Rich Evansc39cb492015-01-30 12:01:34 +0000167/**
Rose Zadik332658d2018-01-25 22:02:53 +0000168 * \brief This function allows configuring a custom \p fprintf function pointer.
Rich Evansc39cb492015-01-30 12:01:34 +0000169 *
Rose Zadik332658d2018-01-25 22:02:53 +0000170 * \param fprintf_func The \c fprintf function implementation.
Rich Evansc39cb492015-01-30 12:01:34 +0000171 *
Rose Zadik332658d2018-01-25 22:02:53 +0000172 * \return \c 0.
Rich Evansc39cb492015-01-30 12:01:34 +0000173 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200174int mbedtls_platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *,
Paul Bakker747a83a2014-02-01 22:50:07 +0100175 ... ) );
176#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200177#if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO)
178#define mbedtls_fprintf MBEDTLS_PLATFORM_FPRINTF_MACRO
Rich Evans16f8cd82015-02-06 16:14:34 +0000179#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200180#define mbedtls_fprintf fprintf
181#endif /* MBEDTLS_PLATFORM_FPRINTF_MACRO */
182#endif /* MBEDTLS_PLATFORM_FPRINTF_ALT */
Rich Evansc39cb492015-01-30 12:01:34 +0000183
184/*
Rich Evans16f8cd82015-02-06 16:14:34 +0000185 * The function pointers for printf
186 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200187#if defined(MBEDTLS_PLATFORM_PRINTF_ALT)
188extern int (*mbedtls_printf)( const char *format, ... );
Rich Evans16f8cd82015-02-06 16:14:34 +0000189
190/**
Rose Zadik332658d2018-01-25 22:02:53 +0000191 * \brief This function allows configuring a custom \c printf function
192 * pointer.
Rich Evans16f8cd82015-02-06 16:14:34 +0000193 *
Rose Zadik332658d2018-01-25 22:02:53 +0000194 * \param printf_func The \c printf function implementation.
Rich Evans16f8cd82015-02-06 16:14:34 +0000195 *
Rose Zadik332658d2018-01-25 22:02:53 +0000196 * \return \c 0 on success.
Rich Evans16f8cd82015-02-06 16:14:34 +0000197 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200198int mbedtls_platform_set_printf( int (*printf_func)( const char *, ... ) );
199#else /* !MBEDTLS_PLATFORM_PRINTF_ALT */
200#if defined(MBEDTLS_PLATFORM_PRINTF_MACRO)
201#define mbedtls_printf MBEDTLS_PLATFORM_PRINTF_MACRO
Rich Evans16f8cd82015-02-06 16:14:34 +0000202#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200203#define mbedtls_printf printf
204#endif /* MBEDTLS_PLATFORM_PRINTF_MACRO */
205#endif /* MBEDTLS_PLATFORM_PRINTF_ALT */
Rich Evans16f8cd82015-02-06 16:14:34 +0000206
207/*
208 * The function pointers for snprintf
Manuel Pégourié-Gonnard6c0c8e02015-06-22 10:23:34 +0200209 *
210 * The snprintf implementation should conform to C99:
211 * - it *must* always correctly zero-terminate the buffer
212 * (except when n == 0, then it must leave the buffer untouched)
213 * - however it is acceptable to return -1 instead of the required length when
214 * the destination buffer is too short.
Rich Evans16f8cd82015-02-06 16:14:34 +0000215 */
Manuel Pégourié-Gonnard6c0c8e02015-06-22 10:23:34 +0200216#if defined(_WIN32)
217/* For Windows (inc. MSYS2), we provide our own fixed implementation */
218int mbedtls_platform_win32_snprintf( char *s, size_t n, const char *fmt, ... );
219#endif
220
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200221#if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
222extern int (*mbedtls_snprintf)( char * s, size_t n, const char * format, ... );
Rich Evans16f8cd82015-02-06 16:14:34 +0000223
224/**
Rose Zadik332658d2018-01-25 22:02:53 +0000225 * \brief This function allows configuring a custom \c snprintf function
226 * pointer.
Rich Evans16f8cd82015-02-06 16:14:34 +0000227 *
Rose Zadik332658d2018-01-25 22:02:53 +0000228 * \param snprintf_func The \c snprintf function implementation.
Rich Evans16f8cd82015-02-06 16:14:34 +0000229 *
Rose Zadik332658d2018-01-25 22:02:53 +0000230 * \return \c 0 on success.
Rich Evans16f8cd82015-02-06 16:14:34 +0000231 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200232int mbedtls_platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
Rich Evans16f8cd82015-02-06 16:14:34 +0000233 const char * format, ... ) );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200234#else /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
235#if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO)
236#define mbedtls_snprintf MBEDTLS_PLATFORM_SNPRINTF_MACRO
Rich Evans16f8cd82015-02-06 16:14:34 +0000237#else
Azim Khan26838602018-03-23 18:34:35 +0000238#define mbedtls_snprintf MBEDTLS_PLATFORM_STD_SNPRINTF
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200239#endif /* MBEDTLS_PLATFORM_SNPRINTF_MACRO */
240#endif /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
Rich Evans16f8cd82015-02-06 16:14:34 +0000241
242/*
Rich Evansc39cb492015-01-30 12:01:34 +0000243 * The function pointers for exit
244 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200245#if defined(MBEDTLS_PLATFORM_EXIT_ALT)
246extern void (*mbedtls_exit)( int status );
Rich Evansc39cb492015-01-30 12:01:34 +0000247
248/**
Rose Zadik332658d2018-01-25 22:02:53 +0000249 * \brief This function allows configuring a custom \c exit function
250 * pointer.
Rich Evansc39cb492015-01-30 12:01:34 +0000251 *
Rose Zadik332658d2018-01-25 22:02:53 +0000252 * \param exit_func The \c exit function implementation.
Rich Evansc39cb492015-01-30 12:01:34 +0000253 *
Rose Zadik332658d2018-01-25 22:02:53 +0000254 * \return \c 0 on success.
Rich Evansc39cb492015-01-30 12:01:34 +0000255 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200256int mbedtls_platform_set_exit( void (*exit_func)( int status ) );
Rich Evansc39cb492015-01-30 12:01:34 +0000257#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200258#if defined(MBEDTLS_PLATFORM_EXIT_MACRO)
259#define mbedtls_exit MBEDTLS_PLATFORM_EXIT_MACRO
Rich Evans16f8cd82015-02-06 16:14:34 +0000260#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200261#define mbedtls_exit exit
262#endif /* MBEDTLS_PLATFORM_EXIT_MACRO */
263#endif /* MBEDTLS_PLATFORM_EXIT_ALT */
Paul Bakker747a83a2014-02-01 22:50:07 +0100264
Janos Follath91947442016-03-18 13:49:27 +0000265/*
266 * The default exit values
267 */
268#if defined(MBEDTLS_PLATFORM_STD_EXIT_SUCCESS)
269#define MBEDTLS_EXIT_SUCCESS MBEDTLS_PLATFORM_STD_EXIT_SUCCESS
270#else
271#define MBEDTLS_EXIT_SUCCESS 0
272#endif
273#if defined(MBEDTLS_PLATFORM_STD_EXIT_FAILURE)
274#define MBEDTLS_EXIT_FAILURE MBEDTLS_PLATFORM_STD_EXIT_FAILURE
275#else
276#define MBEDTLS_EXIT_FAILURE 1
277#endif
278
SimonBd5800b72016-04-26 07:43:27 +0100279/*
Paul Bakkere021a4b2016-06-01 11:25:44 +0100280 * The function pointers for reading from and writing a seed file to
281 * Non-Volatile storage (NV) in a platform-independent way
282 *
283 * Only enabled when the NV seed entropy source is enabled
284 */
285#if defined(MBEDTLS_ENTROPY_NV_SEED)
286#if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS) && defined(MBEDTLS_FS_IO)
287/* Internal standard platform definitions */
288int mbedtls_platform_std_nv_seed_read( unsigned char *buf, size_t buf_len );
289int mbedtls_platform_std_nv_seed_write( unsigned char *buf, size_t buf_len );
290#endif
291
292#if defined(MBEDTLS_PLATFORM_NV_SEED_ALT)
293extern int (*mbedtls_nv_seed_read)( unsigned char *buf, size_t buf_len );
294extern int (*mbedtls_nv_seed_write)( unsigned char *buf, size_t buf_len );
295
296/**
Rose Zadik332658d2018-01-25 22:02:53 +0000297 * \brief This function allows configuring custom seed file writing and
298 * reading functions.
Paul Bakkere021a4b2016-06-01 11:25:44 +0100299 *
Rose Zadik332658d2018-01-25 22:02:53 +0000300 * \param nv_seed_read_func The seed reading function implementation.
301 * \param nv_seed_write_func The seed writing function implementation.
Paul Bakkere021a4b2016-06-01 11:25:44 +0100302 *
Rose Zadik332658d2018-01-25 22:02:53 +0000303 * \return \c 0 on success.
Paul Bakkere021a4b2016-06-01 11:25:44 +0100304 */
305int mbedtls_platform_set_nv_seed(
306 int (*nv_seed_read_func)( unsigned char *buf, size_t buf_len ),
307 int (*nv_seed_write_func)( unsigned char *buf, size_t buf_len )
308 );
309#else
310#if defined(MBEDTLS_PLATFORM_NV_SEED_READ_MACRO) && \
311 defined(MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO)
312#define mbedtls_nv_seed_read MBEDTLS_PLATFORM_NV_SEED_READ_MACRO
313#define mbedtls_nv_seed_write MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO
314#else
315#define mbedtls_nv_seed_read mbedtls_platform_std_nv_seed_read
316#define mbedtls_nv_seed_write mbedtls_platform_std_nv_seed_write
317#endif
318#endif /* MBEDTLS_PLATFORM_NV_SEED_ALT */
319#endif /* MBEDTLS_ENTROPY_NV_SEED */
320
Andres Amaya Garciad91f99f2017-07-18 10:23:04 +0100321#if !defined(MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT)
Andres Amaya Garcia3c8a39d2017-07-12 11:25:17 +0100322
Andres Amaya Garcia64b02cd2017-07-12 11:32:40 +0100323/**
Rose Zadik332658d2018-01-25 22:02:53 +0000324 * \brief The platform context structure.
Andres Amaya Garcia64b02cd2017-07-12 11:32:40 +0100325 *
326 * \note This structure may be used to assist platform-specific
Rose Zadik332658d2018-01-25 22:02:53 +0000327 * setup or teardown operations.
Andres Amaya Garcia64b02cd2017-07-12 11:32:40 +0100328 */
329typedef struct {
Rose Zadik332658d2018-01-25 22:02:53 +0000330 char dummy; /**< Placeholder member, as empty structs are not portable. */
Andres Amaya Garcia64b02cd2017-07-12 11:32:40 +0100331}
332mbedtls_platform_context;
333
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100334#else
335#include "platform_alt.h"
Andres Amaya Garciad91f99f2017-07-18 10:23:04 +0100336#endif /* !MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT */
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100337
338/**
Rose Zadik332658d2018-01-25 22:02:53 +0000339 * \brief This function performs any platform initialization operations.
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100340 *
Rose Zadik332658d2018-01-25 22:02:53 +0000341 * \param ctx The Mbed TLS 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 *
Rose Zadik332658d2018-01-25 22:02:53 +0000345 * \note This function is intended to allow platform-specific initialization,
Simon Butcherd3be27a2017-07-21 02:08:00 +0200346 * and should be called before any other library functions. Its
Rose Zadik332658d2018-01-25 22:02:53 +0000347 * implementation is platform-specific, and unless
348 * platform-specific code is provided, it does nothing.
Simon Butcherd3be27a2017-07-21 02:08:00 +0200349 *
Rose Zadik332658d2018-01-25 22:02:53 +0000350 * Its use and whether it is necessary to call it is dependent on the
Simon Butcherd3be27a2017-07-21 02:08:00 +0200351 * platform.
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100352 */
353int mbedtls_platform_setup( mbedtls_platform_context *ctx );
354/**
Rose Zadik332658d2018-01-25 22:02:53 +0000355 * \brief This function performs any platform teardown operations.
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100356 *
Rose Zadik332658d2018-01-25 22:02:53 +0000357 * \param ctx The Mbed TLS context.
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100358 *
Rose Zadik332658d2018-01-25 22:02:53 +0000359 * \note This function should be called after every other Mbed TLS module
360 * has been correctly freed using the appropriate free function.
361 * Its implementation is platform-specific, and unless
362 * platform-specific code is provided, it does nothing.
Simon Butcherd3be27a2017-07-21 02:08:00 +0200363 *
Rose Zadik332658d2018-01-25 22:02:53 +0000364 * Its use and whether it is necessary to call it is dependent on the
Simon Butcherd3be27a2017-07-21 02:08:00 +0200365 * platform.
Andres Amaya Garcia2a6f39c2017-07-07 13:03:23 +0100366 */
367void mbedtls_platform_teardown( mbedtls_platform_context *ctx );
368
Paul Bakker747a83a2014-02-01 22:50:07 +0100369#ifdef __cplusplus
370}
371#endif
372
373#endif /* platform.h */