mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 03:45:38 +01:00
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
1bd5d7da82
commit
ad1115a3fd
@ -319,9 +319,9 @@ int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
|
|||||||
if( ++n == 4 )
|
if( ++n == 4 )
|
||||||
{
|
{
|
||||||
n = 0;
|
n = 0;
|
||||||
if( j > 0 ) *p++ = (unsigned char)( x >> 16 );
|
if( j > 0 ) *p++ = MBEDTLS_BYTE_2( x );
|
||||||
if( j > 1 ) *p++ = (unsigned char)( x >> 8 );
|
if( j > 1 ) *p++ = MBEDTLS_BYTE_1( x );
|
||||||
if( j > 2 ) *p++ = (unsigned char)( 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;
|
size_t offset = i * 4U;
|
||||||
|
|
||||||
keystream[offset ] = (unsigned char)( working_state[i] );
|
keystream[offset ] = MBEDTLS_BYTE_0( working_state[i] );
|
||||||
keystream[offset + 1U] = (unsigned char)( working_state[i] >> 8 );
|
keystream[offset + 1U] = MBEDTLS_BYTE_1( working_state[i] );
|
||||||
keystream[offset + 2U] = (unsigned char)( working_state[i] >> 16 );
|
keystream[offset + 2U] = MBEDTLS_BYTE_2( working_state[i] );
|
||||||
keystream[offset + 3U] = (unsigned char)( working_state[i] >> 24 );
|
keystream[offset + 3U] = MBEDTLS_BYTE_3( working_state[i] );
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_platform_zeroize( working_state, sizeof( working_state ) );
|
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
|
/* The lengths of the AAD and ciphertext are processed by
|
||||||
* Poly1305 as the final 128-bit block, encoded as little-endian integers.
|
* Poly1305 as the final 128-bit block, encoded as little-endian integers.
|
||||||
*/
|
*/
|
||||||
len_block[ 0] = (unsigned char)( ctx->aad_len );
|
len_block[ 0] = MBEDTLS_BYTE_0( ctx->aad_len );
|
||||||
len_block[ 1] = (unsigned char)( ctx->aad_len >> 8 );
|
len_block[ 1] = MBEDTLS_BYTE_1( ctx->aad_len );
|
||||||
len_block[ 2] = (unsigned char)( ctx->aad_len >> 16 );
|
len_block[ 2] = MBEDTLS_BYTE_2( ctx->aad_len );
|
||||||
len_block[ 3] = (unsigned char)( ctx->aad_len >> 24 );
|
len_block[ 3] = MBEDTLS_BYTE_3( ctx->aad_len );
|
||||||
len_block[ 4] = (unsigned char)( ctx->aad_len >> 32 );
|
len_block[ 4] = MBEDTLS_BYTE_4( ctx->aad_len );
|
||||||
len_block[ 5] = (unsigned char)( ctx->aad_len >> 40 );
|
len_block[ 5] = MBEDTLS_BYTE_5( ctx->aad_len );
|
||||||
len_block[ 6] = (unsigned char)( ctx->aad_len >> 48 );
|
len_block[ 6] = MBEDTLS_BYTE_6( ctx->aad_len );
|
||||||
len_block[ 7] = (unsigned char)( ctx->aad_len >> 56 );
|
len_block[ 7] = MBEDTLS_BYTE_7( ctx->aad_len );
|
||||||
len_block[ 8] = (unsigned char)( ctx->ciphertext_len );
|
len_block[ 8] = MBEDTLS_BYTE_0( ctx->ciphertext_len );
|
||||||
len_block[ 9] = (unsigned char)( ctx->ciphertext_len >> 8 );
|
len_block[ 9] = MBEDTLS_BYTE_1( ctx->ciphertext_len );
|
||||||
len_block[10] = (unsigned char)( ctx->ciphertext_len >> 16 );
|
len_block[10] = MBEDTLS_BYTE_2( ctx->ciphertext_len );
|
||||||
len_block[11] = (unsigned char)( ctx->ciphertext_len >> 24 );
|
len_block[11] = MBEDTLS_BYTE_3( ctx->ciphertext_len );
|
||||||
len_block[12] = (unsigned char)( ctx->ciphertext_len >> 32 );
|
len_block[12] = MBEDTLS_BYTE_4( ctx->ciphertext_len );
|
||||||
len_block[13] = (unsigned char)( ctx->ciphertext_len >> 40 );
|
len_block[13] = MBEDTLS_BYTE_5( ctx->ciphertext_len );
|
||||||
len_block[14] = (unsigned char)( ctx->ciphertext_len >> 48 );
|
len_block[14] = MBEDTLS_BYTE_6( ctx->ciphertext_len );
|
||||||
len_block[15] = (unsigned char)( ctx->ciphertext_len >> 56 );
|
len_block[15] = MBEDTLS_BYTE_7( ctx->ciphertext_len );
|
||||||
|
|
||||||
ret = mbedtls_poly1305_update( &ctx->poly1305_ctx, len_block, 16U );
|
ret = mbedtls_poly1305_update( &ctx->poly1305_ctx, len_block, 16U );
|
||||||
if( ret != 0 )
|
if( ret != 0 )
|
||||||
|
@ -231,8 +231,8 @@ int mbedtls_dhm_make_params( mbedtls_dhm_context *ctx, int x_size,
|
|||||||
MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary( ( X ), \
|
MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary( ( X ), \
|
||||||
p + 2, \
|
p + 2, \
|
||||||
( n ) ) ); \
|
( n ) ) ); \
|
||||||
*p++ = (unsigned char)( ( n ) >> 8 ); \
|
*p++ = MBEDTLS_BYTE_1( n ); \
|
||||||
*p++ = (unsigned char)( ( n ) ); \
|
*p++ = MBEDTLS_BYTE_0( n ); \
|
||||||
p += ( n ); \
|
p += ( n ); \
|
||||||
} while( 0 )
|
} while( 0 )
|
||||||
|
|
||||||
|
@ -1160,8 +1160,8 @@ int mbedtls_ecp_tls_write_group( const mbedtls_ecp_group *grp, size_t *olen,
|
|||||||
/*
|
/*
|
||||||
* Next two bytes are the namedcurve value
|
* Next two bytes are the namedcurve value
|
||||||
*/
|
*/
|
||||||
buf[0] = curve_info->tls_id >> 8;
|
buf[0] = MBEDTLS_BYTE_1( curve_info->tls_id );
|
||||||
buf[1] = curve_info->tls_id & 0xFF;
|
buf[1] = MBEDTLS_BYTE_0( curve_info->tls_id );
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
@ -330,8 +330,8 @@ int mbedtls_pkcs12_derivation( unsigned char *data, size_t datalen,
|
|||||||
for( i = v; i > 0; i-- )
|
for( i = v; i > 0; i-- )
|
||||||
{
|
{
|
||||||
j = salt_block[i - 1] + hash_block[i - 1] + c;
|
j = salt_block[i - 1] + hash_block[i - 1] + c;
|
||||||
c = (unsigned char) (j >> 8);
|
c = MBEDTLS_BYTE_1( j );
|
||||||
salt_block[i - 1] = j & 0xFF;
|
salt_block[i - 1] = MBEDTLS_BYTE_0( j );
|
||||||
}
|
}
|
||||||
|
|
||||||
// pwd_block += B
|
// pwd_block += B
|
||||||
@ -339,8 +339,8 @@ int mbedtls_pkcs12_derivation( unsigned char *data, size_t datalen,
|
|||||||
for( i = v; i > 0; i-- )
|
for( i = v; i > 0; i-- )
|
||||||
{
|
{
|
||||||
j = pwd_block[i - 1] + hash_block[i - 1] + c;
|
j = pwd_block[i - 1] + hash_block[i - 1] + c;
|
||||||
c = (unsigned char) (j >> 8);
|
c = MBEDTLS_BYTE_1( j );
|
||||||
pwd_block[i - 1] = j & 0xFF;
|
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 */
|
/* a = al + 2**16 ah, b = bl + 2**16 bh */
|
||||||
const uint16_t al = (uint16_t) a;
|
const uint16_t al = (uint16_t) a;
|
||||||
const uint16_t bl = (uint16_t) b;
|
const uint16_t bl = (uint16_t) b;
|
||||||
const uint16_t ah = a >> 16;
|
const uint16_t ah = MBEDTLS_BYTE_2( a );
|
||||||
const uint16_t bh = b >> 16;
|
const uint16_t bh = MBEDTLS_BYTE_2( b );
|
||||||
|
|
||||||
/* ab = al*bl + 2**16 (ah*bl + bl*bh) + 2**32 ah*bh */
|
/* ab = al*bl + 2**16 (ah*bl + bl*bh) + 2**32 ah*bh */
|
||||||
const uint32_t lo = (uint32_t) al * bl;
|
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 );
|
acc3 += ctx->s[3] + (uint32_t) ( d >> 32U );
|
||||||
|
|
||||||
/* Compute MAC (128 least significant bits of the accumulator) */
|
/* Compute MAC (128 least significant bits of the accumulator) */
|
||||||
mac[ 0] = (unsigned char)( acc0 );
|
mac[ 0] = MBEDTLS_BYTE_0( acc0 );
|
||||||
mac[ 1] = (unsigned char)( acc0 >> 8 );
|
mac[ 1] = MBEDTLS_BYTE_1( acc0 );
|
||||||
mac[ 2] = (unsigned char)( acc0 >> 16 );
|
mac[ 2] = MBEDTLS_BYTE_2( acc0 );
|
||||||
mac[ 3] = (unsigned char)( acc0 >> 24 );
|
mac[ 3] = MBEDTLS_BYTE_3( acc0 );
|
||||||
mac[ 4] = (unsigned char)( acc1 );
|
mac[ 4] = MBEDTLS_BYTE_0( acc1 );
|
||||||
mac[ 5] = (unsigned char)( acc1 >> 8 );
|
mac[ 5] = MBEDTLS_BYTE_1( acc1 );
|
||||||
mac[ 6] = (unsigned char)( acc1 >> 16 );
|
mac[ 6] = MBEDTLS_BYTE_2( acc1 );
|
||||||
mac[ 7] = (unsigned char)( acc1 >> 24 );
|
mac[ 7] = MBEDTLS_BYTE_3( acc1 );
|
||||||
mac[ 8] = (unsigned char)( acc2 );
|
mac[ 8] = MBEDTLS_BYTE_0( acc2 );
|
||||||
mac[ 9] = (unsigned char)( acc2 >> 8 );
|
mac[ 9] = MBEDTLS_BYTE_1( acc2 );
|
||||||
mac[10] = (unsigned char)( acc2 >> 16 );
|
mac[10] = MBEDTLS_BYTE_2( acc2 );
|
||||||
mac[11] = (unsigned char)( acc2 >> 24 );
|
mac[11] = MBEDTLS_BYTE_3( acc2 );
|
||||||
mac[12] = (unsigned char)( acc3 );
|
mac[12] = MBEDTLS_BYTE_0( acc3 );
|
||||||
mac[13] = (unsigned char)( acc3 >> 8 );
|
mac[13] = MBEDTLS_BYTE_1( acc3 );
|
||||||
mac[14] = (unsigned char)( acc3 >> 16 );
|
mac[14] = MBEDTLS_BYTE_2( acc3 );
|
||||||
mac[15] = (unsigned char)( acc3 >> 24 );
|
mac[15] = MBEDTLS_BYTE_3( acc3 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void mbedtls_poly1305_init( mbedtls_poly1305_context *ctx )
|
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++ )
|
grp_id++ )
|
||||||
{
|
{
|
||||||
info = mbedtls_ecp_curve_info_from_grp_id( *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++] = MBEDTLS_BYTE_1( info->tls_id );
|
||||||
elliptic_curve_list[elliptic_curve_len++] = info->tls_id & 0xFF;
|
elliptic_curve_list[elliptic_curve_len++] = MBEDTLS_BYTE_0( info->tls_id );
|
||||||
}
|
}
|
||||||
|
|
||||||
*p++ = MBEDTLS_BYTE_1( MBEDTLS_TLS_EXT_SUPPORTED_ELLIPTIC_CURVES );
|
*p++ = MBEDTLS_BYTE_1( MBEDTLS_TLS_EXT_SUPPORTED_ELLIPTIC_CURVES );
|
||||||
@ -889,10 +889,10 @@ static int ssl_generate_random( mbedtls_ssl_context *ssl )
|
|||||||
|
|
||||||
#if defined(MBEDTLS_HAVE_TIME)
|
#if defined(MBEDTLS_HAVE_TIME)
|
||||||
t = mbedtls_time( NULL );
|
t = mbedtls_time( NULL );
|
||||||
*p++ = (unsigned char)( t >> 24 );
|
*p++ = MBEDTLS_BYTE_3( t );
|
||||||
*p++ = (unsigned char)( t >> 16 );
|
*p++ = MBEDTLS_BYTE_2( t );
|
||||||
*p++ = (unsigned char)( t >> 8 );
|
*p++ = MBEDTLS_BYTE_1( t );
|
||||||
*p++ = (unsigned char)( t );
|
*p++ = MBEDTLS_BYTE_0( t );
|
||||||
|
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, current time: %" MBEDTLS_PRINTF_LONGLONG,
|
MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, current time: %" MBEDTLS_PRINTF_LONGLONG,
|
||||||
(long long) t ) );
|
(long long) t ) );
|
||||||
@ -1182,8 +1182,8 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl )
|
|||||||
MBEDTLS_SSL_CHK_BUF_PTR( p, end, 2 );
|
MBEDTLS_SSL_CHK_BUF_PTR( p, end, 2 );
|
||||||
|
|
||||||
n++;
|
n++;
|
||||||
*p++ = (unsigned char)( ciphersuites[i] >> 8 );
|
*p++ = MBEDTLS_BYTE_1( ciphersuites[i] );
|
||||||
*p++ = (unsigned char)( ciphersuites[i] );
|
*p++ = MBEDTLS_BYTE_0( ciphersuites[i] );
|
||||||
}
|
}
|
||||||
|
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 3,
|
MBEDTLS_SSL_DEBUG_MSG( 3,
|
||||||
@ -1198,8 +1198,8 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl )
|
|||||||
{
|
{
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "adding EMPTY_RENEGOTIATION_INFO_SCSV" ) );
|
MBEDTLS_SSL_DEBUG_MSG( 3, ( "adding EMPTY_RENEGOTIATION_INFO_SCSV" ) );
|
||||||
MBEDTLS_SSL_CHK_BUF_PTR( p, end, 2 );
|
MBEDTLS_SSL_CHK_BUF_PTR( p, end, 2 );
|
||||||
*p++ = (unsigned char)( MBEDTLS_SSL_EMPTY_RENEGOTIATION_INFO >> 8 );
|
*p++ = MBEDTLS_BYTE_1( MBEDTLS_SSL_EMPTY_RENEGOTIATION_INFO );
|
||||||
*p++ = (unsigned char)( MBEDTLS_SSL_EMPTY_RENEGOTIATION_INFO );
|
*p++ = MBEDTLS_BYTE_0( MBEDTLS_SSL_EMPTY_RENEGOTIATION_INFO );
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2897,8 +2897,8 @@ static int ssl_write_encrypted_pms( mbedtls_ssl_context *ssl,
|
|||||||
defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
||||||
if( len_bytes == 2 )
|
if( len_bytes == 2 )
|
||||||
{
|
{
|
||||||
ssl->out_msg[offset+0] = (unsigned char)( *olen >> 8 );
|
ssl->out_msg[offset+0] = MBEDTLS_BYTE_1( *olen );
|
||||||
ssl->out_msg[offset+1] = (unsigned char)( *olen );
|
ssl->out_msg[offset+1] = MBEDTLS_BYTE_0( *olen );
|
||||||
*olen += 2;
|
*olen += 2;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -3682,8 +3682,8 @@ static int ssl_write_client_key_exchange( mbedtls_ssl_context *ssl )
|
|||||||
*/
|
*/
|
||||||
content_len = ssl->handshake->dhm_ctx.len;
|
content_len = ssl->handshake->dhm_ctx.len;
|
||||||
|
|
||||||
ssl->out_msg[4] = (unsigned char)( content_len >> 8 );
|
ssl->out_msg[4] = MBEDTLS_BYTE_1( content_len );
|
||||||
ssl->out_msg[5] = (unsigned char)( content_len );
|
ssl->out_msg[5] = MBEDTLS_BYTE_0( content_len );
|
||||||
header_len = 6;
|
header_len = 6;
|
||||||
|
|
||||||
ret = mbedtls_dhm_make_public( &ssl->handshake->dhm_ctx,
|
ret = mbedtls_dhm_make_public( &ssl->handshake->dhm_ctx,
|
||||||
@ -3898,8 +3898,8 @@ ecdh_calc_secret:
|
|||||||
return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL );
|
return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL );
|
||||||
}
|
}
|
||||||
|
|
||||||
ssl->out_msg[header_len++] = (unsigned char)( content_len >> 8 );
|
ssl->out_msg[header_len++] = MBEDTLS_BYTE_1( content_len );
|
||||||
ssl->out_msg[header_len++] = (unsigned char)( content_len );
|
ssl->out_msg[header_len++] = MBEDTLS_BYTE_0( content_len );
|
||||||
|
|
||||||
memcpy( ssl->out_msg + header_len,
|
memcpy( ssl->out_msg + header_len,
|
||||||
ssl->conf->psk_identity,
|
ssl->conf->psk_identity,
|
||||||
@ -3950,8 +3950,8 @@ ecdh_calc_secret:
|
|||||||
return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL );
|
return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL );
|
||||||
}
|
}
|
||||||
|
|
||||||
ssl->out_msg[header_len++] = (unsigned char)( content_len >> 8 );
|
ssl->out_msg[header_len++] = MBEDTLS_BYTE_1( content_len );
|
||||||
ssl->out_msg[header_len++] = (unsigned char)( content_len );
|
ssl->out_msg[header_len++] = MBEDTLS_BYTE_0( content_len );
|
||||||
|
|
||||||
ret = mbedtls_dhm_make_public( &ssl->handshake->dhm_ctx,
|
ret = mbedtls_dhm_make_public( &ssl->handshake->dhm_ctx,
|
||||||
(int) mbedtls_mpi_size( &ssl->handshake->dhm_ctx.P ),
|
(int) mbedtls_mpi_size( &ssl->handshake->dhm_ctx.P ),
|
||||||
@ -4257,8 +4257,8 @@ sign:
|
|||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
ssl->out_msg[4 + offset] = (unsigned char)( n >> 8 );
|
ssl->out_msg[4 + offset] = MBEDTLS_BYTE_1( n );
|
||||||
ssl->out_msg[5 + offset] = (unsigned char)( n );
|
ssl->out_msg[5 + offset] = MBEDTLS_BYTE_0( n );
|
||||||
|
|
||||||
ssl->out_msglen = 6 + n + offset;
|
ssl->out_msglen = 6 + n + offset;
|
||||||
ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE;
|
ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE;
|
||||||
|
@ -166,10 +166,10 @@ int mbedtls_ssl_cookie_write( void *p_ctx,
|
|||||||
t = ctx->serial++;
|
t = ctx->serial++;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
(*p)[0] = (unsigned char)( t >> 24 );
|
(*p)[0] = MBEDTLS_BYTE_3( t );
|
||||||
(*p)[1] = (unsigned char)( t >> 16 );
|
(*p)[1] = MBEDTLS_BYTE_2( t );
|
||||||
(*p)[2] = (unsigned char)( t >> 8 );
|
(*p)[2] = MBEDTLS_BYTE_1( t );
|
||||||
(*p)[3] = (unsigned char)( t );
|
(*p)[3] = MBEDTLS_BYTE_0( t );
|
||||||
*p += 4;
|
*p += 4;
|
||||||
|
|
||||||
#if defined(MBEDTLS_THREADING_C)
|
#if defined(MBEDTLS_THREADING_C)
|
||||||
|
@ -2729,9 +2729,9 @@ int mbedtls_ssl_write_handshake_msg( mbedtls_ssl_context *ssl )
|
|||||||
*/
|
*/
|
||||||
if( ssl->out_msgtype == MBEDTLS_SSL_MSG_HANDSHAKE )
|
if( ssl->out_msgtype == MBEDTLS_SSL_MSG_HANDSHAKE )
|
||||||
{
|
{
|
||||||
ssl->out_msg[1] = (unsigned char)( hs_len >> 16 );
|
ssl->out_msg[1] = MBEDTLS_BYTE_2( hs_len );
|
||||||
ssl->out_msg[2] = (unsigned char)( hs_len >> 8 );
|
ssl->out_msg[2] = MBEDTLS_BYTE_1( hs_len );
|
||||||
ssl->out_msg[3] = (unsigned char)( hs_len );
|
ssl->out_msg[3] = MBEDTLS_BYTE_0( hs_len );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* DTLS has additional fields in the Handshake layer,
|
* DTLS has additional fields in the Handshake layer,
|
||||||
@ -2874,8 +2874,8 @@ int mbedtls_ssl_write_record( mbedtls_ssl_context *ssl, uint8_t force_flush )
|
|||||||
ssl->conf->transport, ssl->out_hdr + 1 );
|
ssl->conf->transport, ssl->out_hdr + 1 );
|
||||||
|
|
||||||
memcpy( ssl->out_ctr, ssl->cur_out_ctr, 8 );
|
memcpy( ssl->out_ctr, ssl->cur_out_ctr, 8 );
|
||||||
ssl->out_len[0] = (unsigned char)( len >> 8 );
|
ssl->out_len[0] = MBEDTLS_BYTE_1( len );
|
||||||
ssl->out_len[1] = (unsigned char)( len );
|
ssl->out_len[1] = MBEDTLS_BYTE_0( len );
|
||||||
|
|
||||||
if( ssl->transform_out != NULL )
|
if( ssl->transform_out != NULL )
|
||||||
{
|
{
|
||||||
@ -2915,8 +2915,8 @@ int mbedtls_ssl_write_record( mbedtls_ssl_context *ssl, uint8_t force_flush )
|
|||||||
memcpy( ssl->out_cid, rec.cid, rec.cid_len );
|
memcpy( ssl->out_cid, rec.cid, rec.cid_len );
|
||||||
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
|
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
|
||||||
ssl->out_msglen = len = rec.data_len;
|
ssl->out_msglen = len = rec.data_len;
|
||||||
ssl->out_len[0] = (unsigned char)( rec.data_len >> 8 );
|
ssl->out_len[0] = MBEDTLS_BYTE_1( rec.data_len );
|
||||||
ssl->out_len[1] = (unsigned char)( rec.data_len );
|
ssl->out_len[1] = MBEDTLS_BYTE_0( rec.data_len );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected_record_size = len + mbedtls_ssl_out_hdr_len( ssl );
|
protected_record_size = len + mbedtls_ssl_out_hdr_len( ssl );
|
||||||
@ -3488,12 +3488,12 @@ static int ssl_check_dtls_clihlo_cookie(
|
|||||||
/* Go back and fill length fields */
|
/* Go back and fill length fields */
|
||||||
obuf[27] = (unsigned char)( *olen - 28 );
|
obuf[27] = (unsigned char)( *olen - 28 );
|
||||||
|
|
||||||
obuf[14] = obuf[22] = (unsigned char)( ( *olen - 25 ) >> 16 );
|
obuf[14] = obuf[22] = MBEDTLS_BYTE_2( *olen - 25 );
|
||||||
obuf[15] = obuf[23] = (unsigned char)( ( *olen - 25 ) >> 8 );
|
obuf[15] = obuf[23] = MBEDTLS_BYTE_1( *olen - 25 );
|
||||||
obuf[16] = obuf[24] = (unsigned char)( ( *olen - 25 ) );
|
obuf[16] = obuf[24] = MBEDTLS_BYTE_0( *olen - 25 );
|
||||||
|
|
||||||
obuf[11] = (unsigned char)( ( *olen - 13 ) >> 8 );
|
obuf[11] = MBEDTLS_BYTE_1( *olen - 13 );
|
||||||
obuf[12] = (unsigned char)( ( *olen - 13 ) );
|
obuf[12] = MBEDTLS_BYTE_0( *olen - 13 );
|
||||||
|
|
||||||
return( MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED );
|
return( MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED );
|
||||||
}
|
}
|
||||||
@ -4891,8 +4891,8 @@ static int ssl_get_next_record( mbedtls_ssl_context *ssl )
|
|||||||
ssl->in_hdr[0] = rec.type;
|
ssl->in_hdr[0] = rec.type;
|
||||||
ssl->in_msg = rec.buf + rec.data_offset;
|
ssl->in_msg = rec.buf + rec.data_offset;
|
||||||
ssl->in_msglen = rec.data_len;
|
ssl->in_msglen = rec.data_len;
|
||||||
ssl->in_len[0] = (unsigned char)( rec.data_len >> 8 );
|
ssl->in_len[0] = MBEDTLS_BYTE_1( rec.data_len );
|
||||||
ssl->in_len[1] = (unsigned char)( rec.data_len );
|
ssl->in_len[1] = MBEDTLS_BYTE_0( rec.data_len );
|
||||||
|
|
||||||
#if defined(MBEDTLS_ZLIB_SUPPORT)
|
#if defined(MBEDTLS_ZLIB_SUPPORT)
|
||||||
if( ssl->transform_in != NULL &&
|
if( ssl->transform_in != NULL &&
|
||||||
|
@ -2861,10 +2861,10 @@ static int ssl_write_server_hello( mbedtls_ssl_context *ssl )
|
|||||||
|
|
||||||
#if defined(MBEDTLS_HAVE_TIME)
|
#if defined(MBEDTLS_HAVE_TIME)
|
||||||
t = mbedtls_time( NULL );
|
t = mbedtls_time( NULL );
|
||||||
*p++ = (unsigned char)( t >> 24 );
|
*p++ = MBEDTLS_BYTE_3( t );
|
||||||
*p++ = (unsigned char)( t >> 16 );
|
*p++ = MBEDTLS_BYTE_2( t );
|
||||||
*p++ = (unsigned char)( t >> 8 );
|
*p++ = MBEDTLS_BYTE_1( t );
|
||||||
*p++ = (unsigned char)( t );
|
*p++ = MBEDTLS_BYTE_0( t );
|
||||||
|
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "server hello, current time: %" MBEDTLS_PRINTF_LONGLONG,
|
MBEDTLS_SSL_DEBUG_MSG( 3, ( "server hello, current time: %" MBEDTLS_PRINTF_LONGLONG,
|
||||||
(long long) t ) );
|
(long long) t ) );
|
||||||
@ -2945,9 +2945,9 @@ static int ssl_write_server_hello( mbedtls_ssl_context *ssl )
|
|||||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "%s session has been resumed",
|
MBEDTLS_SSL_DEBUG_MSG( 3, ( "%s session has been resumed",
|
||||||
ssl->handshake->resume ? "a" : "no" ) );
|
ssl->handshake->resume ? "a" : "no" ) );
|
||||||
|
|
||||||
*p++ = (unsigned char)( ssl->session_negotiate->ciphersuite >> 8 );
|
*p++ = MBEDTLS_BYTE_1( ssl->session_negotiate->ciphersuite );
|
||||||
*p++ = (unsigned char)( ssl->session_negotiate->ciphersuite );
|
*p++ = MBEDTLS_BYTE_0( ssl->session_negotiate->ciphersuite );
|
||||||
*p++ = (unsigned char)( ssl->session_negotiate->compression );
|
*p++ = MBEDTLS_BYTE_0( ssl->session_negotiate->compression );
|
||||||
|
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "server hello, chosen ciphersuite: %s",
|
MBEDTLS_SSL_DEBUG_MSG( 3, ( "server hello, chosen ciphersuite: %s",
|
||||||
mbedtls_ssl_get_ciphersuite_name( ssl->session_negotiate->ciphersuite ) ) );
|
mbedtls_ssl_get_ciphersuite_name( ssl->session_negotiate->ciphersuite ) ) );
|
||||||
@ -3167,8 +3167,8 @@ static int ssl_write_certificate_request( mbedtls_ssl_context *ssl )
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
p[0] = (unsigned char)( sa_len >> 8 );
|
p[0] = MBEDTLS_BYTE_1( sa_len );
|
||||||
p[1] = (unsigned char)( sa_len );
|
p[1] = MBEDTLS_BYTE_0( sa_len );
|
||||||
sa_len += 2;
|
sa_len += 2;
|
||||||
p += sa_len;
|
p += sa_len;
|
||||||
}
|
}
|
||||||
@ -3208,8 +3208,8 @@ static int ssl_write_certificate_request( mbedtls_ssl_context *ssl )
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
*p++ = (unsigned char)( dn_size >> 8 );
|
*p++ = MBEDTLS_BYTE_1( dn_size );
|
||||||
*p++ = (unsigned char)( dn_size );
|
*p++ = MBEDTLS_BYTE_0( dn_size );
|
||||||
memcpy( p, crt->subject_raw.p, dn_size );
|
memcpy( p, crt->subject_raw.p, dn_size );
|
||||||
p += dn_size;
|
p += dn_size;
|
||||||
|
|
||||||
@ -3223,8 +3223,8 @@ static int ssl_write_certificate_request( mbedtls_ssl_context *ssl )
|
|||||||
ssl->out_msglen = p - buf;
|
ssl->out_msglen = p - buf;
|
||||||
ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE;
|
ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE;
|
||||||
ssl->out_msg[0] = MBEDTLS_SSL_HS_CERTIFICATE_REQUEST;
|
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[4 + ct_len + sa_len] = MBEDTLS_BYTE_1( total_dn_size );
|
||||||
ssl->out_msg[5 + ct_len + sa_len] = (unsigned char)( total_dn_size );
|
ssl->out_msg[5 + ct_len + sa_len] = MBEDTLS_BYTE_0( total_dn_size );
|
||||||
|
|
||||||
ret = mbedtls_ssl_write_handshake_msg( ssl );
|
ret = mbedtls_ssl_write_handshake_msg( ssl );
|
||||||
|
|
||||||
@ -3722,8 +3722,8 @@ static int ssl_write_server_key_exchange( mbedtls_ssl_context *ssl )
|
|||||||
#if defined(MBEDTLS_KEY_EXCHANGE_WITH_SERVER_SIGNATURE_ENABLED)
|
#if defined(MBEDTLS_KEY_EXCHANGE_WITH_SERVER_SIGNATURE_ENABLED)
|
||||||
if( signature_len != 0 )
|
if( signature_len != 0 )
|
||||||
{
|
{
|
||||||
ssl->out_msg[ssl->out_msglen++] = (unsigned char)( signature_len >> 8 );
|
ssl->out_msg[ssl->out_msglen++] = MBEDTLS_BYTE_1( signature_len );
|
||||||
ssl->out_msg[ssl->out_msglen++] = (unsigned char)( signature_len );
|
ssl->out_msg[ssl->out_msglen++] = MBEDTLS_BYTE_0( signature_len );
|
||||||
|
|
||||||
MBEDTLS_SSL_DEBUG_BUF( 3, "my signature",
|
MBEDTLS_SSL_DEBUG_BUF( 3, "my signature",
|
||||||
ssl->out_msg + ssl->out_msglen,
|
ssl->out_msg + ssl->out_msglen,
|
||||||
|
@ -1948,8 +1948,8 @@ int mbedtls_ssl_psk_derive_premaster( mbedtls_ssl_context *ssl, mbedtls_key_exch
|
|||||||
if( end - p < 2 )
|
if( end - p < 2 )
|
||||||
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
|
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
|
||||||
|
|
||||||
*(p++) = (unsigned char)( psk_len >> 8 );
|
*(p++) = MBEDTLS_BYTE_1( psk_len );
|
||||||
*(p++) = (unsigned char)( psk_len );
|
*(p++) = MBEDTLS_BYTE_0( psk_len );
|
||||||
|
|
||||||
if( end < p || (size_t)( end - p ) < psk_len )
|
if( end < p || (size_t)( end - p ) < psk_len )
|
||||||
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
|
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
|
||||||
@ -1989,8 +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 );
|
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_dhm_calc_secret", ret );
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
*(p++) = (unsigned char)( len >> 8 );
|
*(p++) = MBEDTLS_BYTE_1( len );
|
||||||
*(p++) = (unsigned char)( len );
|
*(p++) = MBEDTLS_BYTE_0( len );
|
||||||
p += len;
|
p += len;
|
||||||
|
|
||||||
MBEDTLS_SSL_DEBUG_MPI( 3, "DHM: K ", &ssl->handshake->dhm_ctx.K );
|
MBEDTLS_SSL_DEBUG_MPI( 3, "DHM: K ", &ssl->handshake->dhm_ctx.K );
|
||||||
@ -2011,8 +2011,8 @@ int mbedtls_ssl_psk_derive_premaster( mbedtls_ssl_context *ssl, mbedtls_key_exch
|
|||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
*(p++) = (unsigned char)( zlen >> 8 );
|
*(p++) = MBEDTLS_BYTE_1( zlen );
|
||||||
*(p++) = (unsigned char)( zlen );
|
*(p++) = MBEDTLS_BYTE_0( zlen );
|
||||||
p += zlen;
|
p += zlen;
|
||||||
|
|
||||||
MBEDTLS_SSL_DEBUG_ECDH( 3, &ssl->handshake->ecdh_ctx,
|
MBEDTLS_SSL_DEBUG_ECDH( 3, &ssl->handshake->ecdh_ctx,
|
||||||
@ -2029,8 +2029,8 @@ int mbedtls_ssl_psk_derive_premaster( mbedtls_ssl_context *ssl, mbedtls_key_exch
|
|||||||
if( end - p < 2 )
|
if( end - p < 2 )
|
||||||
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
|
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
|
||||||
|
|
||||||
*(p++) = (unsigned char)( psk_len >> 8 );
|
*(p++) = MBEDTLS_BYTE_1( psk_len );
|
||||||
*(p++) = (unsigned char)( psk_len );
|
*(p++) = MBEDTLS_BYTE_0( psk_len );
|
||||||
|
|
||||||
if( end < p || (size_t)( end - p ) < psk_len )
|
if( end < p || (size_t)( end - p ) < psk_len )
|
||||||
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
|
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
|
||||||
@ -2224,17 +2224,17 @@ int mbedtls_ssl_write_certificate( mbedtls_ssl_context *ssl )
|
|||||||
return( MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE );
|
return( MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE );
|
||||||
}
|
}
|
||||||
|
|
||||||
ssl->out_msg[i ] = (unsigned char)( n >> 16 );
|
ssl->out_msg[i ] = MBEDTLS_BYTE_2( n );
|
||||||
ssl->out_msg[i + 1] = (unsigned char)( n >> 8 );
|
ssl->out_msg[i + 1] = MBEDTLS_BYTE_1( n );
|
||||||
ssl->out_msg[i + 2] = (unsigned char)( n );
|
ssl->out_msg[i + 2] = MBEDTLS_BYTE_0( n );
|
||||||
|
|
||||||
i += 3; memcpy( ssl->out_msg + i, crt->raw.p, n );
|
i += 3; memcpy( ssl->out_msg + i, crt->raw.p, n );
|
||||||
i += n; crt = crt->next;
|
i += n; crt = crt->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssl->out_msg[4] = (unsigned char)( ( i - 7 ) >> 16 );
|
ssl->out_msg[4] = MBEDTLS_BYTE_2( i - 7 );
|
||||||
ssl->out_msg[5] = (unsigned char)( ( i - 7 ) >> 8 );
|
ssl->out_msg[5] = MBEDTLS_BYTE_1( i - 7 );
|
||||||
ssl->out_msg[6] = (unsigned char)( ( i - 7 ) );
|
ssl->out_msg[6] = MBEDTLS_BYTE_0( i - 7 );
|
||||||
|
|
||||||
ssl->out_msglen = i;
|
ssl->out_msglen = i;
|
||||||
ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE;
|
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 );
|
return( MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE );
|
||||||
|
|
||||||
c = buf + 5;
|
c = buf + 5;
|
||||||
ku[0] = (unsigned char)( key_usage );
|
ku[0] = MBEDTLS_BYTE_0( key_usage );
|
||||||
ku[1] = (unsigned char)( key_usage >> 8 );
|
ku[1] = MBEDTLS_BYTE_1( key_usage );
|
||||||
ret = mbedtls_asn1_write_named_bitstring( &c, buf, ku, 9 );
|
ret = mbedtls_asn1_write_named_bitstring( &c, buf, ku, 9 );
|
||||||
|
|
||||||
if( ret < 0 )
|
if( ret < 0 )
|
||||||
|
Loading…
Reference in New Issue
Block a user