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