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
|
/***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
* Copyright (c) 2025-present Eclipse ThreadX Contributors
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/** */
/** NetX Crypto Component */
/** */
/** Crypto Self Test */
/** */
/**************************************************************************/
/**************************************************************************/
#define NX_CRYPTO_SOURCE_CODE
/* Include necessary system files. */
#include "nx_crypto_method_self_test.h"
#ifdef NX_CRYPTO_SELF_TEST
static UCHAR metadata[10240];
extern NX_CRYPTO_METHOD crypto_method_aes_cbc_128;
extern NX_CRYPTO_METHOD crypto_method_aes_cbc_192;
extern NX_CRYPTO_METHOD crypto_method_aes_cbc_256;
extern NX_CRYPTO_METHOD crypto_method_3des;
extern NX_CRYPTO_METHOD crypto_method_des;
extern NX_CRYPTO_METHOD crypto_method_rsa;
extern NX_CRYPTO_METHOD crypto_method_md5;
extern NX_CRYPTO_METHOD crypto_method_sha1;
extern NX_CRYPTO_METHOD crypto_method_sha224;
extern NX_CRYPTO_METHOD crypto_method_sha256;
extern NX_CRYPTO_METHOD crypto_method_sha384;
extern NX_CRYPTO_METHOD crypto_method_sha512;
extern NX_CRYPTO_METHOD crypto_method_sha512_224;
extern NX_CRYPTO_METHOD crypto_method_sha512_256;
extern NX_CRYPTO_METHOD crypto_method_hmac_md5;
extern NX_CRYPTO_METHOD crypto_method_hmac_sha1;
extern NX_CRYPTO_METHOD crypto_method_hmac_sha224;
extern NX_CRYPTO_METHOD crypto_method_hmac_sha256;
extern NX_CRYPTO_METHOD crypto_method_hmac_sha384;
extern NX_CRYPTO_METHOD crypto_method_hmac_sha512;
extern NX_CRYPTO_METHOD crypto_method_hmac_sha512_224;
extern NX_CRYPTO_METHOD crypto_method_hmac_sha512_256;
extern NX_CRYPTO_METHOD crypto_method_tls_prf_1;
extern NX_CRYPTO_METHOD crypto_method_tls_prf_sha256;
extern NX_CRYPTO_METHOD crypto_method_tls_prf_sha384;
extern NX_CRYPTO_METHOD crypto_method_tls_prf_sha512;
extern NX_CRYPTO_METHOD crypto_method_drbg;
extern NX_CRYPTO_METHOD crypto_method_ecdsa;
extern NX_CRYPTO_METHOD crypto_method_pkcs1;
extern NX_CRYPTO_METHOD crypto_method_ecdh;
extern NX_CRYPTO_METHOD crypto_method_ecdhe;
const CHAR nx_crypto_hash_key[] = "EL_CRYPTO_VERSION_5.12 _FOR_FIPS";
const UINT nx_crypto_hash_key_size = sizeof(nx_crypto_hash_key) << 3;
#define NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status) \
if(status) \
{ \
_nx_crypto_library_state |= NX_CRYPTO_LIBRARY_STATE_POST_FAILED; \
}
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* nx_crypto_method_self_test PORTABLE C */
/* 6.4.3 */
/* AUTHOR */
/* */
/* Timothy Stapko, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function performs the Known Answer Test for crypto method. */
/* */
/* INPUT */
/* */
/* method_ptr Pointer to the crypto method */
/* to be tested. */
/* */
/* OUTPUT */
/* */
/* status Completion status */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/**************************************************************************/
NX_CRYPTO_KEEP INT _nx_crypto_method_self_test(INT arg)
{
UINT metadata_size = sizeof(metadata);
UINT status;
/* Set the crypto state to POST_IN_PROGRESS */
/* Also clear the UNINITIALIZED flag */
_nx_crypto_library_state = _nx_crypto_library_state & (~NX_CRYPTO_LIBRARY_STATE_UNINITIALIZED);
_nx_crypto_library_state = _nx_crypto_library_state | NX_CRYPTO_LIBRARY_STATE_POST_IN_PROGRESS;
/* Initialize hardware random number generator. */
NX_CRYPTO_HARDWARE_RAND_INITIALIZE
NX_CRYPTO_INTEGRITY_TEST
status = _nx_crypto_method_self_test_des(&crypto_method_des, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_aes(&crypto_method_aes_cbc_256, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_3des(&crypto_method_3des, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_rsa(&crypto_method_rsa, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_md5(&crypto_method_md5, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_sha(&crypto_method_sha1, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_sha(&crypto_method_sha224, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_sha(&crypto_method_sha256, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_sha(&crypto_method_sha384, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_sha(&crypto_method_sha512, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_sha(&crypto_method_sha512_224, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_sha(&crypto_method_sha512_256, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_hmac_md5(&crypto_method_hmac_md5, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_hmac_sha(&crypto_method_hmac_sha1, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_hmac_sha(&crypto_method_hmac_sha224, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_hmac_sha(&crypto_method_hmac_sha256, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_hmac_sha(&crypto_method_hmac_sha384, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_hmac_sha(&crypto_method_hmac_sha512, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_hmac_sha(&crypto_method_hmac_sha512_224, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_hmac_sha(&crypto_method_hmac_sha512_256, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_prf(&crypto_method_tls_prf_1, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_prf(&crypto_method_tls_prf_sha256, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_prf(&crypto_method_tls_prf_sha384, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_prf(&crypto_method_tls_prf_sha512, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_drbg(&crypto_method_drbg, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_ecdsa(&crypto_method_ecdsa, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_pkcs1(&crypto_method_pkcs1, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_ecdh(&crypto_method_ecdh, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
status = _nx_crypto_method_self_test_ecdh(&crypto_method_ecdhe, metadata, metadata_size);
NX_CRYPTO_FUNCTIONAL_TEST_CHECK(status)
/* Clear the POST-inprogress flag */
_nx_crypto_library_state = _nx_crypto_library_state & (~NX_CRYPTO_LIBRARY_STATE_POST_IN_PROGRESS);
/* Set the library state to "operational" if POST is successful. */
if((_nx_crypto_library_state & NX_CRYPTO_LIBRARY_STATE_POST_FAILED) == 0)
_nx_crypto_library_state = NX_CRYPTO_LIBRARY_STATE_OPERATIONAL;
/* All done. Return. */
return(arg);
}
#endif
|