1 /*
2  * Copyright (c) 2019-2022, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef CRYPTO_ACCELERATOR_CONF_H
9 #define CRYPTO_ACCELERATOR_CONF_H
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif /* __cplusplus */
14 
15 /****************************************************************/
16 /* Require built-in implementations based on PSA requirements */
17 /****************************************************************/
18 
19 #define PSA_WANT_KEY_TYPE_AES                   1
20 
21 /* The CC312 does not support CFB mode */
22 #ifdef PSA_WANT_ALG_CFB
23 #undef PSA_WANT_ALG_CFB
24 #endif /* PSA_WANT_ALG_CFB */
25 
26 #ifdef LEGACY_DRIVER_API_ENABLED
27 
28 #ifdef PSA_WANT_KEY_TYPE_AES
29 #define MBEDTLS_AES_ALT
30 #define MBEDTLS_AES_SETKEY_ENC_ALT
31 #define MBEDTLS_AES_SETKEY_DEC_ALT
32 #define MBEDTLS_AES_ENCRYPT_ALT
33 #define MBEDTLS_AES_DECRYPT_ALT
34 #endif /* PSA_WANT_KEY_TYPE_AES */
35 
36 #ifdef PSA_WANT_KEY_TYPE_ARIA
37 #define MBEDTLS_ARIA_ALT
38 #endif /* PSA_WANT_KEY_TYPE_ARIA */
39 
40 #ifdef PSA_WANT_ALG_CCM
41 #define MBEDTLS_CCM_ALT
42 #endif /* PSA_WANT_ALG_CCM */
43 
44 #ifdef PSA_WANT_KEY_TYPE_CHACHA20
45 #define MBEDTLS_CHACHA20_ALT
46 #ifdef PSA_WANT_ALG_CHACHA20_POLY1305
47 #define MBEDTLS_CHACHAPOLY_ALT
48 #endif /* PSA_WANT_ALG_CHACHA20_POLY1305 */
49 #endif /* PSA_WANT_KEY_TYPE_CHACHA20 */
50 
51 #ifdef PSA_WANT_ALG_CMAC
52 #define MBEDTLS_CMAC_ALT
53 #endif /* PSA_WANT_ALG_CMAC */
54 
55 #ifdef PSA_WANT_ALG_ECDH
56 #define MBEDTLS_ECDH_GEN_PUBLIC_ALT
57 #define MBEDTLS_ECDH_COMPUTE_SHARED_ALT
58 #endif /* PSA_WANT_ALG_ECDH */
59 
60 #ifdef PSA_WANT_ALG_ECDSA
61 #define MBEDTLS_ECDSA_VERIFY_ALT
62 #define MBEDTLS_ECDSA_SIGN_ALT
63 
64 #ifndef CRYPTO_HW_ACCELERATOR_OTP_PROVISIONING
65 #define MBEDTLS_ECDSA_GENKEY_ALT
66 #endif
67 #endif /* PSA_WANT_ALG_ECDSA */
68 
69 #ifdef PSA_WANT_ALG_GCM
70 #define MBEDTLS_GCM_ALT
71 #endif /* PSA_WANT_ALG_GCM */
72 
73 #ifdef PSA_WANT_ALG_SHA_1
74 #define MBEDTLS_SHA1_ALT
75 #define MBEDTLS_SHA1_PROCESS_ALT
76 #endif /* PSA_WANT_ALG_SHA_1 */
77 
78 #ifdef PSA_WANT_ALG_SHA_256
79 #define MBEDTLS_SHA256_ALT
80 #define MBEDTLS_SHA256_PROCESS_ALT
81 #else
82 #endif /* PSA_WANT_ALG_SHA_256 */
83 
84 #else /* LEGACY_DRIVER_API_ENABLED */
85 
86 #ifdef PSA_WANT_KEY_TYPE_AES
87 #define MBEDTLS_PSA_ACCEL_KEY_TYPE_AES
88 #endif
89 
90 #ifdef PSA_WANT_KEY_TYPE_CHACHA20
91 #define MBEDTLS_PSA_ACCEL_KEY_TYPE_CHACHA20
92 #endif
93 
94 #ifdef PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC
95 #define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY
96 #define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_BASIC
97 #define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_IMPORT
98 #define MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_EXPORT
99 #endif
100 
101 #ifdef PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC
102 #define MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR_BASIC
103 #endif
104 
105 #ifdef PSA_WANT_ALG_ECDH
106 #define MBEDTLS_PSA_ACCEL_ALG_ECDH
107 #endif
108 
109 #ifdef PSA_WANT_ALG_ECDSA
110 #define MBEDTLS_PSA_ACCEL_ALG_ECDSA
111 #endif
112 
113 #ifdef PSA_WANT_ALG_DETERMINISTIC_ECDSA
114 #define MBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA
115 #define MBEDTLS_HMAC_DRBG_C
116 #define MBEDTLS_MD_C
117 #endif
118 
119 #ifdef PSA_WANT_ALG_CBC_NO_PADDING
120 #define MBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING
121 #endif
122 
123 #ifdef PSA_WANT_ALG_CBC_PKCS7
124 #define MBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7
125 #endif
126 
127 #ifdef PSA_WANT_ALG_ECB_NO_PADDING
128 #define MBEDTLS_PSA_ACCEL_ALG_ECB_NO_PADDING
129 #endif
130 
131 #ifdef PSA_WANT_ALG_CTR
132 #define MBEDTLS_PSA_ACCEL_ALG_CTR
133 #endif
134 
135 #ifdef PSA_WANT_ALG_OFB
136 #define MBEDTLS_PSA_ACCEL_ALG_OFB
137 #endif
138 
139 #ifdef PSA_WANT_ALG_CCM
140 #define MBEDTLS_PSA_ACCEL_ALG_CCM
141 #endif
142 
143 #ifdef PSA_WANT_ALG_GCM
144 #define MBEDTLS_PSA_ACCEL_ALG_GCM
145 #define MBEDTLS_GCM_C
146 #endif
147 
148 #ifdef PSA_WANT_ALG_CMAC
149 #define MBEDTLS_PSA_ACCEL_ALG_CMAC
150 #endif
151 
152 #ifdef PSA_WANT_ALG_HMAC
153 #define MBEDTLS_PSA_ACCEL_ALG_HMAC
154 #endif
155 
156 #ifdef PSA_WANT_ALG_CHACHA20_POLY1305
157 #define MBEDTLS_PSA_ACCEL_ALG_CHACHA20_POLY1305
158 #endif
159 
160 #ifdef PSA_WANT_ALG_SHA_1
161 #define MBEDTLS_PSA_ACCEL_ALG_SHA_1
162 #endif
163 
164 #ifdef PSA_WANT_ALG_SHA_224
165 #define MBEDTLS_PSA_ACCEL_ALG_SHA_224
166 #endif
167 
168 #ifdef PSA_WANT_ALG_SHA_256
169 #define MBEDTLS_PSA_ACCEL_ALG_SHA_256
170 #endif
171 
172 #ifdef PSA_WANT_ALG_RSA_OAEP
173 #define MBEDTLS_PSA_ACCEL_ALG_RSA_OAEP
174 #define MBEDTLS_PKCS1_V21
175 #endif
176 
177 #ifdef PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
178 #define MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT
179 #define MBEDTLS_PKCS1_V15
180 #endif
181 
182 #ifdef PSA_WANT_ALG_RSA_PKCS1V15_SIGN
183 #define MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN
184 #define MBEDTLS_PKCS1_V15
185 #endif
186 
187 #ifdef PSA_WANT_ALG_RSA_PSS
188 #define MBEDTLS_PSA_ACCEL_ALG_RSA_PSS
189 #define MBEDTLS_PKCS1_V21
190 #endif
191 
192 #endif /* LEGACY_DRIVER_API_ENABLED */
193 
194 #if defined(PSA_WANT_ALG_RSA_OAEP)                 ||     \
195     defined(PSA_WANT_ALG_RSA_PKCS1V15_CRYPT)       ||     \
196     defined(PSA_WANT_ALG_RSA_PKCS1V15_SIGN)        ||     \
197     defined(PSA_WANT_ALG_RSA_PSS)                  ||     \
198     defined(PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC)  ||     \
199     defined(PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY)
200 #ifdef LEGACY_DRIVER_API_ENABLED
201 #define MBEDTLS_RSA_ALT
202 #define MBEDTLS_PK_RSA_ALT_SUPPORT
203 #endif /* LEGACY_DRIVER_API_ENABLED */
204 #define MBEDTLS_GENPRIME
205 #endif
206 
207 #ifdef __cplusplus
208 }
209 #endif /* __cplusplus */
210 
211 #endif /* CRYPTO_ACCELERATOR_CONF_H */
212