31#ifndef MBEDTLS_PLATFORM_H
32#define MBEDTLS_PLATFORM_H
34#if !defined(MBEDTLS_CONFIG_FILE)
37#include MBEDTLS_CONFIG_FILE
40#if defined(MBEDTLS_HAVE_TIME)
51#define MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED -0x0070
52#define MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED -0x0072
70#if defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER <= 1900)
71#define MBEDTLS_PLATFORM_HAS_NON_CONFORMING_SNPRINTF
72#define MBEDTLS_PLATFORM_HAS_NON_CONFORMING_VSNPRINTF
75#if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS)
79#if !defined(MBEDTLS_PLATFORM_STD_SNPRINTF)
80#if defined(MBEDTLS_PLATFORM_HAS_NON_CONFORMING_SNPRINTF)
81#define MBEDTLS_PLATFORM_STD_SNPRINTF mbedtls_platform_win32_snprintf
83#define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf
86#if !defined(MBEDTLS_PLATFORM_STD_VSNPRINTF)
87#if defined(MBEDTLS_PLATFORM_HAS_NON_CONFORMING_VSNPRINTF)
88#define MBEDTLS_PLATFORM_STD_VSNPRINTF mbedtls_platform_win32_vsnprintf
90#define MBEDTLS_PLATFORM_STD_VSNPRINTF vsnprintf
93#if !defined(MBEDTLS_PLATFORM_STD_PRINTF)
94#define MBEDTLS_PLATFORM_STD_PRINTF printf
96#if !defined(MBEDTLS_PLATFORM_STD_FPRINTF)
97#define MBEDTLS_PLATFORM_STD_FPRINTF fprintf
99#if !defined(MBEDTLS_PLATFORM_STD_CALLOC)
100#define MBEDTLS_PLATFORM_STD_CALLOC calloc
102#if !defined(MBEDTLS_PLATFORM_STD_FREE)
103#define MBEDTLS_PLATFORM_STD_FREE free
105#if !defined(MBEDTLS_PLATFORM_STD_EXIT)
106#define MBEDTLS_PLATFORM_STD_EXIT exit
108#if !defined(MBEDTLS_PLATFORM_STD_TIME)
109#define MBEDTLS_PLATFORM_STD_TIME time
111#if !defined(MBEDTLS_PLATFORM_STD_EXIT_SUCCESS)
112#define MBEDTLS_PLATFORM_STD_EXIT_SUCCESS EXIT_SUCCESS
114#if !defined(MBEDTLS_PLATFORM_STD_EXIT_FAILURE)
115#define MBEDTLS_PLATFORM_STD_EXIT_FAILURE EXIT_FAILURE
117#if defined(MBEDTLS_FS_IO)
118#if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_READ)
119#define MBEDTLS_PLATFORM_STD_NV_SEED_READ mbedtls_platform_std_nv_seed_read
121#if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_WRITE)
122#define MBEDTLS_PLATFORM_STD_NV_SEED_WRITE mbedtls_platform_std_nv_seed_write
124#if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_FILE)
125#define MBEDTLS_PLATFORM_STD_NV_SEED_FILE "seedfile"
129#if defined(MBEDTLS_PLATFORM_STD_MEM_HDR)
130#include MBEDTLS_PLATFORM_STD_MEM_HDR
140#if defined(MBEDTLS_PLATFORM_MEMORY)
141#if defined(MBEDTLS_PLATFORM_FREE_MACRO) && \
142 defined(MBEDTLS_PLATFORM_CALLOC_MACRO)
143#define mbedtls_free MBEDTLS_PLATFORM_FREE_MACRO
144#define mbedtls_calloc MBEDTLS_PLATFORM_CALLOC_MACRO
148extern void *mbedtls_calloc(
size_t n,
size_t size );
149extern void mbedtls_free(
void *ptr );
160int mbedtls_platform_set_calloc_free(
void * (*calloc_func)(
size_t,
size_t ),
161 void (*free_func)(
void * ) );
164#define mbedtls_free free
165#define mbedtls_calloc calloc
171#if defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
174extern int (*mbedtls_fprintf)( FILE *stream,
const char *format, ... );
185int mbedtls_platform_set_fprintf(
int (*fprintf_func)( FILE *stream,
const char *,
188#if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO)
189#define mbedtls_fprintf MBEDTLS_PLATFORM_FPRINTF_MACRO
191#define mbedtls_fprintf fprintf
198#if defined(MBEDTLS_PLATFORM_PRINTF_ALT)
199extern int (*mbedtls_printf)(
const char *format, ... );
210int mbedtls_platform_set_printf(
int (*printf_func)(
const char *, ... ) );
212#if defined(MBEDTLS_PLATFORM_PRINTF_MACRO)
213#define mbedtls_printf MBEDTLS_PLATFORM_PRINTF_MACRO
215#define mbedtls_printf printf
228#if defined(MBEDTLS_PLATFORM_HAS_NON_CONFORMING_SNPRINTF)
230int mbedtls_platform_win32_snprintf(
char *s,
size_t n,
const char *fmt, ... );
233#if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
234extern int (*mbedtls_snprintf)(
char * s,
size_t n,
const char * format, ... );
244int mbedtls_platform_set_snprintf(
int (*snprintf_func)(
char * s,
size_t n,
245 const char * format, ... ) );
247#if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO)
248#define mbedtls_snprintf MBEDTLS_PLATFORM_SNPRINTF_MACRO
250#define mbedtls_snprintf MBEDTLS_PLATFORM_STD_SNPRINTF
263#if defined(MBEDTLS_PLATFORM_HAS_NON_CONFORMING_VSNPRINTF)
266int mbedtls_platform_win32_vsnprintf(
char *s,
size_t n,
const char *fmt, va_list arg );
269#if defined(MBEDTLS_PLATFORM_VSNPRINTF_ALT)
271extern int (*mbedtls_vsnprintf)(
char * s,
size_t n,
const char * format, va_list arg );
280int mbedtls_platform_set_vsnprintf(
int (*vsnprintf_func)(
char * s,
size_t n,
281 const char * format, va_list arg ) );
283#if defined(MBEDTLS_PLATFORM_VSNPRINTF_MACRO)
284#define mbedtls_vsnprintf MBEDTLS_PLATFORM_VSNPRINTF_MACRO
286#define mbedtls_vsnprintf vsnprintf
293#if defined(MBEDTLS_PLATFORM_EXIT_ALT)
294extern void (*mbedtls_exit)(
int status );
305int mbedtls_platform_set_exit(
void (*exit_func)(
int status ) );
307#if defined(MBEDTLS_PLATFORM_EXIT_MACRO)
308#define mbedtls_exit MBEDTLS_PLATFORM_EXIT_MACRO
310#define mbedtls_exit exit
317#if defined(MBEDTLS_PLATFORM_STD_EXIT_SUCCESS)
318#define MBEDTLS_EXIT_SUCCESS MBEDTLS_PLATFORM_STD_EXIT_SUCCESS
320#define MBEDTLS_EXIT_SUCCESS 0
322#if defined(MBEDTLS_PLATFORM_STD_EXIT_FAILURE)
323#define MBEDTLS_EXIT_FAILURE MBEDTLS_PLATFORM_STD_EXIT_FAILURE
325#define MBEDTLS_EXIT_FAILURE 1
334#if defined(MBEDTLS_ENTROPY_NV_SEED)
335#if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS) && defined(MBEDTLS_FS_IO)
337int mbedtls_platform_std_nv_seed_read(
unsigned char *buf,
size_t buf_len );
338int mbedtls_platform_std_nv_seed_write(
unsigned char *buf,
size_t buf_len );
341#if defined(MBEDTLS_PLATFORM_NV_SEED_ALT)
342extern int (*mbedtls_nv_seed_read)(
unsigned char *buf,
size_t buf_len );
343extern int (*mbedtls_nv_seed_write)(
unsigned char *buf,
size_t buf_len );
354int mbedtls_platform_set_nv_seed(
355 int (*nv_seed_read_func)(
unsigned char *buf,
size_t buf_len ),
356 int (*nv_seed_write_func)(
unsigned char *buf,
size_t buf_len )
359#if defined(MBEDTLS_PLATFORM_NV_SEED_READ_MACRO) && \
360 defined(MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO)
361#define mbedtls_nv_seed_read MBEDTLS_PLATFORM_NV_SEED_READ_MACRO
362#define mbedtls_nv_seed_write MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO
364#define mbedtls_nv_seed_read mbedtls_platform_std_nv_seed_read
365#define mbedtls_nv_seed_write mbedtls_platform_std_nv_seed_write
370#if !defined(MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT)
385#include "platform_alt.h"
Configuration options (set of defines)
The platform context structure.
char dummy
A placeholder member, as empty structs are not portable.