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:
parent
99edd6c810
commit
fbeb692dd0
13 changed files with 118 additions and 118 deletions
|
@ -319,9 +319,9 @@ int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
|
|||
if( ++n == 4 )
|
||||
{
|
||||
n = 0;
|
||||
if( j > 0 ) *p++ = (unsigned char)( x >> 16 );
|
||||
if( j > 1 ) *p++ = (unsigned char)( x >> 8 );
|
||||
if( j > 2 ) *p++ = (unsigned char)( x );
|
||||
if( j > 0 ) *p++ = MBEDTLS_BYTE_2( x );
|
||||
if( j > 1 ) *p++ = MBEDTLS_BYTE_1( x );
|
||||
if( j > 2 ) *p++ = MBEDTLS_BYTE_0( x );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -164,10 +164,10 @@ static void chacha20_block( const uint32_t initial_state[16],
|
|||
{
|
||||
size_t offset = i * 4U;
|
||||
|
||||
keystream[offset ] = (unsigned char)( working_state[i] );
|
||||
keystream[offset + 1U] = (unsigned char)( working_state[i] >> 8 );
|
||||
keystream[offset + 2U] = (unsigned char)( working_state[i] >> 16 );
|
||||
keystream[offset + 3U] = (unsigned char)( working_state[i] >> 24 );
|
||||
keystream[offset ] = MBEDTLS_BYTE_0( working_state[i] );
|
||||
keystream[offset + 1U] = MBEDTLS_BYTE_1( working_state[i] );
|
||||
keystream[offset + 2U] = MBEDTLS_BYTE_2( working_state[i] );
|
||||
keystream[offset + 3U] = MBEDTLS_BYTE_3( working_state[i] );
|
||||
}
|
||||
|
||||
mbedtls_platform_zeroize( working_state, sizeof( working_state ) );
|
||||
|
|
|
@ -263,22 +263,22 @@ int mbedtls_chachapoly_finish( mbedtls_chachapoly_context *ctx,
|
|||
/* The lengths of the AAD and ciphertext are processed by
|
||||
* Poly1305 as the final 128-bit block, encoded as little-endian integers.
|
||||
*/
|
||||
len_block[ 0] = (unsigned char)( ctx->aad_len );
|
||||
len_block[ 1] = (unsigned char)( ctx->aad_len >> 8 );
|
||||
len_block[ 2] = (unsigned char)( ctx->aad_len >> 16 );
|
||||
len_block[ 3] = (unsigned char)( ctx->aad_len >> 24 );
|
||||
len_block[ 4] = (unsigned char)( ctx->aad_len >> 32 );
|
||||
len_block[ 5] = (unsigned char)( ctx->aad_len >> 40 );
|
||||
len_block[ 6] = (unsigned char)( ctx->aad_len >> 48 );
|
||||
len_block[ 7] = (unsigned char)( ctx->aad_len >> 56 );
|
||||
len_block[ 8] = (unsigned char)( ctx->ciphertext_len );
|
||||
len_block[ 9] = (unsigned char)( ctx->ciphertext_len >> 8 );
|
||||
len_block[10] = (unsigned char)( ctx->ciphertext_len >> 16 );
|
||||
len_block[11] = (unsigned char)( ctx->ciphertext_len >> 24 );
|
||||
len_block[12] = (unsigned char)( ctx->ciphertext_len >> 32 );
|
||||
len_block[13] = (unsigned char)( ctx->ciphertext_len >> 40 );
|
||||
len_block[14] = (unsigned char)( ctx->ciphertext_len >> 48 );
|
||||
len_block[15] = (unsigned char)( ctx->ciphertext_len >> 56 );
|
||||
len_block[ 0] = MBEDTLS_BYTE_0( ctx->aad_len );
|
||||
len_block[ 1] = MBEDTLS_BYTE_1( ctx->aad_len );
|
||||
len_block[ 2] = MBEDTLS_BYTE_2( ctx->aad_len );
|
||||
len_block[ 3] = MBEDTLS_BYTE_3( ctx->aad_len );
|
||||
len_block[ 4] = MBEDTLS_BYTE_4( ctx->aad_len );
|
||||
len_block[ 5] = MBEDTLS_BYTE_5( ctx->aad_len );
|
||||
len_block[ 6] = MBEDTLS_BYTE_6( ctx->aad_len );
|
||||
len_block[ 7] = MBEDTLS_BYTE_7( ctx->aad_len );
|
||||
len_block[ 8] = MBEDTLS_BYTE_0( ctx->ciphertext_len );
|
||||
len_block[ 9] = MBEDTLS_BYTE_1( ctx->ciphertext_len );
|
||||
len_block[10] = MBEDTLS_BYTE_2( ctx->ciphertext_len );
|
||||
len_block[11] = MBEDTLS_BYTE_3( ctx->ciphertext_len );
|
||||
len_block[12] = MBEDTLS_BYTE_4( ctx->ciphertext_len );
|
||||
len_block[13] = MBEDTLS_BYTE_5( ctx->ciphertext_len );
|
||||
len_block[14] = MBEDTLS_BYTE_6( ctx->ciphertext_len );
|
||||
len_block[15] = MBEDTLS_BYTE_7( ctx->ciphertext_len );
|
||||
|
||||
ret = mbedtls_poly1305_update( &ctx->poly1305_ctx, len_block, 16U );
|
||||
if( ret != 0 )
|
||||
|
|
|
@ -270,8 +270,8 @@ int mbedtls_dhm_make_params( mbedtls_dhm_context *ctx, int x_size,
|
|||
MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary( ( X ), \
|
||||
p + 2, \
|
||||
( n ) ) ); \
|
||||
*p++ = (unsigned char)( ( n ) >> 8 ); \
|
||||
*p++ = (unsigned char)( ( n ) ); \
|
||||
*p++ = MBEDTLS_BYTE_1( n ); \
|
||||
*p++ = MBEDTLS_BYTE_0( n ); \
|
||||
p += ( n ); \
|
||||
} while( 0 )
|
||||
|
||||
|
|
|
@ -1012,8 +1012,8 @@ int mbedtls_ecp_tls_write_group( const mbedtls_ecp_group *grp, size_t *olen,
|
|||
/*
|
||||
* Next two bytes are the namedcurve value
|
||||
*/
|
||||
buf[0] = curve_info->tls_id >> 8;
|
||||
buf[1] = curve_info->tls_id & 0xFF;
|
||||
buf[0] = MBEDTLS_BYTE_1( curve_info->tls_id );
|
||||
buf[1] = MBEDTLS_BYTE_0( curve_info->tls_id );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
|
|
@ -285,8 +285,8 @@ int mbedtls_pkcs12_derivation( unsigned char *data, size_t datalen,
|
|||
for( i = v; i > 0; i-- )
|
||||
{
|
||||
j = salt_block[i - 1] + hash_block[i - 1] + c;
|
||||
c = (unsigned char) (j >> 8);
|
||||
salt_block[i - 1] = j & 0xFF;
|
||||
c = MBEDTLS_BYTE_1( j );
|
||||
salt_block[i - 1] = MBEDTLS_BYTE_0( j );
|
||||
}
|
||||
|
||||
// pwd_block += B
|
||||
|
@ -294,8 +294,8 @@ int mbedtls_pkcs12_derivation( unsigned char *data, size_t datalen,
|
|||
for( i = v; i > 0; i-- )
|
||||
{
|
||||
j = pwd_block[i - 1] + hash_block[i - 1] + c;
|
||||
c = (unsigned char) (j >> 8);
|
||||
pwd_block[i - 1] = j & 0xFF;
|
||||
c = MBEDTLS_BYTE_1( j );
|
||||
pwd_block[i - 1] = MBEDTLS_BYTE_0( j );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -62,8 +62,8 @@ static uint64_t mul64( uint32_t a, uint32_t b )
|
|||
/* a = al + 2**16 ah, b = bl + 2**16 bh */
|
||||
const uint16_t al = (uint16_t) a;
|
||||
const uint16_t bl = (uint16_t) b;
|
||||
const uint16_t ah = a >> 16;
|
||||
const uint16_t bh = b >> 16;
|
||||
const uint16_t ah = MBEDTLS_BYTE_2( a );
|
||||
const uint16_t bh = MBEDTLS_BYTE_2( b );
|
||||
|
||||
/* ab = al*bl + 2**16 (ah*bl + bl*bh) + 2**32 ah*bh */
|
||||
const uint32_t lo = (uint32_t) al * bl;
|
||||
|
@ -250,22 +250,22 @@ static void poly1305_compute_mac( const mbedtls_poly1305_context *ctx,
|
|||
acc3 += ctx->s[3] + (uint32_t) ( d >> 32U );
|
||||
|
||||
/* Compute MAC (128 least significant bits of the accumulator) */
|
||||
mac[ 0] = (unsigned char)( acc0 );
|
||||
mac[ 1] = (unsigned char)( acc0 >> 8 );
|
||||
mac[ 2] = (unsigned char)( acc0 >> 16 );
|
||||
mac[ 3] = (unsigned char)( acc0 >> 24 );
|
||||
mac[ 4] = (unsigned char)( acc1 );
|
||||
mac[ 5] = (unsigned char)( acc1 >> 8 );
|
||||
mac[ 6] = (unsigned char)( acc1 >> 16 );
|
||||
mac[ 7] = (unsigned char)( acc1 >> 24 );
|
||||
mac[ 8] = (unsigned char)( acc2 );
|
||||
mac[ 9] = (unsigned char)( acc2 >> 8 );
|
||||
mac[10] = (unsigned char)( acc2 >> 16 );
|
||||
mac[11] = (unsigned char)( acc2 >> 24 );
|
||||
mac[12] = (unsigned char)( acc3 );
|
||||
mac[13] = (unsigned char)( acc3 >> 8 );
|
||||
mac[14] = (unsigned char)( acc3 >> 16 );
|
||||
mac[15] = (unsigned char)( acc3 >> 24 );
|
||||
mac[ 0] = MBEDTLS_BYTE_0( acc0 );
|
||||
mac[ 1] = MBEDTLS_BYTE_1( acc0 );
|
||||
mac[ 2] = MBEDTLS_BYTE_2( acc0 );
|
||||
mac[ 3] = MBEDTLS_BYTE_3( acc0 );
|
||||
mac[ 4] = MBEDTLS_BYTE_0( acc1 );
|
||||
mac[ 5] = MBEDTLS_BYTE_1( acc1 );
|
||||
mac[ 6] = MBEDTLS_BYTE_2( acc1 );
|
||||
mac[ 7] = MBEDTLS_BYTE_3( acc1 );
|
||||
mac[ 8] = MBEDTLS_BYTE_0( acc2 );
|
||||
mac[ 9] = MBEDTLS_BYTE_1( acc2 );
|
||||
mac[10] = MBEDTLS_BYTE_2( acc2 );
|
||||
mac[11] = MBEDTLS_BYTE_3( acc2 );
|
||||
mac[12] = MBEDTLS_BYTE_0( acc3 );
|
||||
mac[13] = MBEDTLS_BYTE_1( acc3 );
|
||||
mac[14] = MBEDTLS_BYTE_2( acc3 );
|
||||
mac[15] = MBEDTLS_BYTE_3( acc3 );
|
||||
}
|
||||
|
||||
void mbedtls_poly1305_init( mbedtls_poly1305_context *ctx )
|
||||
|
|
|
@ -352,8 +352,8 @@ static int ssl_write_supported_elliptic_curves_ext( mbedtls_ssl_context *ssl,
|
|||
grp_id++ )
|
||||
{
|
||||
info = mbedtls_ecp_curve_info_from_grp_id( *grp_id );
|
||||
elliptic_curve_list[elliptic_curve_len++] = info->tls_id >> 8;
|
||||
elliptic_curve_list[elliptic_curve_len++] = info->tls_id & 0xFF;
|
||||
elliptic_curve_list[elliptic_curve_len++] = MBEDTLS_BYTE_1( info->tls_id );
|
||||
elliptic_curve_list[elliptic_curve_len++] = MBEDTLS_BYTE_0( info->tls_id );
|
||||
}
|
||||
|
||||
*p++ = MBEDTLS_BYTE_1( MBEDTLS_TLS_EXT_SUPPORTED_ELLIPTIC_CURVES );
|
||||
|
@ -857,10 +857,10 @@ static int ssl_generate_random( 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, ( "client hello, current time: %" MBEDTLS_PRINTF_LONGLONG,
|
||||
(long long) t ) );
|
||||
|
@ -1143,8 +1143,8 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl )
|
|||
MBEDTLS_SSL_CHK_BUF_PTR( p, end, 2 );
|
||||
|
||||
n++;
|
||||
*p++ = (unsigned char)( ciphersuites[i] >> 8 );
|
||||
*p++ = (unsigned char)( ciphersuites[i] );
|
||||
*p++ = MBEDTLS_BYTE_1( ciphersuites[i] );
|
||||
*p++ = MBEDTLS_BYTE_0( ciphersuites[i] );
|
||||
}
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3,
|
||||
|
@ -1159,8 +1159,8 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl )
|
|||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "adding EMPTY_RENEGOTIATION_INFO_SCSV" ) );
|
||||
MBEDTLS_SSL_CHK_BUF_PTR( p, end, 2 );
|
||||
*p++ = (unsigned char)( MBEDTLS_SSL_EMPTY_RENEGOTIATION_INFO >> 8 );
|
||||
*p++ = (unsigned char)( MBEDTLS_SSL_EMPTY_RENEGOTIATION_INFO );
|
||||
*p++ = MBEDTLS_BYTE_1( MBEDTLS_SSL_EMPTY_RENEGOTIATION_INFO );
|
||||
*p++ = MBEDTLS_BYTE_0( MBEDTLS_SSL_EMPTY_RENEGOTIATION_INFO );
|
||||
n++;
|
||||
}
|
||||
|
||||
|
@ -2745,8 +2745,8 @@ static int ssl_write_encrypted_pms( mbedtls_ssl_context *ssl,
|
|||
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||
if( len_bytes == 2 )
|
||||
{
|
||||
ssl->out_msg[offset+0] = (unsigned char)( *olen >> 8 );
|
||||
ssl->out_msg[offset+1] = (unsigned char)( *olen );
|
||||
ssl->out_msg[offset+0] = MBEDTLS_BYTE_1( *olen );
|
||||
ssl->out_msg[offset+1] = MBEDTLS_BYTE_0( *olen );
|
||||
*olen += 2;
|
||||
}
|
||||
#endif
|
||||
|
@ -3503,8 +3503,8 @@ static int ssl_write_client_key_exchange( mbedtls_ssl_context *ssl )
|
|||
*/
|
||||
content_len = mbedtls_dhm_get_len( &ssl->handshake->dhm_ctx );
|
||||
|
||||
ssl->out_msg[4] = (unsigned char)( content_len >> 8 );
|
||||
ssl->out_msg[5] = (unsigned char)( content_len );
|
||||
ssl->out_msg[4] = MBEDTLS_BYTE_1( content_len );
|
||||
ssl->out_msg[5] = MBEDTLS_BYTE_0( content_len );
|
||||
header_len = 6;
|
||||
|
||||
ret = mbedtls_dhm_make_public( &ssl->handshake->dhm_ctx,
|
||||
|
@ -3719,8 +3719,8 @@ ecdh_calc_secret:
|
|||
return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL );
|
||||
}
|
||||
|
||||
ssl->out_msg[header_len++] = (unsigned char)( content_len >> 8 );
|
||||
ssl->out_msg[header_len++] = (unsigned char)( content_len );
|
||||
ssl->out_msg[header_len++] = MBEDTLS_BYTE_1( content_len );
|
||||
ssl->out_msg[header_len++] = MBEDTLS_BYTE_0( content_len );
|
||||
|
||||
memcpy( ssl->out_msg + header_len,
|
||||
ssl->conf->psk_identity,
|
||||
|
@ -3771,8 +3771,8 @@ ecdh_calc_secret:
|
|||
return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL );
|
||||
}
|
||||
|
||||
ssl->out_msg[header_len++] = (unsigned char)( content_len >> 8 );
|
||||
ssl->out_msg[header_len++] = (unsigned char)( content_len );
|
||||
ssl->out_msg[header_len++] = MBEDTLS_BYTE_1( content_len );
|
||||
ssl->out_msg[header_len++] = MBEDTLS_BYTE_0( content_len );
|
||||
|
||||
ret = mbedtls_dhm_make_public( &ssl->handshake->dhm_ctx,
|
||||
(int) mbedtls_dhm_get_len( &ssl->handshake->dhm_ctx ),
|
||||
|
@ -4054,8 +4054,8 @@ sign:
|
|||
return( ret );
|
||||
}
|
||||
|
||||
ssl->out_msg[4 + offset] = (unsigned char)( n >> 8 );
|
||||
ssl->out_msg[5 + offset] = (unsigned char)( n );
|
||||
ssl->out_msg[4 + offset] = MBEDTLS_BYTE_1( n );
|
||||
ssl->out_msg[5 + offset] = MBEDTLS_BYTE_0( n );
|
||||
|
||||
ssl->out_msglen = 6 + n + offset;
|
||||
ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE;
|
||||
|
|
|
@ -165,10 +165,10 @@ int mbedtls_ssl_cookie_write( void *p_ctx,
|
|||
t = ctx->serial++;
|
||||
#endif
|
||||
|
||||
(*p)[0] = (unsigned char)( t >> 24 );
|
||||
(*p)[1] = (unsigned char)( t >> 16 );
|
||||
(*p)[2] = (unsigned char)( t >> 8 );
|
||||
(*p)[3] = (unsigned char)( t );
|
||||
(*p)[0] = MBEDTLS_BYTE_3( t );
|
||||
(*p)[1] = MBEDTLS_BYTE_2( t );
|
||||
(*p)[2] = MBEDTLS_BYTE_1( t );
|
||||
(*p)[3] = MBEDTLS_BYTE_0( t );
|
||||
*p += 4;
|
||||
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
|
|
|
@ -2451,9 +2451,9 @@ int mbedtls_ssl_write_handshake_msg_ext( mbedtls_ssl_context *ssl,
|
|||
*/
|
||||
if( ssl->out_msgtype == MBEDTLS_SSL_MSG_HANDSHAKE )
|
||||
{
|
||||
ssl->out_msg[1] = (unsigned char)( hs_len >> 16 );
|
||||
ssl->out_msg[2] = (unsigned char)( hs_len >> 8 );
|
||||
ssl->out_msg[3] = (unsigned char)( hs_len );
|
||||
ssl->out_msg[1] = MBEDTLS_BYTE_2( hs_len );
|
||||
ssl->out_msg[2] = MBEDTLS_BYTE_1( hs_len );
|
||||
ssl->out_msg[3] = MBEDTLS_BYTE_0( hs_len );
|
||||
|
||||
/*
|
||||
* DTLS has additional fields in the Handshake layer,
|
||||
|
@ -2566,8 +2566,8 @@ int mbedtls_ssl_write_record( mbedtls_ssl_context *ssl, uint8_t force_flush )
|
|||
ssl->conf->transport, ssl->out_hdr + 1 );
|
||||
|
||||
memcpy( ssl->out_ctr, ssl->cur_out_ctr, 8 );
|
||||
ssl->out_len[0] = (unsigned char)( len >> 8 );
|
||||
ssl->out_len[1] = (unsigned char)( len );
|
||||
ssl->out_len[0] = MBEDTLS_BYTE_1( len );
|
||||
ssl->out_len[1] = MBEDTLS_BYTE_0( len );
|
||||
|
||||
if( ssl->transform_out != NULL )
|
||||
{
|
||||
|
@ -2607,8 +2607,8 @@ int mbedtls_ssl_write_record( mbedtls_ssl_context *ssl, uint8_t force_flush )
|
|||
memcpy( ssl->out_cid, rec.cid, rec.cid_len );
|
||||
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
|
||||
ssl->out_msglen = len = rec.data_len;
|
||||
ssl->out_len[0] = (unsigned char)( rec.data_len >> 8 );
|
||||
ssl->out_len[1] = (unsigned char)( rec.data_len );
|
||||
ssl->out_len[0] = MBEDTLS_BYTE_1( rec.data_len );
|
||||
ssl->out_len[1] = MBEDTLS_BYTE_0( rec.data_len );
|
||||
}
|
||||
|
||||
protected_record_size = len + mbedtls_ssl_out_hdr_len( ssl );
|
||||
|
@ -3180,12 +3180,12 @@ static int ssl_check_dtls_clihlo_cookie(
|
|||
/* Go back and fill length fields */
|
||||
obuf[27] = (unsigned char)( *olen - 28 );
|
||||
|
||||
obuf[14] = obuf[22] = (unsigned char)( ( *olen - 25 ) >> 16 );
|
||||
obuf[15] = obuf[23] = (unsigned char)( ( *olen - 25 ) >> 8 );
|
||||
obuf[16] = obuf[24] = (unsigned char)( ( *olen - 25 ) );
|
||||
obuf[14] = obuf[22] = MBEDTLS_BYTE_2( *olen - 25 );
|
||||
obuf[15] = obuf[23] = MBEDTLS_BYTE_1( *olen - 25 );
|
||||
obuf[16] = obuf[24] = MBEDTLS_BYTE_0( *olen - 25 );
|
||||
|
||||
obuf[11] = (unsigned char)( ( *olen - 13 ) >> 8 );
|
||||
obuf[12] = (unsigned char)( ( *olen - 13 ) );
|
||||
obuf[11] = MBEDTLS_BYTE_1( *olen - 13 );
|
||||
obuf[12] = MBEDTLS_BYTE_0( *olen - 13 );
|
||||
|
||||
return( MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED );
|
||||
}
|
||||
|
@ -4565,8 +4565,8 @@ static int ssl_get_next_record( mbedtls_ssl_context *ssl )
|
|||
ssl->in_hdr[0] = rec.type;
|
||||
ssl->in_msg = rec.buf + rec.data_offset;
|
||||
ssl->in_msglen = rec.data_len;
|
||||
ssl->in_len[0] = (unsigned char)( rec.data_len >> 8 );
|
||||
ssl->in_len[1] = (unsigned char)( rec.data_len );
|
||||
ssl->in_len[0] = MBEDTLS_BYTE_1( rec.data_len );
|
||||
ssl->in_len[1] = MBEDTLS_BYTE_0( rec.data_len );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -1487,8 +1487,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++) = (unsigned char)( psk_len >> 8 );
|
||||
*(p++) = (unsigned char)( psk_len );
|
||||
*(p++) = MBEDTLS_BYTE_1( psk_len );
|
||||
*(p++) = MBEDTLS_BYTE_0( psk_len );
|
||||
|
||||
if( end < p || (size_t)( end - p ) < psk_len )
|
||||
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
|
||||
|
@ -1528,8 +1528,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++) = (unsigned char)( len >> 8 );
|
||||
*(p++) = (unsigned char)( len );
|
||||
*(p++) = MBEDTLS_BYTE_1( len );
|
||||
*(p++) = MBEDTLS_BYTE_0( len );
|
||||
p += len;
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MPI( 3, "DHM: K ", &ssl->handshake->dhm_ctx.K );
|
||||
|
@ -1550,8 +1550,8 @@ int mbedtls_ssl_psk_derive_premaster( mbedtls_ssl_context *ssl, mbedtls_key_exch
|
|||
return( ret );
|
||||
}
|
||||
|
||||
*(p++) = (unsigned char)( zlen >> 8 );
|
||||
*(p++) = (unsigned char)( zlen );
|
||||
*(p++) = MBEDTLS_BYTE_1( zlen );
|
||||
*(p++) = MBEDTLS_BYTE_0( zlen );
|
||||
p += zlen;
|
||||
|
||||
MBEDTLS_SSL_DEBUG_ECDH( 3, &ssl->handshake->ecdh_ctx,
|
||||
|
@ -1568,8 +1568,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++) = (unsigned char)( psk_len >> 8 );
|
||||
*(p++) = (unsigned char)( psk_len );
|
||||
*(p++) = MBEDTLS_BYTE_1( psk_len );
|
||||
*(p++) = MBEDTLS_BYTE_0( psk_len );
|
||||
|
||||
if( end < p || (size_t)( end - p ) < psk_len )
|
||||
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
|
||||
|
@ -1746,17 +1746,17 @@ int mbedtls_ssl_write_certificate( mbedtls_ssl_context *ssl )
|
|||
return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL );
|
||||
}
|
||||
|
||||
ssl->out_msg[i ] = (unsigned char)( n >> 16 );
|
||||
ssl->out_msg[i + 1] = (unsigned char)( n >> 8 );
|
||||
ssl->out_msg[i + 2] = (unsigned char)( n );
|
||||
ssl->out_msg[i ] = MBEDTLS_BYTE_2( n );
|
||||
ssl->out_msg[i + 1] = MBEDTLS_BYTE_1( n );
|
||||
ssl->out_msg[i + 2] = MBEDTLS_BYTE_0( n );
|
||||
|
||||
i += 3; memcpy( ssl->out_msg + i, crt->raw.p, n );
|
||||
i += n; crt = crt->next;
|
||||
}
|
||||
|
||||
ssl->out_msg[4] = (unsigned char)( ( i - 7 ) >> 16 );
|
||||
ssl->out_msg[5] = (unsigned char)( ( i - 7 ) >> 8 );
|
||||
ssl->out_msg[6] = (unsigned char)( ( i - 7 ) );
|
||||
ssl->out_msg[4] = MBEDTLS_BYTE_2( i - 7 );
|
||||
ssl->out_msg[5] = MBEDTLS_BYTE_1( i - 7 );
|
||||
ssl->out_msg[6] = MBEDTLS_BYTE_0( i - 7 );
|
||||
|
||||
ssl->out_msglen = i;
|
||||
ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE;
|
||||
|
|
|
@ -251,8 +251,8 @@ int mbedtls_x509write_crt_set_key_usage( mbedtls_x509write_cert *ctx,
|
|||
return( MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE );
|
||||
|
||||
c = buf + 5;
|
||||
ku[0] = (unsigned char)( key_usage );
|
||||
ku[1] = (unsigned char)( key_usage >> 8 );
|
||||
ku[0] = MBEDTLS_BYTE_0( key_usage );
|
||||
ku[1] = MBEDTLS_BYTE_1( key_usage );
|
||||
ret = mbedtls_asn1_write_named_bitstring( &c, buf, ku, 9 );
|
||||
|
||||
if( ret < 0 )
|
||||
|
|
Loading…
Reference in a new issue