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

how to use sec_aes_ccm_enc function with struct sec_aes_ccm_req_t

i am working on aes_ccm with '802_15_4_lib_keil.lib' , and i have build the target,but the result is not right. since there is no example with this lib, now i have a big problem with struct 'sec_aes_ccm_req_t', cause i don't know how to fill these struct data,especially the 'mic' and 'level'. can someone help me to solve this? thanks a lot!

  • Actually, there is one example for the 802.15.4 library and it can be found in the following location: examples\802_15_4\experimental\wireless_uart (Release 14.0.0). However, this example does not show how to use sec_aes_ccm.h API. The mic field and the security level field settings are related to each other. The security level determines how long Message Integrity Code (MIC) should be. You can refer to the Table 95 in the 7.6.2.2.1 section of the 802.15.4 specification (here is the link: standards.ieee.org/.../802.15.4-2006.pdf) to see the relation between the security level and the corresponding type of MIC. For example, if the security level is equal to 0x06, then you can expect the 8 byte long MIC:

    #include "sec_aes_ccm.h"
    
    #define CONFIG_POOL_SIZE 0x2000
    
    static uint8_t __ALIGN(ALIGN_VALUE) m_heap[CONFIG_POOL_SIZE];
    static const size_t                 m_heap_size = CONFIG_POOL_SIZE;
    
    #define BLOCK_SIZE      16
    #define NONCE_SIZE      13
    #define ENC_MIC_64_SIZE 8
    
    uint8_t key[BLOCK_SIZE]     = {0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF};
    uint8_t nonce[NONCE_SIZE]   = {0xAC, 0xDE, 0x48, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x06};
    uint8_t m[]                 = {0xCE};
    uint8_t a[]                 = {0x2B, 0xDC, 0x84, 0x21, 0x43, 0x02, 0x00, 0x00, 0x00, 0x00, 0x48, 0xDE, 0xAC, 0xFF, 0xFF, 0x01,
                                   0x00, 0x00, 0x00, 0x00, 0x48, 0xDE, 0xAC, 0x06, 0x05, 0x00, 0x00, 0x00, 0x01};
    uint8_t mic[ENC_MIC_64_SIZE];
    
    
    int main(void)
    {
    (...)
        sys_init(m_heap, m_heap_size);
    
        sec_aes_ccm_status_t value;
        sec_aes_ccm_req_t    request =
        {
            .auth_data     = a,
            .auth_data_len = sizeof(a),
            .text_data     = m,
            .text_data_len = sizeof(m),
            .nonce         = nonce,
            .key           = key,
            .level         = 0x06,
            .mic           = mic
        };
    
        value = sec_aes_ccm_enc(&request);
        if (value == AES_CCM_OK)
        {
            NRF_LOG_INFO("Encrypted data:");
            NRF_LOG_HEXDUMP_INFO(request.text_data, request.text_data_len);
            NRF_LOG_INFO("MIC:");
            NRF_LOG_HEXDUMP_INFO(request.mic, ENC_MIC_64_SIZE)
        }
    (...)
    }
    
  • Hi,thanks for your answer; i used this lib,and tested, the result is not right. I searched in the nordic Infocenter,and found that IEEE 802.15.4 MAC library is for nRF52840 SoC only, is that right? is there any example for 52832 with aes ccm example?

  • Yes, the IEEE 802.15.4 MAC library can only be used with the nRF52840 SoC. When it comes to nRF52832, there is no support for the 15.4 stack at the HW level (the RADIO peripheral does not support it). However, if you are interested in AES CCM encryption alone and you do not need the 15.4 stack, you can check out this GitHub example: github.com/.../nrf52-esb-ccm-example. It was created for the nRF52832 target.

Related