neocturne / fastd

Fast and Secure Tunnelling Daemon
Other
115 stars 16 forks source link

cipher: fix OpenSSL linking for aes128-ctr #8

Closed kaechele closed 4 years ago

kaechele commented 4 years ago

Signed-off-by: Felix Kaechele felix@kaechele.ca

neocturne commented 4 years ago

This seems unnecessary - OPENSSL_CRYPTO_LIBRARY is always linked when it is set.

kaechele commented 4 years ago

Yet, without this patch fastd fails to compile on Fedora 32:

[100%] Linking C executable fastd
cd /home/felix/rpmbuild/BUILD/fastd-19/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/fastd.dir/link.txt --verbose=1
/usr/lib64/ccache/cc -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection  -Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -rdynamic -pthread     CMakeFiles/fastd.dir/android.c.o CMakeFiles/fastd.dir/async.c.o CMakeFiles/fastd.dir/capabilities.c.o CMakeFiles/fastd.dir/config.c.o CMakeFiles/fastd.dir/handshake.c.o CMakeFiles/fastd.dir/hkdf_sha256.c.o CMakeFiles/fastd.dir/fastd.c.o CMakeFiles/fastd.dir/iface.c.o CMakeFiles/fastd.dir/lex.c.o CMakeFiles/fastd.dir/log.c.o CMakeFiles/fastd.dir/options.c.o CMakeFiles/fastd.dir/peer.c.o CMakeFiles/fastd.dir/peer_hashtable.c.o CMakeFiles/fastd.dir/poll.c.o CMakeFiles/fastd.dir/pqueue.c.o CMakeFiles/fastd.dir/random.c.o CMakeFiles/fastd.dir/receive.c.o CMakeFiles/fastd.dir/resolve.c.o CMakeFiles/fastd.dir/send.c.o CMakeFiles/fastd.dir/sha256.c.o CMakeFiles/fastd.dir/shell.c.o CMakeFiles/fastd.dir/socket.c.o CMakeFiles/fastd.dir/status.c.o CMakeFiles/fastd.dir/task.c.o CMakeFiles/fastd.dir/time.c.o CMakeFiles/fastd.dir/vector.c.o CMakeFiles/fastd.dir/verify.c.o CMakeFiles/fastd.dir/__/gen/generated/config.yy.c.o  -o fastd  protocols/libprotocols.a methods/libmethods.a crypto/cipher/libciphers.a crypto/mac/libmacs.a -lcap -luecc -lsodium -lcrypto -ljson-c methods/null/libmethod_null.a methods/cipher_test/libmethod_cipher_test.a methods/composed_gmac/libmethod_composed_gmac.a methods/composed_umac/libmethod_composed_umac.a methods/generic_gmac/libmethod_generic_gmac.a methods/generic_poly1305/libmethod_generic_poly1305.a methods/generic_umac/libmethod_generic_umac.a methods/libmethod_common.a crypto/cipher/aes128_ctr/libcipher_aes128_ctr.a crypto/cipher/aes128_ctr/openssl/libcipher_aes128_ctr_openssl.a crypto/cipher/null/libcipher_null.a crypto/cipher/null/memcpy/libcipher_null_memcpy.a crypto/cipher/salsa2012/libcipher_salsa2012.a crypto/cipher/salsa2012/xmm/libcipher_salsa2012_xmm.a crypto/cipher/salsa2012/nacl/libcipher_salsa2012_nacl.a crypto/cipher/salsa20/libcipher_salsa20.a crypto/cipher/salsa20/xmm/libcipher_salsa20_xmm.a crypto/cipher/salsa20/nacl/libcipher_salsa20_nacl.a crypto/mac/ghash/libmac_ghash.a crypto/mac/ghash/pclmulqdq/libmac_ghash_pclmulqdq.a crypto/mac/ghash/builtin/libmac_ghash_builtin.a crypto/mac/uhash/libmac_uhash.a crypto/mac/uhash/builtin/libmac_uhash_builtin.a -lsodium 
/usr/bin/ld: crypto/cipher/aes128_ctr/openssl/libcipher_aes128_ctr_openssl.a(aes128_ctr_openssl.c.o): in function `aes128_ctr_free':
/home/felix/rpmbuild/BUILD/fastd-19/src/crypto/cipher/aes128_ctr/openssl/aes128_ctr_openssl.c:60: undefined reference to `EVP_CIPHER_CTX_free'
/usr/bin/ld: crypto/cipher/aes128_ctr/openssl/libcipher_aes128_ctr_openssl.a(aes128_ctr_openssl.c.o): in function `aes128_ctr_crypt':
/home/felix/rpmbuild/BUILD/fastd-19/src/crypto/cipher/aes128_ctr/openssl/aes128_ctr_openssl.c:42: undefined reference to `EVP_EncryptInit_ex'
/usr/bin/ld: /home/felix/rpmbuild/BUILD/fastd-19/src/crypto/cipher/aes128_ctr/openssl/aes128_ctr_openssl.c:45: undefined reference to `EVP_EncryptUpdate'
/usr/bin/ld: /home/felix/rpmbuild/BUILD/fastd-19/src/crypto/cipher/aes128_ctr/openssl/aes128_ctr_openssl.c:48: undefined reference to `EVP_EncryptFinal'
/usr/bin/ld: crypto/cipher/aes128_ctr/openssl/libcipher_aes128_ctr_openssl.a(aes128_ctr_openssl.c.o): in function `aes128_ctr_init':
/home/felix/rpmbuild/BUILD/fastd-19/src/crypto/cipher/aes128_ctr/openssl/aes128_ctr_openssl.c:30: undefined reference to `EVP_CIPHER_CTX_new'
/usr/bin/ld: /home/felix/rpmbuild/BUILD/fastd-19/src/crypto/cipher/aes128_ctr/openssl/aes128_ctr_openssl.c:31: undefined reference to `EVP_aes_128_ctr'
/usr/bin/ld: /home/felix/rpmbuild/BUILD/fastd-19/src/crypto/cipher/aes128_ctr/openssl/aes128_ctr_openssl.c:31: undefined reference to `EVP_EncryptInit_ex'
collect2: error: ld returned 1 exit status

Alternatively setting:

cmake
  -DCMAKE_AR=/usr/bin/gcc-ar \
  -DCMAKE_NM=/usr/bin/gcc-nm \
  -DCMAKE_RANLIB=/usr/bin/gcc-ranlib \
  .

works as a workaround.

neocturne commented 4 years ago

Ugh, it seems like CMake has its own ideas about link order, and doesn't keep the sorting used in target_link_libraries() :/

I'll look into this.

neocturne commented 4 years ago

Thanks, I could reproduce the issue on Arch with -Wl,--as-needed.