1
10
13
14
20
21
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
84
85
92
93
94
95
96
97
98
100
101
102
103
104
105
106
107
108
109
110
111
112
119
120
126
127
128
129
130
131
132
133
134
135
136
137
138
...
...
...
#define NX_SECURE_SOURCE_CODE
#include "nx_secure_dtls.h"
#ifdef NX_SECURE_ENABLE_DTLS...
...
UINT _nx_secure_dtls_send_helloverifyrequest(NX_SECURE_DTLS_SESSION *dtls_session,
NX_PACKET *send_packet)
{
UINT length;
UINT i;
UINT random_value;
UCHAR *packet_buffer;
USHORT protocol_version;
/* ... */
if (((ULONG)(send_packet -> nx_packet_data_end) - (ULONG)(send_packet -> nx_packet_append_ptr)) <
(3u + dtls_session -> nx_secure_dtls_cookie_length))
{
return(NX_SECURE_TLS_PACKET_BUFFER_TOO_SMALL);
}if (((ULONG)(send_packet -> nx_packet_data_end) - (ULONG)(send_packet -> nx_packet_append_ptr)) < (3u + dtls_session -> nx_secure_dtls_cookie_length)) { ... }
length = 0;
packet_buffer = send_packet -> nx_packet_append_ptr;
/* ... */
protocol_version = NX_SECURE_DTLS_VERSION_1_0;
packet_buffer[length] = (UCHAR)((protocol_version & 0xFF00) >> 8);
packet_buffer[length + 1] = (UCHAR)(protocol_version & 0x00FF);
length += 2;
dtls_session -> nx_secure_dtls_cookie_length = 20;
packet_buffer[length] = (UCHAR)(dtls_session -> nx_secure_dtls_cookie_length);
length += 1;
for (i = 0; i < dtls_session -> nx_secure_dtls_cookie_length; i += (UINT)sizeof(random_value))
{
random_value = (UINT)NX_RAND();
NX_CHANGE_ULONG_ENDIAN(random_value);
NX_SECURE_MEMCPY(&dtls_session -> nx_secure_dtls_cookie[i],
(UCHAR *)&random_value, sizeof(random_value));
}for (i = 0; i < dtls_session -> nx_secure_dtls_cookie_length; i += (UINT)sizeof(random_value)) { ... }
if (dtls_session -> nx_secure_dtls_cookie_length > sizeof(dtls_session -> nx_secure_dtls_cookie))
{
return(NX_SECURE_TLS_PACKET_BUFFER_TOO_SMALL);
}if (dtls_session -> nx_secure_dtls_cookie_length > sizeof(dtls_session -> nx_secure_dtls_cookie)) { ... }
NX_SECURE_MEMCPY(&packet_buffer[length], dtls_session -> nx_secure_dtls_cookie, dtls_session -> nx_secure_dtls_cookie_length);
length += dtls_session -> nx_secure_dtls_cookie_length;
send_packet -> nx_packet_append_ptr = send_packet -> nx_packet_append_ptr + length;
send_packet -> nx_packet_length = send_packet -> nx_packet_length + length;
return(NX_SECURE_TLS_SUCCESS);
}_nx_secure_dtls_send_helloverifyrequest (NX_SECURE_DTLS_SESSION *dtls_session, NX_PACKET *send_packet) { ... }
/* ... */#endif