Dov
Dov

Reputation: 8562

Link error when using AES256 example with OpenSSL

Using gcc 4.8.2 on Ubuntu 14.04 to compile openssl example.

gcc SSLsample.c -lssl3

The linker gives undefined symbols:

SSLsample.c:(.text+0x25d): undefined reference to `EVP_CIPHER_CTX_new'
SSLsample.c:(.text+0x272): undefined reference to `EVP_aes_256_cbc'
SSLsample.c:(.text+0x294): undefined reference to `EVP_DecryptInit_ex'
SSLsample.c:(.text+0x2bc): undefined reference to `EVP_DecryptUpdate'
SSLsample.c:(.text+0x2ed): undefined reference to `EVP_DecryptFinal_ex'
SSLsample.c:(.text+0x309): undefined reference to `EVP_CIPHER_CTX_free'
collect2: error: ld returned 1 exit status
make: *** [sample] Error 1

There are many libraries under engines, but they are listed as alternate implementations, what is the main implementation?

The suggestions to link with -lssl and -lcrypt sounded good, but look:

gcc SSLsample.c  -lssl -lcrypt
/tmp/cczNovmQ.o: In function `main':
SSLsample.c:(.text+0x4a): undefined reference to `ERR_load_crypto_strings'
SSLsample.c:(.text+0x4f): undefined reference to `OPENSSL_add_all_algorithms_no\
conf'
SSLsample.c:(.text+0x59): undefined reference to `OPENSSL_config'
SSLsample.c:(.text+0xc6): undefined reference to `BIO_dump_fp'
SSLsample.c:(.text+0x12c): undefined reference to `EVP_cleanup'
SSLsample.c:(.text+0x131): undefined reference to `ERR_free_strings'
/tmp/cczNovmQ.o: In function `handleErrors':
SSLsample.c:(.text+0x167): undefined reference to `ERR_print_errors_fp'
/tmp/cczNovmQ.o: In function `encrypt':
SSLsample.c:(.text+0x18c): undefined reference to `EVP_CIPHER_CTX_new'
SSLsample.c:(.text+0x1a1): undefined reference to `EVP_aes_256_cbc'
SSLsample.c:(.text+0x1c3): undefined reference to `EVP_EncryptInit_ex'
SSLsample.c:(.text+0x1eb): undefined reference to `EVP_EncryptUpdate'
SSLsample.c:(.text+0x21c): undefined reference to `EVP_EncryptFinal_ex'
SSLsample.c:(.text+0x238): undefined reference to `EVP_CIPHER_CTX_free'
/tmp/cczNovmQ.o: In function `decrypt':
SSLsample.c:(.text+0x25d): undefined reference to `EVP_CIPHER_CTX_new'
SSLsample.c:(.text+0x272): undefined reference to `EVP_aes_256_cbc'
SSLsample.c:(.text+0x294): undefined reference to `EVP_DecryptInit_ex'
SSLsample.c:(.text+0x2bc): undefined reference to `EVP_DecryptUpdate'
SSLsample.c:(.text+0x2ed): undefined reference to `EVP_DecryptFinal_ex'
SSLsample.c:(.text+0x309): undefined reference to `EVP_CIPHER_CTX_free'
collect2: error: ld returned 1 exit status

Upvotes: 6

Views: 16626

Answers (2)

user149341
user149341

Reputation:

Ciphers, such as AES256, and other encryption utilities are part of the libcrypto library; libssl is primarily concerned with the SSL/TLS protocol. Link with -lcrypto instead of -lssl3.

Upvotes: 10

jww
jww

Reputation: 102296

 gcc SSLsample.c -lssl3

Use:

gcc SSLsample.c -o sample.exe -lssl -lcrypto

The names and order of the library matters. its libssl and libcrypto, and libcrypto must follow libssl because libssl depends upon libcrypto.

You could also use static archives:

gcc SSLsample.c /usr/lib/libssl.a /usr/lib/libcrypto.a -o sample.exe

That avoids problems with linker and library paths, and LD_PRELOAD tricks at runtime.

Upvotes: 5

Related Questions