GET macros use a target variable

The GET macros used to write to a macro parameter, but now
they can be used to assign a value to the desired variable
rather than pass it in as an argument and have it modified
in the macro function.

Due to this MBEDTLS_BYTES_TO_U32_LE is the same as
MBEDTLS_GET_UINT32_LE and was there for replaced in the
appropriate files and removed from common.h

Signed-off-by: Joe Subbiani <joe.subbiani@arm.com>
This commit is contained in:
Joe Subbiani 2021-07-07 16:56:29 +01:00
parent 266476da00
commit 9231d5f919
14 changed files with 211 additions and 180 deletions

View File

@ -567,7 +567,7 @@ int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
for( i = 0; i < ( keybits >> 5 ); i++ )
{
MBEDTLS_GET_UINT32_LE( RK[i], key, i << 2 );
RK[i] = MBEDTLS_GET_UINT32_LE( key, i << 2 );
}
switch( ctx->nr )
@ -850,10 +850,10 @@ int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
uint32_t Y[4];
} t;
MBEDTLS_GET_UINT32_LE( t.X[0], input, 0 ); t.X[0] ^= *RK++;
MBEDTLS_GET_UINT32_LE( t.X[1], input, 4 ); t.X[1] ^= *RK++;
MBEDTLS_GET_UINT32_LE( t.X[2], input, 8 ); t.X[2] ^= *RK++;
MBEDTLS_GET_UINT32_LE( t.X[3], input, 12 ); t.X[3] ^= *RK++;
t.X[0] = MBEDTLS_GET_UINT32_LE( input, 0 ); t.X[0] ^= *RK++;
t.X[1] = MBEDTLS_GET_UINT32_LE( input, 4 ); t.X[1] ^= *RK++;
t.X[2] = MBEDTLS_GET_UINT32_LE( input, 8 ); t.X[2] ^= *RK++;
t.X[3] = MBEDTLS_GET_UINT32_LE( input, 12 ); t.X[3] ^= *RK++;
for( i = ( ctx->nr >> 1 ) - 1; i > 0; i-- )
{
@ -923,10 +923,10 @@ int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
uint32_t Y[4];
} t;
MBEDTLS_GET_UINT32_LE( t.X[0], input, 0 ); t.X[0] ^= *RK++;
MBEDTLS_GET_UINT32_LE( t.X[1], input, 4 ); t.X[1] ^= *RK++;
MBEDTLS_GET_UINT32_LE( t.X[2], input, 8 ); t.X[2] ^= *RK++;
MBEDTLS_GET_UINT32_LE( t.X[3], input, 12 ); t.X[3] ^= *RK++;
t.X[0] = MBEDTLS_GET_UINT32_LE( input, 0 ); t.X[0] ^= *RK++;
t.X[1] = MBEDTLS_GET_UINT32_LE( input, 4 ); t.X[1] ^= *RK++;
t.X[2] = MBEDTLS_GET_UINT32_LE( input, 8 ); t.X[2] ^= *RK++;
t.X[3] = MBEDTLS_GET_UINT32_LE( input, 12 ); t.X[3] ^= *RK++;
for( i = ( ctx->nr >> 1 ) - 1; i > 0; i-- )
{

View File

@ -434,21 +434,21 @@ int mbedtls_aria_setkey_enc( mbedtls_aria_context *ctx,
return( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA );
/* Copy key to W0 (and potential remainder to W1) */
MBEDTLS_GET_UINT32_LE( w[0][0], key, 0 );
MBEDTLS_GET_UINT32_LE( w[0][1], key, 4 );
MBEDTLS_GET_UINT32_LE( w[0][2], key, 8 );
MBEDTLS_GET_UINT32_LE( w[0][3], key, 12 );
w[0][0] = MBEDTLS_GET_UINT32_LE( key, 0 );
w[0][1] = MBEDTLS_GET_UINT32_LE( key, 4 );
w[0][2] = MBEDTLS_GET_UINT32_LE( key, 8 );
w[0][3] = MBEDTLS_GET_UINT32_LE( key, 12 );
memset( w[1], 0, 16 );
if( keybits >= 192 )
{
MBEDTLS_GET_UINT32_LE( w[1][0], key, 16 ); // 192 bit key
MBEDTLS_GET_UINT32_LE( w[1][1], key, 20 );
w[1][0] = MBEDTLS_GET_UINT32_LE( key, 16 ); // 192 bit key
w[1][1] = MBEDTLS_GET_UINT32_LE( key, 20 );
}
if( keybits == 256 )
{
MBEDTLS_GET_UINT32_LE( w[1][2], key, 24 ); // 256 bit key
MBEDTLS_GET_UINT32_LE( w[1][3], key, 28 );
w[1][2] = MBEDTLS_GET_UINT32_LE( key, 24 ); // 256 bit key
w[1][3] = MBEDTLS_GET_UINT32_LE( key, 28 );
}
i = ( keybits - 128 ) >> 6; // index: 0, 1, 2
@ -525,10 +525,10 @@ int mbedtls_aria_crypt_ecb( mbedtls_aria_context *ctx,
ARIA_VALIDATE_RET( input != NULL );
ARIA_VALIDATE_RET( output != NULL );
MBEDTLS_GET_UINT32_LE( a, input, 0 );
MBEDTLS_GET_UINT32_LE( b, input, 4 );
MBEDTLS_GET_UINT32_LE( c, input, 8 );
MBEDTLS_GET_UINT32_LE( d, input, 12 );
a = MBEDTLS_GET_UINT32_LE( input, 0 );
b = MBEDTLS_GET_UINT32_LE( input, 4 );
c = MBEDTLS_GET_UINT32_LE( input, 8 );
d = MBEDTLS_GET_UINT32_LE( input, 12 );
i = 0;
while( 1 )

View File

@ -353,8 +353,8 @@ int mbedtls_camellia_setkey_enc( mbedtls_camellia_context *ctx,
* Prepare SIGMA values
*/
for( i = 0; i < 6; i++ ) {
MBEDTLS_GET_UINT32_BE( SIGMA[i][0], SIGMA_CHARS[i], 0 );
MBEDTLS_GET_UINT32_BE( SIGMA[i][1], SIGMA_CHARS[i], 4 );
SIGMA[i][0] = MBEDTLS_GET_UINT32_BE( SIGMA_CHARS[i], 0 );
SIGMA[i][1] = MBEDTLS_GET_UINT32_BE( SIGMA_CHARS[i], 4 );
}
/*
@ -365,7 +365,7 @@ int mbedtls_camellia_setkey_enc( mbedtls_camellia_context *ctx,
/* Store KL, KR */
for( i = 0; i < 8; i++ )
MBEDTLS_GET_UINT32_BE( KC[i], t, i * 4 );
KC[i] = MBEDTLS_GET_UINT32_BE( t, i * 4 );
/* Generate KA */
for( i = 0; i < 4; ++i )
@ -491,10 +491,10 @@ int mbedtls_camellia_crypt_ecb( mbedtls_camellia_context *ctx,
NR = ctx->nr;
RK = ctx->rk;
MBEDTLS_GET_UINT32_BE( X[0], input, 0 );
MBEDTLS_GET_UINT32_BE( X[1], input, 4 );
MBEDTLS_GET_UINT32_BE( X[2], input, 8 );
MBEDTLS_GET_UINT32_BE( X[3], input, 12 );
X[0] = MBEDTLS_GET_UINT32_BE( input, 0 );
X[1] = MBEDTLS_GET_UINT32_BE( input, 4 );
X[2] = MBEDTLS_GET_UINT32_BE( input, 8 );
X[3] = MBEDTLS_GET_UINT32_BE( input, 12 );
X[0] ^= *RK++;
X[1] ^= *RK++;

View File

@ -205,14 +205,14 @@ int mbedtls_chacha20_setkey( mbedtls_chacha20_context *ctx,
ctx->state[3] = 0x6b206574;
/* Set key */
ctx->state[4] = MBEDTLS_BYTES_TO_U32_LE( key, 0 );
ctx->state[5] = MBEDTLS_BYTES_TO_U32_LE( key, 4 );
ctx->state[6] = MBEDTLS_BYTES_TO_U32_LE( key, 8 );
ctx->state[7] = MBEDTLS_BYTES_TO_U32_LE( key, 12 );
ctx->state[8] = MBEDTLS_BYTES_TO_U32_LE( key, 16 );
ctx->state[9] = MBEDTLS_BYTES_TO_U32_LE( key, 20 );
ctx->state[10] = MBEDTLS_BYTES_TO_U32_LE( key, 24 );
ctx->state[11] = MBEDTLS_BYTES_TO_U32_LE( key, 28 );
ctx->state[4] = MBEDTLS_GET_UINT32_LE( key, 0 );
ctx->state[5] = MBEDTLS_GET_UINT32_LE( key, 4 );
ctx->state[6] = MBEDTLS_GET_UINT32_LE( key, 8 );
ctx->state[7] = MBEDTLS_GET_UINT32_LE( key, 12 );
ctx->state[8] = MBEDTLS_GET_UINT32_LE( key, 16 );
ctx->state[9] = MBEDTLS_GET_UINT32_LE( key, 20 );
ctx->state[10] = MBEDTLS_GET_UINT32_LE( key, 24 );
ctx->state[11] = MBEDTLS_GET_UINT32_LE( key, 28 );
return( 0 );
}
@ -228,9 +228,9 @@ int mbedtls_chacha20_starts( mbedtls_chacha20_context* ctx,
ctx->state[12] = counter;
/* Nonce */
ctx->state[13] = MBEDTLS_BYTES_TO_U32_LE( nonce, 0 );
ctx->state[14] = MBEDTLS_BYTES_TO_U32_LE( nonce, 4 );
ctx->state[15] = MBEDTLS_BYTES_TO_U32_LE( nonce, 8 );
ctx->state[13] = MBEDTLS_GET_UINT32_LE( nonce, 0 );
ctx->state[14] = MBEDTLS_GET_UINT32_LE( nonce, 4 );
ctx->state[15] = MBEDTLS_GET_UINT32_LE( nonce, 8 );
mbedtls_platform_zeroize( ctx->keystream8, sizeof( ctx->keystream8 ) );

View File

@ -69,38 +69,45 @@
#define MBEDTLS_BYTE_3( x ) ( (uint8_t) ( ( ( x ) >> 24 ) & 0xff ) )
/**
* 32-bit integer manipulation macros
* 32-bit integer manipulation GET macros (big endian)
*
* \brief Using GET-
* From input data, take the most significant bytes
* and concatonate them as you shift along
* Using PUT-
* Read from a 32 bit integer and store each byte
* in memory, offset by a byte each, resulting in
* each byte being adjacent in memory.
* \brief Use this to assign an unsigned 32 bit integer
* by taking data stored adjacent in memory that
* can be accessed via on offset
* Big Endian is used when wanting to
* transmit the most signifcant bits first
*
* \param n 32 bit integer where data is accessed via
* PUT or stored using GET
* \param data The data used to translate to a 32 bit
* integer
* \param offset the shift in bytes to access the next byte
* of data
*/
#ifndef MBEDTLS_GET_UINT32_BE
#define MBEDTLS_GET_UINT32_BE( data , offset ) \
( \
( (uint32_t) ( data )[( offset ) ] << 24 ) \
| ( (uint32_t) ( data )[( offset ) + 1] << 16 ) \
| ( (uint32_t) ( data )[( offset ) + 2] << 8 ) \
| ( (uint32_t) ( data )[( offset ) + 3] ) \
)
#endif
/**
* 32-bit integer manipulation PUT macros (big endian)
*
* \brief Read from a 32 bit integer and store each byte
* in memory, offset by a specified amount, resulting
* in each byte being adjacent in memory.
* Big Endian is used when wanting to
* transmit the most signifcant bits first
*
* \param n 32 bit integer where data is accessed
* \param b const unsigned char array of data to be
* manipulated
* \param i offset in bytes, In the case of UINT32, i
* would increment by 4 every use assuming
* the data is being stored in the same location
*/
/**
* 32-bit integer manipulation macros (big endian)
*/
#ifndef MBEDTLS_GET_UINT32_BE
#define MBEDTLS_GET_UINT32_BE(n,b,i) \
do { \
(n) = ( (uint32_t) (b)[(i) ] << 24 ) \
| ( (uint32_t) (b)[(i) + 1] << 16 ) \
| ( (uint32_t) (b)[(i) + 2] << 8 ) \
| ( (uint32_t) (b)[(i) + 3] ); \
} while( 0 )
#endif
#ifndef MBEDTLS_PUT_UINT32_BE
#define MBEDTLS_PUT_UINT32_BE(n,b,i) \
do { \
@ -112,18 +119,45 @@
#endif
/**
* 32-bit integer manipulation macros (little endian)
* 32-bit integer manipulation GET macros (little endian)
*
* \brief Use this to assign an unsigned 32 bit integer
* by taking data stored adjacent in memory that
* can be accessed via on offset
* Little Endian is used when wanting to
* transmit the least signifcant bits first
*
* \param data The data used to translate to a 32 bit
* integer
* \param offset the shift in bytes to access the next byte
* of data
*/
#ifndef MBEDTLS_GET_UINT32_LE
#define MBEDTLS_GET_UINT32_LE(n,b,i) \
do { \
(n) = ( (uint32_t) (b)[(i) ] ) \
| ( (uint32_t) (b)[(i) + 1] << 8 ) \
| ( (uint32_t) (b)[(i) + 2] << 16 ) \
| ( (uint32_t) (b)[(i) + 3] << 24 ); \
} while( 0 )
#define MBEDTLS_GET_UINT32_LE( data, offset ) \
( \
( (uint32_t) ( data )[( offset ) ] ) \
| ( (uint32_t) ( data )[( offset ) + 1] << 8 ) \
| ( (uint32_t) ( data )[( offset ) + 2] << 16 ) \
| ( (uint32_t) ( data )[( offset ) + 3] << 24 ) \
)
#endif
/**
* 32-bit integer manipulation PUT macros (little endian)
*
* \brief Read from a 32 bit integer and store each byte
* in memory, offset by a specified amount, resulting
* in each byte being adjacent in memory.
* Little Endian is used when wanting to
* transmit the least signifcant bits first
*
* \param n 32 bit integer where data is accessed
* \param b const unsigned char array of data to be
* manipulated
* \param i offset in bytes, In the case of UINT32, i
* would increment by 4 every use assuming
* the data is being stored in the same location
*/
#ifndef MBEDTLS_PUT_UINT32_LE
#define MBEDTLS_PUT_UINT32_LE(n,b,i) \
do { \
@ -135,46 +169,43 @@
#endif
/**
* 32-bit integer conversion from bytes (little endian)
* 16-bit integer manipulation GET macros (little endian)
*
* \brief Use this to assign an unsigned 16 bit integer
* by taking data stored adjacent in memory that
* can be accessed via on offset
* Little Endian is used when wanting to
* transmit the least signifcant bits first
*
* \param data The data used to translate to a 16 bit
* integer
* \param offset the shit in bytes to access the next byte
* of data
*/
#define MBEDTLS_BYTES_TO_U32_LE( data, offset ) \
( (uint32_t) (data)[offset] \
| (uint32_t) ( (uint32_t) (data)[( offset ) + 1] << 8 ) \
| (uint32_t) ( (uint32_t) (data)[( offset ) + 2] << 16 ) \
| (uint32_t) ( (uint32_t) (data)[( offset ) + 3] << 24 ) \
#ifndef MBEDTLS_GET_UINT16_LE
#define MBEDTLS_GET_UINT16_LE( data, offset ) \
( \
( (uint16_t) ( data )[( offset ) ] ) \
| ( (uint16_t) ( data )[( offset ) + 1] << 8 ) \
)
#endif
/**
* 16-bit integer manipulation macros
* 16-bit integer manipulation PUT macros (little endian)
*
* \brief Using GET-
* From input data, take the most significant bytes
* and concatonate them as you shift along
* Using PUT-
* Read from a 16 bit integer and store each byte
* in memory, offset by a byte each, resulting in
* each byte being adjacent in memory.
* \brief Read from a 16 bit integer and store each byte
* in memory, offset by a specified amount, resulting
* in each byte being adjacent in memory.
* Little Endian is used when wanting to
* transmit the least signifcant bits first
*
* \param n 16 bit integer where data is accessed via
* PUT or stored using GET
* \param n 16 bit integer where data is accessed
* \param b const unsigned char array of data to be
* manipulated
* \param i offset in bytes, In the case of UINT16, i
* would increment by 2 every use assuming
* the data is being stored in the same location
*/
/**
* 16-bit integer manipulation macros (little endian)
*/
#ifndef MBEDTLS_GET_UINT16_LE
#define MBEDTLS_GET_UINT16_LE( n, b, i ) \
{ \
(n) = ( (uint16_t) (b)[(i) ] ) \
| ( (uint16_t) (b)[(i) + 1] << 8 ); \
}
#endif
#ifndef MBEDTLS_PUT_UINT16_LE
#define MBEDTLS_PUT_UINT16_LE( n, b, i ) \
{ \

View File

@ -400,8 +400,8 @@ void mbedtls_des_setkey( uint32_t SK[32], const unsigned char key[MBEDTLS_DES_KE
int i;
uint32_t X, Y, T;
MBEDTLS_GET_UINT32_BE( X, key, 0 );
MBEDTLS_GET_UINT32_BE( Y, key, 4 );
X = MBEDTLS_GET_UINT32_BE( key, 0 );
Y = MBEDTLS_GET_UINT32_BE( key, 4 );
/*
* Permuted Choice 1
@ -610,8 +610,8 @@ int mbedtls_des_crypt_ecb( mbedtls_des_context *ctx,
SK = ctx->sk;
MBEDTLS_GET_UINT32_BE( X, input, 0 );
MBEDTLS_GET_UINT32_BE( Y, input, 4 );
X = MBEDTLS_GET_UINT32_BE( input, 0 );
Y = MBEDTLS_GET_UINT32_BE( input, 4 );
DES_IP( X, Y );
@ -697,8 +697,8 @@ int mbedtls_des3_crypt_ecb( mbedtls_des3_context *ctx,
SK = ctx->sk;
MBEDTLS_GET_UINT32_BE( X, input, 0 );
MBEDTLS_GET_UINT32_BE( Y, input, 4 );
X = MBEDTLS_GET_UINT32_BE( input, 0 );
Y = MBEDTLS_GET_UINT32_BE( input, 4 );
DES_IP( X, Y );

View File

@ -88,12 +88,12 @@ static int gcm_gen_table( mbedtls_gcm_context *ctx )
return( ret );
/* pack h as two 64-bits ints, big-endian */
MBEDTLS_GET_UINT32_BE( hi, h, 0 );
MBEDTLS_GET_UINT32_BE( lo, h, 4 );
hi = MBEDTLS_GET_UINT32_BE( h, 0 );
lo = MBEDTLS_GET_UINT32_BE( h, 4 );
vh = (uint64_t) hi << 32 | lo;
MBEDTLS_GET_UINT32_BE( hi, h, 8 );
MBEDTLS_GET_UINT32_BE( lo, h, 12 );
hi = MBEDTLS_GET_UINT32_BE( h, 8 );
lo = MBEDTLS_GET_UINT32_BE( h, 12 );
vl = (uint64_t) hi << 32 | lo;
/* 8 = 1000 corresponds to 1 in GF(2^128) */

View File

@ -94,22 +94,22 @@ int mbedtls_internal_md5_process( mbedtls_md5_context *ctx,
uint32_t X[16], A, B, C, D;
} local;
MBEDTLS_GET_UINT32_LE( local.X[ 0], data, 0 );
MBEDTLS_GET_UINT32_LE( local.X[ 1], data, 4 );
MBEDTLS_GET_UINT32_LE( local.X[ 2], data, 8 );
MBEDTLS_GET_UINT32_LE( local.X[ 3], data, 12 );
MBEDTLS_GET_UINT32_LE( local.X[ 4], data, 16 );
MBEDTLS_GET_UINT32_LE( local.X[ 5], data, 20 );
MBEDTLS_GET_UINT32_LE( local.X[ 6], data, 24 );
MBEDTLS_GET_UINT32_LE( local.X[ 7], data, 28 );
MBEDTLS_GET_UINT32_LE( local.X[ 8], data, 32 );
MBEDTLS_GET_UINT32_LE( local.X[ 9], data, 36 );
MBEDTLS_GET_UINT32_LE( local.X[10], data, 40 );
MBEDTLS_GET_UINT32_LE( local.X[11], data, 44 );
MBEDTLS_GET_UINT32_LE( local.X[12], data, 48 );
MBEDTLS_GET_UINT32_LE( local.X[13], data, 52 );
MBEDTLS_GET_UINT32_LE( local.X[14], data, 56 );
MBEDTLS_GET_UINT32_LE( local.X[15], data, 60 );
local.X[ 0] = MBEDTLS_GET_UINT32_LE( data, 0 );
local.X[ 1] = MBEDTLS_GET_UINT32_LE( data, 4 );
local.X[ 2] = MBEDTLS_GET_UINT32_LE( data, 8 );
local.X[ 3] = MBEDTLS_GET_UINT32_LE( data, 12 );
local.X[ 4] = MBEDTLS_GET_UINT32_LE( data, 16 );
local.X[ 5] = MBEDTLS_GET_UINT32_LE( data, 20 );
local.X[ 6] = MBEDTLS_GET_UINT32_LE( data, 24 );
local.X[ 7] = MBEDTLS_GET_UINT32_LE( data, 28 );
local.X[ 8] = MBEDTLS_GET_UINT32_LE( data, 32 );
local.X[ 9] = MBEDTLS_GET_UINT32_LE( data, 36 );
local.X[10] = MBEDTLS_GET_UINT32_LE( data, 40 );
local.X[11] = MBEDTLS_GET_UINT32_LE( data, 44 );
local.X[12] = MBEDTLS_GET_UINT32_LE( data, 48 );
local.X[13] = MBEDTLS_GET_UINT32_LE( data, 52 );
local.X[14] = MBEDTLS_GET_UINT32_LE( data, 56 );
local.X[15] = MBEDTLS_GET_UINT32_LE( data, 60 );
#define S(x,n) \
( ( (x) << (n) ) | ( ( (x) & 0xFFFFFFFF) >> ( 32 - (n) ) ) )

View File

@ -454,7 +454,7 @@ int mbedtls_nist_kw_unwrap( mbedtls_nist_kw_context *ctx,
ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED;
}
MBEDTLS_GET_UINT32_BE( Plen, A, KW_SEMIBLOCK_LENGTH / 2 );
Plen = MBEDTLS_GET_UINT32_BE( A, KW_SEMIBLOCK_LENGTH / 2 );
/*
* Plen is the length of the plaintext, when the input is valid.

View File

@ -122,10 +122,10 @@ static void poly1305_process( mbedtls_poly1305_context *ctx,
for( i = 0U; i < nblocks; i++ )
{
/* The input block is treated as a 128-bit little-endian integer */
d0 = MBEDTLS_BYTES_TO_U32_LE( input, offset + 0 );
d1 = MBEDTLS_BYTES_TO_U32_LE( input, offset + 4 );
d2 = MBEDTLS_BYTES_TO_U32_LE( input, offset + 8 );
d3 = MBEDTLS_BYTES_TO_U32_LE( input, offset + 12 );
d0 = MBEDTLS_GET_UINT32_LE( input, offset + 0 );
d1 = MBEDTLS_GET_UINT32_LE( input, offset + 4 );
d2 = MBEDTLS_GET_UINT32_LE( input, offset + 8 );
d3 = MBEDTLS_GET_UINT32_LE( input, offset + 12 );
/* Compute: acc += (padded) block as a 130-bit integer */
d0 += (uint64_t) acc0;
@ -290,15 +290,15 @@ int mbedtls_poly1305_starts( mbedtls_poly1305_context *ctx,
POLY1305_VALIDATE_RET( key != NULL );
/* r &= 0x0ffffffc0ffffffc0ffffffc0fffffff */
ctx->r[0] = MBEDTLS_BYTES_TO_U32_LE( key, 0 ) & 0x0FFFFFFFU;
ctx->r[1] = MBEDTLS_BYTES_TO_U32_LE( key, 4 ) & 0x0FFFFFFCU;
ctx->r[2] = MBEDTLS_BYTES_TO_U32_LE( key, 8 ) & 0x0FFFFFFCU;
ctx->r[3] = MBEDTLS_BYTES_TO_U32_LE( key, 12 ) & 0x0FFFFFFCU;
ctx->r[0] = MBEDTLS_GET_UINT32_LE( key, 0 ) & 0x0FFFFFFFU;
ctx->r[1] = MBEDTLS_GET_UINT32_LE( key, 4 ) & 0x0FFFFFFCU;
ctx->r[2] = MBEDTLS_GET_UINT32_LE( key, 8 ) & 0x0FFFFFFCU;
ctx->r[3] = MBEDTLS_GET_UINT32_LE( key, 12 ) & 0x0FFFFFFCU;
ctx->s[0] = MBEDTLS_BYTES_TO_U32_LE( key, 16 );
ctx->s[1] = MBEDTLS_BYTES_TO_U32_LE( key, 20 );
ctx->s[2] = MBEDTLS_BYTES_TO_U32_LE( key, 24 );
ctx->s[3] = MBEDTLS_BYTES_TO_U32_LE( key, 28 );
ctx->s[0] = MBEDTLS_GET_UINT32_LE( key, 16 );
ctx->s[1] = MBEDTLS_GET_UINT32_LE( key, 20 );
ctx->s[2] = MBEDTLS_GET_UINT32_LE( key, 24 );
ctx->s[3] = MBEDTLS_GET_UINT32_LE( key, 28 );
/* Initial accumulator state */
ctx->acc[0] = 0U;

View File

@ -297,11 +297,11 @@ psa_status_t psa_parse_key_data_from_storage( const uint8_t *storage_data,
if( status != PSA_SUCCESS )
return( status );
MBEDTLS_GET_UINT32_LE( version, storage_format->version, 0 );
version = MBEDTLS_GET_UINT32_LE( storage_format->version, 0 );
if( version != 0 )
return( PSA_ERROR_DATA_INVALID );
MBEDTLS_GET_UINT32_LE( *key_data_length, storage_format->data_len, 0 );
*key_data_length = MBEDTLS_GET_UINT32_LE( storage_format->data_len, 0 );
if( *key_data_length > ( storage_data_length - sizeof(*storage_format) ) ||
*key_data_length > PSA_CRYPTO_MAX_STORAGE_SIZE )
return( PSA_ERROR_DATA_INVALID );
@ -318,12 +318,12 @@ psa_status_t psa_parse_key_data_from_storage( const uint8_t *storage_data,
memcpy( *key_data, storage_format->key_data, *key_data_length );
}
MBEDTLS_GET_UINT32_LE( attr->lifetime, storage_format->lifetime, 0 );
MBEDTLS_GET_UINT16_LE( attr->type, storage_format->type, 0 );
MBEDTLS_GET_UINT16_LE( attr->bits, storage_format->bits, 0 );
MBEDTLS_GET_UINT32_LE( attr->policy.usage, storage_format->policy, 0 );
MBEDTLS_GET_UINT32_LE( attr->policy.alg, storage_format->policy, sizeof( uint32_t ) );
MBEDTLS_GET_UINT32_LE( attr->policy.alg2, storage_format->policy, 2 * sizeof( uint32_t ) );
attr->lifetime = MBEDTLS_GET_UINT32_LE( storage_format->lifetime, 0 );
attr->type = MBEDTLS_GET_UINT16_LE( storage_format->type, 0 );
attr->bits = MBEDTLS_GET_UINT16_LE( storage_format->bits, 0 );
attr->policy.usage = MBEDTLS_GET_UINT32_LE( storage_format->policy, 0 );
attr->policy.alg = MBEDTLS_GET_UINT32_LE( storage_format->policy, sizeof( uint32_t ) );
attr->policy.alg2 = MBEDTLS_GET_UINT32_LE( storage_format->policy, 2 * sizeof( uint32_t ) );
return( PSA_SUCCESS );
}

View File

@ -99,22 +99,22 @@ int mbedtls_internal_ripemd160_process( mbedtls_ripemd160_context *ctx,
uint32_t A, B, C, D, E, Ap, Bp, Cp, Dp, Ep, X[16];
} local;
MBEDTLS_GET_UINT32_LE( local.X[ 0], data, 0 );
MBEDTLS_GET_UINT32_LE( local.X[ 1], data, 4 );
MBEDTLS_GET_UINT32_LE( local.X[ 2], data, 8 );
MBEDTLS_GET_UINT32_LE( local.X[ 3], data, 12 );
MBEDTLS_GET_UINT32_LE( local.X[ 4], data, 16 );
MBEDTLS_GET_UINT32_LE( local.X[ 5], data, 20 );
MBEDTLS_GET_UINT32_LE( local.X[ 6], data, 24 );
MBEDTLS_GET_UINT32_LE( local.X[ 7], data, 28 );
MBEDTLS_GET_UINT32_LE( local.X[ 8], data, 32 );
MBEDTLS_GET_UINT32_LE( local.X[ 9], data, 36 );
MBEDTLS_GET_UINT32_LE( local.X[10], data, 40 );
MBEDTLS_GET_UINT32_LE( local.X[11], data, 44 );
MBEDTLS_GET_UINT32_LE( local.X[12], data, 48 );
MBEDTLS_GET_UINT32_LE( local.X[13], data, 52 );
MBEDTLS_GET_UINT32_LE( local.X[14], data, 56 );
MBEDTLS_GET_UINT32_LE( local.X[15], data, 60 );
local.X[ 0] = MBEDTLS_GET_UINT32_LE( data, 0 );
local.X[ 1] = MBEDTLS_GET_UINT32_LE( data, 4 );
local.X[ 2] = MBEDTLS_GET_UINT32_LE( data, 8 );
local.X[ 3] = MBEDTLS_GET_UINT32_LE( data, 12 );
local.X[ 4] = MBEDTLS_GET_UINT32_LE( data, 16 );
local.X[ 5] = MBEDTLS_GET_UINT32_LE( data, 20 );
local.X[ 6] = MBEDTLS_GET_UINT32_LE( data, 24 );
local.X[ 7] = MBEDTLS_GET_UINT32_LE( data, 28 );
local.X[ 8] = MBEDTLS_GET_UINT32_LE( data, 32 );
local.X[ 9] = MBEDTLS_GET_UINT32_LE( data, 36 );
local.X[10] = MBEDTLS_GET_UINT32_LE( data, 40 );
local.X[11] = MBEDTLS_GET_UINT32_LE( data, 44 );
local.X[12] = MBEDTLS_GET_UINT32_LE( data, 48 );
local.X[13] = MBEDTLS_GET_UINT32_LE( data, 52 );
local.X[14] = MBEDTLS_GET_UINT32_LE( data, 56 );
local.X[15] = MBEDTLS_GET_UINT32_LE( data, 60 );
local.A = local.Ap = ctx->state[0];
local.B = local.Bp = ctx->state[1];

View File

@ -110,22 +110,22 @@ int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx,
SHA1_VALIDATE_RET( ctx != NULL );
SHA1_VALIDATE_RET( (const unsigned char *)data != NULL );
MBEDTLS_GET_UINT32_BE( local.W[ 0], data, 0 );
MBEDTLS_GET_UINT32_BE( local.W[ 1], data, 4 );
MBEDTLS_GET_UINT32_BE( local.W[ 2], data, 8 );
MBEDTLS_GET_UINT32_BE( local.W[ 3], data, 12 );
MBEDTLS_GET_UINT32_BE( local.W[ 4], data, 16 );
MBEDTLS_GET_UINT32_BE( local.W[ 5], data, 20 );
MBEDTLS_GET_UINT32_BE( local.W[ 6], data, 24 );
MBEDTLS_GET_UINT32_BE( local.W[ 7], data, 28 );
MBEDTLS_GET_UINT32_BE( local.W[ 8], data, 32 );
MBEDTLS_GET_UINT32_BE( local.W[ 9], data, 36 );
MBEDTLS_GET_UINT32_BE( local.W[10], data, 40 );
MBEDTLS_GET_UINT32_BE( local.W[11], data, 44 );
MBEDTLS_GET_UINT32_BE( local.W[12], data, 48 );
MBEDTLS_GET_UINT32_BE( local.W[13], data, 52 );
MBEDTLS_GET_UINT32_BE( local.W[14], data, 56 );
MBEDTLS_GET_UINT32_BE( local.W[15], data, 60 );
local.W[ 0] = MBEDTLS_GET_UINT32_BE( data, 0 );
local.W[ 1] = MBEDTLS_GET_UINT32_BE( data, 4 );
local.W[ 2] = MBEDTLS_GET_UINT32_BE( data, 8 );
local.W[ 3] = MBEDTLS_GET_UINT32_BE( data, 12 );
local.W[ 4] = MBEDTLS_GET_UINT32_BE( data, 16 );
local.W[ 5] = MBEDTLS_GET_UINT32_BE( data, 20 );
local.W[ 6] = MBEDTLS_GET_UINT32_BE( data, 24 );
local.W[ 7] = MBEDTLS_GET_UINT32_BE( data, 28 );
local.W[ 8] = MBEDTLS_GET_UINT32_BE( data, 32 );
local.W[ 9] = MBEDTLS_GET_UINT32_BE( data, 36 );
local.W[10] = MBEDTLS_GET_UINT32_BE( data, 40 );
local.W[11] = MBEDTLS_GET_UINT32_BE( data, 44 );
local.W[12] = MBEDTLS_GET_UINT32_BE( data, 48 );
local.W[13] = MBEDTLS_GET_UINT32_BE( data, 52 );
local.W[14] = MBEDTLS_GET_UINT32_BE( data, 56 );
local.W[15] = MBEDTLS_GET_UINT32_BE( data, 60 );
#define S(x,n) (((x) << (n)) | (((x) & 0xFFFFFFFF) >> (32 - (n))))

View File

@ -191,7 +191,7 @@ int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,
for( i = 0; i < 64; i++ )
{
if( i < 16 )
MBEDTLS_GET_UINT32_BE( local.W[i], data, 4 * i );
local.W[i] = MBEDTLS_GET_UINT32_BE( data, 4 * i );
else
R( i );
@ -206,7 +206,7 @@ int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,
}
#else /* MBEDTLS_SHA256_SMALLER */
for( i = 0; i < 16; i++ )
MBEDTLS_GET_UINT32_BE( local.W[i], data, 4 * i );
local.W[i] = MBEDTLS_GET_UINT32_BE( data, 4 * i );
for( i = 0; i < 16; i += 8 )
{