This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2642R: AES encryption

Part Number: CC2642R
Other Parts Discussed in Thread: BLE-STACK

Hi team,

I referred the AES example of our SDK [see below] but got "AESECB_STATUS_ERROR(-1) " when calling AESECB_oneStepEncrypt. The error is defined as:

#define AESECB_STATUS_ERROR (-1)

/*!
* @brief An error status code returned if the hardware or software resource
* is currently unavailable.
*
* AESECB driver implementations may have hardware or software limitations on how
* many clients can simultaneously perform operations. This status code is returned
* if the mutual exclusion mechanism signals that an operation cannot currently be performed.
*/: 

Is there any hardware or software limitation to implement AES on CC2642?

  

  • In which context are you trying to do this? Are you doing this using the BLE stack? 

  • Yes, i am doing this with BLE stack. Is there any limitation?

  • What are you doing encryption on? 

  • I tested with simple_peripheral.

  • Any suggestion?

  • Hi Viki,

    Did you follow the code example in the API documentation?

    #include <ti/drivers/AESECB.h>
    #include <ti/drivers/types/cryptoKey/CryptoKey_Plaintext.h>
    ...
    AESECB_Handle handle;
    CryptoKey cryptoKey;
    int_fast16_t encryptionResult;
    uint8_t plaintext[] = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
                           0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
                           0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
                           0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51};
    uint8_t ciphertext[sizof(plaintext)];
    uint8_t keyingMaterial[16] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
                                  0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c}
    handle = AESECB_open(0, NULL);
    if (handle == NULL) {
        // handle error
    }
    CryptoKeyPlaintext_initKey(&cryptoKey, keyingMaterial, sizeof(keyingMaterial));
        AESECB_Operation operation;
        AESECB_Operation_init(&operation);
        operation.key               = &cryptoKey;
        operation.input             = plaintext;
        operation.output            = ciphertext;
        operation.inputLength       = sizeof(plaintext);
    encryptionResult = AESECB_oneStepEncrypt(handle, &operation);
    if (encryptionResult != AESECB_STATUS_SUCCESS) {
        // handle error
    }
    // The resultant ciphertext should be:
    // 0x3a, 0xd7, 0x7b, 0xb4, 0x0d, 0x7a, 0x36, 0x60,
    // 0xa8, 0x9e, 0xca, 0xf3, 0x24, 0x66, 0xef, 0x97,
    // 0xf5, 0xd3, 0xd5, 0x85, 0x03, 0xb9, 0x69, 0x9d,
    // 0xe7, 0x85, 0x89, 0x5a, 0x96, 0xfd, 0xba, 0xaf
    AESECB_close(handle);

    Did you check the return status on AESECB_open()?

  • Hi Marie,

    SDK: 3.20

    I work together with Viki. AESECB_open() will return unknown status. In addition, API documentation have some incorrect information, i have fixed it.

     0361.simple_peripheral.c

  • Hi Alvin, Viki,

    The BLE-Stack is already using AESECB index 0, that's why your AESECB_open() call is failing. You can use index 1 if you configure as follows:

    If you open your board file and look at the AESECB objects, you will see that two instances are defined (0 and 1). (From CC26X2R1_LAUNCHXL.h:)

    /*!
     *  @def    CC26X2R1_LAUNCHXL_AESECBName
     *  @brief  Enum of AESECB names
     */
    typedef enum CC26X2R1_LAUNCHXL_AESECBName {
        CC26X2R1_LAUNCHXL_AESECB0 = 0,
        CC26X2R1_LAUNCHXL_AESECB1 = 1,
    
        CC26X2R1_LAUNCHXL_AESECBCOUNT
    } CC26X2R1_LAUNCHXL_AESECBName;

    However, the hardware attributes are only configured for instance 0. You will need to add an entry in aesecbCC26XXHWAttrs:

    /*
     *  =============================== AESECB ===============================
     */
    #include <ti/drivers/AESECB.h>
    #include <ti/drivers/aesecb/AESECBCC26XX.h>
    
    AESECBCC26XX_Object aesecbCC26XXObjects[CC26X2R1_LAUNCHXL_AESECBCOUNT];
    
    const AESECBCC26XX_HWAttrs aesecbCC26XXHWAttrs[CC26X2R1_LAUNCHXL_AESECBCOUNT] = {
        {
            .intPriority       = ~0,
        },
        {
            .intPriority       = ~0,
        },
    };
    
    const AESECB_Config AESECB_config[CC26X2R1_LAUNCHXL_AESECBCOUNT] = {
        {
             .object  = &aesecbCC26XXObjects[CC26X2R1_LAUNCHXL_AESECB0],
             .hwAttrs = &aesecbCC26XXHWAttrs[CC26X2R1_LAUNCHXL_AESECB0]
        },
        {
             .object  = &aesecbCC26XXObjects[CC26X2R1_LAUNCHXL_AESECB1],
             .hwAttrs = &aesecbCC26XXHWAttrs[CC26X2R1_LAUNCHXL_AESECB1]
        },
    };
    
    const uint_least8_t AESECB_count = CC26X2R1_LAUNCHXL_AESECBCOUNT;

    In addition, the BLE-Stack instance (0) and your application instance (1) of the AESECB driver will be using the same hardware accelerator. To avoid conflicts you should only call it inside a critical section.

    You should also note that these operation can be time-consuming, so make sure the BLE-Stack is not in the middle of something time critical when you are using the AESECB.

  • Hi Marie,

    Thanks for your answer. It work well.