blob: 603c7dd200d24a8c471bdbf89e7fd52151ea55c0 [file] [log] [blame]
Gilles Peskinec0a562c2025-07-25 17:07:13 +02001/* -*-c-*-
Bence Szépkútibb0cfeb2021-05-28 09:42:25 +02002 * Query Mbed TLS compile time configurations from mbedtls_config.h
Andres Amaya Garcia88121a92018-10-16 22:00:13 +01003 *
Bence Szépkúti1e148272020-08-07 13:07:28 +02004 * Copyright The Mbed TLS Contributors
Dave Rodgman16799db2023-11-02 19:47:20 +00005 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Andres Amaya Garcia88121a92018-10-16 22:00:13 +01006 */
7
Bence Szépkútic662b362021-05-27 11:25:03 +02008#include "mbedtls/build_info.h"
Andres Amaya Garcia88121a92018-10-16 22:00:13 +01009
Gilles Peskinec772b182021-01-12 15:55:10 +010010#include "query_config.h"
11
Andres Amaya Garcia88121a92018-10-16 22:00:13 +010012#include "mbedtls/platform.h"
Andres Amaya Garcia88121a92018-10-16 22:00:13 +010013#include <string.h>
14
Gilles Peskine409c6882025-07-26 00:15:21 +020015/* Work around https://github.com/Mbed-TLS/TF-PSA-Crypto/issues/393 */
16#if defined(MBEDTLS_HAVE_TIME)
17#include <mbedtls/platform_time.h>
18#endif
19
Gilles Peskinebb8bafa2025-07-26 00:23:05 +020020/* *INDENT-OFF* */
Gilles Peskinec0a562c2025-07-25 17:07:13 +020021INCLUDE_HEADERS
Gilles Peskinebb8bafa2025-07-26 00:23:05 +020022/* *INDENT-ON* */
Gilles Peskinec0a562c2025-07-25 17:07:13 +020023
Andres Amaya Garcia27b33722018-12-05 10:47:31 +000024/*
25 * Helper macros to convert a macro or its expansion into a string
26 * WARNING: This does not work for expanding function-like macros. However,
27 * Mbed TLS does not currently have configuration options used in this fashion.
28 */
Andres Amaya Garcia88121a92018-10-16 22:00:13 +010029#define MACRO_EXPANSION_TO_STR(macro) MACRO_NAME_TO_STR(macro)
Andres Amaya Garcia27b33722018-12-05 10:47:31 +000030#define MACRO_NAME_TO_STR(macro) \
Gilles Peskine449bd832023-01-11 14:50:10 +010031 mbedtls_printf("%s", strlen( #macro "") > 0 ? #macro "\n" : "")
Andres Amaya Garcia88121a92018-10-16 22:00:13 +010032
Jerry Yu2e8b0012021-12-10 20:29:02 +080033#define STRINGIFY(macro) #macro
Jerry Yu84e63a72021-12-06 13:40:37 +080034#define OUTPUT_MACRO_NAME_VALUE(macro) mbedtls_printf( #macro "%s\n", \
Gilles Peskine449bd832023-01-11 14:50:10 +010035 (STRINGIFY(macro) "")[0] != 0 ? "=" STRINGIFY( \
36 macro) : "")
Jerry Yu84e63a72021-12-06 13:40:37 +080037
Andres Amaya Garcia17c53c52019-01-24 09:55:14 +000038#if defined(_MSC_VER)
39/*
40 * Visual Studio throws the warning 4003 because many Mbed TLS feature macros
41 * are defined empty. This means that from the preprocessor's point of view
42 * the macro MBEDTLS_EXPANSION_TO_STR is being invoked without arguments as
43 * some macros expand to nothing. We suppress that specific warning to get a
44 * clean build and to ensure that tests treating warnings as errors do not
45 * fail.
46 */
47#pragma warning(push)
48#pragma warning(disable:4003)
49#endif /* _MSC_VER */
50
Gilles Peskine449bd832023-01-11 14:50:10 +010051int query_config(const char *config)
Andres Amaya Garcia88121a92018-10-16 22:00:13 +010052{
Gilles Peskine449bd832023-01-11 14:50:10 +010053 CHECK_CONFIG /* If the symbol is not found, return an error */
54 return 1;
Andres Amaya Garcia88121a92018-10-16 22:00:13 +010055}
Andres Amaya Garcia17c53c52019-01-24 09:55:14 +000056
Gilles Peskine449bd832023-01-11 14:50:10 +010057void list_config(void)
Jerry Yu84e63a72021-12-06 13:40:37 +080058{
59 LIST_CONFIG
60}
Andres Amaya Garcia17c53c52019-01-24 09:55:14 +000061#if defined(_MSC_VER)
62#pragma warning(pop)
63#endif /* _MSC_VER */