Use mbedtls_xor in CMAC

Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
Dave Rodgman 2022-11-22 16:38:44 +00:00
parent c1d9022bab
commit 8c0ff81ce7

View file

@ -148,15 +148,6 @@ exit:
#endif /* !defined(MBEDTLS_CMAC_ALT) || defined(MBEDTLS_SELF_TEST) */ #endif /* !defined(MBEDTLS_CMAC_ALT) || defined(MBEDTLS_SELF_TEST) */
#if !defined(MBEDTLS_CMAC_ALT) #if !defined(MBEDTLS_CMAC_ALT)
static void cmac_xor_block( unsigned char *output, const unsigned char *input1,
const unsigned char *input2,
const size_t block_size )
{
size_t idx;
for( idx = 0; idx < block_size; idx++ )
output[ idx ] = input1[ idx ] ^ input2[ idx ];
}
/* /*
* Create padded last block from (partial) last block. * Create padded last block from (partial) last block.
@ -247,7 +238,7 @@ int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx,
input, input,
block_size - cmac_ctx->unprocessed_len ); block_size - cmac_ctx->unprocessed_len );
cmac_xor_block( state, cmac_ctx->unprocessed_block, state, block_size ); mbedtls_xor( state, cmac_ctx->unprocessed_block, state, block_size );
if( ( ret = mbedtls_cipher_update( ctx, state, block_size, state, if( ( ret = mbedtls_cipher_update( ctx, state, block_size, state,
&olen ) ) != 0 ) &olen ) ) != 0 )
@ -267,7 +258,7 @@ int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx,
* final partial or complete block */ * final partial or complete block */
for( j = 1; j < n; j++ ) for( j = 1; j < n; j++ )
{ {
cmac_xor_block( state, input, state, block_size ); mbedtls_xor( state, input, state, block_size );
if( ( ret = mbedtls_cipher_update( ctx, state, block_size, state, if( ( ret = mbedtls_cipher_update( ctx, state, block_size, state,
&olen ) ) != 0 ) &olen ) ) != 0 )
@ -319,16 +310,16 @@ int mbedtls_cipher_cmac_finish( mbedtls_cipher_context_t *ctx,
if( cmac_ctx->unprocessed_len < block_size ) if( cmac_ctx->unprocessed_len < block_size )
{ {
cmac_pad( M_last, block_size, last_block, cmac_ctx->unprocessed_len ); cmac_pad( M_last, block_size, last_block, cmac_ctx->unprocessed_len );
cmac_xor_block( M_last, M_last, K2, block_size ); mbedtls_xor( M_last, M_last, K2, block_size );
} }
else else
{ {
/* Last block is complete block */ /* Last block is complete block */
cmac_xor_block( M_last, last_block, K1, block_size ); mbedtls_xor( M_last, last_block, K1, block_size );
} }
cmac_xor_block( state, M_last, state, block_size ); mbedtls_xor( state, M_last, state, block_size );
if( ( ret = mbedtls_cipher_update( ctx, state, block_size, state, if( ( ret = mbedtls_cipher_update( ctx, state, block_size, state,
&olen ) ) != 0 ) &olen ) ) != 0 )
{ {