我们现在正在使用2642的芯片,但2642与2640所使用的协议栈不同。请问有针对2642最新协议栈,使用AES进行加密的相关例程吗
附:2642 TIOS版本 simplelink_cc13x2_26x2_sdk_3_10_00_53
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.
我们现在正在使用2642的芯片,但2642与2640所使用的协议栈不同。请问有针对2642最新协议栈,使用AES进行加密的相关例程吗
附:2642 TIOS版本 simplelink_cc13x2_26x2_sdk_3_10_00_53
Hi, 请用如下代码:
由于BLE-stack已经使用0请使用1.
先修改板级文件配置:
/* * =============================== 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;
那个文档有些过时了,我更正了它,请参考如下程序:
#include <ti/drivers/AESECB.h> // doc need update path #include <ti/drivers/cryptoutils/cryptokey/CryptoKeyPlaintext.h> void AES_Test() { 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}; //doc error:uint8_t ciphertext[sizof(plaintext)]; uint8_t ciphertext[sizeof(plaintext)]; // doc: loss ; uint8_t keyingMaterial[16] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c}; handle = AESECB_open(CC26X2R1_LAUNCHXL_AESECB1, NULL); if (handle == NULL) { while(1); } 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) { while(1); } }