1 /**
2  * \file mbedtls/config_psa.h
3  * \brief PSA crypto configuration options (set of defines)
4  *
5  *  This set of compile-time options takes settings defined in
6  *  include/mbedtls/config.h and include/psa/crypto_config.h and uses
7  *  those definitions to define symbols used in the library code.
8  *
9  *  Users and integrators should not edit this file, please edit
10  *  include/mbedtls/config.h for MBETLS_XXX settings or
11  *  include/psa/crypto_config.h for PSA_WANT_XXX settings.
12  */
13 /*
14  *  Copyright The Mbed TLS Contributors
15  *  SPDX-License-Identifier: Apache-2.0
16  *
17  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
18  *  not use this file except in compliance with the License.
19  *  You may obtain a copy of the License at
20  *
21  *  http://www.apache.org/licenses/LICENSE-2.0
22  *
23  *  Unless required by applicable law or agreed to in writing, software
24  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
25  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26  *  See the License for the specific language governing permissions and
27  *  limitations under the License.
28  */
29 
30 #ifndef MBEDTLS_CONFIG_PSA_H
31 #define MBEDTLS_CONFIG_PSA_H
32 
33 #if defined(MBEDTLS_PSA_CRYPTO_CONFIG)
34 #include "psa/crypto_config.h"
35 #endif /* defined(MBEDTLS_PSA_CRYPTO_CONFIG) */
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 #if defined(MBEDTLS_PSA_CRYPTO_CONFIG)
42 
43 #if defined(PSA_WANT_ALG_DETERMINISTIC_ECDSA)
44 #if !defined(MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA)
45 #define MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA 1
46 #define MBEDTLS_ECDSA_DETERMINISTIC
47 #define MBEDTLS_ECDSA_C
48 #define MBEDTLS_HMAC_DRBG_C
49 #define MBEDTLS_MD_C
50 #endif /* !MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA */
51 #endif /* PSA_WANT_ALG_DETERMINISTIC_ECDSA */
52 
53 #if defined(PSA_WANT_ALG_ECDH)
54 #if !defined(MBEDTLS_PSA_ACCEL_ALG_ECDH)
55 #define MBEDTLS_PSA_BUILTIN_ALG_ECDH 1
56 #define MBEDTLS_ECDH_C
57 #define MBEDTLS_ECP_C
58 #define MBEDTLS_BIGNUM_C
59 #endif /* !MBEDTLS_PSA_ACCEL_ALG_ECDH */
60 #endif /* PSA_WANT_ALG_ECDH */
61 
62 #if defined(PSA_WANT_ALG_ECDSA)
63 #if !defined(MBEDTLS_PSA_ACCEL_ALG_ECDSA)
64 #define MBEDTLS_PSA_BUILTIN_ALG_ECDSA 1
65 #define MBEDTLS_ECDSA_C
66 #endif /* !MBEDTLS_PSA_ACCEL_ALG_ECDSA */
67 #endif /* PSA_WANT_ALG_ECDSA */
68 
69 #if defined(PSA_WANT_ALG_HKDF)
70 #if !defined(MBEDTLS_PSA_ACCEL_ALG_HKDF)
71 #define MBEDTLS_PSA_BUILTIN_ALG_HMAC 1
72 #define MBEDTLS_PSA_BUILTIN_ALG_HKDF 1
73 #endif /* !MBEDTLS_PSA_ACCEL_ALG_HKDF */
74 #endif /* PSA_WANT_ALG_HKDF */
75 
76 #if defined(PSA_WANT_ALG_HMAC)
77 #if !defined(MBEDTLS_PSA_ACCEL_ALG_HMAC)
78 #define MBEDTLS_PSA_BUILTIN_ALG_HMAC 1
79 #endif /* !MBEDTLS_PSA_ACCEL_ALG_HMAC */
80 #endif /* PSA_WANT_ALG_HMAC */
81 
82 #if defined(PSA_WANT_ALG_MD2) && !defined(MBEDTLS_PSA_ACCEL_ALG_MD2)
83 #define MBEDTLS_PSA_BUILTIN_ALG_MD2 1
84 #define MBEDTLS_MD2_C
85 #endif
86 
87 #if defined(PSA_WANT_ALG_MD4) && !defined(MBEDTLS_PSA_ACCEL_ALG_MD4)
88 #define MBEDTLS_PSA_BUILTIN_ALG_MD4 1
89 #define MBEDTLS_MD4_C
90 #endif
91 
92 #if defined(PSA_WANT_ALG_MD5) && !defined(MBEDTLS_PSA_ACCEL_ALG_MD5)
93 #define MBEDTLS_PSA_BUILTIN_ALG_MD5 1
94 #define MBEDTLS_MD5_C
95 #endif
96 
97 #if defined(PSA_WANT_ALG_RIPEMD160) && !defined(MBEDTLS_PSA_ACCEL_ALG_RIPEMD160)
98 #define MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160 1
99 #define MBEDTLS_RIPEMD160_C
100 #endif
101 
102 #if defined(PSA_WANT_ALG_RSA_OAEP)
103 #if !defined(MBEDTLS_PSA_ACCEL_ALG_RSA_OAEP)
104 #define MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP 1
105 #define MBEDTLS_RSA_C
106 #define MBEDTLS_BIGNUM_C
107 #define MBEDTLS_OID_C
108 #define MBEDTLS_PKCS1_V21
109 #define MBEDTLS_MD_C
110 #endif /* !MBEDTLS_PSA_ACCEL_ALG_RSA_OAEP */
111 #endif /* PSA_WANT_ALG_RSA_OAEP */
112 
113 #if defined(PSA_WANT_ALG_RSA_PKCS1V15_CRYPT)
114 #if !defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT)
115 #define MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT 1
116 #define MBEDTLS_RSA_C
117 #define MBEDTLS_BIGNUM_C
118 #define MBEDTLS_OID_C
119 #define MBEDTLS_PKCS1_V15
120 #endif /* !MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT */
121 #endif /* PSA_WANT_ALG_RSA_PKCS1V15_CRYPT */
122 
123 #if defined(PSA_WANT_ALG_RSA_PKCS1V15_SIGN)
124 #if !defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN)
125 #define MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN 1
126 #define MBEDTLS_RSA_C
127 #define MBEDTLS_BIGNUM_C
128 #define MBEDTLS_OID_C
129 #define MBEDTLS_PKCS1_V15
130 #define MBEDTLS_MD_C
131 #endif /* !MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN */
132 #endif /* PSA_WANT_ALG_RSA_PKCS1V15_SIGN */
133 
134 #if defined(PSA_WANT_ALG_RSA_PSS)
135 #if !defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PSS)
136 #define MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS 1
137 #define MBEDTLS_RSA_C
138 #define MBEDTLS_BIGNUM_C
139 #define MBEDTLS_OID_C
140 #define MBEDTLS_PKCS1_V21
141 #define MBEDTLS_MD_C
142 #endif /* !MBEDTLS_PSA_ACCEL_ALG_RSA_PSS */
143 #endif /* PSA_WANT_ALG_RSA_PSS */
144 
145 #if defined(PSA_WANT_ALG_SHA_1) && !defined(MBEDTLS_PSA_ACCEL_ALG_SHA_1)
146 #define MBEDTLS_PSA_BUILTIN_ALG_SHA_1 1
147 #define MBEDTLS_SHA1_C
148 #endif
149 
150 #if defined(PSA_WANT_ALG_SHA_224) && !defined(MBEDTLS_PSA_ACCEL_ALG_SHA_224)
151 #define MBEDTLS_PSA_BUILTIN_ALG_SHA_224 1
152 #define MBEDTLS_SHA256_C
153 #endif
154 
155 #if defined(PSA_WANT_ALG_SHA_256) && !defined(MBEDTLS_PSA_ACCEL_ALG_SHA_256)
156 #define MBEDTLS_PSA_BUILTIN_ALG_SHA_256 1
157 #define MBEDTLS_SHA256_C
158 #endif
159 
160 #if defined(PSA_WANT_ALG_SHA_384) && !defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384)
161 #define MBEDTLS_PSA_BUILTIN_ALG_SHA_384 1
162 #define MBEDTLS_SHA512_C
163 #endif
164 
165 #if defined(PSA_WANT_ALG_SHA_512) && !defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512)
166 #define MBEDTLS_PSA_BUILTIN_ALG_SHA_512 1
167 #define MBEDTLS_SHA512_C
168 #endif
169 
170 #if defined(PSA_WANT_ALG_TLS12_PRF)
171 #if !defined(MBEDTLS_PSA_ACCEL_ALG_TLS12_PRF)
172 #define MBEDTLS_PSA_BUILTIN_ALG_TLS12_PRF 1
173 #endif /* !MBEDTLS_PSA_ACCEL_ALG_TLS12_PRF */
174 #endif /* PSA_WANT_ALG_TLS12_PRF */
175 
176 #if defined(PSA_WANT_ALG_TLS12_PSK_TO_MS)
177 #if !defined(MBEDTLS_PSA_ACCEL_ALG_TLS12_PSK_TO_MS)
178 #define MBEDTLS_PSA_BUILTIN_ALG_TLS12_PSK_TO_MS 1
179 #endif /* !MBEDTLS_PSA_ACCEL_ALG_TLS12_PSK_TO_MS */
180 #endif /* PSA_WANT_ALG_TLS12_PSK_TO_MS */
181 
182 #if defined(PSA_WANT_KEY_TYPE_ECC_KEY_PAIR)
183 #if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR)
184 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR 1
185 #define MBEDTLS_ECP_C
186 #define MBEDTLS_BIGNUM_C
187 #endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR */
188 #endif /* PSA_WANT_KEY_TYPE_ECC_KEY_PAIR */
189 
190 #if defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY)
191 #if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY)
192 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY 1
193 #define MBEDTLS_ECP_C
194 #define MBEDTLS_BIGNUM_C
195 #endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY */
196 #endif /* PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY */
197 
198 #if defined(PSA_WANT_KEY_TYPE_RSA_KEY_PAIR)
199 #if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR)
200 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR 1
201 #define MBEDTLS_RSA_C
202 #define MBEDTLS_BIGNUM_C
203 #define MBEDTLS_OID_C
204 #define MBEDTLS_GENPRIME
205 #define MBEDTLS_PK_PARSE_C
206 #define MBEDTLS_PK_WRITE_C
207 #define MBEDTLS_PK_C
208 #endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR */
209 #endif /* PSA_WANT_KEY_TYPE_RSA_KEY_PAIR */
210 
211 #if defined(PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY)
212 #if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY)
213 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY 1
214 #define MBEDTLS_RSA_C
215 #define MBEDTLS_BIGNUM_C
216 #define MBEDTLS_OID_C
217 #define MBEDTLS_PK_PARSE_C
218 #define MBEDTLS_PK_WRITE_C
219 #define MBEDTLS_PK_C
220 #endif /* !MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY */
221 #endif /* PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY */
222 
223 #else /* MBEDTLS_PSA_CRYPTO_CONFIG */
224 
225 /*
226  * Ensure PSA_WANT_* defines are setup properly if MBEDTLS_PSA_CRYPTO_CONFIG
227  * is not defined
228  */
229 
230 #if defined(MBEDTLS_ECDH_C)
231 #define MBEDTLS_PSA_BUILTIN_ALG_ECDH 1
232 #define PSA_WANT_ALG_ECDH 1
233 #endif /* MBEDTLS_ECDH_C */
234 
235 #if defined(MBEDTLS_ECDSA_C)
236 #define MBEDTLS_PSA_BUILTIN_ALG_ECDSA 1
237 #define PSA_WANT_ALG_ECDSA 1
238 
239 // Only add in DETERMINISTIC support if ECDSA is also enabled
240 #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
241 #define MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA 1
242 #define PSA_WANT_ALG_DETERMINISTIC_ECDSA 1
243 #endif /* MBEDTLS_ECDSA_DETERMINISTIC */
244 
245 #endif /* MBEDTLS_ECDSA_C */
246 
247 #if defined(MBEDTLS_ECP_C)
248 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR 1
249 #define PSA_WANT_KEY_TYPE_ECC_KEY_PAIR 1
250 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY 1
251 #define PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
252 #endif /* MBEDTLS_ECP_C */
253 
254 #if defined(MBEDTLS_HKDF_C)
255 #define MBEDTLS_PSA_BUILTIN_ALG_HMAC 1
256 #define PSA_WANT_ALG_HMAC 1
257 #define MBEDTLS_PSA_BUILTIN_ALG_HKDF 1
258 #define PSA_WANT_ALG_HKDF 1
259 #endif /* MBEDTLS_HKDF_C */
260 
261 #if defined(MBEDTLS_MD_C)
262 #define MBEDTLS_PSA_BUILTIN_ALG_HMAC 1
263 #define PSA_WANT_ALG_HMAC 1
264 #define MBEDTLS_PSA_BUILTIN_ALG_TLS12_PRF 1
265 #define PSA_WANT_ALG_TLS12_PRF 1
266 #define MBEDTLS_PSA_BUILTIN_ALG_TLS12_PSK_TO_MS 1
267 #define PSA_WANT_ALG_TLS12_PSK_TO_MS 1
268 #endif /* MBEDTLS_MD_C */
269 
270 #if defined(MBEDTLS_MD2_C)
271 #define MBEDTLS_PSA_BUILTIN_ALG_MD2 1
272 #define PSA_WANT_ALG_MD2 1
273 #endif
274 
275 #if defined(MBEDTLS_MD4_C)
276 #define MBEDTLS_PSA_BUILTIN_ALG_MD4 1
277 #define PSA_WANT_ALG_MD4 1
278 #endif
279 
280 #if defined(MBEDTLS_MD5_C)
281 #define MBEDTLS_PSA_BUILTIN_ALG_MD5 1
282 #define PSA_WANT_ALG_MD5 1
283 #endif
284 
285 #if defined(MBEDTLS_RIPEMD160_C)
286 #define MBEDTLS_PSA_BUILTIN_ALG_RIPEMD160 1
287 #define PSA_WANT_ALG_RIPEMD160 1
288 #endif
289 
290 #if defined(MBEDTLS_RSA_C)
291 #if defined(MBEDTLS_PKCS1_V15)
292 #define MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_CRYPT 1
293 #define PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
294 #define MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN 1
295 #define PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
296 #endif /* MBEDTLSS_PKCS1_V15 */
297 #if defined(MBEDTLS_PKCS1_V21)
298 #define MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP 1
299 #define PSA_WANT_ALG_RSA_OAEP 1
300 #define MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS 1
301 #define PSA_WANT_ALG_RSA_PSS 1
302 #endif /* MBEDTLS_PKCS1_V21 */
303 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR 1
304 #define PSA_WANT_KEY_TYPE_RSA_KEY_PAIR 1
305 #define MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY 1
306 #define PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
307 #endif /* MBEDTLS_RSA_C */
308 
309 #if defined(MBEDTLS_SHA1_C)
310 #define MBEDTLS_PSA_BUILTIN_ALG_SHA_1 1
311 #define PSA_WANT_ALG_SHA_1 1
312 #endif
313 
314 #if defined(MBEDTLS_SHA256_C)
315 #define MBEDTLS_PSA_BUILTIN_ALG_SHA_224 1
316 #define MBEDTLS_PSA_BUILTIN_ALG_SHA_256 1
317 #define PSA_WANT_ALG_SHA_256 1
318 #endif
319 
320 #if defined(MBEDTLS_SHA512_C)
321 #if !defined(MBEDTLS_SHA512_NO_SHA384)
322 #define MBEDTLS_PSA_BUILTIN_ALG_SHA_384 1
323 #define PSA_WANT_ALG_SHA_384 1
324 #endif
325 #define MBEDTLS_PSA_BUILTIN_ALG_SHA_512 1
326 #define PSA_WANT_ALG_SHA_512 1
327 #endif
328 
329 #endif /* MBEDTLS_PSA_CRYPTO_CONFIG */
330 
331 #ifdef __cplusplus
332 }
333 #endif
334 
335 #endif /* MBEDTLS_CONFIG_PSA_H */
336