This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

ECB with mbedtls

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_tpKeyuint8_tinputuint8_toutput)
{
    return aes_ecb_128_encrypt(pKey, input, 16, output);
}
ht_error_t aes_ecb_128_encrypt(const uint8_tkeyconst uint8_tplaintextuint8_t plenuint8_tciphertext)
{
    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.
  • Hi,

    The code runs, but I find the function: ccm_auth_crypt in ccm.c, output two result of original function and the changed.

    I'm not sure if I understand what you mean by this. Is the input parameters not changed after the function returns? Can you give an example? Is the softdevice enabled before you call the function? Do the softdevice function call return NRF_SUCCESS?

    Best regards,
    Jørgen 

Related