Move UINT32_BE macros to common.h
32-bit integer manipulation macros (big edian): GET_UINT32_BE and PUT_UINT32_BE appear in several files in library/. Removes duplicate code and save vertical space the macro has been moved to common.h. Improves maintainability. Signed-off-by: Joe Subbiani <joe.subbiani@arm.com>
This commit is contained in:
parent
3b394509da
commit
30d974c232
@ -49,29 +49,6 @@
|
|||||||
#define CAMELLIA_VALIDATE( cond ) \
|
#define CAMELLIA_VALIDATE( cond ) \
|
||||||
MBEDTLS_INTERNAL_VALIDATE( cond )
|
MBEDTLS_INTERNAL_VALIDATE( cond )
|
||||||
|
|
||||||
/*
|
|
||||||
* 32-bit integer manipulation macros (big endian)
|
|
||||||
*/
|
|
||||||
#ifndef GET_UINT32_BE
|
|
||||||
#define GET_UINT32_BE(n,b,i) \
|
|
||||||
{ \
|
|
||||||
(n) = ( (uint32_t) (b)[(i) ] << 24 ) \
|
|
||||||
| ( (uint32_t) (b)[(i) + 1] << 16 ) \
|
|
||||||
| ( (uint32_t) (b)[(i) + 2] << 8 ) \
|
|
||||||
| ( (uint32_t) (b)[(i) + 3] ); \
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef PUT_UINT32_BE
|
|
||||||
#define PUT_UINT32_BE(n,b,i) \
|
|
||||||
{ \
|
|
||||||
(b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
|
|
||||||
(b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
|
|
||||||
(b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
|
|
||||||
(b)[(i) + 3] = (unsigned char) ( (n) ); \
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static const unsigned char SIGMA_CHARS[6][8] =
|
static const unsigned char SIGMA_CHARS[6][8] =
|
||||||
{
|
{
|
||||||
{ 0xa0, 0x9e, 0x66, 0x7f, 0x3b, 0xcc, 0x90, 0x8b },
|
{ 0xa0, 0x9e, 0x66, 0x7f, 0x3b, 0xcc, 0x90, 0x8b },
|
||||||
|
@ -76,6 +76,29 @@ extern void (*mbedtls_test_hook_test_fail)( const char * test, int line, const c
|
|||||||
#define BYTE_2( x ) ( (uint8_t) ( ( ( x ) >> 16 ) & 0xff ) )
|
#define BYTE_2( x ) ( (uint8_t) ( ( ( x ) >> 16 ) & 0xff ) )
|
||||||
#define BYTE_3( x ) ( (uint8_t) ( ( ( x ) >> 24 ) & 0xff ) )
|
#define BYTE_3( x ) ( (uint8_t) ( ( ( x ) >> 24 ) & 0xff ) )
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 32-bit integer manipulation macros (big endian)
|
||||||
|
*/
|
||||||
|
#ifndef GET_UINT32_BE
|
||||||
|
#define GET_UINT32_BE(n,b,i) \
|
||||||
|
{ \
|
||||||
|
(n) = ( (uint32_t) (b)[(i) ] << 24 ) \
|
||||||
|
| ( (uint32_t) (b)[(i) + 1] << 16 ) \
|
||||||
|
| ( (uint32_t) (b)[(i) + 2] << 8 ) \
|
||||||
|
| ( (uint32_t) (b)[(i) + 3] ); \
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef PUT_UINT32_BE
|
||||||
|
#define PUT_UINT32_BE(n,b,i) \
|
||||||
|
{ \
|
||||||
|
(b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
|
||||||
|
(b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
|
||||||
|
(b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
|
||||||
|
(b)[(i) + 3] = (unsigned char) ( (n) ); \
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -43,29 +43,6 @@
|
|||||||
|
|
||||||
#if !defined(MBEDTLS_DES_ALT)
|
#if !defined(MBEDTLS_DES_ALT)
|
||||||
|
|
||||||
/*
|
|
||||||
* 32-bit integer manipulation macros (big endian)
|
|
||||||
*/
|
|
||||||
#ifndef GET_UINT32_BE
|
|
||||||
#define GET_UINT32_BE(n,b,i) \
|
|
||||||
{ \
|
|
||||||
(n) = ( (uint32_t) (b)[(i) ] << 24 ) \
|
|
||||||
| ( (uint32_t) (b)[(i) + 1] << 16 ) \
|
|
||||||
| ( (uint32_t) (b)[(i) + 2] << 8 ) \
|
|
||||||
| ( (uint32_t) (b)[(i) + 3] ); \
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef PUT_UINT32_BE
|
|
||||||
#define PUT_UINT32_BE(n,b,i) \
|
|
||||||
{ \
|
|
||||||
(b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
|
|
||||||
(b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
|
|
||||||
(b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
|
|
||||||
(b)[(i) + 3] = (unsigned char) ( (n) ); \
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Expanded DES S-boxes
|
* Expanded DES S-boxes
|
||||||
*/
|
*/
|
||||||
|
@ -58,29 +58,6 @@
|
|||||||
#define GCM_VALIDATE( cond ) \
|
#define GCM_VALIDATE( cond ) \
|
||||||
MBEDTLS_INTERNAL_VALIDATE( cond )
|
MBEDTLS_INTERNAL_VALIDATE( cond )
|
||||||
|
|
||||||
/*
|
|
||||||
* 32-bit integer manipulation macros (big endian)
|
|
||||||
*/
|
|
||||||
#ifndef GET_UINT32_BE
|
|
||||||
#define GET_UINT32_BE(n,b,i) \
|
|
||||||
{ \
|
|
||||||
(n) = ( (uint32_t) (b)[(i) ] << 24 ) \
|
|
||||||
| ( (uint32_t) (b)[(i) + 1] << 16 ) \
|
|
||||||
| ( (uint32_t) (b)[(i) + 2] << 8 ) \
|
|
||||||
| ( (uint32_t) (b)[(i) + 3] ); \
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef PUT_UINT32_BE
|
|
||||||
#define PUT_UINT32_BE(n,b,i) \
|
|
||||||
{ \
|
|
||||||
(b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
|
|
||||||
(b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
|
|
||||||
(b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
|
|
||||||
(b)[(i) + 3] = (unsigned char) ( (n) ); \
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize a context
|
* Initialize a context
|
||||||
*/
|
*/
|
||||||
|
@ -77,26 +77,6 @@ static const unsigned char NIST_KW_ICV1[] = {0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6,
|
|||||||
/*! The 32-bit default integrity check value (ICV) for KWP mode. */
|
/*! The 32-bit default integrity check value (ICV) for KWP mode. */
|
||||||
static const unsigned char NIST_KW_ICV2[] = {0xA6, 0x59, 0x59, 0xA6};
|
static const unsigned char NIST_KW_ICV2[] = {0xA6, 0x59, 0x59, 0xA6};
|
||||||
|
|
||||||
#ifndef GET_UINT32_BE
|
|
||||||
#define 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 PUT_UINT32_BE
|
|
||||||
#define PUT_UINT32_BE(n,b,i) \
|
|
||||||
do { \
|
|
||||||
(b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
|
|
||||||
(b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
|
|
||||||
(b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
|
|
||||||
(b)[(i) + 3] = (unsigned char) ( (n) ); \
|
|
||||||
} while( 0 )
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize context
|
* Initialize context
|
||||||
*/
|
*/
|
||||||
|
@ -48,29 +48,6 @@
|
|||||||
|
|
||||||
#if !defined(MBEDTLS_SHA1_ALT)
|
#if !defined(MBEDTLS_SHA1_ALT)
|
||||||
|
|
||||||
/*
|
|
||||||
* 32-bit integer manipulation macros (big endian)
|
|
||||||
*/
|
|
||||||
#ifndef GET_UINT32_BE
|
|
||||||
#define GET_UINT32_BE(n,b,i) \
|
|
||||||
{ \
|
|
||||||
(n) = ( (uint32_t) (b)[(i) ] << 24 ) \
|
|
||||||
| ( (uint32_t) (b)[(i) + 1] << 16 ) \
|
|
||||||
| ( (uint32_t) (b)[(i) + 2] << 8 ) \
|
|
||||||
| ( (uint32_t) (b)[(i) + 3] ); \
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef PUT_UINT32_BE
|
|
||||||
#define PUT_UINT32_BE(n,b,i) \
|
|
||||||
{ \
|
|
||||||
(b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
|
|
||||||
(b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
|
|
||||||
(b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
|
|
||||||
(b)[(i) + 3] = (unsigned char) ( (n) ); \
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void mbedtls_sha1_init( mbedtls_sha1_context *ctx )
|
void mbedtls_sha1_init( mbedtls_sha1_context *ctx )
|
||||||
{
|
{
|
||||||
SHA1_VALIDATE( ctx != NULL );
|
SHA1_VALIDATE( ctx != NULL );
|
||||||
|
@ -50,29 +50,6 @@
|
|||||||
|
|
||||||
#if !defined(MBEDTLS_SHA256_ALT)
|
#if !defined(MBEDTLS_SHA256_ALT)
|
||||||
|
|
||||||
/*
|
|
||||||
* 32-bit integer manipulation macros (big endian)
|
|
||||||
*/
|
|
||||||
#ifndef GET_UINT32_BE
|
|
||||||
#define 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 PUT_UINT32_BE
|
|
||||||
#define PUT_UINT32_BE(n,b,i) \
|
|
||||||
do { \
|
|
||||||
(b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
|
|
||||||
(b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
|
|
||||||
(b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
|
|
||||||
(b)[(i) + 3] = (unsigned char) ( (n) ); \
|
|
||||||
} while( 0 )
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void mbedtls_sha256_init( mbedtls_sha256_context *ctx )
|
void mbedtls_sha256_init( mbedtls_sha256_context *ctx )
|
||||||
{
|
{
|
||||||
SHA256_VALIDATE( ctx != NULL );
|
SHA256_VALIDATE( ctx != NULL );
|
||||||
|
Loading…
Reference in New Issue
Block a user