【发布时间】:2016-05-09 21:59:32
【问题描述】:
我有一个 C 程序,它使用 OpenSSL 库中的 AES 例程。
我已经安装了必要的库 (libssl-dev)
我可以静态编译我的程序:
gcc -s -o aes aes.c /usr/lib/x86_64-linux-gnu/libcrypto.a
但是当我尝试动态编译它时,我得到以下错误:
$ gcc -s -o aes aes.c -lcrypto
/tmp/ccofFr4N.o: In function `encrypt':
aes.c:(.text+0x9f): undefined reference to `aesni_set_encrypt_key'
aes.c:(.text+0xd9): undefined reference to `aesni_cbc_encrypt'
aes.c:(.text+0x1a0): undefined reference to `aesni_cbc_encrypt'
/tmp/ccofFr4N.o: In function `decrypt':
aes.c:(.text+0x2d4): undefined reference to `aesni_set_decrypt_key'
aes.c:(.text+0x31e): undefined reference to `aesni_cbc_encrypt'
collect2: error: ld returned 1 exit status
为什么我不能用动态链接的 OpenSSL 编译我的程序?
更新
所以,这里是来自libssl-dev 的库:
$ ls /usr/lib/x86_64-linux-gnu/libcrypto.*
/usr/lib/x86_64-linux-gnu/libcrypto.a
/usr/lib/x86_64-linux-gnu/libcrypto.so
/usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
我注意到以下内容。当我用 grep 查找 AES 函数的名称时,只有 libcrypto.a 匹配。
$ grep aesni_set_encrypt_key /usr/lib/x86_64-linux-gnu/libcrypto.*
Binary file /usr/lib/x86_64-linux-gnu/libcrypto.a matches
/usr/lib/x86_64-linux-gnu/libcrypto.so 不应该也包含这些功能吗?
【问题讨论】:
-
您确定在搜索路径的某处没有一些不相关/旧的 libcrypto.so 吗?如果你说
nm -D /usr/lib/libcrypto.so | grep aesni_set_decrypt_key(或者你的 64 位库存储在哪里)会发生什么? -
@n.m. -
nm -D /usr/lib/x86_64-linux-gnu/libcrypto.so | grep aesni没有显示任何内容。 -
你的代码是否直接使用了那些未定义的函数?
-
@Ian Abbott - 是的,我直接在我的代码中调用这些函数,即:
aesni_cbc_encrypt(buffer, buffer, len, &aes_ks3, iv, AES_ENCRYPT);。 -
@MartinVegter - 在这种情况下,也许您应该使用 EVP 功能。见EVP Symmetric Encryption and Decryption。
标签: c linux gcc linker openssl