Apply Upstream code (2021-03-15)
[platform/upstream/connectedhomeip.git] / src / platform / K32W / k32w-chip-mbedtls-config.h
1 /*
2  *
3  *    Copyright (c) 2021 Project CHIP Authors
4  *
5  *    Licensed under the Apache License, Version 2.0 (the "License");
6  *    you may not use this file except in compliance with the License.
7  *    You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *    Unless required by applicable law or agreed to in writing, software
12  *    distributed under the License is distributed on an "AS IS" BASIS,
13  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *    See the License for the specific language governing permissions and
15  *    limitations under the License.
16  */
17
18 #ifndef K32W061_MBEDTLS_CONFIG_H
19 #define K32W061_MBEDTLS_CONFIG_H
20
21 #if defined(MBEDTLS_ECP_WINDOW_SIZE)
22 #undef MBEDTLS_ECP_WINDOW_SIZE
23 #define MBEDTLS_ECP_WINDOW_SIZE 4 /**< Maximum window size used */
24 #endif
25
26 #if defined(MBEDTLS_ECP_FIXED_POINT_OPTIM)
27 #undef MBEDTLS_ECP_FIXED_POINT_OPTIM
28 #define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 /**< Enable fixed-point speed-up */
29 #endif
30
31 /**
32  * \def MBEDTLS_AES_ALT
33  *
34  * Enable hardware acceleration for the AES block cipher
35  *
36  * See MBEDTLS_AES_C for more information.
37  */
38 #define MBEDTLS_AES_ALT
39
40 #if defined(MBEDTLS_AES_ALT)
41 /**************************** KSDK ********************************************/
42 #include "fsl_device_registers.h"
43
44 /* Enable LTC use in library if there is LTC on chip. */
45 #if defined(FSL_FEATURE_SOC_LTC_COUNT) && (FSL_FEATURE_SOC_LTC_COUNT > 0)
46 #include "fsl_ltc.h"
47
48 #define LTC_INSTANCE LTC0 /* LTC base register.*/
49
50 #if FSL_FEATURE_LTC_HAS_SHA
51 #define MBEDTLS_FREESCALE_LTC_SHA1   /* Enable use of LTC SHA.*/
52 #define MBEDTLS_FREESCALE_LTC_SHA256 /* Enable use of LTC SHA256.*/
53 #endif
54 #if defined(FSL_FEATURE_LTC_HAS_DES) && FSL_FEATURE_LTC_HAS_DES
55 #define MBEDTLS_FREESCALE_LTC_DES /* Enable use of LTC DES.*/
56 #endif
57 #define MBEDTLS_FREESCALE_LTC_AES /* Enable use of LTC AES.*/
58 #if defined(FSL_FEATURE_LTC_HAS_GCM) && FSL_FEATURE_LTC_HAS_GCM
59 #define MBEDTLS_FREESCALE_LTC_AES_GCM /* Enable use of LTC AES GCM.*/
60 #endif
61 #if defined(FSL_FEATURE_LTC_HAS_PKHA) && FSL_FEATURE_LTC_HAS_PKHA
62 #define MBEDTLS_FREESCALE_LTC_PKHA /* Enable use of LTC PKHA.*/
63 #define FREESCALE_PKHA_INT_MAX_BYTES 256
64 #endif
65 #endif
66
67 /* Enable MMCAU use in library if there is MMCAU on chip. */
68 #if defined(FSL_FEATURE_SOC_MMCAU_COUNT) && (FSL_FEATURE_SOC_MMCAU_COUNT > 0)
69 #include "fsl_mmcau.h"
70
71 #define MBEDTLS_FREESCALE_MMCAU_MD5    /* Enable use of MMCAU MD5.*/
72 #define MBEDTLS_FREESCALE_MMCAU_SHA1   /* Enable use of MMCAU SHA1.*/
73 #define MBEDTLS_FREESCALE_MMCAU_SHA256 /* Enable use of MMCAU SHA256.*/
74 #define MBEDTLS_FREESCALE_MMCAU_DES    /* Enable use of MMCAU DES, when LTC is disabled.*/
75 #define MBEDTLS_FREESCALE_MMCAU_AES    /* Enable use of MMCAU AES, when LTC is disabled.*/
76 #endif
77
78 /* Enable CAU3 use in library if there is CAU3 on chip. */
79 #if defined(FSL_FEATURE_SOC_CAU3_COUNT) && (FSL_FEATURE_SOC_CAU3_COUNT > 0)
80 #include "cau3_pkha.h"
81 #include "fsl_cau3.h"
82
83 #define MBEDTLS_CAU3_COMPLETION_SIGNAL CAU3_CC_CMD_EVT
84 #define MBEDTLS_SHA256_ALT_NO_224
85
86 #define MBEDTLS_FREESCALE_CAU3_AES    /* Enable use of CAU3 AES.*/
87 #define MBEDTLS_FREESCALE_CAU3_SHA256 /* Enable use of CAU3 SHA256.*/
88 #define MBEDTLS_FREESCALE_CAU3_PKHA   /* Enable use of CAU3 PKHA.*/
89 #define FREESCALE_PKHA_INT_MAX_BYTES 512
90 #endif
91
92 #if defined(MBEDTLS_FREESCALE_LTC_PKHA) || defined(MBEDTLS_FREESCALE_CAU3_PKHA)
93 /*
94  * This FREESCALE_PKHA_LONG_OPERANDS_ENABLE macro can be defined.
95  * In such a case both software and hardware algorithm for TFM is linked in.
96  * The decision for which algorithm is used is determined at runtime
97  * from size of inputs. If inputs and result can fit into LTC (see FREESCALE_PKHA_INT_MAX_BYTES)
98  * then we call hardware algorithm, otherwise we call software algorithm.
99  *
100  * Note that mbedTLS algorithms break modular operations unefficiently into two steps.
101  * First is normal operation, for example non-modular multiply, which can produce number
102  * with greater size than operands. Second is modular reduction.
103  * The implication of this is that if for example FREESCALE_PKHA_INT_MAX_BYTES is 256 (2048 bits),
104  * RSA-2048 still requires the FREESCALE_PKHA_LONG_OPERANDS_ENABLE macro to be defined,
105  * otherwise it fails at runtime.
106  */
107 //#define FREESCALE_PKHA_LONG_OPERANDS_ENABLE
108 #endif
109
110 /* Enable AES use in library if there is AES on chip. */
111 #if defined(FSL_FEATURE_SOC_AES_COUNT) && (FSL_FEATURE_SOC_AES_COUNT > 0)
112 #include "fsl_aes.h"
113
114 #define AES_INSTANCE AES0             /* AES base register.*/
115 #define MBEDTLS_FREESCALE_LPC_AES     /* Enable use of LPC AES.*/
116 #define MBEDTLS_FREESCALE_LPC_AES_GCM /* Enable use of LPC AES GCM.*/
117
118 #endif
119
120 /* Enable SHA use in library if there is SHA on chip. */
121 #if defined(FSL_FEATURE_SOC_SHA_COUNT) && (FSL_FEATURE_SOC_SHA_COUNT > 0)
122 #include "fsl_sha.h"
123
124 //#define SHA_INSTANCE SHA0            /* AES base register.*/
125 #define MBEDTLS_FREESCALE_LPC_SHA1 /* Enable use of LPC SHA.*/
126 //#define MBEDTLS_FREESCALE_LPC_SHA256 /* Enable use of LPC SHA256.*/
127
128 #endif
129
130 /* Define ALT MMCAU & LTC functions. Do not change it. */
131 #if defined(MBEDTLS_FREESCALE_MMCAU_DES) || defined(MBEDTLS_FREESCALE_LTC_DES)
132 #define MBEDTLS_DES_SETKEY_ENC_ALT
133 #define MBEDTLS_DES_SETKEY_DEC_ALT
134 #define MBEDTLS_DES_CRYPT_ECB_ALT
135 #define MBEDTLS_DES3_CRYPT_ECB_ALT
136 #endif
137 #if defined(MBEDTLS_FREESCALE_LTC_DES)
138 #define MBEDTLS_DES_CRYPT_CBC_ALT
139 #define MBEDTLS_DES3_CRYPT_CBC_ALT
140 #endif
141 #if defined(MBEDTLS_FREESCALE_LTC_AES) || defined(MBEDTLS_FREESCALE_MMCAU_AES) || defined(MBEDTLS_FREESCALE_LPC_AES) ||            \
142     defined(MBEDTLS_FREESCALE_CAU3_AES)
143 #define MBEDTLS_AES_SETKEY_ENC_ALT
144 #define MBEDTLS_AES_SETKEY_DEC_ALT
145 #define MBEDTLS_AES_ENCRYPT_ALT
146 #define MBEDTLS_AES_DECRYPT_ALT
147 #endif
148 #if defined(MBEDTLS_FREESCALE_LTC_AES)
149 #define MBEDTLS_AES_CRYPT_CBC_ALT
150 #define MBEDTLS_AES_CRYPT_CTR_ALT
151 #define MBEDTLS_CCM_CRYPT_ALT
152 #endif
153 #if defined(MBEDTLS_FREESCALE_LTC_AES_GCM) || defined(MBEDTLS_FREESCALE_LPC_AES_GCM)
154 #define MBEDTLS_GCM_CRYPT_ALT
155 #endif
156 #if defined(MBEDTLS_FREESCALE_LTC_PKHA) || defined(MBEDTLS_FREESCALE_CAU3_PKHA)
157 #define MBEDTLS_MPI_ADD_ABS_ALT
158 #define MBEDTLS_MPI_SUB_ABS_ALT
159 #define MBEDTLS_MPI_MUL_MPI_ALT
160 #define MBEDTLS_MPI_MOD_MPI_ALT
161 #define MBEDTLS_MPI_EXP_MOD_ALT
162 #define MBEDTLS_MPI_GCD_ALT
163 #define MBEDTLS_MPI_INV_MOD_ALT
164 #define MBEDTLS_MPI_IS_PRIME_ALT
165 #if defined(MBEDTLS_FREESCALE_LTC_PKHA)
166 #define MBEDTLS_ECP_MUL_COMB_ALT
167 #define MBEDTLS_ECP_ADD_ALT
168 #endif
169 #endif
170 #if defined(MBEDTLS_FREESCALE_LTC_SHA1) || defined(MBEDTLS_FREESCALE_LPC_SHA1)
171 #define MBEDTLS_SHA1_ALT
172 #endif
173 #if defined(MBEDTLS_FREESCALE_LTC_SHA256) || defined(MBEDTLS_FREESCALE_LPC_SHA256)
174 //#define MBEDTLS_SHA256_ALT
175 /*
176  * LPC SHA module does not support SHA-224.
177  *
178  * Since mbed TLS does not provide separate APIs for SHA-224 and SHA-256
179  * and SHA-224 is not widely used, this implementation provides HW accelerated SHA-256 only
180  * and SHA-224 is not available at all (calls will fail).
181  *
182  * To use SHA-224 on LPC, do not define MBEDTLS_SHA256_ALT and both SHA-224 and SHA-256 will use
183  * original mbed TLS software implementation.
184  */
185 #if defined(MBEDTLS_FREESCALE_LPC_SHA256)
186 #define MBEDTLS_SHA256_ALT_NO_224
187 #endif
188 #endif
189 #if defined(MBEDTLS_FREESCALE_MMCAU_MD5)
190 #define MBEDTLS_MD5_PROCESS_ALT
191 #endif
192 #if defined(MBEDTLS_FREESCALE_MMCAU_SHA1)
193 #define MBEDTLS_SHA1_PROCESS_ALT
194 #endif
195 #if defined(MBEDTLS_FREESCALE_MMCAU_SHA256)
196 #define MBEDTLS_SHA256_PROCESS_ALT
197 #endif
198 #if defined(MBEDTLS_FREESCALE_CAU3_SHA256)
199 #define MBEDTLS_SHA256_PROCESS_ALT
200 #endif
201 #if defined(MBEDTLS_FREESCALE_CAU3_AES)
202 #define MBEDTLS_AES_ALT_NO_192
203 #endif
204 #if defined(MBEDTLS_FREESCALE_LTC_AES)
205 #if !defined(FSL_FEATURE_LTC_HAS_AES192) || !FSL_FEATURE_LTC_HAS_AES192
206 #define MBEDTLS_AES_ALT_NO_192
207 #endif
208 #if !defined(FSL_FEATURE_LTC_HAS_AES256) || !FSL_FEATURE_LTC_HAS_AES256
209 #define MBEDTLS_AES_ALT_NO_256
210 #endif
211 #endif
212 #if defined(MBEDTLS_FREESCALE_LPC_AES)
213 #define MBEDTLS_AES_CRYPT_CBC_ALT
214 #define MBEDTLS_AES_CRYPT_CFB_ALT
215 #define MBEDTLS_AES_CRYPT_CTR_ALT
216 #endif
217 #if defined(MBEDTLS_FREESCALE_LPC_SHA1)
218 #define MBEDTLS_SHA1_PROCESS_ALT
219 #endif
220 #if defined(MBEDTLS_FREESCALE_LPC_SHA256)
221 #define MBEDTLS_SHA256_PROCESS_ALT
222 #endif
223
224 #if USE_RTOS && defined(FSL_RTOS_FREE_RTOS)
225 #include "FreeRTOS.h"
226
227 #define MBEDTLS_PLATFORM_MEMORY
228
229 #endif /* USE_RTOS*/
230 /**************************** KSDK end ****************************************/
231 #endif /* MBEDTLS_AES_ALT || MBEDTLS_SHA256_ALT */
232
233 #endif // K32W061_MBEDTLS_CONFIG_H