接前一篇文章:ESP32-C3模组上跑通AES-GCM(4)
四、ESP-IDF中的AES-GCM例程解析
上一回开始对于ESP-IDF中的AES-GCM进行讲解,讲解了components\components\mbedtls\test_apps\main\test_aes_gcm.c中例程的aes_gcm_test函数的第1部分中的第1段的第1个语句(说是一行代码,但其中包含的内容不少)。本回继续往下讲解第1段的余下内容。
1. aes_gcm_test函数
(1)为ciphertext(密文)和output分配空间
uint8_t *ciphertext = heap_caps_malloc(cfg->plaintext_length, cfg->output_caps);
uint8_t *output = heap_caps_malloc(cfg->plaintext_length, MALLOC_CAP_DMA | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
if (cfg->plaintext_length != 0) {
TEST_ASSERT_NOT_NULL(ciphertext);
TEST_ASSERT_NOT_NULL(output);
}
memset(ciphertext, 0, cfg->plaintext_length);
memset(output, 0, cfg->plai