環境:Windows 10、Simplicity Studio 5
SDK: EmberZnet SDK 6.8.2.0
簡介
EFR32 系列晶片自帶AES硬體加密,官方也提供了軟體加密,在插件上可以選擇使用哪一種。
This plugin provides the AES-CCM* api for encryption, decryption, and Message Integrity Authentication. Implementation can be provided by the mbedTLS framework, or through software
使用注意點
- 要先初始化AES-CCM子產品,Silicon 将其封裝了,找不到接口,隻能先加入網絡,讓其進行初始化。
- 提供 13 bytes nonce 初始化向量IV;
- packet指針的可使用記憶體大小為待加密資料的位元組數加 MIC_LENGTH;
- MIC:Message integrity check,消息完整性檢查,附加在加密資料後。
- AES-CCM參考:安全協定系列(二)----CCM與CCMP
代碼
uint8_t nonce[NONCE_LENGTH];
uint8_t packet[4 + MIC_LENGTH] = {0x45, 0x67, 0x89, 0x10, 0, 0, 0, 0};
EmberStatus status = 0;
for(uint8_t i = 0; i < sizeof packet; i++)
packet[i] = i;
Print(" packet, status %d: ", status);
PrintBuffer(packet, sizeof packet, true);
status = emberCcmEncryptAndTagPacket(nonce, packet, 0 , 4);
Print("encrypt, status %d: ", status);
PrintBuffer(packet, sizeof packet, true);
status = emberCcmAuthDecryptPacket(nonce, packet, 0, 4);
Print("decrypt, status %d: ", status);
PrintBuffer(packet, sizeof packet, true);
日志
UM> packet, status 0: 00 01 02 03 04 05 06 07
UM>encrypt, status 0: BF E2 35 85 D5 40 39 73
UM>decrypt, status 0: 00 01 02 03 D5 40 39 73