From 0bdb68a2428af036005aa45aa8b85a751494f73e Mon Sep 17 00:00:00 2001 From: Neil Armstrong Date: Wed, 23 Mar 2022 17:46:32 +0100 Subject: [PATCH] Introduce zlen size variable in ECHDE-PSK part of ssl_write_client_key_exchange() Signed-off-by: Neil Armstrong --- library/ssl_tls12_client.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/library/ssl_tls12_client.c b/library/ssl_tls12_client.c index 91cad8b293..d372663873 100644 --- a/library/ssl_tls12_client.c +++ b/library/ssl_tls12_client.c @@ -3098,6 +3098,8 @@ ecdh_calc_secret: unsigned char *p = ssl->handshake->premaster; const unsigned char* const p_end = p + sizeof( ssl->handshake->premaster ); + /* uint16 to store length (in octets) of the ECDH computation */ + const size_t zlen_size = 2; size_t zlen = 0; /* Perform ECDH computation after the uint16 reserved for the length */ @@ -3105,8 +3107,8 @@ ecdh_calc_secret: handshake->ecdh_psa_privkey, handshake->ecdh_psa_peerkey, handshake->ecdh_psa_peerkey_len, - p + 2, - p_end - ( p + 2 ), + p + zlen_size, + p_end - ( p + zlen_size ), &zlen ); destruction_status = psa_destroy_key( handshake->ecdh_psa_privkey ); @@ -3119,7 +3121,7 @@ ecdh_calc_secret: /* Write the ECDH computation length before the ECDH computation */ MBEDTLS_PUT_UINT16_BE( zlen, p, 0 ); - p += 2 + zlen; + p += zlen_size + zlen; /* opaque psk<0..2^16-1>; */ if( p_end - p < 2 )