blob: c60458b61b4251d19411886865608e3aca41b7bb [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 Peskinec0a562c2025-07-25 17:07:13 +020020INCLUDE_HEADERS
21
Andres Amaya Garcia27b33722018-12-05 10:47:31 +000022/*
23 * Helper macros to convert a macro or its expansion into a string
24 * WARNING: This does not work for expanding function-like macros. However,
25 * Mbed TLS does not currently have configuration options used in this fashion.
26 */
Andres Amaya Garcia88121a92018-10-16 22:00:13 +010027#define MACRO_EXPANSION_TO_STR(macro) MACRO_NAME_TO_STR(macro)
Andres Amaya Garcia27b33722018-12-05 10:47:31 +000028#define MACRO_NAME_TO_STR(macro) \
Gilles Peskine449bd832023-01-11 14:50:10 +010029 mbedtls_printf("%s", strlen( #macro "") > 0 ? #macro "\n" : "")
Andres Amaya Garcia88121a92018-10-16 22:00:13 +010030
Jerry Yu2e8b0012021-12-10 20:29:02 +080031#define STRINGIFY(macro) #macro
Jerry Yu84e63a72021-12-06 13:40:37 +080032#define OUTPUT_MACRO_NAME_VALUE(macro) mbedtls_printf( #macro "%s\n", \
Gilles Peskine449bd832023-01-11 14:50:10 +010033 (STRINGIFY(macro) "")[0] != 0 ? "=" STRINGIFY( \
34 macro) : "")
Jerry Yu84e63a72021-12-06 13:40:37 +080035
Andres Amaya Garcia17c53c52019-01-24 09:55:14 +000036#if defined(_MSC_VER)
37/*
38 * Visual Studio throws the warning 4003 because many Mbed TLS feature macros
39 * are defined empty. This means that from the preprocessor's point of view
40 * the macro MBEDTLS_EXPANSION_TO_STR is being invoked without arguments as
41 * some macros expand to nothing. We suppress that specific warning to get a
42 * clean build and to ensure that tests treating warnings as errors do not
43 * fail.
44 */
45#pragma warning(push)
46#pragma warning(disable:4003)
47#endif /* _MSC_VER */
48
Gilles Peskine449bd832023-01-11 14:50:10 +010049int query_config(const char *config)
Andres Amaya Garcia88121a92018-10-16 22:00:13 +010050{
Gilles Peskine449bd832023-01-11 14:50:10 +010051 CHECK_CONFIG /* If the symbol is not found, return an error */
52 return 1;
Andres Amaya Garcia88121a92018-10-16 22:00:13 +010053}
Andres Amaya Garcia17c53c52019-01-24 09:55:14 +000054
Gilles Peskine449bd832023-01-11 14:50:10 +010055void list_config(void)
Jerry Yu84e63a72021-12-06 13:40:37 +080056{
57 LIST_CONFIG
58}
Andres Amaya Garcia17c53c52019-01-24 09:55:14 +000059#if defined(_MSC_VER)
60#pragma warning(pop)
61#endif /* _MSC_VER */