#include <mbedtls/aes.h>
#include <stdio.h>
const uint8_t AES_KEY[] = {
0x6d, 0x62, 0x65, 0x64, 0x54, 0x4c, 0x53, 0x2c,
0x20, 0x43, 0x69, 0x61, 0x6c, 0x6c, 0x6f, 0x21,
};
const uint8_t ENCRYPTED_DATA[] = {
0x45, 0xe8, 0xc5, 0x81, 0x25, 0xeb, 0x2e, 0x7b, 0xf1,
0x0c, 0x26, 0xa7, 0xa7, 0xb5, 0x28, 0x01, 0x78, 0xa4,
0x7c, 0x22, 0x4a, 0x0b, 0x62, 0x1a, 0x98, 0xbe, 0xfc,
};
int main(void) {
// AES context 结构
mbedtls_aes_context aes_ctx;
mbedtls_aes_init(&aes_ctx);
// 设置 AES 密钥(之后使用 AES-CFB 模式,因此应设置加密密钥而非解密密钥)
mbedtls_aes_setkey_enc(&aes_ctx, AES_KEY, 128);
// mbedtls_aes_setkey_dec(&aes_ctx, AES_KEY, 128);
size_t iv_off = 0;
uint8_t iv[16] = "mbedTLS, Ciallo!";
char data_out[sizeof ENCRYPTED_DATA];
mbedtls_aes_crypt_cfb128(&aes_ctx, MBEDTLS_AES_DECRYPT,
sizeof ENCRYPTED_DATA, &iv_off, iv,
ENCRYPTED_DATA, (uint8_t *)data_out);
mbedtls_aes_free(&aes_ctx);
puts(data_out);
}