mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-29 22:20:30 +00:00
Move GET/PUT_UINT16_LE macros to common.h
Although these only appear in one file: psa_crypto_storage.c it is tidy to give it the same prefix as the UINT32 macros and to store them in the fame file Signed-off-by: Joe Subbiani <joe.subbiani@arm.com>
This commit is contained in:
parent
c46997377a
commit
9fa9ac3612
@ -80,7 +80,7 @@ extern void (*mbedtls_test_hook_test_fail)( const char * test, int line, const c
|
||||
* 32-bit integer manipulation macros (big endian)
|
||||
*/
|
||||
#ifndef MBEDTLS_GET_UINT32_BE
|
||||
#define MBEDTLS_GET_UINT32_BE(n,b,i) \
|
||||
#define MBEDTLS_GET_UINT32_BE(n,b,i) \
|
||||
do { \
|
||||
(n) = ( (uint32_t) (b)[(i) ] << 24 ) \
|
||||
| ( (uint32_t) (b)[(i) + 1] << 16 ) \
|
||||
@ -90,7 +90,7 @@ extern void (*mbedtls_test_hook_test_fail)( const char * test, int line, const c
|
||||
#endif
|
||||
|
||||
#ifndef MBEDTLS_PUT_UINT32_BE
|
||||
#define MBEDTLS_PUT_UINT32_BE(n,b,i) \
|
||||
#define MBEDTLS_PUT_UINT32_BE(n,b,i) \
|
||||
do { \
|
||||
(b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
|
||||
(b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
|
||||
@ -103,7 +103,7 @@ extern void (*mbedtls_test_hook_test_fail)( const char * test, int line, const c
|
||||
* 32-bit integer manipulation macros (little endian)
|
||||
*/
|
||||
#ifndef MBEDTLS_GET_UINT32_LE
|
||||
#define MBEDTLS_GET_UINT32_LE(n,b,i) \
|
||||
#define MBEDTLS_GET_UINT32_LE(n,b,i) \
|
||||
do { \
|
||||
(n) = ( (uint32_t) (b)[(i) ] ) \
|
||||
| ( (uint32_t) (b)[(i) + 1] << 8 ) \
|
||||
@ -113,7 +113,7 @@ extern void (*mbedtls_test_hook_test_fail)( const char * test, int line, const c
|
||||
#endif
|
||||
|
||||
#ifndef MBEDTLS_PUT_UINT32_LE
|
||||
#define MBEDTLS_PUT_UINT32_LE(n,b,i) \
|
||||
#define MBEDTLS_PUT_UINT32_LE(n,b,i) \
|
||||
do { \
|
||||
(b)[(i) ] = (unsigned char) ( ( (n) ) & 0xFF ); \
|
||||
(b)[(i) + 1] = (unsigned char) ( ( (n) >> 8 ) & 0xFF ); \
|
||||
@ -125,11 +125,32 @@ extern void (*mbedtls_test_hook_test_fail)( const char * test, int line, const c
|
||||
/**
|
||||
* 32-bit integer conversion from bytes (little endian)
|
||||
*/
|
||||
#define MBEDTLS_BYTES_TO_U32_LE( data, offset ) \
|
||||
#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 ) \
|
||||
)
|
||||
|
||||
|
||||
/*
|
||||
* 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 ) \
|
||||
{ \
|
||||
(b)[(i) ] = (unsigned char) ( ( (n) ) & 0xFF ); \
|
||||
(b)[(i) + 1] = (unsigned char) ( ( (n) >> 8 ) & 0xFF ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* MBEDTLS_LIBRARY_COMMON_H */
|
||||
|
@ -230,25 +230,6 @@ static psa_status_t psa_crypto_storage_get_data_length(
|
||||
return( PSA_SUCCESS );
|
||||
}
|
||||
|
||||
/*
|
||||
* 16-bit integer manipulation macros (little endian)
|
||||
*/
|
||||
#ifndef GET_UINT16_LE
|
||||
#define GET_UINT16_LE( n, b, i ) \
|
||||
{ \
|
||||
(n) = ( (uint16_t) (b)[(i) ] ) \
|
||||
| ( (uint16_t) (b)[(i) + 1] << 8 ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef PUT_UINT16_LE
|
||||
#define PUT_UINT16_LE( n, b, i ) \
|
||||
{ \
|
||||
(b)[(i) ] = (unsigned char) ( ( (n) ) & 0xFF ); \
|
||||
(b)[(i) + 1] = (unsigned char) ( ( (n) >> 8 ) & 0xFF ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Persistent key storage magic header.
|
||||
*/
|
||||
@ -277,8 +258,8 @@ void psa_format_key_data_for_storage( const uint8_t *data,
|
||||
memcpy( storage_format->magic, PSA_KEY_STORAGE_MAGIC_HEADER, PSA_KEY_STORAGE_MAGIC_HEADER_LENGTH );
|
||||
MBEDTLS_PUT_UINT32_LE( 0, storage_format->version, 0 );
|
||||
MBEDTLS_PUT_UINT32_LE( attr->lifetime, storage_format->lifetime, 0 );
|
||||
PUT_UINT16_LE( (uint16_t) attr->type, storage_format->type, 0 );
|
||||
PUT_UINT16_LE( (uint16_t) attr->bits, storage_format->bits, 0 );
|
||||
MBEDTLS_PUT_UINT16_LE( (uint16_t) attr->type, storage_format->type, 0 );
|
||||
MBEDTLS_PUT_UINT16_LE( (uint16_t) attr->bits, storage_format->bits, 0 );
|
||||
MBEDTLS_PUT_UINT32_LE( attr->policy.usage, storage_format->policy, 0 );
|
||||
MBEDTLS_PUT_UINT32_LE( attr->policy.alg, storage_format->policy, sizeof( uint32_t ) );
|
||||
MBEDTLS_PUT_UINT32_LE( attr->policy.alg2, storage_format->policy, 2 * sizeof( uint32_t ) );
|
||||
@ -334,8 +315,8 @@ psa_status_t psa_parse_key_data_from_storage( const uint8_t *storage_data,
|
||||
}
|
||||
|
||||
MBEDTLS_GET_UINT32_LE( attr->lifetime, storage_format->lifetime, 0 );
|
||||
GET_UINT16_LE( attr->type, storage_format->type, 0 );
|
||||
GET_UINT16_LE( attr->bits, storage_format->bits, 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 ) );
|
||||
|
Loading…
x
Reference in New Issue
Block a user