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:
parent
94180e708f
commit
a5cb0d24d4
@ -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;
|
||||
|
@ -180,10 +180,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;
|
||||
|
||||
@ -223,10 +220,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 );
|
||||
|
@ -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++) = 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 );
|
||||
@ -1528,9 +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++) = 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 );
|
||||
}
|
||||
@ -1550,9 +1549,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 );
|
||||
@ -1568,8 +1566,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 );
|
||||
|
Loading…
Reference in New Issue
Block a user