4

I have a C program, which is using AES routines from the OpenSSL library. I have the necessary library installed (libssl-dev)

I can compile my program statically:

gcc -s -o aes aes.c /usr/lib/x86_64-linux-gnu/libcrypto.a

but when i try to compile it dynamically, I get following error:

$ 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

Why can't I compile my program with OpenSSL linked dynamically ?

UPDATE

So, here are the libraries from 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

I noticed the following. When I grep them for the name of the AES function, only libcrypto.a matches.

$ grep aesni_set_encrypt_key /usr/lib/x86_64-linux-gnu/libcrypto.*
Binary file /usr/lib/x86_64-linux-gnu/libcrypto.a matches

Shouldn't /usr/lib/x86_64-linux-gnu/libcrypto.so contain these functions as well ?

Martin Vegter
  • 136
  • 9
  • 32
  • 56
  • Are you sure you don't have some unrelated/old libcrypto.so somewhere in the search path? What happens if you say `nm -D /usr/lib/libcrypto.so | grep aesni_set_decrypt_key` (or where are your 64-bit libraries stored)? – n. m. could be an AI Feb 01 '16 at 13:11
  • @n.m. - `nm -D /usr/lib/x86_64-linux-gnu/libcrypto.so | grep aesni` does not show nothing. – Martin Vegter Feb 01 '16 at 13:21
  • Does your code use those undefined functions directly? – Ian Abbott Feb 01 '16 at 13:24
  • @Ian Abbott - yes, I am calling those functions directly in my code, ie: `aesni_cbc_encrypt(buffer, buffer, len, &aes_ks3, iv, AES_ENCRYPT);`. – Martin Vegter Feb 01 '16 at 13:26
  • @MartinVegter - aren't you supposed to use `AES_cbc_encrypt`, etc.? – Ian Abbott Feb 01 '16 at 13:32
  • @Ian Abbott - `AES_cbc_encrypt` is 5 times slower, because it is not using the `AES_NI` instructions of my CPU. See my previous [question](http://stackoverflow.com/questions/34993514/program-linked-with-lcrypto-is-many-times-slower-than-openssl-command). – Martin Vegter Feb 01 '16 at 13:36
  • 1
    @MartinVegter - in that case, perhaps you should be using the EVP functions. See [EVP Symmetric Encryption and Decryption](https://wiki.openssl.org/index.php/EVP_Symmetric_Encryption_and_Decryption). – Ian Abbott Feb 01 '16 at 14:11
  • Are you sure `/usr/lib/x86_64-linux-gnu/libcrypto.a` is the correct library to link? – dlmeetei Feb 01 '16 at 14:16
  • @Deleisha - I am sure the program compiled using `gcc -s -o aes aes.c /usr/lib/x86_64-linux-gnu/libcrypto.a` works properly. The only problem is, that being statically linked, it is rather large. – Martin Vegter Feb 01 '16 at 14:20
  • On my system, `nm -D /usr/lib64/libcrypto.so | fgrep aesni` prints all AES NI symbols as defined. It's an old system with libcrypto.so.0.9.8. I imagine newer versions should have them too. Are you sure your libcrypt.so really belongs to libssl-dev and its version corresponds to libcrypto.a? – n. m. could be an AI Feb 01 '16 at 14:46
  • `https://rt.openssl.org/Ticket/Display.html?id=2503&user=guest&pass=guest` could this be the issue – dlmeetei Feb 01 '16 at 15:17

1 Answers1

0

most likely the /usr/lib/x86_64-linux-gnu/ is not part of the compiler search path.

Suggest, before the -lcrypto to insert the parameter: -L/usr/lib/x86_64-linux-gnu/

user3629249
  • 16,402
  • 1
  • 16
  • 17
  • unfortunately, this does not help. I still get the same error. Besides, see my update. It looks as if the functions were not exported by the libcrypto shared library. – Martin Vegter Feb 02 '16 at 09:11