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
34
35
36
37
38
39
40
41
44
45
48
49
50
51
53
55
56
58
61
64
65
66
67
68
71
72
73
74
75
78
79
80
85
86
87
90
91
92
93
94
95
96
97
98
99
100
101
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
130
131
134
135
136
143
144
145
146
147
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
169
170
174
175
176
177
180
181
182
183
184
187
188
191
192
193
194
195
196
197
198
199
200
201
202
205
206
209
210
211
212
213
216
217
220
221
222
223
224
227
228
231
232
233
234
235
236
237
238
239
240
241
244
245
251
252
255
256
259
260
264
267
270
271
274
275
280
285
286
289
290
293
294
297
303
304
307
308
311
312
313
314
315
316
317
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
336
337
340
341
342
343
344
347
348
349
352
353
354
357
358
362
363
369
370
371
372
377
378
381
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
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
496
497
500
501
504
505
508
509
510
511
512
513
514
515
518
519
522
523
526
527
528
529
530
531
532
533
534
535
536
537
540
541
542
545
546
547
548
549
550
551
552
553
556
557
560
561
562
565
566
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
592
593
594
595
596
597
598
599
600
602
603
604
608
609
611
614
615
618
619
620
637
654
655
658
659
662
663
664
667
668
669
672
673
674
677
678
679
680
681
682
683
/* ... */
#ifndef __STM32F4xx_HAL_CRYP_H
#define __STM32F4xx_HAL_CRYP_H
#ifdef __cplusplus
extern "C" {
#endif
#include "stm32f4xx_hal_def.h"
/* ... */
#if defined (AES) || defined (CRYP)
/* ... */
/* ... */
/* ... */
typedef struct
{
uint32_t DataType;
/* ... */
uint32_t KeySize;
/* ... */
uint32_t *pKey;
uint32_t *pInitVect;
/* ... */
uint32_t Algorithm;
/* ... */
uint32_t *Header;
/* ... */
uint32_t HeaderSize;
uint32_t *B0;
uint32_t DataWidthUnit;
uint32_t HeaderWidthUnit;
uint32_t KeyIVConfigSkip;
/* ... */
...} CRYP_ConfigTypeDef;
/* ... */
typedef enum
{
HAL_CRYP_STATE_RESET = 0x00U,
HAL_CRYP_STATE_READY = 0x01U,
HAL_CRYP_STATE_BUSY = 0x02U
...} HAL_CRYP_STATETypeDef;
/* ... */
typedef struct __CRYP_HandleTypeDef
{
#if defined (CRYP)
CRYP_TypeDef *Instance;
#else
AES_TypeDef *Instance;
#endif
CRYP_ConfigTypeDef Init;
FunctionalState AutoKeyDerivation;
/* ... */
uint32_t *pCrypInBuffPtr;
uint32_t *pCrypOutBuffPtr;
__IO uint16_t CrypHeaderCount;
__IO uint16_t CrypInCount;
__IO uint16_t CrypOutCount;
uint16_t Size;
uint32_t Phase;
DMA_HandleTypeDef *hdmain;
DMA_HandleTypeDef *hdmaout;
HAL_LockTypeDef Lock;
__IO HAL_CRYP_STATETypeDef State;
__IO uint32_t ErrorCode;
uint32_t KeyIVConfig;
/* ... */
uint32_t SizesSum;
/* ... */
#if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
void (*InCpltCallback)(struct __CRYP_HandleTypeDef *hcryp);
void (*OutCpltCallback)(struct __CRYP_HandleTypeDef *hcryp);
void (*ErrorCallback)(struct __CRYP_HandleTypeDef *hcryp);
void (* MspInitCallback)(struct __CRYP_HandleTypeDef *hcryp);
void (* MspDeInitCallback)(struct __CRYP_HandleTypeDef *hcryp);
/* ... */
#endif
...} CRYP_HandleTypeDef;
/* ... */
#if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
/* ... */
typedef enum
{
HAL_CRYP_INPUT_COMPLETE_CB_ID = 0x01U,
HAL_CRYP_OUTPUT_COMPLETE_CB_ID = 0x02U,
HAL_CRYP_ERROR_CB_ID = 0x03U,
HAL_CRYP_MSPINIT_CB_ID = 0x04U,
HAL_CRYP_MSPDEINIT_CB_ID = 0x05U
...} HAL_CRYP_CallbackIDTypeDef;
/* ... */
/* ... */
typedef void (*pCRYP_CallbackTypeDef)(CRYP_HandleTypeDef *hcryp);
/* ... */
/* ... */
#endif
Exported types
/* ... */
/* ... */
#define HAL_CRYP_ERROR_NONE 0x00000000U
#define HAL_CRYP_ERROR_WRITE 0x00000001U
#define HAL_CRYP_ERROR_READ 0x00000002U
#define HAL_CRYP_ERROR_DMA 0x00000004U
#define HAL_CRYP_ERROR_BUSY 0x00000008U
#define HAL_CRYP_ERROR_TIMEOUT 0x00000010U
#define HAL_CRYP_ERROR_NOT_SUPPORTED 0x00000020U
#define HAL_CRYP_ERROR_AUTH_TAG_SEQUENCE 0x00000040U
8 defines#if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
#define HAL_CRYP_ERROR_INVALID_CALLBACK ((uint32_t)0x00000080U)
#endif
/* ... */
/* ... */
#define CRYP_DATAWIDTHUNIT_WORD 0x00000000U
#define CRYP_DATAWIDTHUNIT_BYTE 0x00000001U
/* ... */
/* ... */
#define CRYP_HEADERWIDTHUNIT_WORD 0x00000000U
#define CRYP_HEADERWIDTHUNIT_BYTE 0x00000001U
/* ... */
/* ... */
#if defined(CRYP)
#define CRYP_DES_ECB CRYP_CR_ALGOMODE_DES_ECB
#define CRYP_DES_CBC CRYP_CR_ALGOMODE_DES_CBC
#define CRYP_TDES_ECB CRYP_CR_ALGOMODE_TDES_ECB
#define CRYP_TDES_CBC CRYP_CR_ALGOMODE_TDES_CBC
#define CRYP_AES_ECB CRYP_CR_ALGOMODE_AES_ECB
#define CRYP_AES_CBC CRYP_CR_ALGOMODE_AES_CBC
#define CRYP_AES_CTR CRYP_CR_ALGOMODE_AES_CTR
7 defines#if defined (CRYP_CR_ALGOMODE_AES_GCM)
#define CRYP_AES_GCM CRYP_CR_ALGOMODE_AES_GCM
#define CRYP_AES_CCM CRYP_CR_ALGOMODE_AES_CCM
/* ... */#endif /* ... */
#else
#define CRYP_AES_ECB 0x00000000U
#define CRYP_AES_CBC AES_CR_CHMOD_0
#define CRYP_AES_CTR AES_CR_CHMOD_1
#define CRYP_AES_GCM_GMAC (AES_CR_CHMOD_0 | AES_CR_CHMOD_1)
#define CRYP_AES_CCM AES_CR_CHMOD_2
/* ... */#endif
/* ... */
/* ... */
#if defined(CRYP)
#define CRYP_KEYSIZE_128B 0x00000000U
#define CRYP_KEYSIZE_192B CRYP_CR_KEYSIZE_0
#define CRYP_KEYSIZE_256B CRYP_CR_KEYSIZE_1
/* ... */#else
#define CRYP_KEYSIZE_128B 0x00000000U
#define CRYP_KEYSIZE_256B AES_CR_KEYSIZE
/* ... */#endif
/* ... */
/* ... */
#if defined(CRYP)
#define CRYP_DATATYPE_32B 0x00000000U
#define CRYP_DATATYPE_16B CRYP_CR_DATATYPE_0
#define CRYP_DATATYPE_8B CRYP_CR_DATATYPE_1
#define CRYP_DATATYPE_1B CRYP_CR_DATATYPE
/* ... */#else
#define CRYP_DATATYPE_32B 0x00000000U
#define CRYP_DATATYPE_16B AES_CR_DATATYPE_0
#define CRYP_DATATYPE_8B AES_CR_DATATYPE_1
#define CRYP_DATATYPE_1B AES_CR_DATATYPE
/* ... */#endif
/* ... */
/* ... */
#if defined (CRYP)
#define CRYP_IT_INI CRYP_IMSCR_INIM
#define CRYP_IT_OUTI CRYP_IMSCR_OUTIM
/* ... */#else
#define CRYP_IT_CCFIE AES_CR_CCFIE
#define CRYP_IT_ERRIE AES_CR_ERRIE
#define CRYP_IT_WRERR AES_SR_WRERR
#define CRYP_IT_RDERR AES_SR_RDERR
#define CRYP_IT_CCF AES_SR_CCF
/* ... */#endif
/* ... */
/* ... */
#if defined (CRYP)
#define CRYP_FLAG_IFEM CRYP_SR_IFEM
#define CRYP_FLAG_IFNF CRYP_SR_IFNF
#define CRYP_FLAG_OFNE CRYP_SR_OFNE
#define CRYP_FLAG_OFFU CRYP_SR_OFFU
#define CRYP_FLAG_BUSY CRYP_SR_BUSY
/* ... */
#define CRYP_FLAG_OUTRIS 0x01000002U
#define CRYP_FLAG_INRIS 0x01000001U
7 defines#else/* ... */
#define CRYP_FLAG_BUSY AES_SR_BUSY
#define CRYP_FLAG_WRERR AES_SR_WRERR
#define CRYP_FLAG_RDERR AES_SR_RDERR
#define CRYP_FLAG_CCF AES_SR_CCF
#define CRYP_CCF_CLEAR AES_CR_CCFC
#define CRYP_ERR_CLEAR AES_CR_ERRC
6 defines#endif/* ... */
/* ... */
/* ... */
#define CRYP_KEYIVCONFIG_ALWAYS 0x00000000U
#define CRYP_KEYIVCONFIG_ONCE 0x00000001U
/* ... */
/* ... */
Exported constants
/* ... */
/* ... */
#if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
#define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) do{\
(__HANDLE__)->State = HAL_CRYP_STATE_RESET;\
(__HANDLE__)->MspInitCallback = NULL;\
(__HANDLE__)->MspDeInitCallback = NULL;\
...}while(0)...
/* ... */#else
#define __HAL_CRYP_RESET_HANDLE_STATE(__HANDLE__) ( (__HANDLE__)->State = HAL_CRYP_STATE_RESET)
#endif
/* ... */
#if defined(CRYP)
#define __HAL_CRYP_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= CRYP_CR_CRYPEN)
#define __HAL_CRYP_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~CRYP_CR_CRYPEN)
/* ... */#else
#define __HAL_CRYP_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= AES_CR_EN)
#define __HAL_CRYP_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~AES_CR_EN)
/* ... */#endif
/* ... */
#define CRYP_FLAG_MASK 0x0000001FU
#if defined(CRYP)
#define __HAL_CRYP_GET_FLAG(__HANDLE__, __FLAG__) ((((uint8_t)((__FLAG__) >> 24)) == 0x01U)?((((__HANDLE__)->Instance->RISR) & ((__FLAG__) & CRYP_FLAG_MASK)) == ((__FLAG__) & CRYP_FLAG_MASK)): \
((((__HANDLE__)->Instance->RISR) & ((__FLAG__) & CRYP_FLAG_MASK)) == ((__FLAG__) & CRYP_FLAG_MASK)))...
/* ... */#else
#define __HAL_CRYP_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
#endif
/* ... */
#if defined(AES)
#define __HAL_CRYP_CLEAR_FLAG(__HANDLE__, __FLAG__) SET_BIT((__HANDLE__)->Instance->CR, (__FLAG__))
/* ... */
#define __HAL_CRYP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR\
& (__INTERRUPT__)) == (__INTERRUPT__))...
/* ... */
#endif
/* ... */
#if defined(CRYP)
#define __HAL_CRYP_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->MISR\
& (__INTERRUPT__)) == (__INTERRUPT__))...
/* ... */#else
#define __HAL_CRYP_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR & (__INTERRUPT__)) == (__INTERRUPT__))
#endif
/* ... */
#if defined(CRYP)
#define __HAL_CRYP_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IMSCR) |= (__INTERRUPT__))
#else
#define __HAL_CRYP_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) |= (__INTERRUPT__))
#endif
/* ... */
#if defined(CRYP)
#define __HAL_CRYP_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IMSCR) &= ~(__INTERRUPT__))
#else
#define __HAL_CRYP_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) &= ~(__INTERRUPT__))
#endif
/* ... */
#if defined (CRYP_CR_ALGOMODE_AES_GCM)|| defined (AES)
#include "stm32f4xx_hal_cryp_ex.h"
/* ... */#endif Exported macros
/* ... */
/* ... */
HAL_StatusTypeDef HAL_CRYP_Init(CRYP_HandleTypeDef *hcryp);
HAL_StatusTypeDef HAL_CRYP_DeInit(CRYP_HandleTypeDef *hcryp);
void HAL_CRYP_MspInit(CRYP_HandleTypeDef *hcryp);
void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef *hcryp);
HAL_StatusTypeDef HAL_CRYP_SetConfig(CRYP_HandleTypeDef *hcryp, CRYP_ConfigTypeDef *pConf);
HAL_StatusTypeDef HAL_CRYP_GetConfig(CRYP_HandleTypeDef *hcryp, CRYP_ConfigTypeDef *pConf);
#if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
HAL_StatusTypeDef HAL_CRYP_RegisterCallback(CRYP_HandleTypeDef *hcryp, HAL_CRYP_CallbackIDTypeDef CallbackID,
pCRYP_CallbackTypeDef pCallback);
HAL_StatusTypeDef HAL_CRYP_UnRegisterCallback(CRYP_HandleTypeDef *hcryp, HAL_CRYP_CallbackIDTypeDef CallbackID);/* ... */
#endif
/* ... */
/* ... */
HAL_StatusTypeDef HAL_CRYP_Encrypt(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output,
uint32_t Timeout);
HAL_StatusTypeDef HAL_CRYP_Decrypt(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output,
uint32_t Timeout);
HAL_StatusTypeDef HAL_CRYP_Encrypt_IT(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output);
HAL_StatusTypeDef HAL_CRYP_Decrypt_IT(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output);
HAL_StatusTypeDef HAL_CRYP_Encrypt_DMA(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output);
HAL_StatusTypeDef HAL_CRYP_Decrypt_DMA(CRYP_HandleTypeDef *hcryp, uint32_t *Input, uint16_t Size, uint32_t *Output);
/* ... */
/* ... */
void HAL_CRYP_IRQHandler(CRYP_HandleTypeDef *hcryp);
HAL_CRYP_STATETypeDef HAL_CRYP_GetState(CRYP_HandleTypeDef *hcryp);
void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp);
void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp);
void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp);
uint32_t HAL_CRYP_GetError(CRYP_HandleTypeDef *hcryp);
/* ... */
/* ... */
Exported functions
/* ... */
/* ... */
#if defined(CRYP)
#if defined (CRYP_CR_ALGOMODE_AES_GCM)
#define IS_CRYP_ALGORITHM(ALGORITHM) (((ALGORITHM) == CRYP_DES_ECB) || \
((ALGORITHM) == CRYP_DES_CBC) || \
((ALGORITHM) == CRYP_TDES_ECB) || \
((ALGORITHM) == CRYP_TDES_CBC) || \
((ALGORITHM) == CRYP_AES_ECB) || \
((ALGORITHM) == CRYP_AES_CBC) || \
((ALGORITHM) == CRYP_AES_CTR) || \
((ALGORITHM) == CRYP_AES_GCM) || \
((ALGORITHM) == CRYP_AES_CCM))...
/* ... */#else
#define IS_CRYP_ALGORITHM(ALGORITHM) (((ALGORITHM) == CRYP_DES_ECB) || \
((ALGORITHM) == CRYP_DES_CBC) || \
((ALGORITHM) == CRYP_TDES_ECB) || \
((ALGORITHM) == CRYP_TDES_CBC) || \
((ALGORITHM) == CRYP_AES_ECB) || \
((ALGORITHM) == CRYP_AES_CBC) || \
((ALGORITHM) == CRYP_AES_CTR))...
/* ... */#endif
#define IS_CRYP_KEYSIZE(KEYSIZE)(((KEYSIZE) == CRYP_KEYSIZE_128B) || \
((KEYSIZE) == CRYP_KEYSIZE_192B) || \
((KEYSIZE) == CRYP_KEYSIZE_256B))...
/* ... */#else
#define IS_CRYP_ALGORITHM(ALGORITHM) (((ALGORITHM) == CRYP_AES_ECB) || \
((ALGORITHM) == CRYP_AES_CBC) || \
((ALGORITHM) == CRYP_AES_CTR) || \
((ALGORITHM) == CRYP_AES_GCM_GMAC)|| \
((ALGORITHM) == CRYP_AES_CCM))...
#define IS_CRYP_KEYSIZE(KEYSIZE)(((KEYSIZE) == CRYP_KEYSIZE_128B) || \
((KEYSIZE) == CRYP_KEYSIZE_256B))...
/* ... */#endif
#define IS_CRYP_DATATYPE(DATATYPE)(((DATATYPE) == CRYP_DATATYPE_32B) || \
((DATATYPE) == CRYP_DATATYPE_16B) || \
((DATATYPE) == CRYP_DATATYPE_8B) || \
((DATATYPE) == CRYP_DATATYPE_1B))...
#define IS_CRYP_INIT(CONFIG)(((CONFIG) == CRYP_KEYIVCONFIG_ALWAYS) || \
((CONFIG) == CRYP_KEYIVCONFIG_ONCE))...
/* ... */
/* ... */
Private macros
/* ... */
/* ... */
Private constants
/* ... */
/* ... */
Private defines
/* ... */
/* ... */
Private variables
/* ... */
/* ... */
Private functions prototypes
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */#endif
/* ... */
#ifdef __cplusplus
}extern "C" { ... }
#endif
/* ... */
#endif