1 /*
2  *  Copyright (c) 2018, The OpenThread Authors.
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *  1. Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  *  2. Redistributions in binary form must reproduce the above copyright
10  *     notice, this list of conditions and the following disclaimer in the
11  *     documentation and/or other materials provided with the distribution.
12  *  3. Neither the name of the copyright holder nor the
13  *     names of its contributors may be used to endorse or promote products
14  *     derived from this software without specific prior written permission.
15  *
16  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  *  POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 // Spans multiple lines to avoid being processed by unifdef
30 #ifndef \
31     MBEDTLS_CONFIG_H
32 #define MBEDTLS_CONFIG_H
33 
34 #include "openthread-core-config.h"
35 
36 #include <stdio.h>
37 #include <stdlib.h>
38 
39 #include <openthread/config.h>
40 #include <openthread/platform/logging.h>
41 #include <openthread/platform/memory.h>
42 
43 #define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf
44 
45 #define MBEDTLS_AES_C
46 #define MBEDTLS_AES_ROM_TABLES
47 #define MBEDTLS_ASN1_PARSE_C
48 #define MBEDTLS_ASN1_WRITE_C
49 #define MBEDTLS_BIGNUM_C
50 #define MBEDTLS_CCM_C
51 #define MBEDTLS_CIPHER_C
52 #define MBEDTLS_CMAC_C
53 #define MBEDTLS_CTR_DRBG_C
54 #define MBEDTLS_ECJPAKE_C
55 #define MBEDTLS_ECP_C
56 #define MBEDTLS_ECP_DP_SECP256R1_ENABLED
57 #define MBEDTLS_ECP_NIST_OPTIM
58 #define MBEDTLS_ENTROPY_C
59 #define MBEDTLS_HAVE_ASM
60 #define MBEDTLS_HMAC_DRBG_C
61 #define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
62 #define MBEDTLS_MD_C
63 #define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
64 #define MBEDTLS_NO_PLATFORM_ENTROPY
65 #define MBEDTLS_PK_C
66 #define MBEDTLS_PK_PARSE_C
67 #define MBEDTLS_PLATFORM_C
68 #define MBEDTLS_PLATFORM_MEMORY
69 #define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
70 #define MBEDTLS_SHA256_C
71 #define MBEDTLS_SHA256_SMALLER
72 #define MBEDTLS_SSL_CLI_C
73 #define MBEDTLS_SSL_DTLS_ANTI_REPLAY
74 #define MBEDTLS_SSL_DTLS_HELLO_VERIFY
75 #define MBEDTLS_SSL_EXPORT_KEYS
76 #define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
77 #define MBEDTLS_SSL_PROTO_TLS1_2
78 #define MBEDTLS_SSL_PROTO_DTLS
79 #define MBEDTLS_SSL_TLS_C
80 
81 #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE || OPENTHREAD_CONFIG_COMMISSIONER_ENABLE || OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE
82 #define MBEDTLS_SSL_COOKIE_C
83 #define MBEDTLS_SSL_SRV_C
84 #endif
85 
86 #if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE
87 #define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
88 #define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
89 #endif
90 
91 #ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
92 #define MBEDTLS_BASE64_C
93 #define MBEDTLS_ECDH_C
94 #define MBEDTLS_ECDSA_C
95 #define MBEDTLS_OID_C
96 #define MBEDTLS_PEM_PARSE_C
97 #define MBEDTLS_X509_USE_C
98 #define MBEDTLS_X509_CRT_PARSE_C
99 #endif
100 
101 #if OPENTHREAD_CONFIG_ECDSA_ENABLE
102 #define MBEDTLS_BASE64_C
103 #define MBEDTLS_ECDH_C
104 #define MBEDTLS_ECDSA_C
105 #define MBEDTLS_ECDSA_DETERMINISTIC
106 #define MBEDTLS_OID_C
107 #define MBEDTLS_PEM_PARSE_C
108 #define MBEDTLS_PK_WRITE_C
109 #endif
110 
111 #define MBEDTLS_MPI_WINDOW_SIZE            1 /**< Maximum windows size used. */
112 #define MBEDTLS_MPI_MAX_SIZE              32 /**< Maximum number of bytes for usable MPIs. */
113 #define MBEDTLS_ECP_MAX_BITS             256 /**< Maximum bit size of groups */
114 #define MBEDTLS_ECP_WINDOW_SIZE            2 /**< Maximum window size used */
115 #define MBEDTLS_ECP_FIXED_POINT_OPTIM      0 /**< Enable fixed-point speed-up */
116 #define MBEDTLS_ENTROPY_MAX_SOURCES        1 /**< Maximum number of sources supported */
117 
118 #if OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
119 #define MBEDTLS_PLATFORM_STD_CALLOC      otPlatCAlloc /**< Default allocator to use, can be undefined */
120 #define MBEDTLS_PLATFORM_STD_FREE        otPlatFree /**< Default free to use, can be undefined */
121 #else
122 #define MBEDTLS_MEMORY_BUFFER_ALLOC_C
123 #endif
124 
125 #if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE
126 #define MBEDTLS_SSL_MAX_CONTENT_LEN      900 /**< Maxium fragment length in bytes */
127 #else
128 #define MBEDTLS_SSL_MAX_CONTENT_LEN      768 /**< Maxium fragment length in bytes */
129 #endif
130 
131 #define MBEDTLS_SSL_CIPHERSUITES         MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8
132 
133 // Spans multiple lines to avoid being processed by unifdef
134 #if defined(\
135     MBEDTLS_USER_CONFIG_FILE)
136 #include MBEDTLS_USER_CONFIG_FILE
137 #endif
138 
139 #include "mbedtls/check_config.h"
140 
141 #endif /* MBEDTLS_CONFIG_H */
142