HAL
Select one of the symbols to view example projects that use it.
 
Outline
#include "stm32f4xx_hal.h"
Private define
#define CRYP_PHASE_INIT
#define CRYP_PHASE_HEADER
#define CRYP_PHASE_PAYLOAD
#define CRYP_PHASE_FINAL
#define CRYP_OPERATINGMODE_ENCRYPT
#define CRYP_OPERATINGMODE_KEYDERIVATION
#define CRYP_OPERATINGMODE_DECRYPT
#define CRYP_OPERATINGMODE_KEYDERIVATION_DECRYPT
#define CRYP_PHASE_INIT
#define CRYP_PHASE_HEADER
#define CRYP_PHASE_PAYLOAD
#define CRYP_PHASE_FINAL
#define CRYP_OPERATINGMODE_ENCRYPT
#define CRYP_OPERATINGMODE_DECRYPT
#define CRYPEx_PHASE_PROCESS
#define CRYPEx_PHASE_FINAL
#define CRYP_CCM_CTR0_0
#define CRYP_CCM_CTR0_3
Private function prototypes
HAL_CRYPEx_AESGCM_GenerateAuthTAG(CRYP_HandleTypeDef *, uint32_t *, uint32_t)
HAL_CRYPEx_AESCCM_GenerateAuthTAG(CRYP_HandleTypeDef *, uint32_t *, uint32_t)
Files
loading...
SourceVuSTM32 Libraries and SamplesHALSrc/stm32f4xx_hal_cryp_ex.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file stm32f4xx_hal_cryp_ex.c * @author MCD Application Team * @brief Extended CRYP HAL module driver * This file provides firmware functions to manage the following * functionalities of CRYP extension peripheral: * + Extended AES processing functions * ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim ============================================================================== ##### How to use this driver ##### ============================================================================== [..] The CRYP extension HAL driver can be used as follows: (#)After AES-GCM or AES-CCM Encryption/Decryption user can start following API to get the authentication messages : (##) HAL_CRYPEx_AESGCM_GenerateAuthTAG (##) HAL_CRYPEx_AESCCM_GenerateAuthTAG @endverbatim ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "stm32f4xx_hal.h" /** @addtogroup STM32F4xx_HAL_Driver * @{ *//* ... */ #if defined (AES) || defined (CRYP) #if defined (CRYP_CR_ALGOMODE_AES_GCM)|| defined (AES) /** @defgroup CRYPEx CRYPEx * @brief CRYP Extension HAL module driver. * @{ *//* ... */ #ifdef HAL_CRYP_MODULE_ENABLED /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /** @addtogroup CRYPEx_Private_Defines * @{ *//* ... */ #if defined(AES) #define CRYP_PHASE_INIT 0x00000000U /*!< GCM/GMAC (or CCM) init phase */ #define CRYP_PHASE_HEADER AES_CR_GCMPH_0 /*!< GCM/GMAC or CCM header phase */ #define CRYP_PHASE_PAYLOAD AES_CR_GCMPH_1 /*!< GCM(/CCM) payload phase */ #define CRYP_PHASE_FINAL AES_CR_GCMPH /*!< GCM/GMAC or CCM final phase */ #define CRYP_OPERATINGMODE_ENCRYPT 0x00000000U /*!< Encryption mode */ #define CRYP_OPERATINGMODE_KEYDERIVATION AES_CR_MODE_0 /*!< Key derivation mode only used when performing ECB and CBC decryptions */ #define CRYP_OPERATINGMODE_DECRYPT AES_CR_MODE_1 /*!< Decryption */ #define CRYP_OPERATINGMODE_KEYDERIVATION_DECRYPT AES_CR_MODE /*!< Key derivation and decryption only used when performing ECB and CBC decryptions */ 8 defines /* ... */#else /* CRYP */ #define CRYP_PHASE_INIT 0x00000000U #define CRYP_PHASE_HEADER CRYP_CR_GCM_CCMPH_0 #define CRYP_PHASE_PAYLOAD CRYP_CR_GCM_CCMPH_1 #define CRYP_PHASE_FINAL CRYP_CR_GCM_CCMPH #define CRYP_OPERATINGMODE_ENCRYPT 0x00000000U #define CRYP_OPERATINGMODE_DECRYPT CRYP_CR_ALGODIR 6 defines#endif/* ... */ /* End AES or CRYP */ #define CRYPEx_PHASE_PROCESS 0x02U /*!< CRYP peripheral is in processing phase */ #define CRYPEx_PHASE_FINAL 0x03U /*!< CRYP peripheral is in final phase this is relevant only with CCM and GCM modes */ /* CTR0 information to use in CCM algorithm */ #define CRYP_CCM_CTR0_0 0x07FFFFFFU #define CRYP_CCM_CTR0_3 0xFFFFFF00U /** * @} *//* ... */ Private define /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ Private function prototypes /* Exported functions---------------------------------------------------------*/ /** @addtogroup CRYPEx_Exported_Functions * @{ *//* ... */ /** @defgroup CRYPEx_Exported_Functions_Group1 Extended AES processing functions * @brief Extended processing functions. * @verbatim ============================================================================== ##### Extended AES processing functions ##### ============================================================================== [..] This section provides functions allowing to generate the authentication TAG in Polling mode (#)HAL_CRYPEx_AESGCM_GenerateAuthTAG (#)HAL_CRYPEx_AESCCM_GenerateAuthTAG they should be used after Encrypt/Decrypt operation. @endverbatim * @{ *//* ... */ /** * @brief generate the GCM authentication TAG. * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains * the configuration information for CRYP module * @param AuthTag: Pointer to the authentication buffer * @param Timeout: Timeout duration * @retval HAL status *//* ... */ HAL_StatusTypeDef HAL_CRYPEx_AESGCM_GenerateAuthTAG(CRYP_HandleTypeDef *hcryp, uint32_t *AuthTag, uint32_t Timeout) { uint32_t tickstart; /* Assume first Init.HeaderSize is in words */ uint64_t headerlength = (uint64_t)(hcryp->Init.HeaderSize) * 32U; /* Header length in bits */ uint64_t inputlength = (uint64_t)hcryp->SizesSum * 8U; /* Input length in bits */ uint32_t tagaddr = (uint32_t)AuthTag; /* Correct headerlength if Init.HeaderSize is actually in bytes */ if (hcryp->Init.HeaderWidthUnit == CRYP_HEADERWIDTHUNIT_BYTE) { headerlength /= 4U; }if (hcryp->Init.HeaderWidthUnit == CRYP_HEADERWIDTHUNIT_BYTE) { ... } if (hcryp->State == HAL_CRYP_STATE_READY) { /* Process locked */ __HAL_LOCK(hcryp); /* Change the CRYP peripheral state */ hcryp->State = HAL_CRYP_STATE_BUSY; /* Check if initialization phase has already been performed */ if (hcryp->Phase == CRYPEx_PHASE_PROCESS) { /* Change the CRYP phase */ hcryp->Phase = CRYPEx_PHASE_FINAL; }if (hcryp->Phase == CRYPEx_PHASE_PROCESS) { ... } else /* Initialization phase has not been performed*/ { /* Disable the Peripheral */ __HAL_CRYP_DISABLE(hcryp); /* Sequence error code field */ hcryp->ErrorCode |= HAL_CRYP_ERROR_AUTH_TAG_SEQUENCE; /* Change the CRYP peripheral state */ hcryp->State = HAL_CRYP_STATE_READY; /* Process unlocked */ __HAL_UNLOCK(hcryp); return HAL_ERROR; }else { ... } #if defined(CRYP) /* Disable CRYP to start the final phase */ __HAL_CRYP_DISABLE(hcryp); /* Select final phase */ MODIFY_REG(hcryp->Instance->CR, CRYP_CR_GCM_CCMPH, CRYP_PHASE_FINAL); /*ALGODIR bit must be set to '0'.*/ hcryp->Instance->CR &= ~CRYP_CR_ALGODIR; /* Enable the CRYP peripheral */ __HAL_CRYP_ENABLE(hcryp); /* Write the number of bits in header (64 bits) followed by the number of bits in the payload *//* ... */ if (hcryp->Init.DataType == CRYP_DATATYPE_1B) { hcryp->Instance->DIN = 0U; hcryp->Instance->DIN = __RBIT((uint32_t)(headerlength)); hcryp->Instance->DIN = 0U; hcryp->Instance->DIN = __RBIT((uint32_t)(inputlength)); }if (hcryp->Init.DataType == CRYP_DATATYPE_1B) { ... } else if (hcryp->Init.DataType == CRYP_DATATYPE_8B) { hcryp->Instance->DIN = 0U; hcryp->Instance->DIN = __REV((uint32_t)(headerlength)); hcryp->Instance->DIN = 0U; hcryp->Instance->DIN = __REV((uint32_t)(inputlength)); }else if (hcryp->Init.DataType == CRYP_DATATYPE_8B) { ... } else if (hcryp->Init.DataType == CRYP_DATATYPE_16B) { hcryp->Instance->DIN = 0U; hcryp->Instance->DIN = __ROR((uint32_t)headerlength, 16U); hcryp->Instance->DIN = 0U; hcryp->Instance->DIN = __ROR((uint32_t)inputlength, 16U); }else if (hcryp->Init.DataType == CRYP_DATATYPE_16B) { ... } else if (hcryp->Init.DataType == CRYP_DATATYPE_32B) { hcryp->Instance->DIN = 0U; hcryp->Instance->DIN = (uint32_t)(headerlength); hcryp->Instance->DIN = 0U; hcryp->Instance->DIN = (uint32_t)(inputlength); }else if (hcryp->Init.DataType == CRYP_DATATYPE_32B) { ... } else { /* Nothing to do */ }else { ... } /* Wait for OFNE flag to be raised */ tickstart = HAL_GetTick(); while (HAL_IS_BIT_CLR(hcryp->Instance->SR, CRYP_FLAG_OFNE)) { /* Check for the Timeout */ if (Timeout != HAL_MAX_DELAY) { if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) { /* Disable the CRYP Peripheral Clock */ __HAL_CRYP_DISABLE(hcryp); /* Change state */ hcryp->ErrorCode |= HAL_CRYP_ERROR_TIMEOUT; hcryp->State = HAL_CRYP_STATE_READY; /* Process unlocked */ __HAL_UNLOCK(hcryp); return HAL_ERROR; }if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) { ... } }if (Timeout != HAL_MAX_DELAY) { ... } }while (HAL_IS_BIT_CLR(hcryp->Instance->SR, CRYP_FLAG_OFNE)) { ... } /* Read the authentication TAG in the output FIFO */ *(uint32_t *)(tagaddr) = hcryp->Instance->DOUT; tagaddr += 4U; *(uint32_t *)(tagaddr) = hcryp->Instance->DOUT; tagaddr += 4U; *(uint32_t *)(tagaddr) = hcryp->Instance->DOUT; tagaddr += 4U; *(uint32_t *)(tagaddr) = hcryp->Instance->DOUT; /* ... */ #else /* AES*/ /* Select final phase */ MODIFY_REG(hcryp->Instance->CR, AES_CR_GCMPH, CRYP_PHASE_FINAL); /* Write the number of bits in header (64 bits) followed by the number of bits in the payload *//* ... */ if (hcryp->Init.DataType == CRYP_DATATYPE_1B) { hcryp->Instance->DINR = 0U; hcryp->Instance->DINR = __RBIT((uint32_t)(headerlength)); hcryp->Instance->DINR = 0U; hcryp->Instance->DINR = __RBIT((uint32_t)(inputlength)); }if (hcryp->Init.DataType == CRYP_DATATYPE_1B) { ... } else if (hcryp->Init.DataType == CRYP_DATATYPE_8B) { hcryp->Instance->DINR = 0U; hcryp->Instance->DINR = __REV((uint32_t)(headerlength)); hcryp->Instance->DINR = 0U; hcryp->Instance->DINR = __REV((uint32_t)(inputlength)); }else if (hcryp->Init.DataType == CRYP_DATATYPE_8B) { ... } else if (hcryp->Init.DataType == CRYP_DATATYPE_16B) { hcryp->Instance->DINR = 0U; hcryp->Instance->DINR = __ROR((uint32_t)headerlength, 16U); hcryp->Instance->DINR = 0U; hcryp->Instance->DINR = __ROR((uint32_t)inputlength, 16U); }else if (hcryp->Init.DataType == CRYP_DATATYPE_16B) { ... } else if (hcryp->Init.DataType == CRYP_DATATYPE_32B) { hcryp->Instance->DINR = 0U; hcryp->Instance->DINR = (uint32_t)(headerlength); hcryp->Instance->DINR = 0U; hcryp->Instance->DINR = (uint32_t)(inputlength); }else if (hcryp->Init.DataType == CRYP_DATATYPE_32B) { ... } else { /* Nothing to do */ }else { ... } /* Wait for CCF flag to be raised */ tickstart = HAL_GetTick(); while (HAL_IS_BIT_CLR(hcryp->Instance->SR, AES_SR_CCF)) { /* Check for the Timeout */ if (Timeout != HAL_MAX_DELAY) { if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) { /* Disable the CRYP peripheral clock */ __HAL_CRYP_DISABLE(hcryp); /* Change state */ hcryp->ErrorCode |= HAL_CRYP_ERROR_TIMEOUT; hcryp->State = HAL_CRYP_STATE_READY; /* Process unlocked */ __HAL_UNLOCK(hcryp); return HAL_ERROR; }if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) { ... } }if (Timeout != HAL_MAX_DELAY) { ... } }while (HAL_IS_BIT_CLR(hcryp->Instance->SR, AES_SR_CCF)) { ... } /* Read the authentication TAG in the output FIFO */ *(uint32_t *)(tagaddr) = hcryp->Instance->DOUTR; tagaddr += 4U; *(uint32_t *)(tagaddr) = hcryp->Instance->DOUTR; tagaddr += 4U; *(uint32_t *)(tagaddr) = hcryp->Instance->DOUTR; tagaddr += 4U; *(uint32_t *)(tagaddr) = hcryp->Instance->DOUTR; /* Clear CCF flag */ __HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CCF_CLEAR); /* ... */ #endif /* End AES or CRYP */ /* Disable the peripheral */ __HAL_CRYP_DISABLE(hcryp); /* Change the CRYP peripheral state */ hcryp->State = HAL_CRYP_STATE_READY; /* Process unlocked */ __HAL_UNLOCK(hcryp); }if (hcryp->State == HAL_CRYP_STATE_READY) { ... } else { /* Busy error code field */ hcryp->ErrorCode |= HAL_CRYP_ERROR_BUSY; return HAL_ERROR; }else { ... } /* Return function status */ return HAL_OK; }{ ... } /** * @brief AES CCM Authentication TAG generation. * @param hcryp: pointer to a CRYP_HandleTypeDef structure that contains * the configuration information for CRYP module * @param AuthTag: Pointer to the authentication buffer * @param Timeout: Timeout duration * @retval HAL status *//* ... */ HAL_StatusTypeDef HAL_CRYPEx_AESCCM_GenerateAuthTAG(CRYP_HandleTypeDef *hcryp, uint32_t *AuthTag, uint32_t Timeout) { uint32_t tagaddr = (uint32_t)AuthTag; uint32_t ctr0 [4] = {0}; uint32_t ctr0addr = (uint32_t)ctr0; uint32_t tickstart; if (hcryp->State == HAL_CRYP_STATE_READY) { /* Process locked */ __HAL_LOCK(hcryp); /* Change the CRYP peripheral state */ hcryp->State = HAL_CRYP_STATE_BUSY; /* Check if initialization phase has already been performed */ if (hcryp->Phase == CRYPEx_PHASE_PROCESS) { /* Change the CRYP phase */ hcryp->Phase = CRYPEx_PHASE_FINAL; }if (hcryp->Phase == CRYPEx_PHASE_PROCESS) { ... } else /* Initialization phase has not been performed*/ { /* Disable the peripheral */ __HAL_CRYP_DISABLE(hcryp); /* Sequence error code field */ hcryp->ErrorCode |= HAL_CRYP_ERROR_AUTH_TAG_SEQUENCE; /* Change the CRYP peripheral state */ hcryp->State = HAL_CRYP_STATE_READY; /* Process unlocked */ __HAL_UNLOCK(hcryp); return HAL_ERROR; }else { ... } #if defined(CRYP) /* Disable CRYP to start the final phase */ __HAL_CRYP_DISABLE(hcryp); /* Select final phase & ALGODIR bit must be set to '0'. */ MODIFY_REG(hcryp->Instance->CR, CRYP_CR_GCM_CCMPH | CRYP_CR_ALGODIR, CRYP_PHASE_FINAL | CRYP_OPERATINGMODE_ENCRYPT); /* Enable the CRYP peripheral */ __HAL_CRYP_ENABLE(hcryp); /* Write the counter block in the IN FIFO, CTR0 information from B0 data has to be swapped according to the DATATYPE*//* ... */ ctr0[0] = (hcryp->Init.B0[0]) & CRYP_CCM_CTR0_0; ctr0[1] = hcryp->Init.B0[1]; ctr0[2] = hcryp->Init.B0[2]; ctr0[3] = hcryp->Init.B0[3] & CRYP_CCM_CTR0_3; if (hcryp->Init.DataType == CRYP_DATATYPE_8B) { hcryp->Instance->DIN = __REV(*(uint32_t *)(ctr0addr)); ctr0addr += 4U; hcryp->Instance->DIN = __REV(*(uint32_t *)(ctr0addr)); ctr0addr += 4U; hcryp->Instance->DIN = __REV(*(uint32_t *)(ctr0addr)); ctr0addr += 4U; hcryp->Instance->DIN = __REV(*(uint32_t *)(ctr0addr)); }if (hcryp->Init.DataType == CRYP_DATATYPE_8B) { ... } else if (hcryp->Init.DataType == CRYP_DATATYPE_16B) { hcryp->Instance->DIN = __ROR(*(uint32_t *)(ctr0addr), 16U); ctr0addr += 4U; hcryp->Instance->DIN = __ROR(*(uint32_t *)(ctr0addr), 16U); ctr0addr += 4U; hcryp->Instance->DIN = __ROR(*(uint32_t *)(ctr0addr), 16U); ctr0addr += 4U; hcryp->Instance->DIN = __ROR(*(uint32_t *)(ctr0addr), 16U); }else if (hcryp->Init.DataType == CRYP_DATATYPE_16B) { ... } else if (hcryp->Init.DataType == CRYP_DATATYPE_1B) { hcryp->Instance->DIN = __RBIT(*(uint32_t *)(ctr0addr)); ctr0addr += 4U; hcryp->Instance->DIN = __RBIT(*(uint32_t *)(ctr0addr)); ctr0addr += 4U; hcryp->Instance->DIN = __RBIT(*(uint32_t *)(ctr0addr)); ctr0addr += 4U; hcryp->Instance->DIN = __RBIT(*(uint32_t *)(ctr0addr)); }else if (hcryp->Init.DataType == CRYP_DATATYPE_1B) { ... } else { hcryp->Instance->DIN = *(uint32_t *)(ctr0addr); ctr0addr += 4U; hcryp->Instance->DIN = *(uint32_t *)(ctr0addr); ctr0addr += 4U; hcryp->Instance->DIN = *(uint32_t *)(ctr0addr); ctr0addr += 4U; hcryp->Instance->DIN = *(uint32_t *)(ctr0addr); }else { ... } /* Wait for OFNE flag to be raised */ tickstart = HAL_GetTick(); while (HAL_IS_BIT_CLR(hcryp->Instance->SR, CRYP_FLAG_OFNE)) { /* Check for the Timeout */ if (Timeout != HAL_MAX_DELAY) { if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) { /* Disable the CRYP peripheral Clock */ __HAL_CRYP_DISABLE(hcryp); /* Change state */ hcryp->ErrorCode |= HAL_CRYP_ERROR_TIMEOUT; hcryp->State = HAL_CRYP_STATE_READY; /* Process unlocked */ __HAL_UNLOCK(hcryp); return HAL_ERROR; }if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) { ... } }if (Timeout != HAL_MAX_DELAY) { ... } }while (HAL_IS_BIT_CLR(hcryp->Instance->SR, CRYP_FLAG_OFNE)) { ... } /* Read the Auth TAG in the IN FIFO */ *(uint32_t *)(tagaddr) = hcryp->Instance->DOUT; tagaddr += 4U; *(uint32_t *)(tagaddr) = hcryp->Instance->DOUT; tagaddr += 4U; *(uint32_t *)(tagaddr) = hcryp->Instance->DOUT; tagaddr += 4U; *(uint32_t *)(tagaddr) = hcryp->Instance->DOUT; /* ... */ #else /* AES */ /* Select final phase */ MODIFY_REG(hcryp->Instance->CR, AES_CR_GCMPH, CRYP_PHASE_FINAL); /* Write the counter block in the IN FIFO, CTR0 information from B0 data has to be swapped according to the DATATYPE*//* ... */ if (hcryp->Init.DataType == CRYP_DATATYPE_8B) { ctr0[0] = (__REV(hcryp->Init.B0[0]) & CRYP_CCM_CTR0_0); ctr0[1] = __REV(hcryp->Init.B0[1]); ctr0[2] = __REV(hcryp->Init.B0[2]); ctr0[3] = (__REV(hcryp->Init.B0[3])& CRYP_CCM_CTR0_3); hcryp->Instance->DINR = __REV(*(uint32_t *)(ctr0addr)); ctr0addr += 4U; hcryp->Instance->DINR = __REV(*(uint32_t *)(ctr0addr)); ctr0addr += 4U; hcryp->Instance->DINR = __REV(*(uint32_t *)(ctr0addr)); ctr0addr += 4U; hcryp->Instance->DINR = __REV(*(uint32_t *)(ctr0addr)); }if (hcryp->Init.DataType == CRYP_DATATYPE_8B) { ... } else if (hcryp->Init.DataType == CRYP_DATATYPE_16B) { ctr0[0] = (__ROR((hcryp->Init.B0[0]), 16U)& CRYP_CCM_CTR0_0); ctr0[1] = __ROR((hcryp->Init.B0[1]), 16U); ctr0[2] = __ROR((hcryp->Init.B0[2]), 16U); ctr0[3] = (__ROR((hcryp->Init.B0[3]), 16U)& CRYP_CCM_CTR0_3); hcryp->Instance->DINR = __ROR(*(uint32_t *)(ctr0addr), 16U); ctr0addr += 4U; hcryp->Instance->DINR = __ROR(*(uint32_t *)(ctr0addr), 16U); ctr0addr += 4U; hcryp->Instance->DINR = __ROR(*(uint32_t *)(ctr0addr), 16U); ctr0addr += 4U; hcryp->Instance->DINR = __ROR(*(uint32_t *)(ctr0addr), 16U); }else if (hcryp->Init.DataType == CRYP_DATATYPE_16B) { ... } else if (hcryp->Init.DataType == CRYP_DATATYPE_1B) { ctr0[0] = (__RBIT(hcryp->Init.B0[0])& CRYP_CCM_CTR0_0); ctr0[1] = __RBIT(hcryp->Init.B0[1]); ctr0[2] = __RBIT(hcryp->Init.B0[2]); ctr0[3] = (__RBIT(hcryp->Init.B0[3])& CRYP_CCM_CTR0_3); hcryp->Instance->DINR = __RBIT(*(uint32_t *)(ctr0addr)); ctr0addr += 4U; hcryp->Instance->DINR = __RBIT(*(uint32_t *)(ctr0addr)); ctr0addr += 4U; hcryp->Instance->DINR = __RBIT(*(uint32_t *)(ctr0addr)); ctr0addr += 4U; hcryp->Instance->DINR = __RBIT(*(uint32_t *)(ctr0addr)); }else if (hcryp->Init.DataType == CRYP_DATATYPE_1B) { ... } else { ctr0[0] = (hcryp->Init.B0[0]) & CRYP_CCM_CTR0_0; ctr0[1] = hcryp->Init.B0[1]; ctr0[2] = hcryp->Init.B0[2]; ctr0[3] = hcryp->Init.B0[3] & CRYP_CCM_CTR0_3; hcryp->Instance->DINR = *(uint32_t *)(ctr0addr); ctr0addr += 4U; hcryp->Instance->DINR = *(uint32_t *)(ctr0addr); ctr0addr += 4U; hcryp->Instance->DINR = *(uint32_t *)(ctr0addr); ctr0addr += 4U; hcryp->Instance->DINR = *(uint32_t *)(ctr0addr); }else { ... } /* Wait for CCF flag to be raised */ tickstart = HAL_GetTick(); while (HAL_IS_BIT_CLR(hcryp->Instance->SR, AES_SR_CCF)) { /* Check for the Timeout */ if (Timeout != HAL_MAX_DELAY) { if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) { /* Disable the CRYP peripheral Clock */ __HAL_CRYP_DISABLE(hcryp); /* Change state */ hcryp->ErrorCode |= HAL_CRYP_ERROR_TIMEOUT; hcryp->State = HAL_CRYP_STATE_READY; /* Process unlocked */ __HAL_UNLOCK(hcryp); return HAL_ERROR; }if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) { ... } }if (Timeout != HAL_MAX_DELAY) { ... } }while (HAL_IS_BIT_CLR(hcryp->Instance->SR, AES_SR_CCF)) { ... } /* Read the authentication TAG in the output FIFO */ *(uint32_t *)(tagaddr) = hcryp->Instance->DOUTR; tagaddr += 4U; *(uint32_t *)(tagaddr) = hcryp->Instance->DOUTR; tagaddr += 4U; *(uint32_t *)(tagaddr) = hcryp->Instance->DOUTR; tagaddr += 4U; *(uint32_t *)(tagaddr) = hcryp->Instance->DOUTR; /* Clear CCF Flag */ __HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CCF_CLEAR); /* ... */ #endif /* End of AES || CRYP */ /* Change the CRYP peripheral state */ hcryp->State = HAL_CRYP_STATE_READY; /* Process unlocked */ __HAL_UNLOCK(hcryp); /* Disable CRYP */ __HAL_CRYP_DISABLE(hcryp); }if (hcryp->State == HAL_CRYP_STATE_READY) { ... } else { /* Busy error code field */ hcryp->ErrorCode = HAL_CRYP_ERROR_BUSY; return HAL_ERROR; }else { ... } /* Return function status */ return HAL_OK; }{ ... } /** * @} *//* ... */ #if defined (AES) /** @defgroup CRYPEx_Exported_Functions_Group2 Key Derivation functions * @brief AutoKeyDerivation functions * @verbatim ============================================================================== ##### Key Derivation functions ##### ============================================================================== [..] This section provides functions allowing to Enable or Disable the the AutoKeyDerivation parameter in CRYP_HandleTypeDef structure These function are allowed only in TinyAES IP. @endverbatim * @{ *//* ... */ /** * @brief AES enable key derivation functions * @param hcryp: pointer to a CRYP_HandleTypeDef structure. * @retval None *//* ... */ void HAL_CRYPEx_EnableAutoKeyDerivation(CRYP_HandleTypeDef *hcryp) { if (hcryp->State == HAL_CRYP_STATE_READY) { hcryp->AutoKeyDerivation = ENABLE; }if (hcryp->State == HAL_CRYP_STATE_READY) { ... } else { /* Busy error code field */ hcryp->ErrorCode = HAL_CRYP_ERROR_BUSY; }else { ... } }HAL_CRYPEx_EnableAutoKeyDerivation (CRYP_HandleTypeDef *hcryp) { ... } /** * @brief AES disable key derivation functions * @param hcryp: pointer to a CRYP_HandleTypeDef structure. * @retval None *//* ... */ void HAL_CRYPEx_DisableAutoKeyDerivation(CRYP_HandleTypeDef *hcryp) { if (hcryp->State == HAL_CRYP_STATE_READY) { hcryp->AutoKeyDerivation = DISABLE; }if (hcryp->State == HAL_CRYP_STATE_READY) { ... } else { /* Busy error code field */ hcryp->ErrorCode = HAL_CRYP_ERROR_BUSY; }else { ... } }HAL_CRYPEx_DisableAutoKeyDerivation (CRYP_HandleTypeDef *hcryp) { ... } /** * @} *//* ... */ /* ... */#endif /* AES or GCM CCM defined*//* ... */ #endif /* AES *//* ... */ #endif /* HAL_CRYP_MODULE_ENABLED */ /** * @} *//* ... */ /* ... */#endif /* TinyAES or CRYP*/ /** * @} *//* ... */ /** * @} *//* ... */
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.