3 * Copyright (c) 2021 Project CHIP Authors
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #ifndef K32W061_MBEDTLS_CONFIG_H
19 #define K32W061_MBEDTLS_CONFIG_H
21 #if defined(MBEDTLS_ECP_WINDOW_SIZE)
22 #undef MBEDTLS_ECP_WINDOW_SIZE
23 #define MBEDTLS_ECP_WINDOW_SIZE 4 /**< Maximum window size used */
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 */
32 * \def MBEDTLS_AES_ALT
34 * Enable hardware acceleration for the AES block cipher
36 * See MBEDTLS_AES_C for more information.
38 #define MBEDTLS_AES_ALT
40 #if defined(MBEDTLS_AES_ALT)
41 /**************************** KSDK ********************************************/
42 #include "fsl_device_registers.h"
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)
48 #define LTC_INSTANCE LTC0 /* LTC base register.*/
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.*/
54 #if defined(FSL_FEATURE_LTC_HAS_DES) && FSL_FEATURE_LTC_HAS_DES
55 #define MBEDTLS_FREESCALE_LTC_DES /* Enable use of LTC DES.*/
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.*/
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
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"
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.*/
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"
83 #define MBEDTLS_CAU3_COMPLETION_SIGNAL CAU3_CC_CMD_EVT
84 #define MBEDTLS_SHA256_ALT_NO_224
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
92 #if defined(MBEDTLS_FREESCALE_LTC_PKHA) || defined(MBEDTLS_FREESCALE_CAU3_PKHA)
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.
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.
107 //#define FREESCALE_PKHA_LONG_OPERANDS_ENABLE
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)
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.*/
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)
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.*/
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
137 #if defined(MBEDTLS_FREESCALE_LTC_DES)
138 #define MBEDTLS_DES_CRYPT_CBC_ALT
139 #define MBEDTLS_DES3_CRYPT_CBC_ALT
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
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
153 #if defined(MBEDTLS_FREESCALE_LTC_AES_GCM) || defined(MBEDTLS_FREESCALE_LPC_AES_GCM)
154 #define MBEDTLS_GCM_CRYPT_ALT
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
170 #if defined(MBEDTLS_FREESCALE_LTC_SHA1) || defined(MBEDTLS_FREESCALE_LPC_SHA1)
171 #define MBEDTLS_SHA1_ALT
173 #if defined(MBEDTLS_FREESCALE_LTC_SHA256) || defined(MBEDTLS_FREESCALE_LPC_SHA256)
174 //#define MBEDTLS_SHA256_ALT
176 * LPC SHA module does not support SHA-224.
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).
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.
185 #if defined(MBEDTLS_FREESCALE_LPC_SHA256)
186 #define MBEDTLS_SHA256_ALT_NO_224
189 #if defined(MBEDTLS_FREESCALE_MMCAU_MD5)
190 #define MBEDTLS_MD5_PROCESS_ALT
192 #if defined(MBEDTLS_FREESCALE_MMCAU_SHA1)
193 #define MBEDTLS_SHA1_PROCESS_ALT
195 #if defined(MBEDTLS_FREESCALE_MMCAU_SHA256)
196 #define MBEDTLS_SHA256_PROCESS_ALT
198 #if defined(MBEDTLS_FREESCALE_CAU3_SHA256)
199 #define MBEDTLS_SHA256_PROCESS_ALT
201 #if defined(MBEDTLS_FREESCALE_CAU3_AES)
202 #define MBEDTLS_AES_ALT_NO_192
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
208 #if !defined(FSL_FEATURE_LTC_HAS_AES256) || !FSL_FEATURE_LTC_HAS_AES256
209 #define MBEDTLS_AES_ALT_NO_256
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
217 #if defined(MBEDTLS_FREESCALE_LPC_SHA1)
218 #define MBEDTLS_SHA1_PROCESS_ALT
220 #if defined(MBEDTLS_FREESCALE_LPC_SHA256)
221 #define MBEDTLS_SHA256_PROCESS_ALT
224 #if USE_RTOS && defined(FSL_RTOS_FREE_RTOS)
225 #include "FreeRTOS.h"
227 extern void * pvPortCallocRtos(size_t num, size_t size); /*Calloc for HEAP3.*/
229 #define MBEDTLS_PLATFORM_MEMORY
230 #define MBEDTLS_PLATFORM_STD_CALLOC pvPortCallocRtos
231 #define MBEDTLS_PLATFORM_STD_FREE vPortFree
234 /**************************** KSDK end ****************************************/
235 #endif /* MBEDTLS_AES_ALT || MBEDTLS_SHA256_ALT */
237 #endif // K32W061_MBEDTLS_CONFIG_H