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