Use static inline function unconditionally

No need to play tricks with macros and functions depending on whether
SHA256_SMALLER is enabled or not, with a static inline function all common
compilers (tested with arm-gcc, armcc5, arm-clang) will Do The Right Thing
depending on whether we told them to optimize for size or speed.
This commit is contained in:
Manuel Pégourié-Gonnard 2019-09-05 11:33:32 +02:00
parent 100c057d0d
commit c7abba3796

View file

@ -56,7 +56,7 @@
#if !defined(MBEDTLS_SHA256_ALT) #if !defined(MBEDTLS_SHA256_ALT)
/* /*
* 32-bit integer manipulation macros (big endian) * 32-bit integer manipulation (big endian)
*/ */
#ifndef GET_UINT32_BE #ifndef GET_UINT32_BE
#define GET_UINT32_BE(n,b,i) \ #define GET_UINT32_BE(n,b,i) \
@ -68,24 +68,15 @@ do { \
} while( 0 ) } while( 0 )
#endif #endif
#ifndef PUT_UINT32_BE static inline void sha256_put_uint32_be( uint32_t n,
#define PUT_UINT32_BE(n,b,i) \ unsigned char *b,
do { \ uint8_t 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) ); \
} while( 0 )
#endif
#if defined(MBEDTLS_SHA256_SMALLER)
static void sha256_put_uint32_be( uint32_t n, unsigned char *b, uint8_t i )
{ {
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 );
} }
#else
#define sha256_put_uint32_be PUT_UINT32_BE
#endif
void mbedtls_sha256_init( mbedtls_sha256_context *ctx ) void mbedtls_sha256_init( mbedtls_sha256_context *ctx )
{ {