Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
#define NX_CRYPTO_SOURCE_CODE
#include "nx_crypto.h"
#include "nx_crypto_hmac_sha2.h"
#define REG32
#define STM32F4_RCC
#define STM32F4_RCC_AHB2ENR
#define STM32F4_RCC_AHB2ENR_RNGEN
#define STM32L4_RCC
#define STM32L4_RCC_AHB2ENR
#define STM32L4_RCC_AHB2ENR_RNGEN
#define STM32_RNG
#define STM32_RNG_CR
#define STM32_RNG_SR
#define STM32_RNG_DR
#define STM32_RNG_CR_RNGEN
#define STM32_RNG_CR_IE
#define STM32_RNG_CR_CED
#define STM32_RNG_SR_DRDY
#define STM32_RNG_SR_CECS
#define STM32_RNG_SR_SECS
#define STM32_RNG_SR_CEIS
#define STM32_RNG_SR_SEIS
#define DBGMCU_IDCODE
#define DBGMCU_IDCODE_DEV_ID_MASK
#define DEV_ID_L47x
...
...
...
...
...
...
...
...
Files
loading...
SourceVuSTM32 Libraries and Samplesnetxduocrypto_libraries/src/nx_crypto_module_start.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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ ... /**************************************************************************/ /**************************************************************************/ /** */ /** NetX Crypto Component */ /** */ /** Crypto Module Initialization, startup, and helper routines */ /** */... /**************************************************************************/ /**************************************************************************/ /* NOTE: This file is used for FIPS certification on STM32F469 only. */ #define NX_CRYPTO_SOURCE_CODE #include "nx_crypto.h" #include "nx_crypto_hmac_sha2.h" #if defined(NX_CRYPTO_SELF_TEST) && defined(STM32F469xx) #define NX_CRYPTO_INTEGRITY_TEST_CHECK(status) \ if(status) \ { \ _nx_crypto_library_state |= NX_CRYPTO_LIBRARY_STATE_POST_FAILED; \ ...}... #define REG32(x) (*(volatile unsigned int *)(x)) /* Define RCC register. */ #define STM32F4_RCC 0x40023800 #define STM32F4_RCC_AHB2ENR REG32(STM32F4_RCC + 0x34) #define STM32F4_RCC_AHB2ENR_RNGEN 0x00000040 #define STM32L4_RCC 0x40021000 #define STM32L4_RCC_AHB2ENR REG32(STM32L4_RCC + 0x4C) #define STM32L4_RCC_AHB2ENR_RNGEN 0x00040000 /* Define RNG registers. */ #define STM32_RNG 0x50060800 #define STM32_RNG_CR REG32(STM32_RNG + 0x00) #define STM32_RNG_SR REG32(STM32_RNG + 0x04) #define STM32_RNG_DR REG32(STM32_RNG + 0x08) #define STM32_RNG_CR_RNGEN 0x00000004 #define STM32_RNG_CR_IE 0x00000008 #define STM32_RNG_CR_CED 0x00000020 #define STM32_RNG_SR_DRDY 0x00000001 #define STM32_RNG_SR_CECS 0x00000002 #define STM32_RNG_SR_SECS 0x00000004 #define STM32_RNG_SR_CEIS 0x00000020 #define STM32_RNG_SR_SEIS 0x00000040 #define DBGMCU_IDCODE REG32(0xE0042000) #define DBGMCU_IDCODE_DEV_ID_MASK 0x00000FFF #define DEV_ID_L47x 0x415 23 defines const unsigned long long _nx_crypto_module_program_begin @ "NX_CRYPTO_PROGRAM_BEGIN" = 0ull; const unsigned char _nx_crypto_module_hash_value[32] @ "NX_CRYPTO_PROGRAM_END" = { #if (__VER__ == 8030002) /* IAR 8.30.2 */ 0xe0, 0xa6, 0xf3, 0x19, 0x9f, 0x43, 0x02, 0x4f, 0xe6, 0x69, 0xfb, 0xd3, 0x4c, 0x1b, 0xdd, 0xee, 0x90, 0x3c, 0xff, 0xba, 0x16, 0x56, 0x51, 0x78, 0x57, 0xe6, 0x47, 0xc2, 0xca, 0x83, 0xff, 0xc9/* ... */ #else /* IAR 8.22.2 */ 0xe8, 0xd9, 0xe8, 0xac, 0xd3, 0x7c, 0x54, 0x7e, 0xd0, 0x72, 0x96, 0x38, 0xde, 0x45, 0x78, 0xff, 0xe1, 0xe4, 0xb2, 0xfc, 0xfd, 0xa6, 0x11, 0xd7, 0x0c, 0xda, 0xc9, 0xc9, 0xf2, 0x95, 0xd2, 0xa4/* ... */ #endif ...}; extern NX_CRYPTO_METHOD crypto_method_hmac_sha256; extern const CHAR nx_crypto_hash_key[]; extern const UINT nx_crypto_hash_key_size; static UCHAR nx_crypto_hmac_output[64]; static NX_CRYPTO_SHA256_HMAC nx_crypto_self_test_hmac; /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nx_crypto_hardware_rand_initialize PORTABLE C */ /* 6.1.10 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function initializes hardware random number generator. */ /* The following processors are supported: */ /* STM32F407 */ /* STM32F417 */ /* STM32F429 */ /* STM32F439 */ /* STM32F469 */ /* STM32F479 */ /* STM32L475 */ /* STM32L476 */ /* */ /* INPUT */ /* */ /* None */ /* */ /* OUTPUT */ /* */ /* None */ /* */ /* CALLS */ /* */ /* None */ /* */ /* CALLED BY */ /* */ /* _nx_crypto_method_self_test */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ /* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* renamed FIPS symbol to */ /* self-test, */ /* resulting in version 6.1.7 */ /* 01-31-2022 Bhupendra Naphade Modified comment(s), */ /* updated build condition, */ /* resulting in version 6.1.10 */ /* */... /**************************************************************************/ NX_CRYPTO_KEEP void _nx_crypto_hardware_rand_initialize_stm32f4(void) { unsigned int device_id; /* Read device ID. */ device_id = DBGMCU_IDCODE & DBGMCU_IDCODE_DEV_ID_MASK; if (device_id == DEV_ID_L47x) { /* Enable clock for the RNG. */ STM32L4_RCC_AHB2ENR |= STM32L4_RCC_AHB2ENR_RNGEN; }if (device_id == DEV_ID_L47x) { ... } else { /* Enable clock for the RNG. */ STM32F4_RCC_AHB2ENR |= STM32F4_RCC_AHB2ENR_RNGEN; }else { ... } /* Enable the random number generator. */ STM32_RNG_CR = STM32_RNG_CR_RNGEN; }_nx_crypto_hardware_rand_initialize_stm32f4 (void) { ... } NX_CRYPTO_KEEP INT nx_crypto_hardware_rand(VOID) { /* Wait for data ready. */ while((STM32_RNG_SR & STM32_RNG_SR_DRDY) == 0); /* Return the random number. */ return STM32_RNG_DR; }nx_crypto_hardware_rand (VOID) { ... } ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* __aeabi_memcpy PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function performs memory copy function for the FIPS 140-2 */ /* compliance build. */ /* */ /* INPUT */ /* */ /* dest Pointer to the destination */ /* memory */ /* value value (in byte) to set to the */ /* memory location */ /* size Number of bytes to copy */ /* */ /* OUTPUT */ /* */ /* void * Pointer to the destination */ /* memory */ /* */ /* CALLS */ /* */ /* None */ /* */ /* CALLED BY */ /* */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ NX_CRYPTO_KEEP __nounwind __interwork __softfp __aapcs_core void __aeabi_memcpy (void *dest, const void *src, size_t size) { char *from, *to; unsigned int i; from = (char*)src; to = (char*)dest; for(i = 0; i < size; i++) { to[i] = from[i]; }for (i = 0; i < size; i++) { ... } }__aeabi_memcpy (void *dest, const void *src, size_t size) { ... } ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* __aeabi_memcpy4 PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function performs memory copy function for the FIPS 140-2 */ /* compliance build. */ /* */ /* INPUT */ /* */ /* dest Pointer to the destination */ /* memory */ /* value value (in byte) to set to the */ /* memory location */ /* size Number of bytes to copy */ /* */ /* OUTPUT */ /* */ /* void * Pointer to the destination */ /* memory */ /* */ /* CALLS */ /* */ /* None */ /* */ /* CALLED BY */ /* */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ NX_CRYPTO_KEEP __nounwind __interwork __softfp __aapcs_core void __aeabi_memcpy4 (void *dest, const void *src, size_t size) { char *from, *to; unsigned int i; from = (char*)src; to = (char*)dest; for(i = 0; i < size; i++) { to[i] = from[i]; }for (i = 0; i < size; i++) { ... } }__aeabi_memcpy4 (void *dest, const void *src, size_t size) { ... } ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* __aeabi_memcpy8 PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function performs memory copy function for the FIPS 140-2 */ /* compliance build. */ /* */ /* INPUT */ /* */ /* dest Pointer to the destination */ /* memory */ /* value value (in byte) to set to the */ /* memory location */ /* size Number of bytes to copy */ /* */ /* OUTPUT */ /* */ /* void * Pointer to the destination */ /* memory */ /* */ /* CALLS */ /* */ /* None */ /* */ /* CALLED BY */ /* */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ NX_CRYPTO_KEEP __nounwind __interwork __softfp __aapcs_core void __aeabi_memcpy8 (void *dest, const void *src, size_t size) { char *from, *to; unsigned int i; from = (char*)src; to = (char*)dest; for(i = 0; i < size; i++) { to[i] = from[i]; }for (i = 0; i < size; i++) { ... } }__aeabi_memcpy8 (void *dest, const void *src, size_t size) { ... } NX_CRYPTO_KEEP UINT _nx_crypto_integrity_test(void) { UINT status; status = _nx_crypto_method_hmac_sha256_operation(NX_CRYPTO_AUTHENTICATE, /* op */ (VOID*)&nx_crypto_self_test_hmac, &crypto_method_hmac_sha256, /* Method */ (UCHAR*)nx_crypto_hash_key, nx_crypto_hash_key_size, (UCHAR*)&_nx_crypto_module_program_begin, (ULONG)_nx_crypto_module_hash_value - (ULONG)&_nx_crypto_module_program_begin, NX_CRYPTO_NULL, /* iv_ptr, not used */ nx_crypto_hmac_output, sizeof(nx_crypto_hmac_output), &nx_crypto_self_test_hmac, sizeof(nx_crypto_self_test_hmac), NX_CRYPTO_NULL, NX_CRYPTO_NULL); NX_CRYPTO_INTEGRITY_TEST_CHECK(status) status = (UINT)NX_CRYPTO_MEMCMP(nx_crypto_hmac_output, _nx_crypto_module_hash_value, 32); NX_CRYPTO_INTEGRITY_TEST_CHECK(status); return(status); }_nx_crypto_integrity_test (void) { ... } ... /* ... */#endif
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.