Communication error when using the AES256 example with OpenSSL

Using gcc 4.8.2 on Ubuntu 14.04 to compile the openssl example.

gcc SSLsample.c -lssl3

      

The component gives undefined characters:

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 the engines, but they are listed as alternative implementations, what is the main implementation?

The suggestions for linking with -lss and -lcrypt sound good, but take a 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

      

+3


source to share


2 answers


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

.



+6


source


 gcc SSLsample.c -lssl3

      

Using:

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

      

Library names and order. its libssl

and libcrypto

, and libcrypto

should follow libssl

, because it libssl

depends on libcrypto

.



You can also use static archives:

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

      

This avoids problems with linkers and library paths and LD_PRELOAD

runtime tricks .

+1


source







All Articles