查看EFM32的源代码
←
EFM32
跳转到:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
您刚才请求的操作只有这个用户组中的用户才能使用:
用户
您可以查看并复制此页面的源代码:
== EF32ZG AES == 128-bit key (54 HFCORECLK cycles) Data, Key and IV 的地址必须 4 字节对齐,否则极其容易 hang ... 参考:NodeTao/examples/efm32/aes * https://docs.silabs.com/mcu/5.5/efm32zg/group-AES * https://siliconlabs.github.io/Gecko_SDK_Doc/efm32zg/html/group__AES.html * https://www.sekorm.com/news/7996.html <source lang=cpp> #include "em_aes.h" /* * Encrypt a plaintext message (32 bytes) using the AES CBC block cipher * mode with a 128 bits key and initial vector (iv) of 16 bytes * */ const uint8_t msg[32] __attribute__((aligned(4))) = {0x47, 0x4F, 0x33, 0x00, 0x00, 0x00, 0x02, 0xC5, 0x6E, 0x3B, 0xBA, 0x00, 0x8F, 0x0E, 0x29, 0x02, 0xE5, 0x75, 0x05, 0x15, 0x00, 0x41, 0x4D, 0x8C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; const uint8_t key[16] __attribute__((aligned(4))) = {0x64, 0x63, 0x47, 0x4F, 0x64, 0x63, 0x47, 0x4F, 0x64, 0x63, 0x47, 0x4F, 0x64, 0x63, 0x47, 0x4F}; const uint8_t iv[16] __attribute__((aligned(4))) = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}; uint8_t e_msg[32] __attribute__((aligned(4))); /* Output buffer for encrypted data (ciphertext). */ uint8_t d_key[16] __attribute__((aligned(4))); void setup() { Serial.setRouteLoc(1); Serial.begin(115200); CMU_ClockEnable(cmuClock_AES, true); } void print_msg(uint8_t *pkt) { for (int i = 0; i < 32; i++) { if (pkt[i] < 16) Serial.print("0"); Serial.print(pkt[i], HEX); Serial.print(" "); } Serial.println(""); } void loop() { int start = 0, end = 0; Serial.println("Testing the AES Engine... "); start = millis(); AES_CBC128(e_msg, msg, 32, key, iv, true); /* true means encrypt. */ end = millis(); Serial.print("Encrypted 32 bytes spend: "); Serial.print(end - start); Serial.println("ms"); Serial.println("The Encrypyted MSG:"); print_msg(e_msg); AES_DecryptKey128(d_key, key); AES_CBC128(e_msg, e_msg, 32, d_key, iv, false); Serial.println("The Decrypyted MSG:"); print_msg(e_msg); delay(6000); } </source> <br>
返回到
EFM32
。
个人工具
登录
名字空间
页面
讨论
变换
查看
阅读
查看源代码
查看历史
操作
搜索
导航
首页
社区专页
新闻动态
最近更改
随机页面
帮助
工具箱
链入页面
相关更改
特殊页面