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