我试图在我的程序中只使用aes。我复制了这些文件
到文件夹polarssl。但是当我运行程序的时候
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "polarssl/aes.h"
#include "polarssl/havege.h"
int main()
{
char buff[2][64] = {"ABCDEFGHIJKLMN", ""};
havege_state hs;
int retval;
unsigned char IV[16];
unsigned char IV2[16];
unsigned char key[32];
aes_context enc_ctx;
aes_context dec_ctx;
havege_init(&hs);
havege_random(&hs, IV, 16);
havege_random(&hs, key, 32);
strncpy(IV, IV2, 16); //copy IV
aes_setkey_enc(&enc_ctx, key, 256);
aes_setkey_dec(&dec_ctx, key, 256);
//encrypt
aes_crypt_cbc(&enc_ctx, AES_ENCRYPT, 64, IV, buff[0], buff[1]);
printf("Before encrypt:%s\n", buff[0]);
//decrypt
aes_crypt_cbc(&dec_ctx, AES_DECRYPT, 64, IV2, buff[1],buff[0]);
printf("After decrypt:%s\n", buff[0]);
return 0;
}我收到错误了
In function `main':
ex.c:(.text+0x68): undefined reference to `havege_init'
ex.c:(.text+0x86): undefined reference to `havege_random'
ex.c:(.text+0xa4): undefined reference to `havege_random'
ex.c:(.text+0xe0): undefined reference to `aes_setkey_enc'
ex.c:(.text+0xfe): undefined reference to `aes_setkey_dec'
ex.c:(.text+0x133): undefined reference to `aes_crypt_cbc'
ex.c:(.text+0x17e): undefined reference to `aes_crypt_cbc'
collect2: error: ld returned 1 exit status发布于 2013-12-22 12:20:28
在头文件旁边,您还需要.c文件!并在代码中编译这些代码。
在实现方面:*您确定要使用HAVEGE吗?对于它的有效性有很多疑问(取决于你运行的系统),标准化的CTR-DRBG似乎是一个更好的选择。
发布于 2014-01-13 15:28:12
我认为您的错误与链接到Aes和哈瓦格文件有关。你的编译器不认识他们!它们和主文件夹在同一个文件夹里吗?如果它们位于同一个文件夹中,则从顶部的头文件名中移除"polarssl/“。
或者,在编译过程中,请确保包含美学.c和美学.h。我发现,由于这个原因,我也犯了同样的错误。我在编撰时只包括了美学。示例
$terminal: gcc main.c aes.h aes.c -o encrypt只是好奇?如果你只想使用aes,你为什么要使用have.h?
https://stackoverflow.com/questions/20725704
复制相似问题