AES128 FPGA验证C程序
时间: 2024-03-16 20:40:54 浏览: 11
以下是一个基于FPGA的AES128加密算法验证程序的示例代码(用C语言编写):
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "aes.h"
void print_hex(uint8_t *data, int len) {
for (int i = 0; i < len; i++) {
printf("%02x ", data[i]);
}
printf("\n");
}
int main(int argc, char *argv[]) {
uint8_t key[16] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};
uint8_t plain_text[16] = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a};
uint8_t cipher_text[16];
AES128_ECB_encrypt(plain_text, key, cipher_text);
printf("plain_text: ");
print_hex(plain_text, 16);
printf("key: ");
print_hex(key, 16);
printf("cipher_text: ");
print_hex(cipher_text, 16);
return 0;
}
```
该测试程序使用了一个AES128加密算法的库文件,并调用了其中的AES128_ECB_encrypt函数,用于加密输入的明文。在程序运行过程中,设置了128位的密钥和待加密的明文,并打印出加密后的密文结果。需要注意的是,这里的密钥和明文需要使用16进制格式表示。