我正在尝试使用 gcc4mbed 离线编译器为 mbed LPC1768 微控制器编译 mbedtls。
我想获得一个基本的 AESCBC 加密和解密示例来学习;我不确定我是否缺少包含或者我没有正确实例化。错误:
error: 'aes_setkey' was not declared in this scope
我正在知识库中的本指南中工作:知识库
代码:
#include "mbed.h"
#include "crypto/include/polarssl/config.h"
#include "crypto/include/polarssl/platform.h"
#include "crypto/include/polarssl/aes.h"
DigitalOut myled(LED1);
aes_context aes;
Serial pc(USBTX, USBRX);
unsigned char key[32] = { 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31,
0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31 };
unsigned char iv[16] = { 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31 };
unsigned char input[128] = { 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,
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 };
unsigned char output[128];
size_t input_len = 40;
size_t output_len = 0;
int main() {
pc.baud(115200);
aes_setkey(&aes, key, 256);
aes_crypt_cbc(&aes, AES_ENCRYPT, 24, iv, input, output);
pc.printf("\r\n\r\nFirst run\r\n");
/*while(1) {
myled = 1;
wait(0.2);
myled = 0;
wait(0.2);
}*/
}