From c7abba379647986bca193f0bbe7c77d181a4687d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Thu, 5 Sep 2019 11:33:32 +0200 Subject: [PATCH] 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. --- library/sha256.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/library/sha256.c b/library/sha256.c index fe381d2a2..5551140c3 100644 --- a/library/sha256.c +++ b/library/sha256.c @@ -56,7 +56,7 @@ #if !defined(MBEDTLS_SHA256_ALT) /* - * 32-bit integer manipulation macros (big endian) + * 32-bit integer manipulation (big endian) */ #ifndef GET_UINT32_BE #define GET_UINT32_BE(n,b,i) \ @@ -68,24 +68,15 @@ do { \ } 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 - -#if defined(MBEDTLS_SHA256_SMALLER) -static void sha256_put_uint32_be( uint32_t n, unsigned char *b, uint8_t i ) +static inline 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 ) {