From d18c70708e716da885cd2021c58ab5fd3e7d6d09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Wed, 13 Jan 2016 15:03:05 +0000 Subject: [PATCH] cmac: reduce visibility of macros The #undef is usefull for people who want to to amalgamated releases --- library/cmac.c | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/library/cmac.c b/library/cmac.c index d9e94a6fc..35c32f3a5 100644 --- a/library/cmac.c +++ b/library/cmac.c @@ -46,29 +46,6 @@ #endif /* MBEDTLS_PLATFORM_C */ #endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */ -/* - * Macros for common operations. - * Results in smaller compiled code than static inline functions. - */ - -/* - * XOR 128-bit - */ -#define XOR_128( o, i1, i2 ) \ - for( i = 0; i < 16; i++ ) \ - ( o )[i] = ( i1 )[i] ^ ( i2 )[i]; - -/* - * Update the CMAC state using an input block x - */ -#define UPDATE_CMAC( x ) \ -do { \ - XOR_128( state, ( x ), state ); \ - if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx, \ - state, 16, state, &olen ) ) != 0 ) \ - return( ret ); \ -} while( 0 ) - /* Implementation that should never be optimized out by the compiler */ static void mbedtls_zeroize( void *v, size_t n ) { volatile unsigned char *p = v; while( n-- ) *p++ = 0; @@ -211,6 +188,25 @@ static void padding( unsigned char padded_block[16], } } +/* + * XOR 128-bit + * Here, macro results in smaller compiled code than static inline function + */ +#define XOR_128( o, i1, i2 ) \ + for( i = 0; i < 16; i++ ) \ + ( o )[i] = ( i1 )[i] ^ ( i2 )[i]; + +/* + * Update the CMAC state using an input block x + */ +#define UPDATE_CMAC( x ) \ +do { \ + XOR_128( state, ( x ), state ); \ + if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx, \ + state, 16, state, &olen ) ) != 0 ) \ + return( ret ); \ +} while( 0 ) + /* * Generate tag on complete message */ @@ -261,6 +257,9 @@ static int cmac_generate( mbedtls_cmac_context *ctx, return( 0 ); } +#undef XOR_128 +#undef UPDATE_CMAC + int mbedtls_cmac_generate( mbedtls_cmac_context *ctx, const unsigned char *input, size_t in_len, unsigned char *tag, size_t tag_len )