Tidy up grouped MBEDTLS_BYTE_x macros

exchange groups of the byte reading macros with MBEDTLS_PUT_UINTxyz
and then shift the pointer afterwards. Easier to read as you can
see how big the data is that you are putting in, and in the case of
UINT32 AND UINT64 it saves some vertical space.

Signed-off-by: Joe Subbiani <joe.subbiani@arm.com>
This commit is contained in:
Joe Subbiani 2021-08-23 11:35:25 +01:00
parent 24647c5cd2
commit a651e6f762
5 changed files with 16 additions and 26 deletions

View File

@ -152,11 +152,8 @@ static int block_cipher_df( unsigned char *output,
* (Total is padded to a multiple of 16-bytes with zeroes)
*/
p = buf + MBEDTLS_CTR_DRBG_BLOCKSIZE;
*p++ = MBEDTLS_BYTE_3( data_len );
*p++ = MBEDTLS_BYTE_2( data_len );
*p++ = MBEDTLS_BYTE_1( data_len );
*p++ = MBEDTLS_BYTE_0( data_len );
p += 3;
MBEDTLS_PUT_UINT32_BE( data_len, p, 0);
p += 4 + 3;
*p++ = MBEDTLS_CTR_DRBG_SEEDLEN;
memcpy( p, data, data_len );
p[data_len] = 0x80;

View File

@ -166,10 +166,7 @@ static int ecjpake_write_len_point( unsigned char **p,
if( ret != 0 )
return( ret );
(*p)[0] = MBEDTLS_BYTE_3( len );
(*p)[1] = MBEDTLS_BYTE_2( len );
(*p)[2] = MBEDTLS_BYTE_1( len );
(*p)[3] = MBEDTLS_BYTE_0( len );
MBEDTLS_PUT_UINT32_BE( len, *p, 0 );
*p += 4 + len;
@ -209,10 +206,8 @@ static int ecjpake_hash( const mbedtls_md_info_t *md_info,
if( end - p < 4 )
return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL );
*p++ = MBEDTLS_BYTE_3( id_len );
*p++ = MBEDTLS_BYTE_2( id_len );
*p++ = MBEDTLS_BYTE_1( id_len );
*p++ = MBEDTLS_BYTE_0( id_len );
MBEDTLS_PUT_UINT32_BE( id_len, p, 0 );
p += 4;
if( end < p || (size_t)( end - p ) < id_len )
return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL );

View File

@ -493,9 +493,8 @@ static void ssl_mac( mbedtls_md_context_t *md_ctx,
padlen = 40;
memcpy( header, ctr, 8 );
header[ 8] = (unsigned char) type;
header[ 9] = MBEDTLS_BYTE_1( len );
header[10] = MBEDTLS_BYTE_0( len );
header[8] = (unsigned char) type;
header[9] = MBEDTLS_PUT_UINT16_BE( len, header, 9);
memset( padding, 0x36, padlen );
mbedtls_md_starts( md_ctx );

View File

@ -3871,6 +3871,7 @@ static int ssl_decrypt_encrypted_pms( mbedtls_ssl_context *ssl,
if( *p++ != MBEDTLS_BYTE_1( len ) ||
*p++ != MBEDTLS_BYTE_0( len ) )
{
//p += 2;
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client key exchange message" ) );
return( MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE );
}

View File

@ -1948,8 +1948,8 @@ int mbedtls_ssl_psk_derive_premaster( mbedtls_ssl_context *ssl, mbedtls_key_exch
if( end - p < 2 )
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
*(p++) = MBEDTLS_BYTE_1( psk_len );
*(p++) = MBEDTLS_BYTE_0( psk_len );
MBEDTLS_PUT_UINT16_BE( psk_len, p, 0 );
p += 2;
if( end < p || (size_t)( end - p ) < psk_len )
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
@ -1989,9 +1989,8 @@ int mbedtls_ssl_psk_derive_premaster( mbedtls_ssl_context *ssl, mbedtls_key_exch
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_dhm_calc_secret", ret );
return( ret );
}
*(p++) = MBEDTLS_BYTE_1( len );
*(p++) = MBEDTLS_BYTE_0( len );
p += len;
MBEDTLS_PUT_UINT16_BE( len, p, 0 );
p += 2 + len;
MBEDTLS_SSL_DEBUG_MPI( 3, "DHM: K ", &ssl->handshake->dhm_ctx.K );
}
@ -2011,9 +2010,8 @@ int mbedtls_ssl_psk_derive_premaster( mbedtls_ssl_context *ssl, mbedtls_key_exch
return( ret );
}
*(p++) = MBEDTLS_BYTE_1( zlen );
*(p++) = MBEDTLS_BYTE_0( zlen );
p += zlen;
MBEDTLS_PUT_UINT16_BE( zlen, p, 0 );
p += 2 + zlen;
MBEDTLS_SSL_DEBUG_ECDH( 3, &ssl->handshake->ecdh_ctx,
MBEDTLS_DEBUG_ECDH_Z );
@ -2029,8 +2027,8 @@ int mbedtls_ssl_psk_derive_premaster( mbedtls_ssl_context *ssl, mbedtls_key_exch
if( end - p < 2 )
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
*(p++) = MBEDTLS_BYTE_1( psk_len );
*(p++) = MBEDTLS_BYTE_0( psk_len );
MBEDTLS_PUT_UINT16_BE( psk_len, p, 0 );
p += 2;
if( end < p || (size_t)( end - p ) < psk_len )
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );