1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** NetX Crypto Component                                                 */
16 /**                                                                       */
17 /**   Crypto Self Test                                                    */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define NX_CRYPTO_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 #include "nx_crypto_method_self_test.h"
27 
28 #ifdef NX_CRYPTO_SELF_TEST
29 
30 /* 7c9c67323a1df1adbfe5ceb415eaef0155ece2820f4d50c1ec22cba4928ac656c83fe585db6a78ce40bc42757aba7e5a3f582428d6ca68d0c3978336a6efb729613e8d9979016204bfd921322fdd5222183554447de5e6e9bbe6edf76d7b71e18dc2e8d6dc89b7398364f652fafc734329aafa3dcd45d4f31e388e4fafd7fc6495f37ca5cbab7f54d586463da4bfeaa3bae09f7b8e9239d832b4f0a733aa609cc1f8d4 */
31 static UCHAR plain_1[] = {
32 0x7c, 0x9c, 0x67, 0x32, 0x3a, 0x1d, 0xf1, 0xad, 0xbf, 0xe5, 0xce, 0xb4, 0x15, 0xea, 0xef, 0x01,
33 0x55, 0xec, 0xe2, 0x82, 0x0f, 0x4d, 0x50, 0xc1, 0xec, 0x22, 0xcb, 0xa4, 0x92, 0x8a, 0xc6, 0x56,
34 0xc8, 0x3f, 0xe5, 0x85, 0xdb, 0x6a, 0x78, 0xce, 0x40, 0xbc, 0x42, 0x75, 0x7a, 0xba, 0x7e, 0x5a,
35 0x3f, 0x58, 0x24, 0x28, 0xd6, 0xca, 0x68, 0xd0, 0xc3, 0x97, 0x83, 0x36, 0xa6, 0xef, 0xb7, 0x29,
36 0x61, 0x3e, 0x8d, 0x99, 0x79, 0x01, 0x62, 0x04, 0xbf, 0xd9, 0x21, 0x32, 0x2f, 0xdd, 0x52, 0x22,
37 0x18, 0x35, 0x54, 0x44, 0x7d, 0xe5, 0xe6, 0xe9, 0xbb, 0xe6, 0xed, 0xf7, 0x6d, 0x7b, 0x71, 0xe1,
38 0x8d, 0xc2, 0xe8, 0xd6, 0xdc, 0x89, 0xb7, 0x39, 0x83, 0x64, 0xf6, 0x52, 0xfa, 0xfc, 0x73, 0x43,
39 0x29, 0xaa, 0xfa, 0x3d, 0xcd, 0x45, 0xd4, 0xf3, 0x1e, 0x38, 0x8e, 0x4f, 0xaf, 0xd7, 0xfc, 0x64,
40 0x95, 0xf3, 0x7c, 0xa5, 0xcb, 0xab, 0x7f, 0x54, 0xd5, 0x86, 0x46, 0x3d, 0xa4, 0xbf, 0xea, 0xa3,
41 0xba, 0xe0, 0x9f, 0x7b, 0x8e, 0x92, 0x39, 0xd8, 0x32, 0xb4, 0xf0, 0xa7, 0x33, 0xaa, 0x60, 0x9c,
42 0xc1, 0xf8, 0xd4,
43 };
44 
45 /* d8fd6a91ef3b6ced05b98358a99107c1fac8c807 */
46 static UCHAR secret_1[] = {
47 0xd8, 0xfd, 0x6a, 0x91, 0xef, 0x3b, 0x6c, 0xed, 0x05, 0xb9, 0x83, 0x58, 0xa9, 0x91, 0x07, 0xc1,
48 0xfa, 0xc8, 0xc8, 0x07,
49 };
50 
51 /* 5c86f6cffcb86a96771335dafcd82a730c55ecc68caca5a319d5fa6e9be63e7d1d92e5c2dcf03caa9d7e584444664ca6a300a08d9097fe433a702dc6bd084426f39e172f8df1f648634b979b09be5076a3ae89f1fa9072d2cff0f1ad6fb9df5087b1735e3a43fe397181d92572699cabb567913cf21c69177f5e2d6dd98077c281d3e196096cbe456e28082ca8ee9a0d80349fb4a2c54bdbf3c1c94c24e57445880c49 */
52 static UCHAR plain_224[] = {
53 0x5c, 0x86, 0xf6, 0xcf, 0xfc, 0xb8, 0x6a, 0x96, 0x77, 0x13, 0x35, 0xda, 0xfc, 0xd8, 0x2a, 0x73,
54 0x0c, 0x55, 0xec, 0xc6, 0x8c, 0xac, 0xa5, 0xa3, 0x19, 0xd5, 0xfa, 0x6e, 0x9b, 0xe6, 0x3e, 0x7d,
55 0x1d, 0x92, 0xe5, 0xc2, 0xdc, 0xf0, 0x3c, 0xaa, 0x9d, 0x7e, 0x58, 0x44, 0x44, 0x66, 0x4c, 0xa6,
56 0xa3, 0x00, 0xa0, 0x8d, 0x90, 0x97, 0xfe, 0x43, 0x3a, 0x70, 0x2d, 0xc6, 0xbd, 0x08, 0x44, 0x26,
57 0xf3, 0x9e, 0x17, 0x2f, 0x8d, 0xf1, 0xf6, 0x48, 0x63, 0x4b, 0x97, 0x9b, 0x09, 0xbe, 0x50, 0x76,
58 0xa3, 0xae, 0x89, 0xf1, 0xfa, 0x90, 0x72, 0xd2, 0xcf, 0xf0, 0xf1, 0xad, 0x6f, 0xb9, 0xdf, 0x50,
59 0x87, 0xb1, 0x73, 0x5e, 0x3a, 0x43, 0xfe, 0x39, 0x71, 0x81, 0xd9, 0x25, 0x72, 0x69, 0x9c, 0xab,
60 0xb5, 0x67, 0x91, 0x3c, 0xf2, 0x1c, 0x69, 0x17, 0x7f, 0x5e, 0x2d, 0x6d, 0xd9, 0x80, 0x77, 0xc2,
61 0x81, 0xd3, 0xe1, 0x96, 0x09, 0x6c, 0xbe, 0x45, 0x6e, 0x28, 0x08, 0x2c, 0xa8, 0xee, 0x9a, 0x0d,
62 0x80, 0x34, 0x9f, 0xb4, 0xa2, 0xc5, 0x4b, 0xdb, 0xf3, 0xc1, 0xc9, 0x4c, 0x24, 0xe5, 0x74, 0x45,
63 0x88, 0x0c, 0x49,
64 };
65 
66 /* f5dc44aaa40faca8f32836ed372a16a6e90f61c52a2665cdeea4d50c */
67 static UCHAR secret_224[] = {
68 0xf5, 0xdc, 0x44, 0xaa, 0xa4, 0x0f, 0xac, 0xa8, 0xf3, 0x28, 0x36, 0xed, 0x37, 0x2a, 0x16, 0xa6,
69 0xe9, 0x0f, 0x61, 0xc5, 0x2a, 0x26, 0x65, 0xcd, 0xee, 0xa4, 0xd5, 0x0c,
70 };
71 
72 /* F90D116B1CE425438CE09A7F03E07203BFEC2A4A8FD13D6E649ADA05403FAF754114227A18255F663B57DF0B6D2F004E737A93124FF0D93878C9ED1CB2DB9417311E0F48DC8A25532E958832F489E8273346407B9F12051AC18EC8323F1D766063F045469D686A7DC8120E0C730FBB79BD90FF4F8295ED1803DA0812B69E103B9F79135C8FBAA311BA7E833E5E663E261E8CE17F1E195E449EA5ED1B5FA0037A373EBD2AD9FCCC27CDCF0348AAB8503D29EDA6604599F1645C94E5545A0BB628212417388A296E074E959E50546A5733293C73210F2467039387CD138C2CB967AC8CD1005C9ADB1FFF3B74616A1DD150DE2FC93803167D7320BCE10B7DA9DC14 */
73 static UCHAR plain_256[] = {
74 0xF9, 0x0D, 0x11, 0x6B, 0x1C, 0xE4, 0x25, 0x43, 0x8C, 0xE0, 0x9A, 0x7F, 0x03, 0xE0, 0x72, 0x03,
75 0xBF, 0xEC, 0x2A, 0x4A, 0x8F, 0xD1, 0x3D, 0x6E, 0x64, 0x9A, 0xDA, 0x05, 0x40, 0x3F, 0xAF, 0x75,
76 0x41, 0x14, 0x22, 0x7A, 0x18, 0x25, 0x5F, 0x66, 0x3B, 0x57, 0xDF, 0x0B, 0x6D, 0x2F, 0x00, 0x4E,
77 0x73, 0x7A, 0x93, 0x12, 0x4F, 0xF0, 0xD9, 0x38, 0x78, 0xC9, 0xED, 0x1C, 0xB2, 0xDB, 0x94, 0x17,
78 0x31, 0x1E, 0x0F, 0x48, 0xDC, 0x8A, 0x25, 0x53, 0x2E, 0x95, 0x88, 0x32, 0xF4, 0x89, 0xE8, 0x27,
79 0x33, 0x46, 0x40, 0x7B, 0x9F, 0x12, 0x05, 0x1A, 0xC1, 0x8E, 0xC8, 0x32, 0x3F, 0x1D, 0x76, 0x60,
80 0x63, 0xF0, 0x45, 0x46, 0x9D, 0x68, 0x6A, 0x7D, 0xC8, 0x12, 0x0E, 0x0C, 0x73, 0x0F, 0xBB, 0x79,
81 0xBD, 0x90, 0xFF, 0x4F, 0x82, 0x95, 0xED, 0x18, 0x03, 0xDA, 0x08, 0x12, 0xB6, 0x9E, 0x10, 0x3B,
82 0x9F, 0x79, 0x13, 0x5C, 0x8F, 0xBA, 0xA3, 0x11, 0xBA, 0x7E, 0x83, 0x3E, 0x5E, 0x66, 0x3E, 0x26,
83 0x1E, 0x8C, 0xE1, 0x7F, 0x1E, 0x19, 0x5E, 0x44, 0x9E, 0xA5, 0xED, 0x1B, 0x5F, 0xA0, 0x03, 0x7A,
84 0x37, 0x3E, 0xBD, 0x2A, 0xD9, 0xFC, 0xCC, 0x27, 0xCD, 0xCF, 0x03, 0x48, 0xAA, 0xB8, 0x50, 0x3D,
85 0x29, 0xED, 0xA6, 0x60, 0x45, 0x99, 0xF1, 0x64, 0x5C, 0x94, 0xE5, 0x54, 0x5A, 0x0B, 0xB6, 0x28,
86 0x21, 0x24, 0x17, 0x38, 0x8A, 0x29, 0x6E, 0x07, 0x4E, 0x95, 0x9E, 0x50, 0x54, 0x6A, 0x57, 0x33,
87 0x29, 0x3C, 0x73, 0x21, 0x0F, 0x24, 0x67, 0x03, 0x93, 0x87, 0xCD, 0x13, 0x8C, 0x2C, 0xB9, 0x67,
88 0xAC, 0x8C, 0xD1, 0x00, 0x5C, 0x9A, 0xDB, 0x1F, 0xFF, 0x3B, 0x74, 0x61, 0x6A, 0x1D, 0xD1, 0x50,
89 0xDE, 0x2F, 0xC9, 0x38, 0x03, 0x16, 0x7D, 0x73, 0x20, 0xBC, 0xE1, 0x0B, 0x7D, 0xA9, 0xDC, 0x14,
90 };
91 
92 /* 316A9D20B8596F02FA6DFF4B4BEF48E50EA4096E828424ECE6711D7DE35FEFA1 */
93 static UCHAR secret_256[] = {
94 0x31, 0x6A, 0x9D, 0x20, 0xB8, 0x59, 0x6F, 0x02, 0xFA, 0x6D, 0xFF, 0x4B, 0x4B, 0xEF, 0x48, 0xE5,
95 0x0E, 0xA4, 0x09, 0x6E, 0x82, 0x84, 0x24, 0xEC, 0xE6, 0x71, 0x1D, 0x7D, 0xE3, 0x5F, 0xEF, 0xA1,
96 };
97 
98 /* EDA8CA35AA932D057F0A762965BA7544EC9EA83B8662ED6D63BD7D29761753782C47A370D501151360391F476E176C7B7D8E487DA309BE662E2DAE4665431A2A94A1294F59E09B3CE879606F8ED9D1158F35BE7B04BAB0276710F322ACC9952D76CD103EF4F97C5BF411856E55419C63910E7375C5EA1302BF48E6407EB73D2B6F7E41073E535C6AE371B36F5B1DEA42C5B54958462F3119D2343D3BF1FCEC481B31462C326E5C025F14594499BF8E29D5771A698D41070BFE02A9536A194438E621A347E67C0943F8F2154E75576143EB36BA6A600309712121F7706104CB2854FD854C15337C5FB645670CE50BF941DA1D9061758E4D4D63C3366D4A9CD168 */
99 static UCHAR plain_384[] = {
100 0xED, 0xA8, 0xCA, 0x35, 0xAA, 0x93, 0x2D, 0x05, 0x7F, 0x0A, 0x76, 0x29, 0x65, 0xBA, 0x75, 0x44,
101 0xEC, 0x9E, 0xA8, 0x3B, 0x86, 0x62, 0xED, 0x6D, 0x63, 0xBD, 0x7D, 0x29, 0x76, 0x17, 0x53, 0x78,
102 0x2C, 0x47, 0xA3, 0x70, 0xD5, 0x01, 0x15, 0x13, 0x60, 0x39, 0x1F, 0x47, 0x6E, 0x17, 0x6C, 0x7B,
103 0x7D, 0x8E, 0x48, 0x7D, 0xA3, 0x09, 0xBE, 0x66, 0x2E, 0x2D, 0xAE, 0x46, 0x65, 0x43, 0x1A, 0x2A,
104 0x94, 0xA1, 0x29, 0x4F, 0x59, 0xE0, 0x9B, 0x3C, 0xE8, 0x79, 0x60, 0x6F, 0x8E, 0xD9, 0xD1, 0x15,
105 0x8F, 0x35, 0xBE, 0x7B, 0x04, 0xBA, 0xB0, 0x27, 0x67, 0x10, 0xF3, 0x22, 0xAC, 0xC9, 0x95, 0x2D,
106 0x76, 0xCD, 0x10, 0x3E, 0xF4, 0xF9, 0x7C, 0x5B, 0xF4, 0x11, 0x85, 0x6E, 0x55, 0x41, 0x9C, 0x63,
107 0x91, 0x0E, 0x73, 0x75, 0xC5, 0xEA, 0x13, 0x02, 0xBF, 0x48, 0xE6, 0x40, 0x7E, 0xB7, 0x3D, 0x2B,
108 0x6F, 0x7E, 0x41, 0x07, 0x3E, 0x53, 0x5C, 0x6A, 0xE3, 0x71, 0xB3, 0x6F, 0x5B, 0x1D, 0xEA, 0x42,
109 0xC5, 0xB5, 0x49, 0x58, 0x46, 0x2F, 0x31, 0x19, 0xD2, 0x34, 0x3D, 0x3B, 0xF1, 0xFC, 0xEC, 0x48,
110 0x1B, 0x31, 0x46, 0x2C, 0x32, 0x6E, 0x5C, 0x02, 0x5F, 0x14, 0x59, 0x44, 0x99, 0xBF, 0x8E, 0x29,
111 0xD5, 0x77, 0x1A, 0x69, 0x8D, 0x41, 0x07, 0x0B, 0xFE, 0x02, 0xA9, 0x53, 0x6A, 0x19, 0x44, 0x38,
112 0xE6, 0x21, 0xA3, 0x47, 0xE6, 0x7C, 0x09, 0x43, 0xF8, 0xF2, 0x15, 0x4E, 0x75, 0x57, 0x61, 0x43,
113 0xEB, 0x36, 0xBA, 0x6A, 0x60, 0x03, 0x09, 0x71, 0x21, 0x21, 0xF7, 0x70, 0x61, 0x04, 0xCB, 0x28,
114 0x54, 0xFD, 0x85, 0x4C, 0x15, 0x33, 0x7C, 0x5F, 0xB6, 0x45, 0x67, 0x0C, 0xE5, 0x0B, 0xF9, 0x41,
115 0xDA, 0x1D, 0x90, 0x61, 0x75, 0x8E, 0x4D, 0x4D, 0x63, 0xC3, 0x36, 0x6D, 0x4A, 0x9C, 0xD1, 0x68,
116 };
117 
118 /* 08E3D346F6E3C03D8A15D1EB273EC5EE5AD7201C9CE9325B586486C32BBF3FB9DB7DB416D54C68C2AD3E6694E06CFC45 */
119 static UCHAR secret_384[] = {
120 0x08, 0xE3, 0xD3, 0x46, 0xF6, 0xE3, 0xC0, 0x3D, 0x8A, 0x15, 0xD1, 0xEB, 0x27, 0x3E, 0xC5, 0xEE,
121 0x5A, 0xD7, 0x20, 0x1C, 0x9C, 0xE9, 0x32, 0x5B, 0x58, 0x64, 0x86, 0xC3, 0x2B, 0xBF, 0x3F, 0xB9,
122 0xDB, 0x7D, 0xB4, 0x16, 0xD5, 0x4C, 0x68, 0xC2, 0xAD, 0x3E, 0x66, 0x94, 0xE0, 0x6C, 0xFC, 0x45,
123 };
124 
125 /* A40C7F79AC43604D7A11E57C3859E87976E76E7ADF96E26C99830D20B9F64609606C9415EFDD6F36ECDDB2024CC49312EEF3CF718935562B44C6A30B47DA670492D05F7D466BA517A858A4328FA2C10B875D9C1E9D01416DBB01257DB244A91984BFE51493D5E732220F3D50F47EEE62CC079F4D8EF051331A57C31671141E473B34B2009468A813A96D0641B11B217B74FF8A0042F113616A126804D46B1F1631CF831756F01A072030B3281FC35309E025713264F65634679DBB0D72F6D02FAA61FC4B0FF65F400199923B32BF986AACF7A02DBD9AB738E403420430B7864250709F6B06137F54253675251D783E399503D1073F8D383C8E8C5C00D0378308 */
126 static UCHAR plain_512[] = {
127 0xA4, 0x0C, 0x7F, 0x79, 0xAC, 0x43, 0x60, 0x4D, 0x7A, 0x11, 0xE5, 0x7C, 0x38, 0x59, 0xE8, 0x79,
128 0x76, 0xE7, 0x6E, 0x7A, 0xDF, 0x96, 0xE2, 0x6C, 0x99, 0x83, 0x0D, 0x20, 0xB9, 0xF6, 0x46, 0x09,
129 0x60, 0x6C, 0x94, 0x15, 0xEF, 0xDD, 0x6F, 0x36, 0xEC, 0xDD, 0xB2, 0x02, 0x4C, 0xC4, 0x93, 0x12,
130 0xEE, 0xF3, 0xCF, 0x71, 0x89, 0x35, 0x56, 0x2B, 0x44, 0xC6, 0xA3, 0x0B, 0x47, 0xDA, 0x67, 0x04,
131 0x92, 0xD0, 0x5F, 0x7D, 0x46, 0x6B, 0xA5, 0x17, 0xA8, 0x58, 0xA4, 0x32, 0x8F, 0xA2, 0xC1, 0x0B,
132 0x87, 0x5D, 0x9C, 0x1E, 0x9D, 0x01, 0x41, 0x6D, 0xBB, 0x01, 0x25, 0x7D, 0xB2, 0x44, 0xA9, 0x19,
133 0x84, 0xBF, 0xE5, 0x14, 0x93, 0xD5, 0xE7, 0x32, 0x22, 0x0F, 0x3D, 0x50, 0xF4, 0x7E, 0xEE, 0x62,
134 0xCC, 0x07, 0x9F, 0x4D, 0x8E, 0xF0, 0x51, 0x33, 0x1A, 0x57, 0xC3, 0x16, 0x71, 0x14, 0x1E, 0x47,
135 0x3B, 0x34, 0xB2, 0x00, 0x94, 0x68, 0xA8, 0x13, 0xA9, 0x6D, 0x06, 0x41, 0xB1, 0x1B, 0x21, 0x7B,
136 0x74, 0xFF, 0x8A, 0x00, 0x42, 0xF1, 0x13, 0x61, 0x6A, 0x12, 0x68, 0x04, 0xD4, 0x6B, 0x1F, 0x16,
137 0x31, 0xCF, 0x83, 0x17, 0x56, 0xF0, 0x1A, 0x07, 0x20, 0x30, 0xB3, 0x28, 0x1F, 0xC3, 0x53, 0x09,
138 0xE0, 0x25, 0x71, 0x32, 0x64, 0xF6, 0x56, 0x34, 0x67, 0x9D, 0xBB, 0x0D, 0x72, 0xF6, 0xD0, 0x2F,
139 0xAA, 0x61, 0xFC, 0x4B, 0x0F, 0xF6, 0x5F, 0x40, 0x01, 0x99, 0x92, 0x3B, 0x32, 0xBF, 0x98, 0x6A,
140 0xAC, 0xF7, 0xA0, 0x2D, 0xBD, 0x9A, 0xB7, 0x38, 0xE4, 0x03, 0x42, 0x04, 0x30, 0xB7, 0x86, 0x42,
141 0x50, 0x70, 0x9F, 0x6B, 0x06, 0x13, 0x7F, 0x54, 0x25, 0x36, 0x75, 0x25, 0x1D, 0x78, 0x3E, 0x39,
142 0x95, 0x03, 0xD1, 0x07, 0x3F, 0x8D, 0x38, 0x3C, 0x8E, 0x8C, 0x5C, 0x00, 0xD0, 0x37, 0x83, 0x08,
143 };
144 
145 /* 4A5C6FC817649A45AF89D4FA2D66B7A8EC28CCC44C3946C25B2A21CC7B9FB36EA4E3887199BBDAC58238AB823E4C03491703023C04B110438A3E069F33F2C79C */
146 static UCHAR secret_512[] = {
147 0x4A, 0x5C, 0x6F, 0xC8, 0x17, 0x64, 0x9A, 0x45, 0xAF, 0x89, 0xD4, 0xFA, 0x2D, 0x66, 0xB7, 0xA8,
148 0xEC, 0x28, 0xCC, 0xC4, 0x4C, 0x39, 0x46, 0xC2, 0x5B, 0x2A, 0x21, 0xCC, 0x7B, 0x9F, 0xB3, 0x6E,
149 0xA4, 0xE3, 0x88, 0x71, 0x99, 0xBB, 0xDA, 0xC5, 0x82, 0x38, 0xAB, 0x82, 0x3E, 0x4C, 0x03, 0x49,
150 0x17, 0x03, 0x02, 0x3C, 0x04, 0xB1, 0x10, 0x43, 0x8A, 0x3E, 0x06, 0x9F, 0x33, 0xF2, 0xC7, 0x9C,
151 };
152 
153 /* 8b8dc1ecc9041023f453f24a54f213300dc9c99f4f96ebe1ce8ee68272470d584fd531c1d734722c4ee654db7fdc16e7ae9a3f84cd977986f3e2a224090b21fcc7417658dfb815b0774e7570dd6d64fa76339deff8d09cabd930b10e08db5482da19b839 */
154 static UCHAR plain_512_224[] = {
155 0x8b, 0x8d, 0xc1, 0xec, 0xc9, 0x04, 0x10, 0x23, 0xf4, 0x53, 0xf2, 0x4a, 0x54, 0xf2, 0x13, 0x30,
156 0x0d, 0xc9, 0xc9, 0x9f, 0x4f, 0x96, 0xeb, 0xe1, 0xce, 0x8e, 0xe6, 0x82, 0x72, 0x47, 0x0d, 0x58,
157 0x4f, 0xd5, 0x31, 0xc1, 0xd7, 0x34, 0x72, 0x2c, 0x4e, 0xe6, 0x54, 0xdb, 0x7f, 0xdc, 0x16, 0xe7,
158 0xae, 0x9a, 0x3f, 0x84, 0xcd, 0x97, 0x79, 0x86, 0xf3, 0xe2, 0xa2, 0x24, 0x09, 0x0b, 0x21, 0xfc,
159 0xc7, 0x41, 0x76, 0x58, 0xdf, 0xb8, 0x15, 0xb0, 0x77, 0x4e, 0x75, 0x70, 0xdd, 0x6d, 0x64, 0xfa,
160 0x76, 0x33, 0x9d, 0xef, 0xf8, 0xd0, 0x9c, 0xab, 0xd9, 0x30, 0xb1, 0x0e, 0x08, 0xdb, 0x54, 0x82,
161 0xda, 0x19, 0xb8, 0x39,
162 };
163 
164 /* cad33c88f68417b6792cc167667b083d8e6a96eb70df04a4ad15c7f4 */
165 static UCHAR secret_512_224[] = {
166 0xca, 0xd3, 0x3c, 0x88, 0xf6, 0x84, 0x17, 0xb6, 0x79, 0x2c, 0xc1, 0x67, 0x66, 0x7b, 0x08, 0x3d,
167 0x8e, 0x6a, 0x96, 0xeb, 0x70, 0xdf, 0x04, 0xa4, 0xad, 0x15, 0xc7, 0xf4,
168 };
169 
170 /* b7e9f6d45cc926165fa80c187c246000562107720e0f41fa136c24aa3c8949041490c51a75c65af3580eef31ebaf3ef1e456cdf3155f1ffb41502b762fa60d61fcd5fc67b58a7c492633d483ecc1c32dd2ac6f1f5a389e5899f828a14890ad6d19be8304479cf2e0711fa457a8e4577bc72cd53f022526db */
171 static UCHAR plain_512_256[] = {
172 0xb7, 0xe9, 0xf6, 0xd4, 0x5c, 0xc9, 0x26, 0x16, 0x5f, 0xa8, 0x0c, 0x18, 0x7c, 0x24, 0x60, 0x00,
173 0x56, 0x21, 0x07, 0x72, 0x0e, 0x0f, 0x41, 0xfa, 0x13, 0x6c, 0x24, 0xaa, 0x3c, 0x89, 0x49, 0x04,
174 0x14, 0x90, 0xc5, 0x1a, 0x75, 0xc6, 0x5a, 0xf3, 0x58, 0x0e, 0xef, 0x31, 0xeb, 0xaf, 0x3e, 0xf1,
175 0xe4, 0x56, 0xcd, 0xf3, 0x15, 0x5f, 0x1f, 0xfb, 0x41, 0x50, 0x2b, 0x76, 0x2f, 0xa6, 0x0d, 0x61,
176 0xfc, 0xd5, 0xfc, 0x67, 0xb5, 0x8a, 0x7c, 0x49, 0x26, 0x33, 0xd4, 0x83, 0xec, 0xc1, 0xc3, 0x2d,
177 0xd2, 0xac, 0x6f, 0x1f, 0x5a, 0x38, 0x9e, 0x58, 0x99, 0xf8, 0x28, 0xa1, 0x48, 0x90, 0xad, 0x6d,
178 0x19, 0xbe, 0x83, 0x04, 0x47, 0x9c, 0xf2, 0xe0, 0x71, 0x1f, 0xa4, 0x57, 0xa8, 0xe4, 0x57, 0x7b,
179 0xc7, 0x2c, 0xd5, 0x3f, 0x02, 0x25, 0x26, 0xdb,
180 };
181 
182 /* ba196a3ea840ff21f6f43988fb515354b209ad601fdf00861a584e7623f59ffe */
183 static UCHAR secret_512_256[] = {
184 0xba, 0x19, 0x6a, 0x3e, 0xa8, 0x40, 0xff, 0x21, 0xf6, 0xf4, 0x39, 0x88, 0xfb, 0x51, 0x53, 0x54,
185 0xb2, 0x09, 0xad, 0x60, 0x1f, 0xdf, 0x00, 0x86, 0x1a, 0x58, 0x4e, 0x76, 0x23, 0xf5, 0x9f, 0xfe,
186 };
187 
188 /* Output. */
189 static ULONG output[16];
190 
191 /**************************************************************************/
192 /*                                                                        */
193 /*  FUNCTION                                               RELEASE        */
194 /*                                                                        */
195 /*    nx_crypto_method_self_test_sha                      PORTABLE C      */
196 /*                                                           6.1.7        */
197 /*  AUTHOR                                                                */
198 /*                                                                        */
199 /*    Timothy Stapko, Microsoft Corporation                               */
200 /*                                                                        */
201 /*  DESCRIPTION                                                           */
202 /*                                                                        */
203 /*    This function performs the Known Answer Test for SHA crypto method. */
204 /*                                                                        */
205 /*  INPUT                                                                 */
206 /*                                                                        */
207 /*    method_ptr                            Pointer to the crypto method  */
208 /*                                            to be tested.               */
209 /*                                                                        */
210 /*  OUTPUT                                                                */
211 /*                                                                        */
212 /*    status                                Completion status             */
213 /*                                                                        */
214 /*  CALLS                                                                 */
215 /*                                                                        */
216 /*    None                                                                */
217 /*                                                                        */
218 /*  CALLED BY                                                             */
219 /*                                                                        */
220 /*    Application Code                                                    */
221 /*                                                                        */
222 /*  RELEASE HISTORY                                                       */
223 /*                                                                        */
224 /*    DATE              NAME                      DESCRIPTION             */
225 /*                                                                        */
226 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
227 /*  09-30-2020     Timothy Stapko           Modified comment(s),          */
228 /*                                            resulting in version 6.1    */
229 /*  06-02-2021     Bhupendra Naphade        Modified comment(s),          */
230 /*                                            renamed FIPS symbol to      */
231 /*                                            self-test,                  */
232 /*                                            resulting in version 6.1.7  */
233 /*                                                                        */
234 /**************************************************************************/
_nx_crypto_method_self_test_sha(NX_CRYPTO_METHOD * crypto_method_sha,VOID * metadata,UINT metadata_size)235 NX_CRYPTO_KEEP UINT _nx_crypto_method_self_test_sha(NX_CRYPTO_METHOD *crypto_method_sha,
236                                                     VOID *metadata, UINT metadata_size)
237 {
238 UCHAR  *input;
239 UCHAR  *secret;
240 UINT    input_length;
241 UINT    output_length;
242 UINT    status;
243 VOID   *handler = NX_CRYPTO_NULL;
244 
245 
246     /* Validate the crypto method */
247     if(crypto_method_sha == NX_CRYPTO_NULL)
248         return(NX_CRYPTO_PTR_ERROR);
249 
250     /* Set the test data.  */
251     switch (crypto_method_sha -> nx_crypto_algorithm)
252     {
253     case NX_CRYPTO_HASH_SHA1:
254         input = plain_1;
255         secret = secret_1;
256         input_length = sizeof(plain_1);
257         output_length = sizeof(secret_1);
258         break;
259     case NX_CRYPTO_HASH_SHA224:
260         input = plain_224;
261         secret = secret_224;
262         input_length = sizeof(plain_224);
263         output_length = sizeof(secret_224);
264         break;
265     case NX_CRYPTO_HASH_SHA256:
266         input = plain_256;
267         secret = secret_256;
268         input_length = sizeof(plain_256);
269         output_length = sizeof(secret_256);
270         break;
271     case NX_CRYPTO_HASH_SHA384:
272         input = plain_384;
273         secret = secret_384;
274         input_length = sizeof(plain_384);
275         output_length = sizeof(secret_384);
276         break;
277     case NX_CRYPTO_HASH_SHA512:
278         input = plain_512;
279         secret = secret_512;
280         input_length = sizeof(plain_512);
281         output_length = sizeof(secret_512);
282         break;
283     case NX_CRYPTO_HASH_SHA512_224:
284         input = plain_512_224;
285         secret = secret_512_224;
286         input_length = sizeof(plain_512_224);
287         output_length = sizeof(secret_512_224);
288         break;
289     case NX_CRYPTO_HASH_SHA512_256:
290         input = plain_512_256;
291         secret = secret_512_256;
292         input_length = sizeof(plain_512_256);
293         output_length = sizeof(secret_512_256);
294         break;
295     default:
296         return(1);
297     }
298 
299     if (crypto_method_sha -> nx_crypto_init)
300     {
301         status = crypto_method_sha -> nx_crypto_init(crypto_method_sha,
302                                                      NX_CRYPTO_NULL,
303                                                      0,
304                                                      &handler,
305                                                      metadata,
306                                                      metadata_size);
307 
308         if (status != NX_CRYPTO_SUCCESS)
309         {
310             return(status);
311         }
312     }
313 
314     if (crypto_method_sha -> nx_crypto_operation == NX_CRYPTO_NULL)
315     {
316         return(NX_CRYPTO_PTR_ERROR);
317     }
318 
319     /* Clear the output buffer.  */
320     NX_CRYPTO_MEMSET(output, 0, sizeof(output));
321 
322     /* Call the crypto operation function.  */
323     status = crypto_method_sha -> nx_crypto_operation(NX_CRYPTO_AUTHENTICATE,
324                                                       handler,
325                                                       crypto_method_sha,
326                                                       NX_CRYPTO_NULL,
327                                                       0,
328                                                       input,
329                                                       input_length,
330                                                       NX_CRYPTO_NULL,
331                                                       (UCHAR *)output,
332                                                       output_length,
333                                                       metadata,
334                                                       metadata_size,
335                                                       NX_CRYPTO_NULL, NX_CRYPTO_NULL);
336 
337     /* Check the status.  */
338     if(status != NX_CRYPTO_SUCCESS)
339     {
340         return(status);
341     }
342 
343     /* Validate the output.  */
344     if(NX_CRYPTO_MEMCMP(output, secret, output_length) != 0)
345     {
346         return(NX_CRYPTO_NOT_SUCCESSFUL);
347     }
348 
349     if (crypto_method_sha -> nx_crypto_cleanup)
350     {
351         status = crypto_method_sha -> nx_crypto_cleanup(metadata);
352     }
353 
354     return(status);
355 }
356 #endif
357