Other Parts Discussed in Thread: SYSCONFIG
我使用cc2642,进行AES_CBC加密操作,按照sysconfig中的example,完成了初始化、设置参数等步骤,与例子使用相同的key、iv、input。
#include <ti/drivers/AESCBC.h>
#include <ti/drivers/cryptoutils/cryptokey/CryptoKeyPlaintext.h>
...
AESCBC_Handle handle;
CryptoKey cryptoKey;
int_fast16_t encryptionResult;
// For example purposes only. Generate IVs in a non-static way in practice.
// Test vector 0 from NIST CAPV set CBCMMT128
uint8_t iv[16] = {0x2f, 0xe2, 0xb3, 0x33, 0xce, 0xda, 0x8f, 0x98,
0xf4, 0xa9, 0x9b, 0x40, 0xd2, 0xcd, 0x34, 0xa8};
uint8_t plaintext[16] = {0x45, 0xcf, 0x12, 0x96, 0x4f, 0xc8, 0x24, 0xab,
0x76, 0x61, 0x6a, 0xe2, 0xf4, 0xbf, 0x08, 0x22};
uint8_t ciphertext[sizeof(plaintext)];
uint8_t keyingMaterial[16] = {0x1f, 0x8e, 0x49, 0x73, 0x95, 0x3f, 0x3f, 0xb0,
0xbd, 0x6b, 0x16, 0x66, 0x2e, 0x9a, 0x3c, 0x17};
// The ciphertext should be the following after the encryption operation:
// 0x0f, 0x61, 0xc4, 0xd4, 0x4c, 0x51, 0x47, 0xc0
// 0x3c, 0x19, 0x5a, 0xd7, 0xe2, 0xcc, 0x12, 0xb2
handle = AESCBC_open(0, NULL);
if (handle == NULL) {
// handle error
}
CryptoKeyPlaintext_initKey(&cryptoKey, keyingMaterial, sizeof(keyingMaterial));
AESCBC_OneStepOperation operation;
AESCBC_OneStepOperation_init(&operation);
operation.key = &cryptoKey;
operation.input = plaintext;
operation.output = ciphertext;
operation.inputLength = sizeof(plaintext);
operation.iv = iv;
encryptionResult = AESCBC_oneStepEncrypt(handle, &operation);
if (encryptionResult != AESCBC_STATUS_SUCCESS) {
// handle error
}
AESCBC_close(handle);
在运行完encryptionResult = AESCBC_oneStepEncrypt(handle, &operation);后,结果是失败AESCBC_STATUS_ERROR状态,未能完成加密。
经过单步调试,发现程序跑到AESCBCCC26XX.c中的AESWriteToKeyStore(keyingMaterial, keyLength, AES_KEY_AREA_6) != AES_SUCCESS这个判断失败的。
/*
* Load the key from RAM or flash into the key store at
* a hardcoded and reserved location
*/
if (AESWriteToKeyStore(keyingMaterial, keyLength, AES_KEY_AREA_6) != AES_SUCCESS)
{
return AESCBC_STATUS_ERROR;
}
代码不能找到AESWriteToKeyStore这个函数(编译是通过的)。请问这个是SDK的问题还是算法使用设置的问题?
