1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** NetX Crypto Component */
17 /** */
18 /** Crypto Self Test */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23 #define NX_CRYPTO_SOURCE_CODE
24
25
26 /* Include necessary system files. */
27 #include "nx_crypto_method_self_test.h"
28 #include "nx_crypto_drbg.h"
29 #include "nx_crypto_aes.h"
30
31 #ifdef NX_CRYPTO_SELF_TEST
32
33 /*
34 [AES-128 use df]
35 [PredictionResistance = True]
36 [EntropyInputLen = 128]
37 [NonceLen = 64]
38 [PersonalizationStringLen = 128]
39 [AdditionalInputLen = 128]
40 [ReturnedBitsLen = 512]
41
42 COUNT = 0
43 EntropyInput = c87bcfa53ded926698bb792254eba853
44 Nonce = 1165ebdb6fe78232
45 PersonalizationString = 7ee8c40ebd3551fe103c8349377ea7cc
46 AdditionalInput = db2422dba1157857785ce57b43bc938e
47 EntropyInputPR = da60722bd8d6d4313d47ce07c4f63c29
48 AdditionalInput = 06b93f6b069e4859a8c76247a4825a64
49 EntropyInputPR = 933623ef7527bc0449ca8d629d84a91f
50 ReturnedBits = fd76ace1287a800d01a969fc99d6db8b3f309f6cf5b2b07eec12e3f0169cbbcdebf9a1485a57ed0f5ecc14de122c5eee9c39f48ee8e98e5bb58141e9dc33121e
51
52 [AES-128 use df]
53 [PredictionResistance = False]
54 [EntropyInputLen = 128]
55 [NonceLen = 64]
56 [PersonalizationStringLen = 128]
57 [AdditionalInputLen = 128]
58 [ReturnedBitsLen = 512]
59
60 COUNT = 0
61 EntropyInput = 63f226b4a964681df99ac1965cecac3a
62 Nonce = d888574290239f93
63 PersonalizationString = d0ef2ed4a740a78ee06b461758a67912
64 EntropyInputReseed = 5d093a54a1201f46ab562e8abf77fa8f
65 AdditionalInputReseed = 39232ea4871483ae596a8fa56fec03d6
66 AdditionalInput = b8f5e41effe52e62f2a258c9e29ad5b3
67 AdditionalInput = bb8fd9404da2c601b0209e0f4b1a5094
68 ReturnedBits = 22e3066c23bbaae85b118dffc21c3572dcbede7a7c7a7c73bcdee8a060500ef67af6c13cee6f4da309f8b3e3fa8dc4c37f94d99b591a1cede6aec30b200c81f7
69 */
70
71 static UCHAR entropy_input_aes128[] = {
72 0xc8, 0x7b, 0xcf, 0xa5, 0x3d, 0xed, 0x92, 0x66, 0x98, 0xbb, 0x79, 0x22, 0x54, 0xeb, 0xa8, 0x53
73 };
74 static UINT entropy_input_len_aes128 = 16;
75 static UCHAR nonce_aes128[] = {
76 0x11, 0x65, 0xeb, 0xdb, 0x6f, 0xe7, 0x82, 0x32 };
77 static UCHAR personalization_string_aes128[] = {
78 0x7e, 0xe8, 0xc4, 0x0e, 0xbd, 0x35, 0x51, 0xfe, 0x10, 0x3c, 0x83, 0x49, 0x37, 0x7e, 0xa7, 0xcc
79 };
80 static UCHAR additional_input_0_aes128[] = {
81 0xdb, 0x24, 0x22, 0xdb, 0xa1, 0x15, 0x78, 0x57, 0x78, 0x5c, 0xe5, 0x7b, 0x43, 0xbc, 0x93, 0x8e
82 };
83 static UCHAR entropy_input_pr_0_aes128[] = {
84 0xda, 0x60, 0x72, 0x2b, 0xd8, 0xd6, 0xd4, 0x31, 0x3d, 0x47, 0xce, 0x07, 0xc4, 0xf6, 0x3c, 0x29
85 };
86 static UCHAR additional_input_1_aes128[] = {
87 0x06, 0xb9, 0x3f, 0x6b, 0x06, 0x9e, 0x48, 0x59, 0xa8, 0xc7, 0x62, 0x47, 0xa4, 0x82, 0x5a, 0x64
88 };
89 static UCHAR entropy_input_pr_1_aes128[] = {
90 0x93, 0x36, 0x23, 0xef, 0x75, 0x27, 0xbc, 0x04, 0x49, 0xca, 0x8d, 0x62, 0x9d, 0x84, 0xa9, 0x1f
91 };
92 static UCHAR returned_bits_aes128[] = {
93 0xfd, 0x76, 0xac, 0xe1, 0x28, 0x7a, 0x80, 0x0d, 0x01, 0xa9, 0x69, 0xfc, 0x99, 0xd6, 0xdb, 0x8b,
94 0x3f, 0x30, 0x9f, 0x6c, 0xf5, 0xb2, 0xb0, 0x7e, 0xec, 0x12, 0xe3, 0xf0, 0x16, 0x9c, 0xbb, 0xcd,
95 0xeb, 0xf9, 0xa1, 0x48, 0x5a, 0x57, 0xed, 0x0f, 0x5e, 0xcc, 0x14, 0xde, 0x12, 0x2c, 0x5e, 0xee,
96 0x9c, 0x39, 0xf4, 0x8e, 0xe8, 0xe9, 0x8e, 0x5b, 0xb5, 0x81, 0x41, 0xe9, 0xdc, 0x33, 0x12, 0x1e
97 };
98
99 static UCHAR entropy_input_npr_aes128[] = {
100 0x63, 0xf2, 0x26, 0xb4, 0xa9, 0x64, 0x68, 0x1d, 0xf9, 0x9a, 0xc1, 0x96, 0x5c, 0xec, 0xac, 0x3a
101 };
102 static UINT entropy_input_len_npr_aes128 = 16;
103 static UCHAR nonce_npr_aes128[] = {
104 0xd8, 0x88, 0x57, 0x42, 0x90, 0x23, 0x9f, 0x93
105 };
106 static UCHAR personalization_string_npr_aes128[] = {
107 0xd0, 0xef, 0x2e, 0xd4, 0xa7, 0x40, 0xa7, 0x8e, 0xe0, 0x6b, 0x46, 0x17, 0x58, 0xa6, 0x79, 0x12
108 };
109 static UCHAR entropy_input_reseed_npr_aes128[] = {
110 0x5d, 0x09, 0x3a, 0x54, 0xa1, 0x20, 0x1f, 0x46, 0xab, 0x56, 0x2e, 0x8a, 0xbf, 0x77, 0xfa, 0x8f
111 };
112 static UCHAR additional_input_reseed_npr_aes128[] = {
113 0x39, 0x23, 0x2e, 0xa4, 0x87, 0x14, 0x83, 0xae, 0x59, 0x6a, 0x8f, 0xa5, 0x6f, 0xec, 0x03, 0xd6
114 };
115 static UCHAR additional_input_0_npr_aes128[] = {
116 0xb8, 0xf5, 0xe4, 0x1e, 0xff, 0xe5, 0x2e, 0x62, 0xf2, 0xa2, 0x58, 0xc9, 0xe2, 0x9a, 0xd5, 0xb3
117 };
118 static UCHAR additional_input_1_npr_aes128[] = {
119 0xbb, 0x8f, 0xd9, 0x40, 0x4d, 0xa2, 0xc6, 0x01, 0xb0, 0x20, 0x9e, 0x0f, 0x4b, 0x1a, 0x50, 0x94
120 };
121 static UCHAR returned_bits_npr_aes128[] = {
122 0x22, 0xe3, 0x06, 0x6c, 0x23, 0xbb, 0xaa, 0xe8, 0x5b, 0x11, 0x8d, 0xff, 0xc2, 0x1c, 0x35, 0x72,
123 0xdc, 0xbe, 0xde, 0x7a, 0x7c, 0x7a, 0x7c, 0x73, 0xbc, 0xde, 0xe8, 0xa0, 0x60, 0x50, 0x0e, 0xf6,
124 0x7a, 0xf6, 0xc1, 0x3c, 0xee, 0x6f, 0x4d, 0xa3, 0x09, 0xf8, 0xb3, 0xe3, 0xfa, 0x8d, 0xc4, 0xc3,
125 0x7f, 0x94, 0xd9, 0x9b, 0x59, 0x1a, 0x1c, 0xed, 0xe6, 0xae, 0xc3, 0x0b, 0x20, 0x0c, 0x81, 0xf7
126 };
127
128 /* Output. */
129 static UCHAR output[64];
130 static NX_CRYPTO_AES aes_metadata;
131
132 /* Global variable. */
133 static UCHAR drbg_test_entropy_count_pr;
134 static UCHAR drbg_test_entropy_count_npr;
135
136 /**************************************************************************/
137 /* */
138 /* FUNCTION RELEASE */
139 /* */
140 /* drbg_test_get_entropy_pr PORTABLE C */
141 /* 6.1.7 */
142 /* AUTHOR */
143 /* */
144 /* Timothy Stapko, Microsoft Corporation */
145 /* */
146 /* DESCRIPTION */
147 /* */
148 /* This function serves an entrpoy source for the DRBG module, for the */
149 /* purpose of the self test. */
150 /* */
151 /* INPUT */
152 /* */
153 /* entropy Pointer to the buffer for */
154 /* the value to be returned */
155 /* entropy_len Number of valid bytes written */
156 /* entrypy_max_len Size of the input buffer */
157 /* */
158 /* OUTPUT */
159 /* */
160 /* status Completion status */
161 /* */
162 /* CALLS */
163 /* */
164 /* NX_CRYPTO_MEMCPY */
165 /* */
166 /* CALLED BY */
167 /* */
168 /* DRBG internal logic */
169 /* */
170 /* RELEASE HISTORY */
171 /* */
172 /* DATE NAME DESCRIPTION */
173 /* */
174 /* 05-19-2020 Timothy Stapko Initial Version 6.0 */
175 /* 09-30-2020 Timothy Stapko Modified comment(s), */
176 /* verified memcpy use cases, */
177 /* resulting in version 6.1 */
178 /* 06-02-2021 Bhupendra Naphade Modified comment(s), */
179 /* renamed FIPS symbol to */
180 /* self-test, */
181 /* resulting in version 6.1.7 */
182 /* */
183 /**************************************************************************/
drbg_test_get_entropy_pr(UCHAR * entropy,UINT * entropy_len,UINT entropy_max_len)184 NX_CRYPTO_KEEP static UINT drbg_test_get_entropy_pr(UCHAR *entropy, UINT *entropy_len, UINT entropy_max_len)
185 {
186 if (entropy_input_len_aes128 < *entropy_len)
187 {
188 return(NX_CRYPTO_SIZE_ERROR);
189 }
190
191 if (entropy_input_len_aes128 > entropy_max_len)
192 {
193 return(NX_CRYPTO_SIZE_ERROR);
194 }
195
196 if (drbg_test_entropy_count_pr == 0)
197 {
198 NX_CRYPTO_MEMCPY(entropy, entropy_input_aes128, entropy_input_len_aes128); /* Use case of memcpy is verified. */
199 *entropy_len = entropy_input_len_aes128;
200 }
201 else if (drbg_test_entropy_count_pr == 1)
202 {
203 NX_CRYPTO_MEMCPY(entropy, entropy_input_pr_0_aes128, entropy_input_len_aes128); /* Use case of memcpy is verified. */
204 *entropy_len = entropy_input_len_aes128;
205 }
206 else if (drbg_test_entropy_count_pr == 2)
207 {
208 NX_CRYPTO_MEMCPY(entropy, entropy_input_pr_1_aes128, entropy_input_len_aes128); /* Use case of memcpy is verified. */
209 *entropy_len = entropy_input_len_aes128;
210 }
211 else
212 {
213 return(1);
214 }
215
216 drbg_test_entropy_count_pr++;
217
218 return(NX_CRYPTO_SUCCESS);
219 }
220
221 /**************************************************************************/
222 /* */
223 /* FUNCTION RELEASE */
224 /* */
225 /* drbg_test_get_entropy_npr PORTABLE C */
226 /* 6.1 */
227 /* AUTHOR */
228 /* */
229 /* Timothy Stapko, Microsoft Corporation */
230 /* */
231 /* DESCRIPTION */
232 /* */
233 /* This function serves an entrpoy source for the DRBG module, for the */
234 /* purpose of the self test. */
235 /* */
236 /* INPUT */
237 /* */
238 /* entropy Pointer to the buffer for */
239 /* the value to be returned */
240 /* entropy_len Number of valid bytes written */
241 /* entrypy_max_len Size of the input buffer */
242 /* */
243 /* OUTPUT */
244 /* */
245 /* status Completion status */
246 /* */
247 /* CALLS */
248 /* */
249 /* NX_CRYPTO_MEMCPY */
250 /* */
251 /* CALLED BY */
252 /* */
253 /* DRBG internal logic */
254 /* */
255 /* RELEASE HISTORY */
256 /* */
257 /* DATE NAME DESCRIPTION */
258 /* */
259 /* 05-19-2020 Timothy Stapko Initial Version 6.0 */
260 /* 09-30-2020 Timothy Stapko Modified comment(s), */
261 /* verified memcpy use cases, */
262 /* resulting in version 6.1 */
263 /* */
264 /**************************************************************************/
drbg_test_get_entropy_npr(UCHAR * entropy,UINT * entropy_len,UINT entropy_max_len)265 NX_CRYPTO_KEEP static UINT drbg_test_get_entropy_npr(UCHAR *entropy, UINT *entropy_len, UINT entropy_max_len)
266 {
267 if (entropy_input_len_npr_aes128 < *entropy_len)
268 {
269 return(NX_CRYPTO_SIZE_ERROR);
270 }
271
272 if (entropy_input_len_npr_aes128 > entropy_max_len)
273 {
274 return(NX_CRYPTO_SIZE_ERROR);
275 }
276
277 if (drbg_test_entropy_count_npr == 0)
278 {
279 NX_CRYPTO_MEMCPY(entropy, entropy_input_npr_aes128, entropy_input_len_npr_aes128); /* Use case of memcpy is verified. */
280 *entropy_len = entropy_input_len_npr_aes128;
281 }
282 else if (drbg_test_entropy_count_npr == 1)
283 {
284 NX_CRYPTO_MEMCPY(entropy, entropy_input_reseed_npr_aes128, entropy_input_len_npr_aes128); /* Use case of memcpy is verified. */
285 *entropy_len = entropy_input_len_npr_aes128;
286 }
287 else
288 {
289 return(NX_CRYPTO_NOT_SUCCESSFUL);
290 }
291
292 drbg_test_entropy_count_npr++;
293
294 return(NX_CRYPTO_SUCCESS);
295 }
296
297 /**************************************************************************/
298 /* */
299 /* FUNCTION RELEASE */
300 /* */
301 /* nx_crypto_method_self_test_drbg PORTABLE C */
302 /* 6.1 */
303 /* AUTHOR */
304 /* */
305 /* Timothy Stapko, Microsoft Corporation */
306 /* */
307 /* DESCRIPTION */
308 /* */
309 /* This function performs the Known Answer Test for DRBG crypto method.*/
310 /* */
311 /* INPUT */
312 /* */
313 /* method_ptr Pointer to the crypto method */
314 /* to be tested. */
315 /* metadata Metadata area required by */
316 /* the DRBG module */
317 /* metadata_size Size of the metadata area */
318 /* */
319 /* OUTPUT */
320 /* */
321 /* status Completion status */
322 /* */
323 /* CALLS */
324 /* */
325 /* NX_CRYPTO_MEMCPY */
326 /* NX_CRYPTO_MEMCMP */
327 /* */
328 /* */
329 /* CALLED BY */
330 /* */
331 /* Application Code */
332 /* */
333 /* RELEASE HISTORY */
334 /* */
335 /* DATE NAME DESCRIPTION */
336 /* */
337 /* 05-19-2020 Timothy Stapko Initial Version 6.0 */
338 /* 09-30-2020 Timothy Stapko Modified comment(s), */
339 /* resulting in version 6.1 */
340 /* */
341 /**************************************************************************/
_nx_crypto_method_self_test_drbg(NX_CRYPTO_METHOD * crypto_method_drbg,VOID * metadata,UINT metadata_size)342 NX_CRYPTO_KEEP UINT _nx_crypto_method_self_test_drbg(NX_CRYPTO_METHOD *crypto_method_drbg,
343 VOID *metadata, UINT metadata_size)
344 {
345 NX_CRYPTO_DRBG_OPTIONS drbg_opt;
346 UCHAR *personalization_string;
347 UINT personalization_string_len;
348 UCHAR *additional_input[2];
349 UINT additional_input_len;
350 UCHAR *nonce;
351 UINT nonce_len;
352 UCHAR *returned_bits;
353 UINT returned_bits_len;
354 UINT status;
355 VOID *handler = NX_CRYPTO_NULL;
356
357
358 /* Validate the crypto method */
359 if(crypto_method_drbg == NX_CRYPTO_NULL)
360 return(NX_CRYPTO_PTR_ERROR);
361
362 /* Set the test data. */
363 drbg_opt.crypto_method = &crypto_method_aes_cbc_128;
364 drbg_opt.crypto_metadata = (UCHAR *)&aes_metadata;
365 drbg_opt.entropy_input = drbg_test_get_entropy_pr;
366 drbg_opt.use_df = 1;
367 drbg_opt.prediction_resistance = 1;
368 drbg_opt.security_strength = entropy_input_len_aes128;
369
370 personalization_string = personalization_string_aes128;
371 personalization_string_len = sizeof(personalization_string_aes128);
372 nonce = nonce_aes128;
373 nonce_len = sizeof(nonce_aes128);
374 additional_input[0] = additional_input_0_aes128;
375 additional_input[1] = additional_input_1_aes128;
376 additional_input_len = sizeof(additional_input_0_aes128);
377 returned_bits = returned_bits_aes128;
378 returned_bits_len = sizeof(returned_bits_aes128);
379
380 /* Clear the output buffer. */
381 NX_CRYPTO_MEMSET(output, 0, sizeof(output));
382 drbg_test_entropy_count_pr = 0;
383
384 /* Call the crypto initialization function. */
385 if (crypto_method_drbg -> nx_crypto_init)
386 {
387 status = crypto_method_drbg -> nx_crypto_init(crypto_method_drbg,
388 NX_CRYPTO_NULL,
389 0,
390 &handler,
391 metadata,
392 metadata_size);
393
394 /* Check the status. */
395 if(status != NX_CRYPTO_SUCCESS)
396 {
397 return(status);
398 }
399 }
400
401 if (crypto_method_drbg -> nx_crypto_operation == NX_CRYPTO_NULL)
402 {
403 return(NX_CRYPTO_PTR_ERROR);
404 }
405
406 /* Call the crypto operation function. */
407 status = crypto_method_drbg -> nx_crypto_operation(NX_CRYPTO_DRBG_OPTIONS_SET,
408 handler,
409 crypto_method_drbg,
410 NX_CRYPTO_NULL,
411 0,
412 (UCHAR *)&drbg_opt,
413 sizeof(drbg_opt),
414 NX_CRYPTO_NULL,
415 NX_CRYPTO_NULL,
416 0,
417 metadata,
418 metadata_size,
419 NX_CRYPTO_NULL, NX_CRYPTO_NULL);
420
421 /* Check the status. */
422 if(status != NX_CRYPTO_SUCCESS)
423 {
424 return(status);
425 }
426
427 /* Call the crypto operation function. */
428 status = crypto_method_drbg -> nx_crypto_operation(NX_CRYPTO_DRBG_INSTANTIATE,
429 handler,
430 crypto_method_drbg,
431 nonce,
432 nonce_len << 3,
433 personalization_string,
434 personalization_string_len,
435 NX_CRYPTO_NULL,
436 NX_CRYPTO_NULL,
437 0,
438 metadata,
439 metadata_size,
440 NX_CRYPTO_NULL, NX_CRYPTO_NULL);
441
442 /* Check the status. */
443 if(status != NX_CRYPTO_SUCCESS)
444 {
445 return(status);
446 }
447
448 /* Call the crypto operation function. */
449 status = crypto_method_drbg -> nx_crypto_operation(NX_CRYPTO_DRBG_GENERATE,
450 handler,
451 crypto_method_drbg,
452 NX_CRYPTO_NULL,
453 0,
454 additional_input[0],
455 additional_input_len,
456 NX_CRYPTO_NULL,
457 output,
458 returned_bits_len,
459 metadata,
460 metadata_size,
461 NX_CRYPTO_NULL, NX_CRYPTO_NULL);
462
463 /* Check the status. */
464 if(status != NX_CRYPTO_SUCCESS)
465 {
466 return(status);
467 }
468
469 /* Call the crypto operation function. */
470 status = crypto_method_drbg -> nx_crypto_operation(NX_CRYPTO_DRBG_GENERATE,
471 handler,
472 crypto_method_drbg,
473 NX_CRYPTO_NULL,
474 0,
475 additional_input[1],
476 additional_input_len,
477 NX_CRYPTO_NULL,
478 output,
479 returned_bits_len,
480 metadata,
481 metadata_size,
482 NX_CRYPTO_NULL, NX_CRYPTO_NULL);
483
484 /* Check the status. */
485 if(status != NX_CRYPTO_SUCCESS)
486 {
487 return(status);
488 }
489
490 /* Validate the output. */
491 if(NX_CRYPTO_MEMCMP(output, returned_bits, returned_bits_len) != 0)
492 {
493 return(NX_CRYPTO_NOT_SUCCESSFUL);
494 }
495
496 if (crypto_method_drbg -> nx_crypto_cleanup)
497 {
498 status = crypto_method_drbg -> nx_crypto_cleanup(metadata);
499 }
500
501 /* Check the status. */
502 if(status != NX_CRYPTO_SUCCESS)
503 {
504 return(status);
505 }
506
507
508 /* Set the test data for reseed. */
509 drbg_opt.crypto_method = &crypto_method_aes_cbc_128;
510 drbg_opt.crypto_metadata = (UCHAR *)&aes_metadata;
511 drbg_opt.entropy_input = drbg_test_get_entropy_npr;
512 drbg_opt.use_df = 1;
513 drbg_opt.prediction_resistance = 0;
514 drbg_opt.security_strength = entropy_input_len_npr_aes128;
515
516 /* Clear the output buffer. */
517 NX_CRYPTO_MEMSET(output, 0, sizeof(output));
518 drbg_test_entropy_count_npr = 0;
519
520 /* Call the crypto initialization function. */
521 if (crypto_method_drbg -> nx_crypto_init)
522 {
523 status = crypto_method_drbg -> nx_crypto_init(crypto_method_drbg,
524 NX_CRYPTO_NULL,
525 0,
526 &handler,
527 metadata,
528 metadata_size);
529
530 /* Check the status. */
531 if(status != NX_CRYPTO_SUCCESS)
532 {
533 return(status);
534 }
535 }
536
537 if (crypto_method_drbg -> nx_crypto_operation == NX_CRYPTO_NULL)
538 {
539 return(NX_CRYPTO_PTR_ERROR);
540 }
541
542 /* Call the crypto operation function. */
543 status = crypto_method_drbg -> nx_crypto_operation(NX_CRYPTO_DRBG_OPTIONS_SET,
544 handler,
545 crypto_method_drbg,
546 NX_CRYPTO_NULL,
547 0,
548 (UCHAR *)&drbg_opt,
549 sizeof(drbg_opt),
550 NX_CRYPTO_NULL,
551 NX_CRYPTO_NULL,
552 0,
553 metadata,
554 metadata_size,
555 NX_CRYPTO_NULL, NX_CRYPTO_NULL);
556
557 /* Check the status. */
558 if(status != NX_CRYPTO_SUCCESS)
559 {
560 return(status);
561 }
562
563 /* Call the crypto operation function. */
564 status = crypto_method_drbg -> nx_crypto_operation(NX_CRYPTO_DRBG_INSTANTIATE,
565 handler,
566 crypto_method_drbg,
567 nonce_npr_aes128,
568 sizeof(nonce_npr_aes128) << 3,
569 personalization_string_npr_aes128,
570 sizeof(personalization_string_npr_aes128),
571 NX_CRYPTO_NULL,
572 NX_CRYPTO_NULL,
573 0,
574 metadata,
575 metadata_size,
576 NX_CRYPTO_NULL, NX_CRYPTO_NULL);
577
578 /* Check the status. */
579 if(status != NX_CRYPTO_SUCCESS)
580 {
581 return(status);
582 }
583
584 /* Call the crypto operation function. */
585 status = crypto_method_drbg -> nx_crypto_operation(NX_CRYPTO_DRBG_RESEED,
586 handler,
587 crypto_method_drbg,
588 NX_CRYPTO_NULL,
589 0,
590 additional_input_reseed_npr_aes128,
591 sizeof(additional_input_reseed_npr_aes128),
592 NX_CRYPTO_NULL,
593 NX_CRYPTO_NULL,
594 0,
595 metadata,
596 metadata_size,
597 NX_CRYPTO_NULL, NX_CRYPTO_NULL);
598
599 /* Check the status. */
600 if(status != NX_CRYPTO_SUCCESS)
601 {
602 return(status);
603 }
604
605 /* Call the crypto operation function. */
606 status = crypto_method_drbg -> nx_crypto_operation(NX_CRYPTO_DRBG_GENERATE,
607 handler,
608 crypto_method_drbg,
609 NX_CRYPTO_NULL,
610 0,
611 additional_input_0_npr_aes128,
612 sizeof(additional_input_0_npr_aes128),
613 NX_CRYPTO_NULL,
614 output,
615 sizeof(returned_bits_npr_aes128),
616 metadata,
617 metadata_size,
618 NX_CRYPTO_NULL, NX_CRYPTO_NULL);
619
620 /* Check the status. */
621 if(status != NX_CRYPTO_SUCCESS)
622 {
623 return(status);
624 }
625
626 /* Call the crypto operation function. */
627 status = crypto_method_drbg -> nx_crypto_operation(NX_CRYPTO_DRBG_GENERATE,
628 handler,
629 crypto_method_drbg,
630 NX_CRYPTO_NULL,
631 0,
632 additional_input_1_npr_aes128,
633 sizeof(additional_input_1_npr_aes128),
634 NX_CRYPTO_NULL,
635 output,
636 sizeof(returned_bits_npr_aes128),
637 metadata,
638 metadata_size,
639 NX_CRYPTO_NULL, NX_CRYPTO_NULL);
640
641 /* Check the status. */
642 if(status != NX_CRYPTO_SUCCESS)
643 {
644 return(status);
645 }
646
647 /* Validate the output. */
648 if(NX_CRYPTO_MEMCMP(output, returned_bits_npr_aes128, sizeof(returned_bits_npr_aes128)) != 0)
649 {
650 return(NX_CRYPTO_NOT_SUCCESSFUL);
651 }
652
653 if (crypto_method_drbg -> nx_crypto_cleanup)
654 {
655 status = crypto_method_drbg -> nx_crypto_cleanup(metadata);
656 }
657
658 return(status);
659 }
660 #endif
661