ChibiOS/HAL  6.1.0
hal_crypto_lld.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_lld.c
19  * @brief PLATFORM cryptographic subsystem low level driver source.
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 /** @brief CRY1 driver identifier.*/
38 #if PLATFORM_CRY_USE_CRY1 || defined(__DOXYGEN__)
40 #endif
41 
42 /*===========================================================================*/
43 /* Driver local variables and types. */
44 /*===========================================================================*/
45 
46 /*===========================================================================*/
47 /* Driver local functions. */
48 /*===========================================================================*/
49 
50 /*===========================================================================*/
51 /* Driver interrupt handlers. */
52 /*===========================================================================*/
53 
54 /*===========================================================================*/
55 /* Driver exported functions. */
56 /*===========================================================================*/
57 
58 /**
59  * @brief Low level crypto driver initialization.
60  *
61  * @notapi
62  */
63 void cry_lld_init(void) {
64 
65 }
66 
67 /**
68  * @brief Configures and activates the crypto peripheral.
69  *
70  * @param[in] cryp pointer to the @p CRYDriver object
71  *
72  * @notapi
73  */
74 void cry_lld_start(CRYDriver *cryp) {
75 
76  if (cryp->state == CRY_STOP) {
77 
78  }
79 }
80 
81 /**
82  * @brief Deactivates the crypto peripheral.
83  *
84  * @param[in] cryp pointer to the @p CRYDriver object
85  *
86  * @notapi
87  */
88 void cry_lld_stop(CRYDriver *cryp) {
89 
90  if (cryp->state == CRY_READY) {
91 
92  }
93 }
94 
95 /**
96  * @brief Initializes the transient key for a specific algorithm.
97  *
98  * @param[in] cryp pointer to the @p CRYDriver object
99  * @param[in] algorithm the algorithm identifier
100  * @param[in] size key size in bytes
101  * @param[in] keyp pointer to the key data
102  * @return The operation status.
103  * @retval CRY_NOERROR if the operation succeeded.
104  * @retval CRY_ERR_INV_ALGO if the specified algorithm is unknown or
105  * unsupported.
106  * @retval CRY_ERR_INV_KEY_SIZE if the specified key size is invalid.
107  *
108  * @notapi
109  */
111  cryalgorithm_t algorithm,
112  size_t size,
113  const uint8_t *keyp) {
114 
115  (void)cryp;
116  (void)algorithm;
117  (void)size;
118  (void)keyp;
119 
120  return CRY_NOERROR;
121 }
122 
123 /**
124  * @brief Encryption of a single block using AES.
125  * @note The implementation of this function must guarantee that it can
126  * be called from any context.
127  *
128  * @param[in] cryp pointer to the @p CRYDriver object
129  * @param[in] key_id the key to be used for the operation, zero is
130  * the transient key, other values are keys stored
131  * in an unspecified way
132  * @param[in] in buffer containing the input plaintext
133  * @param[out] out buffer for the output cyphertext
134  * @return The operation status.
135  * @retval CRY_NOERROR if the operation succeeded.
136  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
137  * device instance.
138  * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
139  * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
140  * or refers to an empty key slot.
141  *
142  * @notapi
143  */
145  crykey_t key_id,
146  const uint8_t *in,
147  uint8_t *out) {
148 
149  (void)cryp;
150  (void)key_id;
151  (void)in;
152  (void)out;
153 
154  return CRY_ERR_INV_ALGO;
155 }
156 
157 /**
158  * @brief Decryption of a single block using AES.
159  * @note The implementation of this function must guarantee that it can
160  * be called from any context.
161  *
162  * @param[in] cryp pointer to the @p CRYDriver object
163  * @param[in] key_id the key to be used for the operation, zero is
164  * the transient key, other values are keys stored
165  * in an unspecified way
166  * @param[in] in buffer containing the input cyphertext
167  * @param[out] out buffer for the output plaintext
168  * @return The operation status.
169  * @retval CRY_NOERROR if the operation succeeded.
170  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
171  * device instance.
172  * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
173  * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
174  * or refers to an empty key slot.
175  *
176  * @notapi
177  */
179  crykey_t key_id,
180  const uint8_t *in,
181  uint8_t *out) {
182 
183  (void)cryp;
184  (void)key_id;
185  (void)in;
186  (void)out;
187 
188  return CRY_ERR_INV_ALGO;
189 }
190 
191 /**
192  * @brief Encryption operation using AES-ECB.
193  * @note The function operates on data buffers whose lenght is a multiple
194  * of an AES block, this means that padding must be done by the
195  * caller.
196  *
197  * @param[in] cryp pointer to the @p CRYDriver object
198  * @param[in] key_id the key to be used for the operation, zero is
199  * the transient key, other values are keys stored
200  * in an unspecified way
201  * @param[in] size size of the plaintext buffer, this number must
202  * be a multiple of the selected key size
203  * @param[in] in buffer containing the input plaintext
204  * @param[out] out buffer for the output cyphertext
205  * @return The operation status.
206  * @retval CRY_NOERROR if the operation succeeded.
207  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
208  * device instance.
209  * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
210  * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
211  * or refers to an empty key slot.
212  *
213  * @notapi
214  */
216  crykey_t key_id,
217  size_t size,
218  const uint8_t *in,
219  uint8_t *out) {
220 
221  (void)cryp;
222  (void)key_id;
223  (void)size;
224  (void)in;
225  (void)out;
226 
227  return CRY_ERR_INV_ALGO;
228 }
229 
230 /**
231  * @brief Decryption operation using AES-ECB.
232  * @note The function operates on data buffers whose lenght is a multiple
233  * of an AES block, this means that padding must be done by the
234  * caller.
235  *
236  * @param[in] cryp pointer to the @p CRYDriver object
237  * @param[in] key_id the key to be used for the operation, zero is
238  * the transient key, other values are keys stored
239  * in an unspecified way
240  * @param[in] size size of the plaintext buffer, this number must
241  * be a multiple of the selected key size
242  * @param[in] in buffer containing the input plaintext
243  * @param[out] out buffer for the output cyphertext
244  * @return The operation status.
245  * @retval CRY_NOERROR if the operation succeeded.
246  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
247  * device instance.
248  * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
249  * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
250  * or refers to an empty key slot.
251  *
252  * @notapi
253  */
255  crykey_t key_id,
256  size_t size,
257  const uint8_t *in,
258  uint8_t *out) {
259 
260  (void)cryp;
261  (void)key_id;
262  (void)size;
263  (void)in;
264  (void)out;
265 
266  return CRY_ERR_INV_ALGO;
267 }
268 
269 /**
270  * @brief Encryption operation using AES-CBC.
271  * @note The function operates on data buffers whose lenght is a multiple
272  * of an AES block, this means that padding must be done by the
273  * caller.
274  *
275  * @param[in] cryp pointer to the @p CRYDriver object
276  * @param[in] key_id the key to be used for the operation, zero is
277  * the transient key, other values are keys stored
278  * in an unspecified way
279  * @param[in] size size of the plaintext buffer, this number must
280  * be a multiple of the selected key size
281  * @param[in] in buffer containing the input plaintext
282  * @param[out] out buffer for the output cyphertext
283  * @param[in] iv 128 bits initial vector
284  * @return The operation status.
285  * @retval CRY_NOERROR if the operation succeeded.
286  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
287  * device instance.
288  * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
289  * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
290  * or refers to an empty key slot.
291  *
292  * @notapi
293  */
295  crykey_t key_id,
296  size_t size,
297  const uint8_t *in,
298  uint8_t *out,
299  const uint8_t *iv) {
300 
301  (void)cryp;
302  (void)key_id;
303  (void)size;
304  (void)in;
305  (void)out;
306  (void)iv;
307 
308  return CRY_ERR_INV_ALGO;
309 }
310 
311 /**
312  * @brief Decryption operation using AES-CBC.
313  * @note The function operates on data buffers whose lenght is a multiple
314  * of an AES block, this means that padding must be done by the
315  * caller.
316  *
317  * @param[in] cryp pointer to the @p CRYDriver object
318  * @param[in] key_id the key to be used for the operation, zero is
319  * the transient key, other values are keys stored
320  * in an unspecified way
321  * @param[in] size size of the plaintext buffer, this number must
322  * be a multiple of the selected key size
323  * @param[in] in buffer containing the input plaintext
324  * @param[out] out buffer for the output cyphertext
325  * @param[in] iv 128 bits initial vector
326  * @return The operation status.
327  * @retval CRY_NOERROR if the operation succeeded.
328  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
329  * device instance.
330  * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
331  * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
332  * or refers to an empty key slot.
333  *
334  * @notapi
335  */
337  crykey_t key_id,
338  size_t size,
339  const uint8_t *in,
340  uint8_t *out,
341  const uint8_t *iv) {
342 
343  (void)cryp;
344  (void)key_id;
345  (void)size;
346  (void)in;
347  (void)out;
348  (void)iv;
349 
350  return CRY_ERR_INV_ALGO;
351 }
352 
353 /**
354  * @brief Encryption operation using AES-CFB.
355  * @note The function operates on data buffers whose lenght is a multiple
356  * of an AES block, this means that padding must be done by the
357  * caller.
358  *
359  * @param[in] cryp pointer to the @p CRYDriver object
360  * @param[in] key_id the key to be used for the operation, zero is
361  * the transient key, other values are keys stored
362  * in an unspecified way
363  * @param[in] size size of the plaintext buffer, this number must
364  * be a multiple of the selected key size
365  * @param[in] in buffer containing the input plaintext
366  * @param[out] out buffer for the output cyphertext
367  * @param[in] iv 128 bits initial vector
368  * @return The operation status.
369  * @retval CRY_NOERROR if the operation succeeded.
370  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
371  * device instance.
372  * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
373  * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
374  * or refers to an empty key slot.
375  *
376  * @notapi
377  */
379  crykey_t key_id,
380  size_t size,
381  const uint8_t *in,
382  uint8_t *out,
383  const uint8_t *iv) {
384 
385  (void)cryp;
386  (void)key_id;
387  (void)size;
388  (void)in;
389  (void)out;
390  (void)iv;
391 
392  return CRY_ERR_INV_ALGO;
393 }
394 
395 /**
396  * @brief Decryption operation using AES-CFB.
397  * @note The function operates on data buffers whose lenght is a multiple
398  * of an AES block, this means that padding must be done by the
399  * caller.
400  *
401  * @param[in] cryp pointer to the @p CRYDriver object
402  * @param[in] key_id the key to be used for the operation, zero is
403  * the transient key, other values are keys stored
404  * in an unspecified way
405  * @param[in] size size of the plaintext buffer, this number must
406  * be a multiple of the selected key size
407  * @param[in] in buffer containing the input plaintext
408  * @param[out] out buffer for the output cyphertext
409  * @param[in] iv 128 bits initial vector
410  * @return The operation status.
411  * @retval CRY_NOERROR if the operation succeeded.
412  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
413  * device instance.
414  * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
415  * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
416  * or refers to an empty key slot.
417  *
418  * @notapi
419  */
421  crykey_t key_id,
422  size_t size,
423  const uint8_t *in,
424  uint8_t *out,
425  const uint8_t *iv) {
426 
427  (void)cryp;
428  (void)key_id;
429  (void)size;
430  (void)in;
431  (void)out;
432  (void)iv;
433 
434  return CRY_ERR_INV_ALGO;
435 }
436 
437 /**
438  * @brief Encryption operation using AES-CTR.
439  * @note The function operates on data buffers whose lenght is a multiple
440  * of an AES block, this means that padding must be done by the
441  * caller.
442  *
443  * @param[in] cryp pointer to the @p CRYDriver object
444  * @param[in] key_id the key to be used for the operation, zero is
445  * the transient key, other values are keys stored
446  * in an unspecified way
447  * @param[in] size size of the plaintext buffer, this number must
448  * be a multiple of 16
449  * @param[in] in buffer containing the input plaintext
450  * @param[out] out buffer for the output cyphertext
451  * @param[in] iv 128 bits initial vector + counter, it contains
452  * a 96 bits IV and a 32 bits counter
453  * @return The operation status.
454  * @retval CRY_NOERROR if the operation succeeded.
455  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
456  * device instance.
457  * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
458  * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
459  * or refers to an empty key slot.
460  *
461  * @notapi
462  */
464  crykey_t key_id,
465  size_t size,
466  const uint8_t *in,
467  uint8_t *out,
468  const uint8_t *iv) {
469 
470  (void)cryp;
471  (void)key_id;
472  (void)size;
473  (void)in;
474  (void)out;
475  (void)iv;
476 
477  return CRY_ERR_INV_ALGO;
478 }
479 
480 /**
481  * @brief Decryption operation using AES-CTR.
482  * @note The function operates on data buffers whose lenght is a multiple
483  * of an AES block, this means that padding must be done by the
484  * caller.
485  *
486  * @param[in] cryp pointer to the @p CRYDriver object
487  * @param[in] key_id the key to be used for the operation, zero is
488  * the transient key, other values are keys stored
489  * in an unspecified way
490  * @param[in] size size of the plaintext buffer, this number must
491  * be a multiple of 16
492  * @param[in] in buffer containing the input cyphertext
493  * @param[out] out buffer for the output plaintext
494  * @param[in] iv 128 bits initial vector + counter, it contains
495  * a 96 bits IV and a 32 bits counter
496  * @return The operation status.
497  * @retval CRY_NOERROR if the operation succeeded.
498  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
499  * device instance.
500  * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
501  * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
502  * or refers to an empty key slot.
503  *
504  * @notapi
505  */
507  crykey_t key_id,
508  size_t size,
509  const uint8_t *in,
510  uint8_t *out,
511  const uint8_t *iv) {
512 
513  (void)cryp;
514  (void)key_id;
515  (void)size;
516  (void)in;
517  (void)out;
518  (void)iv;
519 
520  return CRY_ERR_INV_ALGO;
521 }
522 
523 /**
524  * @brief Encryption operation using AES-GCM.
525  * @note The function operates on data buffers whose lenght is a multiple
526  * of an AES block, this means that padding must be done by the
527  * caller.
528  *
529  * @param[in] cryp pointer to the @p CRYDriver object
530  * @param[in] key_id the key to be used for the operation, zero is
531  * the transient key, other values are keys stored
532  * in an unspecified way
533  * @param[in] size size of the text buffers, this number must be a
534  * multiple of 16
535  * @param[in] in buffer containing the input plaintext
536  * @param[out] out buffer for the output cyphertext
537  * @param[in] iv 128 bits initial vector + counter, it contains
538  * a 96 bits IV and a 32 bits counter
539  * @param[in] aadsize size of the authentication data, this number
540  * must be a multiple of 16
541  * @param[in] aad buffer containing the authentication data
542  * @param[in] authtag 128 bits buffer for the generated authentication
543  * tag
544  * @return The operation status.
545  * @retval CRY_NOERROR if the operation succeeded.
546  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
547  * device instance.
548  * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
549  * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
550  * or refers to an empty key slot.
551  *
552  * @notapi
553  */
555  crykey_t key_id,
556  size_t size,
557  const uint8_t *in,
558  uint8_t *out,
559  const uint8_t *iv,
560  size_t aadsize,
561  const uint8_t *aad,
562  uint8_t *authtag) {
563 
564  (void)cryp;
565  (void)key_id;
566  (void)size;
567  (void)in;
568  (void)out;
569  (void)iv;
570  (void)aadsize;
571  (void)aad;
572  (void)authtag;
573 
574  return CRY_ERR_INV_ALGO;
575 }
576 
577 /**
578  * @brief Decryption operation using AES-GCM.
579  * @note The function operates on data buffers whose lenght is a multiple
580  * of an AES block, this means that padding must be done by the
581  * caller.
582  *
583  * @param[in] cryp pointer to the @p CRYDriver object
584  * @param[in] key_id the key to be used for the operation, zero is
585  * the transient key, other values are keys stored
586  * in an unspecified way
587  * @param[in] size size of the text buffers, this number must be a
588  * multiple of 16
589  * @param[in] in buffer for the output cyphertext
590  * @param[out] out buffer containing the input plaintext
591  * @param[in] iv 128 bits initial vector + counter, it contains
592  * a 96 bits IV and a 32 bits counter
593  * @param[in] aadsize size of the authentication data, this number
594  * must be a multiple of 16
595  * @param[in] aad buffer containing the authentication data
596  * @param[in] authtag 128 bits buffer for the generated authentication
597  * tag
598  * @return The operation status.
599  * @retval CRY_NOERROR if the operation succeeded.
600  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
601  * device instance.
602  * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
603  * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
604  * or refers to an empty key slot.
605  *
606  * @notapi
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  size_t aadsize,
615  const uint8_t *aad,
616  uint8_t *authtag) {
617 
618  (void)cryp;
619  (void)key_id;
620  (void)size;
621  (void)in;
622  (void)out;
623  (void)iv;
624  (void)aadsize;
625  (void)aad;
626  (void)authtag;
627 
628  return CRY_ERR_INV_ALGO;
629 }
630 
631 /**
632  * @brief Encryption of a single block using (T)DES.
633  * @note The implementation of this function must guarantee that it can
634  * be called from any context.
635  *
636  * @param[in] cryp pointer to the @p CRYDriver object
637  * @param[in] key_id the key to be used for the operation, zero is
638  * the transient key, other values are keys stored
639  * in an unspecified way
640  * @param[in] in buffer containing the input plaintext
641  * @param[out] out buffer for the output cyphertext
642  * @return The operation status.
643  * @retval CRY_NOERROR if the operation succeeded.
644  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
645  * device instance.
646  * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
647  * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
648  * or refers to an empty key slot.
649  *
650  * @notapi
651  */
653  crykey_t key_id,
654  const uint8_t *in,
655  uint8_t *out) {
656 
657  (void)cryp;
658  (void)key_id;
659  (void)in;
660  (void)out;
661 
662  return CRY_ERR_INV_ALGO;
663 }
664 
665 /**
666  * @brief Decryption of a single block using (T)DES.
667  * @note The implementation of this function must guarantee that it can
668  * be called from any context.
669  *
670  *
671  * @param[in] cryp pointer to the @p CRYDriver object
672  * @param[in] key_id the key to be used for the operation, zero is
673  * the transient key, other values are keys stored
674  * in an unspecified way
675  * @param[in] in buffer containing the input cyphertext
676  * @param[out] out buffer for the output plaintext
677  * @return The operation status.
678  * @retval CRY_NOERROR if the operation succeeded.
679  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
680  * device instance.
681  * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
682  * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
683  * or refers to an empty key slot.
684  *
685  * @notapi
686  */
688  crykey_t key_id,
689  const uint8_t *in,
690  uint8_t *out) {
691 
692  (void)cryp;
693  (void)key_id;
694  (void)in;
695  (void)out;
696 
697  return CRY_ERR_INV_ALGO;
698 }
699 
700 /**
701  * @brief Encryption operation using (T)DES-ECB.
702  * @note The function operates on data buffers whose length is a multiple
703  * of an DES block, this means that padding must be done by the
704  * caller.
705  *
706  * @param[in] cryp pointer to the @p CRYDriver object
707  * @param[in] key_id the key to be used for the operation, zero is
708  * the transient key, other values are keys stored
709  * in an unspecified way
710  * @param[in] size size of the plaintext buffer, this number must
711  * be a multiple of 8
712  * @param[in] in buffer containing the input plaintext
713  * @param[out] out buffer for the output cyphertext
714  * @return The operation status.
715  * @retval CRY_NOERROR if the operation succeeded.
716  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
717  * device instance.
718  * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
719  * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
720  * or refers to an empty key slot.
721  *
722  * @notapi
723  */
725  crykey_t key_id,
726  size_t size,
727  const uint8_t *in,
728  uint8_t *out) {
729 
730  (void)cryp;
731  (void)key_id;
732  (void)size;
733  (void)in;
734  (void)out;
735 
736  return CRY_ERR_INV_ALGO;
737 }
738 
739 /**
740  * @brief Decryption operation using (T)DES-ECB.
741  * @note The function operates on data buffers whose length is a multiple
742  * of an DES block, this means that padding must be done by the
743  * caller.
744  *
745  * @param[in] cryp pointer to the @p CRYDriver object
746  * @param[in] key_id the key to be used for the operation, zero is
747  * the transient key, other values are keys stored
748  * in an unspecified way
749  * @param[in] size size of the plaintext buffer, this number must
750  * be a multiple of 8
751  * @param[in] in buffer containing the input cyphertext
752  * @param[out] out buffer for the output plaintext
753  * @return T he operation status.
754  * @retval CRY_NOERROR if the operation succeeded.
755  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
756  * device instance.
757  * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
758  * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
759  * or refers to an empty key slot.
760  *
761  * @notapi
762  */
764  crykey_t key_id,
765  size_t size,
766  const uint8_t *in,
767  uint8_t *out) {
768 
769  (void)cryp;
770  (void)key_id;
771  (void)size;
772  (void)in;
773  (void)out;
774 
775  return CRY_ERR_INV_ALGO;
776 }
777 
778 /**
779  * @brief Encryption operation using (T)DES-CBC.
780  * @note The function operates on data buffers whose length is a multiple
781  * of an DES block, this means that padding must be done by the
782  * caller.
783  *
784  * @param[in] cryp pointer to the @p CRYDriver object
785  * @param[in] key_id the key to be used for the operation, zero is
786  * the transient key, other values are keys stored
787  * in an unspecified way
788  * @param[in] size size of the plaintext buffer, this number must
789  * be a multiple of 8
790  * @param[in] in buffer containing the input plaintext
791  * @param[out] out buffer for the output cyphertext
792  * @param[in] iv 64 bits input vector
793  * @return The operation status.
794  * @retval CRY_NOERROR if the operation succeeded.
795  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
796  * device instance.
797  * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
798  * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
799  * or refers to an empty key slot.
800  *
801  * @notapi
802  */
804  crykey_t key_id,
805  size_t size,
806  const uint8_t *in,
807  uint8_t *out,
808  const uint8_t *iv) {
809 
810  (void)cryp;
811  (void)key_id;
812  (void)size;
813  (void)in;
814  (void)out;
815  (void)iv;
816 
817  return CRY_ERR_INV_ALGO;
818 }
819 
820 /**
821  * @brief Decryption operation using (T)DES-CBC.
822  * @note The function operates on data buffers whose length is a multiple
823  * of an DES block, this means that padding must be done by the
824  * caller.
825  *
826  * @param[in] cryp pointer to the @p CRYDriver object
827  * @param[in] key_id the key to be used for the operation, zero is
828  * the transient key, other values are keys stored
829  * in an unspecified way
830  * @param[in] size size of the plaintext buffer, this number must
831  * be a multiple of 8
832  * @param[in] in buffer containing the input cyphertext
833  * @param[out] out buffer for the output plaintext
834  * @param[in] iv 64 bits input vector
835  * @return The operation status.
836  * @retval CRY_NOERROR if the operation succeeded.
837  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
838  * device instance.
839  * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation.
840  * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid
841  * or refers to an empty key slot.
842  *
843  * @notapi
844  */
846  crykey_t key_id,
847  size_t size,
848  const uint8_t *in,
849  uint8_t *out,
850  const uint8_t *iv) {
851 
852  (void)cryp;
853  (void)key_id;
854  (void)size;
855  (void)in;
856  (void)out;
857  (void)iv;
858 
859  return CRY_ERR_INV_ALGO;
860 }
861 
862 /**
863  * @brief Hash initialization using SHA1.
864  * @note Use of this algorithm is not recommended because proven weak.
865  *
866  * @param[in] cryp pointer to the @p CRYDriver object
867  * @param[out] sha1ctxp pointer to a SHA1 context to be initialized
868  * @retval CRY_NOERROR if the operation succeeded.
869  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
870  * device instance.
871  *
872  * @notapi
873  */
875 
876  (void)cryp;
877  (void)sha1ctxp;
878 
879  return CRY_ERR_INV_ALGO;
880 }
881 
882 /**
883  * @brief Hash update using SHA1.
884  * @note Use of this algorithm is not recommended because proven weak.
885  *
886  * @param[in] cryp pointer to the @p CRYDriver object
887  * @param[in] sha1ctxp pointer to a SHA1 context
888  * @param[in] size size of input buffer
889  * @param[in] in buffer containing the input text
890  * @return The operation status.
891  * @retval CRY_NOERROR if the operation succeeded.
892  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
893  * device instance.
894  *
895  * @notapi
896  */
898  size_t size, const uint8_t *in) {
899 
900  (void)cryp;
901  (void)sha1ctxp;
902  (void)size;
903  (void)in;
904 
905  return CRY_ERR_INV_ALGO;
906 }
907 
908 /**
909  * @brief Hash finalization using SHA1.
910  * @note Use of this algorithm is not recommended because proven weak.
911  *
912  * @param[in] cryp pointer to the @p CRYDriver object
913  * @param[in] sha1ctxp pointer to a SHA1 context
914  * @param[out] out 160 bits output buffer
915  * @return The operation status.
916  * @retval CRY_NOERROR if the operation succeeded.
917  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
918  * device instance.
919  *
920  * @notapi
921  */
923  uint8_t *out) {
924 
925  (void)cryp;
926  (void)sha1ctxp;
927  (void)out;
928 
929  return CRY_ERR_INV_ALGO;
930 }
931 
932 /**
933  * @brief Hash initialization using SHA256.
934  *
935  * @param[in] cryp pointer to the @p CRYDriver object
936  * @param[out] sha256ctxp pointer to a SHA256 context to be initialized
937  * @retval CRY_NOERROR if the operation succeeded.
938  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
939  * device instance.
940  *
941  * @notapi
942  */
944 
945  (void)cryp;
946  (void)sha256ctxp;
947 
948  return CRY_ERR_INV_ALGO;
949 }
950 
951 /**
952  * @brief Hash update using SHA256.
953  *
954  * @param[in] cryp pointer to the @p CRYDriver object
955  * @param[in] sha256ctxp pointer to a SHA256 context
956  * @param[in] size size of input buffer
957  * @param[in] in buffer containing the input text
958  * @return The operation status.
959  * @retval CRY_NOERROR if the operation succeeded.
960  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
961  * device instance.
962  *
963  * @notapi
964  */
966  size_t size, const uint8_t *in) {
967 
968  (void)cryp;
969  (void)sha256ctxp;
970  (void)size;
971  (void)in;
972 
973  return CRY_ERR_INV_ALGO;
974 }
975 
976 /**
977  * @brief Hash finalization using SHA256.
978  *
979  * @param[in] cryp pointer to the @p CRYDriver object
980  * @param[in] sha256ctxp pointer to a SHA256 context
981  * @param[out] out 256 bits output buffer
982  * @return The operation status.
983  * @retval CRY_NOERROR if the operation succeeded.
984  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
985  * device instance.
986  *
987  * @notapi
988  */
990  uint8_t *out) {
991 
992  (void)cryp;
993  (void)sha256ctxp;
994  (void)out;
995 
996  return CRY_ERR_INV_ALGO;
997 }
998 
999 /**
1000  * @brief Hash initialization using SHA512.
1001  *
1002  * @param[in] cryp pointer to the @p CRYDriver object
1003  * @param[out] sha512ctxp pointer to a SHA512 context to be initialized
1004  * @retval CRY_NOERROR if the operation succeeded.
1005  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
1006  * device instance.
1007  *
1008  * @notapi
1009  */
1011 
1012  (void)cryp;
1013  (void)sha512ctxp;
1014 
1015  return CRY_ERR_INV_ALGO;
1016 }
1017 
1018 /**
1019  * @brief Hash update using SHA512.
1020  *
1021  * @param[in] cryp pointer to the @p CRYDriver object
1022  * @param[in] sha512ctxp pointer to a SHA512 context
1023  * @param[in] size size of input buffer
1024  * @param[in] in buffer containing the input text
1025  * @return The operation status.
1026  * @retval CRY_NOERROR if the operation succeeded.
1027  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
1028  * device instance.
1029  *
1030  * @notapi
1031  */
1033  size_t size, const uint8_t *in) {
1034 
1035  (void)cryp;
1036  (void)sha512ctxp;
1037  (void)size;
1038  (void)in;
1039 
1040  return CRY_ERR_INV_ALGO;
1041 }
1042 
1043 /**
1044  * @brief Hash finalization using SHA512.
1045  *
1046  * @param[in] cryp pointer to the @p CRYDriver object
1047  * @param[in] sha512ctxp pointer to a SHA512 context
1048  * @param[out] out 512 bits output buffer
1049  * @return The operation status.
1050  * @retval CRY_NOERROR if the operation succeeded.
1051  * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this
1052  * device instance.
1053  *
1054  * @notapi
1055  */
1057  uint8_t *out) {
1058 
1059  (void)cryp;
1060  (void)sha512ctxp;
1061  (void)out;
1062 
1063  return CRY_ERR_INV_ALGO;
1064 }
1065 
1066 /**
1067  * @brief True random numbers generator.
1068  *
1069  * @param[in] cryp pointer to the @p CRYDriver object
1070  * @param[out] out 128 bits output buffer
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  *
1076  * @notapi
1077  */
1079 
1080  (void)cryp;
1081  (void)out;
1082 
1083  return CRY_ERR_INV_ALGO;
1084 }
1085 
1086 #endif /* HAL_USE_CRY == TRUE */
1087 
1088 /** @} */
cryerror_t cry_lld_SHA1_init(CRYDriver *cryp, SHA1Context *sha1ctxp)
Hash initialization using SHA1.
cryerror_t cry_lld_decrypt_AES_GCM(CRYDriver *cryp, crykey_t key_id, size_t size, const uint8_t *in, uint8_t *out, const uint8_t *iv, size_t aadsize, const uint8_t *aad, uint8_t *authtag)
Decryption operation using AES-GCM.
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 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.
Type of a SHA512 context.
Definition: hal_crypto.h:190
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 cry_lld_TRNG(CRYDriver *cryp, uint8_t *out)
True random numbers generator.
Structure representing an CRY driver.
HAL subsystem header.
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.
void cry_lld_stop(CRYDriver *cryp)
Deactivates the crypto peripheral.
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
Driver error codes.
Definition: hal_crypto.h:94
cryerror_t cry_lld_encrypt_AES_GCM(CRYDriver *cryp, crykey_t key_id, size_t size, const uint8_t *in, uint8_t *out, const uint8_t *iv, size_t aadsize, const uint8_t *aad, uint8_t *authtag)
Encryption operation using AES-GCM.
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.
void cry_lld_start(CRYDriver *cryp)
Configures and activates the crypto peripheral.
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 cry_lld_SHA512_init(CRYDriver *cryp, SHA512Context *sha512ctxp)
Hash initialization using SHA512.
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.
cryalgorithm_t
Type of an algorithm identifier.
Definition: hal_crypto.h:106
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.
CRYDriver CRYD1
CRY1 driver identifier.
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.
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 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.
Type of a SHA1 context.
Definition: hal_crypto.h:174
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_loadkey(CRYDriver *cryp, cryalgorithm_t algorithm, size_t size, const uint8_t *keyp)
Initializes the transient key for a specific algorithm.
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:182
cryerror_t cry_lld_SHA256_final(CRYDriver *cryp, SHA256Context *sha256ctxp, uint8_t *out)
Hash finalization using SHA256.
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.