环境: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