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.

LAUNCHXL-CC1312R1: AES128 CBC

Part Number: LAUNCHXL-CC1312R1

i working on AES CBC 128, 

my problem is on AESCBC_getNextIv(),

when i run this, all the IV go to zero(which should not be,

the .h it tells:

/**
 *  @brief Returns the IV for the next block to encrypt or decrypt.
 *
 *  When encrypting or decrypting messages in multiple segments, it is necessary
 *  to save the intermediate iv to use with the next message segment.
 *
 *  Only call this function after a successful call to #AESCBC_oneStepEncrypt()
 *  or #AESCBC_oneStepDecrypt() and before starting another operation with the
 *  same handle.
 *
 *  @param  [in]    handle  A CBC handle returned from #AESCBC_open()
 *
 *  @param  [out]   iv      IV of the next block to encrypt or decrypt
 *
 *  @retval #AESCBC_STATUS_SUCCESS  The operation succeeded.
 *  @retval #AESCBC_STATUS_ERROR    The operation failed.
 */
int_fast16_t AESCBC_getNextIv(AESCBC_Handle handle, uint8_t *iv);

my code :


uint8_t iv[16] =                {
                                  0x2D, 0x2C, 0x07, 0x71, 0x94, 0x15, 0x01, 0x02,
                                  0xB3, 0xB3, 0xB3, 0xB3, 0xB3, 0xB3, 0xB3, 0xB3
                                };

void aes_encrpyt(void)
{
    int_fast16_t next_iv_f = 0;
    aes_handle = AESCBC_open(Board_AESCBC0, NULL);

    // Initialize symmetric key
    CryptoKeyPlaintext_initKey(&cryptoKey, keyingMaterial, sizeof(keyingMaterial));

    AESCBC_Operation operation;
    // Set up AESCBC_Operation
    AESCBC_Operation_init(&operation);
    operation.key               = &cryptoKey;
    operation.input             = plaintext;
    operation.output            = ciphertext;
    operation.inputLength       = sizeof(plaintext);
    operation.iv                = iv;

    encryptionResult = AESCBC_oneStepEncrypt(aes_handle, &operation);
    test001 = encryptionResult;
    if (encryptionResult != AESCBC_STATUS_SUCCESS)
    {
        // handle error
    }

    //testing here
    next_iv_f = AESCBC_getNextIv( aes_handle,iv);
AESCBC_close(aes_handle);
    //return NULL;

}

So can someone pinpoint to me why does it happen?

Second question , do we need to handle the padding in AES CBC 128 mode?(i assume yes)
thanks

Jeff

  • Hi Jeff,

    1) What version of the SimpleLink CC13x2/CC26x2 SDK are you using?

    2) What example project are you using as a starting point for your application?

    3) What does the AESCBC_getNextIv() call return?

    4) I'm not sure  understand what you are trying to do. AESCBC_getNextIv() is meant for doing more than one operation on the same handle.

    5) Yes you need to handle the padding.

  • Hi Marie,

    thanks for quick reply.

    1) What version of the SimpleLink CC13x2/CC26x2 SDK are you using?

    A: 3.20.00.68

    2) What example project are you using as a starting point for your application?

    A: my own one but literally encrpt and decrpyt for testing

    3) What does the AESCBC_getNextIv() call return?

    A: the IV gone to ALL '0'

    4) I'm not sure  understand what you are trying to do. AESCBC_getNextIv() is meant for doing more than one operation on the same handle.

    A Can you elaborate more?
    Since Only call this function after a successful call to #AESCBC_oneStepEncrypt()

     *  or #AESCBC_oneStepDecrypt() and before starting another operation with the
     *  same handle.
    so what, where and when  exactly to use this function?

    5) Yes you need to handle the padding.

    OK. thanks

    Thanks~

    Jeff

  • Hi Jeff,

    Sorry for the delayed answer. I have had a discussion with the software developers and we apologize for the poor documentation.

    Actually for CBC mode it does not make sense to use this API. Instead, for continued operation you can set the last ciphertext block to operation.iv.