@@ -98,7 +98,6 @@ const NX_CRYPTO_METHOD *public_cipher_method;
9898VOID * handler = NX_NULL ;
9999#endif
100100UINT data_size ;
101- UINT key_size ;
102101UCHAR * encrypted_data_ptr ;
103102#ifndef NX_SECURE_DISABLE_X509
104103UCHAR rand_byte ;
@@ -133,50 +132,17 @@ NX_CRYPTO_EXTENDED_OUTPUT extended_output;
133132 if (ciphersuite -> nx_secure_tls_public_cipher -> nx_crypto_algorithm == NX_CRYPTO_KEY_EXCHANGE_ECDH ||
134133 ciphersuite -> nx_secure_tls_public_cipher -> nx_crypto_algorithm == NX_CRYPTO_KEY_EXCHANGE_ECDHE )
135134 {
136- data_size = 0 ;
135+ data_size = ( UINT )( 1 + tls_key_material -> nx_secure_tls_new_key_material_data [ 0 ]) ;
137136
138- if (ciphersuite -> nx_secure_tls_public_auth -> nx_crypto_algorithm == NX_CRYPTO_KEY_EXCHANGE_PSK )
139- {
140- if ((tls_credentials -> nx_secure_tls_client_psk .nx_secure_tls_psk_id_hint_size >
141- sizeof (tls_credentials -> nx_secure_tls_client_psk .nx_secure_tls_psk_id_hint )) ||
142- (tls_credentials -> nx_secure_tls_client_psk .nx_secure_tls_psk_id_hint_size >
143- (buffer_length - 2 )))
144- {
145-
146- /* Packet buffer too small. */
147- return (NX_SECURE_TLS_PACKET_BUFFER_TOO_SMALL );
148- }
149-
150- /* Pointer to the output encrypted pre-master secret. */
151- encrypted_data_ptr = & data_buffer [2 ];
152-
153- /* Send the PSK Identity string to the remote server along with its length. */
154- NX_SECURE_MEMCPY (encrypted_data_ptr , tls_credentials -> nx_secure_tls_client_psk .nx_secure_tls_psk_id ,
155- tls_credentials -> nx_secure_tls_client_psk .nx_secure_tls_psk_id_size ); /* Use case of memcpy is verified. */
156-
157- /* Make sure our size is correct. */
158- data_size = tls_credentials -> nx_secure_tls_client_psk .nx_secure_tls_psk_id_size ;
159-
160- /* Put the length into our outgoing packet buffer. */
161- data_buffer [0 ] = (UCHAR )((data_size & 0xFF00 ) >> 8 );
162- data_buffer [1 ] = (UCHAR )(data_size & 0x00FF );
163-
164- data_size += 2 ;
165- data_buffer += data_size ;
166- }
167-
168- key_size = (UINT )(1 + tls_key_material -> nx_secure_tls_new_key_material_data [0 ]);
169- data_size += key_size ;
170-
171- if ((key_size > sizeof (tls_key_material -> nx_secure_tls_new_key_material_data )) ||
137+ if ((data_size > sizeof (tls_key_material -> nx_secure_tls_new_key_material_data )) ||
172138 (data_size > buffer_length ))
173139 {
174140
175141 /* Packet buffer too small. */
176142 return (NX_SECURE_TLS_PACKET_BUFFER_TOO_SMALL );
177143 }
178144
179- NX_SECURE_MEMCPY (data_buffer , tls_key_material -> nx_secure_tls_new_key_material_data , key_size ); /* Use case of memcpy is verified. */
145+ NX_SECURE_MEMCPY (data_buffer , tls_key_material -> nx_secure_tls_new_key_material_data , data_size ); /* Use case of memcpy is verified. */
180146 }
181147 else
182148#endif /* NX_SECURE_ENABLE_ECC_CIPHERSUITE */
0 commit comments