13 #if RUUVI_NRF5_SDK15_AES_ENABLED
17 #include "nrf_crypto_aes.h"
21 #define ECB_128_BLOCK_SIZE_BYTES (16U)
23 static void aes_ecb_128_encrypt_sdapi (
const uint8_t *
const cleartext,
24 uint8_t *
const ciphertext,
25 const uint8_t *
const key,
26 const size_t data_length)
28 const size_t crypt_rounds = (data_length / ECB_128_BLOCK_SIZE_BYTES);
29 nrf_ecb_hal_data_t soc_ecb_data;
30 memcpy (soc_ecb_data.key, key, ECB_128_BLOCK_SIZE_BYTES);
32 for (
size_t round = 0; round < crypt_rounds; round++)
34 memcpy (soc_ecb_data.cleartext,
35 cleartext + (round * ECB_128_BLOCK_SIZE_BYTES),
36 ECB_128_BLOCK_SIZE_BYTES);
37 sd_ecb_block_encrypt (&soc_ecb_data);
38 memcpy (ciphertext + (round * ECB_128_BLOCK_SIZE_BYTES),
39 soc_ecb_data.ciphertext,
40 ECB_128_BLOCK_SIZE_BYTES);
45 aes_ecb_128_encrypt_nrfapi (
const uint8_t *
const cleartext,
46 uint8_t *
const ciphertext,
47 const uint8_t *
const key,
48 const size_t data_length)
50 ret_code_t err_code = NRF_SUCCESS;
53 err_code |= nrf_crypto_aes_crypt (NULL,
54 &g_nrf_crypto_aes_ecb_128_info,
58 (uint8_t *) cleartext,
63 if (data_length != out_data_len)
87 uint8_t *
const ciphertext,
88 const uint8_t *
const key,
89 const size_t data_length)
93 if ( (NULL == cleartext) || (NULL == ciphertext) || (NULL == key))
97 else if ( (!data_length) || (data_length % ECB_128_BLOCK_SIZE_BYTES))
102 else if (nrf_sdh_is_enabled())
104 aes_ecb_128_encrypt_sdapi (cleartext, ciphertext, key, data_length);
109 err_code |= aes_ecb_128_encrypt_nrfapi (cleartext, ciphertext, key, data_length);
rd_status_t ri_aes_ecb_128_encrypt(const uint8_t *const cleartext, uint8_t *const ciphertext, const uint8_t *const key, const size_t data_length)
encrypt a block with AES ECB 128 encryption
#define RD_ERROR_NULL
Null Pointer.
uint32_t rd_status_t
bitfield for representing errors
#define RD_ERROR_INVALID_LENGTH
Invalid Length.
rd_status_t ruuvi_nrf5_sdk15_to_ruuvi_error(const ret_code_t error)
convert nrf5 sdk15 error code into Ruuvi error code.
#define RD_SUCCESS
Internal Error.
#define RD_ERROR_DATA_SIZE
Invalid Data size.
Header to enable and disable module compilation.
Ruuvi error codes and error check function.