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
215
216
217
221
222
223
224
225
226
229
230
233
234
235
238
239
242
243
246
247
250
251
254
255
258
259
262
263
266
267
268
269
270
273
274
275
276
277
278
279
280
281
282
285
286
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
335
336
337
338
339
340
341
342
343
344
345
346
347
349
350
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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
408
409
410
411
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
437
438
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
464
473
474
479
488
489
490
491
492
493
494
495
496
497
498
499
500
509
510
517
526
527
534
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
570
571
572
573
574
575
576
577
581
585
589
593
597
603
604
605
625
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
666
671
675
679
683
689
690
691
711
718
719
720
721
722
723
724
725
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
799
800
801
802
803
804
805
806
807
808
809
810
811
815
816
817
818
819
820
821
822
823
824
825
826
827
828
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
857
858
859
860
861
862
863
864
865
866
867
868
869
873
874
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
944
945
946
947
948
949
950
951
952
953
954
955
959
960
961
962
963
964
965
966
967
968
969
970
971
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1132
1133
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1193
1194
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1253
1254
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1331
1332
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1374
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1424
1425
1427
1428
1429
1430
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1472
1473
1474
1475
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1519
1520
1521
1522
1523
1524
1525
1531
1532
1533
1537
1538
1542
1543
1544
1548
1549
1554
1558
1559
1560
1561
1562
1563
1567
1568
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1599
1601
1602
1607
1608
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1630
1635
1638
1639
1640
1643
1644
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1728
1729
1730
1731
1732
1733
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1781
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1846
1847
1848
1850
1851
1852
1853
1854
1855
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1958
1959
1960
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2049
2050
2051
2052
2059
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2110
2111
2112
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2129
2130
2131
2132
2133
2134
2136
2137
2138
2139
2140
2141
2147
2148
2149
2150
2151
2152
2154
2155
2156
2160
2161
2162
2163
2164
2165
2166
2170
2171
2172
2173
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2192
2197
2199
2216
2224
2225
2226
2227
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2243
2244
2245
2246
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2332
2333
2334
2335
2336
2337
2338
2343
2344
2345
2346
2347
2348
2349
2350
2351
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2374
2375
2376
2377
2380
2381
2382
2383
2384
2385
2390
2391
2392
2393
2394
2395
2396
2397
2398
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2506
2507
2508
2509
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2538
2539
2540
2541
2542
2543
2544
2545
2546
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2600
2601
2602
2603
2604
2605
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2634
2635
2636
2637
2638
2643
2644
2645
2646
2647
2648
2649
2650
2651
2655
2656
2657
2662
2663
2664
2665
2666
2667
2668
2669
2670
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2703
2704
2705
2706
2707
2708
2713
2714
2715
2716
2717
2718
2723
2724
2725
2726
2727
2728
2729
2735
2739
2740
2741
2742
2743
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2772
2774
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2854
2856
2860
2861
2862
2863
2867
2868
2869
2870
2871
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2908
2909
2910
2911
2912
2913
2917
2918
2919
2920
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2983
2984
2985
2986
2987
2988
2989
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3071
3072
3073
3074
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3098
3099
3100
3101
3102
3103
3104
3105
3106
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3180
3185
3186
3187
3190
3191
3193
3195
3196
3198
3200
3201
3202
3203
3204
3205
3206
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3261
3266
3267
3270
3271
3272
3273
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3291
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3346
3347
3348
3349
3350
3351
3352
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3387
3399
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3492
3493
3494
3495
3496
3500
3501
3504
3505
3506
3507
3510
3511
3514
/* ... */
#include "stm32f4xx_hal.h"
/* ... */
#if defined (HASH)
/* ... */
#ifdef HAL_HASH_MODULE_ENABLED
/* ... */
/* ... */
#define HASH_DIGEST_CALCULATION_NOT_STARTED ((uint32_t)0x00000000U)
#define HASH_DIGEST_CALCULATION_STARTED ((uint32_t)0x00000001U)
/* ... */
/* ... */
#define HASH_NUMBER_OF_CSR_REGISTERS 54U
/* ... */
/* ... */
#define HASH_TIMEOUTVALUE 1000U
/* ... */
/* ... */
#define HASH_DMA_SUSPENSION_WORDS_LIMIT 20U
5 defines
/* ... */
/* ... */
Private define
/* ... */
static void HASH_DMAXferCplt(DMA_HandleTypeDef *hdma);
static void HASH_DMAError(DMA_HandleTypeDef *hdma);
static void HASH_GetDigest(uint8_t *pMsgDigest, uint8_t Size);
static HAL_StatusTypeDef HASH_WaitOnFlagUntilTimeout(HASH_HandleTypeDef *hhash, uint32_t Flag, FlagStatus Status,
uint32_t Timeout);
static HAL_StatusTypeDef HASH_WriteData(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size);
static HAL_StatusTypeDef HASH_IT(HASH_HandleTypeDef *hhash);
static uint32_t HASH_Write_Block_Data(HASH_HandleTypeDef *hhash);
static HAL_StatusTypeDef HMAC_Processing(HASH_HandleTypeDef *hhash, uint32_t Timeout);
/* ... */
/* ... */
/* ... */
/* ... */
HAL_StatusTypeDef HAL_HASH_Init(HASH_HandleTypeDef *hhash)
{
if (hhash == NULL)
{
return HAL_ERROR;
}if (hhash == NULL) { ... }
assert_param(IS_HASH_DATATYPE(hhash->Init.DataType));
#if (USE_HAL_HASH_REGISTER_CALLBACKS == 1)
if (hhash->State == HAL_HASH_STATE_RESET)
{
hhash->Lock = HAL_UNLOCKED;
hhash->InCpltCallback = HAL_HASH_InCpltCallback;
hhash->DgstCpltCallback = HAL_HASH_DgstCpltCallback;
/* ... */
hhash->ErrorCallback = HAL_HASH_ErrorCallback;
if (hhash->MspInitCallback == NULL)
{
hhash->MspInitCallback = HAL_HASH_MspInit;
}if (hhash->MspInitCallback == NULL) { ... }
hhash->MspInitCallback(hhash);
}if (hhash->State == HAL_HASH_STATE_RESET) { ... }
/* ... */#else
if (hhash->State == HAL_HASH_STATE_RESET)
{
hhash->Lock = HAL_UNLOCKED;
HAL_HASH_MspInit(hhash);
}if (hhash->State == HAL_HASH_STATE_RESET) { ... }
/* ... */#endif
hhash->State = HAL_HASH_STATE_BUSY;
hhash->HashInCount = 0;
hhash->HashBuffSize = 0;
hhash->HashITCounter = 0;
hhash->NbWordsAlreadyPushed = 0;
hhash->DigestCalculationDisable = RESET;
hhash->Phase = HAL_HASH_PHASE_READY;
hhash->SuspendRequest = HAL_HASH_SUSPEND_NONE;
MODIFY_REG(HASH->CR, HASH_CR_DATATYPE, hhash->Init.DataType);
#if defined(HASH_CR_MDMAT)
__HAL_HASH_RESET_MDMAT();/* ... */
#endif
hhash->Status = HAL_OK;
hhash->State = HAL_HASH_STATE_READY;
hhash->ErrorCode = HAL_HASH_ERROR_NONE;
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HASH_DeInit(HASH_HandleTypeDef *hhash)
{
if (hhash == NULL)
{
return HAL_ERROR;
}if (hhash == NULL) { ... }
hhash->State = HAL_HASH_STATE_BUSY;
hhash->Phase = HAL_HASH_PHASE_READY;
hhash->HashInCount = 0;
hhash->HashBuffSize = 0;
hhash->HashITCounter = 0;
hhash->DigestCalculationDisable = RESET;
#if (USE_HAL_HASH_REGISTER_CALLBACKS == 1)
if (hhash->MspDeInitCallback == NULL)
{
hhash->MspDeInitCallback = HAL_HASH_MspDeInit;
}if (hhash->MspDeInitCallback == NULL) { ... }
hhash->MspDeInitCallback(hhash);/* ... */
#else
HAL_HASH_MspDeInit(hhash);/* ... */
#endif
hhash->Status = HAL_OK;
hhash->State = HAL_HASH_STATE_RESET;
hhash->ErrorCode = HAL_HASH_ERROR_NONE;
hhash->Accumulation = 0U;
return HAL_OK;
}{ ... }
/* ... */
__weak void HAL_HASH_MspInit(HASH_HandleTypeDef *hhash)
{
UNUSED(hhash);
/* ... */
}{ ... }
/* ... */
__weak void HAL_HASH_MspDeInit(HASH_HandleTypeDef *hhash)
{
UNUSED(hhash);
/* ... */
}{ ... }
/* ... */
__weak void HAL_HASH_InCpltCallback(HASH_HandleTypeDef *hhash)
{
UNUSED(hhash);
/* ... */
}{ ... }
/* ... */
__weak void HAL_HASH_DgstCpltCallback(HASH_HandleTypeDef *hhash)
{
UNUSED(hhash);
/* ... */
}{ ... }
/* ... */
__weak void HAL_HASH_ErrorCallback(HASH_HandleTypeDef *hhash)
{
UNUSED(hhash);
/* ... */
}{ ... }
#if (USE_HAL_HASH_REGISTER_CALLBACKS == 1)
/* ... */
HAL_StatusTypeDef HAL_HASH_RegisterCallback(HASH_HandleTypeDef *hhash, HAL_HASH_CallbackIDTypeDef CallbackID,
pHASH_CallbackTypeDef pCallback)
{
HAL_StatusTypeDef status = HAL_OK;
if (pCallback == NULL)
{
hhash->ErrorCode |= HAL_HASH_ERROR_INVALID_CALLBACK;
return HAL_ERROR;
}if (pCallback == NULL) { ... }
__HAL_LOCK(hhash);
if (HAL_HASH_STATE_READY == hhash->State)
{
switch (CallbackID)
{
case HAL_HASH_INPUTCPLT_CB_ID :
hhash->InCpltCallback = pCallback;
break;
case HAL_HASH_INPUTCPLT_CB_ID :
case HAL_HASH_DGSTCPLT_CB_ID :
hhash->DgstCpltCallback = pCallback;
break;
case HAL_HASH_DGSTCPLT_CB_ID :
case HAL_HASH_ERROR_CB_ID :
hhash->ErrorCallback = pCallback;
break;
case HAL_HASH_ERROR_CB_ID :
case HAL_HASH_MSPINIT_CB_ID :
hhash->MspInitCallback = pCallback;
break;
case HAL_HASH_MSPINIT_CB_ID :
case HAL_HASH_MSPDEINIT_CB_ID :
hhash->MspDeInitCallback = pCallback;
break;
case HAL_HASH_MSPDEINIT_CB_ID :
default :
hhash->ErrorCode |= HAL_HASH_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;default
}switch (CallbackID) { ... }
}if (HAL_HASH_STATE_READY == hhash->State) { ... }
else if (HAL_HASH_STATE_RESET == hhash->State)
{
switch (CallbackID)
{
case HAL_HASH_MSPINIT_CB_ID :
hhash->MspInitCallback = pCallback;
break;
case HAL_HASH_MSPINIT_CB_ID :
case HAL_HASH_MSPDEINIT_CB_ID :
hhash->MspDeInitCallback = pCallback;
break;
case HAL_HASH_MSPDEINIT_CB_ID :
default :
hhash->ErrorCode |= HAL_HASH_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;default
}switch (CallbackID) { ... }
}else if (HAL_HASH_STATE_RESET == hhash->State) { ... }
else
{
hhash->ErrorCode |= HAL_HASH_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
}else { ... }
__HAL_UNLOCK(hhash);
return status;
}HAL_HASH_RegisterCallback (HASH_HandleTypeDef *hhash, HAL_HASH_CallbackIDTypeDef CallbackID, pHASH_CallbackTypeDef pCallback) { ... }
/* ... */
HAL_StatusTypeDef HAL_HASH_UnRegisterCallback(HASH_HandleTypeDef *hhash, HAL_HASH_CallbackIDTypeDef CallbackID)
{
HAL_StatusTypeDef status = HAL_OK;
__HAL_LOCK(hhash);
if (HAL_HASH_STATE_READY == hhash->State)
{
switch (CallbackID)
{
case HAL_HASH_INPUTCPLT_CB_ID :
hhash->InCpltCallback = HAL_HASH_InCpltCallback;
break;
case HAL_HASH_INPUTCPLT_CB_ID :
case HAL_HASH_DGSTCPLT_CB_ID :
hhash->DgstCpltCallback = HAL_HASH_DgstCpltCallback;
/* ... */
break;
case HAL_HASH_DGSTCPLT_CB_ID :
case HAL_HASH_ERROR_CB_ID :
hhash->ErrorCallback = HAL_HASH_ErrorCallback;
break;
case HAL_HASH_ERROR_CB_ID :
case HAL_HASH_MSPINIT_CB_ID :
hhash->MspInitCallback = HAL_HASH_MspInit;
break;
case HAL_HASH_MSPINIT_CB_ID :
case HAL_HASH_MSPDEINIT_CB_ID :
hhash->MspDeInitCallback = HAL_HASH_MspDeInit;
break;
case HAL_HASH_MSPDEINIT_CB_ID :
default :
hhash->ErrorCode |= HAL_HASH_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;default
}switch (CallbackID) { ... }
}if (HAL_HASH_STATE_READY == hhash->State) { ... }
else if (HAL_HASH_STATE_RESET == hhash->State)
{
switch (CallbackID)
{
case HAL_HASH_MSPINIT_CB_ID :
hhash->MspInitCallback = HAL_HASH_MspInit;
break;
case HAL_HASH_MSPINIT_CB_ID :
case HAL_HASH_MSPDEINIT_CB_ID :
hhash->MspDeInitCallback = HAL_HASH_MspDeInit;
break;
case HAL_HASH_MSPDEINIT_CB_ID :
default :
hhash->ErrorCode |= HAL_HASH_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;default
}switch (CallbackID) { ... }
}else if (HAL_HASH_STATE_RESET == hhash->State) { ... }
else
{
hhash->ErrorCode |= HAL_HASH_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
}else { ... }
__HAL_UNLOCK(hhash);
return status;
}HAL_HASH_UnRegisterCallback (HASH_HandleTypeDef *hhash, HAL_HASH_CallbackIDTypeDef CallbackID) { ... }
/* ... */#endif
/* ... */
/* ... */
/* ... */
HAL_StatusTypeDef HAL_HASH_MD5_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
uint32_t Timeout)
{
return HASH_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_MD5);
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HASH_MD5_Accmlt(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
{
return HASH_Accumulate(hhash, pInBuffer, Size, HASH_ALGOSELECTION_MD5);
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HASH_MD5_Accmlt_End(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size,
uint8_t *pOutBuffer, uint32_t Timeout)
{
return HASH_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_MD5);
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HASH_SHA1_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
uint32_t Timeout)
{
return HASH_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA1);
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HASH_SHA1_Accmlt(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
{
return HASH_Accumulate(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA1);
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HASH_SHA1_Accmlt_End(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size,
uint8_t *pOutBuffer, uint32_t Timeout)
{
return HASH_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA1);
}{ ... }
/* ... */
/* ... */
/* ... */
HAL_StatusTypeDef HAL_HASH_MD5_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size,
uint8_t *pOutBuffer)
{
return HASH_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_MD5);
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HASH_MD5_Accmlt_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
{
return HASH_Accumulate_IT(hhash, pInBuffer, Size, HASH_ALGOSELECTION_MD5);
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HASH_MD5_Accmlt_End_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size,
uint8_t *pOutBuffer)
{
return HASH_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_MD5);
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HASH_SHA1_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size,
uint8_t *pOutBuffer)
{
return HASH_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA1);
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HASH_SHA1_Accmlt_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
{
return HASH_Accumulate_IT(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA1);
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HASH_SHA1_Accmlt_End_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size,
uint8_t *pOutBuffer)
{
return HASH_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA1);
}{ ... }
/* ... */
void HAL_HASH_IRQHandler(HASH_HandleTypeDef *hhash)
{
hhash->Status = HASH_IT(hhash);
if (hhash->Status != HAL_OK)
{
hhash->ErrorCode |= HAL_HASH_ERROR_IT;
#if (USE_HAL_HASH_REGISTER_CALLBACKS == 1)
hhash->ErrorCallback(hhash);
#else
HAL_HASH_ErrorCallback(hhash);
#endif
hhash->Status = HAL_OK;
}if (hhash->Status != HAL_OK) { ... }
}{ ... }
/* ... */
/* ... */
/* ... */
HAL_StatusTypeDef HAL_HASH_MD5_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
{
return HASH_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_MD5);
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HASH_MD5_Finish(HASH_HandleTypeDef *hhash, uint8_t *pOutBuffer, uint32_t Timeout)
{
return HASH_Finish(hhash, pOutBuffer, Timeout);
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HASH_SHA1_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
{
return HASH_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA1);
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HASH_SHA1_Finish(HASH_HandleTypeDef *hhash, uint8_t *pOutBuffer, uint32_t Timeout)
{
return HASH_Finish(hhash, pOutBuffer, Timeout);
}{ ... }
/* ... */
/* ... */
/* ... */
HAL_StatusTypeDef HAL_HMAC_MD5_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
uint32_t Timeout)
{
return HMAC_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_MD5);
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HMAC_SHA1_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
uint32_t Timeout)
{
return HMAC_Start(hhash, pInBuffer, Size, pOutBuffer, Timeout, HASH_ALGOSELECTION_SHA1);
}{ ... }
/* ... */
/* ... */
/* ... */
HAL_StatusTypeDef HAL_HMAC_MD5_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size,
uint8_t *pOutBuffer)
{
return HMAC_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_MD5);
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HMAC_SHA1_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size,
uint8_t *pOutBuffer)
{
return HMAC_Start_IT(hhash, pInBuffer, Size, pOutBuffer, HASH_ALGOSELECTION_SHA1);
}{ ... }
/* ... */
/* ... */
/* ... */
HAL_StatusTypeDef HAL_HMAC_MD5_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
{
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_MD5);
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HMAC_SHA1_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
{
return HMAC_Start_DMA(hhash, pInBuffer, Size, HASH_ALGOSELECTION_SHA1);
}{ ... }
/* ... */
/* ... */
/* ... */
HAL_HASH_StateTypeDef HAL_HASH_GetState(HASH_HandleTypeDef *hhash)
{
return hhash->State;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HASH_GetStatus(HASH_HandleTypeDef *hhash)
{
return hhash->Status;
}{ ... }
/* ... */
void HAL_HASH_ContextSaving(HASH_HandleTypeDef *hhash, uint8_t *pMemBuffer)
{
uint32_t mem_ptr = (uint32_t)pMemBuffer;
uint32_t csr_ptr = (uint32_t)HASH->CSR;
uint32_t i;
UNUSED(hhash);
*(uint32_t *)(mem_ptr) = READ_BIT(HASH->IMR, HASH_IT_DINI | HASH_IT_DCI);
mem_ptr += 4U;
*(uint32_t *)(mem_ptr) = READ_BIT(HASH->STR, HASH_STR_NBLW);
mem_ptr += 4U;
#if defined(HASH_CR_MDMAT)
*(uint32_t *)(mem_ptr) = READ_BIT(HASH->CR, HASH_CR_DMAE | HASH_CR_DATATYPE | HASH_CR_MODE | HASH_CR_ALGO |
HASH_CR_LKEY | HASH_CR_MDMAT);/* ... */
#else
*(uint32_t *)(mem_ptr) = READ_BIT(HASH->CR, HASH_CR_DMAE | HASH_CR_DATATYPE | HASH_CR_MODE | HASH_CR_ALGO |
HASH_CR_LKEY);/* ... */
#endif
mem_ptr += 4U;
for (i = HASH_NUMBER_OF_CSR_REGISTERS; i > 0U; i--)
{
*(uint32_t *)(mem_ptr) = *(uint32_t *)(csr_ptr);
mem_ptr += 4U;
csr_ptr += 4U;
}for (i = HASH_NUMBER_OF_CSR_REGISTERS; i > 0U; i--) { ... }
}{ ... }
/* ... */
void HAL_HASH_ContextRestoring(HASH_HandleTypeDef *hhash, uint8_t *pMemBuffer)
{
uint32_t mem_ptr = (uint32_t)pMemBuffer;
uint32_t csr_ptr = (uint32_t)HASH->CSR;
uint32_t i;
UNUSED(hhash);
WRITE_REG(HASH->IMR, (*(uint32_t *)(mem_ptr)));
mem_ptr += 4U;
WRITE_REG(HASH->STR, (*(uint32_t *)(mem_ptr)));
mem_ptr += 4U;
WRITE_REG(HASH->CR, (*(uint32_t *)(mem_ptr)));
mem_ptr += 4U;
/* ... */
__HAL_HASH_INIT();
for (i = HASH_NUMBER_OF_CSR_REGISTERS; i > 0U; i--)
{
WRITE_REG((*(uint32_t *)(csr_ptr)), (*(uint32_t *)(mem_ptr)));
mem_ptr += 4U;
csr_ptr += 4U;
}for (i = HASH_NUMBER_OF_CSR_REGISTERS; i > 0U; i--) { ... }
}{ ... }
/* ... */
void HAL_HASH_SwFeed_ProcessSuspend(HASH_HandleTypeDef *hhash)
{
hhash->SuspendRequest = HAL_HASH_SUSPEND;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_HASH_DMAFeed_ProcessSuspend(HASH_HandleTypeDef *hhash)
{
uint32_t tmp_remaining_DMATransferSize_inWords;
uint32_t tmp_initial_DMATransferSize_inWords;
uint32_t tmp_words_already_pushed;
if (hhash->State == HAL_HASH_STATE_READY)
{
return HAL_ERROR;
}if (hhash->State == HAL_HASH_STATE_READY) { ... }
else
{
tmp_remaining_DMATransferSize_inWords = ((DMA_Stream_TypeDef *)hhash->hdmain->Instance)->NDTR;
if (tmp_remaining_DMATransferSize_inWords <= HASH_DMA_SUSPENSION_WORDS_LIMIT)
{
return HAL_ERROR;
}if (tmp_remaining_DMATransferSize_inWords <= HASH_DMA_SUSPENSION_WORDS_LIMIT) { ... }
if (HASH_WaitOnFlagUntilTimeout(hhash, HASH_FLAG_BUSY, SET, HASH_TIMEOUTVALUE) != HAL_OK)
{
return HAL_TIMEOUT;
}if (HASH_WaitOnFlagUntilTimeout(hhash, HASH_FLAG_BUSY, SET, HASH_TIMEOUTVALUE) != HAL_OK) { ... }
if (__HAL_HASH_GET_FLAG(HASH_FLAG_DCIS) != RESET)
{
return HAL_ERROR;
}if (__HAL_HASH_GET_FLAG(HASH_FLAG_DCIS) != RESET) { ... }
if (HASH_WaitOnFlagUntilTimeout(hhash, HASH_FLAG_BUSY, RESET, HASH_TIMEOUTVALUE) != HAL_OK)
{
return HAL_TIMEOUT;
}if (HASH_WaitOnFlagUntilTimeout(hhash, HASH_FLAG_BUSY, RESET, HASH_TIMEOUTVALUE) != HAL_OK) { ... }
/* ... */
if (HAL_DMA_Abort(hhash->hdmain) != HAL_OK)
{
return HAL_ERROR;
}if (HAL_DMA_Abort(hhash->hdmain) != HAL_OK) { ... }
CLEAR_BIT(HASH->CR, HASH_CR_DMAE);
if (HASH_WaitOnFlagUntilTimeout(hhash, HASH_FLAG_BUSY, SET, HASH_TIMEOUTVALUE) != HAL_OK)
{
return HAL_TIMEOUT;
}if (HASH_WaitOnFlagUntilTimeout(hhash, HASH_FLAG_BUSY, SET, HASH_TIMEOUTVALUE) != HAL_OK) { ... }
if (__HAL_HASH_GET_FLAG(HASH_FLAG_DCIS) != RESET)
{
return HAL_ERROR;
}if (__HAL_HASH_GET_FLAG(HASH_FLAG_DCIS) != RESET) { ... }
tmp_remaining_DMATransferSize_inWords = ((DMA_Stream_TypeDef *)hhash->hdmain->Instance)->NDTR;
if (tmp_remaining_DMATransferSize_inWords == 0U)
{
/* ... */
return HAL_ERROR;
}if (tmp_remaining_DMATransferSize_inWords == 0U) { ... }
else
{
tmp_initial_DMATransferSize_inWords = (((hhash->HashInCount % 4U) != 0U) ? \
((hhash->HashInCount + 3U) / 4U) : (hhash->HashInCount / 4U));
/* ... */
/* ... */
tmp_words_already_pushed = hhash->NbWordsAlreadyPushed;
if (((tmp_words_already_pushed + tmp_initial_DMATransferSize_inWords - \
tmp_remaining_DMATransferSize_inWords) % 16U) != HASH_NBW_PUSHED())
{
tmp_remaining_DMATransferSize_inWords--;
}if (((tmp_words_already_pushed + tmp_initial_DMATransferSize_inWords - \ tmp_remaining_DMATransferSize_inWords) % 16U) != HASH_NBW_PUSHED()) { ... }
/* ... */
hhash->pHashInBuffPtr += 4U * (tmp_initial_DMATransferSize_inWords - tmp_remaining_DMATransferSize_inWords) ;
hhash->HashInCount = 4U * tmp_remaining_DMATransferSize_inWords;
}else { ... }
hhash->State = HAL_HASH_STATE_SUSPENDED;
return HAL_OK;
}else { ... }
}{ ... }
/* ... */
uint32_t HAL_HASH_GetError(HASH_HandleTypeDef *hhash)
{
return hhash->ErrorCode;
}{ ... }
/* ... */
/* ... */
/* ... */
/* ... */
static void HASH_DMAXferCplt(DMA_HandleTypeDef *hdma)
{
HASH_HandleTypeDef *hhash = (HASH_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
uint32_t inputaddr;
uint32_t buffersize;
HAL_StatusTypeDef status;
if (hhash->State != HAL_HASH_STATE_SUSPENDED)
{
CLEAR_BIT(HASH->CR, HASH_CR_DMAE);
if (READ_BIT(HASH->CR, HASH_CR_MODE) == 0U)
{
hhash->State = HAL_HASH_STATE_READY;
#if (USE_HAL_HASH_REGISTER_CALLBACKS == 1)
hhash->InCpltCallback(hhash);
#else
HAL_HASH_InCpltCallback(hhash);
#endif
}if (READ_BIT(HASH->CR, HASH_CR_MODE) == 0U) { ... }
else
{
/* ... */
if (hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_3)
{
hhash->State = HAL_HASH_STATE_READY;
/* ... */
#if (USE_HAL_HASH_REGISTER_CALLBACKS == 1)
hhash->InCpltCallback(hhash);
#else
HAL_HASH_InCpltCallback(hhash);
#endif
return;
}if (hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_3) { ... }
else if (hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_1)
{
inputaddr = (uint32_t)hhash->pHashMsgBuffPtr;
buffersize = hhash->HashBuffSize;
hhash->Phase = HAL_HASH_PHASE_HMAC_STEP_2;
hhash->HashInCount = hhash->HashBuffSize;
hhash->pHashInBuffPtr = hhash->pHashMsgBuffPtr ;
hhash->NbWordsAlreadyPushed = 0U;
#if defined(HASH_CR_MDMAT)
if (hhash->DigestCalculationDisable != RESET)
{
/* ... */
__HAL_HASH_SET_MDMAT();
}if (hhash->DigestCalculationDisable != RESET) { ... }
/* ... */#endif
}else if (hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_1) { ... }
else
{
if (hhash->DigestCalculationDisable != RESET)
{
/* ... */
hhash->State = HAL_HASH_STATE_READY;
#if (USE_HAL_HASH_REGISTER_CALLBACKS == 1)
hhash->InCpltCallback(hhash);
#else
HAL_HASH_InCpltCallback(hhash);
#endif
return ;
}if (hhash->DigestCalculationDisable != RESET) { ... }
else
{
/* ... */
inputaddr = (uint32_t)hhash->Init.pKey;
buffersize = hhash->Init.KeySize;
hhash->Phase = HAL_HASH_PHASE_HMAC_STEP_3;
hhash->HashInCount = hhash->Init.KeySize;
hhash->pHashInBuffPtr = hhash->Init.pKey ;
hhash->NbWordsAlreadyPushed = 0U;
}else { ... }
}else { ... }
__HAL_HASH_SET_NBVALIDBITS(buffersize);
hhash->hdmain->XferCpltCallback = HASH_DMAXferCplt;
status = HAL_DMA_Start_IT(hhash->hdmain, inputaddr, (uint32_t)&HASH->DIN, \
(((buffersize % 4U) != 0U) ? ((buffersize + (4U - (buffersize % 4U))) / 4U) : \
(buffersize / 4U)));
SET_BIT(HASH->CR, HASH_CR_DMAE);
if (status != HAL_OK)
{
hhash->State = HAL_HASH_STATE_ERROR;
}if (status != HAL_OK) { ... }
else
{
hhash->State = HAL_HASH_STATE_BUSY;
}else { ... }
}else { ... }
}if (hhash->State != HAL_HASH_STATE_SUSPENDED) { ... }
return;
}{ ... }
/* ... */
static void HASH_DMAError(DMA_HandleTypeDef *hdma)
{
HASH_HandleTypeDef *hhash = (HASH_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
if (hhash->State != HAL_HASH_STATE_SUSPENDED)
{
hhash->ErrorCode |= HAL_HASH_ERROR_DMA;
/* ... */
hhash->State = HAL_HASH_STATE_READY;
hhash->Status = HAL_ERROR;
#if (USE_HAL_HASH_REGISTER_CALLBACKS == 1)
hhash->ErrorCallback(hhash);
#else
HAL_HASH_ErrorCallback(hhash);
#endif
hhash->Status = HAL_OK;
}if (hhash->State != HAL_HASH_STATE_SUSPENDED) { ... }
}{ ... }
/* ... */
static HAL_StatusTypeDef HASH_WriteData(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size)
{
uint32_t buffercounter;
__IO uint32_t inputaddr = (uint32_t) pInBuffer;
for (buffercounter = 0U; buffercounter < Size; buffercounter += 4U)
{
HASH->DIN = *(uint32_t *)inputaddr;
inputaddr += 4U;
/* ... */
if ((hhash->SuspendRequest == HAL_HASH_SUSPEND) && ((buffercounter + 4U) < Size))
{
/* ... */
if (__HAL_HASH_GET_FLAG(HASH_FLAG_DINIS))
{
hhash->SuspendRequest = HAL_HASH_SUSPEND_NONE;
/* ... */
if ((hhash->Phase == HAL_HASH_PHASE_PROCESS) || (hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_2))
{
hhash->pHashInBuffPtr = (uint8_t *)inputaddr;
hhash->HashInCount = Size - (buffercounter + 4U);
}if ((hhash->Phase == HAL_HASH_PHASE_PROCESS) || (hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_2)) { ... }
else if ((hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_1) || (hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_3))
{
hhash->pHashKeyBuffPtr = (uint8_t *)inputaddr;
hhash->HashKeyCount = Size - (buffercounter + 4U);
}else if ((hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_1) || (hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_3)) { ... }
else
{
hhash->State = HAL_HASH_STATE_READY;
__HAL_UNLOCK(hhash);
return HAL_ERROR;
}else { ... }
hhash->State = HAL_HASH_STATE_SUSPENDED;
return HAL_OK;
}if (__HAL_HASH_GET_FLAG(HASH_FLAG_DINIS)) { ... }
}if ((hhash->SuspendRequest == HAL_HASH_SUSPEND) && ((buffercounter + 4U) < Size)) { ... }
}for (buffercounter = 0U; buffercounter < Size; buffercounter += 4U) { ... }
return HAL_OK;
}{ ... }
/* ... */
static void HASH_GetDigest(uint8_t *pMsgDigest, uint8_t Size)
{
uint32_t msgdigest = (uint32_t)pMsgDigest;
switch (Size)
{
case 16:
*(uint32_t *)(msgdigest) = __REV(HASH->HR[0]);
msgdigest += 4U;
*(uint32_t *)(msgdigest) = __REV(HASH->HR[1]);
msgdigest += 4U;
*(uint32_t *)(msgdigest) = __REV(HASH->HR[2]);
msgdigest += 4U;
*(uint32_t *)(msgdigest) = __REV(HASH->HR[3]);
break;case 16:
case 20:
*(uint32_t *)(msgdigest) = __REV(HASH->HR[0]);
msgdigest += 4U;
*(uint32_t *)(msgdigest) = __REV(HASH->HR[1]);
msgdigest += 4U;
*(uint32_t *)(msgdigest) = __REV(HASH->HR[2]);
msgdigest += 4U;
*(uint32_t *)(msgdigest) = __REV(HASH->HR[3]);
msgdigest += 4U;
*(uint32_t *)(msgdigest) = __REV(HASH->HR[4]);
break;case 20:
case 28:
*(uint32_t *)(msgdigest) = __REV(HASH->HR[0]);
msgdigest += 4U;
*(uint32_t *)(msgdigest) = __REV(HASH->HR[1]);
msgdigest += 4U;
*(uint32_t *)(msgdigest) = __REV(HASH->HR[2]);
msgdigest += 4U;
*(uint32_t *)(msgdigest) = __REV(HASH->HR[3]);
msgdigest += 4U;
*(uint32_t *)(msgdigest) = __REV(HASH->HR[4]);
#if defined(HASH_CR_MDMAT)
msgdigest += 4U;
*(uint32_t *)(msgdigest) = __REV(HASH_DIGEST->HR[5]);
msgdigest += 4U;
*(uint32_t *)(msgdigest) = __REV(HASH_DIGEST->HR[6]);/* ... */
#endif
break;case 28:
case 32:
*(uint32_t *)(msgdigest) = __REV(HASH->HR[0]);
msgdigest += 4U;
*(uint32_t *)(msgdigest) = __REV(HASH->HR[1]);
msgdigest += 4U;
*(uint32_t *)(msgdigest) = __REV(HASH->HR[2]);
msgdigest += 4U;
*(uint32_t *)(msgdigest) = __REV(HASH->HR[3]);
msgdigest += 4U;
*(uint32_t *)(msgdigest) = __REV(HASH->HR[4]);
#if defined(HASH_CR_MDMAT)
msgdigest += 4U;
*(uint32_t *)(msgdigest) = __REV(HASH_DIGEST->HR[5]);
msgdigest += 4U;
*(uint32_t *)(msgdigest) = __REV(HASH_DIGEST->HR[6]);
msgdigest += 4U;
*(uint32_t *)(msgdigest) = __REV(HASH_DIGEST->HR[7]);/* ... */
#endif
break;case 32:
default:
break;default
}switch (Size) { ... }
}{ ... }
/* ... */
static HAL_StatusTypeDef HASH_WaitOnFlagUntilTimeout(HASH_HandleTypeDef *hhash, uint32_t Flag, FlagStatus Status,
uint32_t Timeout)
{
uint32_t tickstart = HAL_GetTick();
if (Status == RESET)
{
while (__HAL_HASH_GET_FLAG(Flag) == RESET)
{
if (Timeout != HAL_MAX_DELAY)
{
if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
{
hhash->State = HAL_HASH_STATE_READY;
hhash->Status = HAL_TIMEOUT;
__HAL_UNLOCK(hhash);
return HAL_TIMEOUT;
}if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) { ... }
}if (Timeout != HAL_MAX_DELAY) { ... }
}while (__HAL_HASH_GET_FLAG(Flag) == RESET) { ... }
}if (Status == RESET) { ... }
else
{
while (__HAL_HASH_GET_FLAG(Flag) != RESET)
{
if (Timeout != HAL_MAX_DELAY)
{
if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
{
hhash->State = HAL_HASH_STATE_READY;
hhash->Status = HAL_TIMEOUT;
__HAL_UNLOCK(hhash);
return HAL_TIMEOUT;
}if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U)) { ... }
}if (Timeout != HAL_MAX_DELAY) { ... }
}while (__HAL_HASH_GET_FLAG(Flag) != RESET) { ... }
}else { ... }
return HAL_OK;
}{ ... }
/* ... */
static HAL_StatusTypeDef HASH_IT(HASH_HandleTypeDef *hhash)
{
if (hhash->State == HAL_HASH_STATE_BUSY)
{
if (hhash->HashITCounter == 0U)
{
__HAL_HASH_DISABLE_IT(HASH_IT_DINI | HASH_IT_DCI);
/* ... */
hhash->State = HAL_HASH_STATE_READY;
return HAL_ERROR;
}if (hhash->HashITCounter == 0U) { ... }
else if (hhash->HashITCounter == 1U)
{
/* ... */
hhash->HashITCounter = 2U;
}else if (hhash->HashITCounter == 1U) { ... }
else
{
/* ... */
hhash->HashITCounter = 3U;
}else { ... }
if (__HAL_HASH_GET_FLAG(HASH_FLAG_DCIS))
{
HASH_GetDigest(hhash->pHashOutBuffPtr, HASH_DIGEST_LENGTH());
__HAL_HASH_DISABLE_IT(HASH_IT_DINI | HASH_IT_DCI);
hhash->State = HAL_HASH_STATE_READY;
hhash->Phase = HAL_HASH_PHASE_READY;
#if (USE_HAL_HASH_REGISTER_CALLBACKS == 1)
hhash->DgstCpltCallback(hhash);
#else
HAL_HASH_DgstCpltCallback(hhash);
#endif
return HAL_OK;
}if (__HAL_HASH_GET_FLAG(HASH_FLAG_DCIS)) { ... }
if (__HAL_HASH_GET_FLAG(HASH_FLAG_DINIS))
{
/* ... */
if ((hhash->HashInCount != 0U) && (hhash->SuspendRequest == HAL_HASH_SUSPEND))
{
__HAL_HASH_DISABLE_IT(HASH_IT_DINI | HASH_IT_DCI);
hhash->SuspendRequest = HAL_HASH_SUSPEND_NONE;
hhash->State = HAL_HASH_STATE_SUSPENDED;
return HAL_OK;
}if ((hhash->HashInCount != 0U) && (hhash->SuspendRequest == HAL_HASH_SUSPEND)) { ... }
/* ... */
if (HASH_Write_Block_Data(hhash) == HASH_DIGEST_CALCULATION_STARTED)
{
/* ... */
#if (USE_HAL_HASH_REGISTER_CALLBACKS == 1)
hhash->InCpltCallback(hhash);
#else
HAL_HASH_InCpltCallback(hhash);
#endif
if (hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_1)
{
if (HASH_WaitOnFlagUntilTimeout(hhash, HASH_FLAG_BUSY, SET, HASH_TIMEOUTVALUE) != HAL_OK)
{
__HAL_HASH_DISABLE_IT(HASH_IT_DINI | HASH_IT_DCI);
return HAL_TIMEOUT;
}if (HASH_WaitOnFlagUntilTimeout(hhash, HASH_FLAG_BUSY, SET, HASH_TIMEOUTVALUE) != HAL_OK) { ... }
hhash->Phase = HAL_HASH_PHASE_HMAC_STEP_2;
__HAL_HASH_SET_NBVALIDBITS(hhash->HashBuffSize);
hhash->HashInCount = hhash->HashBuffSize;
hhash->pHashInBuffPtr = hhash->pHashMsgBuffPtr;
hhash->HashITCounter = 1;
/* ... */
__HAL_HASH_ENABLE_IT(HASH_IT_DINI);
}if (hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_1) { ... }
else if (hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_2)
{
if (HASH_WaitOnFlagUntilTimeout(hhash, HASH_FLAG_BUSY, SET, HASH_TIMEOUTVALUE) != HAL_OK)
{
__HAL_HASH_DISABLE_IT(HASH_IT_DINI | HASH_IT_DCI);
return HAL_TIMEOUT;
}if (HASH_WaitOnFlagUntilTimeout(hhash, HASH_FLAG_BUSY, SET, HASH_TIMEOUTVALUE) != HAL_OK) { ... }
hhash->Phase = HAL_HASH_PHASE_HMAC_STEP_3;
__HAL_HASH_SET_NBVALIDBITS(hhash->Init.KeySize);
hhash->HashInCount = hhash->Init.KeySize;
hhash->pHashInBuffPtr = hhash->Init.pKey;
hhash->HashITCounter = 1;
/* ... */
__HAL_HASH_ENABLE_IT(HASH_IT_DINI);
}else if (hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_2) { ... }
else
{
}else { ... }
}if (HASH_Write_Block_Data(hhash) == HASH_DIGEST_CALCULATION_STARTED) { ... }
}if (__HAL_HASH_GET_FLAG(HASH_FLAG_DINIS)) { ... }
return HAL_OK;
}if (hhash->State == HAL_HASH_STATE_BUSY) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
static uint32_t HASH_Write_Block_Data(HASH_HandleTypeDef *hhash)
{
uint32_t inputaddr;
uint32_t buffercounter;
uint32_t inputcounter;
uint32_t ret = HASH_DIGEST_CALCULATION_NOT_STARTED;
if (hhash->HashInCount > 64U)
{
inputaddr = (uint32_t)hhash->pHashInBuffPtr;
/* ... */
for (buffercounter = 0U; buffercounter < 64U; buffercounter += 4U)
{
HASH->DIN = *(uint32_t *)inputaddr;
inputaddr += 4U;
}for (buffercounter = 0U; buffercounter < 64U; buffercounter += 4U) { ... }
/* ... */
if (hhash->HashITCounter == 2U)
{
HASH->DIN = *(uint32_t *)inputaddr;
if (hhash->HashInCount >= 68U)
{
/* ... */
hhash->HashInCount -= 68U;
hhash->pHashInBuffPtr += 68U;
}if (hhash->HashInCount >= 68U) { ... }
else
{
hhash->HashInCount = 0U;
}else { ... }
}if (hhash->HashITCounter == 2U) { ... }
else
{
/* ... */
hhash->HashInCount -= 64U;
hhash->pHashInBuffPtr += 64U;
}else { ... }
}if (hhash->HashInCount > 64U) { ... }
else
{
/* ... */
inputaddr = (uint32_t)hhash->pHashInBuffPtr;
inputcounter = hhash->HashInCount;
__HAL_HASH_DISABLE_IT(HASH_IT_DINI);
for (buffercounter = 0U; buffercounter < ((inputcounter + 3U) / 4U); buffercounter++)
{
HASH->DIN = *(uint32_t *)inputaddr;
inputaddr += 4U;
}for (buffercounter = 0U; buffercounter < ((inputcounter + 3U) / 4U); buffercounter++) { ... }
if (hhash->Accumulation == 1U)
{
/* ... */
hhash->Accumulation = 0U;
hhash->State = HAL_HASH_STATE_READY;
#if (USE_HAL_HASH_REGISTER_CALLBACKS == 1)
hhash->InCpltCallback(hhash);
#else
HAL_HASH_InCpltCallback(hhash);
#endif
}if (hhash->Accumulation == 1U) { ... }
else
{
__HAL_HASH_START_DIGEST();
/* ... */
ret = HASH_DIGEST_CALCULATION_STARTED;
}else { ... }
hhash->HashInCount = 0;
}else { ... }
return ret;
}{ ... }
/* ... */
static HAL_StatusTypeDef HMAC_Processing(HASH_HandleTypeDef *hhash, uint32_t Timeout)
{
if ((hhash->Phase != HAL_HASH_PHASE_HMAC_STEP_1) && (hhash->Phase != HAL_HASH_PHASE_HMAC_STEP_2)
&& (hhash->Phase != HAL_HASH_PHASE_HMAC_STEP_3))
{
hhash->State = HAL_HASH_STATE_READY;
__HAL_UNLOCK(hhash);
return HAL_ERROR;
}if ((hhash->Phase != HAL_HASH_PHASE_HMAC_STEP_1) && (hhash->Phase != HAL_HASH_PHASE_HMAC_STEP_2) && (hhash->Phase != HAL_HASH_PHASE_HMAC_STEP_3)) { ... }
if (hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_1)
{
__HAL_HASH_SET_NBVALIDBITS(hhash->Init.KeySize);
hhash->Status = HASH_WriteData(hhash, hhash->pHashKeyBuffPtr, hhash->HashKeyCount);
if (hhash->Status != HAL_OK)
{
return hhash->Status;
}if (hhash->Status != HAL_OK) { ... }
if (hhash->State == HAL_HASH_STATE_SUSPENDED)
{
__HAL_UNLOCK(hhash);
return HAL_OK;
}if (hhash->State == HAL_HASH_STATE_SUSPENDED) { ... }
__HAL_HASH_START_DIGEST();
if (HASH_WaitOnFlagUntilTimeout(hhash, HASH_FLAG_BUSY, SET, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}if (HASH_WaitOnFlagUntilTimeout(hhash, HASH_FLAG_BUSY, SET, Timeout) != HAL_OK) { ... }
hhash->Phase = HAL_HASH_PHASE_HMAC_STEP_2;
}if (hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_1) { ... }
/* ... */
if (hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_2)
{
__HAL_HASH_SET_NBVALIDBITS(hhash->HashBuffSize);
hhash->Status = HASH_WriteData(hhash, hhash->pHashInBuffPtr, hhash->HashInCount);
if (hhash->Status != HAL_OK)
{
return hhash->Status;
}if (hhash->Status != HAL_OK) { ... }
if (hhash->State == HAL_HASH_STATE_SUSPENDED)
{
__HAL_UNLOCK(hhash);
return HAL_OK;
}if (hhash->State == HAL_HASH_STATE_SUSPENDED) { ... }
__HAL_HASH_START_DIGEST();
if (HASH_WaitOnFlagUntilTimeout(hhash, HASH_FLAG_BUSY, SET, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}if (HASH_WaitOnFlagUntilTimeout(hhash, HASH_FLAG_BUSY, SET, Timeout) != HAL_OK) { ... }
hhash->Phase = HAL_HASH_PHASE_HMAC_STEP_3;
/* ... */
hhash->pHashKeyBuffPtr = hhash->Init.pKey;
hhash->HashKeyCount = hhash->Init.KeySize;
}if (hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_2) { ... }
/* ... */
if (hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_3)
{
__HAL_HASH_SET_NBVALIDBITS(hhash->Init.KeySize);
hhash->Status = HASH_WriteData(hhash, hhash->pHashKeyBuffPtr, hhash->HashKeyCount);
if (hhash->Status != HAL_OK)
{
return hhash->Status;
}if (hhash->Status != HAL_OK) { ... }
if (hhash->State == HAL_HASH_STATE_SUSPENDED)
{
__HAL_UNLOCK(hhash);
return HAL_OK;
}if (hhash->State == HAL_HASH_STATE_SUSPENDED) { ... }
__HAL_HASH_START_DIGEST();
if (HASH_WaitOnFlagUntilTimeout(hhash, HASH_FLAG_DCIS, RESET, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}if (HASH_WaitOnFlagUntilTimeout(hhash, HASH_FLAG_DCIS, RESET, Timeout) != HAL_OK) { ... }
HASH_GetDigest(hhash->pHashOutBuffPtr, HASH_DIGEST_LENGTH());
hhash->Phase = HAL_HASH_PHASE_READY;
}if (hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_3) { ... }
hhash->State = HAL_HASH_STATE_READY;
__HAL_UNLOCK(hhash);
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HASH_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
uint32_t Timeout, uint32_t Algorithm)
{
uint8_t *pInBuffer_tmp;
uint32_t Size_tmp;
HAL_HASH_StateTypeDef State_tmp = hhash->State;
if ((State_tmp == HAL_HASH_STATE_READY) || (State_tmp == HAL_HASH_STATE_SUSPENDED))
{
if ((pInBuffer == NULL) || (pOutBuffer == NULL))
{
hhash->State = HAL_HASH_STATE_READY;
return HAL_ERROR;
}if ((pInBuffer == NULL) || (pOutBuffer == NULL)) { ... }
__HAL_LOCK(hhash);
if (hhash->Phase == HAL_HASH_PHASE_READY)
{
hhash->State = HAL_HASH_STATE_BUSY;
MODIFY_REG(HASH->CR, HASH_CR_LKEY | HASH_CR_ALGO | HASH_CR_MODE | HASH_CR_INIT, Algorithm | HASH_CR_INIT);
__HAL_HASH_SET_NBVALIDBITS(Size);
/* ... */
pInBuffer_tmp = pInBuffer;
Size_tmp = Size;
hhash->Phase = HAL_HASH_PHASE_PROCESS;
}if (hhash->Phase == HAL_HASH_PHASE_READY) { ... }
else if (hhash->Phase == HAL_HASH_PHASE_PROCESS)
{
if (hhash->State == HAL_HASH_STATE_SUSPENDED)
{
/* ... */
pInBuffer_tmp = hhash->pHashInBuffPtr;
Size_tmp = hhash->HashInCount;
}if (hhash->State == HAL_HASH_STATE_SUSPENDED) { ... }
else
{
/* ... */
pInBuffer_tmp = pInBuffer;
Size_tmp = Size;
__HAL_HASH_SET_NBVALIDBITS(Size);
}else { ... }
hhash->State = HAL_HASH_STATE_BUSY;
}else if (hhash->Phase == HAL_HASH_PHASE_PROCESS) { ... }
else
{
hhash->State = HAL_HASH_STATE_READY;
__HAL_UNLOCK(hhash);
return HAL_ERROR;
}else { ... }
hhash->Status = HASH_WriteData(hhash, pInBuffer_tmp, Size_tmp);
if (hhash->Status != HAL_OK)
{
return hhash->Status;
}if (hhash->Status != HAL_OK) { ... }
if (hhash->State != HAL_HASH_STATE_SUSPENDED)
{
__HAL_HASH_START_DIGEST();
if (HASH_WaitOnFlagUntilTimeout(hhash, HASH_FLAG_DCIS, RESET, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}if (HASH_WaitOnFlagUntilTimeout(hhash, HASH_FLAG_DCIS, RESET, Timeout) != HAL_OK) { ... }
HASH_GetDigest(pOutBuffer, HASH_DIGEST_LENGTH());
hhash->State = HAL_HASH_STATE_READY;
hhash->Phase = HAL_HASH_PHASE_READY;
}if (hhash->State != HAL_HASH_STATE_SUSPENDED) { ... }
__HAL_UNLOCK(hhash);
return HAL_OK;
}if ((State_tmp == HAL_HASH_STATE_READY) || (State_tmp == HAL_HASH_STATE_SUSPENDED)) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HASH_Accumulate(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint32_t Algorithm)
{
uint8_t *pInBuffer_tmp;
uint32_t Size_tmp;
HAL_HASH_StateTypeDef State_tmp = hhash->State;
if ((Size % 4U) != 0U)
{
return HAL_ERROR;
}if ((Size % 4U) != 0U) { ... }
if ((State_tmp == HAL_HASH_STATE_READY) || (State_tmp == HAL_HASH_STATE_SUSPENDED))
{
if ((pInBuffer == NULL) || (Size == 0U))
{
hhash->State = HAL_HASH_STATE_READY;
return HAL_ERROR;
}if ((pInBuffer == NULL) || (Size == 0U)) { ... }
__HAL_LOCK(hhash);
if (hhash->State == HAL_HASH_STATE_SUSPENDED)
{
hhash->State = HAL_HASH_STATE_BUSY;
/* ... */
pInBuffer_tmp = hhash->pHashInBuffPtr;
Size_tmp = hhash->HashInCount;
}if (hhash->State == HAL_HASH_STATE_SUSPENDED) { ... }
else
{
hhash->State = HAL_HASH_STATE_BUSY;
/* ... */
pInBuffer_tmp = pInBuffer;
Size_tmp = Size;
if (hhash->Phase == HAL_HASH_PHASE_READY)
{
MODIFY_REG(HASH->CR, HASH_CR_LKEY | HASH_CR_ALGO | HASH_CR_MODE | HASH_CR_INIT, Algorithm | HASH_CR_INIT);
}if (hhash->Phase == HAL_HASH_PHASE_READY) { ... }
hhash->Phase = HAL_HASH_PHASE_PROCESS;
}else { ... }
hhash->Status = HASH_WriteData(hhash, pInBuffer_tmp, Size_tmp);
if (hhash->Status != HAL_OK)
{
return hhash->Status;
}if (hhash->Status != HAL_OK) { ... }
if (hhash->State != HAL_HASH_STATE_SUSPENDED)
{
hhash->State = HAL_HASH_STATE_READY;
}if (hhash->State != HAL_HASH_STATE_SUSPENDED) { ... }
__HAL_UNLOCK(hhash);
return HAL_OK;
}if ((State_tmp == HAL_HASH_STATE_READY) || (State_tmp == HAL_HASH_STATE_SUSPENDED)) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HASH_Accumulate_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint32_t Algorithm)
{
HAL_HASH_StateTypeDef State_tmp = hhash->State;
__IO uint32_t inputaddr = (uint32_t) pInBuffer;
uint32_t SizeVar = Size;
if ((Size % 4U) != 0U)
{
return HAL_ERROR;
}if ((Size % 4U) != 0U) { ... }
if ((State_tmp == HAL_HASH_STATE_READY) || (State_tmp == HAL_HASH_STATE_SUSPENDED))
{
if ((pInBuffer == NULL) || (Size == 0U))
{
hhash->State = HAL_HASH_STATE_READY;
return HAL_ERROR;
}if ((pInBuffer == NULL) || (Size == 0U)) { ... }
__HAL_LOCK(hhash);
if (hhash->State == HAL_HASH_STATE_SUSPENDED)
{
hhash->State = HAL_HASH_STATE_BUSY;
}if (hhash->State == HAL_HASH_STATE_SUSPENDED) { ... }
else
{
hhash->State = HAL_HASH_STATE_BUSY;
if (hhash->Phase == HAL_HASH_PHASE_READY)
{
MODIFY_REG(HASH->CR, HASH_CR_LKEY | HASH_CR_ALGO | HASH_CR_MODE | HASH_CR_INIT, Algorithm | HASH_CR_INIT);
hhash->HashITCounter = 1;
}if (hhash->Phase == HAL_HASH_PHASE_READY) { ... }
else
{
hhash->HashITCounter = 3;
}else { ... }
hhash->Phase = HAL_HASH_PHASE_PROCESS;
/* ... */
while ((!(__HAL_HASH_GET_FLAG(HASH_FLAG_DINIS))) && (SizeVar > 0U))
{
HASH->DIN = *(uint32_t *)inputaddr;
inputaddr += 4U;
SizeVar -= 4U;
}while ((!(__HAL_HASH_GET_FLAG(HASH_FLAG_DINIS))) && (SizeVar > 0U)) { ... }
if ((!(__HAL_HASH_GET_FLAG(HASH_FLAG_DINIS))) || (SizeVar == 0U))
{
hhash->State = HAL_HASH_STATE_READY;
__HAL_UNLOCK(hhash);
return HAL_OK;
}if ((!(__HAL_HASH_GET_FLAG(HASH_FLAG_DINIS))) || (SizeVar == 0U)) { ... }
hhash->HashInCount = SizeVar;
/* ... */
hhash->pHashInBuffPtr = (uint8_t *)inputaddr;
/* ... */
/* ... */
}else { ... }
hhash->Accumulation = 1U;
__HAL_UNLOCK(hhash);
__HAL_HASH_ENABLE_IT(HASH_IT_DINI);
return HAL_OK;
}if ((State_tmp == HAL_HASH_STATE_READY) || (State_tmp == HAL_HASH_STATE_SUSPENDED)) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HASH_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
uint32_t Algorithm)
{
HAL_HASH_StateTypeDef State_tmp = hhash->State;
__IO uint32_t inputaddr = (uint32_t) pInBuffer;
uint32_t polling_step = 0U;
uint32_t initialization_skipped = 0U;
uint32_t SizeVar = Size;
if ((State_tmp == HAL_HASH_STATE_READY) || (State_tmp == HAL_HASH_STATE_SUSPENDED))
{
if ((pInBuffer == NULL) || (Size == 0U) || (pOutBuffer == NULL))
{
hhash->State = HAL_HASH_STATE_READY;
return HAL_ERROR;
}if ((pInBuffer == NULL) || (Size == 0U) || (pOutBuffer == NULL)) { ... }
__HAL_LOCK(hhash);
hhash->State = HAL_HASH_STATE_BUSY;
hhash->HashITCounter = 1;
if (hhash->Phase == HAL_HASH_PHASE_READY)
{
MODIFY_REG(HASH->CR, HASH_CR_LKEY | HASH_CR_ALGO | HASH_CR_MODE | HASH_CR_INIT, Algorithm | HASH_CR_INIT);
__HAL_HASH_SET_NBVALIDBITS(SizeVar);
hhash->HashInCount = SizeVar;
/* ... */
hhash->pHashInBuffPtr = pInBuffer;
/* ... */
/* ... */
hhash->pHashOutBuffPtr = pOutBuffer;
}if (hhash->Phase == HAL_HASH_PHASE_READY) { ... }
else
{
initialization_skipped = 1;
}else { ... }
hhash->Phase = HAL_HASH_PHASE_PROCESS;
/* ... */
while ((!(__HAL_HASH_GET_FLAG(HASH_FLAG_DINIS))) && (SizeVar > 3U))
{
polling_step = 1U;
HASH->DIN = *(uint32_t *)inputaddr;
inputaddr += 4U;
SizeVar -= 4U;
}while ((!(__HAL_HASH_GET_FLAG(HASH_FLAG_DINIS))) && (SizeVar > 3U)) { ... }
if (polling_step == 1U)
{
if (SizeVar == 0U)
{
/* ... */
hhash->pHashOutBuffPtr = pOutBuffer;
__HAL_HASH_START_DIGEST();
__HAL_UNLOCK(hhash);
__HAL_HASH_ENABLE_IT(HASH_IT_DCI);
return HAL_OK;
}if (SizeVar == 0U) { ... }
else if (__HAL_HASH_GET_FLAG(HASH_FLAG_DINIS))
{
/* ... */
hhash->HashInCount = SizeVar;
hhash->pHashInBuffPtr = (uint8_t *)inputaddr;
__HAL_HASH_SET_NBVALIDBITS(SizeVar);
hhash->pHashOutBuffPtr = pOutBuffer;
if (initialization_skipped == 1U)
{
hhash->HashITCounter = 3;
}if (initialization_skipped == 1U) { ... }
}else if (__HAL_HASH_GET_FLAG(HASH_FLAG_DINIS)) { ... }
else
{
/* ... */
__HAL_HASH_SET_NBVALIDBITS(SizeVar);
HASH->DIN = *(uint32_t *)inputaddr;
hhash->pHashOutBuffPtr = pOutBuffer;
__HAL_HASH_START_DIGEST();
__HAL_UNLOCK(hhash);
__HAL_HASH_ENABLE_IT(HASH_IT_DCI);
return HAL_OK;
}else { ... }
}if (polling_step == 1U) { ... }
__HAL_UNLOCK(hhash);
__HAL_HASH_ENABLE_IT(HASH_IT_DINI | HASH_IT_DCI);
return HAL_OK;
}if ((State_tmp == HAL_HASH_STATE_READY) || (State_tmp == HAL_HASH_STATE_SUSPENDED)) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HASH_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint32_t Algorithm)
{
uint32_t inputaddr;
uint32_t inputSize;
HAL_StatusTypeDef status ;
HAL_HASH_StateTypeDef State_tmp = hhash->State;
#if defined (HASH_CR_MDMAT)
/* ... */
assert_param(IS_HASH_DMA_MULTIBUFFER_SIZE(Size));/* ... */
#endif
if ((State_tmp == HAL_HASH_STATE_READY) || (State_tmp == HAL_HASH_STATE_SUSPENDED))
{
if ((pInBuffer == NULL) || (Size == 0U) ||
/* ... */
((hhash->Phase != HAL_HASH_PHASE_READY) && (!(IS_HASH_PROCESSING(hhash)))))
{
hhash->State = HAL_HASH_STATE_READY;
return HAL_ERROR;
}if ((pInBuffer == NULL) || (Size == 0U) || /* Check phase coherency. Phase must be either READY (fresh start) or PROCESS (multi-buffer HASH management) */ ((hhash->Phase != HAL_HASH_PHASE_READY) && (!(IS_HASH_PROCESSING(hhash))))) { ... }
__HAL_LOCK(hhash);
if (hhash->State == HAL_HASH_STATE_READY)
{
hhash->State = HAL_HASH_STATE_BUSY;
/* ... */
if (hhash->Phase == HAL_HASH_PHASE_READY)
{
MODIFY_REG(HASH->CR, HASH_CR_LKEY | HASH_CR_ALGO | HASH_CR_MODE | HASH_CR_INIT, Algorithm | HASH_CR_INIT);
hhash->Phase = HAL_HASH_PHASE_PROCESS;
}if (hhash->Phase == HAL_HASH_PHASE_READY) { ... }
__HAL_HASH_SET_NBVALIDBITS(Size);
inputaddr = (uint32_t)pInBuffer;
inputSize = Size;
hhash->pHashInBuffPtr = pInBuffer;
hhash->HashInCount = Size;
}if (hhash->State == HAL_HASH_STATE_READY) { ... }
else
{
hhash->State = HAL_HASH_STATE_BUSY;
/* ... */
inputaddr = (uint32_t)hhash->pHashInBuffPtr;
inputSize = hhash->HashInCount;
}else { ... }
hhash->hdmain->XferCpltCallback = HASH_DMAXferCplt;
hhash->hdmain->XferErrorCallback = HASH_DMAError;
hhash->NbWordsAlreadyPushed = HASH_NBW_PUSHED();
status = HAL_DMA_Start_IT(hhash->hdmain, inputaddr, (uint32_t)&HASH->DIN, \
(((inputSize % 4U) != 0U) ? ((inputSize + (4U - (inputSize % 4U))) / 4U) : \
(inputSize / 4U)));
SET_BIT(HASH->CR, HASH_CR_DMAE);
__HAL_UNLOCK(hhash);
if (status != HAL_OK)
{
hhash->State = HAL_HASH_STATE_ERROR;
}if (status != HAL_OK) { ... }
return status;
}if ((State_tmp == HAL_HASH_STATE_READY) || (State_tmp == HAL_HASH_STATE_SUSPENDED)) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HASH_Finish(HASH_HandleTypeDef *hhash, uint8_t *pOutBuffer, uint32_t Timeout)
{
if (hhash->State == HAL_HASH_STATE_READY)
{
if (pOutBuffer == NULL)
{
return HAL_ERROR;
}if (pOutBuffer == NULL) { ... }
__HAL_LOCK(hhash);
hhash->State = HAL_HASH_STATE_BUSY;
if (HASH_WaitOnFlagUntilTimeout(hhash, HASH_FLAG_DCIS, RESET, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}if (HASH_WaitOnFlagUntilTimeout(hhash, HASH_FLAG_DCIS, RESET, Timeout) != HAL_OK) { ... }
HASH_GetDigest(pOutBuffer, HASH_DIGEST_LENGTH());
hhash->State = HAL_HASH_STATE_READY;
hhash->Phase = HAL_HASH_PHASE_READY;
__HAL_UNLOCK(hhash);
return HAL_OK;
}if (hhash->State == HAL_HASH_STATE_READY) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HMAC_Start(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
uint32_t Timeout, uint32_t Algorithm)
{
HAL_HASH_StateTypeDef State_tmp = hhash->State;
if ((State_tmp == HAL_HASH_STATE_READY) || (State_tmp == HAL_HASH_STATE_SUSPENDED))
{
if ((pInBuffer == NULL) || (Size == 0U) || (hhash->Init.pKey == NULL) || (hhash->Init.KeySize == 0U)
|| (pOutBuffer == NULL))
{
hhash->State = HAL_HASH_STATE_READY;
return HAL_ERROR;
}if ((pInBuffer == NULL) || (Size == 0U) || (hhash->Init.pKey == NULL) || (hhash->Init.KeySize == 0U) || (pOutBuffer == NULL)) { ... }
__HAL_LOCK(hhash);
hhash->State = HAL_HASH_STATE_BUSY;
if (hhash->Phase == HAL_HASH_PHASE_READY)
{
if (hhash->Init.KeySize > 64U)
{
MODIFY_REG(HASH->CR, HASH_CR_LKEY | HASH_CR_ALGO | HASH_CR_MODE | HASH_CR_INIT,
Algorithm | HASH_ALGOMODE_HMAC | HASH_HMAC_KEYTYPE_LONGKEY | HASH_CR_INIT);
}if (hhash->Init.KeySize > 64U) { ... }
else
{
MODIFY_REG(HASH->CR, HASH_CR_LKEY | HASH_CR_ALGO | HASH_CR_MODE | HASH_CR_INIT,
Algorithm | HASH_ALGOMODE_HMAC | HASH_CR_INIT);
}else { ... }
hhash->Phase = HAL_HASH_PHASE_HMAC_STEP_1;
/* ... */
hhash->pHashOutBuffPtr = pOutBuffer;
hhash->pHashInBuffPtr = pInBuffer;
/* ... */
hhash->HashInCount = Size;
/* ... */
hhash->HashBuffSize = Size;
hhash->pHashKeyBuffPtr = hhash->Init.pKey;
/* ... */
hhash->HashKeyCount = hhash->Init.KeySize;
/* ... */
}if (hhash->Phase == HAL_HASH_PHASE_READY) { ... }
return HMAC_Processing(hhash, Timeout);
}if ((State_tmp == HAL_HASH_STATE_READY) || (State_tmp == HAL_HASH_STATE_SUSPENDED)) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HMAC_Start_IT(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint8_t *pOutBuffer,
uint32_t Algorithm)
{
HAL_HASH_StateTypeDef State_tmp = hhash->State;
if ((State_tmp == HAL_HASH_STATE_READY) || (State_tmp == HAL_HASH_STATE_SUSPENDED))
{
if ((pInBuffer == NULL) || (Size == 0U) || (hhash->Init.pKey == NULL) || (hhash->Init.KeySize == 0U)
|| (pOutBuffer == NULL))
{
hhash->State = HAL_HASH_STATE_READY;
return HAL_ERROR;
}if ((pInBuffer == NULL) || (Size == 0U) || (hhash->Init.pKey == NULL) || (hhash->Init.KeySize == 0U) || (pOutBuffer == NULL)) { ... }
__HAL_LOCK(hhash);
hhash->State = HAL_HASH_STATE_BUSY;
hhash->HashITCounter = 1;
if (hhash->Phase == HAL_HASH_PHASE_READY)
{
if (hhash->Init.KeySize > 64U)
{
MODIFY_REG(HASH->CR, HASH_CR_LKEY | HASH_CR_ALGO | HASH_CR_MODE | HASH_CR_INIT,
Algorithm | HASH_ALGOMODE_HMAC | HASH_HMAC_KEYTYPE_LONGKEY | HASH_CR_INIT);
}if (hhash->Init.KeySize > 64U) { ... }
else
{
MODIFY_REG(HASH->CR, HASH_CR_LKEY | HASH_CR_ALGO | HASH_CR_MODE | HASH_CR_INIT,
Algorithm | HASH_ALGOMODE_HMAC | HASH_CR_INIT);
}else { ... }
/* ... */
hhash->HashInCount = hhash->Init.KeySize;
hhash->pHashInBuffPtr = hhash->Init.pKey ;
/* ... */
hhash->pHashKeyBuffPtr = hhash->Init.pKey;
hhash->pHashMsgBuffPtr = pInBuffer;
hhash->HashBuffSize = Size;
hhash->pHashOutBuffPtr = pOutBuffer;
__HAL_HASH_SET_NBVALIDBITS(hhash->Init.KeySize);
hhash->Phase = HAL_HASH_PHASE_HMAC_STEP_1;
}if (hhash->Phase == HAL_HASH_PHASE_READY) { ... }
else if ((hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_1) || (hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_3))
{
}else if ((hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_1) || (hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_3)) { ... }
else if (hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_2)
{
}else if (hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_2) { ... }
else
{
__HAL_UNLOCK(hhash);
hhash->State = HAL_HASH_STATE_READY;
return HAL_ERROR;
}else { ... }
__HAL_UNLOCK(hhash);
__HAL_HASH_ENABLE_IT(HASH_IT_DINI | HASH_IT_DCI);
return HAL_OK;
}if ((State_tmp == HAL_HASH_STATE_READY) || (State_tmp == HAL_HASH_STATE_SUSPENDED)) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HMAC_Start_DMA(HASH_HandleTypeDef *hhash, uint8_t *pInBuffer, uint32_t Size, uint32_t Algorithm)
{
uint32_t inputaddr;
uint32_t inputSize;
HAL_StatusTypeDef status ;
HAL_HASH_StateTypeDef State_tmp = hhash->State;
/* ... */
assert_param(IS_HMAC_DMA_MULTIBUFFER_SIZE(hhash, Size));
if ((State_tmp == HAL_HASH_STATE_READY) || (State_tmp == HAL_HASH_STATE_SUSPENDED))
{
if ((pInBuffer == NULL) || (Size == 0U) || (hhash->Init.pKey == NULL) || (hhash->Init.KeySize == 0U) ||
/* ... */
((hhash->Phase != HAL_HASH_PHASE_READY) && (!(IS_HMAC_PROCESSING(hhash)))))
{
hhash->State = HAL_HASH_STATE_READY;
return HAL_ERROR;
}if ((pInBuffer == NULL) || (Size == 0U) || (hhash->Init.pKey == NULL) || (hhash->Init.KeySize == 0U) || /* Check phase coherency. Phase must be either READY (fresh start) or one of HMAC PROCESS steps (multi-buffer HASH management) */ ((hhash->Phase != HAL_HASH_PHASE_READY) && (!(IS_HMAC_PROCESSING(hhash))))) { ... }
__HAL_LOCK(hhash);
if (hhash->State == HAL_HASH_STATE_READY)
{
if (hhash->Phase == HAL_HASH_PHASE_READY)
{
hhash->State = HAL_HASH_STATE_BUSY;
#if defined(HASH_CR_MDMAT)
/* ... */
if (hhash->Init.KeySize > 64U)
{
MODIFY_REG(HASH->CR, HASH_CR_MDMAT | HASH_CR_LKEY | HASH_CR_ALGO | HASH_CR_MODE | HASH_CR_INIT,
Algorithm | HASH_ALGOMODE_HMAC | HASH_HMAC_KEYTYPE_LONGKEY | HASH_CR_INIT);
}if (hhash->Init.KeySize > 64U) { ... }
else
{
MODIFY_REG(HASH->CR, HASH_CR_MDMAT | HASH_CR_LKEY | HASH_CR_ALGO | HASH_CR_MODE | HASH_CR_INIT,
Algorithm | HASH_ALGOMODE_HMAC | HASH_CR_INIT);
}else { ... }
/* ... */#else
if (hhash->Init.KeySize > 64U)
{
MODIFY_REG(HASH->CR, HASH_CR_LKEY | HASH_CR_ALGO | HASH_CR_MODE | HASH_CR_INIT,
Algorithm | HASH_ALGOMODE_HMAC | HASH_HMAC_KEYTYPE_LONGKEY | HASH_CR_INIT);
}if (hhash->Init.KeySize > 64U) { ... }
else
{
MODIFY_REG(HASH->CR, HASH_CR_LKEY | HASH_CR_ALGO | HASH_CR_MODE | HASH_CR_INIT,
Algorithm | HASH_ALGOMODE_HMAC | HASH_CR_INIT);
}else { ... }
/* ... */#endif
/* ... */
hhash->HashInCount = hhash->Init.KeySize;
hhash->pHashKeyBuffPtr = hhash->Init.pKey;
hhash->pHashInBuffPtr = hhash->Init.pKey ;
hhash->pHashMsgBuffPtr = pInBuffer;
hhash->HashBuffSize = Size;
inputaddr = (uint32_t)(hhash->Init.pKey);
inputSize = hhash->Init.KeySize;
__HAL_HASH_SET_NBVALIDBITS(hhash->Init.KeySize);
hhash->Phase = HAL_HASH_PHASE_HMAC_STEP_1;
}if (hhash->Phase == HAL_HASH_PHASE_READY) { ... }
else if (hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_2)
{
/* ... */
hhash->State = HAL_HASH_STATE_BUSY;
hhash->HashInCount = Size;
hhash->pHashInBuffPtr = pInBuffer;
inputaddr = (uint32_t)pInBuffer;
inputSize = Size;
if (hhash->DigestCalculationDisable == RESET)
{
#if defined(HASH_CR_MDMAT)
__HAL_HASH_RESET_MDMAT();
#endif
__HAL_HASH_SET_NBVALIDBITS(inputSize);
}if (hhash->DigestCalculationDisable == RESET) { ... }
}else if (hhash->Phase == HAL_HASH_PHASE_HMAC_STEP_2) { ... }
else
{
__HAL_UNLOCK(hhash);
return HAL_ERROR;
}else { ... }
}if (hhash->State == HAL_HASH_STATE_READY) { ... }
else
{
hhash->State = HAL_HASH_STATE_BUSY;
/* ... */
inputaddr = (uint32_t)(hhash->pHashInBuffPtr);
inputSize = hhash->HashInCount;
}else { ... }
hhash->hdmain->XferCpltCallback = HASH_DMAXferCplt;
hhash->hdmain->XferErrorCallback = HASH_DMAError;
hhash->NbWordsAlreadyPushed = HASH_NBW_PUSHED();
status = HAL_DMA_Start_IT(hhash->hdmain, inputaddr, (uint32_t)&HASH->DIN, \
(((inputSize % 4U) != 0U) ? ((inputSize + (4U - (inputSize % 4U))) / 4U) \
: (inputSize / 4U)));
SET_BIT(HASH->CR, HASH_CR_DMAE);
__HAL_UNLOCK(hhash);
if (status != HAL_OK)
{
hhash->State = HAL_HASH_STATE_ERROR;
}if (status != HAL_OK) { ... }
return status;
}if ((State_tmp == HAL_HASH_STATE_READY) || (State_tmp == HAL_HASH_STATE_SUSPENDED)) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
/* ... */
#endif
/* ... */
/* ... */#endif
/* ... */