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