1
10
13
14
20
21
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
92
93
94
95
96
97
98
104
109
110
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
138
139
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
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
209
210
211
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
240
241
242
243
244
245
246
249
250
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
301
302
303
304
305
306
307
...
...
...
#define NX_SECURE_SOURCE_CODE
#include "nx_secure_tls.h"
#ifdef NX_SECURE_ENABLE_DTLS
#include "nx_secure_dtls.h"
#endif
...
...
UINT _nx_secure_tls_handshake_hash_update(NX_SECURE_TLS_SESSION *tls_session, UCHAR *data,
UINT length)
{
UINT status = NX_NOT_SUCCESSFUL;
const NX_CRYPTO_METHOD *method_ptr;
#if (NX_SECURE_TLS_TLS_1_3_ENABLED)
UINT hash_length;
USHORT hello_retry_process = 0;/* ... */
#endif
#if (NX_SECURE_TLS_TLS_1_3_ENABLED)
if(tls_session->nx_secure_tls_1_3)
{
if (tls_session -> nx_secure_tls_session_ciphersuite == NX_NULL)
{
method_ptr = tls_session -> nx_secure_tls_crypto_table->nx_secure_tls_handshake_hash_sha256_method;
}if (tls_session -> nx_secure_tls_session_ciphersuite == NX_NULL) { ... }
else
{
method_ptr = tls_session -> nx_secure_tls_session_ciphersuite -> nx_secure_tls_hash;
}else { ... }
/* ... */
if (method_ptr -> nx_crypto_operation != NX_NULL)
{
status = method_ptr -> nx_crypto_operation(NX_CRYPTO_HASH_UPDATE,
tls_session -> nx_secure_tls_handshake_hash.nx_secure_tls_handshake_hash_sha256_handler,
(NX_CRYPTO_METHOD*)method_ptr,
NX_NULL,
0,
data,
length,
NX_NULL,
NX_NULL,
0,
tls_session -> nx_secure_tls_handshake_hash.nx_secure_tls_handshake_hash_sha256_metadata,
tls_session -> nx_secure_tls_handshake_hash.nx_secure_tls_handshake_hash_sha256_metadata_size,
NX_NULL,
NX_NULL);
#ifndef NX_SECURE_TLS_SERVER_DISABLED
if (tls_session -> nx_secure_tls_socket_type == NX_SECURE_TLS_SESSION_TYPE_SERVER)
{
hello_retry_process = (tls_session -> nx_secure_tls_server_state == NX_SECURE_TLS_SERVER_STATE_SEND_HELLO_RETRY);
}if (tls_session -> nx_secure_tls_socket_type == NX_SECURE_TLS_SESSION_TYPE_SERVER) { ... }
/* ... */#endif
#ifndef NX_SECURE_TLS_CLIENT_DISABLED
if (tls_session -> nx_secure_tls_socket_type == NX_SECURE_TLS_SESSION_TYPE_CLIENT)
{
hello_retry_process = (tls_session -> nx_secure_tls_client_state == NX_SECURE_TLS_CLIENT_STATE_HELLO_RETRY);
}if (tls_session -> nx_secure_tls_socket_type == NX_SECURE_TLS_SESSION_TYPE_CLIENT) { ... }
/* ... */#endif
if ((status == NX_SUCCESS) &&
(hello_retry_process) &&
(data[0] == NX_SECURE_TLS_CLIENT_HELLO) &&
(length > NX_SECURE_TLS_HANDSHAKE_HEADER_SIZE))
{
status = method_ptr -> nx_crypto_operation(NX_CRYPTO_HASH_CALCULATE,
tls_session -> nx_secure_tls_handshake_hash.nx_secure_tls_handshake_hash_sha256_handler,
(NX_CRYPTO_METHOD*)method_ptr,
NX_NULL,
0,
NX_NULL,
0,
NX_NULL,
data + 4,
NX_SECURE_TLS_MAX_HASH_SIZE,
tls_session -> nx_secure_tls_handshake_hash.nx_secure_tls_handshake_hash_sha256_metadata,
tls_session -> nx_secure_tls_handshake_hash.nx_secure_tls_handshake_hash_sha256_metadata_size,
NX_NULL,
NX_NULL);
if (status == NX_SUCCESS)
{
status = _nx_secure_tls_handshake_hash_init(tls_session);
}if (status == NX_SUCCESS) { ... }
if (status == NX_SUCCESS)
{
hash_length = method_ptr -> nx_crypto_ICV_size_in_bits >> 3;
data[0] = NX_SECURE_TLS_MESSAGE_HASH & 0xFF;
data[1] = 0;
data[2] = 0;
data[3] = hash_length & 0xFF;
status = method_ptr -> nx_crypto_operation(NX_CRYPTO_HASH_UPDATE,
tls_session -> nx_secure_tls_handshake_hash.nx_secure_tls_handshake_hash_sha256_handler,
(NX_CRYPTO_METHOD*)method_ptr,
NX_NULL,
0,
data,
hash_length + 4,
NX_NULL,
NX_NULL,
0,
tls_session -> nx_secure_tls_handshake_hash.nx_secure_tls_handshake_hash_sha256_metadata,
tls_session -> nx_secure_tls_handshake_hash.nx_secure_tls_handshake_hash_sha256_metadata_size,
NX_NULL,
NX_NULL);
}if (status == NX_SUCCESS) { ... }
}if ((status == NX_SUCCESS) && (hello_retry_process) && (data[0] == NX_SECURE_TLS_CLIENT_HELLO) && (length > NX_SECURE_TLS_HANDSHAKE_HEADER_SIZE)) { ... }
}if (method_ptr -> nx_crypto_operation != NX_NULL) { ... }
return(status);
}if (tls_session->nx_secure_tls_1_3) { ... }
/* ... */#endif
/* ... */
#if (NX_SECURE_TLS_TLS_1_2_ENABLED)
#ifdef NX_SECURE_ENABLE_DTLS
if (tls_session -> nx_secure_tls_protocol_version == NX_SECURE_TLS_VERSION_TLS_1_2 ||
tls_session -> nx_secure_tls_protocol_version == NX_SECURE_DTLS_VERSION_1_2)/* ... */
#else
if (tls_session -> nx_secure_tls_protocol_version == NX_SECURE_TLS_VERSION_TLS_1_2)
#endif
{
method_ptr = tls_session -> nx_secure_tls_crypto_table -> nx_secure_tls_handshake_hash_sha256_method;
if (method_ptr -> nx_crypto_operation != NX_NULL)
{
status = method_ptr -> nx_crypto_operation(NX_CRYPTO_HASH_UPDATE,
tls_session -> nx_secure_tls_handshake_hash.nx_secure_tls_handshake_hash_sha256_handler,
(NX_CRYPTO_METHOD*)method_ptr,
NX_NULL,
0,
data,
length,
NX_NULL,
NX_NULL,
0,
tls_session -> nx_secure_tls_handshake_hash.nx_secure_tls_handshake_hash_sha256_metadata,
tls_session -> nx_secure_tls_handshake_hash.nx_secure_tls_handshake_hash_sha256_metadata_size,
NX_NULL,
NX_NULL);
if (status != NX_CRYPTO_SUCCESS)
{
return(status);
}if (status != NX_CRYPTO_SUCCESS) { ... }
}if (method_ptr -> nx_crypto_operation != NX_NULL) { ... }
...}/* ... */
#endif
#if (NX_SECURE_TLS_TLS_1_0_ENABLED || NX_SECURE_TLS_TLS_1_1_ENABLED)
#ifdef NX_SECURE_ENABLE_DTLS
if (tls_session -> nx_secure_tls_protocol_version == NX_SECURE_TLS_VERSION_TLS_1_0 ||
tls_session -> nx_secure_tls_protocol_version == NX_SECURE_TLS_VERSION_TLS_1_1 ||
tls_session -> nx_secure_tls_protocol_version == NX_SECURE_DTLS_VERSION_1_0)/* ... */
#else
if (tls_session -> nx_secure_tls_protocol_version == NX_SECURE_TLS_VERSION_TLS_1_0 ||
tls_session -> nx_secure_tls_protocol_version == NX_SECURE_TLS_VERSION_TLS_1_1)/* ... */
#endif
{
method_ptr = tls_session -> nx_secure_tls_crypto_table -> nx_secure_tls_handshake_hash_md5_method;
if (method_ptr -> nx_crypto_operation != NX_NULL)
{
status = method_ptr -> nx_crypto_operation(NX_CRYPTO_HASH_UPDATE,
tls_session -> nx_secure_tls_handshake_hash.nx_secure_tls_handshake_hash_md5_handler,
(NX_CRYPTO_METHOD*)method_ptr,
NX_NULL,
0,
data,
length,
NX_NULL,
NX_NULL,
0,
tls_session -> nx_secure_tls_handshake_hash.nx_secure_tls_handshake_hash_md5_metadata,
tls_session -> nx_secure_tls_handshake_hash.nx_secure_tls_handshake_hash_md5_metadata_size,
NX_NULL,
NX_NULL);
if (status != NX_CRYPTO_SUCCESS)
{
return(status);
}if (status != NX_CRYPTO_SUCCESS) { ... }
}if (method_ptr -> nx_crypto_operation != NX_NULL) { ... }
method_ptr = tls_session -> nx_secure_tls_crypto_table -> nx_secure_tls_handshake_hash_sha1_method;
if (method_ptr -> nx_crypto_operation != NX_NULL)
{
status = method_ptr -> nx_crypto_operation(NX_CRYPTO_HASH_UPDATE,
tls_session -> nx_secure_tls_handshake_hash.nx_secure_tls_handshake_hash_sha1_handler,
(NX_CRYPTO_METHOD*)method_ptr,
NX_NULL,
0,
data,
length,
NX_NULL,
NX_NULL,
0,
tls_session -> nx_secure_tls_handshake_hash.nx_secure_tls_handshake_hash_sha1_metadata,
tls_session -> nx_secure_tls_handshake_hash.nx_secure_tls_handshake_hash_sha1_metadata_size,
NX_NULL,
NX_NULL);
if (status != NX_CRYPTO_SUCCESS)
{
return(status);
}if (status != NX_CRYPTO_SUCCESS) { ... }
}if (method_ptr -> nx_crypto_operation != NX_NULL) { ... }
...}/* ... */
#endif
return(status);
}{ ... }