2021-06-24 19:31:26 +00:00
|
|
|
#ifndef COSMOPOLITAN_THIRD_PARTY_MBEDTLS_PLATFORM_H_
|
|
|
|
#define COSMOPOLITAN_THIRD_PARTY_MBEDTLS_PLATFORM_H_
|
|
|
|
#include "libc/assert.h"
|
2021-06-16 02:52:02 +00:00
|
|
|
#include "libc/fmt/fmt.h"
|
2022-08-14 00:20:50 +00:00
|
|
|
#include "libc/intrin/likely.h"
|
2021-06-24 19:31:26 +00:00
|
|
|
#include "libc/mem/mem.h"
|
|
|
|
#include "libc/runtime/runtime.h"
|
2021-06-16 02:52:02 +00:00
|
|
|
#include "libc/stdio/stdio.h"
|
2021-06-16 03:18:59 +00:00
|
|
|
#include "third_party/mbedtls/config.h"
|
2021-06-24 19:31:26 +00:00
|
|
|
COSMOPOLITAN_C_START_
|
2021-06-15 18:39:36 +00:00
|
|
|
|
|
|
|
#define MBEDTLS_EXIT_SUCCESS 0
|
|
|
|
#define MBEDTLS_EXIT_FAILURE 1
|
|
|
|
|
2021-06-24 19:31:26 +00:00
|
|
|
#define mbedtls_free free
|
|
|
|
#define mbedtls_calloc calloc
|
|
|
|
#define mbedtls_snprintf snprintf
|
|
|
|
#define mbedtls_vsnprintf vsnprintf
|
|
|
|
#define mbedtls_exit exit
|
2022-08-14 00:20:50 +00:00
|
|
|
#define mbedtls_time_t int64_t
|
2021-06-24 19:31:26 +00:00
|
|
|
#define mbedtls_time time
|
|
|
|
#define mbedtls_platform_gmtime_r gmtime_r
|
|
|
|
|
|
|
|
#define mbedtls_fprintf(...) ((void)0)
|
|
|
|
#define mbedtls_printf(...) ((void)0)
|
|
|
|
|
|
|
|
#ifdef MBEDTLS_CHECK_PARAMS
|
|
|
|
#define MBEDTLS_PARAM_FAILED(cond) \
|
|
|
|
mbedtls_param_failed(#cond, __FILE__, __LINE__)
|
|
|
|
#else
|
|
|
|
#define MBEDTLS_PARAM_FAILED(cond) unreachable
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define MBEDTLS_INTERNAL_VALIDATE_RET(cond, ret) \
|
|
|
|
do { \
|
2021-07-06 14:07:18 +00:00
|
|
|
if (UNLIKELY(!(cond))) { \
|
2021-06-24 19:31:26 +00:00
|
|
|
MBEDTLS_PARAM_FAILED(cond); \
|
|
|
|
return ret; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define MBEDTLS_INTERNAL_VALIDATE(cond) \
|
|
|
|
do { \
|
2021-07-06 14:07:18 +00:00
|
|
|
if (UNLIKELY(!(cond))) { \
|
2021-06-24 19:31:26 +00:00
|
|
|
MBEDTLS_PARAM_FAILED(cond); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2021-07-19 21:55:20 +00:00
|
|
|
#if IsModeDbg()
|
|
|
|
#define MBEDTLS_ASSERT(EXPR) \
|
|
|
|
((void)((EXPR) || (__assert_fail(#EXPR, __FILE__, __LINE__), 0)))
|
|
|
|
#else
|
2022-10-10 05:38:28 +00:00
|
|
|
#define MBEDTLS_ASSERT(EXPR) _unassert(EXPR)
|
2021-07-19 21:55:20 +00:00
|
|
|
#endif
|
|
|
|
|
2021-06-24 19:31:26 +00:00
|
|
|
typedef struct mbedtls_platform_context {
|
|
|
|
char dummy;
|
|
|
|
} mbedtls_platform_context;
|
|
|
|
|
|
|
|
void mbedtls_platform_zeroize(void *, size_t);
|
|
|
|
int mbedtls_platform_setup(mbedtls_platform_context *);
|
|
|
|
void mbedtls_platform_teardown(mbedtls_platform_context *);
|
|
|
|
void mbedtls_param_failed(const char *, const char *, int) relegated;
|
|
|
|
|
|
|
|
COSMOPOLITAN_C_END_
|
|
|
|
#endif /* COSMOPOLITAN_THIRD_PARTY_MBEDTLS_PLATFORM_H_ */
|