Use byte reading macros in places not using a byte mask

byte shifting opertations throughout library/ were only replaced with
the byte reading macros when an 0xff mask was being used.
The byte reading macros are now more widley used, however they have not
been used in all cases of a byte shift operation, as it detracted from
the immediate readability or otherwise did not seem appropriate.

Signed-off-by: Joe Subbiani <joe.subbiani@arm.com>
This commit is contained in:
Joe Subbiani 2021-07-16 14:27:50 +01:00
parent 99edd6c810
commit fbeb692dd0
13 changed files with 118 additions and 118 deletions

View file

@ -2494,10 +2494,10 @@ static int ssl_write_server_hello( mbedtls_ssl_context *ssl )
#if defined(MBEDTLS_HAVE_TIME)
t = mbedtls_time( NULL );
*p++ = (unsigned char)( t >> 24 );
*p++ = (unsigned char)( t >> 16 );
*p++ = (unsigned char)( t >> 8 );
*p++ = (unsigned char)( t );
*p++ = MBEDTLS_BYTE_3( t );
*p++ = MBEDTLS_BYTE_2( t );
*p++ = MBEDTLS_BYTE_1( t );
*p++ = MBEDTLS_BYTE_0( t );
MBEDTLS_SSL_DEBUG_MSG( 3, ( "server hello, current time: %" MBEDTLS_PRINTF_LONGLONG,
(long long) t ) );
@ -2578,9 +2578,9 @@ static int ssl_write_server_hello( mbedtls_ssl_context *ssl )
MBEDTLS_SSL_DEBUG_MSG( 3, ( "%s session has been resumed",
ssl->handshake->resume ? "a" : "no" ) );
*p++ = (unsigned char)( ssl->session_negotiate->ciphersuite >> 8 );
*p++ = (unsigned char)( ssl->session_negotiate->ciphersuite );
*p++ = (unsigned char)( ssl->session_negotiate->compression );
*p++ = MBEDTLS_BYTE_1( ssl->session_negotiate->ciphersuite );
*p++ = MBEDTLS_BYTE_0( ssl->session_negotiate->ciphersuite );
*p++ = MBEDTLS_BYTE_0( ssl->session_negotiate->compression );
MBEDTLS_SSL_DEBUG_MSG( 3, ( "server hello, chosen ciphersuite: %s",
mbedtls_ssl_get_ciphersuite_name( ssl->session_negotiate->ciphersuite ) ) );
@ -2785,8 +2785,8 @@ static int ssl_write_certificate_request( mbedtls_ssl_context *ssl )
#endif
}
p[0] = (unsigned char)( sa_len >> 8 );
p[1] = (unsigned char)( sa_len );
p[0] = MBEDTLS_BYTE_1( sa_len );
p[1] = MBEDTLS_BYTE_0( sa_len );
sa_len += 2;
p += sa_len;
}
@ -2826,8 +2826,8 @@ static int ssl_write_certificate_request( mbedtls_ssl_context *ssl )
break;
}
*p++ = (unsigned char)( dn_size >> 8 );
*p++ = (unsigned char)( dn_size );
*p++ = MBEDTLS_BYTE_1( dn_size );
*p++ = MBEDTLS_BYTE_0( dn_size );
memcpy( p, crt->subject_raw.p, dn_size );
p += dn_size;
@ -2841,8 +2841,8 @@ static int ssl_write_certificate_request( mbedtls_ssl_context *ssl )
ssl->out_msglen = p - buf;
ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE;
ssl->out_msg[0] = MBEDTLS_SSL_HS_CERTIFICATE_REQUEST;
ssl->out_msg[4 + ct_len + sa_len] = (unsigned char)( total_dn_size >> 8 );
ssl->out_msg[5 + ct_len + sa_len] = (unsigned char)( total_dn_size );
ssl->out_msg[4 + ct_len + sa_len] = MBEDTLS_BYTE_1( total_dn_size );
ssl->out_msg[5 + ct_len + sa_len] = MBEDTLS_BYTE_0( total_dn_size );
ret = mbedtls_ssl_write_handshake_msg( ssl );
@ -3320,8 +3320,8 @@ static int ssl_write_server_key_exchange( mbedtls_ssl_context *ssl )
#if defined(MBEDTLS_KEY_EXCHANGE_WITH_SERVER_SIGNATURE_ENABLED)
if( signature_len != 0 )
{
ssl->out_msg[ssl->out_msglen++] = (unsigned char)( signature_len >> 8 );
ssl->out_msg[ssl->out_msglen++] = (unsigned char)( signature_len );
ssl->out_msg[ssl->out_msglen++] = MBEDTLS_BYTE_1( signature_len );
ssl->out_msg[ssl->out_msglen++] = MBEDTLS_BYTE_0( signature_len );
MBEDTLS_SSL_DEBUG_BUF( 3, "my signature",
ssl->out_msg + ssl->out_msglen,