| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 1 | /* | 
| 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 |  | 
| Andres Amaya Garcia | c28da7e | 2018-10-29 18:58:41 +0000 | [diff] [blame] | 14 | /* | 
|  | 15 | * Include all the headers with public APIs in case they define a macro to its | 
| Tom Cosgrove | b839c54 | 2022-07-26 11:54:08 +0100 | [diff] [blame] | 16 | * default value when that configuration is not set in mbedtls_config.h, or | 
|  | 17 | * for PSA_WANT macros, in case they're auto-defined based on mbedtls_config.h | 
|  | 18 | * rather than defined directly in crypto_config.h. | 
| Andres Amaya Garcia | c28da7e | 2018-10-29 18:58:41 +0000 | [diff] [blame] | 19 | */ | 
| Tom Cosgrove | b839c54 | 2022-07-26 11:54:08 +0100 | [diff] [blame] | 20 | #include "psa/crypto.h" | 
|  | 21 |  | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 22 | #include "mbedtls/aes.h" | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 23 | #include "mbedtls/aria.h" | 
|  | 24 | #include "mbedtls/asn1.h" | 
|  | 25 | #include "mbedtls/asn1write.h" | 
|  | 26 | #include "mbedtls/base64.h" | 
|  | 27 | #include "mbedtls/bignum.h" | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 28 | #include "mbedtls/camellia.h" | 
|  | 29 | #include "mbedtls/ccm.h" | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 30 | #include "mbedtls/chacha20.h" | 
|  | 31 | #include "mbedtls/chachapoly.h" | 
|  | 32 | #include "mbedtls/cipher.h" | 
|  | 33 | #include "mbedtls/cmac.h" | 
|  | 34 | #include "mbedtls/ctr_drbg.h" | 
|  | 35 | #include "mbedtls/debug.h" | 
|  | 36 | #include "mbedtls/des.h" | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 37 | #include "mbedtls/ecdh.h" | 
|  | 38 | #include "mbedtls/ecdsa.h" | 
|  | 39 | #include "mbedtls/ecjpake.h" | 
|  | 40 | #include "mbedtls/ecp.h" | 
|  | 41 | #include "mbedtls/entropy.h" | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 42 | #include "mbedtls/error.h" | 
|  | 43 | #include "mbedtls/gcm.h" | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 44 | #include "mbedtls/hkdf.h" | 
|  | 45 | #include "mbedtls/hmac_drbg.h" | 
|  | 46 | #include "mbedtls/md.h" | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 47 | #include "mbedtls/md5.h" | 
|  | 48 | #include "mbedtls/memory_buffer_alloc.h" | 
|  | 49 | #include "mbedtls/net_sockets.h" | 
|  | 50 | #include "mbedtls/nist_kw.h" | 
|  | 51 | #include "mbedtls/oid.h" | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 52 | #include "mbedtls/pem.h" | 
|  | 53 | #include "mbedtls/pk.h" | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 54 | #include "mbedtls/pkcs12.h" | 
|  | 55 | #include "mbedtls/pkcs5.h" | 
| Daniel Axtens | f071024 | 2020-05-28 11:43:41 +1000 | [diff] [blame] | 56 | #if defined(MBEDTLS_HAVE_TIME) | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 57 | #include "mbedtls/platform_time.h" | 
| Daniel Axtens | f071024 | 2020-05-28 11:43:41 +1000 | [diff] [blame] | 58 | #endif | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 59 | #include "mbedtls/platform_util.h" | 
|  | 60 | #include "mbedtls/poly1305.h" | 
|  | 61 | #include "mbedtls/ripemd160.h" | 
|  | 62 | #include "mbedtls/rsa.h" | 
|  | 63 | #include "mbedtls/sha1.h" | 
|  | 64 | #include "mbedtls/sha256.h" | 
|  | 65 | #include "mbedtls/sha512.h" | 
|  | 66 | #include "mbedtls/ssl.h" | 
|  | 67 | #include "mbedtls/ssl_cache.h" | 
|  | 68 | #include "mbedtls/ssl_ciphersuites.h" | 
|  | 69 | #include "mbedtls/ssl_cookie.h" | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 70 | #include "mbedtls/ssl_ticket.h" | 
|  | 71 | #include "mbedtls/threading.h" | 
|  | 72 | #include "mbedtls/timing.h" | 
|  | 73 | #include "mbedtls/version.h" | 
|  | 74 | #include "mbedtls/x509.h" | 
|  | 75 | #include "mbedtls/x509_crl.h" | 
|  | 76 | #include "mbedtls/x509_crt.h" | 
|  | 77 | #include "mbedtls/x509_csr.h" | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 78 |  | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 79 | #include <string.h> | 
|  | 80 |  | 
| Andres Amaya Garcia | 27b3372 | 2018-12-05 10:47:31 +0000 | [diff] [blame] | 81 | /* | 
|  | 82 | * Helper macros to convert a macro or its expansion into a string | 
|  | 83 | * WARNING: This does not work for expanding function-like macros. However, | 
|  | 84 | * Mbed TLS does not currently have configuration options used in this fashion. | 
|  | 85 | */ | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 86 | #define MACRO_EXPANSION_TO_STR(macro)   MACRO_NAME_TO_STR(macro) | 
| Andres Amaya Garcia | 27b3372 | 2018-12-05 10:47:31 +0000 | [diff] [blame] | 87 | #define MACRO_NAME_TO_STR(macro)                                        \ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 88 | mbedtls_printf("%s", strlen( #macro "") > 0 ? #macro "\n" : "") | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 89 |  | 
| Jerry Yu | 2e8b001 | 2021-12-10 20:29:02 +0800 | [diff] [blame] | 90 | #define STRINGIFY(macro)  #macro | 
| Jerry Yu | 84e63a7 | 2021-12-06 13:40:37 +0800 | [diff] [blame] | 91 | #define OUTPUT_MACRO_NAME_VALUE(macro) mbedtls_printf( #macro "%s\n",   \ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 92 | (STRINGIFY(macro) "")[0] != 0 ? "=" STRINGIFY( \ | 
|  | 93 | macro) : "") | 
| Jerry Yu | 84e63a7 | 2021-12-06 13:40:37 +0800 | [diff] [blame] | 94 |  | 
| Andres Amaya Garcia | 17c53c5 | 2019-01-24 09:55:14 +0000 | [diff] [blame] | 95 | #if defined(_MSC_VER) | 
|  | 96 | /* | 
|  | 97 | * Visual Studio throws the warning 4003 because many Mbed TLS feature macros | 
|  | 98 | * are defined empty. This means that from the preprocessor's point of view | 
|  | 99 | * the macro MBEDTLS_EXPANSION_TO_STR is being invoked without arguments as | 
|  | 100 | * some macros expand to nothing. We suppress that specific warning to get a | 
|  | 101 | * clean build and to ensure that tests treating warnings as errors do not | 
|  | 102 | * fail. | 
|  | 103 | */ | 
|  | 104 | #pragma warning(push) | 
|  | 105 | #pragma warning(disable:4003) | 
|  | 106 | #endif /* _MSC_VER */ | 
|  | 107 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 108 | int query_config(const char *config) | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 109 | { | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 110 | CHECK_CONFIG /* If the symbol is not found, return an error */ | 
|  | 111 | return 1; | 
| Andres Amaya Garcia | 88121a9 | 2018-10-16 22:00:13 +0100 | [diff] [blame] | 112 | } | 
| Andres Amaya Garcia | 17c53c5 | 2019-01-24 09:55:14 +0000 | [diff] [blame] | 113 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 114 | void list_config(void) | 
| Jerry Yu | 84e63a7 | 2021-12-06 13:40:37 +0800 | [diff] [blame] | 115 | { | 
|  | 116 | LIST_CONFIG | 
|  | 117 | } | 
| Andres Amaya Garcia | 17c53c5 | 2019-01-24 09:55:14 +0000 | [diff] [blame] | 118 | #if defined(_MSC_VER) | 
|  | 119 | #pragma warning(pop) | 
|  | 120 | #endif /* _MSC_VER */ |