Replace MBEDTLS_CHAR_x with MBEDTLS_BYTE_x

The CHAR macros casted to an unsigned char which in this project
is garunteed to be 8 bits - the same as uint8_t (which BYTE casts
to) therefore, instances of CHAR have been swapped with BYTE and
the number of macros have been cut down

Signed-off-by: Joe Subbiani <joe.subbiani@arm.com>
This commit is contained in:
Joe Subbiani 2021-07-14 12:31:31 +01:00
parent 5b96e67ea1
commit c045dc14b0
9 changed files with 196 additions and 199 deletions

View File

@ -60,8 +60,8 @@ int mbedtls_asn1_write_len( unsigned char **p, unsigned char *start, size_t len
if( *p - start < 3 )
return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
*--(*p) = MBEDTLS_CHAR_0( len );
*--(*p) = MBEDTLS_CHAR_1( len );
*--(*p) = MBEDTLS_BYTE_0( len );
*--(*p) = MBEDTLS_BYTE_1( len );
*--(*p) = 0x82;
return( 3 );
}
@ -71,9 +71,9 @@ int mbedtls_asn1_write_len( unsigned char **p, unsigned char *start, size_t len
if( *p - start < 4 )
return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
*--(*p) = MBEDTLS_CHAR_0( len );
*--(*p) = MBEDTLS_CHAR_1( len );
*--(*p) = MBEDTLS_CHAR_2( len );
*--(*p) = MBEDTLS_BYTE_0( len );
*--(*p) = MBEDTLS_BYTE_1( len );
*--(*p) = MBEDTLS_BYTE_2( len );
*--(*p) = 0x83;
return( 4 );
}
@ -85,10 +85,10 @@ int mbedtls_asn1_write_len( unsigned char **p, unsigned char *start, size_t len
if( *p - start < 5 )
return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
*--(*p) = MBEDTLS_CHAR_0( len );
*--(*p) = MBEDTLS_CHAR_1( len );
*--(*p) = MBEDTLS_CHAR_2( len );
*--(*p) = MBEDTLS_CHAR_3( len );
*--(*p) = MBEDTLS_BYTE_0( len );
*--(*p) = MBEDTLS_BYTE_1( len );
*--(*p) = MBEDTLS_BYTE_2( len );
*--(*p) = MBEDTLS_BYTE_3( len );
*--(*p) = 0x84;
return( 5 );
}

View File

@ -200,7 +200,7 @@ static int ccm_auth_crypt( mbedtls_ccm_context *ctx, int mode, size_t length,
memcpy( b + 1, iv, iv_len );
for( i = 0, len_left = length; i < q; i++, len_left >>= 8 )
b[15-i] = MBEDTLS_CHAR_0( len_left );
b[15-i] = MBEDTLS_BYTE_0( len_left );
if( len_left > 0 )
return( MBEDTLS_ERR_CCM_BAD_INPUT );
@ -221,8 +221,8 @@ static int ccm_auth_crypt( mbedtls_ccm_context *ctx, int mode, size_t length,
src = add;
memset( b, 0, 16 );
b[0] = MBEDTLS_CHAR_1( add_len );
b[1] = MBEDTLS_CHAR_0( add_len );
b[0] = MBEDTLS_BYTE_1( add_len );
b[1] = MBEDTLS_BYTE_0( add_len );
use_len = len_left < 16 - 2 ? len_left : 16 - 2;
memcpy( b + 2, src, use_len );

View File

@ -29,6 +29,8 @@
#include "mbedtls/config.h"
#endif
#include <stdint.h>
/** Helper to define a function as static except when building invasive tests.
*
* If a function is only used inside its own source file and should be
@ -63,19 +65,14 @@
* Using MBEDTLS_BYTE_a will shift a*8 bits
* to retrieve the next byte of information
*/
#define MBEDTLS_BYTE_0( x ) ( (uint8_t) ( ( x ) & 0xff ) )
#define MBEDTLS_BYTE_0( x ) ( (uint8_t) ( ( x ) & 0xff ) )
#define MBEDTLS_BYTE_1( x ) ( (uint8_t) ( ( ( x ) >> 8 ) & 0xff ) )
#define MBEDTLS_BYTE_2( x ) ( (uint8_t) ( ( ( x ) >> 16 ) & 0xff ) )
#define MBEDTLS_BYTE_3( x ) ( (uint8_t) ( ( ( x ) >> 24 ) & 0xff ) )
#define MBEDTLS_CHAR_0( x ) ( (unsigned char) ( ( x ) & 0xff ) )
#define MBEDTLS_CHAR_1( x ) ( (unsigned char) ( ( ( x ) >> 8 ) & 0xff ) )
#define MBEDTLS_CHAR_2( x ) ( (unsigned char) ( ( ( x ) >> 16 ) & 0xff ) )
#define MBEDTLS_CHAR_3( x ) ( (unsigned char) ( ( ( x ) >> 24 ) & 0xff ) )
#define MBEDTLS_CHAR_4( x ) ( (unsigned char) ( ( ( x ) >> 32 ) & 0xff ) )
#define MBEDTLS_CHAR_5( x ) ( (unsigned char) ( ( ( x ) >> 40 ) & 0xff ) )
#define MBEDTLS_CHAR_6( x ) ( (unsigned char) ( ( ( x ) >> 48 ) & 0xff ) )
#define MBEDTLS_CHAR_7( x ) ( (unsigned char) ( ( ( x ) >> 56 ) & 0xff ) )
#define MBEDTLS_BYTE_4( x ) ( (uint8_t) ( ( ( x ) >> 32 ) & 0xff ) )
#define MBEDTLS_BYTE_5( x ) ( (uint8_t) ( ( ( x ) >> 40 ) & 0xff ) )
#define MBEDTLS_BYTE_6( x ) ( (uint8_t) ( ( ( x ) >> 48 ) & 0xff ) )
#define MBEDTLS_BYTE_7( x ) ( (uint8_t) ( ( ( x ) >> 56 ) & 0xff ) )
/**
* Get the unsigned 32 bits integer corresponding to four bytes in

View File

@ -166,10 +166,10 @@ static int ecjpake_write_len_point( unsigned char **p,
if( ret != 0 )
return( ret );
(*p)[0] = MBEDTLS_CHAR_3( len );
(*p)[1] = MBEDTLS_CHAR_2( len );
(*p)[2] = MBEDTLS_CHAR_1( len );
(*p)[3] = MBEDTLS_CHAR_0( len );
(*p)[0] = MBEDTLS_BYTE_3( len );
(*p)[1] = MBEDTLS_BYTE_2( len );
(*p)[2] = MBEDTLS_BYTE_1( len );
(*p)[3] = MBEDTLS_BYTE_0( len );
*p += 4 + len;
@ -209,10 +209,10 @@ static int ecjpake_hash( const mbedtls_md_info_t *md_info,
if( end - p < 4 )
return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL );
*p++ = MBEDTLS_CHAR_3( id_len );
*p++ = MBEDTLS_CHAR_2( id_len );
*p++ = MBEDTLS_CHAR_1( id_len );
*p++ = MBEDTLS_CHAR_0( id_len );
*p++ = MBEDTLS_BYTE_3( id_len );
*p++ = MBEDTLS_BYTE_2( id_len );
*p++ = MBEDTLS_BYTE_1( id_len );
*p++ = MBEDTLS_BYTE_0( id_len );
if( end < p || (size_t)( end - p ) < id_len )
return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL );
@ -352,7 +352,7 @@ static int ecjpake_zkp_write( const mbedtls_md_info_t *md_info,
goto cleanup;
}
*(*p)++ = MBEDTLS_CHAR_0( len );
*(*p)++ = MBEDTLS_BYTE_0( len );
MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary( &h, *p, len ) ); /* r */
*p += len;

View File

@ -136,18 +136,18 @@ static int ssl_write_hostname_ext( mbedtls_ssl_context *ssl,
* } ServerNameList;
*
*/
*p++ = MBEDTLS_CHAR_1( MBEDTLS_TLS_EXT_SERVERNAME );
*p++ = MBEDTLS_CHAR_0( MBEDTLS_TLS_EXT_SERVERNAME );
*p++ = MBEDTLS_BYTE_1( MBEDTLS_TLS_EXT_SERVERNAME );
*p++ = MBEDTLS_BYTE_0( MBEDTLS_TLS_EXT_SERVERNAME );
*p++ = MBEDTLS_CHAR_1( hostname_len + 5);
*p++ = MBEDTLS_CHAR_0( hostname_len + 5);
*p++ = MBEDTLS_BYTE_1( hostname_len + 5);
*p++ = MBEDTLS_BYTE_0( hostname_len + 5);
*p++ = MBEDTLS_CHAR_1( hostname_len + 3 );
*p++ = MBEDTLS_CHAR_0( hostname_len + 3 );
*p++ = MBEDTLS_BYTE_1( hostname_len + 3 );
*p++ = MBEDTLS_BYTE_0( hostname_len + 3 );
*p++ = MBEDTLS_CHAR_0( MBEDTLS_TLS_EXT_SERVERNAME_HOSTNAME );
*p++ = MBEDTLS_CHAR_1( hostname_len );
*p++ = MBEDTLS_CHAR_0( hostname_len );
*p++ = MBEDTLS_BYTE_0( MBEDTLS_TLS_EXT_SERVERNAME_HOSTNAME );
*p++ = MBEDTLS_BYTE_1( hostname_len );
*p++ = MBEDTLS_BYTE_0( hostname_len );
memcpy( p, ssl->hostname, hostname_len );
@ -181,12 +181,12 @@ static int ssl_write_renegotiation_ext( mbedtls_ssl_context *ssl,
/*
* Secure renegotiation
*/
*p++ = MBEDTLS_CHAR_1( MBEDTLS_TLS_EXT_RENEGOTIATION_INFO );
*p++ = MBEDTLS_CHAR_0( MBEDTLS_TLS_EXT_RENEGOTIATION_INFO );
*p++ = MBEDTLS_BYTE_1( MBEDTLS_TLS_EXT_RENEGOTIATION_INFO );
*p++ = MBEDTLS_BYTE_0( MBEDTLS_TLS_EXT_RENEGOTIATION_INFO );
*p++ = 0x00;
*p++ = MBEDTLS_CHAR_0( ssl->verify_data_len + 1 );
*p++ = MBEDTLS_CHAR_0( ssl->verify_data_len );
*p++ = MBEDTLS_BYTE_0( ssl->verify_data_len + 1 );
*p++ = MBEDTLS_BYTE_0( ssl->verify_data_len );
memcpy( p, ssl->own_verify_data, ssl->verify_data_len );
@ -281,14 +281,14 @@ static int ssl_write_signature_algorithms_ext( mbedtls_ssl_context *ssl,
* SignatureAndHashAlgorithm
* supported_signature_algorithms<2..2^16-2>;
*/
*p++ = MBEDTLS_CHAR_1( MBEDTLS_TLS_EXT_SIG_ALG );
*p++ = MBEDTLS_CHAR_0( MBEDTLS_TLS_EXT_SIG_ALG );
*p++ = MBEDTLS_BYTE_1( MBEDTLS_TLS_EXT_SIG_ALG );
*p++ = MBEDTLS_BYTE_0( MBEDTLS_TLS_EXT_SIG_ALG );
*p++ = MBEDTLS_CHAR_1( sig_alg_len + 2 );
*p++ = MBEDTLS_CHAR_0( sig_alg_len + 2 );
*p++ = MBEDTLS_BYTE_1( sig_alg_len + 2 );
*p++ = MBEDTLS_BYTE_0( sig_alg_len + 2 );
*p++ = MBEDTLS_CHAR_1( sig_alg_len );
*p++ = MBEDTLS_CHAR_0( sig_alg_len );
*p++ = MBEDTLS_BYTE_1( sig_alg_len );
*p++ = MBEDTLS_BYTE_0( sig_alg_len );
*olen = 6 + sig_alg_len;
@ -356,14 +356,14 @@ static int ssl_write_supported_elliptic_curves_ext( mbedtls_ssl_context *ssl,
elliptic_curve_list[elliptic_curve_len++] = info->tls_id & 0xFF;
}
*p++ = MBEDTLS_CHAR_1( MBEDTLS_TLS_EXT_SUPPORTED_ELLIPTIC_CURVES );
*p++ = MBEDTLS_CHAR_0( MBEDTLS_TLS_EXT_SUPPORTED_ELLIPTIC_CURVES );
*p++ = MBEDTLS_BYTE_1( MBEDTLS_TLS_EXT_SUPPORTED_ELLIPTIC_CURVES );
*p++ = MBEDTLS_BYTE_0( MBEDTLS_TLS_EXT_SUPPORTED_ELLIPTIC_CURVES );
*p++ = MBEDTLS_CHAR_1( elliptic_curve_len + 2 );
*p++ = MBEDTLS_CHAR_0( elliptic_curve_len + 2 );
*p++ = MBEDTLS_BYTE_1( elliptic_curve_len + 2 );
*p++ = MBEDTLS_BYTE_0( elliptic_curve_len + 2 );
*p++ = MBEDTLS_CHAR_1( elliptic_curve_len );
*p++ = MBEDTLS_CHAR_0( elliptic_curve_len );
*p++ = MBEDTLS_BYTE_1( elliptic_curve_len );
*p++ = MBEDTLS_BYTE_0( elliptic_curve_len );
*olen = 6 + elliptic_curve_len;
@ -384,8 +384,8 @@ static int ssl_write_supported_point_formats_ext( mbedtls_ssl_context *ssl,
( "client hello, adding supported_point_formats extension" ) );
MBEDTLS_SSL_CHK_BUF_PTR( p, end, 6 );
*p++ = MBEDTLS_CHAR_1( MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS );
*p++ = MBEDTLS_CHAR_0( MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS );
*p++ = MBEDTLS_BYTE_1( MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS );
*p++ = MBEDTLS_BYTE_0( MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS );
*p++ = 0x00;
*p++ = 2;
@ -421,8 +421,8 @@ static int ssl_write_ecjpake_kkpp_ext( mbedtls_ssl_context *ssl,
MBEDTLS_SSL_CHK_BUF_PTR( p, end, 4 );
*p++ = MBEDTLS_CHAR_1( MBEDTLS_TLS_EXT_ECJPAKE_KKPP );
*p++ = MBEDTLS_CHAR_0( MBEDTLS_TLS_EXT_ECJPAKE_KKPP );
*p++ = MBEDTLS_BYTE_1( MBEDTLS_TLS_EXT_ECJPAKE_KKPP );
*p++ = MBEDTLS_BYTE_0( MBEDTLS_TLS_EXT_ECJPAKE_KKPP );
/*
* We may need to send ClientHello multiple times for Hello verification.
@ -464,8 +464,8 @@ static int ssl_write_ecjpake_kkpp_ext( mbedtls_ssl_context *ssl,
memcpy( p + 2, ssl->handshake->ecjpake_cache, kkpp_len );
}
*p++ = MBEDTLS_CHAR_1( kkpp_len );
*p++ = MBEDTLS_CHAR_0( kkpp_len );
*p++ = MBEDTLS_BYTE_1( kkpp_len );
*p++ = MBEDTLS_BYTE_0( kkpp_len );
*olen = kkpp_len + 4;
@ -504,11 +504,11 @@ static int ssl_write_cid_ext( mbedtls_ssl_context *ssl,
MBEDTLS_SSL_CHK_BUF_PTR( p, end, (unsigned)( ssl->own_cid_len + 5 ) );
/* Add extension ID + size */
*p++ = MBEDTLS_CHAR_1( MBEDTLS_TLS_EXT_CID );
*p++ = MBEDTLS_CHAR_0( MBEDTLS_TLS_EXT_CID );
*p++ = MBEDTLS_BYTE_1( MBEDTLS_TLS_EXT_CID );
*p++ = MBEDTLS_BYTE_0( MBEDTLS_TLS_EXT_CID );
ext_len = (size_t) ssl->own_cid_len + 1;
*p++ = MBEDTLS_CHAR_1( ext_len );
*p++ = MBEDTLS_CHAR_0( ext_len );
*p++ = MBEDTLS_BYTE_1( ext_len );
*p++ = MBEDTLS_BYTE_0( ext_len );
*p++ = (uint8_t) ssl->own_cid_len;
memcpy( p, ssl->own_cid, ssl->own_cid_len );
@ -537,8 +537,8 @@ static int ssl_write_max_fragment_length_ext( mbedtls_ssl_context *ssl,
MBEDTLS_SSL_CHK_BUF_PTR( p, end, 5 );
*p++ = MBEDTLS_CHAR_1( MBEDTLS_TLS_EXT_MAX_FRAGMENT_LENGTH );
*p++ = MBEDTLS_CHAR_0( MBEDTLS_TLS_EXT_MAX_FRAGMENT_LENGTH );
*p++ = MBEDTLS_BYTE_1( MBEDTLS_TLS_EXT_MAX_FRAGMENT_LENGTH );
*p++ = MBEDTLS_BYTE_0( MBEDTLS_TLS_EXT_MAX_FRAGMENT_LENGTH );
*p++ = 0x00;
*p++ = 1;
@ -600,8 +600,8 @@ static int ssl_write_encrypt_then_mac_ext( mbedtls_ssl_context *ssl,
MBEDTLS_SSL_CHK_BUF_PTR( p, end, 4 );
*p++ = MBEDTLS_CHAR_1( MBEDTLS_TLS_EXT_ENCRYPT_THEN_MAC );
*p++ = MBEDTLS_CHAR_0( MBEDTLS_TLS_EXT_ENCRYPT_THEN_MAC );
*p++ = MBEDTLS_BYTE_1( MBEDTLS_TLS_EXT_ENCRYPT_THEN_MAC );
*p++ = MBEDTLS_BYTE_0( MBEDTLS_TLS_EXT_ENCRYPT_THEN_MAC );
*p++ = 0x00;
*p++ = 0x00;
@ -631,8 +631,8 @@ static int ssl_write_extended_ms_ext( mbedtls_ssl_context *ssl,
MBEDTLS_SSL_CHK_BUF_PTR( p, end, 4 );
*p++ = MBEDTLS_CHAR_1( MBEDTLS_TLS_EXT_EXTENDED_MASTER_SECRET );
*p++ = MBEDTLS_CHAR_0( MBEDTLS_TLS_EXT_EXTENDED_MASTER_SECRET );
*p++ = MBEDTLS_BYTE_1( MBEDTLS_TLS_EXT_EXTENDED_MASTER_SECRET );
*p++ = MBEDTLS_BYTE_0( MBEDTLS_TLS_EXT_EXTENDED_MASTER_SECRET );
*p++ = 0x00;
*p++ = 0x00;
@ -663,11 +663,11 @@ static int ssl_write_session_ticket_ext( mbedtls_ssl_context *ssl,
/* The addition is safe here since the ticket length is 16 bit. */
MBEDTLS_SSL_CHK_BUF_PTR( p, end, 4 + tlen );
*p++ = MBEDTLS_CHAR_1( MBEDTLS_TLS_EXT_SESSION_TICKET );
*p++ = MBEDTLS_CHAR_0( MBEDTLS_TLS_EXT_SESSION_TICKET );
*p++ = MBEDTLS_BYTE_1( MBEDTLS_TLS_EXT_SESSION_TICKET );
*p++ = MBEDTLS_BYTE_0( MBEDTLS_TLS_EXT_SESSION_TICKET );
*p++ = MBEDTLS_CHAR_1( tlen );
*p++ = MBEDTLS_CHAR_0( tlen );
*p++ = MBEDTLS_BYTE_1( tlen );
*p++ = MBEDTLS_BYTE_0( tlen );
*olen = 4;
@ -707,8 +707,8 @@ static int ssl_write_alpn_ext( mbedtls_ssl_context *ssl,
MBEDTLS_SSL_CHK_BUF_PTR( p, end, 6 + alpnlen );
*p++ = MBEDTLS_CHAR_1( MBEDTLS_TLS_EXT_ALPN );
*p++ = MBEDTLS_CHAR_0( MBEDTLS_TLS_EXT_ALPN );
*p++ = MBEDTLS_BYTE_1( MBEDTLS_TLS_EXT_ALPN );
*p++ = MBEDTLS_BYTE_0( MBEDTLS_TLS_EXT_ALPN );
/*
* opaque ProtocolName<1..2^8-1>;
@ -735,12 +735,12 @@ static int ssl_write_alpn_ext( mbedtls_ssl_context *ssl,
*olen = p - buf;
/* List length = olen - 2 (ext_type) - 2 (ext_len) - 2 (list_len) */
buf[4] = MBEDTLS_CHAR_1( *olen - 6 );
buf[5] = MBEDTLS_CHAR_0( *olen - 6 );
buf[4] = MBEDTLS_BYTE_1( *olen - 6 );
buf[5] = MBEDTLS_BYTE_0( *olen - 6 );
/* Extension length = olen - 2 (ext_type) - 2 (ext_len) */
buf[2] = MBEDTLS_CHAR_1( *olen - 4 );
buf[3] = MBEDTLS_CHAR_0( *olen - 4 );
buf[2] = MBEDTLS_BYTE_1( *olen - 4 );
buf[3] = MBEDTLS_BYTE_0( *olen - 4 );
return( 0 );
}
@ -792,12 +792,12 @@ static int ssl_write_use_srtp_ext( mbedtls_ssl_context *ssl,
*/
MBEDTLS_SSL_CHK_BUF_PTR( p, end, ext_len + 4 );
*p++ = MBEDTLS_CHAR_1( MBEDTLS_TLS_EXT_USE_SRTP );
*p++ = MBEDTLS_CHAR_0( MBEDTLS_TLS_EXT_USE_SRTP );
*p++ = MBEDTLS_BYTE_1( MBEDTLS_TLS_EXT_USE_SRTP );
*p++ = MBEDTLS_BYTE_0( MBEDTLS_TLS_EXT_USE_SRTP );
*p++ = MBEDTLS_CHAR_1( ext_len & 0xFF00 );
*p++ = MBEDTLS_CHAR_0( ext_len );
*p++ = MBEDTLS_BYTE_1( ext_len & 0xFF00 );
*p++ = MBEDTLS_BYTE_0( ext_len );
/* protection profile length: 2*(ssl->conf->dtls_srtp_profile_list_len) */
/* micro-optimization:
@ -808,7 +808,7 @@ static int ssl_write_use_srtp_ext( mbedtls_ssl_context *ssl,
* >> 8 ) & 0xFF );
*/
*p++ = 0;
*p++ = MBEDTLS_CHAR_0( 2 * ssl->conf->dtls_srtp_profile_list_len );
*p++ = MBEDTLS_BYTE_0( 2 * ssl->conf->dtls_srtp_profile_list_len );
for( protection_profiles_index=0;
protection_profiles_index < ssl->conf->dtls_srtp_profile_list_len;
@ -1417,8 +1417,8 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl )
{
/* No need to check for space here, because the extension
* writing functions already took care of that. */
*p++ = MBEDTLS_CHAR_1( ext_len );
*p++ = MBEDTLS_CHAR_0( ext_len );
*p++ = MBEDTLS_BYTE_1( ext_len );
*p++ = MBEDTLS_BYTE_0( ext_len );
p += ext_len;
}

View File

@ -454,15 +454,15 @@ static void ssl_extract_add_data_from_record( unsigned char* add_data,
*cur = rec->cid_len;
cur++;
cur[0] = MBEDTLS_CHAR_1( rec->data_len );
cur[1] = MBEDTLS_CHAR_0( rec->data_len );
cur[0] = MBEDTLS_BYTE_1( rec->data_len );
cur[1] = MBEDTLS_BYTE_0( rec->data_len );
cur += 2;
}
else
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
{
cur[0] = MBEDTLS_CHAR_1( rec->data_len );
cur[1] = MBEDTLS_CHAR_0( rec->data_len );
cur[0] = MBEDTLS_BYTE_1( rec->data_len );
cur[1] = MBEDTLS_BYTE_0( rec->data_len );
cur += 2;
}
@ -2759,8 +2759,8 @@ int mbedtls_ssl_write_handshake_msg( mbedtls_ssl_context *ssl )
/* Write message_seq and update it, except for HelloRequest */
if( hs_type != MBEDTLS_SSL_HS_HELLO_REQUEST )
{
ssl->out_msg[4] = MBEDTLS_CHAR_1( ssl->handshake->out_msg_seq );
ssl->out_msg[5] = MBEDTLS_CHAR_0( ssl->handshake->out_msg_seq );
ssl->out_msg[4] = MBEDTLS_BYTE_1( ssl->handshake->out_msg_seq );
ssl->out_msg[5] = MBEDTLS_BYTE_0( ssl->handshake->out_msg_seq );
++( ssl->handshake->out_msg_seq );
}
else

View File

@ -2335,11 +2335,11 @@ static void ssl_write_cid_ext( mbedtls_ssl_context *ssl,
* } ConnectionId;
*/
*p++ = MBEDTLS_CHAR_1( MBEDTLS_TLS_EXT_CID );
*p++ = MBEDTLS_CHAR_0( MBEDTLS_TLS_EXT_CID );
*p++ = MBEDTLS_BYTE_1( MBEDTLS_TLS_EXT_CID );
*p++ = MBEDTLS_BYTE_0( MBEDTLS_TLS_EXT_CID );
ext_len = (size_t) ssl->own_cid_len + 1;
*p++ = MBEDTLS_CHAR_1( ext_len );
*p++ = MBEDTLS_CHAR_0( ext_len );
*p++ = MBEDTLS_BYTE_1( ext_len );
*p++ = MBEDTLS_BYTE_0( ext_len );
*p++ = (uint8_t) ssl->own_cid_len;
memcpy( p, ssl->own_cid, ssl->own_cid_len );
@ -2381,8 +2381,8 @@ static void ssl_write_encrypt_then_mac_ext( mbedtls_ssl_context *ssl,
MBEDTLS_SSL_DEBUG_MSG( 3, ( "server hello, adding encrypt then mac extension" ) );
*p++ = MBEDTLS_CHAR_1( MBEDTLS_TLS_EXT_ENCRYPT_THEN_MAC );
*p++ = MBEDTLS_CHAR_0( MBEDTLS_TLS_EXT_ENCRYPT_THEN_MAC );
*p++ = MBEDTLS_BYTE_1( MBEDTLS_TLS_EXT_ENCRYPT_THEN_MAC );
*p++ = MBEDTLS_BYTE_0( MBEDTLS_TLS_EXT_ENCRYPT_THEN_MAC );
*p++ = 0x00;
*p++ = 0x00;
@ -2408,8 +2408,8 @@ static void ssl_write_extended_ms_ext( mbedtls_ssl_context *ssl,
MBEDTLS_SSL_DEBUG_MSG( 3, ( "server hello, adding extended master secret "
"extension" ) );
*p++ = MBEDTLS_CHAR_1( MBEDTLS_TLS_EXT_EXTENDED_MASTER_SECRET );
*p++ = MBEDTLS_CHAR_0( MBEDTLS_TLS_EXT_EXTENDED_MASTER_SECRET );
*p++ = MBEDTLS_BYTE_1( MBEDTLS_TLS_EXT_EXTENDED_MASTER_SECRET );
*p++ = MBEDTLS_BYTE_0( MBEDTLS_TLS_EXT_EXTENDED_MASTER_SECRET );
*p++ = 0x00;
*p++ = 0x00;
@ -2433,8 +2433,8 @@ static void ssl_write_session_ticket_ext( mbedtls_ssl_context *ssl,
MBEDTLS_SSL_DEBUG_MSG( 3, ( "server hello, adding session ticket extension" ) );
*p++ = MBEDTLS_CHAR_1( MBEDTLS_TLS_EXT_SESSION_TICKET );
*p++ = MBEDTLS_CHAR_0( MBEDTLS_TLS_EXT_SESSION_TICKET );
*p++ = MBEDTLS_BYTE_1( MBEDTLS_TLS_EXT_SESSION_TICKET );
*p++ = MBEDTLS_BYTE_0( MBEDTLS_TLS_EXT_SESSION_TICKET );
*p++ = 0x00;
*p++ = 0x00;
@ -2457,8 +2457,8 @@ static void ssl_write_renegotiation_ext( mbedtls_ssl_context *ssl,
MBEDTLS_SSL_DEBUG_MSG( 3, ( "server hello, secure renegotiation extension" ) );
*p++ = MBEDTLS_CHAR_1( MBEDTLS_TLS_EXT_RENEGOTIATION_INFO );
*p++ = MBEDTLS_CHAR_0( MBEDTLS_TLS_EXT_RENEGOTIATION_INFO );
*p++ = MBEDTLS_BYTE_1( MBEDTLS_TLS_EXT_RENEGOTIATION_INFO );
*p++ = MBEDTLS_BYTE_0( MBEDTLS_TLS_EXT_RENEGOTIATION_INFO );
#if defined(MBEDTLS_SSL_RENEGOTIATION)
if( ssl->renego_status != MBEDTLS_SSL_INITIAL_HANDSHAKE )
@ -2498,8 +2498,8 @@ static void ssl_write_max_fragment_length_ext( mbedtls_ssl_context *ssl,
MBEDTLS_SSL_DEBUG_MSG( 3, ( "server hello, max_fragment_length extension" ) );
*p++ = MBEDTLS_CHAR_1( MBEDTLS_TLS_EXT_MAX_FRAGMENT_LENGTH );
*p++ = MBEDTLS_CHAR_0( MBEDTLS_TLS_EXT_MAX_FRAGMENT_LENGTH );
*p++ = MBEDTLS_BYTE_1( MBEDTLS_TLS_EXT_MAX_FRAGMENT_LENGTH );
*p++ = MBEDTLS_BYTE_0( MBEDTLS_TLS_EXT_MAX_FRAGMENT_LENGTH );
*p++ = 0x00;
*p++ = 1;
@ -2528,8 +2528,8 @@ static void ssl_write_supported_point_formats_ext( mbedtls_ssl_context *ssl,
MBEDTLS_SSL_DEBUG_MSG( 3, ( "server hello, supported_point_formats extension" ) );
*p++ = MBEDTLS_CHAR_1( MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS );
*p++ = MBEDTLS_CHAR_0( MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS );
*p++ = MBEDTLS_BYTE_1( MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS );
*p++ = MBEDTLS_BYTE_0( MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS );
*p++ = 0x00;
*p++ = 2;
@ -2566,8 +2566,8 @@ static void ssl_write_ecjpake_kkpp_ext( mbedtls_ssl_context *ssl,
return;
}
*p++ = MBEDTLS_CHAR_1( MBEDTLS_TLS_EXT_ECJPAKE_KKPP );
*p++ = MBEDTLS_CHAR_0( MBEDTLS_TLS_EXT_ECJPAKE_KKPP );
*p++ = MBEDTLS_BYTE_1( MBEDTLS_TLS_EXT_ECJPAKE_KKPP );
*p++ = MBEDTLS_BYTE_0( MBEDTLS_TLS_EXT_ECJPAKE_KKPP );
ret = mbedtls_ecjpake_write_round_one( &ssl->handshake->ecjpake_ctx,
p + 2, end - p - 2, &kkpp_len,
@ -2578,8 +2578,8 @@ static void ssl_write_ecjpake_kkpp_ext( mbedtls_ssl_context *ssl,
return;
}
*p++ = MBEDTLS_CHAR_1( kkpp_len );
*p++ = MBEDTLS_CHAR_0( kkpp_len );
*p++ = MBEDTLS_BYTE_1( kkpp_len );
*p++ = MBEDTLS_BYTE_0( kkpp_len );
*olen = kkpp_len + 4;
}
@ -2604,18 +2604,18 @@ static void ssl_write_alpn_ext( mbedtls_ssl_context *ssl,
* 6 . 6 protocol name length
* 7 . 7+n protocol name
*/
buf[0] = MBEDTLS_CHAR_1( MBEDTLS_TLS_EXT_ALPN );
buf[1] = MBEDTLS_CHAR_0( MBEDTLS_TLS_EXT_ALPN );
buf[0] = MBEDTLS_BYTE_1( MBEDTLS_TLS_EXT_ALPN );
buf[1] = MBEDTLS_BYTE_0( MBEDTLS_TLS_EXT_ALPN );
*olen = 7 + strlen( ssl->alpn_chosen );
buf[2] = MBEDTLS_CHAR_1( *olen - 4 );
buf[3] = MBEDTLS_CHAR_0( *olen - 4 );
buf[2] = MBEDTLS_BYTE_1( *olen - 4 );
buf[3] = MBEDTLS_BYTE_0( *olen - 4 );
buf[4] = MBEDTLS_CHAR_1( *olen - 6 );
buf[5] = MBEDTLS_CHAR_0( *olen - 6 );
buf[4] = MBEDTLS_BYTE_1( *olen - 6 );
buf[5] = MBEDTLS_BYTE_0( *olen - 6 );
buf[6] = MBEDTLS_CHAR_0( *olen - 7 );
buf[6] = MBEDTLS_BYTE_0( *olen - 7 );
memcpy( buf + 7, ssl->alpn_chosen, *olen - 7 );
}
@ -2660,15 +2660,15 @@ static void ssl_write_use_srtp_ext( mbedtls_ssl_context *ssl,
}
/* extension */
buf[0] = MBEDTLS_CHAR_1( MBEDTLS_TLS_EXT_USE_SRTP );
buf[1] = MBEDTLS_CHAR_0( MBEDTLS_TLS_EXT_USE_SRTP );
buf[0] = MBEDTLS_BYTE_1( MBEDTLS_TLS_EXT_USE_SRTP );
buf[1] = MBEDTLS_BYTE_0( MBEDTLS_TLS_EXT_USE_SRTP );
/*
* total length 5 and mki value: only one profile(2 bytes)
* and length(2 bytes) and srtp_mki )
*/
ext_len = 5 + mki_len;
buf[2] = MBEDTLS_CHAR_1( ext_len );
buf[3] = MBEDTLS_CHAR_0( ext_len );
buf[2] = MBEDTLS_BYTE_1( ext_len );
buf[3] = MBEDTLS_BYTE_0( ext_len );
/* protection profile length: 2 */
buf[4] = 0x00;
@ -2677,8 +2677,8 @@ static void ssl_write_use_srtp_ext( mbedtls_ssl_context *ssl,
ssl->dtls_srtp_info.chosen_dtls_srtp_profile );
if( profile_value != MBEDTLS_TLS_SRTP_UNSET )
{
buf[6] = MBEDTLS_CHAR_1( profile_value );
buf[7] = MBEDTLS_CHAR_0( profile_value );
buf[6] = MBEDTLS_BYTE_1( profile_value );
buf[7] = MBEDTLS_BYTE_0( profile_value );
}
else
{
@ -3026,8 +3026,8 @@ static int ssl_write_server_hello( mbedtls_ssl_context *ssl )
if( ext_len > 0 )
{
*p++ = MBEDTLS_CHAR_1( ext_len );
*p++ = MBEDTLS_CHAR_0( ext_len );
*p++ = MBEDTLS_BYTE_1( ext_len );
*p++ = MBEDTLS_BYTE_0( ext_len );
p += ext_len;
}
@ -4646,13 +4646,13 @@ static int ssl_write_new_session_ticket( mbedtls_ssl_context *ssl )
tlen = 0;
}
ssl->out_msg[4] = MBEDTLS_CHAR_3( lifetime );
ssl->out_msg[5] = MBEDTLS_CHAR_2( lifetime );
ssl->out_msg[6] = MBEDTLS_CHAR_1( lifetime );
ssl->out_msg[7] = MBEDTLS_CHAR_0( lifetime );
ssl->out_msg[4] = MBEDTLS_BYTE_3( lifetime );
ssl->out_msg[5] = MBEDTLS_BYTE_2( lifetime );
ssl->out_msg[6] = MBEDTLS_BYTE_1( lifetime );
ssl->out_msg[7] = MBEDTLS_BYTE_0( lifetime );
ssl->out_msg[8] = MBEDTLS_CHAR_1( tlen );
ssl->out_msg[9] = MBEDTLS_CHAR_0( tlen );
ssl->out_msg[8] = MBEDTLS_BYTE_1( tlen );
ssl->out_msg[9] = MBEDTLS_BYTE_0( tlen );
ssl->out_msglen = 10 + tlen;

View File

@ -5278,8 +5278,8 @@ static unsigned char ssl_serialized_session_header[] = {
MBEDTLS_VERSION_MAJOR,
MBEDTLS_VERSION_MINOR,
MBEDTLS_VERSION_PATCH,
MBEDTLS_CHAR_1( SSL_SERIALIZED_SESSION_CONFIG_BITFLAG ),
MBEDTLS_CHAR_0( SSL_SERIALIZED_SESSION_CONFIG_BITFLAG ),
MBEDTLS_BYTE_1( SSL_SERIALIZED_SESSION_CONFIG_BITFLAG ),
MBEDTLS_BYTE_0( SSL_SERIALIZED_SESSION_CONFIG_BITFLAG ),
};
/*
@ -5360,14 +5360,14 @@ static int ssl_session_save( const mbedtls_ssl_session *session,
{
start = (uint64_t) session->start;
*p++ = MBEDTLS_CHAR_7( start );
*p++ = MBEDTLS_CHAR_6( start );
*p++ = MBEDTLS_CHAR_5( start );
*p++ = MBEDTLS_CHAR_4( start );
*p++ = MBEDTLS_CHAR_3( start );
*p++ = MBEDTLS_CHAR_2( start );
*p++ = MBEDTLS_CHAR_1( start );
*p++ = MBEDTLS_CHAR_0( start );
*p++ = MBEDTLS_BYTE_7( start );
*p++ = MBEDTLS_BYTE_6( start );
*p++ = MBEDTLS_BYTE_5( start );
*p++ = MBEDTLS_BYTE_4( start );
*p++ = MBEDTLS_BYTE_3( start );
*p++ = MBEDTLS_BYTE_2( start );
*p++ = MBEDTLS_BYTE_1( start );
*p++ = MBEDTLS_BYTE_0( start );
}
#endif /* MBEDTLS_HAVE_TIME */
@ -5383,22 +5383,22 @@ static int ssl_session_save( const mbedtls_ssl_session *session,
if( used <= buf_len )
{
*p++ = MBEDTLS_CHAR_1( session->ciphersuite );
*p++ = MBEDTLS_CHAR_0( session->ciphersuite );
*p++ = MBEDTLS_BYTE_1( session->ciphersuite );
*p++ = MBEDTLS_BYTE_0( session->ciphersuite );
*p++ = MBEDTLS_CHAR_0( session->compression );
*p++ = MBEDTLS_BYTE_0( session->compression );
*p++ = MBEDTLS_CHAR_0( session->id_len );
*p++ = MBEDTLS_BYTE_0( session->id_len );
memcpy( p, session->id, 32 );
p += 32;
memcpy( p, session->master, 48 );
p += 48;
*p++ = MBEDTLS_CHAR_3( session->verify_result );
*p++ = MBEDTLS_CHAR_2( session->verify_result );
*p++ = MBEDTLS_CHAR_1( session->verify_result );
*p++ = MBEDTLS_CHAR_0( session->verify_result );
*p++ = MBEDTLS_BYTE_3( session->verify_result );
*p++ = MBEDTLS_BYTE_2( session->verify_result );
*p++ = MBEDTLS_BYTE_1( session->verify_result );
*p++ = MBEDTLS_BYTE_0( session->verify_result );
}
/*
@ -5415,9 +5415,9 @@ static int ssl_session_save( const mbedtls_ssl_session *session,
if( used <= buf_len )
{
*p++ = MBEDTLS_CHAR_2( cert_len );
*p++ = MBEDTLS_CHAR_1( cert_len );
*p++ = MBEDTLS_CHAR_0( cert_len );
*p++ = MBEDTLS_BYTE_2( cert_len );
*p++ = MBEDTLS_BYTE_1( cert_len );
*p++ = MBEDTLS_BYTE_0( cert_len );
if( session->peer_cert != NULL )
{
@ -5458,9 +5458,9 @@ static int ssl_session_save( const mbedtls_ssl_session *session,
if( used <= buf_len )
{
*p++ = MBEDTLS_CHAR_2( session->ticket_len );
*p++ = MBEDTLS_CHAR_1( session->ticket_len );
*p++ = MBEDTLS_CHAR_0( session->ticket_len );
*p++ = MBEDTLS_BYTE_2( session->ticket_len );
*p++ = MBEDTLS_BYTE_1( session->ticket_len );
*p++ = MBEDTLS_BYTE_0( session->ticket_len );
if( session->ticket != NULL )
{
@ -5468,10 +5468,10 @@ static int ssl_session_save( const mbedtls_ssl_session *session,
p += session->ticket_len;
}
*p++ = MBEDTLS_CHAR_3( session->ticket_lifetime );
*p++ = MBEDTLS_CHAR_2( session->ticket_lifetime );
*p++ = MBEDTLS_CHAR_1( session->ticket_lifetime );
*p++ = MBEDTLS_CHAR_0( session->ticket_lifetime );
*p++ = MBEDTLS_BYTE_3( session->ticket_lifetime );
*p++ = MBEDTLS_BYTE_2( session->ticket_lifetime );
*p++ = MBEDTLS_BYTE_1( session->ticket_lifetime );
*p++ = MBEDTLS_BYTE_0( session->ticket_lifetime );
}
#endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */
@ -5496,7 +5496,7 @@ static int ssl_session_save( const mbedtls_ssl_session *session,
used += 1;
if( used <= buf_len )
*p++ = MBEDTLS_CHAR_0( session->encrypt_then_mac );
*p++ = MBEDTLS_BYTE_0( session->encrypt_then_mac );
#endif
/* Done */
@ -6149,11 +6149,11 @@ static unsigned char ssl_serialized_context_header[] = {
MBEDTLS_VERSION_MAJOR,
MBEDTLS_VERSION_MINOR,
MBEDTLS_VERSION_PATCH,
MBEDTLS_CHAR_1( SSL_SERIALIZED_SESSION_CONFIG_BITFLAG ),
MBEDTLS_CHAR_0( SSL_SERIALIZED_SESSION_CONFIG_BITFLAG ),
MBEDTLS_CHAR_2( SSL_SERIALIZED_CONTEXT_CONFIG_BITFLAG ),
MBEDTLS_CHAR_1( SSL_SERIALIZED_CONTEXT_CONFIG_BITFLAG ),
MBEDTLS_CHAR_0( SSL_SERIALIZED_CONTEXT_CONFIG_BITFLAG ),
MBEDTLS_BYTE_1( SSL_SERIALIZED_SESSION_CONFIG_BITFLAG ),
MBEDTLS_BYTE_0( SSL_SERIALIZED_SESSION_CONFIG_BITFLAG ),
MBEDTLS_BYTE_2( SSL_SERIALIZED_CONTEXT_CONFIG_BITFLAG ),
MBEDTLS_BYTE_1( SSL_SERIALIZED_CONTEXT_CONFIG_BITFLAG ),
MBEDTLS_BYTE_0( SSL_SERIALIZED_CONTEXT_CONFIG_BITFLAG ),
};
/*
@ -6294,10 +6294,10 @@ int mbedtls_ssl_context_save( mbedtls_ssl_context *ssl,
used += 4 + session_len;
if( used <= buf_len )
{
*p++ = MBEDTLS_CHAR_3( session_len );
*p++ = MBEDTLS_CHAR_2( session_len );
*p++ = MBEDTLS_CHAR_1( session_len );
*p++ = MBEDTLS_CHAR_0( session_len );
*p++ = MBEDTLS_BYTE_3( session_len );
*p++ = MBEDTLS_BYTE_2( session_len );
*p++ = MBEDTLS_BYTE_1( session_len );
*p++ = MBEDTLS_BYTE_0( session_len );
ret = ssl_session_save( ssl->session, 1,
p, session_len, &session_len );
@ -6339,10 +6339,10 @@ int mbedtls_ssl_context_save( mbedtls_ssl_context *ssl,
used += 4;
if( used <= buf_len )
{
*p++ = MBEDTLS_CHAR_3( ssl->badmac_seen );
*p++ = MBEDTLS_CHAR_2( ssl->badmac_seen );
*p++ = MBEDTLS_CHAR_1( ssl->badmac_seen );
*p++ = MBEDTLS_CHAR_0( ssl->badmac_seen );
*p++ = MBEDTLS_BYTE_3( ssl->badmac_seen );
*p++ = MBEDTLS_BYTE_2( ssl->badmac_seen );
*p++ = MBEDTLS_BYTE_1( ssl->badmac_seen );
*p++ = MBEDTLS_BYTE_0( ssl->badmac_seen );
}
#endif /* MBEDTLS_SSL_DTLS_BADMAC_LIMIT */
@ -6350,23 +6350,23 @@ int mbedtls_ssl_context_save( mbedtls_ssl_context *ssl,
used += 16;
if( used <= buf_len )
{
*p++ = MBEDTLS_CHAR_7( ssl->in_window_top );
*p++ = MBEDTLS_CHAR_6( ssl->in_window_top );
*p++ = MBEDTLS_CHAR_5( ssl->in_window_top );
*p++ = MBEDTLS_CHAR_4( ssl->in_window_top );
*p++ = MBEDTLS_CHAR_3( ssl->in_window_top );
*p++ = MBEDTLS_CHAR_2( ssl->in_window_top );
*p++ = MBEDTLS_CHAR_1( ssl->in_window_top );
*p++ = MBEDTLS_CHAR_0( ssl->in_window_top );
*p++ = MBEDTLS_BYTE_7( ssl->in_window_top );
*p++ = MBEDTLS_BYTE_6( ssl->in_window_top );
*p++ = MBEDTLS_BYTE_5( ssl->in_window_top );
*p++ = MBEDTLS_BYTE_4( ssl->in_window_top );
*p++ = MBEDTLS_BYTE_3( ssl->in_window_top );
*p++ = MBEDTLS_BYTE_2( ssl->in_window_top );
*p++ = MBEDTLS_BYTE_1( ssl->in_window_top );
*p++ = MBEDTLS_BYTE_0( ssl->in_window_top );
*p++ = MBEDTLS_CHAR_7( ssl->in_window );
*p++ = MBEDTLS_CHAR_6( ssl->in_window );
*p++ = MBEDTLS_CHAR_5( ssl->in_window );
*p++ = MBEDTLS_CHAR_4( ssl->in_window );
*p++ = MBEDTLS_CHAR_3( ssl->in_window );
*p++ = MBEDTLS_CHAR_2( ssl->in_window );
*p++ = MBEDTLS_CHAR_1( ssl->in_window );
*p++ = MBEDTLS_CHAR_0( ssl->in_window );
*p++ = MBEDTLS_BYTE_7( ssl->in_window );
*p++ = MBEDTLS_BYTE_6( ssl->in_window );
*p++ = MBEDTLS_BYTE_5( ssl->in_window );
*p++ = MBEDTLS_BYTE_4( ssl->in_window );
*p++ = MBEDTLS_BYTE_3( ssl->in_window );
*p++ = MBEDTLS_BYTE_2( ssl->in_window );
*p++ = MBEDTLS_BYTE_1( ssl->in_window );
*p++ = MBEDTLS_BYTE_0( ssl->in_window );
}
#endif /* MBEDTLS_SSL_DTLS_ANTI_REPLAY */
@ -6389,8 +6389,8 @@ int mbedtls_ssl_context_save( mbedtls_ssl_context *ssl,
used += 2;
if( used <= buf_len )
{
*p++ = MBEDTLS_CHAR_1( ssl->mtu );
*p++ = MBEDTLS_CHAR_0( ssl->mtu );
*p++ = MBEDTLS_BYTE_1( ssl->mtu );
*p++ = MBEDTLS_BYTE_0( ssl->mtu );
}
#endif /* MBEDTLS_SSL_PROTO_DTLS */

View File

@ -112,17 +112,17 @@ static void ssl_tls1_3_hkdf_encode_label(
#endif
*p++ = 0;
*p++ = MBEDTLS_CHAR_0( desired_length );
*p++ = MBEDTLS_BYTE_0( desired_length );
/* Add label incl. prefix */
*p++ = MBEDTLS_CHAR_0( total_label_len );
*p++ = MBEDTLS_BYTE_0( total_label_len );
memcpy( p, tls1_3_label_prefix, sizeof(tls1_3_label_prefix) );
p += sizeof(tls1_3_label_prefix);
memcpy( p, label, llen );
p += llen;
/* Add context value */
*p++ = MBEDTLS_CHAR_0( clen );
*p++ = MBEDTLS_BYTE_0( clen );
if( clen != 0 )
memcpy( p, ctx, clen );