I am using mbedtls with ECB hard accelerator on nRF52840. So I changed the macro definition: UPDATE_CBC_MAC in ccm.c to function:
#define HT_UPDATE_CBC_MAC \
for( i = 0; i < 16; i++ ) \
y[i] ^= b[i]; \
\
if( ( ret = ht_aes_ecb_encrypt( key, y, y) ) != 0 ) \
return( ret );
static int ht_aes_ecb_encrypt(const uint8_t* pKey, uint8_t* input, uint8_t* output)
{
return aes_ecb_128_encrypt(pKey, input, 16, output);
}
ht_error_t aes_ecb_128_encrypt(const uint8_t* key, const uint8_t* plaintext, uint8_t plen, uint8_t* ciphertext)
{
uint32_t errno;
nrf_ecb_hal_data_t ctx = {0};
if ( plaintext == NULL || key == NULL)
return HT_ERR_INVALID_ADDR;
else if (plen > 16)
return HT_ERR_INVALID_LENGTH;
memcpy(ctx.key, key, 16);
memcpy(ctx.cleartext, plaintext, plen);
errno = sd_ecb_block_encrypt(&ctx);
memcpy(ciphertext, ctx.ciphertext, plen);
return err_code_convert(errno);
}
The code runs, but I find the function: ccm_auth_crypt in ccm.c, output two result of original function and the changed. Why? Is any wrong with sd_ecb_block_encrypt?
Anything is appreciatory.