Platform config + memory wrapper
This commit is contained in:
parent
821d862159
commit
992c1612af
3808
include/mbedtls/config.h.reference
Normal file
3808
include/mbedtls/config.h.reference
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -11,13 +11,6 @@
|
||||
* implementations of these functions, or implementations specific to
|
||||
* their platform, which can be statically linked to the library or
|
||||
* dynamically configured at runtime.
|
||||
*
|
||||
* When all compilation options related to platform abstraction are
|
||||
* disabled, this header just defines `mbedtls_xxx` function names
|
||||
* as aliases to the standard `xxx` function.
|
||||
*
|
||||
* Most modules in the library and example programs are expected to
|
||||
* include this header.
|
||||
*/
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
@ -37,14 +30,20 @@
|
||||
*/
|
||||
#ifndef MBEDTLS_PLATFORM_H
|
||||
#define MBEDTLS_PLATFORM_H
|
||||
#include "mbedtls/private_access.h"
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_HAVE_TIME)
|
||||
#include "mbedtls/platform_time.h"
|
||||
#endif
|
||||
|
||||
#define MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED -0x0070 /**< Hardware accelerator failed */
|
||||
#define MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED -0x0072 /**< The requested feature is not supported by the platform */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -53,7 +52,7 @@ extern "C" {
|
||||
* \name SECTION: Module settings
|
||||
*
|
||||
* The configuration options you can set for this module are in this section.
|
||||
* Either change them in mbedtls_config.h or define them on the compiler command line.
|
||||
* Either change them in config.h or define them on the compiler command line.
|
||||
* \{
|
||||
*/
|
||||
|
||||
@ -69,9 +68,7 @@ extern "C" {
|
||||
#if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS)
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#if defined(MBEDTLS_HAVE_TIME)
|
||||
#include <time.h>
|
||||
#endif
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_SNPRINTF)
|
||||
#if defined(MBEDTLS_PLATFORM_HAS_NON_CONFORMING_SNPRINTF)
|
||||
#define MBEDTLS_PLATFORM_STD_SNPRINTF mbedtls_platform_win32_snprintf /**< The default \c snprintf function to use. */
|
||||
@ -92,18 +89,15 @@ extern "C" {
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_FPRINTF)
|
||||
#define MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< The default \c fprintf function to use. */
|
||||
#endif
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_CALLOC)
|
||||
#define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< The default \c calloc function to use. */
|
||||
#endif
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_FREE)
|
||||
#define MBEDTLS_PLATFORM_STD_FREE free /**< The default \c free function to use. */
|
||||
#endif
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_SETBUF)
|
||||
#define MBEDTLS_PLATFORM_STD_SETBUF setbuf /**< The default \c setbuf function to use. */
|
||||
#endif
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_EXIT)
|
||||
#define MBEDTLS_PLATFORM_STD_EXIT exit /**< The default \c exit function to use. */
|
||||
#endif
|
||||
//#if !defined(MBEDTLS_PLATFORM_STD_CALLOC)
|
||||
//#define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< The default \c calloc function to use. */
|
||||
//#endif
|
||||
//#if !defined(MBEDTLS_PLATFORM_STD_FREE)
|
||||
//#define MBEDTLS_PLATFORM_STD_FREE free /**< The default \c free function to use. */
|
||||
//#endif
|
||||
//#if !defined(MBEDTLS_PLATFORM_STD_EXIT)
|
||||
//#define MBEDTLS_PLATFORM_STD_EXIT exit /**< The default \c exit function to use. */
|
||||
//#endif
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_TIME)
|
||||
#define MBEDTLS_PLATFORM_STD_TIME time /**< The default \c time function to use. */
|
||||
#endif
|
||||
@ -131,7 +125,7 @@ extern "C" {
|
||||
#endif /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
|
||||
|
||||
|
||||
/** \} name SECTION: Module settings */
|
||||
/* \} name SECTION: Module settings */
|
||||
|
||||
/*
|
||||
* The function pointers for calloc and free.
|
||||
@ -286,56 +280,6 @@ int mbedtls_platform_set_vsnprintf( int (*vsnprintf_func)( char * s, size_t n,
|
||||
#endif /* MBEDTLS_PLATFORM_VSNPRINTF_MACRO */
|
||||
#endif /* MBEDTLS_PLATFORM_VSNPRINTF_ALT */
|
||||
|
||||
/*
|
||||
* The function pointers for setbuf
|
||||
*/
|
||||
#if defined(MBEDTLS_PLATFORM_SETBUF_ALT)
|
||||
#include <stdio.h>
|
||||
/**
|
||||
* \brief Function pointer to call for `setbuf()` functionality
|
||||
* (changing the internal buffering on stdio calls).
|
||||
*
|
||||
* \note The library calls this function to disable
|
||||
* buffering when reading or writing sensitive data,
|
||||
* to avoid having extra copies of sensitive data
|
||||
* remaining in stdio buffers after the file is
|
||||
* closed. If this is not a concern, for example if
|
||||
* your platform's stdio doesn't have any buffering,
|
||||
* you can set mbedtls_setbuf to a function that
|
||||
* does nothing.
|
||||
*
|
||||
* The library always calls this function with
|
||||
* `buf` equal to `NULL`.
|
||||
*/
|
||||
extern void (*mbedtls_setbuf)( FILE *stream, char *buf );
|
||||
|
||||
/**
|
||||
* \brief Dynamically configure the function that is called
|
||||
* when the mbedtls_setbuf() function is called by the
|
||||
* library.
|
||||
*
|
||||
* \param setbuf_func The \c setbuf function implementation
|
||||
*
|
||||
* \return \c 0
|
||||
*/
|
||||
int mbedtls_platform_set_setbuf( void (*setbuf_func)(
|
||||
FILE *stream, char *buf ) );
|
||||
#elif defined(MBEDTLS_PLATFORM_SETBUF_MACRO)
|
||||
/**
|
||||
* \brief Macro defining the function for the library to
|
||||
* call for `setbuf` functionality (changing the
|
||||
* internal buffering on stdio calls).
|
||||
*
|
||||
* \note See extra comments on the mbedtls_setbuf() function
|
||||
* pointer above.
|
||||
*
|
||||
* \return \c 0 on success, negative on error.
|
||||
*/
|
||||
#define mbedtls_setbuf MBEDTLS_PLATFORM_SETBUF_MACRO
|
||||
#else
|
||||
#define mbedtls_setbuf setbuf
|
||||
#endif /* MBEDTLS_PLATFORM_SETBUF_ALT / MBEDTLS_PLATFORM_SETBUF_MACRO */
|
||||
|
||||
/*
|
||||
* The function pointers for exit
|
||||
*/
|
||||
@ -426,7 +370,7 @@ int mbedtls_platform_set_nv_seed(
|
||||
*/
|
||||
typedef struct mbedtls_platform_context
|
||||
{
|
||||
char MBEDTLS_PRIVATE(dummy); /**< A placeholder member, as empty structs are not portable. */
|
||||
char dummy; /**< A placeholder member, as empty structs are not portable. */
|
||||
}
|
||||
mbedtls_platform_context;
|
||||
|
||||
|
@ -159,7 +159,7 @@ static inline uint32_t aria_p3( uint32_t x )
|
||||
* = 3210 + 4567 + 6745 + 89ab + 98ba + dcfe + efcd
|
||||
* b = 0101 + 2323 + 5476 + 8998 + baab + eecc + ffdd
|
||||
* = 0123 + 2301 + 5476 + 89ab + ba98 + efcd + fedc
|
||||
* c = 0022 + 1133 + 4554 + 7667 + ab89 + dcdc + fefe
|
||||
* c = 0022 + 1133 + 4554 + 7667 + abz89 + dcdc + fefe
|
||||
* = 0123 + 1032 + 4567 + 7654 + ab89 + dcfe + fedc
|
||||
* d = 1001 + 2332 + 6644 + 7755 + 9898 + baba + cdef
|
||||
* = 1032 + 2301 + 6745 + 7654 + 98ba + ba98 + cdef
|
||||
|
@ -16,66 +16,40 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "KInternal.hpp"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
|
||||
#include "mbedtls/platform.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
#include "mbedtls/error.h"
|
||||
|
||||
|
||||
|
||||
/* The compile time configuration of memory allocation via the macros
|
||||
* MBEDTLS_PLATFORM_{FREE/CALLOC}_MACRO takes precedence over the runtime
|
||||
* configuration via mbedtls_platform_set_calloc_free(). So, omit everything
|
||||
* related to the latter if MBEDTLS_PLATFORM_{FREE/CALLOC}_MACRO are defined. */
|
||||
#if defined(MBEDTLS_PLATFORM_MEMORY) && \
|
||||
!( defined(MBEDTLS_PLATFORM_CALLOC_MACRO) && \
|
||||
defined(MBEDTLS_PLATFORM_FREE_MACRO) )
|
||||
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_CALLOC)
|
||||
static void *platform_calloc_uninit( size_t n, size_t size )
|
||||
{
|
||||
((void) n);
|
||||
((void) size);
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
#define MBEDTLS_PLATFORM_STD_CALLOC platform_calloc_uninit
|
||||
#endif /* !MBEDTLS_PLATFORM_STD_CALLOC */
|
||||
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_FREE)
|
||||
static void platform_free_uninit( void *ptr )
|
||||
{
|
||||
((void) ptr);
|
||||
}
|
||||
|
||||
#define MBEDTLS_PLATFORM_STD_FREE platform_free_uninit
|
||||
#endif /* !MBEDTLS_PLATFORM_STD_FREE */
|
||||
|
||||
static void * (*mbedtls_calloc_func)( size_t, size_t ) = MBEDTLS_PLATFORM_STD_CALLOC;
|
||||
static void (*mbedtls_free_func)( void * ) = MBEDTLS_PLATFORM_STD_FREE;
|
||||
|
||||
void * mbedtls_calloc( size_t nmemb, size_t size )
|
||||
{
|
||||
return (*mbedtls_calloc_func)( nmemb, size );
|
||||
return Aurora::Memory::_ZAlloc(nmemb * size);
|
||||
}
|
||||
|
||||
void mbedtls_free( void * ptr )
|
||||
{
|
||||
(*mbedtls_free_func)( ptr );
|
||||
Aurora::Memory::Free(ptr);
|
||||
}
|
||||
|
||||
int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ),
|
||||
void (*free_func)( void * ) )
|
||||
{
|
||||
mbedtls_calloc_func = calloc_func;
|
||||
mbedtls_free_func = free_func;
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_PLATFORM_MEMORY &&
|
||||
!( defined(MBEDTLS_PLATFORM_CALLOC_MACRO) &&
|
||||
defined(MBEDTLS_PLATFORM_FREE_MACRO) ) */
|
||||
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_HAS_NON_CONFORMING_SNPRINTF)
|
||||
#include <stdarg.h>
|
||||
@ -249,19 +223,12 @@ int mbedtls_platform_set_setbuf( void (*setbuf_func)( FILE *stream, char *buf )
|
||||
#endif /* MBEDTLS_PLATFORM_SETBUF_ALT */
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_EXIT_ALT)
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_EXIT)
|
||||
/*
|
||||
* Make dummy function to prevent NULL pointer dereferences
|
||||
*/
|
||||
static void platform_exit_uninit( int status )
|
||||
{
|
||||
((void) status);
|
||||
Aurora::Debug::Panic();
|
||||
}
|
||||
|
||||
#define MBEDTLS_PLATFORM_STD_EXIT platform_exit_uninit
|
||||
#endif /* !MBEDTLS_PLATFORM_STD_EXIT */
|
||||
|
||||
void (*mbedtls_exit)( int status ) = MBEDTLS_PLATFORM_STD_EXIT;
|
||||
void (*mbedtls_exit)( int status ) = platform_exit_uninit;
|
||||
|
||||
int mbedtls_platform_set_exit( void (*exit_func)( int status ) )
|
||||
{
|
||||
@ -410,5 +377,6 @@ void mbedtls_platform_teardown( mbedtls_platform_context *ctx )
|
||||
(void)ctx;
|
||||
}
|
||||
#endif /* MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT */
|
||||
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
|
||||
}
|
@ -26,6 +26,8 @@
|
||||
#define _POSIX_C_SOURCE 200112L
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include "mbedtls/platform_util.h"
|
||||
|
15
mbedtls.vcxproj.user
Normal file
15
mbedtls.vcxproj.user
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug win32|x64'">
|
||||
<LocalDebuggerWorkingDirectory>..\..\Build\CWD</LocalDebuggerWorkingDirectory>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Stage win32|x64'">
|
||||
<LocalDebuggerWorkingDirectory>..\..\Build\CWD</LocalDebuggerWorkingDirectory>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Ship win32|x64'">
|
||||
<LocalDebuggerWorkingDirectory>..\..\Build\CWD</LocalDebuggerWorkingDirectory>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user