ChibiOS 21.11.4
hal_crypto.c
Go to the documentation of this file.
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.c
19 * @brief Cryptographic Driver code.
20 *
21 * @addtogroup CRYPTO
22 * @{
23 */
24
25#include "hal.h"
26
27#if (HAL_USE_CRY == TRUE) || defined(__DOXYGEN__)
28
29/*===========================================================================*/
30/* Driver local definitions. */
31/*===========================================================================*/
32
33/*===========================================================================*/
34/* Driver exported variables. */
35/*===========================================================================*/
36
37/*===========================================================================*/
38/* Driver local variables and types. */
39/*===========================================================================*/
40
41/*===========================================================================*/
42/* Driver local functions. */
43/*===========================================================================*/
44
45/*===========================================================================*/
46/* Driver exported functions. */
47/*===========================================================================*/
48
49/**
50 * @brief Cryptographic Driver initialization.
51 * @note This function is implicitly invoked by @p halInit(), there is
52 * no need to explicitly initialize the driver.
53 *
54 * @init
55 */
56void cryInit(void) {
57
58#if HAL_CRY_ENFORCE_FALLBACK == FALSE
60#endif
61}
62
63/**
64 * @brief Initializes the standard part of a @p CRYDriver structure.
65 *
66 * @param[out] cryp pointer to the @p CRYDriver object
67 *
68 * @init
69 */
71
72 cryp->state = CRY_STOP;
73 cryp->config = NULL;
74#if defined(CRY_DRIVER_EXT_INIT_HOOK)
75 CRY_DRIVER_EXT_INIT_HOOK(cryp);
76#endif
77}
78
79/**
80 * @brief Configures and activates the cryptographic peripheral.
81 *
82 * @param[in] cryp pointer to the @p CRYDriver object
83 * @param[in] config pointer to the @p CRYConfig object. Depending
84 * on the implementation the value can be @p NULL.
85 * @return The operation status.
86 *
87 * @api
88 */
89msg_t cryStart(CRYDriver *cryp, const CRYConfig *config) {
90 msg_t msg;
91
92 osalDbgCheck(cryp != NULL);
93
95 osalDbgAssert((cryp->state == CRY_STOP) || (cryp->state == CRY_READY),
96 "invalid state");
97 cryp->config = config;
98#if HAL_CRY_ENFORCE_FALLBACK == FALSE
99#if defined(CRY_LLD_ENHANCED_API)
100 msg = cry_lld_start(cryp);
101 if (msg == HAL_RET_SUCCESS) {
102 cryp->state = CRY_READY;
103 }
104 else {
105 cryp->state = CRY_STOP;
106 }
107#else
108 cry_lld_start(cryp);
109 cryp->state = CRY_READY;
110 msg = HAL_RET_SUCCESS;
111#endif
112#else
113 cryp->state = CRY_READY;
114 msg = HAL_RET_SUCCESS;
115#endif
116
118
119 return msg;
120}
121
122/**
123 * @brief Deactivates the cryptographic peripheral.
124 *
125 * @param[in] cryp pointer to the @p CRYDriver object
126 *
127 * @api
128 */
129void cryStop(CRYDriver *cryp) {
130
131 osalDbgCheck(cryp != NULL);
132
133 osalSysLock();
134
135 osalDbgAssert((cryp->state == CRY_STOP) || (cryp->state == CRY_READY),
136 "invalid state");
137
138#if HAL_CRY_ENFORCE_FALLBACK == FALSE
139 cry_lld_stop(cryp);
140#endif
141 cryp->config = NULL;
142 cryp->state = CRY_STOP;
143
145}
146
147/**
148 * @brief Initializes the AES transient key.
149 * @note It is the underlying implementation to decide which key sizes are
150 * allowable.
151 *
152 * @param[in] cryp pointer to the @p CRYDriver object
153 * @param[in] size key size in bytes
154 * @param[in] keyp pointer to the key data
155 * @return The operation status.
156 * @retval CRY_NOERROR if the operation succeeded.
157 * @retval CRY_ERR_INV_ALGO if the algorithm is unsupported.
158 * @retval CRY_ERR_INV_KEY_SIZE if the specified key size is invalid for
159 * the specified algorithm.
160 *
161 * @api
162 */
164 size_t size,
165 const uint8_t *keyp) {
166
167 osalDbgCheck((cryp != NULL) && (keyp != NULL));
168
169#if CRY_LLD_SUPPORTS_AES == TRUE
170 return cry_lld_aes_loadkey(cryp, size, keyp);
171#elif HAL_CRY_USE_FALLBACK == TRUE
172 return cry_fallback_aes_loadkey(cryp, size, keyp);
173#else
174 (void)cryp;
175 (void)size;
176 (void)keyp;
177
178 return CRY_ERR_INV_ALGO;
179#endif
180}
181
182/**
183 * @brief Encryption of a single block using AES.
184 * @note The implementation of this function must guarantee that it can
185 * be called from any context.
186 *
187 * @param[in] cryp pointer to the @p CRYDriver object
188 * @param[in] key_id the key to be used for the operation, zero is
189 * the transient key, other values are keys stored
190 * in an unspecified way
191 * @param[in] in buffer containing the input plaintext
192 * @param[out] out buffer for the output ciphertext
193 * @return The operation status.
194 * @retval CRY_NOERROR if the operation succeeded.
195 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
196 * device instance.
197 * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
198 * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
199 * or refers to an empty key slot.
200 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
201 * dependent.
202 *
203 * @special
204 */
206 crykey_t key_id,
207 const uint8_t *in,
208 uint8_t *out) {
209
210 osalDbgCheck((cryp != NULL) && (in != NULL) && (out != NULL));
211
212 osalDbgAssert(cryp->state == CRY_READY, "not ready");
213
214#if CRY_LLD_SUPPORTS_AES == TRUE
215 return cry_lld_encrypt_AES(cryp, key_id, in, out);
216#elif HAL_CRY_USE_FALLBACK == TRUE
217 return cry_fallback_encrypt_AES(cryp, key_id, in, out);
218#else
219 (void)cryp;
220 (void)key_id;
221 (void)in;
222 (void)out;
223
224 return CRY_ERR_INV_ALGO;
225#endif
226}
227
228/**
229 * @brief Decryption of a single block using AES.
230 * @note The implementation of this function must guarantee that it can
231 * be called from any context.
232 *
233 * @param[in] cryp pointer to the @p CRYDriver object
234 * @param[in] key_id the key to be used for the operation, zero is
235 * the transient key, other values are keys stored
236 * in an unspecified way
237 * @param[in] in buffer containing the input ciphertext
238 * @param[out] out buffer for the output plaintext
239 * @return The operation status.
240 * @retval CRY_NOERROR if the operation succeeded.
241 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
242 * device instance.
243 * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
244 * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
245 * or refers to an empty key slot.
246 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
247 * dependent.
248 *
249 * @special
250 */
252 crykey_t key_id,
253 const uint8_t *in,
254 uint8_t *out) {
255
256 osalDbgCheck((cryp != NULL) && (in != NULL) && (out != NULL));
257
258 osalDbgAssert(cryp->state == CRY_READY, "not ready");
259
260#if CRY_LLD_SUPPORTS_AES == TRUE
261 return cry_lld_decrypt_AES(cryp, key_id, in, out);
262#elif HAL_CRY_USE_FALLBACK == TRUE
263 return cry_fallback_decrypt_AES(cryp, key_id, in, out);
264#else
265 (void)cryp;
266 (void)key_id;
267 (void)in;
268 (void)out;
269
270 return CRY_ERR_INV_ALGO;
271#endif
272}
273
274/**
275 * @brief Encryption operation using AES-ECB.
276 * @note The function operates on data buffers whose length is a multiple
277 * of an AES block, this means that padding must be done by the
278 * caller.
279 *
280 * @param[in] cryp pointer to the @p CRYDriver object
281 * @param[in] key_id the key to be used for the operation, zero is
282 * the transient key, other values are keys stored
283 * in an unspecified way
284 * @param[in] size size of both buffers, this number must be a
285 * multiple of 16
286 * @param[in] in buffer containing the input plaintext
287 * @param[out] out buffer for the output ciphertext
288 * @return The operation status.
289 * @retval CRY_NOERROR if the operation succeeded.
290 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
291 * device instance.
292 * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
293 * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
294 * or refers to an empty key slot.
295 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
296 * dependent.
297 *
298 * @api
299 */
301 crykey_t key_id,
302 size_t size,
303 const uint8_t *in,
304 uint8_t *out) {
305
306 osalDbgCheck((cryp != NULL) && (in != NULL) && (out != NULL) &&
307 ((size & (size_t)15) == (size_t)0));
308
309 osalDbgAssert(cryp->state == CRY_READY, "not ready");
310
311#if CRY_LLD_SUPPORTS_AES_ECB == TRUE
312 return cry_lld_encrypt_AES_ECB(cryp, key_id, size, in, out);
313#elif HAL_CRY_USE_FALLBACK == TRUE
314 return cry_fallback_encrypt_AES_ECB(cryp, key_id, size, in, out);
315#else
316 (void)cryp;
317 (void)key_id;
318 (void)size;
319 (void)in;
320 (void)out;
321
322 return CRY_ERR_INV_ALGO;
323#endif
324}
325
326/**
327 * @brief Decryption operation using AES-ECB.
328 * @note The function operates on data buffers whose length is a multiple
329 * of an AES block, this means that padding must be done by the
330 * caller.
331 *
332 * @param[in] cryp pointer to the @p CRYDriver object
333 * @param[in] key_id the key to be used for the operation, zero is
334 * the transient key, other values are keys stored
335 * in an unspecified way
336 * @param[in] size size of both buffers, this number must be a
337 * multiple of 16
338 * @param[in] in buffer containing the input ciphertext
339 * @param[out] out buffer for the output plaintext
340 * @return The operation status.
341 * @retval CRY_NOERROR if the operation succeeded.
342 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
343 * device instance.
344 * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
345 * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
346 * or refers to an empty key slot.
347 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
348 * dependent.
349 *
350 * @api
351 */
353 crykey_t key_id,
354 size_t size,
355 const uint8_t *in,
356 uint8_t *out) {
357
358 osalDbgCheck((cryp != NULL) && (in != NULL) && (out != NULL) &&
359 ((size & (size_t)15) == (size_t)0));
360
361 osalDbgAssert(cryp->state == CRY_READY, "not ready");
362
363#if CRY_LLD_SUPPORTS_AES_ECB == TRUE
364 return cry_lld_decrypt_AES_ECB(cryp, key_id, size, in, out);
365#elif HAL_CRY_USE_FALLBACK == TRUE
366 return cry_fallback_decrypt_AES_ECB(cryp, key_id, size, in, out);
367#else
368 (void)cryp;
369 (void)key_id;
370 (void)size;
371 (void)in;
372 (void)out;
373
374 return CRY_ERR_INV_ALGO;
375#endif
376}
377
378/**
379 * @brief Encryption operation using AES-CBC.
380 * @note The function operates on data buffers whose length is a multiple
381 * of an AES block, this means that padding must be done by the
382 * caller.
383 *
384 * @param[in] cryp pointer to the @p CRYDriver object
385 * @param[in] key_id the key to be used for the operation, zero is
386 * the transient key, other values are keys stored
387 * in an unspecified way
388 * @param[in] size size of both buffers, this number must be a
389 * multiple of 16
390 * @param[in] in buffer containing the input plaintext
391 * @param[out] out buffer for the output ciphertext
392 * @param[in] iv 128 bits input vector
393 * @return The operation status.
394 * @retval CRY_NOERROR if the operation succeeded.
395 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
396 * device instance.
397 * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
398 * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
399 * or refers to an empty key slot.
400 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
401 * dependent.
402 *
403 * @api
404 */
406 crykey_t key_id,
407 size_t size,
408 const uint8_t *in,
409 uint8_t *out,
410 const uint8_t *iv) {
411
412 osalDbgCheck((cryp != NULL) && (in != NULL) && (out != NULL) &&
413 (iv != NULL) && ((size & (size_t)15) == (size_t)0));
414
415 osalDbgAssert(cryp->state == CRY_READY, "not ready");
416
417#if CRY_LLD_SUPPORTS_AES_CBC == TRUE
418 return cry_lld_encrypt_AES_CBC(cryp, key_id, size, in, out, iv);
419#elif HAL_CRY_USE_FALLBACK == TRUE
420 return cry_fallback_encrypt_AES_CBC(cryp, key_id, size, in, out, iv);
421#else
422 (void)cryp;
423 (void)key_id;
424 (void)size;
425 (void)in;
426 (void)out;
427 (void)iv;
428
429 return CRY_ERR_INV_ALGO;
430#endif
431}
432
433/**
434 * @brief Decryption operation using AES-CBC.
435 * @note The function operates on data buffers whose length is a multiple
436 * of an AES block, this means that padding must be done by the
437 * caller.
438 *
439 * @param[in] cryp pointer to the @p CRYDriver object
440 * @param[in] key_id the key to be used for the operation, zero is
441 * the transient key, other values are keys stored
442 * in an unspecified way
443 * @param[in] size size of both buffers, this number must be a
444 * multiple of 16
445 * @param[in] in buffer containing the input ciphertext
446 * @param[out] out buffer for the output plaintext
447 * @param[in] iv 128 bits input vector
448 * @return The operation status.
449 * @retval CRY_NOERROR if the operation succeeded.
450 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
451 * device instance.
452 * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
453 * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
454 * or refers to an empty key slot.
455 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
456 * dependent.
457 *
458 * @api
459 */
461 crykey_t key_id,
462 size_t size,
463 const uint8_t *in,
464 uint8_t *out,
465 const uint8_t *iv) {
466
467 osalDbgCheck((cryp != NULL) && (in != NULL) && (out != NULL) &&
468 (iv != NULL) && ((size & (size_t)15) == (size_t)0));
469
470 osalDbgAssert(cryp->state == CRY_READY, "not ready");
471
472#if CRY_LLD_SUPPORTS_AES_CBC == TRUE
473 return cry_lld_decrypt_AES_CBC(cryp, key_id, size, in, out, iv);
474#elif HAL_CRY_USE_FALLBACK == TRUE
475 return cry_fallback_decrypt_AES_CBC(cryp, key_id, size, in, out, iv);
476#else
477 (void)cryp;
478 (void)key_id;
479 (void)size;
480 (void)in;
481 (void)out;
482 (void)iv;
483
484 return CRY_ERR_INV_ALGO;
485#endif
486}
487
488/**
489 * @brief Encryption operation using AES-CFB.
490 * @note This is a stream cipher, there are no size restrictions.
491 *
492 * @param[in] cryp pointer to the @p CRYDriver object
493 * @param[in] key_id the key to be used for the operation, zero is
494 * the transient key, other values are keys stored
495 * in an unspecified way
496 * @param[in] size size of both buffers
497 * @param[in] in buffer containing the input plaintext
498 * @param[out] out buffer for the output ciphertext
499 * @param[in] iv 128 bits input vector
500 * @return The operation status.
501 * @retval CRY_NOERROR if the operation succeeded.
502 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
503 * device instance.
504 * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
505 * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
506 * or refers to an empty key slot.
507 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
508 * dependent.
509 *
510 * @api
511 */
513 crykey_t key_id,
514 size_t size,
515 const uint8_t *in,
516 uint8_t *out,
517 const uint8_t *iv) {
518
519 osalDbgCheck((cryp != NULL) && (in != NULL) && (out != NULL) &&
520 (iv != NULL) && (size > (size_t)0));
521
522 osalDbgAssert(cryp->state == CRY_READY, "not ready");
523
524#if CRY_LLD_SUPPORTS_AES_CFB == TRUE
525 return cry_lld_encrypt_AES_CFB(cryp, key_id, size, in, out, iv);
526#elif HAL_CRY_USE_FALLBACK == TRUE
527 return cry_fallback_encrypt_AES_CFB(cryp, key_id, size, in, out, iv);
528#else
529 (void)cryp;
530 (void)key_id;
531 (void)size;
532 (void)in;
533 (void)out;
534 (void)iv;
535
536 return CRY_ERR_INV_ALGO;
537#endif
538}
539
540/**
541 * @brief Decryption operation using AES-CFB.
542 * @note This is a stream cipher, there are no size restrictions.
543 *
544 * @param[in] cryp pointer to the @p CRYDriver object
545 * @param[in] key_id the key to be used for the operation, zero is
546 * the transient key, other values are keys stored
547 * in an unspecified way
548 * @param[in] size size of both buffers
549 * @param[in] in buffer containing the input ciphertext
550 * @param[out] out buffer for the output plaintext
551 * @param[in] iv 128 bits input vector
552 * @return The operation status.
553 * @retval CRY_NOERROR if the operation succeeded.
554 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
555 * device instance.
556 * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
557 * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
558 * or refers to an empty key slot.
559 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
560 * dependent.
561 *
562 * @api
563 */
565 crykey_t key_id,
566 size_t size,
567 const uint8_t *in,
568 uint8_t *out,
569 const uint8_t *iv) {
570
571 osalDbgCheck((cryp != NULL) && (in != NULL) && (out != NULL) &&
572 (iv != NULL) && (size > (size_t)0));
573
574 osalDbgAssert(cryp->state == CRY_READY, "not ready");
575
576#if CRY_LLD_SUPPORTS_AES_CFB == TRUE
577 return cry_lld_decrypt_AES_CFB(cryp, key_id, size, in, out, iv);
578#elif HAL_CRY_USE_FALLBACK == TRUE
579 return cry_fallback_decrypt_AES_CFB(cryp, key_id, size, in, out, iv);
580#else
581 (void)cryp;
582 (void)key_id;
583 (void)size;
584 (void)in;
585 (void)out;
586 (void)iv;
587
588 return CRY_ERR_INV_ALGO;
589#endif
590}
591
592/**
593 * @brief Encryption operation using AES-CTR.
594 * @note This is a stream cipher, there are no size restrictions.
595 *
596 * @param[in] cryp pointer to the @p CRYDriver object
597 * @param[in] key_id the key to be used for the operation, zero is
598 * the transient key, other values are keys stored
599 * in an unspecified way
600 * @param[in] size size of both buffers
601 * @param[in] in buffer containing the input plaintext
602 * @param[out] out buffer for the output ciphertext
603 * @param[in] iv 128 bits input vector + counter, it contains
604 * a 96 bits IV and a 32 bits counter
605 * @return The operation status.
606 * @retval CRY_NOERROR if the operation succeeded.
607 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
608 * device instance.
609 * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
610 * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
611 * or refers to an empty key slot.
612 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
613 * dependent.
614 *
615 * @api
616 */
618 crykey_t key_id,
619 size_t size,
620 const uint8_t *in,
621 uint8_t *out,
622 const uint8_t *iv) {
623
624 osalDbgCheck((cryp != NULL) && (in != NULL) && (out != NULL) &&
625 (iv != NULL) && (size > (size_t)0));
626
627 osalDbgAssert(cryp->state == CRY_READY, "not ready");
628
629#if CRY_LLD_SUPPORTS_AES_CTR == TRUE
630 return cry_lld_encrypt_AES_CTR(cryp, key_id, size, in, out, iv);
631#elif HAL_CRY_USE_FALLBACK == TRUE
632 return cry_fallback_encrypt_AES_CTR(cryp, key_id, size, in, out, iv);
633#else
634 (void)cryp;
635 (void)key_id;
636 (void)size;
637 (void)in;
638 (void)out;
639 (void)iv;
640
641 return CRY_ERR_INV_ALGO;
642#endif
643}
644
645/**
646 * @brief Decryption operation using AES-CTR.
647 * @note This is a stream cipher, there are no size restrictions.
648 *
649 * @param[in] cryp pointer to the @p CRYDriver object
650 * @param[in] key_id the key to be used for the operation, zero is
651 * the transient key, other values are keys stored
652 * in an unspecified way
653 * @param[in] size size of both buffers
654 * @param[in] in buffer containing the input ciphertext
655 * @param[out] out buffer for the output plaintext
656 * @param[in] iv 128 bits input vector + counter, it contains
657 * a 96 bits IV and a 32 bits counter
658 * @return The operation status.
659 * @retval CRY_NOERROR if the operation succeeded.
660 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
661 * device instance.
662 * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
663 * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
664 * or refers to an empty key slot.
665 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
666 * dependent.
667 *
668 * @api
669 */
671 crykey_t key_id,
672 size_t size,
673 const uint8_t *in,
674 uint8_t *out,
675 const uint8_t *iv) {
676
677 osalDbgCheck((cryp != NULL) && (in != NULL) && (out != NULL) &&
678 (iv != NULL) && (size > (size_t)0));
679
680 osalDbgAssert(cryp->state == CRY_READY, "not ready");
681
682#if CRY_LLD_SUPPORTS_AES_CTR == TRUE
683 return cry_lld_decrypt_AES_CTR(cryp, key_id, size, in, out, iv);
684#elif HAL_CRY_USE_FALLBACK == TRUE
685 return cry_fallback_decrypt_AES_CTR(cryp, key_id, size, in, out, iv);
686#else
687 (void)cryp;
688 (void)key_id;
689 (void)size;
690 (void)in;
691 (void)out;
692 (void)iv;
693
694 return CRY_ERR_INV_ALGO;
695#endif
696}
697
698/**
699 * @brief Encryption operation using AES-GCM.
700 * @note This is a stream cipher, there are no size restrictions.
701 *
702 * @param[in] cryp pointer to the @p CRYDriver object
703 * @param[in] key_id the key to be used for the operation, zero is
704 * the transient key, other values are keys stored
705 * in an unspecified way
706 * @param[in] auth_size size of the data buffer to be authenticated
707 * @param[in] auth_in buffer containing the data to be authenticated
708 * @param[in] text_size size of the text buffer
709 * @param[in] text_in buffer containing the input plaintext
710 * @param[out] text_out buffer for the output ciphertext
711 * @param[in] iv 128 bits input vector
712 * @param[in] tag_size size of the authentication tag, this number
713 * must be between 1 and 16
714 * @param[out] tag_out buffer for the generated authentication tag
715 * @return The operation status.
716 * @retval CRY_NOERROR if the operation succeeded.
717 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
718 * device instance.
719 * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
720 * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
721 * or refers to an empty key slot.
722 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
723 * dependent.
724 *
725 * @api
726 */
728 crykey_t key_id,
729 size_t auth_size,
730 const uint8_t *auth_in,
731 size_t text_size,
732 const uint8_t *text_in,
733 uint8_t *text_out,
734 const uint8_t *iv,
735 size_t tag_size,
736 uint8_t *tag_out) {
737
738 osalDbgCheck((cryp != NULL) && (auth_in != NULL) &&
739 (text_size > (size_t)0) &&
740 (text_in != NULL) && (text_out != NULL) && (iv != NULL) &&
741 (tag_size >= (size_t)1) && (tag_size <= (size_t)16) &&
742 (tag_out != NULL));
743
744 osalDbgAssert(cryp->state == CRY_READY, "not ready");
745
746#if CRY_LLD_SUPPORTS_AES_GCM == TRUE
747 return cry_lld_encrypt_AES_GCM(cryp, key_id, auth_size, auth_in,
748 text_size, text_in, text_out, iv,
749 tag_size, tag_out);
750#elif HAL_CRY_USE_FALLBACK == TRUE
751 return cry_fallback_encrypt_AES_GCM(cryp, key_id, auth_size, auth_in,
752 text_size, text_in, text_out, iv,
753 tag_size, tag_out);
754#else
755 (void)cryp;
756 (void)key_id;
757 (void)auth_size;
758 (void)auth_in;
759 (void)text_size;
760 (void)text_in;
761 (void)text_out;
762 (void)iv;
763 (void)tag_size;
764 (void)tag_out;
765
766 return CRY_ERR_INV_ALGO;
767#endif
768}
769
770/**
771 * @brief Decryption operation using AES-GCM.
772 * @note This is a stream cipher, there are no size restrictions.
773 *
774 * @param[in] cryp pointer to the @p CRYDriver object
775 * @param[in] key_id the key to be used for the operation, zero is
776 * the transient key, other values are keys stored
777 * in an unspecified way
778 * @param[in] auth_size size of the data buffer to be authenticated
779 * @param[in] auth_in buffer containing the data to be authenticated
780 * @param[in] text_size size of the text buffer
781 * @param[in] text_in buffer containing the input plaintext
782 * @param[out] text_out buffer for the output ciphertext
783 * @param[in] iv 128 bits input vector
784 * @param[in] tag_size size of the authentication tag, this number
785 * must be between 1 and 16
786 * @param[in] tag_in buffer for the generated authentication tag
787 * @return The operation status.
788 * @retval CRY_NOERROR if the operation succeeded.
789 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
790 * device instance.
791 * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
792 * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
793 * or refers to an empty key slot.
794 * @retval CRY_ERR_AUTH_FAILED authentication failed
795 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
796 * dependent.
797 *
798 * @api
799 */
801 crykey_t key_id,
802 size_t auth_size,
803 const uint8_t *auth_in,
804 size_t text_size,
805 const uint8_t *text_in,
806 uint8_t *text_out,
807 const uint8_t *iv,
808 size_t tag_size,
809 const uint8_t *tag_in) {
810
811 osalDbgCheck((cryp != NULL) && (auth_in != NULL) &&
812 (text_size > (size_t)0) &&
813 (text_in != NULL) && (text_out != NULL) && (iv != NULL) &&
814 (tag_size >= (size_t)1) && (tag_size <= (size_t)16) &&
815 (tag_in != NULL));
816
817 osalDbgAssert(cryp->state == CRY_READY, "not ready");
818
819#if CRY_LLD_SUPPORTS_AES_GCM == TRUE
820 return cry_lld_decrypt_AES_GCM(cryp, key_id, auth_size, auth_in,
821 text_size, text_in, text_out, iv,
822 tag_size, tag_in);
823#elif HAL_CRY_USE_FALLBACK == TRUE
824 return cry_fallback_decrypt_AES_GCM(cryp, key_id, auth_size, auth_in,
825 text_size, text_in, text_out, iv,
826 tag_size, tag_in);
827#else
828 (void)cryp;
829 (void)key_id;
830 (void)auth_size;
831 (void)auth_in;
832 (void)text_size;
833 (void)text_in;
834 (void)text_out;
835 (void)iv;
836 (void)tag_size;
837 (void)tag_in;
838
839 return CRY_ERR_INV_ALGO;
840#endif
841}
842
843/**
844 * @brief Initializes the DES transient key.
845 * @note It is the underlying implementation to decide which key sizes are
846 * allowable.
847 *
848 * @param[in] cryp pointer to the @p CRYDriver object
849 * @param[in] size key size in bytes
850 * @param[in] keyp pointer to the key data
851 * @return The operation status.
852 * @retval CRY_NOERROR if the operation succeeded.
853 * @retval CRY_ERR_INV_ALGO if the algorithm is unsupported.
854 * @retval CRY_ERR_INV_KEY_SIZE if the specified key size is invalid for
855 * the specified algorithm.
856 *
857 * @api
858 */
860 size_t size,
861 const uint8_t *keyp) {
862
863 osalDbgCheck((cryp != NULL) && (keyp != NULL));
864
865#if CRY_LLD_SUPPORTS_DES == TRUE
866 return cry_lld_des_loadkey(cryp, size, keyp);
867#elif HAL_CRY_USE_FALLBACK == TRUE
868 return cry_fallback_des_loadkey(cryp, size, keyp);
869#else
870 (void)cryp;
871 (void)size;
872 (void)keyp;
873
874 return CRY_ERR_INV_ALGO;
875#endif
876}
877
878/**
879 * @brief Encryption of a single block using (T)DES.
880 * @note The implementation of this function must guarantee that it can
881 * be called from any context.
882 *
883 * @param[in] cryp pointer to the @p CRYDriver object
884 * @param[in] key_id the key to be used for the operation, zero is
885 * the transient key, other values are keys stored
886 * in an unspecified way
887 * @param[in] in buffer containing the input plaintext
888 * @param[out] out buffer for the output ciphertext
889 * @return The operation status.
890 * @retval CRY_NOERROR if the operation succeeded.
891 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
892 * device instance.
893 * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
894 * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
895 * or refers to an empty key slot.
896 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
897 * dependent.
898 *
899 * @special
900 */
902 crykey_t key_id,
903 const uint8_t *in,
904 uint8_t *out) {
905
906 osalDbgCheck((cryp != NULL) && (in != NULL) && (out != NULL));
907
908 osalDbgAssert(cryp->state == CRY_READY, "not ready");
909
910#if CRY_LLD_SUPPORTS_DES == TRUE
911 return cry_lld_encrypt_DES(cryp, key_id, in, out);
912#elif HAL_CRY_USE_FALLBACK == TRUE
913 return cry_fallback_encrypt_DES(cryp, key_id, in, out);
914#else
915 (void)cryp;
916 (void)key_id;
917 (void)in;
918 (void)out;
919
920 return CRY_ERR_INV_ALGO;
921#endif
922}
923
924/**
925 * @brief Decryption of a single block using (T)DES.
926 * @note The implementation of this function must guarantee that it can
927 * be called from any context.
928 *
929 *
930 * @param[in] cryp pointer to the @p CRYDriver object
931 * @param[in] key_id the key to be used for the operation, zero is
932 * the transient key, other values are keys stored
933 * in an unspecified way
934 * @param[in] in buffer containing the input ciphertext
935 * @param[out] out buffer for the output plaintext
936 * @return The operation status.
937 * @retval CRY_NOERROR if the operation succeeded.
938 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
939 * device instance.
940 * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
941 * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
942 * or refers to an empty key slot.
943 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
944 * dependent.
945 *
946 * @special
947 */
949 crykey_t key_id,
950 const uint8_t *in,
951 uint8_t *out) {
952
953 osalDbgCheck((cryp != NULL) && (in != NULL) && (out != NULL));
954
955 osalDbgAssert(cryp->state == CRY_READY, "not ready");
956
957#if CRY_LLD_SUPPORTS_DES == TRUE
958 return cry_lld_decrypt_DES(cryp, key_id, in, out);
959#elif HAL_CRY_USE_FALLBACK == TRUE
960 return cry_fallback_decrypt_DES(cryp, key_id, in, out);
961#else
962 (void)cryp;
963 (void)key_id;
964 (void)in;
965 (void)out;
966
967 return CRY_ERR_INV_ALGO;
968#endif
969}
970
971/**
972 * @brief Encryption operation using (T)DES-ECB.
973 * @note The function operates on data buffers whose length is a multiple
974 * of an DES block, this means that padding must be done by the
975 * caller.
976 *
977 * @param[in] cryp pointer to the @p CRYDriver object
978 * @param[in] key_id the key to be used for the operation, zero is
979 * the transient key, other values are keys stored
980 * in an unspecified way
981 * @param[in] size size of both buffers, this number must be a
982 * multiple of 8
983 * @param[in] in buffer containing the input plaintext
984 * @param[out] out buffer for the output ciphertext
985 * @return The operation status.
986 * @retval CRY_NOERROR if the operation succeeded.
987 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
988 * device instance.
989 * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
990 * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
991 * or refers to an empty key slot.
992 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
993 * dependent.
994 *
995 * @api
996 */
998 crykey_t key_id,
999 size_t size,
1000 const uint8_t *in,
1001 uint8_t *out) {
1002
1003 osalDbgCheck((cryp != NULL) && (in != NULL) && (out != NULL) &&
1004 ((size & (size_t)7) == (size_t)0));
1005
1006 osalDbgAssert(cryp->state == CRY_READY, "not ready");
1007
1008#if CRY_LLD_SUPPORTS_DES_ECB == TRUE
1009 return cry_lld_encrypt_DES_ECB(cryp, key_id, size, in, out);
1010#elif HAL_CRY_USE_FALLBACK == TRUE
1011 return cry_fallback_encrypt_DES_ECB(cryp, key_id, size, in, out);
1012#else
1013 (void)cryp;
1014 (void)key_id;
1015 (void)size;
1016 (void)in;
1017 (void)out;
1018
1019 return CRY_ERR_INV_ALGO;
1020#endif
1021}
1022
1023/**
1024 * @brief Decryption operation using (T)DES-ECB.
1025 * @note The function operates on data buffers whose length is a multiple
1026 * of an DES block, this means that padding must be done by the
1027 * caller.
1028 *
1029 * @param[in] cryp pointer to the @p CRYDriver object
1030 * @param[in] key_id the key to be used for the operation, zero is
1031 * the transient key, other values are keys stored
1032 * in an unspecified way
1033 * @param[in] size size of both buffers, this number must be a
1034 * multiple of 8
1035 * @param[in] in buffer containing the input ciphertext
1036 * @param[out] out buffer for the output plaintext
1037 * @return The operation status.
1038 * @retval CRY_NOERROR if the operation succeeded.
1039 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
1040 * device instance.
1041 * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
1042 * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
1043 * or refers to an empty key slot.
1044 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
1045 * dependent.
1046 *
1047 * @api
1048 */
1050 crykey_t key_id,
1051 size_t size,
1052 const uint8_t *in,
1053 uint8_t *out) {
1054
1055 osalDbgCheck((cryp != NULL) && (in != NULL) && (out != NULL) &&
1056 ((size & (size_t)7) == (size_t)0));
1057
1058 osalDbgAssert(cryp->state == CRY_READY, "not ready");
1059
1060#if CRY_LLD_SUPPORTS_DES_ECB == TRUE
1061 return cry_lld_decrypt_DES_ECB(cryp, key_id, size, in, out);
1062#elif HAL_CRY_USE_FALLBACK == TRUE
1063 return cry_fallback_decrypt_DES_ECB(cryp, key_id, size, in, out);
1064#else
1065 (void)cryp;
1066 (void)key_id;
1067 (void)size;
1068 (void)in;
1069 (void)out;
1070
1071 return CRY_ERR_INV_ALGO;
1072#endif
1073}
1074
1075/**
1076 * @brief Encryption operation using (T)DES-CBC.
1077 * @note The function operates on data buffers whose length is a multiple
1078 * of an DES block, this means that padding must be done by the
1079 * caller.
1080 *
1081 * @param[in] cryp pointer to the @p CRYDriver object
1082 * @param[in] key_id the key to be used for the operation, zero is
1083 * the transient key, other values are keys stored
1084 * in an unspecified way
1085 * @param[in] size size of both buffers, this number must be a
1086 * multiple of 8
1087 * @param[in] in buffer containing the input plaintext
1088 * @param[out] out buffer for the output ciphertext
1089 * @param[in] iv 64 bits input vector
1090 * @return The operation status.
1091 * @retval CRY_NOERROR if the operation succeeded.
1092 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
1093 * device instance.
1094 * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
1095 * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
1096 * or refers to an empty key slot.
1097 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
1098 * dependent.
1099 *
1100 * @api
1101 */
1103 crykey_t key_id,
1104 size_t size,
1105 const uint8_t *in,
1106 uint8_t *out,
1107 const uint8_t *iv) {
1108
1109 osalDbgCheck((cryp != NULL) && (in != NULL) && (out != NULL) &&
1110 (iv != NULL) && ((size & (size_t)7) == (size_t)0));
1111
1112 osalDbgAssert(cryp->state == CRY_READY, "not ready");
1113
1114#if CRY_LLD_SUPPORTS_DES_CBC == TRUE
1115 return cry_lld_encrypt_DES_CBC(cryp, key_id, size, in, out, iv);
1116#elif HAL_CRY_USE_FALLBACK == TRUE
1117 return cry_fallback_encrypt_DES_CBC(cryp, key_id, size, in, out, iv);
1118#else
1119 (void)cryp;
1120 (void)key_id;
1121 (void)size;
1122 (void)in;
1123 (void)out;
1124 (void)iv;
1125
1126 return CRY_ERR_INV_ALGO;
1127#endif
1128}
1129
1130/**
1131 * @brief Decryption operation using (T)DES-CBC.
1132 * @note The function operates on data buffers whose length is a multiple
1133 * of an DES block, this means that padding must be done by the
1134 * caller.
1135 *
1136 * @param[in] cryp pointer to the @p CRYDriver object
1137 * @param[in] key_id the key to be used for the operation, zero is
1138 * the transient key, other values are keys stored
1139 * in an unspecified way
1140 * @param[in] size size of both buffers, this number must be a
1141 * multiple of 8
1142 * @param[in] in buffer containing the input ciphertext
1143 * @param[out] out buffer for the output plaintext
1144 * @param[in] iv 64 bits input vector
1145 * @return The operation status.
1146 * @retval CRY_NOERROR if the operation succeeded.
1147 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
1148 * device instance.
1149 * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
1150 * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
1151 * or refers to an empty key slot.
1152 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
1153 * dependent.
1154 *
1155 * @api
1156 */
1158 crykey_t key_id,
1159 size_t size,
1160 const uint8_t *in,
1161 uint8_t *out,
1162 const uint8_t *iv) {
1163
1164 osalDbgCheck((cryp != NULL) && (in != NULL) && (out != NULL) &&
1165 (iv != NULL) && ((size & (size_t)7) == (size_t)0));
1166
1167 osalDbgAssert(cryp->state == CRY_READY, "not ready");
1168
1169#if CRY_LLD_SUPPORTS_DES_CBC == TRUE
1170 return cry_lld_decrypt_DES_CBC(cryp, key_id, size, in, out, iv);
1171#elif HAL_CRY_USE_FALLBACK == TRUE
1172 return cry_fallback_decrypt_DES_CBC(cryp, key_id, size, in, out, iv);
1173#else
1174 (void)cryp;
1175 (void)key_id;
1176 (void)size;
1177 (void)in;
1178 (void)out;
1179 (void)iv;
1180
1181 return CRY_ERR_INV_ALGO;
1182#endif
1183}
1184
1185/**
1186 * @brief Hash initialization using SHA1.
1187 * @note Use of this algorithm is not recommended because proven weak.
1188 *
1189 * @param[in] cryp pointer to the @p CRYDriver object
1190 * @param[out] sha1ctxp pointer to a SHA1 context to be initialized
1191 * @return The operation status.
1192 * @retval CRY_NOERROR if the operation succeeded.
1193 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
1194 * device instance.
1195 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
1196 * dependent.
1197 *
1198 * @api
1199 */
1201
1202 osalDbgCheck((cryp != NULL) && (sha1ctxp != NULL));
1203
1204 osalDbgAssert(cryp->state == CRY_READY, "not ready");
1205
1206#if CRY_LLD_SUPPORTS_SHA1 == TRUE
1207 return cry_lld_SHA1_init(cryp, sha1ctxp);
1208#elif HAL_CRY_USE_FALLBACK == TRUE
1209 return cry_fallback_SHA1_init(cryp, sha1ctxp);
1210#else
1211 (void)cryp;
1212 (void)sha1ctxp;
1213
1214 return CRY_ERR_INV_ALGO;
1215#endif
1216}
1217
1218/**
1219 * @brief Hash update using SHA1.
1220 * @note Use of this algorithm is not recommended because proven weak.
1221 *
1222 * @param[in] cryp pointer to the @p CRYDriver object
1223 * @param[in] sha1ctxp pointer to a SHA1 context
1224 * @param[in] size size of input buffer
1225 * @param[in] in buffer containing the input text
1226 * @return The operation status.
1227 * @retval CRY_NOERROR if the operation succeeded.
1228 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
1229 * device instance.
1230 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
1231 * dependent.
1232 *
1233 * @api
1234 */
1236 size_t size, const uint8_t *in) {
1237
1238 osalDbgCheck((cryp != NULL) && (sha1ctxp != NULL) && (in != NULL));
1239
1240 osalDbgAssert(cryp->state == CRY_READY, "not ready");
1241
1242#if CRY_LLD_SUPPORTS_SHA1 == TRUE
1243 return cry_lld_SHA1_update(cryp, sha1ctxp, size, in);
1244#elif HAL_CRY_USE_FALLBACK == TRUE
1245 return cry_fallback_SHA1_update(cryp, sha1ctxp, size, in);
1246#else
1247 (void)cryp;
1248 (void)sha1ctxp;
1249 (void)size;
1250 (void)in;
1251
1252 return CRY_ERR_INV_ALGO;
1253#endif
1254}
1255
1256/**
1257 * @brief Hash finalization using SHA1.
1258 * @note Use of this algorithm is not recommended because proven weak.
1259 *
1260 * @param[in] cryp pointer to the @p CRYDriver object
1261 * @param[in] sha1ctxp pointer to a SHA1 context
1262 * @param[out] out 160 bits output buffer
1263 * @return The operation status.
1264 * @retval CRY_NOERROR if the operation succeeded.
1265 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
1266 * device instance.
1267 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
1268 * dependent.
1269 *
1270 * @api
1271 */
1272cryerror_t crySHA1Final(CRYDriver *cryp, SHA1Context *sha1ctxp, uint8_t *out) {
1273
1274 osalDbgCheck((cryp != NULL) && (sha1ctxp != NULL) && (out != NULL));
1275
1276 osalDbgAssert(cryp->state == CRY_READY, "not ready");
1277
1278#if CRY_LLD_SUPPORTS_SHA1 == TRUE
1279 return cry_lld_SHA1_final(cryp, sha1ctxp, out);
1280#elif HAL_CRY_USE_FALLBACK == TRUE
1281 return cry_fallback_SHA1_final(cryp, sha1ctxp, out);
1282#else
1283 (void)cryp;
1284 (void)sha1ctxp;
1285 (void)out;
1286
1287 return CRY_ERR_INV_ALGO;
1288#endif
1289}
1290
1291/**
1292 * @brief Hash initialization using SHA256.
1293 *
1294 * @param[in] cryp pointer to the @p CRYDriver object
1295 * @param[out] sha256ctxp pointer to a SHA256 context to be initialized
1296 * @return The operation status.
1297 * @retval CRY_NOERROR if the operation succeeded.
1298 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
1299 * device instance.
1300 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
1301 * dependent.
1302 *
1303 * @api
1304 */
1306
1307 osalDbgCheck((cryp != NULL) && (sha256ctxp != NULL));
1308
1309 osalDbgAssert(cryp->state == CRY_READY, "not ready");
1310
1311#if CRY_LLD_SUPPORTS_SHA256 == TRUE
1312 return cry_lld_SHA256_init(cryp, sha256ctxp);
1313#elif HAL_CRY_USE_FALLBACK == TRUE
1314 return cry_fallback_SHA256_init(cryp, sha256ctxp);
1315#else
1316 (void)cryp;
1317 (void)sha256ctxp;
1318
1319 return CRY_ERR_INV_ALGO;
1320#endif
1321}
1322
1323/**
1324 * @brief Hash update using SHA256.
1325 *
1326 * @param[in] cryp pointer to the @p CRYDriver object
1327 * @param[in] sha256ctxp pointer to a SHA256 context
1328 * @param[in] size size of input buffer
1329 * @param[in] in buffer containing the input text
1330 * @return The operation status.
1331 * @retval CRY_NOERROR if the operation succeeded.
1332 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
1333 * device instance.
1334 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
1335 * dependent.
1336 *
1337 * @api
1338 */
1340 size_t size, const uint8_t *in) {
1341
1342 osalDbgCheck((cryp != NULL) && (sha256ctxp != NULL) && (in != NULL));
1343
1344 osalDbgAssert(cryp->state == CRY_READY, "not ready");
1345
1346#if CRY_LLD_SUPPORTS_SHA256 == TRUE
1347 return cry_lld_SHA256_update(cryp, sha256ctxp, size, in);
1348#elif HAL_CRY_USE_FALLBACK == TRUE
1349 return cry_fallback_SHA256_update(cryp, sha256ctxp, size, in);
1350#else
1351 (void)cryp;
1352 (void)sha256ctxp;
1353 (void)size;
1354 (void)in;
1355
1356 return CRY_ERR_INV_ALGO;
1357#endif
1358}
1359
1360/**
1361 * @brief Hash finalization using SHA256.
1362 *
1363 * @param[in] cryp pointer to the @p CRYDriver object
1364 * @param[in] sha256ctxp pointer to a SHA256 context
1365 * @param[out] out 256 bits output buffer
1366 * @return The operation status.
1367 * @retval CRY_NOERROR if the operation succeeded.
1368 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
1369 * device instance.
1370 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
1371 * dependent.
1372 *
1373 * @api
1374 */
1376 uint8_t *out) {
1377
1378 osalDbgCheck((cryp != NULL) && (sha256ctxp != NULL) && (out != NULL));
1379
1380 osalDbgAssert(cryp->state == CRY_READY, "not ready");
1381
1382#if CRY_LLD_SUPPORTS_SHA256 == TRUE
1383 return cry_lld_SHA256_final(cryp, sha256ctxp, out);
1384#elif HAL_CRY_USE_FALLBACK == TRUE
1385 return cry_fallback_SHA256_final(cryp, sha256ctxp, out);
1386#else
1387 (void)cryp;
1388 (void)sha256ctxp;
1389 (void)out;
1390
1391 return CRY_ERR_INV_ALGO;
1392#endif
1393}
1394
1395/**
1396 * @brief Hash initialization using SHA512.
1397 *
1398 * @param[in] cryp pointer to the @p CRYDriver object
1399 * @param[out] sha512ctxp pointer to a SHA512 context to be initialized
1400 * @return The operation status.
1401 * @retval CRY_NOERROR if the operation succeeded.
1402 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
1403 * device instance.
1404 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
1405 * dependent.
1406 *
1407 * @api
1408 */
1410
1411 osalDbgCheck((cryp != NULL) && (sha512ctxp != NULL));
1412
1413 osalDbgAssert(cryp->state == CRY_READY, "not ready");
1414
1415#if CRY_LLD_SUPPORTS_SHA512 == TRUE
1416 return cry_lld_SHA512_init(cryp, sha512ctxp);
1417#elif HAL_CRY_USE_FALLBACK == TRUE
1418 return cry_fallback_SHA512_init(cryp, sha512ctxp);
1419#else
1420 (void)cryp;
1421 (void)sha512ctxp;
1422
1423 return CRY_ERR_INV_ALGO;
1424#endif
1425}
1426
1427/**
1428 * @brief Hash update using SHA512.
1429 *
1430 * @param[in] cryp pointer to the @p CRYDriver object
1431 * @param[in] sha512ctxp pointer to a SHA512 context
1432 * @param[in] size size of input buffer
1433 * @param[in] in buffer containing the input text
1434 * @return The operation status.
1435 * @retval CRY_NOERROR if the operation succeeded.
1436 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
1437 * device instance.
1438 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
1439 * dependent.
1440 *
1441 * @api
1442 */
1444 size_t size, const uint8_t *in) {
1445
1446 osalDbgCheck((cryp != NULL) && (sha512ctxp != NULL) && (in != NULL));
1447
1448 osalDbgAssert(cryp->state == CRY_READY, "not ready");
1449
1450#if CRY_LLD_SUPPORTS_SHA512 == TRUE
1451 return cry_lld_SHA512_update(cryp, sha512ctxp, size, in);
1452#elif HAL_CRY_USE_FALLBACK == TRUE
1453 return cry_fallback_SHA512_update(cryp, sha512ctxp, size, in);
1454#else
1455 (void)cryp;
1456 (void)sha512ctxp;
1457 (void)size;
1458 (void)in;
1459
1460 return CRY_ERR_INV_ALGO;
1461#endif
1462}
1463
1464/**
1465 * @brief Hash finalization using SHA512.
1466 *
1467 * @param[in] cryp pointer to the @p CRYDriver object
1468 * @param[in] sha512ctxp pointer to a SHA512 context
1469 * @param[out] out 512 bits output buffer
1470 * @return The operation status.
1471 * @retval CRY_NOERROR if the operation succeeded.
1472 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
1473 * device instance.
1474 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
1475 * dependent.
1476 *
1477 * @api
1478 */
1480 uint8_t *out) {
1481
1482 osalDbgCheck((cryp != NULL) && (sha512ctxp != NULL) && (out != NULL));
1483
1484 osalDbgAssert(cryp->state == CRY_READY, "not ready");
1485
1486#if CRY_LLD_SUPPORTS_SHA512 == TRUE
1487 return cry_lld_SHA512_final(cryp, sha512ctxp, out);
1488#elif HAL_CRY_USE_FALLBACK == TRUE
1489 return cry_fallback_SHA512_final(cryp, sha512ctxp, out);
1490#else
1491 (void)cryp;
1492 (void)sha512ctxp;
1493 (void)out;
1494
1495 return CRY_ERR_INV_ALGO;
1496#endif
1497}
1498
1499/**
1500 * @brief Initializes the HMAC transient key.
1501 * @note It is the underlying implementation to decide which key sizes are
1502 * allowable.
1503 *
1504 * @param[in] cryp pointer to the @p CRYDriver object
1505 * @param[in] size key size in bytes
1506 * @param[in] keyp pointer to the key data
1507 * @return The operation status.
1508 * @retval CRY_NOERROR if the operation succeeded.
1509 * @retval CRY_ERR_INV_ALGO if the algorithm is unsupported.
1510 * @retval CRY_ERR_INV_KEY_SIZE if the specified key size is invalid for
1511 * the specified algorithm.
1512 *
1513 * @api
1514 */
1516 size_t size,
1517 const uint8_t *keyp) {
1518
1519 osalDbgCheck((cryp != NULL) && (keyp != NULL));
1520
1521#if (CRY_LLD_SUPPORTS_HMAC_SHA256 == TRUE) || \
1522 (CRY_LLD_SUPPORTS_HMAC_SHA512 == TRUE)
1523 return cry_lld_hmac_loadkey(cryp, size, keyp);
1524#elif HAL_CRY_USE_FALLBACK == TRUE
1525 return cry_fallback_hmac_loadkey(cryp, size, keyp);
1526#else
1527 (void)cryp;
1528 (void)size;
1529 (void)keyp;
1530
1531 return CRY_ERR_INV_ALGO;
1532#endif
1533}
1534
1535/**
1536 * @brief Hash initialization using HMAC_SHA256.
1537 *
1538 * @param[in] cryp pointer to the @p CRYDriver object
1539 * @param[out] hmacsha256ctxp pointer to a HMAC_SHA256 context to be
1540 * initialized
1541 * @return The operation status.
1542 * @retval CRY_NOERROR if the operation succeeded.
1543 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
1544 * device instance.
1545 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
1546 * dependent.
1547 *
1548 * @api
1549 */
1551 HMACSHA256Context *hmacsha256ctxp) {
1552
1553 osalDbgCheck((cryp != NULL) && (hmacsha256ctxp != NULL));
1554
1555 osalDbgAssert(cryp->state == CRY_READY, "not ready");
1556
1557#if CRY_LLD_SUPPORTS_HMAC_SHA256 == TRUE
1558 return cry_lld_HMACSHA256_init(cryp, hmacsha256ctxp);
1559#elif HAL_CRY_USE_FALLBACK == TRUE
1560 return cry_fallback_HMACSHA256_init(cryp, hmacsha256ctxp);
1561#else
1562 (void)cryp;
1563 (void)hmacsha256ctxp;
1564
1565 return CRY_ERR_INV_ALGO;
1566#endif
1567}
1568
1569/**
1570 * @brief Hash update using HMAC.
1571 *
1572 * @param[in] cryp pointer to the @p CRYDriver object
1573 * @param[in] hmacsha256ctxp pointer to a HMAC_SHA256 context
1574 * @param[in] size size of input buffer
1575 * @param[in] in buffer containing the input text
1576 * @return The operation status.
1577 * @retval CRY_NOERROR if the operation succeeded.
1578 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
1579 * device instance.
1580 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
1581 * dependent.
1582 *
1583 * @api
1584 */
1586 HMACSHA256Context *hmacsha256ctxp,
1587 size_t size,
1588 const uint8_t *in) {
1589
1590 osalDbgCheck((cryp != NULL) && (hmacsha256ctxp != NULL) && (in != NULL));
1591
1592 osalDbgAssert(cryp->state == CRY_READY, "not ready");
1593
1594#if CRY_LLD_SUPPORTS_HMAC_SHA256 == TRUE
1595 return cry_lld_HMACSHA256_update(cryp, hmacsha256ctxp, size, in);
1596#elif HAL_CRY_USE_FALLBACK == TRUE
1597 return cry_fallback_HMACSHA256_update(cryp, hmacsha256ctxp, size, in);
1598#else
1599 (void)cryp;
1600 (void)hmacsha256ctxp;
1601 (void)size;
1602 (void)in;
1603
1604 return CRY_ERR_INV_ALGO;
1605#endif
1606}
1607
1608/**
1609 * @brief Hash finalization using HMAC.
1610 *
1611 * @param[in] cryp pointer to the @p CRYDriver object
1612 * @param[in] hmacsha256ctxp pointer to a HMAC_SHA256 context
1613 * @param[out] out 256 bits output buffer
1614 * @return The operation status.
1615 * @retval CRY_NOERROR if the operation succeeded.
1616 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
1617 * device instance.
1618 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
1619 * dependent.
1620 *
1621 * @api
1622 */
1624 HMACSHA256Context *hmacsha256ctxp,
1625 uint8_t *out) {
1626
1627 osalDbgCheck((cryp != NULL) && (hmacsha256ctxp != NULL) && (out != NULL));
1628
1629 osalDbgAssert(cryp->state == CRY_READY, "not ready");
1630
1631#if CRY_LLD_SUPPORTS_HMAC_SHA256 == TRUE
1632 return cry_lld_HMACSHA256_final(cryp, hmacsha256ctxp, out);
1633#elif HAL_CRY_USE_FALLBACK == TRUE
1634 return cry_fallback_HMACSHA256_final(cryp, hmacsha256ctxp, out);
1635#else
1636 (void)cryp;
1637 (void)hmacsha256ctxp;
1638 (void)out;
1639
1640 return CRY_ERR_INV_ALGO;
1641#endif
1642}
1643
1644/**
1645 * @brief Hash initialization using HMAC_SHA512.
1646 *
1647 * @param[in] cryp pointer to the @p CRYDriver object
1648 * @param[out] hmacsha512ctxp pointer to a HMAC_SHA512 context to be
1649 * initialized
1650 * @return The operation status.
1651 * @retval CRY_NOERROR if the operation succeeded.
1652 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
1653 * device instance.
1654 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
1655 * dependent.
1656 *
1657 * @api
1658 */
1660 HMACSHA512Context *hmacsha512ctxp) {
1661
1662 osalDbgCheck((cryp != NULL) && (hmacsha512ctxp != NULL));
1663
1664 osalDbgAssert(cryp->state == CRY_READY, "not ready");
1665
1666#if CRY_LLD_SUPPORTS_HMAC_SHA512 == TRUE
1667 return cry_lld_HMACSHA512_init(cryp, hmacsha512ctxp);
1668#elif HAL_CRY_USE_FALLBACK == TRUE
1669 return cry_fallback_HMACSHA512_init(cryp, hmacsha512ctxp);
1670#else
1671 (void)cryp;
1672 (void)hmacsha512ctxp;
1673
1674 return CRY_ERR_INV_ALGO;
1675#endif
1676}
1677
1678/**
1679 * @brief Hash update using HMAC.
1680 *
1681 * @param[in] cryp pointer to the @p CRYDriver object
1682 * @param[in] hmacsha512ctxp pointer to a HMAC_SHA512 context
1683 * @param[in] size size of input buffer
1684 * @param[in] in buffer containing the input text
1685 * @return The operation status.
1686 * @retval CRY_NOERROR if the operation succeeded.
1687 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
1688 * device instance.
1689 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
1690 * dependent.
1691 *
1692 * @api
1693 */
1695 HMACSHA512Context *hmacsha512ctxp,
1696 size_t size,
1697 const uint8_t *in) {
1698
1699 osalDbgCheck((cryp != NULL) && (hmacsha512ctxp != NULL) && (in != NULL));
1700
1701 osalDbgAssert(cryp->state == CRY_READY, "not ready");
1702
1703#if CRY_LLD_SUPPORTS_HMAC_SHA512 == TRUE
1704 return cry_lld_HMACSHA512_update(cryp, hmacsha512ctxp, size, in);
1705#elif HAL_CRY_USE_FALLBACK == TRUE
1706 return cry_fallback_HMACSHA512_update(cryp, hmacsha512ctxp, size, in);
1707#else
1708 (void)cryp;
1709 (void)hmacsha512ctxp;
1710 (void)size;
1711 (void)in;
1712
1713 return CRY_ERR_INV_ALGO;
1714#endif
1715}
1716
1717/**
1718 * @brief Hash finalization using HMAC.
1719 *
1720 * @param[in] cryp pointer to the @p CRYDriver object
1721 * @param[in] hmacsha512ctxp pointer to a HMAC_SHA512 context
1722 * @param[out] out 512 bits output buffer
1723 * @return The operation status.
1724 * @retval CRY_NOERROR if the operation succeeded.
1725 * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
1726 * device instance.
1727 * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation
1728 * dependent.
1729 *
1730 * @api
1731 */
1733 HMACSHA512Context *hmacsha512ctxp,
1734 uint8_t *out) {
1735
1736 osalDbgCheck((cryp != NULL) && (hmacsha512ctxp != NULL) && (out != NULL));
1737
1738 osalDbgAssert(cryp->state == CRY_READY, "not ready");
1739
1740#if CRY_LLD_SUPPORTS_HMAC_SHA512 == TRUE
1741 return cry_lld_HMACSHA512_final(cryp, hmacsha512ctxp, out);
1742#elif HAL_CRY_USE_FALLBACK == TRUE
1743 return cry_fallback_HMACSHA512_final(cryp, hmacsha512ctxp, out);
1744#else
1745 (void)cryp;
1746 (void)hmacsha512ctxp;
1747 (void)out;
1748
1749 return CRY_ERR_INV_ALGO;
1750#endif
1751}
1752
1753#endif /* HAL_USE_CRY == TRUE */
1754
1755/** @} */
cryerror_t crySHA256Update(CRYDriver *cryp, SHA256Context *sha256ctxp, size_t size, const uint8_t *in)
Hash update using SHA256.
cryerror_t cryDecryptDES(CRYDriver *cryp, crykey_t key_id, const uint8_t *in, uint8_t *out)
Decryption of a single block using (T)DES.
Definition hal_crypto.c:948
cryerror_t cry_lld_decrypt_AES_ECB(CRYDriver *cryp, crykey_t key_id, size_t size, const uint8_t *in, uint8_t *out)
Decryption operation using AES-ECB.
cryerror_t cry_lld_encrypt_AES_ECB(CRYDriver *cryp, crykey_t key_id, size_t size, const uint8_t *in, uint8_t *out)
Encryption operation using AES-ECB.
cryerror_t crySHA512Final(CRYDriver *cryp, SHA512Context *sha512ctxp, uint8_t *out)
Hash finalization using SHA512.
cryerror_t crySHA512Update(CRYDriver *cryp, SHA512Context *sha512ctxp, size_t size, const uint8_t *in)
Hash update using SHA512.
cryerror_t cry_lld_HMACSHA256_init(CRYDriver *cryp, HMACSHA256Context *hmacsha256ctxp)
Hash initialization using HMAC_SHA256.
cryerror_t cryEncryptAES(CRYDriver *cryp, crykey_t key_id, const uint8_t *in, uint8_t *out)
Encryption of a single block using AES.
Definition hal_crypto.c:205
cryerror_t cryEncryptAES_GCM(CRYDriver *cryp, crykey_t key_id, size_t auth_size, const uint8_t *auth_in, size_t text_size, const uint8_t *text_in, uint8_t *text_out, const uint8_t *iv, size_t tag_size, uint8_t *tag_out)
Encryption operation using AES-GCM.
Definition hal_crypto.c:727
cryerror_t cry_lld_decrypt_AES_CTR(CRYDriver *cryp, crykey_t key_id, size_t size, const uint8_t *in, uint8_t *out, const uint8_t *iv)
Decryption operation using AES-CTR.
cryerror_t cryEncryptDES_ECB(CRYDriver *cryp, crykey_t key_id, size_t size, const uint8_t *in, uint8_t *out)
Encryption operation using (T)DES-ECB.
Definition hal_crypto.c:997
cryerror_t cry_lld_HMACSHA512_final(CRYDriver *cryp, HMACSHA512Context *hmacsha512ctxp, uint8_t *out)
Hash finalization using HMAC.
void cry_lld_start(CRYDriver *cryp)
Configures and activates the crypto peripheral.
cryerror_t cry_lld_encrypt_DES_CBC(CRYDriver *cryp, crykey_t key_id, size_t size, const uint8_t *in, uint8_t *out, const uint8_t *iv)
Encryption operation using (T)DES-CBC.
cryerror_t cryEncryptAES_ECB(CRYDriver *cryp, crykey_t key_id, size_t size, const uint8_t *in, uint8_t *out)
Encryption operation using AES-ECB.
Definition hal_crypto.c:300
cryerror_t cryDecryptDES_CBC(CRYDriver *cryp, crykey_t key_id, size_t size, const uint8_t *in, uint8_t *out, const uint8_t *iv)
Decryption operation using (T)DES-CBC.
cryerror_t cry_lld_encrypt_AES_CBC(CRYDriver *cryp, crykey_t key_id, size_t size, const uint8_t *in, uint8_t *out, const uint8_t *iv)
Encryption operation using AES-CBC.
cryerror_t crySHA1Init(CRYDriver *cryp, SHA1Context *sha1ctxp)
Hash initialization using SHA1.
cryerror_t cry_lld_SHA1_update(CRYDriver *cryp, SHA1Context *sha1ctxp, size_t size, const uint8_t *in)
Hash update using SHA1.
cryerror_t cryEncryptAES_CBC(CRYDriver *cryp, crykey_t key_id, size_t size, const uint8_t *in, uint8_t *out, const uint8_t *iv)
Encryption operation using AES-CBC.
Definition hal_crypto.c:405
cryerror_t cry_lld_decrypt_DES(CRYDriver *cryp, crykey_t key_id, const uint8_t *in, uint8_t *out)
Decryption of a single block using (T)DES.
cryerror_t cryHMACSHA512Init(CRYDriver *cryp, HMACSHA512Context *hmacsha512ctxp)
Hash initialization using HMAC_SHA512.
cryerror_t cryHMACSHA256Update(CRYDriver *cryp, HMACSHA256Context *hmacsha256ctxp, size_t size, const uint8_t *in)
Hash update using HMAC.
cryerror_t cry_lld_decrypt_AES(CRYDriver *cryp, crykey_t key_id, const uint8_t *in, uint8_t *out)
Decryption of a single block using AES.
cryerror_t cryDecryptAES_GCM(CRYDriver *cryp, crykey_t key_id, size_t auth_size, const uint8_t *auth_in, size_t text_size, const uint8_t *text_in, uint8_t *text_out, const uint8_t *iv, size_t tag_size, const uint8_t *tag_in)
Decryption operation using AES-GCM.
Definition hal_crypto.c:800
cryerror_t cry_lld_encrypt_AES_GCM(CRYDriver *cryp, crykey_t key_id, size_t auth_size, const uint8_t *auth_in, size_t text_size, const uint8_t *text_in, uint8_t *text_out, const uint8_t *iv, size_t tag_size, uint8_t *tag_out)
Encryption operation using AES-GCM.
cryerror_t cry_lld_SHA512_init(CRYDriver *cryp, SHA512Context *sha512ctxp)
Hash initialization using SHA512.
cryerror_t cry_lld_SHA256_update(CRYDriver *cryp, SHA256Context *sha256ctxp, size_t size, const uint8_t *in)
Hash update using SHA256.
cryerror_t cryLoadDESTransientKey(CRYDriver *cryp, size_t size, const uint8_t *keyp)
Initializes the DES transient key.
Definition hal_crypto.c:859
cryerror_t cry_lld_decrypt_AES_CBC(CRYDriver *cryp, crykey_t key_id, size_t size, const uint8_t *in, uint8_t *out, const uint8_t *iv)
Decryption operation using AES-CBC.
void cry_lld_init(void)
Low level crypto driver initialization.
cryerror_t cryDecryptAES(CRYDriver *cryp, crykey_t key_id, const uint8_t *in, uint8_t *out)
Decryption of a single block using AES.
Definition hal_crypto.c:251
void cryObjectInit(CRYDriver *cryp)
Initializes the standard part of a CRYDriver structure.
Definition hal_crypto.c:70
cryerror_t cry_lld_aes_loadkey(CRYDriver *cryp, size_t size, const uint8_t *keyp)
Initializes the AES transient key.
cryerror_t cry_lld_des_loadkey(CRYDriver *cryp, size_t size, const uint8_t *keyp)
Initializes the DES transient key.
cryerror_t cryDecryptAES_CFB(CRYDriver *cryp, crykey_t key_id, size_t size, const uint8_t *in, uint8_t *out, const uint8_t *iv)
Decryption operation using AES-CFB.
Definition hal_crypto.c:564
cryerror_t cryEncryptAES_CFB(CRYDriver *cryp, crykey_t key_id, size_t size, const uint8_t *in, uint8_t *out, const uint8_t *iv)
Encryption operation using AES-CFB.
Definition hal_crypto.c:512
uint32_t crykey_t
CRY key identifier type.
cryerror_t cryDecryptDES_ECB(CRYDriver *cryp, crykey_t key_id, size_t size, const uint8_t *in, uint8_t *out)
Decryption operation using (T)DES-ECB.
cryerror_t cry_lld_HMACSHA256_final(CRYDriver *cryp, HMACSHA256Context *hmacsha256ctxp, uint8_t *out)
Hash finalization using HMAC.
cryerror_t cry_lld_encrypt_AES_CFB(CRYDriver *cryp, crykey_t key_id, size_t size, const uint8_t *in, uint8_t *out, const uint8_t *iv)
Encryption operation using AES-CFB.
cryerror_t cryEncryptAES_CTR(CRYDriver *cryp, crykey_t key_id, size_t size, const uint8_t *in, uint8_t *out, const uint8_t *iv)
Encryption operation using AES-CTR.
Definition hal_crypto.c:617
cryerror_t cry_lld_HMACSHA256_update(CRYDriver *cryp, HMACSHA256Context *hmacsha256ctxp, size_t size, const uint8_t *in)
Hash update using HMAC.
cryerror_t cry_lld_encrypt_DES(CRYDriver *cryp, crykey_t key_id, const uint8_t *in, uint8_t *out)
Encryption of a single block using (T)DES.
cryerror_t cryDecryptAES_CBC(CRYDriver *cryp, crykey_t key_id, size_t size, const uint8_t *in, uint8_t *out, const uint8_t *iv)
Decryption operation using AES-CBC.
Definition hal_crypto.c:460
cryerror_t crySHA1Update(CRYDriver *cryp, SHA1Context *sha1ctxp, size_t size, const uint8_t *in)
Hash update using SHA1.
cryerror_t cry_lld_HMACSHA512_update(CRYDriver *cryp, HMACSHA512Context *hmacsha512ctxp, size_t size, const uint8_t *in)
Hash update using HMAC.
cryerror_t cry_lld_decrypt_AES_CFB(CRYDriver *cryp, crykey_t key_id, size_t size, const uint8_t *in, uint8_t *out, const uint8_t *iv)
Decryption operation using AES-CFB.
cryerror_t cry_lld_decrypt_DES_ECB(CRYDriver *cryp, crykey_t key_id, size_t size, const uint8_t *in, uint8_t *out)
Decryption operation using (T)DES-ECB.
cryerror_t cryHMACSHA512Final(CRYDriver *cryp, HMACSHA512Context *hmacsha512ctxp, uint8_t *out)
Hash finalization using HMAC.
void cryInit(void)
Cryptographic Driver initialization.
Definition hal_crypto.c:56
cryerror_t crySHA256Final(CRYDriver *cryp, SHA256Context *sha256ctxp, uint8_t *out)
Hash finalization using SHA256.
cryerror_t cry_lld_encrypt_AES(CRYDriver *cryp, crykey_t key_id, const uint8_t *in, uint8_t *out)
Encryption of a single block using AES.
cryerror_t cry_lld_hmac_loadkey(CRYDriver *cryp, size_t size, const uint8_t *keyp)
Initializes the HMAC transient key.
cryerror_t cry_lld_encrypt_AES_CTR(CRYDriver *cryp, crykey_t key_id, size_t size, const uint8_t *in, uint8_t *out, const uint8_t *iv)
Encryption operation using AES-CTR.
cryerror_t cry_lld_SHA256_init(CRYDriver *cryp, SHA256Context *sha256ctxp)
Hash initialization using SHA256.
cryerror_t cry_lld_encrypt_DES_ECB(CRYDriver *cryp, crykey_t key_id, size_t size, const uint8_t *in, uint8_t *out)
Encryption operation using (T)DES-ECB.
cryerror_t cry_lld_SHA512_update(CRYDriver *cryp, SHA512Context *sha512ctxp, size_t size, const uint8_t *in)
Hash update using SHA512.
cryerror_t cry_lld_decrypt_DES_CBC(CRYDriver *cryp, crykey_t key_id, size_t size, const uint8_t *in, uint8_t *out, const uint8_t *iv)
Decryption operation using (T)DES-CBC.
cryerror_t cry_lld_SHA1_final(CRYDriver *cryp, SHA1Context *sha1ctxp, uint8_t *out)
Hash finalization using SHA1.
cryerror_t cry_lld_SHA512_final(CRYDriver *cryp, SHA512Context *sha512ctxp, uint8_t *out)
Hash finalization using SHA512.
cryerror_t cryDecryptAES_CTR(CRYDriver *cryp, crykey_t key_id, size_t size, const uint8_t *in, uint8_t *out, const uint8_t *iv)
Decryption operation using AES-CTR.
Definition hal_crypto.c:670
cryerror_t cryLoadHMACTransientKey(CRYDriver *cryp, size_t size, const uint8_t *keyp)
Initializes the HMAC transient key.
void cry_lld_stop(CRYDriver *cryp)
Deactivates the crypto peripheral.
cryerror_t cryHMACSHA256Final(CRYDriver *cryp, HMACSHA256Context *hmacsha256ctxp, uint8_t *out)
Hash finalization using HMAC.
cryerror_t crySHA1Final(CRYDriver *cryp, SHA1Context *sha1ctxp, uint8_t *out)
Hash finalization using SHA1.
cryerror_t crySHA256Init(CRYDriver *cryp, SHA256Context *sha256ctxp)
Hash initialization using SHA256.
cryerror_t
Driver error codes.
Definition hal_crypto.h:89
cryerror_t crySHA512Init(CRYDriver *cryp, SHA512Context *sha512ctxp)
Hash initialization using SHA512.
void cryStop(CRYDriver *cryp)
Deactivates the cryptographic peripheral.
Definition hal_crypto.c:129
cryerror_t cry_lld_decrypt_AES_GCM(CRYDriver *cryp, crykey_t key_id, size_t auth_size, const uint8_t *auth_in, size_t text_size, const uint8_t *text_in, uint8_t *text_out, const uint8_t *iv, size_t tag_size, const uint8_t *tag_in)
Decryption operation using AES-GCM.
cryerror_t cryHMACSHA512Update(CRYDriver *cryp, HMACSHA512Context *hmacsha512ctxp, size_t size, const uint8_t *in)
Hash update using HMAC.
cryerror_t cry_lld_SHA256_final(CRYDriver *cryp, SHA256Context *sha256ctxp, uint8_t *out)
Hash finalization using SHA256.
cryerror_t cryLoadAESTransientKey(CRYDriver *cryp, size_t size, const uint8_t *keyp)
Initializes the AES transient key.
Definition hal_crypto.c:163
cryerror_t cryDecryptAES_ECB(CRYDriver *cryp, crykey_t key_id, size_t size, const uint8_t *in, uint8_t *out)
Decryption operation using AES-ECB.
Definition hal_crypto.c:352
cryerror_t cryEncryptDES_CBC(CRYDriver *cryp, crykey_t key_id, size_t size, const uint8_t *in, uint8_t *out, const uint8_t *iv)
Encryption operation using (T)DES-CBC.
cryerror_t cryEncryptDES(CRYDriver *cryp, crykey_t key_id, const uint8_t *in, uint8_t *out)
Encryption of a single block using (T)DES.
Definition hal_crypto.c:901
cryerror_t cry_lld_HMACSHA512_init(CRYDriver *cryp, HMACSHA512Context *hmacsha512ctxp)
Hash initialization using HMAC_SHA512.
msg_t cryStart(CRYDriver *cryp, const CRYConfig *config)
Configures and activates the cryptographic peripheral.
Definition hal_crypto.c:89
cryerror_t cryHMACSHA256Init(CRYDriver *cryp, HMACSHA256Context *hmacsha256ctxp)
Hash initialization using HMAC_SHA256.
cryerror_t cry_lld_SHA1_init(CRYDriver *cryp, SHA1Context *sha1ctxp)
Hash initialization using SHA1.
@ CRY_READY
Definition hal_crypto.h:83
@ CRY_STOP
Definition hal_crypto.h:82
@ CRY_ERR_INV_ALGO
Definition hal_crypto.h:91
#define HAL_RET_SUCCESS
Definition hal.h:93
static void osalSysLock(void)
Enters a critical zone from thread context.
Definition osal.h:601
static void osalSysUnlock(void)
Leaves a critical zone from thread context.
Definition osal.h:611
#define osalDbgAssert(c, remark)
Condition assertion.
Definition osal.h:264
#define osalDbgCheck(c)
Function parameters check.
Definition osal.h:284
int32_t msg_t
Definition chearly.h:88
HAL subsystem header.
USBOutEndpointState out
OUT EP0 state.
Definition hal_usb_lld.c:61
USBInEndpointState in
IN EP0 state.
Definition hal_usb_lld.c:57
Driver configuration structure.
Structure representing an CRY driver.
const CRYConfig * config
Current configuration data.
crystate_t state
Driver state.
Type of a HMAC_SHA256 context.
Definition hal_crypto.h:195
Type of a HMAC_SHA512 context.
Definition hal_crypto.h:203
Type of a SHA1 context.
Definition hal_crypto.h:171
Type of a SHA256 context.
Definition hal_crypto.h:179
Type of a SHA512 context.
Definition hal_crypto.h:187