1 /* 2 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 3 * Copyright (c) 2017 Intel Corporation. 4 * Copyright (c) 2018 Nordic Semiconductor ASA 5 * 6 * SPDX-License-Identifier: Apache-2.0 7 * 8 * Generic configuration for TLS, manageable by Kconfig. 9 */ 10 11 #ifndef MBEDTLS_CONFIG_H 12 #define MBEDTLS_CONFIG_H 13 14 /* System support */ 15 #define MBEDTLS_PLATFORM_C 16 #define MBEDTLS_PLATFORM_MEMORY 17 #define MBEDTLS_MEMORY_BUFFER_ALLOC_C 18 #define MBEDTLS_MEMORY_ALIGN_MULTIPLE (sizeof(void *)) 19 #define MBEDTLS_PLATFORM_EXIT_ALT 20 #define MBEDTLS_NO_PLATFORM_ENTROPY 21 22 #if defined(CONFIG_MBEDTLS_ZEROIZE_ALT) 23 #define MBEDTLS_PLATFORM_ZEROIZE_ALT 24 #endif 25 26 #if defined(CONFIG_MBEDTLS_ZEPHYR_ENTROPY) 27 #define MBEDTLS_ENTROPY_HARDWARE_ALT 28 #else 29 #define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES 30 #endif 31 32 #if defined(CONFIG_MBEDTLS_HAVE_ASM) 33 #define MBEDTLS_HAVE_ASM 34 #endif 35 36 #if defined(CONFIG_MBEDTLS_LMS) 37 #define MBEDTLS_LMS_C 38 #define PSA_WANT_ALG_SHA_256 1 39 #endif 40 41 #if defined(CONFIG_MBEDTLS_HAVE_TIME_DATE) 42 #define MBEDTLS_HAVE_TIME 43 #define MBEDTLS_HAVE_TIME_DATE 44 #define MBEDTLS_PLATFORM_MS_TIME_ALT 45 #endif 46 47 #if defined(CONFIG_MBEDTLS_TEST) 48 #define MBEDTLS_SELF_TEST 49 #define MBEDTLS_DEBUG_C 50 #endif 51 52 /* mbedTLS feature support */ 53 54 /* Supported TLS versions */ 55 #if defined(CONFIG_MBEDTLS_TLS_VERSION_1_0) 56 #define MBEDTLS_SSL_PROTO_TLS1 57 #endif 58 59 #if defined(CONFIG_MBEDTLS_TLS_VERSION_1_1) 60 #define MBEDTLS_SSL_PROTO_TLS1_1 61 #endif 62 63 #if defined(CONFIG_MBEDTLS_TLS_VERSION_1_2) 64 #define MBEDTLS_SSL_PROTO_TLS1_2 65 #endif 66 67 68 #if defined(CONFIG_MBEDTLS_TLS_VERSION_1_0) || \ 69 defined(CONFIG_MBEDTLS_TLS_VERSION_1_1) || \ 70 defined(CONFIG_MBEDTLS_TLS_VERSION_1_2) 71 72 /* Modules required for TLS */ 73 #define MBEDTLS_SSL_TLS_C 74 #define MBEDTLS_SSL_SRV_C 75 #define MBEDTLS_SSL_CLI_C 76 #define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH 77 78 #endif 79 80 #if defined(CONFIG_MBEDTLS_DTLS) 81 #define MBEDTLS_SSL_PROTO_DTLS 82 #define MBEDTLS_SSL_DTLS_ANTI_REPLAY 83 #define MBEDTLS_SSL_DTLS_HELLO_VERIFY 84 #define MBEDTLS_SSL_COOKIE_C 85 #endif 86 87 /* Supported key exchange methods */ 88 89 #if defined(CONFIG_MBEDTLS_KEY_EXCHANGE_PSK_ENABLED) 90 #define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED 91 #endif 92 93 #if defined(CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) 94 #define MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED 95 #endif 96 97 #if defined(CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED) 98 #define MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED 99 #endif 100 101 #if defined(CONFIG_MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) 102 #define MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED 103 #endif 104 105 #if defined(CONFIG_MBEDTLS_PSK_MAX_LEN) 106 #define MBEDTLS_PSK_MAX_LEN CONFIG_MBEDTLS_PSK_MAX_LEN 107 #endif 108 109 #if defined(CONFIG_MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) 110 #define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED 111 #endif 112 113 #if defined(CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) 114 #define MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED 115 #endif 116 117 #if defined(CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) 118 #define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED 119 #endif 120 121 #if defined(CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) 122 #define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED 123 #endif 124 125 #if defined(CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) 126 #define MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED 127 #endif 128 129 #if defined(CONFIG_MBEDTLS_ECDSA_DETERMINISTIC) 130 #define MBEDTLS_ECDSA_DETERMINISTIC 131 #endif 132 133 #if defined(CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) 134 #define MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED 135 #endif 136 137 #if defined(CONFIG_MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) 138 #define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED 139 #endif 140 141 /* Supported cipher modes */ 142 143 #if defined(CONFIG_MBEDTLS_CIPHER_AES_ENABLED) 144 #define MBEDTLS_AES_C 145 #endif 146 147 #if defined(CONFIG_MBEDTLS_AES_ROM_TABLES) 148 #define MBEDTLS_AES_ROM_TABLES 149 #endif 150 151 #if defined(CONFIG_MBEDTLS_AES_FEWER_TABLES) 152 #define MBEDTLS_AES_FEWER_TABLES 153 #endif 154 155 #if defined(CONFIG_MBEDTLS_CIPHER_CAMELLIA_ENABLED) 156 #define MBEDTLS_CAMELLIA_C 157 #endif 158 159 #if defined(CONFIG_MBEDTLS_CIPHER_DES_ENABLED) 160 #define MBEDTLS_DES_C 161 #endif 162 163 #if defined(CONFIG_MBEDTLS_CIPHER_ARC4_ENABLED) 164 #define MBEDTLS_ARC4_C 165 #endif 166 167 #if defined(CONFIG_MBEDTLS_CIPHER_CHACHA20_ENABLED) 168 #define MBEDTLS_CHACHA20_C 169 #endif 170 171 #if defined(CONFIG_MBEDTLS_CIPHER_BLOWFISH_ENABLED) 172 #define MBEDTLS_BLOWFISH_C 173 #endif 174 175 #if defined(CONFIG_MBEDTLS_CIPHER_CCM_ENABLED) 176 #define MBEDTLS_CCM_C 177 #endif 178 179 #if defined(CONFIG_MBEDTLS_CIPHER_GCM_ENABLED) 180 #define MBEDTLS_GCM_C 181 #endif 182 183 #if defined(CONFIG_MBEDTLS_CIPHER_MODE_XTS_ENABLED) 184 #define MBEDTLS_CIPHER_MODE_XTS 185 #endif 186 187 #if defined(CONFIG_MBEDTLS_CIPHER_MODE_CBC_ENABLED) 188 #define MBEDTLS_CIPHER_MODE_CBC 189 #endif 190 191 #if defined(CONFIG_MBEDTLS_CIPHER_MODE_CTR_ENABLED) 192 #define MBEDTLS_CIPHER_MODE_CTR 193 #endif 194 195 /* Supported elliptic curve libraries */ 196 197 #if defined(CONFIG_MBEDTLS_ECDH_C) 198 #define MBEDTLS_ECDH_C 199 #endif 200 201 #if defined(CONFIG_MBEDTLS_ECDSA_C) 202 #define MBEDTLS_ECDSA_C 203 #endif 204 205 #if defined(CONFIG_MBEDTLS_ECJPAKE_C) 206 #define MBEDTLS_ECJPAKE_C 207 #endif 208 209 #if defined(CONFIG_MBEDTLS_ECP_C) 210 #define MBEDTLS_ECP_C 211 #endif 212 213 /* Supported elliptic curves */ 214 215 #if defined(CONFIG_MBEDTLS_ECP_DP_SECP192R1_ENABLED) 216 #define MBEDTLS_ECP_DP_SECP192R1_ENABLED 217 #endif 218 219 #if defined(CONFIG_MBEDTLS_ECP_DP_SECP224R1_ENABLED) 220 #define MBEDTLS_ECP_DP_SECP224R1_ENABLED 221 #endif 222 223 #if defined(CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED) 224 #define MBEDTLS_ECP_DP_SECP256R1_ENABLED 225 #endif 226 227 #if defined(CONFIG_MBEDTLS_ECP_DP_SECP384R1_ENABLED) 228 #define MBEDTLS_ECP_DP_SECP384R1_ENABLED 229 #endif 230 231 #if defined(CONFIG_MBEDTLS_ECP_DP_SECP521R1_ENABLED) 232 #define MBEDTLS_ECP_DP_SECP521R1_ENABLED 233 #endif 234 235 #if defined(CONFIG_MBEDTLS_ECP_DP_SECP192K1_ENABLED) 236 #define MBEDTLS_ECP_DP_SECP192K1_ENABLED 237 #endif 238 239 #if defined(CONFIG_MBEDTLS_ECP_DP_SECP224K1_ENABLED) 240 #define MBEDTLS_ECP_DP_SECP224K1_ENABLED 241 #endif 242 243 #if defined(CONFIG_MBEDTLS_ECP_DP_SECP256K1_ENABLED) 244 #define MBEDTLS_ECP_DP_SECP256K1_ENABLED 245 #endif 246 247 #if defined(CONFIG_MBEDTLS_ECP_DP_BP256R1_ENABLED) 248 #define MBEDTLS_ECP_DP_BP256R1_ENABLED 249 #endif 250 251 #if defined(CONFIG_MBEDTLS_ECP_DP_BP384R1_ENABLED) 252 #define MBEDTLS_ECP_DP_BP384R1_ENABLED 253 #endif 254 255 #if defined(CONFIG_MBEDTLS_ECP_DP_BP512R1_ENABLED) 256 #define MBEDTLS_ECP_DP_BP512R1_ENABLED 257 #endif 258 259 #if defined(CONFIG_MBEDTLS_ECP_DP_CURVE25519_ENABLED) 260 #define MBEDTLS_ECP_DP_CURVE25519_ENABLED 261 #endif 262 263 #if defined(CONFIG_MBEDTLS_ECP_DP_CURVE448_ENABLED) 264 #define MBEDTLS_ECP_DP_CURVE448_ENABLED 265 #endif 266 267 #if defined(CONFIG_MBEDTLS_ECP_NIST_OPTIM) 268 #define MBEDTLS_ECP_NIST_OPTIM 269 #endif 270 271 /* Supported message authentication methods */ 272 273 #if defined(CONFIG_MBEDTLS_MAC_MD4_ENABLED) 274 #define MBEDTLS_MD4_C 275 #endif 276 277 #if defined(CONFIG_MBEDTLS_MAC_MD5_ENABLED) 278 #define MBEDTLS_MD5_C 279 #endif 280 281 #if defined(CONFIG_MBEDTLS_MAC_SHA1_ENABLED) 282 #define MBEDTLS_SHA1_C 283 #endif 284 285 #if defined(CONFIG_MBEDTLS_MAC_SHA256_ENABLED) || \ 286 defined(CONFIG_MBEDTLS_HASH_SHA256_ENABLED) 287 #define MBEDTLS_SHA224_C 288 #define MBEDTLS_SHA256_C 289 #endif 290 291 #if defined(CONFIG_MBEDTLS_SHA256_SMALLER) 292 #define MBEDTLS_SHA256_SMALLER 293 #endif 294 295 #if defined(CONFIG_MBEDTLS_MAC_SHA384_ENABLED) || \ 296 defined(CONFIG_MBEDTLS_HASH_SHA384_ENABLED) 297 #define MBEDTLS_SHA384_C 298 #endif 299 300 #if defined(CONFIG_MBEDTLS_MAC_SHA512_ENABLED) || \ 301 defined(CONFIG_MBEDTLS_HASH_SHA512_ENABLED) 302 #define MBEDTLS_SHA512_C 303 #endif 304 305 #if defined(CONFIG_MBEDTLS_MAC_POLY1305_ENABLED) 306 #define MBEDTLS_POLY1305_C 307 #endif 308 309 #if defined(CONFIG_MBEDTLS_MAC_CMAC_ENABLED) 310 #define MBEDTLS_CMAC_C 311 #endif 312 313 /* mbedTLS modules */ 314 #if defined(CONFIG_MBEDTLS_CTR_DRBG_ENABLED) 315 #define MBEDTLS_CTR_DRBG_C 316 #endif 317 318 #if defined(CONFIG_MBEDTLS_HMAC_DRBG_ENABLED) 319 #define MBEDTLS_HMAC_DRBG_C 320 #endif 321 322 #if defined(CONFIG_MBEDTLS_DEBUG) 323 #define MBEDTLS_ERROR_C 324 #define MBEDTLS_DEBUG_C 325 #define MBEDTLS_SSL_DEBUG_ALL 326 #define MBEDTLS_SSL_ALL_ALERT_MESSAGES 327 #endif 328 329 #if defined(CONFIG_MBEDTLS_MEMORY_DEBUG) 330 #define MBEDTLS_MEMORY_DEBUG 331 #endif 332 333 #if defined(CONFIG_MBEDTLS_CHACHAPOLY_AEAD_ENABLED) 334 #define MBEDTLS_CHACHAPOLY_C 335 #endif 336 337 #if defined(CONFIG_MBEDTLS_GENPRIME_ENABLED) 338 #define MBEDTLS_GENPRIME 339 #endif 340 341 #if defined(CONFIG_MBEDTLS_ENTROPY_ENABLED) 342 #define MBEDTLS_ENTROPY_C 343 #endif 344 345 #if defined(CONFIG_MBEDTLS_SSL_EXPORT_KEYS) 346 #define MBEDTLS_SSL_EXPORT_KEYS 347 #endif 348 349 #if defined(CONFIG_MBEDTLS_SSL_ALPN) 350 #define MBEDTLS_SSL_ALPN 351 #endif 352 353 #if defined(CONFIG_MBEDTLS_CIPHER) 354 #define MBEDTLS_CIPHER_C 355 #endif 356 357 #if defined(CONFIG_MBEDTLS_MD) 358 #define MBEDTLS_MD_C 359 #endif 360 361 /* Automatic dependencies */ 362 363 #if defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) || \ 364 defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) 365 #define MBEDTLS_DHM_C 366 #endif 367 368 #if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) || \ 369 defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || \ 370 defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \ 371 defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) 372 #define MBEDTLS_RSA_C 373 #endif 374 375 #if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) || \ 376 defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || \ 377 defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \ 378 defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) 379 #define MBEDTLS_PKCS1_V15 380 #define MBEDTLS_PKCS1_V21 381 #endif 382 383 #if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) || \ 384 defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || \ 385 defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \ 386 defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \ 387 defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \ 388 defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) || \ 389 defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) 390 #define MBEDTLS_X509_CRT_PARSE_C 391 #endif 392 393 #if defined (CONFIG_MBEDTLS_PEM_CERTIFICATE_FORMAT) && \ 394 defined(MBEDTLS_X509_CRT_PARSE_C) 395 #define MBEDTLS_PEM_PARSE_C 396 #define MBEDTLS_BASE64_C 397 #endif 398 399 #if defined(MBEDTLS_X509_CRT_PARSE_C) 400 #define MBEDTLS_X509_USE_C 401 #endif 402 403 #if defined(MBEDTLS_DHM_C) || \ 404 defined(MBEDTLS_ECP_C) || \ 405 defined(MBEDTLS_RSA_C) || \ 406 defined(MBEDTLS_X509_USE_C) || \ 407 defined(MBEDTLS_GENPRIME) 408 #define MBEDTLS_BIGNUM_C 409 #endif 410 411 #if defined(MBEDTLS_RSA_C) || \ 412 defined(MBEDTLS_X509_USE_C) 413 #define MBEDTLS_OID_C 414 #endif 415 416 #if defined(MBEDTLS_X509_USE_C) 417 #define MBEDTLS_PK_PARSE_C 418 #endif 419 420 #if defined(CONFIG_MBEDTLS_PK_WRITE_C) 421 #define MBEDTLS_PK_WRITE_C 422 #endif 423 424 #if defined(MBEDTLS_PK_PARSE_C) || defined(MBEDTLS_PK_WRITE_C) 425 #define MBEDTLS_PK_C 426 #endif 427 428 #if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_ECDSA_C) 429 #define MBEDTLS_ASN1_PARSE_C 430 #endif 431 432 #if defined(MBEDTLS_ECDSA_C) || defined(MBEDTLS_PK_WRITE_C) 433 #define MBEDTLS_ASN1_WRITE_C 434 #endif 435 436 #if defined(CONFIG_MBEDTLS_PKCS5_C) 437 #define MBEDTLS_PKCS5_C 438 #endif 439 440 #define MBEDTLS_SSL_IN_CONTENT_LEN CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN 441 #define MBEDTLS_SSL_OUT_CONTENT_LEN CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN 442 443 /* Enable OpenThread optimizations. */ 444 #if defined(CONFIG_MBEDTLS_OPENTHREAD_OPTIMIZATIONS_ENABLED) 445 #define MBEDTLS_MPI_WINDOW_SIZE 1 /**< Maximum windows size used. */ 446 #define MBEDTLS_MPI_MAX_SIZE 32 /**< Maximum number of bytes for usable MPIs. */ 447 #define MBEDTLS_ECP_WINDOW_SIZE 2 /**< Maximum window size used */ 448 #define MBEDTLS_ECP_FIXED_POINT_OPTIM 0 /**< Enable fixed-point speed-up */ 449 #define MBEDTLS_ENTROPY_MAX_SOURCES 1 /**< Maximum number of sources supported */ 450 #endif 451 452 #if defined(CONFIG_MBEDTLS_SERVER_NAME_INDICATION) && \ 453 defined(MBEDTLS_X509_CRT_PARSE_C) 454 #define MBEDTLS_SSL_SERVER_NAME_INDICATION 455 #endif 456 457 #if defined(CONFIG_MBEDTLS_SSL_CACHE_C) 458 #define MBEDTLS_SSL_CACHE_C 459 #define MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT CONFIG_MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT 460 #define MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES CONFIG_MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES 461 #endif 462 463 #if defined(CONFIG_MBEDTLS_SSL_EXTENDED_MASTER_SECRET) 464 #define MBEDTLS_SSL_EXTENDED_MASTER_SECRET 465 #endif 466 467 #if defined(CONFIG_MBEDTLS_PSA_CRYPTO_C) 468 #define MBEDTLS_PSA_CRYPTO_C 469 #define MBEDTLS_USE_PSA_CRYPTO 470 471 #if defined(CONFIG_ARCH_POSIX) 472 #define MBEDTLS_PSA_KEY_SLOT_COUNT 64 473 #define MBEDTLS_PSA_CRYPTO_STORAGE_C 474 #define MBEDTLS_PSA_ITS_FILE_C 475 #define MBEDTLS_FS_IO 476 #endif 477 478 #endif 479 480 #if defined(CONFIG_MBEDTLS_TLS_VERSION_1_2) && defined(CONFIG_MBEDTLS_PSA_CRYPTO_C) 481 #define MBEDTLS_SSL_ENCRYPT_THEN_MAC 482 #endif 483 484 #if defined(CONFIG_MBEDTLS_SSL_DTLS_CONNECTION_ID) 485 #define MBEDTLS_SSL_DTLS_CONNECTION_ID 486 #endif 487 488 /* User config file */ 489 490 #if defined(CONFIG_MBEDTLS_USER_CONFIG_FILE) 491 #include CONFIG_MBEDTLS_USER_CONFIG_FILE 492 #endif 493 494 #endif /* MBEDTLS_CONFIG_H */ 495