Encryption 仅从Polarssl运行aes的文件

Encryption 仅从Polarssl运行aes的文件,encryption,aes,polarssl,Encryption,Aes,Polarssl,我试图在我的程序中只使用aes。我已经复制了这些文件 配置.h aes.h 哈维热 转到文件夹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

我试图在我的程序中只使用aes。我已经复制了这些文件

  • 配置.h
  • aes.h
  • 哈维热
  • 转到文件夹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;
    }
    

    在头文件旁边,您还需要.c文件!(aes.c,havege.c)并在代码中编译它们

    在执行方面:
    *你确定要使用HAVEGE吗?对其有效性有很多疑问(取决于您运行的系统),标准化似乎是更好的选择。

    我认为您的错误与链接到Aes和Havege文件有关。您的编译器无法识别它们! 它们是否与主文件夹位于同一文件夹中?如果它们位于同一文件夹中,则从顶部的headerfile名称中删除“polarssl/”

    或者,在编译时,确保也包括aes.c和aes.h。我发现由于这个原因,我得到了同样的错误。我只是在编译中加入了aes.h。 范例

    $terminal: gcc main.c aes.h aes.c -o encrypt
    
    只是想知道? 如果您只想使用aes,为什么要尝试使用havege.h

    $terminal: gcc main.c aes.h aes.c -o encrypt