diff options
Diffstat (limited to 'lib/chibios/os/hal/templates/hal_crypto_lld.h')
-rw-r--r-- | lib/chibios/os/hal/templates/hal_crypto_lld.h | 376 |
1 files changed, 376 insertions, 0 deletions
diff --git a/lib/chibios/os/hal/templates/hal_crypto_lld.h b/lib/chibios/os/hal/templates/hal_crypto_lld.h new file mode 100644 index 000000000..8b1842c1f --- /dev/null +++ b/lib/chibios/os/hal/templates/hal_crypto_lld.h | |||
@@ -0,0 +1,376 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_crypto_lld.h | ||
19 | * @brief PLATFORM cryptographic subsystem low level driver header. | ||
20 | * | ||
21 | * @addtogroup CRYPTO | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #ifndef HAL_CRYPTO_LLD_H | ||
26 | #define HAL_CRYPTO_LLD_H | ||
27 | |||
28 | #if (HAL_USE_CRY == TRUE) || defined(__DOXYGEN__) | ||
29 | |||
30 | /*===========================================================================*/ | ||
31 | /* Driver constants. */ | ||
32 | /*===========================================================================*/ | ||
33 | |||
34 | /** | ||
35 | * @name Driver capability switches | ||
36 | * @{ | ||
37 | */ | ||
38 | #define CRY_LLD_SUPPORTS_AES TRUE | ||
39 | #define CRY_LLD_SUPPORTS_AES_ECB TRUE | ||
40 | #define CRY_LLD_SUPPORTS_AES_CBC TRUE | ||
41 | #define CRY_LLD_SUPPORTS_AES_CFB TRUE | ||
42 | #define CRY_LLD_SUPPORTS_AES_CTR TRUE | ||
43 | #define CRY_LLD_SUPPORTS_AES_GCM TRUE | ||
44 | #define CRY_LLD_SUPPORTS_DES TRUE | ||
45 | #define CRY_LLD_SUPPORTS_DES_ECB TRUE | ||
46 | #define CRY_LLD_SUPPORTS_DES_CBC TRUE | ||
47 | #define CRY_LLD_SUPPORTS_SHA1 TRUE | ||
48 | #define CRY_LLD_SUPPORTS_SHA256 TRUE | ||
49 | #define CRY_LLD_SUPPORTS_SHA512 TRUE | ||
50 | #define CRY_LLD_SUPPORTS_HMAC_SHA256 TRUE | ||
51 | #define CRY_LLD_SUPPORTS_HMAC_SHA512 TRUE | ||
52 | /** @} */ | ||
53 | |||
54 | /*===========================================================================*/ | ||
55 | /* Driver pre-compile time settings. */ | ||
56 | /*===========================================================================*/ | ||
57 | |||
58 | /** | ||
59 | * @name PLATFORM configuration options | ||
60 | * @{ | ||
61 | */ | ||
62 | /** | ||
63 | * @brief CRY1 driver enable switch. | ||
64 | * @details If set to @p TRUE the support for CRY1 is included. | ||
65 | * @note The default is @p FALSE. | ||
66 | */ | ||
67 | #if !defined(PLATFORM_CRY_USE_CRY1) || defined(__DOXYGEN__) | ||
68 | #define PLATFORM_CRY_USE_CRY1 FALSE | ||
69 | #endif | ||
70 | /** @} */ | ||
71 | |||
72 | /*===========================================================================*/ | ||
73 | /* Derived constants and error checks. */ | ||
74 | /*===========================================================================*/ | ||
75 | |||
76 | /*===========================================================================*/ | ||
77 | /* Driver data structures and types. */ | ||
78 | /*===========================================================================*/ | ||
79 | |||
80 | /** | ||
81 | * @brief CRY key identifier type. | ||
82 | */ | ||
83 | typedef uint32_t crykey_t; | ||
84 | |||
85 | /** | ||
86 | * @brief Type of a structure representing an CRY driver. | ||
87 | */ | ||
88 | typedef struct CRYDriver CRYDriver; | ||
89 | |||
90 | /** | ||
91 | * @brief Driver configuration structure. | ||
92 | * @note It could be empty on some architectures. | ||
93 | */ | ||
94 | typedef struct { | ||
95 | uint32_t dummy; | ||
96 | } CRYConfig; | ||
97 | |||
98 | /** | ||
99 | * @brief Structure representing an CRY driver. | ||
100 | */ | ||
101 | struct CRYDriver { | ||
102 | /** | ||
103 | * @brief Driver state. | ||
104 | */ | ||
105 | crystate_t state; | ||
106 | /** | ||
107 | * @brief Current configuration data. | ||
108 | */ | ||
109 | const CRYConfig *config; | ||
110 | #if defined(CRY_DRIVER_EXT_FIELDS) | ||
111 | CRY_DRIVER_EXT_FIELDS | ||
112 | #endif | ||
113 | /* End of the mandatory fields.*/ | ||
114 | }; | ||
115 | |||
116 | #if (CRY_LLD_SUPPORTS_SHA1 == TRUE) || defined(__DOXYGEN__) | ||
117 | /** | ||
118 | * @brief Type of a SHA1 context. | ||
119 | */ | ||
120 | typedef struct { | ||
121 | uint32_t dummy; | ||
122 | } SHA1Context; | ||
123 | #endif | ||
124 | |||
125 | #if (CRY_LLD_SUPPORTS_SHA256 == TRUE) || defined(__DOXYGEN__) | ||
126 | /** | ||
127 | * @brief Type of a SHA256 context. | ||
128 | */ | ||
129 | typedef struct { | ||
130 | uint32_t dummy; | ||
131 | } SHA256Context; | ||
132 | #endif | ||
133 | |||
134 | #if (CRY_LLD_SUPPORTS_SHA512 == TRUE) || defined(__DOXYGEN__) | ||
135 | /** | ||
136 | * @brief Type of a SHA512 context. | ||
137 | */ | ||
138 | typedef struct { | ||
139 | uint32_t dummy; | ||
140 | } SHA512Context; | ||
141 | #endif | ||
142 | |||
143 | #if (CRY_LLD_SUPPORTS_HMAC_SHA256 == TRUE) || defined(__DOXYGEN__) | ||
144 | /** | ||
145 | * @brief Type of a HMAC_SHA256 context. | ||
146 | */ | ||
147 | typedef struct { | ||
148 | uint32_t dummy; | ||
149 | } HMACSHA256Context; | ||
150 | #endif | ||
151 | |||
152 | #if (CRY_LLD_SUPPORTS_HMAC_SHA512 == TRUE) || defined(__DOXYGEN__) | ||
153 | /** | ||
154 | * @brief Type of a HMAC_SHA512 context. | ||
155 | */ | ||
156 | typedef struct { | ||
157 | uint32_t dummy; | ||
158 | } HMACSHA512Context; | ||
159 | #endif | ||
160 | |||
161 | /*===========================================================================*/ | ||
162 | /* Driver macros. */ | ||
163 | /*===========================================================================*/ | ||
164 | |||
165 | /*===========================================================================*/ | ||
166 | /* External declarations. */ | ||
167 | /*===========================================================================*/ | ||
168 | |||
169 | #if (PLATFORM_CRY_USE_CRY1 == TRUE) && !defined(__DOXYGEN__) | ||
170 | extern CRYDriver CRYD1; | ||
171 | #endif | ||
172 | |||
173 | #ifdef __cplusplus | ||
174 | extern "C" { | ||
175 | #endif | ||
176 | void cry_lld_init(void); | ||
177 | void cry_lld_start(CRYDriver *cryp); | ||
178 | void cry_lld_stop(CRYDriver *cryp); | ||
179 | #if (CRY_LLD_SUPPORTS_AES == TRUE) || \ | ||
180 | (CRY_LLD_SUPPORTS_AES_ECB == TRUE) || \ | ||
181 | (CRY_LLD_SUPPORTS_AES_CBC == TRUE) || \ | ||
182 | (CRY_LLD_SUPPORTS_AES_CFB == TRUE) || \ | ||
183 | (CRY_LLD_SUPPORTS_AES_CTR == TRUE) || \ | ||
184 | (CRY_LLD_SUPPORTS_AES_GCM == TRUE) || \ | ||
185 | defined(__DOXYGEN__) | ||
186 | cryerror_t cry_lld_aes_loadkey(CRYDriver *cryp, | ||
187 | size_t size, | ||
188 | const uint8_t *keyp); | ||
189 | #endif | ||
190 | #if (CRY_LLD_SUPPORTS_AES == TRUE) || defined(__DOXYGEN__) | ||
191 | cryerror_t cry_lld_encrypt_AES(CRYDriver *cryp, | ||
192 | crykey_t key_id, | ||
193 | const uint8_t *in, | ||
194 | uint8_t *out); | ||
195 | cryerror_t cry_lld_decrypt_AES(CRYDriver *cryp, | ||
196 | crykey_t key_id, | ||
197 | const uint8_t *in, | ||
198 | uint8_t *out); | ||
199 | #endif | ||
200 | #if (CRY_LLD_SUPPORTS_AES_ECB == TRUE) || defined(__DOXYGEN__) | ||
201 | cryerror_t cry_lld_encrypt_AES_ECB(CRYDriver *cryp, | ||
202 | crykey_t key_id, | ||
203 | size_t size, | ||
204 | const uint8_t *in, | ||
205 | uint8_t *out); | ||
206 | cryerror_t cry_lld_decrypt_AES_ECB(CRYDriver *cryp, | ||
207 | crykey_t key_id, | ||
208 | size_t size, | ||
209 | const uint8_t *in, | ||
210 | uint8_t *out); | ||
211 | #endif | ||
212 | #if (CRY_LLD_SUPPORTS_AES_CBC == TRUE) || defined(__DOXYGEN__) | ||
213 | cryerror_t cry_lld_encrypt_AES_CBC(CRYDriver *cryp, | ||
214 | crykey_t key_id, | ||
215 | size_t size, | ||
216 | const uint8_t *in, | ||
217 | uint8_t *out, | ||
218 | const uint8_t *iv); | ||
219 | cryerror_t cry_lld_decrypt_AES_CBC(CRYDriver *cryp, | ||
220 | crykey_t key_id, | ||
221 | size_t size, | ||
222 | const uint8_t *in, | ||
223 | uint8_t *out, | ||
224 | const uint8_t *iv); | ||
225 | #endif | ||
226 | #if (CRY_LLD_SUPPORTS_AES_CFB == TRUE) || defined(__DOXYGEN__) | ||
227 | cryerror_t cry_lld_encrypt_AES_CFB(CRYDriver *cryp, | ||
228 | crykey_t key_id, | ||
229 | size_t size, | ||
230 | const uint8_t *in, | ||
231 | uint8_t *out, | ||
232 | const uint8_t *iv); | ||
233 | cryerror_t cry_lld_decrypt_AES_CFB(CRYDriver *cryp, | ||
234 | crykey_t key_id, | ||
235 | size_t size, | ||
236 | const uint8_t *in, | ||
237 | uint8_t *out, | ||
238 | const uint8_t *iv); | ||
239 | #endif | ||
240 | #if (CRY_LLD_SUPPORTS_AES_CTR == TRUE) || defined(__DOXYGEN__) | ||
241 | cryerror_t cry_lld_encrypt_AES_CTR(CRYDriver *cryp, | ||
242 | crykey_t key_id, | ||
243 | size_t size, | ||
244 | const uint8_t *in, | ||
245 | uint8_t *out, | ||
246 | const uint8_t *iv); | ||
247 | cryerror_t cry_lld_decrypt_AES_CTR(CRYDriver *cryp, | ||
248 | crykey_t key_id, | ||
249 | size_t size, | ||
250 | const uint8_t *in, | ||
251 | uint8_t *out, | ||
252 | const uint8_t *iv); | ||
253 | #endif | ||
254 | #if (CRY_LLD_SUPPORTS_AES_GCM == TRUE) || defined(__DOXYGEN__) | ||
255 | cryerror_t cry_lld_encrypt_AES_GCM(CRYDriver *cryp, | ||
256 | crykey_t key_id, | ||
257 | size_t auth_size, | ||
258 | const uint8_t *auth_in, | ||
259 | size_t text_size, | ||
260 | const uint8_t *text_in, | ||
261 | uint8_t *text_out, | ||
262 | const uint8_t *iv, | ||
263 | size_t tag_size, | ||
264 | uint8_t *tag_out); | ||
265 | cryerror_t cry_lld_decrypt_AES_GCM(CRYDriver *cryp, | ||
266 | crykey_t key_id, | ||
267 | size_t auth_size, | ||
268 | const uint8_t *auth_in, | ||
269 | size_t text_size, | ||
270 | const uint8_t *text_in, | ||
271 | uint8_t *text_out, | ||
272 | const uint8_t *iv, | ||
273 | size_t tag_size, | ||
274 | const uint8_t *tag_in); | ||
275 | #endif | ||
276 | #if (CRY_LLD_SUPPORTS_DES == TRUE) || \ | ||
277 | (CRY_LLD_SUPPORTS_DES_ECB == TRUE) || \ | ||
278 | (CRY_LLD_SUPPORTS_DES_CBC == TRUE) || \ | ||
279 | defined(__DOXYGEN__) | ||
280 | cryerror_t cry_lld_des_loadkey(CRYDriver *cryp, | ||
281 | size_t size, | ||
282 | const uint8_t *keyp); | ||
283 | #endif | ||
284 | #if (CRY_LLD_SUPPORTS_DES == TRUE) || defined(__DOXYGEN__) | ||
285 | cryerror_t cry_lld_encrypt_DES(CRYDriver *cryp, | ||
286 | crykey_t key_id, | ||
287 | const uint8_t *in, | ||
288 | uint8_t *out); | ||
289 | cryerror_t cry_lld_decrypt_DES(CRYDriver *cryp, | ||
290 | crykey_t key_id, | ||
291 | const uint8_t *in, | ||
292 | uint8_t *out); | ||
293 | #endif | ||
294 | #if (CRY_LLD_SUPPORTS_DES_ECB == TRUE) || defined(__DOXYGEN__) | ||
295 | cryerror_t cry_lld_encrypt_DES_ECB(CRYDriver *cryp, | ||
296 | crykey_t key_id, | ||
297 | size_t size, | ||
298 | const uint8_t *in, | ||
299 | uint8_t *out); | ||
300 | cryerror_t cry_lld_decrypt_DES_ECB(CRYDriver *cryp, | ||
301 | crykey_t key_id, | ||
302 | size_t size, | ||
303 | const uint8_t *in, | ||
304 | uint8_t *out); | ||
305 | #endif | ||
306 | #if (CRY_LLD_SUPPORTS_DES_CBC == TRUE) || defined(__DOXYGEN__) | ||
307 | cryerror_t cry_lld_encrypt_DES_CBC(CRYDriver *cryp, | ||
308 | crykey_t key_id, | ||
309 | size_t size, | ||
310 | const uint8_t *in, | ||
311 | uint8_t *out, | ||
312 | const uint8_t *iv); | ||
313 | cryerror_t cry_lld_decrypt_DES_CBC(CRYDriver *cryp, | ||
314 | crykey_t key_id, | ||
315 | size_t size, | ||
316 | const uint8_t *in, | ||
317 | uint8_t *out, | ||
318 | const uint8_t *iv); | ||
319 | #endif | ||
320 | #if (CRY_LLD_SUPPORTS_SHA1 == TRUE) || defined(__DOXYGEN__) | ||
321 | cryerror_t cry_lld_SHA1_init(CRYDriver *cryp, SHA1Context *sha1ctxp); | ||
322 | cryerror_t cry_lld_SHA1_update(CRYDriver *cryp, SHA1Context *sha1ctxp, | ||
323 | size_t size, const uint8_t *in); | ||
324 | cryerror_t cry_lld_SHA1_final(CRYDriver *cryp, SHA1Context *sha1ctxp, | ||
325 | uint8_t *out); | ||
326 | #endif | ||
327 | #if (CRY_LLD_SUPPORTS_SHA256 == TRUE) || defined(__DOXYGEN__) | ||
328 | cryerror_t cry_lld_SHA256_init(CRYDriver *cryp, SHA256Context *sha256ctxp); | ||
329 | cryerror_t cry_lld_SHA256_update(CRYDriver *cryp, SHA256Context *sha256ctxp, | ||
330 | size_t size, const uint8_t *in); | ||
331 | cryerror_t cry_lld_SHA256_final(CRYDriver *cryp, SHA256Context *sha256ctxp, | ||
332 | uint8_t *out); | ||
333 | #endif | ||
334 | #if (CRY_LLD_SUPPORTS_SHA512 == TRUE) || defined(__DOXYGEN__) | ||
335 | cryerror_t cry_lld_SHA512_init(CRYDriver *cryp, SHA512Context *sha512ctxp); | ||
336 | cryerror_t cry_lld_SHA512_update(CRYDriver *cryp, SHA512Context *sha512ctxp, | ||
337 | size_t size, const uint8_t *in); | ||
338 | cryerror_t cry_lld_SHA512_final(CRYDriver *cryp, SHA512Context *sha512ctxp, | ||
339 | uint8_t *out); | ||
340 | #endif | ||
341 | #if (CRY_LLD_SUPPORTS_HMAC_SHA256 == TRUE) || \ | ||
342 | (CRY_LLD_SUPPORTS_HMAC_SHA512 == TRUE) || \ | ||
343 | defined(__DOXYGEN__) | ||
344 | cryerror_t cry_lld_hmac_loadkey(CRYDriver *cryp, | ||
345 | size_t size, | ||
346 | const uint8_t *keyp); | ||
347 | #endif | ||
348 | #if (CRY_LLD_SUPPORTS_HMAC_SHA256 == TRUE) || defined(__DOXYGEN__) | ||
349 | cryerror_t cry_lld_HMACSHA256_init(CRYDriver *cryp, | ||
350 | HMACSHA256Context *hmacsha256ctxp); | ||
351 | cryerror_t cry_lld_HMACSHA256_update(CRYDriver *cryp, | ||
352 | HMACSHA256Context *hmacsha256ctxp, | ||
353 | size_t size, const uint8_t *in); | ||
354 | cryerror_t cry_lld_HMACSHA256_final(CRYDriver *cryp, | ||
355 | HMACSHA256Context *hmacsha256ctxp, | ||
356 | uint8_t *out); | ||
357 | #endif | ||
358 | #if (CRY_LLD_SUPPORTS_HMAC_SHA512 == TRUE) || defined(__DOXYGEN__) | ||
359 | cryerror_t cry_lld_HMACSHA512_init(CRYDriver *cryp, | ||
360 | HMACSHA512Context *hmacsha512ctxp); | ||
361 | cryerror_t cry_lld_HMACSHA512_update(CRYDriver *cryp, | ||
362 | HMACSHA512Context *hmacsha512ctxp, | ||
363 | size_t size, const uint8_t *in); | ||
364 | cryerror_t cry_lld_HMACSHA512_final(CRYDriver *cryp, | ||
365 | HMACSHA512Context *hmacsha512ctxp, | ||
366 | uint8_t *out); | ||
367 | #endif | ||
368 | #ifdef __cplusplus | ||
369 | } | ||
370 | #endif | ||
371 | |||
372 | #endif /* HAL_USE_CRY == TRUE */ | ||
373 | |||
374 | #endif /* HAL_CRYPTO_LLD_H */ | ||
375 | |||
376 | /** @} */ | ||