| Gilles Peskine | c0a562c | 2025-07-25 17:07:13 +0200 | [diff] [blame] | 1 | /* -*-c-*- | 
| Bence Szépkúti | bb0cfeb | 2021-05-28 09:42:25 +0200 | [diff] [blame] | 2 | *  Query Mbed TLS compile time configurations from mbedtls_config.h | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 3 | * | 
| Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 4 | *  Copyright The Mbed TLS Contributors | 
| Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame] | 5 | *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 6 | */ | 
|  | 7 |  | 
| Bence Szépkúti | c662b36 | 2021-05-27 11:25:03 +0200 | [diff] [blame] | 8 | #include "mbedtls/build_info.h" | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 9 |  | 
| Gilles Peskine | c772b18 | 2021-01-12 15:55:10 +0100 | [diff] [blame] | 10 | #include "query_config.h" | 
|  | 11 |  | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 12 | #include "mbedtls/platform.h" | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 13 | #include <string.h> | 
|  | 14 |  | 
| Gilles Peskine | 409c688 | 2025-07-26 00:15:21 +0200 | [diff] [blame] | 15 | /* 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 Peskine | bb8bafa | 2025-07-26 00:23:05 +0200 | [diff] [blame] | 20 | /* *INDENT-OFF* */ | 
| Gilles Peskine | c0a562c | 2025-07-25 17:07:13 +0200 | [diff] [blame] | 21 | INCLUDE_HEADERS | 
| Gilles Peskine | bb8bafa | 2025-07-26 00:23:05 +0200 | [diff] [blame] | 22 | /* *INDENT-ON* */ | 
| Gilles Peskine | c0a562c | 2025-07-25 17:07:13 +0200 | [diff] [blame] | 23 |  | 
| Andres Amaya Garcia | 27b3372 | 2018-12-05 10:47:31 +0000 | [diff] [blame] | 24 | /* | 
|  | 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 Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 29 | #define MACRO_EXPANSION_TO_STR(macro)   MACRO_NAME_TO_STR(macro) | 
| Andres Amaya Garcia | 27b3372 | 2018-12-05 10:47:31 +0000 | [diff] [blame] | 30 | #define MACRO_NAME_TO_STR(macro)                                        \ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 31 | mbedtls_printf("%s", strlen( #macro "") > 0 ? #macro "\n" : "") | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 32 |  | 
| Jerry Yu | 2e8b001 | 2021-12-10 20:29:02 +0800 | [diff] [blame] | 33 | #define STRINGIFY(macro)  #macro | 
| Jerry Yu | 84e63a7 | 2021-12-06 13:40:37 +0800 | [diff] [blame] | 34 | #define OUTPUT_MACRO_NAME_VALUE(macro) mbedtls_printf( #macro "%s\n",   \ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 35 | (STRINGIFY(macro) "")[0] != 0 ? "=" STRINGIFY( \ | 
|  | 36 | macro) : "") | 
| Jerry Yu | 84e63a7 | 2021-12-06 13:40:37 +0800 | [diff] [blame] | 37 |  | 
| Andres Amaya Garcia | 17c53c5 | 2019-01-24 09:55:14 +0000 | [diff] [blame] | 38 | #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 Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 51 | int query_config(const char *config) | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 52 | { | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 53 | CHECK_CONFIG /* If the symbol is not found, return an error */ | 
|  | 54 | return 1; | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 55 | } | 
| Andres Amaya Garcia | 17c53c5 | 2019-01-24 09:55:14 +0000 | [diff] [blame] | 56 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 57 | void list_config(void) | 
| Jerry Yu | 84e63a7 | 2021-12-06 13:40:37 +0800 | [diff] [blame] | 58 | { | 
|  | 59 | LIST_CONFIG | 
|  | 60 | } | 
| Andres Amaya Garcia | 17c53c5 | 2019-01-24 09:55:14 +0000 | [diff] [blame] | 61 | #if defined(_MSC_VER) | 
|  | 62 | #pragma warning(pop) | 
|  | 63 | #endif /* _MSC_VER */ |