nRF52832 AES-128 CCM Extended Mode Support

Hello,

I am currently working with nRF52832 and have been referencing the following sample code: Point right nrf52-esb-ccm-example / ptx/main.c

I have successfully implemented AES-128 CCM based on this example. However, the sample uses : CCM_MODE_LENGTH_Default

This configuration imposes a limitation on the payload length. My application requires transmitting 64 bytes in a single operation, so I would like to clarify the following:

  1. Does the nRF52832 support CCM_MODE_LENGTH_Extended mode?

  2. If so, are there any documents or sample codes that demonstrate how to use CCM Extended mode on the nRF52832?

For reference, my MCU is nRF52832, and the development platform is SDK 17.1.0.

Thank you for your support!

Best regards

Doris

Parents
  • Hi Doris, 

    Does the nRF52832 support CCM_MODE_LENGTH_Extended mode?

    Yes, see the nRF52832 Product Specification/the CCM register: CCM.MODE.LENGTH

    nRF5_sDK\modules\nrfx\mdk\nrf52_bitfields.h:

    If so, are there any documents or sample codes that demonstrate how to use CCM Extended mode on the nRF52832?

    Unfortunately, there are no such resources as you request. 

    Regards,
    Amanda

  • Hello Amanda,

    Thank you for confirming that CCM_MODE_LENGTH_Extended is supported on the nRF52832.

    I tried modifying my code as follows:

    NRF_CCM->MODE = (CCM_MODE_MODE_Encryption << CCM_MODE_MODE_Pos) |
                    (CCM_MODE_DATARATE_1Mbit << CCM_MODE_DATARATE_Pos) |
                    (CCM_MODE_LENGTH_Extended << CCM_MODE_LENGTH_Pos);

    Other settings remain unchanged. However, when I attempt to decode, I encounter errors.

    From my research, it seems that the MAXPACKETSIZE register/parameter may need to be adjusted when using Extended mode. Unfortunately, I cannot find any reference to MAXPACKETSIZE in the nRF52832 product specification.

    Could you please clarify:

    1. How should MAXPACKETSIZE be configured when using CCM_MODE_LENGTH_Extended on nRF52832?

    2. If MAXPACKETSIZE is not exposed in nRF52832, what is the recommended way to avoid decode errors in Extended mode?

    Thank you very much for your support.

    Best regards, Doris

Reply
  • Hello Amanda,

    Thank you for confirming that CCM_MODE_LENGTH_Extended is supported on the nRF52832.

    I tried modifying my code as follows:

    NRF_CCM->MODE = (CCM_MODE_MODE_Encryption << CCM_MODE_MODE_Pos) |
                    (CCM_MODE_DATARATE_1Mbit << CCM_MODE_DATARATE_Pos) |
                    (CCM_MODE_LENGTH_Extended << CCM_MODE_LENGTH_Pos);

    Other settings remain unchanged. However, when I attempt to decode, I encounter errors.

    From my research, it seems that the MAXPACKETSIZE register/parameter may need to be adjusted when using Extended mode. Unfortunately, I cannot find any reference to MAXPACKETSIZE in the nRF52832 product specification.

    Could you please clarify:

    1. How should MAXPACKETSIZE be configured when using CCM_MODE_LENGTH_Extended on nRF52832?

    2. If MAXPACKETSIZE is not exposed in nRF52832, what is the recommended way to avoid decode errors in Extended mode?

    Thank you very much for your support.

    Best regards, Doris

Children
  • Doris.chen said:
    Other settings remain unchanged. However, when I attempt to decode, I encounter errors.

    What are the errors?

  • Hello Amanda,

    Following up on my previous question, I would like to share my current test code for clarity.

    I have included ccm_crypt.c and ccm_crypt.h from the nrf52-esb-ccm-example into my project, and modified the DATA_LENGTH definition in ccm_crypt.h as follows:

    // Configurable parameters
    //#define DATA_LENGTH 28
    #define DATA_LENGTH 64
    
    // Derived parameters (should not be changed)
    #if (DATA_LENGTH > (43 - 16))
    #define SCRATCH_AREA_SIZE (DATA_LENGTH + 16)
    #else
    #define SCRATCH_AREA_SIZE 43
    #endif
    

    In main.c, I set arbitrary values for the key and IV, and created buffers:

    uint8_t Buf_IN[64];
    uint8_t EBuf_OUT[64];
    uint8_t DBuf_OUT[64];
    

    The flow is:

    1. Put data into Buf_IN

    2. Call ccm_crypt_packet_encrypt → output to EBuf_OUT

    3. Call ccm_crypt_packet_decrypt → output to DBuf_OUT

    Code snippet:

    uint8_t Buf_IN[64] ;
    uint8_t EBuf_OUT[64];
    uint8_t DBuf_OUT[64];
    void CCM_init(void)
    {
    		Buf_IN[0] = 1;
    		Buf_IN[1] = 4;
    		Buf_IN[2] = 10;
    
    		ccm_crypt_init(); 	
    		
    		pair_request_packet.key[0] = 1;
    		pair_request_packet.key[1] = 1;
    		
    		pair_request_packet.iv[0] = 3;
    		pair_request_packet.iv[1] = 5;
    
    		ccm_crypt_packet_encrypt(&Buf_IN[0], 3, &EBuf_OUT[0]);
    		NRF_LOG_INFO("Buf_IN %d %d %d",Buf_IN[0],Buf_IN[1],Buf_IN[2]);
    
    		NRF_LOG_INFO("EBuf_OUT %d %d %d",EBuf_OUT[0],EBuf_OUT[1],EBuf_OUT[2]);
    		NRF_LOG_INFO("MIC  %x %x %x %x",EBuf_OUT[3],EBuf_OUT[4],EBuf_OUT[5],EBuf_OUT[6]);
    
    		ccm_crypt_packet_decrypt(&EBuf_OUT[0], 3+4, &DBuf_OUT[0]);
    		NRF_LOG_INFO("DBuf_OUT %d %d %d",DBuf_OUT[0],DBuf_OUT[1],DBuf_OUT[2]);
    }

    Test results:

    • When NRF_CCM->MODE is set to Default mode:

      Buf_IN 1 4 10
      EBuf_OUT 212 124 248
      MIC 94 EE 9 BD
      DBuf_OUT 1 4 10

      → Decode is correct.

    • When NRF_CCM->MODE is set to Extended mode:

      Buf_IN 1 4 10
      EBuf_OUT 216 193 21
      MIC B5 F6 A3 FE
      DBuf_OUT 0 0 0
      → Decode result is incorrect

    This is the issue I am currently facing: encryption works, but decryption fails when using Extended mode. Could you please advise if there are additional parameters or steps required to make decryption work properly with Extended mode on nRF52832?

    Best regards, Doris

  • In ccm_crypt_init(), try setting this:

    NRF_CCM->MAXPACKETSIZE = DATA_LENGTH;
    and the development platform is SDK 17.1.0.

    The nRF5 SDK is in maintenance mode. If you are starting a new project, we recommed either
    https://www.nordicsemi.com/Products/Development-software/nRF-Connect-SDK
    or
    https://www.nordicsemi.com/Products/Development-software/nRF-Connect-SDK/Bare-Metal-option-for-nRF54L-Series (For nRF54L-series)

Related