Skip to content

Commit

Permalink
Merge pull request #6396 from gilles-peskine-arm/platform.h-unconditi…
Browse files Browse the repository at this point in the history
…onal-2.28

Backport 2.28: Include platform.h unconditionally
  • Loading branch information
gilles-peskine-arm authored Oct 13, 2022
2 parents a129bab + 36b33ba commit 279188f
Show file tree
Hide file tree
Showing 129 changed files with 36 additions and 982 deletions.
5 changes: 0 additions & 5 deletions 3rdparty/everest/library/everest.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@
#include "everest/x25519.h"
#include "everest/everest.h"

#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#define mbedtls_calloc calloc
#define mbedtls_free free
#endif

#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)

Expand Down
3 changes: 3 additions & 0 deletions ChangeLog.d/platform-setbuf.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Bugfix
* Provide the missing definition of mbedtls_setbuf() in some configurations
with MBEDTLS_PLATFORM_C disabled. Fixes #6118, #6196.
14 changes: 14 additions & 0 deletions include/mbedtls/check_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,20 @@
#error "MBEDTLS_PLATFORM_SNPRINTF_MACRO and MBEDTLS_PLATFORM_STD_SNPRINTF/MBEDTLS_PLATFORM_SNPRINTF_ALT cannot be defined simultaneously"
#endif

#if defined(MBEDTLS_PLATFORM_VSNPRINTF_ALT) && !defined(MBEDTLS_PLATFORM_C)
#error "MBEDTLS_PLATFORM_VSNPRINTF_ALT defined, but not all prerequisites"
#endif

#if defined(MBEDTLS_PLATFORM_VSNPRINTF_MACRO) && !defined(MBEDTLS_PLATFORM_C)
#error "MBEDTLS_PLATFORM_VSNPRINTF_MACRO defined, but not all prerequisites"
#endif

#if defined(MBEDTLS_PLATFORM_VSNPRINTF_MACRO) &&\
( defined(MBEDTLS_PLATFORM_STD_VSNPRINTF) ||\
defined(MBEDTLS_PLATFORM_VSNPRINTF_ALT) )
#error "MBEDTLS_PLATFORM_VSNPRINTF_MACRO and MBEDTLS_PLATFORM_STD_VSNPRINTF/MBEDTLS_PLATFORM_VSNPRINTF_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"
Expand Down
7 changes: 7 additions & 0 deletions include/mbedtls/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
* 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
Expand Down
7 changes: 0 additions & 7 deletions library/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,7 @@
#include "mbedtls/aesni.h"
#endif

#if defined(MBEDTLS_SELF_TEST)
#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 */

#if !defined(MBEDTLS_AES_ALT)

Expand Down
7 changes: 0 additions & 7 deletions library/arc4.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@

#include <string.h>

#if defined(MBEDTLS_SELF_TEST)
#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 */

#if !defined(MBEDTLS_ARC4_ALT)

Expand Down
7 changes: 0 additions & 7 deletions library/aria.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@

#include <string.h>

#if defined(MBEDTLS_SELF_TEST)
#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 */

#if !defined(MBEDTLS_ARIA_ALT)

Expand Down
6 changes: 0 additions & 6 deletions library/asn1parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@
#include "mbedtls/bignum.h"
#endif

#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdlib.h>
#define mbedtls_calloc calloc
#define mbedtls_free free
#endif

/*
* ASN.1 DER decoding routines
Expand Down
6 changes: 0 additions & 6 deletions library/asn1write.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@

#include <string.h>

#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdlib.h>
#define mbedtls_calloc calloc
#define mbedtls_free free
#endif

int mbedtls_asn1_write_len( unsigned char **p, unsigned char *start, size_t len )
{
Expand Down
5 changes: 0 additions & 5 deletions library/base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@

#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 */

#define BASE64_SIZE_T_MAX ( (size_t) -1 ) /* SIZE_T_MAX is not standard */
Expand Down
8 changes: 0 additions & 8 deletions library/bignum.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,7 @@
#include <limits.h>
#include <string.h>

#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdio.h>
#include <stdlib.h>
#define mbedtls_printf printf
#define mbedtls_calloc calloc
#define mbedtls_free free
#endif

#define MPI_VALIDATE_RET( cond ) \
MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_MPI_BAD_INPUT_DATA )
Expand Down
7 changes: 0 additions & 7 deletions library/camellia.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,7 @@

#include <string.h>

#if defined(MBEDTLS_SELF_TEST)
#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 */

#if !defined(MBEDTLS_CAMELLIA_ALT)

Expand Down
7 changes: 0 additions & 7 deletions library/ccm.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,7 @@

#include <string.h>

#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
#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 && MBEDTLS_AES_C */

#if !defined(MBEDTLS_CCM_ALT)

Expand Down
7 changes: 0 additions & 7 deletions library/chacha20.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,7 @@
#include <stddef.h>
#include <string.h>

#if defined(MBEDTLS_SELF_TEST)
#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 */

#if !defined(MBEDTLS_CHACHA20_ALT)

Expand Down
7 changes: 0 additions & 7 deletions library/chachapoly.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,7 @@

#include <string.h>

#if defined(MBEDTLS_SELF_TEST)
#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 */

#if !defined(MBEDTLS_CHACHAPOLY_ALT)

Expand Down
5 changes: 0 additions & 5 deletions library/cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,7 @@
#include "mbedtls/nist_kw.h"
#endif

#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#define mbedtls_calloc calloc
#define mbedtls_free free
#endif

#define CIPHER_VALIDATE_RET( cond ) \
MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA )
Expand Down
6 changes: 0 additions & 6 deletions library/cipher_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,7 @@
#include <string.h>
#endif

#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdlib.h>
#define mbedtls_calloc calloc
#define mbedtls_free free
#endif

#if defined(MBEDTLS_GCM_C)
/* shared by all GCM ciphers */
Expand Down
7 changes: 0 additions & 7 deletions library/ctr_drbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,7 @@
#include <stdio.h>
#endif

#if defined(MBEDTLS_SELF_TEST)
#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 */

/*
* CTR_DRBG context initialization
Expand Down
9 changes: 0 additions & 9 deletions library/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,7 @@

#if defined(MBEDTLS_DEBUG_C)

#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdlib.h>
#define mbedtls_calloc calloc
#define mbedtls_free free
#define mbedtls_time_t time_t
#define mbedtls_snprintf snprintf
#define mbedtls_vsnprintf vsnprintf
#endif

#include "mbedtls/debug.h"
#include "mbedtls/error.h"
Expand Down
7 changes: 0 additions & 7 deletions library/des.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,7 @@

#include <string.h>

#if defined(MBEDTLS_SELF_TEST)
#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 */

#if !defined(MBEDTLS_DES_ALT)

Expand Down
8 changes: 0 additions & 8 deletions library/dhm.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,7 @@
#include "mbedtls/asn1.h"
#endif

#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdlib.h>
#include <stdio.h>
#define mbedtls_printf printf
#define mbedtls_calloc calloc
#define mbedtls_free free
#endif

#if !defined(MBEDTLS_DHM_ALT)

Expand Down
6 changes: 0 additions & 6 deletions library/ecdsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,7 @@
#include "mbedtls/hmac_drbg.h"
#endif

#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdlib.h>
#define mbedtls_calloc calloc
#define mbedtls_free free
#endif

#include "mbedtls/platform_util.h"
#include "mbedtls/error.h"
Expand Down
5 changes: 0 additions & 5 deletions library/ecjpake.c
Original file line number Diff line number Diff line change
Expand Up @@ -794,12 +794,7 @@ int mbedtls_ecjpake_derive_secret( mbedtls_ecjpake_context *ctx,

#if defined(MBEDTLS_SELF_TEST)

#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdio.h>
#define mbedtls_printf printf
#endif

#if !defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) || \
!defined(MBEDTLS_SHA256_C)
Expand Down
8 changes: 0 additions & 8 deletions library/ecp.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,7 @@
#define ECP_VALIDATE( cond ) \
MBEDTLS_INTERNAL_VALIDATE( cond )

#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdlib.h>
#include <stdio.h>
#define mbedtls_printf printf
#define mbedtls_calloc calloc
#define mbedtls_free free
#endif

#include "mbedtls/ecp_internal.h"

Expand Down
9 changes: 0 additions & 9 deletions library/entropy.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,9 @@
#include <stdio.h>
#endif

#if defined(MBEDTLS_ENTROPY_NV_SEED)
#include "mbedtls/platform.h"
#endif

#if defined(MBEDTLS_SELF_TEST)
#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 */

#if defined(MBEDTLS_HAVEGE_C)
#include "mbedtls/havege.h"
Expand Down
2 changes: 0 additions & 2 deletions library/entropy_poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@
#if defined(MBEDTLS_HAVEGE_C)
#include "mbedtls/havege.h"
#endif
#if defined(MBEDTLS_ENTROPY_NV_SEED)
#include "mbedtls/platform.h"
#endif

#if !defined(MBEDTLS_NO_PLATFORM_ENTROPY)

Expand Down
4 changes: 0 additions & 4 deletions library/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@

#if defined(MBEDTLS_ERROR_C)

#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#define mbedtls_snprintf snprintf
#endif

#include <stdio.h>
#include <string.h>
Expand Down
Loading

0 comments on commit 279188f

Please sign in to comment.