错误:'AES_BLOCK_SIZE'未声明.无法在Linux中使用C编译OpenSSL

bho*_*ath 2 c linux openssl shared-libraries

我已经安装了最新版本的OpenSSL.我只是尝试编译并运行OpenSSL_aes程序.

在使用gcc -Wall openssl_aes.c -lcrypto进行编译时出现以下错误.我尽力解决了这个问题,但无法解决这个编译错误.

openssl_aes.c: In function ‘aes_encrypt’:
openssl_aes.c:51:22: error: ‘AES_BLOCK_SIZE’ undeclared (first use in this function)
   int c_len = *len + AES_BLOCK_SIZE, f_len = 0;
                      ^
openssl_aes.c:51:22: note: each undeclared identifier is reported only once for each function it appears in
openssl_aes.c: In function ‘aes_decrypt’:
openssl_aes.c:75:45: error: ‘AES_BLOCK_SIZE’ undeclared (first use in this function)
   unsigned char *plaintext = malloc(p_len + AES_BLOCK_SIZE);
                                             ^
Run Code Online (Sandbox Code Playgroud)

编辑:

当我#include<openssl/aes.h>按照@ martin 添加时,编译问题就解决了.

现在,gcc -Wall openssl_aes.c -lcrypto已成功编译.

但是,当我尝试运行程序(运行我使用 - ./a.out)时,我得到了以下错误 分段错误(核心转储)

谁能帮助我解决这个问题并运行我的程序?我只想使用OpenSSL执行简单的加密/解密.我在Fedora 19下使用GCC.

提前致谢.

Mar*_*nov 11

您可能不包括openssl/aes.h,AES_BLOCK_SIZE如下所示:#define AES_BLOCK_SIZE 16.所以要确保你有:

#include <openssl/aes.h>
Run Code Online (Sandbox Code Playgroud)

在你的文件中.

  • 因为代码的使用是$> ./ a.out <key_data> (2认同)