mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-13 21:36:00 +03:00
Adds base64 support via mbedtls
This is inspered in the work done at: #1123
This commit is contained in:
parent
4b9cff3ec7
commit
a3ae686f25
@ -3,9 +3,21 @@ BUILT_SOURCES= \
|
|||||||
parser/seclang-parser.cc
|
parser/seclang-parser.cc
|
||||||
|
|
||||||
lib_LTLIBRARIES = libmodsecurity.la
|
lib_LTLIBRARIES = libmodsecurity.la
|
||||||
|
noinst_LTLIBRARIES = libmbedtls.la
|
||||||
libmodsecurity_ladir = $(prefix)/include
|
libmodsecurity_ladir = $(prefix)/include
|
||||||
libmodsecurity_includesubdir = $(pkgincludedir)/collection/
|
libmodsecurity_includesubdir = $(pkgincludedir)/collection/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
libmbedtls_la_SOURCES = \
|
||||||
|
utils/mbedtls/base64.c
|
||||||
|
|
||||||
|
|
||||||
|
libmbedtls_la_CFLAGS = -D MBEDTLS_CONFIG_FILE=\"mbed-tls-config.h\" -Iutils
|
||||||
|
libmbedtls_la_CPPFLAGS =
|
||||||
|
libmbedtls_la_LIBADD =
|
||||||
|
|
||||||
|
|
||||||
CLEANFILES = \
|
CLEANFILES = \
|
||||||
location.hh \
|
location.hh \
|
||||||
position.hh \
|
position.hh \
|
||||||
@ -170,6 +182,7 @@ OPERATORS = \
|
|||||||
|
|
||||||
UTILS = \
|
UTILS = \
|
||||||
utils/acmp.cc \
|
utils/acmp.cc \
|
||||||
|
utils/base64.cc \
|
||||||
utils/geo_lookup.cc \
|
utils/geo_lookup.cc \
|
||||||
utils/https_client.cc \
|
utils/https_client.cc \
|
||||||
utils/ip_tree.cc \
|
utils/ip_tree.cc \
|
||||||
@ -241,7 +254,8 @@ libmodsecurity_la_LIBADD = \
|
|||||||
$(PCRE_LDADD) \
|
$(PCRE_LDADD) \
|
||||||
$(YAJL_LDADD) \
|
$(YAJL_LDADD) \
|
||||||
$(LIBXML2_LDADD) \
|
$(LIBXML2_LDADD) \
|
||||||
../others/libinjection.la
|
../others/libinjection.la \
|
||||||
|
libmbedtls.la
|
||||||
|
|
||||||
|
|
||||||
libmodsecurity_la_LDFLAGS = \
|
libmodsecurity_la_LDFLAGS = \
|
||||||
|
80
src/utils/base64.cc
Normal file
80
src/utils/base64.cc
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* ModSecurity, http://www.modsecurity.org/
|
||||||
|
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
|
||||||
|
*
|
||||||
|
* You may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* If any of the files related to licensing are missing or if you have any
|
||||||
|
* other questions related to licensing please contact Trustwave Holdings, Inc.
|
||||||
|
* directly using the email address security@modsecurity.org.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "utils/base64.h"
|
||||||
|
#include "mbedtls/base64.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
namespace modsecurity {
|
||||||
|
namespace Utils {
|
||||||
|
|
||||||
|
|
||||||
|
std::string Base64::encode(std::string& data) {
|
||||||
|
size_t encoded_len = 0;
|
||||||
|
unsigned char *d = NULL;
|
||||||
|
std::string ret;
|
||||||
|
|
||||||
|
mbedtls_base64_encode(NULL, 0, &encoded_len,
|
||||||
|
reinterpret_cast<const unsigned char*>(data.c_str()), data.size());
|
||||||
|
|
||||||
|
d = reinterpret_cast<unsigned char*>(malloc(sizeof(char) * encoded_len));
|
||||||
|
if (d == NULL) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(d, '\0', encoded_len);
|
||||||
|
|
||||||
|
mbedtls_base64_encode(d, encoded_len, &encoded_len,
|
||||||
|
(unsigned char*) data.c_str(), data.size());
|
||||||
|
|
||||||
|
ret.assign(reinterpret_cast<const char*>(d));
|
||||||
|
free(d);
|
||||||
|
|
||||||
|
|
||||||
|
return std::string(reinterpret_cast<const char*>(d));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string Base64::decode(std::string& data) {
|
||||||
|
size_t decoded_len = 0;
|
||||||
|
unsigned char *d = NULL;
|
||||||
|
std::string ret;
|
||||||
|
|
||||||
|
mbedtls_base64_decode(NULL, 0, &decoded_len,
|
||||||
|
reinterpret_cast<const unsigned char*>(data.c_str()), data.length());
|
||||||
|
|
||||||
|
d = reinterpret_cast<unsigned char*>(malloc(sizeof(char) * decoded_len));
|
||||||
|
if (d == NULL) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(d, '\0', decoded_len);
|
||||||
|
|
||||||
|
mbedtls_base64_decode(d, decoded_len, &decoded_len,
|
||||||
|
reinterpret_cast<const unsigned char*>(data.c_str()), data.length());
|
||||||
|
|
||||||
|
ret.assign(reinterpret_cast<const char*>(d));
|
||||||
|
free(d);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Utils
|
||||||
|
} // namespace modsecurity
|
16
src/utils/base64.h
Normal file
16
src/utils/base64.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
|
||||||
|
namespace modsecurity {
|
||||||
|
namespace Utils {
|
||||||
|
|
||||||
|
class Base64 {
|
||||||
|
public:
|
||||||
|
Base64() { }
|
||||||
|
|
||||||
|
static std::string encode(std::string& data);
|
||||||
|
static std::string decode(std::string& data);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Utils
|
||||||
|
} // namespace modsecurity
|
289
src/utils/mbedtls/base64.c
Normal file
289
src/utils/mbedtls/base64.c
Normal file
@ -0,0 +1,289 @@
|
|||||||
|
/*
|
||||||
|
* RFC 1521 base64 encoding/decoding
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* This file is part of mbed TLS (https://tls.mbed.org)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||||
|
#include "mbedtls/config.h"
|
||||||
|
#else
|
||||||
|
#include MBEDTLS_CONFIG_FILE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_BASE64_C)
|
||||||
|
|
||||||
|
#include "mbedtls/base64.h"
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SELF_TEST)
|
||||||
|
#include <string.h>
|
||||||
|
#if defined(MBEDTLS_PLATFORM_C)
|
||||||
|
#include "mbedtls/platform.h"
|
||||||
|
#else
|
||||||
|
#include <stdio.h>
|
||||||
|
#define mbedtls_printf printf
|
||||||
|
#endif /* MBEDTLS_PLATFORM_C */
|
||||||
|
#endif /* MBEDTLS_SELF_TEST */
|
||||||
|
|
||||||
|
static const unsigned char base64_enc_map[64] =
|
||||||
|
{
|
||||||
|
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
|
||||||
|
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
|
||||||
|
'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
|
||||||
|
'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
|
||||||
|
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
|
||||||
|
'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',
|
||||||
|
'8', '9', '+', '/'
|
||||||
|
};
|
||||||
|
|
||||||
|
static const unsigned char base64_dec_map[128] =
|
||||||
|
{
|
||||||
|
127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
|
||||||
|
127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
|
||||||
|
127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
|
||||||
|
127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
|
||||||
|
127, 127, 127, 62, 127, 127, 127, 63, 52, 53,
|
||||||
|
54, 55, 56, 57, 58, 59, 60, 61, 127, 127,
|
||||||
|
127, 64, 127, 127, 127, 0, 1, 2, 3, 4,
|
||||||
|
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
||||||
|
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
|
||||||
|
25, 127, 127, 127, 127, 127, 127, 26, 27, 28,
|
||||||
|
29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
|
||||||
|
39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
|
||||||
|
49, 50, 51, 127, 127, 127, 127, 127
|
||||||
|
};
|
||||||
|
|
||||||
|
#define BASE64_SIZE_T_MAX ( (size_t) -1 ) /* SIZE_T_MAX is not standard */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Encode a buffer into base64 format
|
||||||
|
*/
|
||||||
|
int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen,
|
||||||
|
const unsigned char *src, size_t slen )
|
||||||
|
{
|
||||||
|
size_t i, n;
|
||||||
|
int C1, C2, C3;
|
||||||
|
unsigned char *p;
|
||||||
|
|
||||||
|
if( slen == 0 )
|
||||||
|
{
|
||||||
|
*olen = 0;
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
n = slen / 3 + ( slen % 3 != 0 );
|
||||||
|
|
||||||
|
if( n > ( BASE64_SIZE_T_MAX - 1 ) / 4 )
|
||||||
|
{
|
||||||
|
*olen = BASE64_SIZE_T_MAX;
|
||||||
|
return( MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL );
|
||||||
|
}
|
||||||
|
|
||||||
|
n *= 4;
|
||||||
|
|
||||||
|
if( dlen < n + 1 )
|
||||||
|
{
|
||||||
|
*olen = n + 1;
|
||||||
|
return( MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL );
|
||||||
|
}
|
||||||
|
|
||||||
|
n = ( slen / 3 ) * 3;
|
||||||
|
|
||||||
|
for( i = 0, p = dst; i < n; i += 3 )
|
||||||
|
{
|
||||||
|
C1 = *src++;
|
||||||
|
C2 = *src++;
|
||||||
|
C3 = *src++;
|
||||||
|
|
||||||
|
*p++ = base64_enc_map[(C1 >> 2) & 0x3F];
|
||||||
|
*p++ = base64_enc_map[(((C1 & 3) << 4) + (C2 >> 4)) & 0x3F];
|
||||||
|
*p++ = base64_enc_map[(((C2 & 15) << 2) + (C3 >> 6)) & 0x3F];
|
||||||
|
*p++ = base64_enc_map[C3 & 0x3F];
|
||||||
|
}
|
||||||
|
|
||||||
|
if( i < slen )
|
||||||
|
{
|
||||||
|
C1 = *src++;
|
||||||
|
C2 = ( ( i + 1 ) < slen ) ? *src++ : 0;
|
||||||
|
|
||||||
|
*p++ = base64_enc_map[(C1 >> 2) & 0x3F];
|
||||||
|
*p++ = base64_enc_map[(((C1 & 3) << 4) + (C2 >> 4)) & 0x3F];
|
||||||
|
|
||||||
|
if( ( i + 1 ) < slen )
|
||||||
|
*p++ = base64_enc_map[((C2 & 15) << 2) & 0x3F];
|
||||||
|
else *p++ = '=';
|
||||||
|
|
||||||
|
*p++ = '=';
|
||||||
|
}
|
||||||
|
|
||||||
|
*olen = p - dst;
|
||||||
|
*p = 0;
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Decode a base64-formatted buffer
|
||||||
|
*/
|
||||||
|
int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
|
||||||
|
const unsigned char *src, size_t slen )
|
||||||
|
{
|
||||||
|
size_t i, n;
|
||||||
|
uint32_t j, x;
|
||||||
|
unsigned char *p;
|
||||||
|
|
||||||
|
/* First pass: check for validity and get output length */
|
||||||
|
for( i = n = j = 0; i < slen; i++ )
|
||||||
|
{
|
||||||
|
/* Skip spaces before checking for EOL */
|
||||||
|
x = 0;
|
||||||
|
while( i < slen && src[i] == ' ' )
|
||||||
|
{
|
||||||
|
++i;
|
||||||
|
++x;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Spaces at end of buffer are OK */
|
||||||
|
if( i == slen )
|
||||||
|
break;
|
||||||
|
|
||||||
|
if( ( slen - i ) >= 2 &&
|
||||||
|
src[i] == '\r' && src[i + 1] == '\n' )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if( src[i] == '\n' )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* Space inside a line is an error */
|
||||||
|
if( x != 0 )
|
||||||
|
return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER );
|
||||||
|
|
||||||
|
if( src[i] == '=' && ++j > 2 )
|
||||||
|
return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER );
|
||||||
|
|
||||||
|
if( src[i] > 127 || base64_dec_map[src[i]] == 127 )
|
||||||
|
return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER );
|
||||||
|
|
||||||
|
if( base64_dec_map[src[i]] < 64 && j != 0 )
|
||||||
|
return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER );
|
||||||
|
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( n == 0 )
|
||||||
|
{
|
||||||
|
*olen = 0;
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
n = ( ( n * 6 ) + 7 ) >> 3;
|
||||||
|
n -= j;
|
||||||
|
|
||||||
|
if( dst == NULL || dlen < n )
|
||||||
|
{
|
||||||
|
*olen = n;
|
||||||
|
return( MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL );
|
||||||
|
}
|
||||||
|
|
||||||
|
for( j = 3, n = x = 0, p = dst; i > 0; i--, src++ )
|
||||||
|
{
|
||||||
|
if( *src == '\r' || *src == '\n' || *src == ' ' )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
j -= ( base64_dec_map[*src] == 64 );
|
||||||
|
x = ( x << 6 ) | ( base64_dec_map[*src] & 0x3F );
|
||||||
|
|
||||||
|
if( ++n == 4 )
|
||||||
|
{
|
||||||
|
n = 0;
|
||||||
|
if( j > 0 ) *p++ = (unsigned char)( x >> 16 );
|
||||||
|
if( j > 1 ) *p++ = (unsigned char)( x >> 8 );
|
||||||
|
if( j > 2 ) *p++ = (unsigned char)( x );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*olen = p - dst;
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SELF_TEST)
|
||||||
|
|
||||||
|
static const unsigned char base64_test_dec[64] =
|
||||||
|
{
|
||||||
|
0x24, 0x48, 0x6E, 0x56, 0x87, 0x62, 0x5A, 0xBD,
|
||||||
|
0xBF, 0x17, 0xD9, 0xA2, 0xC4, 0x17, 0x1A, 0x01,
|
||||||
|
0x94, 0xED, 0x8F, 0x1E, 0x11, 0xB3, 0xD7, 0x09,
|
||||||
|
0x0C, 0xB6, 0xE9, 0x10, 0x6F, 0x22, 0xEE, 0x13,
|
||||||
|
0xCA, 0xB3, 0x07, 0x05, 0x76, 0xC9, 0xFA, 0x31,
|
||||||
|
0x6C, 0x08, 0x34, 0xFF, 0x8D, 0xC2, 0x6C, 0x38,
|
||||||
|
0x00, 0x43, 0xE9, 0x54, 0x97, 0xAF, 0x50, 0x4B,
|
||||||
|
0xD1, 0x41, 0xBA, 0x95, 0x31, 0x5A, 0x0B, 0x97
|
||||||
|
};
|
||||||
|
|
||||||
|
static const unsigned char base64_test_enc[] =
|
||||||
|
"JEhuVodiWr2/F9mixBcaAZTtjx4Rs9cJDLbpEG8i7hPK"
|
||||||
|
"swcFdsn6MWwINP+Nwmw4AEPpVJevUEvRQbqVMVoLlw==";
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Checkup routine
|
||||||
|
*/
|
||||||
|
int mbedtls_base64_self_test( int verbose )
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
const unsigned char *src;
|
||||||
|
unsigned char buffer[128];
|
||||||
|
|
||||||
|
if( verbose != 0 )
|
||||||
|
mbedtls_printf( " Base64 encoding test: " );
|
||||||
|
|
||||||
|
src = base64_test_dec;
|
||||||
|
|
||||||
|
if( mbedtls_base64_encode( buffer, sizeof( buffer ), &len, src, 64 ) != 0 ||
|
||||||
|
memcmp( base64_test_enc, buffer, 88 ) != 0 )
|
||||||
|
{
|
||||||
|
if( verbose != 0 )
|
||||||
|
mbedtls_printf( "failed\n" );
|
||||||
|
|
||||||
|
return( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( verbose != 0 )
|
||||||
|
mbedtls_printf( "passed\n Base64 decoding test: " );
|
||||||
|
|
||||||
|
src = base64_test_enc;
|
||||||
|
|
||||||
|
if( mbedtls_base64_decode( buffer, sizeof( buffer ), &len, src, 88 ) != 0 ||
|
||||||
|
memcmp( base64_test_dec, buffer, 64 ) != 0 )
|
||||||
|
{
|
||||||
|
if( verbose != 0 )
|
||||||
|
mbedtls_printf( "failed\n" );
|
||||||
|
|
||||||
|
return( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( verbose != 0 )
|
||||||
|
mbedtls_printf( "passed\n\n" );
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* MBEDTLS_SELF_TEST */
|
||||||
|
|
||||||
|
#endif /* MBEDTLS_BASE64_C */
|
88
src/utils/mbedtls/base64.h
Normal file
88
src/utils/mbedtls/base64.h
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
/**
|
||||||
|
* \file base64.h
|
||||||
|
*
|
||||||
|
* \brief RFC 1521 base64 encoding/decoding
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* This file is part of mbed TLS (https://tls.mbed.org)
|
||||||
|
*/
|
||||||
|
#ifndef MBEDTLS_BASE64_H
|
||||||
|
#define MBEDTLS_BASE64_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#define MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL -0x002A /**< Output buffer too small. */
|
||||||
|
#define MBEDTLS_ERR_BASE64_INVALID_CHARACTER -0x002C /**< Invalid character in input. */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Encode a buffer into base64 format
|
||||||
|
*
|
||||||
|
* \param dst destination buffer
|
||||||
|
* \param dlen size of the destination buffer
|
||||||
|
* \param olen number of bytes written
|
||||||
|
* \param src source buffer
|
||||||
|
* \param slen amount of data to be encoded
|
||||||
|
*
|
||||||
|
* \return 0 if successful, or MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL.
|
||||||
|
* *olen is always updated to reflect the amount
|
||||||
|
* of data that has (or would have) been written.
|
||||||
|
* If that length cannot be represented, then no data is
|
||||||
|
* written to the buffer and *olen is set to the maximum
|
||||||
|
* length representable as a size_t.
|
||||||
|
*
|
||||||
|
* \note Call this function with dlen = 0 to obtain the
|
||||||
|
* required buffer size in *olen
|
||||||
|
*/
|
||||||
|
int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen,
|
||||||
|
const unsigned char *src, size_t slen );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Decode a base64-formatted buffer
|
||||||
|
*
|
||||||
|
* \param dst destination buffer (can be NULL for checking size)
|
||||||
|
* \param dlen size of the destination buffer
|
||||||
|
* \param olen number of bytes written
|
||||||
|
* \param src source buffer
|
||||||
|
* \param slen amount of data to be decoded
|
||||||
|
*
|
||||||
|
* \return 0 if successful, MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL, or
|
||||||
|
* MBEDTLS_ERR_BASE64_INVALID_CHARACTER if the input data is
|
||||||
|
* not correct. *olen is always updated to reflect the amount
|
||||||
|
* of data that has (or would have) been written.
|
||||||
|
*
|
||||||
|
* \note Call this function with *dst = NULL or dlen = 0 to obtain
|
||||||
|
* the required buffer size in *olen
|
||||||
|
*/
|
||||||
|
int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
|
||||||
|
const unsigned char *src, size_t slen );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Checkup routine
|
||||||
|
*
|
||||||
|
* \return 0 if successful, or 1 if the test failed
|
||||||
|
*/
|
||||||
|
int mbedtls_base64_self_test( int verbose );
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* base64.h */
|
540
src/utils/mbedtls/check_config.h
Normal file
540
src/utils/mbedtls/check_config.h
Normal file
@ -0,0 +1,540 @@
|
|||||||
|
/**
|
||||||
|
* \file check_config.h
|
||||||
|
*
|
||||||
|
* \brief Consistency checks for configuration options
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* This file is part of mbed TLS (https://tls.mbed.org)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* It is recommended to include this file from your config.h
|
||||||
|
* in order to catch dependency issues early.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MBEDTLS_CHECK_CONFIG_H
|
||||||
|
#define MBEDTLS_CHECK_CONFIG_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We assume CHAR_BIT is 8 in many places. In practice, this is true on our
|
||||||
|
* target platforms, so not an issue, but let's just be extra sure.
|
||||||
|
*/
|
||||||
|
#include <limits.h>
|
||||||
|
#if CHAR_BIT != 8
|
||||||
|
#error "mbed TLS requires a platform with 8-bit chars"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#if !defined(MBEDTLS_PLATFORM_C)
|
||||||
|
#error "MBEDTLS_PLATFORM_C is required on Windows"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Fix the config here. Not convenient to put an #ifdef _WIN32 in config.h as
|
||||||
|
* it would confuse config.pl. */
|
||||||
|
#if !defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) && \
|
||||||
|
!defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO)
|
||||||
|
#define MBEDTLS_PLATFORM_SNPRINTF_ALT
|
||||||
|
#endif
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
#if defined(TARGET_LIKE_MBED) && \
|
||||||
|
( defined(MBEDTLS_NET_C) || defined(MBEDTLS_TIMING_C) )
|
||||||
|
#error "The NET and TIMING modules are not available for mbed OS - please use the network and timing functions provided by mbed OS"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_DEPRECATED_WARNING) && \
|
||||||
|
!defined(__GNUC__) && !defined(__clang__)
|
||||||
|
#error "MBEDTLS_DEPRECATED_WARNING only works with GCC and Clang"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_HAVE_TIME_DATE) && !defined(MBEDTLS_HAVE_TIME)
|
||||||
|
#error "MBEDTLS_HAVE_TIME_DATE without MBEDTLS_HAVE_TIME does not make sense"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_AESNI_C) && !defined(MBEDTLS_HAVE_ASM)
|
||||||
|
#error "MBEDTLS_AESNI_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_CTR_DRBG_C) && !defined(MBEDTLS_AES_C)
|
||||||
|
#error "MBEDTLS_CTR_DRBG_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_DHM_C) && !defined(MBEDTLS_BIGNUM_C)
|
||||||
|
#error "MBEDTLS_DHM_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_ECDH_C) && !defined(MBEDTLS_ECP_C)
|
||||||
|
#error "MBEDTLS_ECDH_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_ECDSA_C) && \
|
||||||
|
( !defined(MBEDTLS_ECP_C) || \
|
||||||
|
!defined(MBEDTLS_ASN1_PARSE_C) || \
|
||||||
|
!defined(MBEDTLS_ASN1_WRITE_C) )
|
||||||
|
#error "MBEDTLS_ECDSA_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_ECJPAKE_C) && \
|
||||||
|
( !defined(MBEDTLS_ECP_C) || !defined(MBEDTLS_MD_C) )
|
||||||
|
#error "MBEDTLS_ECJPAKE_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_ECDSA_DETERMINISTIC) && !defined(MBEDTLS_HMAC_DRBG_C)
|
||||||
|
#error "MBEDTLS_ECDSA_DETERMINISTIC defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_ECP_C) && ( !defined(MBEDTLS_BIGNUM_C) || ( \
|
||||||
|
!defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) && \
|
||||||
|
!defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) && \
|
||||||
|
!defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) && \
|
||||||
|
!defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) && \
|
||||||
|
!defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) && \
|
||||||
|
!defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) && \
|
||||||
|
!defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) && \
|
||||||
|
!defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) && \
|
||||||
|
!defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) && \
|
||||||
|
!defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) && \
|
||||||
|
!defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) ) )
|
||||||
|
#error "MBEDTLS_ECP_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_ENTROPY_C) && (!defined(MBEDTLS_SHA512_C) && \
|
||||||
|
!defined(MBEDTLS_SHA256_C))
|
||||||
|
#error "MBEDTLS_ENTROPY_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
#if defined(MBEDTLS_ENTROPY_C) && defined(MBEDTLS_SHA512_C) && \
|
||||||
|
defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN) && (MBEDTLS_CTR_DRBG_ENTROPY_LEN > 64)
|
||||||
|
#error "MBEDTLS_CTR_DRBG_ENTROPY_LEN value too high"
|
||||||
|
#endif
|
||||||
|
#if defined(MBEDTLS_ENTROPY_C) && \
|
||||||
|
( !defined(MBEDTLS_SHA512_C) || defined(MBEDTLS_ENTROPY_FORCE_SHA256) ) \
|
||||||
|
&& defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN) && (MBEDTLS_CTR_DRBG_ENTROPY_LEN > 32)
|
||||||
|
#error "MBEDTLS_CTR_DRBG_ENTROPY_LEN value too high"
|
||||||
|
#endif
|
||||||
|
#if defined(MBEDTLS_ENTROPY_C) && \
|
||||||
|
defined(MBEDTLS_ENTROPY_FORCE_SHA256) && !defined(MBEDTLS_SHA256_C)
|
||||||
|
#error "MBEDTLS_ENTROPY_FORCE_SHA256 defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_GCM_C) && ( \
|
||||||
|
!defined(MBEDTLS_AES_C) && !defined(MBEDTLS_CAMELLIA_C) )
|
||||||
|
#error "MBEDTLS_GCM_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_HAVEGE_C) && !defined(MBEDTLS_TIMING_C)
|
||||||
|
#error "MBEDTLS_HAVEGE_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_HMAC_DRBG_C) && !defined(MBEDTLS_MD_C)
|
||||||
|
#error "MBEDTLS_HMAC_DRBG_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) && \
|
||||||
|
( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) )
|
||||||
|
#error "MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) && \
|
||||||
|
( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) )
|
||||||
|
#error "MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) && !defined(MBEDTLS_DHM_C)
|
||||||
|
#error "MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED) && \
|
||||||
|
!defined(MBEDTLS_ECDH_C)
|
||||||
|
#error "MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) && \
|
||||||
|
( !defined(MBEDTLS_DHM_C) || !defined(MBEDTLS_RSA_C) || \
|
||||||
|
!defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_PKCS1_V15) )
|
||||||
|
#error "MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) && \
|
||||||
|
( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_RSA_C) || \
|
||||||
|
!defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_PKCS1_V15) )
|
||||||
|
#error "MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) && \
|
||||||
|
( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_ECDSA_C) || \
|
||||||
|
!defined(MBEDTLS_X509_CRT_PARSE_C) )
|
||||||
|
#error "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) && \
|
||||||
|
( !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) || \
|
||||||
|
!defined(MBEDTLS_PKCS1_V15) )
|
||||||
|
#error "MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) && \
|
||||||
|
( !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) || \
|
||||||
|
!defined(MBEDTLS_PKCS1_V15) )
|
||||||
|
#error "MBEDTLS_KEY_EXCHANGE_RSA_ENABLED defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) && \
|
||||||
|
( !defined(MBEDTLS_ECJPAKE_C) || !defined(MBEDTLS_SHA256_C) || \
|
||||||
|
!defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) )
|
||||||
|
#error "MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
|
||||||
|
( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_PLATFORM_MEMORY) )
|
||||||
|
#error "MBEDTLS_MEMORY_BUFFER_ALLOC_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PADLOCK_C) && !defined(MBEDTLS_HAVE_ASM)
|
||||||
|
#error "MBEDTLS_PADLOCK_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PEM_PARSE_C) && !defined(MBEDTLS_BASE64_C)
|
||||||
|
#error "MBEDTLS_PEM_PARSE_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PEM_WRITE_C) && !defined(MBEDTLS_BASE64_C)
|
||||||
|
#error "MBEDTLS_PEM_WRITE_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PK_C) && \
|
||||||
|
( !defined(MBEDTLS_RSA_C) && !defined(MBEDTLS_ECP_C) )
|
||||||
|
#error "MBEDTLS_PK_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PK_PARSE_C) && !defined(MBEDTLS_PK_C)
|
||||||
|
#error "MBEDTLS_PK_PARSE_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PK_WRITE_C) && !defined(MBEDTLS_PK_C)
|
||||||
|
#error "MBEDTLS_PK_WRITE_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PKCS11_C) && !defined(MBEDTLS_PK_C)
|
||||||
|
#error "MBEDTLS_PKCS11_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_EXIT_ALT) && !defined(MBEDTLS_PLATFORM_C)
|
||||||
|
#error "MBEDTLS_PLATFORM_EXIT_ALT defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_EXIT_MACRO) && !defined(MBEDTLS_PLATFORM_C)
|
||||||
|
#error "MBEDTLS_PLATFORM_EXIT_MACRO defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_EXIT_MACRO) &&\
|
||||||
|
( defined(MBEDTLS_PLATFORM_STD_EXIT) ||\
|
||||||
|
defined(MBEDTLS_PLATFORM_EXIT_ALT) )
|
||||||
|
#error "MBEDTLS_PLATFORM_EXIT_MACRO and MBEDTLS_PLATFORM_STD_EXIT/MBEDTLS_PLATFORM_EXIT_ALT cannot be defined simultaneously"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_FPRINTF_ALT) && !defined(MBEDTLS_PLATFORM_C)
|
||||||
|
#error "MBEDTLS_PLATFORM_FPRINTF_ALT defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO) && !defined(MBEDTLS_PLATFORM_C)
|
||||||
|
#error "MBEDTLS_PLATFORM_FPRINTF_MACRO defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO) &&\
|
||||||
|
( defined(MBEDTLS_PLATFORM_STD_FPRINTF) ||\
|
||||||
|
defined(MBEDTLS_PLATFORM_FPRINTF_ALT) )
|
||||||
|
#error "MBEDTLS_PLATFORM_FPRINTF_MACRO and MBEDTLS_PLATFORM_STD_FPRINTF/MBEDTLS_PLATFORM_FPRINTF_ALT cannot be defined simultaneously"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_FREE_MACRO) &&\
|
||||||
|
( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_PLATFORM_MEMORY) )
|
||||||
|
#error "MBEDTLS_PLATFORM_FREE_MACRO defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_FREE_MACRO) &&\
|
||||||
|
defined(MBEDTLS_PLATFORM_STD_FREE)
|
||||||
|
#error "MBEDTLS_PLATFORM_FREE_MACRO and MBEDTLS_PLATFORM_STD_FREE cannot be defined simultaneously"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_FREE_MACRO) && !defined(MBEDTLS_PLATFORM_CALLOC_MACRO)
|
||||||
|
#error "MBEDTLS_PLATFORM_CALLOC_MACRO must be defined if MBEDTLS_PLATFORM_FREE_MACRO is"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_CALLOC_MACRO) &&\
|
||||||
|
( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_PLATFORM_MEMORY) )
|
||||||
|
#error "MBEDTLS_PLATFORM_CALLOC_MACRO defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_CALLOC_MACRO) &&\
|
||||||
|
defined(MBEDTLS_PLATFORM_STD_CALLOC)
|
||||||
|
#error "MBEDTLS_PLATFORM_CALLOC_MACRO and MBEDTLS_PLATFORM_STD_CALLOC cannot be defined simultaneously"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_CALLOC_MACRO) && !defined(MBEDTLS_PLATFORM_FREE_MACRO)
|
||||||
|
#error "MBEDTLS_PLATFORM_FREE_MACRO must be defined if MBEDTLS_PLATFORM_CALLOC_MACRO is"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_MEMORY) && !defined(MBEDTLS_PLATFORM_C)
|
||||||
|
#error "MBEDTLS_PLATFORM_MEMORY defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_PRINTF_ALT) && !defined(MBEDTLS_PLATFORM_C)
|
||||||
|
#error "MBEDTLS_PLATFORM_PRINTF_ALT defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_PRINTF_MACRO) && !defined(MBEDTLS_PLATFORM_C)
|
||||||
|
#error "MBEDTLS_PLATFORM_PRINTF_MACRO defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_PRINTF_MACRO) &&\
|
||||||
|
( defined(MBEDTLS_PLATFORM_STD_PRINTF) ||\
|
||||||
|
defined(MBEDTLS_PLATFORM_PRINTF_ALT) )
|
||||||
|
#error "MBEDTLS_PLATFORM_PRINTF_MACRO and MBEDTLS_PLATFORM_STD_PRINTF/MBEDTLS_PLATFORM_PRINTF_ALT cannot be defined simultaneously"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) && !defined(MBEDTLS_PLATFORM_C)
|
||||||
|
#error "MBEDTLS_PLATFORM_SNPRINTF_ALT defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO) && !defined(MBEDTLS_PLATFORM_C)
|
||||||
|
#error "MBEDTLS_PLATFORM_SNPRINTF_MACRO defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO) &&\
|
||||||
|
( defined(MBEDTLS_PLATFORM_STD_SNPRINTF) ||\
|
||||||
|
defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) )
|
||||||
|
#error "MBEDTLS_PLATFORM_SNPRINTF_MACRO and MBEDTLS_PLATFORM_STD_SNPRINTF/MBEDTLS_PLATFORM_SNPRINTF_ALT cannot be defined simultaneously"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_STD_MEM_HDR) &&\
|
||||||
|
!defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS)
|
||||||
|
#error "MBEDTLS_PLATFORM_STD_MEM_HDR defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_STD_CALLOC) && !defined(MBEDTLS_PLATFORM_MEMORY)
|
||||||
|
#error "MBEDTLS_PLATFORM_STD_CALLOC defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_STD_CALLOC) && !defined(MBEDTLS_PLATFORM_MEMORY)
|
||||||
|
#error "MBEDTLS_PLATFORM_STD_CALLOC defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_STD_FREE) && !defined(MBEDTLS_PLATFORM_MEMORY)
|
||||||
|
#error "MBEDTLS_PLATFORM_STD_FREE defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_STD_EXIT) &&\
|
||||||
|
!defined(MBEDTLS_PLATFORM_EXIT_ALT)
|
||||||
|
#error "MBEDTLS_PLATFORM_STD_EXIT defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_STD_FPRINTF) &&\
|
||||||
|
!defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
|
||||||
|
#error "MBEDTLS_PLATFORM_STD_FPRINTF defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_STD_PRINTF) &&\
|
||||||
|
!defined(MBEDTLS_PLATFORM_PRINTF_ALT)
|
||||||
|
#error "MBEDTLS_PLATFORM_STD_PRINTF defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_STD_SNPRINTF) &&\
|
||||||
|
!defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
|
||||||
|
#error "MBEDTLS_PLATFORM_STD_SNPRINTF defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_RSA_C) && ( !defined(MBEDTLS_BIGNUM_C) || \
|
||||||
|
!defined(MBEDTLS_OID_C) )
|
||||||
|
#error "MBEDTLS_RSA_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT) && \
|
||||||
|
( !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_PKCS1_V21) )
|
||||||
|
#error "MBEDTLS_X509_RSASSA_PSS_SUPPORT defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_PROTO_SSL3) && ( !defined(MBEDTLS_MD5_C) || \
|
||||||
|
!defined(MBEDTLS_SHA1_C) )
|
||||||
|
#error "MBEDTLS_SSL_PROTO_SSL3 defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_PROTO_TLS1) && ( !defined(MBEDTLS_MD5_C) || \
|
||||||
|
!defined(MBEDTLS_SHA1_C) )
|
||||||
|
#error "MBEDTLS_SSL_PROTO_TLS1 defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_1) && ( !defined(MBEDTLS_MD5_C) || \
|
||||||
|
!defined(MBEDTLS_SHA1_C) )
|
||||||
|
#error "MBEDTLS_SSL_PROTO_TLS1_1 defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_2) && ( !defined(MBEDTLS_SHA1_C) && \
|
||||||
|
!defined(MBEDTLS_SHA256_C) && !defined(MBEDTLS_SHA512_C) )
|
||||||
|
#error "MBEDTLS_SSL_PROTO_TLS1_2 defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_PROTO_DTLS) && \
|
||||||
|
!defined(MBEDTLS_SSL_PROTO_TLS1_1) && \
|
||||||
|
!defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||||
|
#error "MBEDTLS_SSL_PROTO_DTLS defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_CLI_C) && !defined(MBEDTLS_SSL_TLS_C)
|
||||||
|
#error "MBEDTLS_SSL_CLI_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_TLS_C) && ( !defined(MBEDTLS_CIPHER_C) || \
|
||||||
|
!defined(MBEDTLS_MD_C) )
|
||||||
|
#error "MBEDTLS_SSL_TLS_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_SRV_C) && !defined(MBEDTLS_SSL_TLS_C)
|
||||||
|
#error "MBEDTLS_SSL_SRV_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_TLS_C) && (!defined(MBEDTLS_SSL_PROTO_SSL3) && \
|
||||||
|
!defined(MBEDTLS_SSL_PROTO_TLS1) && !defined(MBEDTLS_SSL_PROTO_TLS1_1) && \
|
||||||
|
!defined(MBEDTLS_SSL_PROTO_TLS1_2))
|
||||||
|
#error "MBEDTLS_SSL_TLS_C defined, but no protocols are active"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_TLS_C) && (defined(MBEDTLS_SSL_PROTO_SSL3) && \
|
||||||
|
defined(MBEDTLS_SSL_PROTO_TLS1_1) && !defined(MBEDTLS_SSL_PROTO_TLS1))
|
||||||
|
#error "Illegal protocol selection"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_TLS_C) && (defined(MBEDTLS_SSL_PROTO_TLS1) && \
|
||||||
|
defined(MBEDTLS_SSL_PROTO_TLS1_2) && !defined(MBEDTLS_SSL_PROTO_TLS1_1))
|
||||||
|
#error "Illegal protocol selection"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_TLS_C) && (defined(MBEDTLS_SSL_PROTO_SSL3) && \
|
||||||
|
defined(MBEDTLS_SSL_PROTO_TLS1_2) && (!defined(MBEDTLS_SSL_PROTO_TLS1) || \
|
||||||
|
!defined(MBEDTLS_SSL_PROTO_TLS1_1)))
|
||||||
|
#error "Illegal protocol selection"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && !defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||||
|
#error "MBEDTLS_SSL_DTLS_HELLO_VERIFY defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE) && \
|
||||||
|
!defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY)
|
||||||
|
#error "MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY) && \
|
||||||
|
( !defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_PROTO_DTLS) )
|
||||||
|
#error "MBEDTLS_SSL_DTLS_ANTI_REPLAY defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT) && \
|
||||||
|
( !defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_PROTO_DTLS) )
|
||||||
|
#error "MBEDTLS_SSL_DTLS_BADMAC_LIMIT defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC) && \
|
||||||
|
!defined(MBEDTLS_SSL_PROTO_TLS1) && \
|
||||||
|
!defined(MBEDTLS_SSL_PROTO_TLS1_1) && \
|
||||||
|
!defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||||
|
#error "MBEDTLS_SSL_ENCRYPT_THEN_MAC defined, but not all prerequsites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET) && \
|
||||||
|
!defined(MBEDTLS_SSL_PROTO_TLS1) && \
|
||||||
|
!defined(MBEDTLS_SSL_PROTO_TLS1_1) && \
|
||||||
|
!defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||||
|
#error "MBEDTLS_SSL_EXTENDED_MASTER_SECRET defined, but not all prerequsites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_TICKET_C) && !defined(MBEDTLS_CIPHER_C)
|
||||||
|
#error "MBEDTLS_SSL_TICKET_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING) && \
|
||||||
|
!defined(MBEDTLS_SSL_PROTO_SSL3) && !defined(MBEDTLS_SSL_PROTO_TLS1)
|
||||||
|
#error "MBEDTLS_SSL_CBC_RECORD_SPLITTING defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION) && \
|
||||||
|
!defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||||
|
#error "MBEDTLS_SSL_SERVER_NAME_INDICATION defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_THREADING_PTHREAD)
|
||||||
|
#if !defined(MBEDTLS_THREADING_C) || defined(MBEDTLS_THREADING_IMPL)
|
||||||
|
#error "MBEDTLS_THREADING_PTHREAD defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
#define MBEDTLS_THREADING_IMPL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_THREADING_ALT)
|
||||||
|
#if !defined(MBEDTLS_THREADING_C) || defined(MBEDTLS_THREADING_IMPL)
|
||||||
|
#error "MBEDTLS_THREADING_ALT defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
#define MBEDTLS_THREADING_IMPL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_THREADING_C) && !defined(MBEDTLS_THREADING_IMPL)
|
||||||
|
#error "MBEDTLS_THREADING_C defined, single threading implementation required"
|
||||||
|
#endif
|
||||||
|
#undef MBEDTLS_THREADING_IMPL
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_VERSION_FEATURES) && !defined(MBEDTLS_VERSION_C)
|
||||||
|
#error "MBEDTLS_VERSION_FEATURES defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_X509_USE_C) && ( !defined(MBEDTLS_BIGNUM_C) || \
|
||||||
|
!defined(MBEDTLS_OID_C) || !defined(MBEDTLS_ASN1_PARSE_C) || \
|
||||||
|
!defined(MBEDTLS_PK_PARSE_C) )
|
||||||
|
#error "MBEDTLS_X509_USE_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_X509_CREATE_C) && ( !defined(MBEDTLS_BIGNUM_C) || \
|
||||||
|
!defined(MBEDTLS_OID_C) || !defined(MBEDTLS_ASN1_WRITE_C) || \
|
||||||
|
!defined(MBEDTLS_PK_WRITE_C) )
|
||||||
|
#error "MBEDTLS_X509_CREATE_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_X509_CRT_PARSE_C) && ( !defined(MBEDTLS_X509_USE_C) )
|
||||||
|
#error "MBEDTLS_X509_CRT_PARSE_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_X509_CRL_PARSE_C) && ( !defined(MBEDTLS_X509_USE_C) )
|
||||||
|
#error "MBEDTLS_X509_CRL_PARSE_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_X509_CSR_PARSE_C) && ( !defined(MBEDTLS_X509_USE_C) )
|
||||||
|
#error "MBEDTLS_X509_CSR_PARSE_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_X509_CRT_WRITE_C) && ( !defined(MBEDTLS_X509_CREATE_C) )
|
||||||
|
#error "MBEDTLS_X509_CRT_WRITE_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_X509_CSR_WRITE_C) && ( !defined(MBEDTLS_X509_CREATE_C) )
|
||||||
|
#error "MBEDTLS_X509_CSR_WRITE_C defined, but not all prerequisites"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Avoid warning from -pedantic. This is a convenient place for this
|
||||||
|
* workaround since this is included by every single file before the
|
||||||
|
* #if defined(MBEDTLS_xxx_C) that results in emtpy translation units.
|
||||||
|
*/
|
||||||
|
typedef int mbedtls_iso_c_forbids_empty_translation_units;
|
||||||
|
|
||||||
|
#endif /* MBEDTLS_CHECK_CONFIG_H */
|
2511
src/utils/mbedtls/mbed-tls-config.h
Normal file
2511
src/utils/mbedtls/mbed-tls-config.h
Normal file
File diff suppressed because it is too large
Load Diff
214
src/utils/mbedtls/platform.h
Normal file
214
src/utils/mbedtls/platform.h
Normal file
@ -0,0 +1,214 @@
|
|||||||
|
/**
|
||||||
|
* \file platform.h
|
||||||
|
*
|
||||||
|
* \brief mbed TLS Platform abstraction layer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* This file is part of mbed TLS (https://tls.mbed.org)
|
||||||
|
*/
|
||||||
|
#ifndef MBEDTLS_PLATFORM_H
|
||||||
|
#define MBEDTLS_PLATFORM_H
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||||
|
#include "config.h"
|
||||||
|
#else
|
||||||
|
#include MBEDTLS_CONFIG_FILE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \name SECTION: Module settings
|
||||||
|
*
|
||||||
|
* The configuration options you can set for this module are in this section.
|
||||||
|
* Either change them in config.h or define them on the compiler command line.
|
||||||
|
* \{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS)
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#if !defined(MBEDTLS_PLATFORM_STD_SNPRINTF)
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#define MBEDTLS_PLATFORM_STD_SNPRINTF mbedtls_platform_win32_snprintf /**< Default snprintf to use */
|
||||||
|
#else
|
||||||
|
#define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf /**< Default snprintf to use */
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#if !defined(MBEDTLS_PLATFORM_STD_PRINTF)
|
||||||
|
#define MBEDTLS_PLATFORM_STD_PRINTF printf /**< Default printf to use */
|
||||||
|
#endif
|
||||||
|
#if !defined(MBEDTLS_PLATFORM_STD_FPRINTF)
|
||||||
|
#define MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use */
|
||||||
|
#endif
|
||||||
|
#if !defined(MBEDTLS_PLATFORM_STD_CALLOC)
|
||||||
|
#define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< Default allocator to use */
|
||||||
|
#endif
|
||||||
|
#if !defined(MBEDTLS_PLATFORM_STD_FREE)
|
||||||
|
#define MBEDTLS_PLATFORM_STD_FREE free /**< Default free to use */
|
||||||
|
#endif
|
||||||
|
#if !defined(MBEDTLS_PLATFORM_STD_EXIT)
|
||||||
|
#define MBEDTLS_PLATFORM_STD_EXIT exit /**< Default free to use */
|
||||||
|
#endif
|
||||||
|
#else /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
|
||||||
|
#if defined(MBEDTLS_PLATFORM_STD_MEM_HDR)
|
||||||
|
#include MBEDTLS_PLATFORM_STD_MEM_HDR
|
||||||
|
#endif
|
||||||
|
#endif /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
|
||||||
|
|
||||||
|
/* \} name SECTION: Module settings */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The function pointers for calloc and free
|
||||||
|
*/
|
||||||
|
#if defined(MBEDTLS_PLATFORM_MEMORY)
|
||||||
|
#if defined(MBEDTLS_PLATFORM_FREE_MACRO) && \
|
||||||
|
defined(MBEDTLS_PLATFORM_CALLOC_MACRO)
|
||||||
|
#define mbedtls_free MBEDTLS_PLATFORM_FREE_MACRO
|
||||||
|
#define mbedtls_calloc MBEDTLS_PLATFORM_CALLOC_MACRO
|
||||||
|
#else
|
||||||
|
/* For size_t */
|
||||||
|
#include <stddef.h>
|
||||||
|
extern void * (*mbedtls_calloc)( size_t n, size_t size );
|
||||||
|
extern void (*mbedtls_free)( void *ptr );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Set your own memory implementation function pointers
|
||||||
|
*
|
||||||
|
* \param calloc_func the calloc function implementation
|
||||||
|
* \param free_func the free function implementation
|
||||||
|
*
|
||||||
|
* \return 0 if successful
|
||||||
|
*/
|
||||||
|
int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ),
|
||||||
|
void (*free_func)( void * ) );
|
||||||
|
#endif /* MBEDTLS_PLATFORM_FREE_MACRO && MBEDTLS_PLATFORM_CALLOC_MACRO */
|
||||||
|
#else /* !MBEDTLS_PLATFORM_MEMORY */
|
||||||
|
#define mbedtls_free free
|
||||||
|
#define mbedtls_calloc calloc
|
||||||
|
#endif /* MBEDTLS_PLATFORM_MEMORY && !MBEDTLS_PLATFORM_{FREE,CALLOC}_MACRO */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The function pointers for fprintf
|
||||||
|
*/
|
||||||
|
#if defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
|
||||||
|
/* We need FILE * */
|
||||||
|
#include <stdio.h>
|
||||||
|
extern int (*mbedtls_fprintf)( FILE *stream, const char *format, ... );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Set your own fprintf function pointer
|
||||||
|
*
|
||||||
|
* \param fprintf_func the fprintf function implementation
|
||||||
|
*
|
||||||
|
* \return 0
|
||||||
|
*/
|
||||||
|
int mbedtls_platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *,
|
||||||
|
... ) );
|
||||||
|
#else
|
||||||
|
#if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO)
|
||||||
|
#define mbedtls_fprintf MBEDTLS_PLATFORM_FPRINTF_MACRO
|
||||||
|
#else
|
||||||
|
#define mbedtls_fprintf fprintf
|
||||||
|
#endif /* MBEDTLS_PLATFORM_FPRINTF_MACRO */
|
||||||
|
#endif /* MBEDTLS_PLATFORM_FPRINTF_ALT */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The function pointers for printf
|
||||||
|
*/
|
||||||
|
#if defined(MBEDTLS_PLATFORM_PRINTF_ALT)
|
||||||
|
extern int (*mbedtls_printf)( const char *format, ... );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Set your own printf function pointer
|
||||||
|
*
|
||||||
|
* \param printf_func the printf function implementation
|
||||||
|
*
|
||||||
|
* \return 0
|
||||||
|
*/
|
||||||
|
int mbedtls_platform_set_printf( int (*printf_func)( const char *, ... ) );
|
||||||
|
#else /* !MBEDTLS_PLATFORM_PRINTF_ALT */
|
||||||
|
#if defined(MBEDTLS_PLATFORM_PRINTF_MACRO)
|
||||||
|
#define mbedtls_printf MBEDTLS_PLATFORM_PRINTF_MACRO
|
||||||
|
#else
|
||||||
|
#define mbedtls_printf printf
|
||||||
|
#endif /* MBEDTLS_PLATFORM_PRINTF_MACRO */
|
||||||
|
#endif /* MBEDTLS_PLATFORM_PRINTF_ALT */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The function pointers for snprintf
|
||||||
|
*
|
||||||
|
* The snprintf implementation should conform to C99:
|
||||||
|
* - it *must* always correctly zero-terminate the buffer
|
||||||
|
* (except when n == 0, then it must leave the buffer untouched)
|
||||||
|
* - however it is acceptable to return -1 instead of the required length when
|
||||||
|
* the destination buffer is too short.
|
||||||
|
*/
|
||||||
|
#if defined(_WIN32)
|
||||||
|
/* For Windows (inc. MSYS2), we provide our own fixed implementation */
|
||||||
|
int mbedtls_platform_win32_snprintf( char *s, size_t n, const char *fmt, ... );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
|
||||||
|
extern int (*mbedtls_snprintf)( char * s, size_t n, const char * format, ... );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Set your own snprintf function pointer
|
||||||
|
*
|
||||||
|
* \param snprintf_func the snprintf function implementation
|
||||||
|
*
|
||||||
|
* \return 0
|
||||||
|
*/
|
||||||
|
int mbedtls_platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
|
||||||
|
const char * format, ... ) );
|
||||||
|
#else /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
|
||||||
|
#if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO)
|
||||||
|
#define mbedtls_snprintf MBEDTLS_PLATFORM_SNPRINTF_MACRO
|
||||||
|
#else
|
||||||
|
#define mbedtls_snprintf snprintf
|
||||||
|
#endif /* MBEDTLS_PLATFORM_SNPRINTF_MACRO */
|
||||||
|
#endif /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The function pointers for exit
|
||||||
|
*/
|
||||||
|
#if defined(MBEDTLS_PLATFORM_EXIT_ALT)
|
||||||
|
extern void (*mbedtls_exit)( int status );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Set your own exit function pointer
|
||||||
|
*
|
||||||
|
* \param exit_func the exit function implementation
|
||||||
|
*
|
||||||
|
* \return 0
|
||||||
|
*/
|
||||||
|
int mbedtls_platform_set_exit( void (*exit_func)( int status ) );
|
||||||
|
#else
|
||||||
|
#if defined(MBEDTLS_PLATFORM_EXIT_MACRO)
|
||||||
|
#define mbedtls_exit MBEDTLS_PLATFORM_EXIT_MACRO
|
||||||
|
#else
|
||||||
|
#define mbedtls_exit exit
|
||||||
|
#endif /* MBEDTLS_PLATFORM_EXIT_MACRO */
|
||||||
|
#endif /* MBEDTLS_PLATFORM_EXIT_ALT */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* platform.h */
|
Loading…
x
Reference in New Issue
Block a user