Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenSSL 1.1 - tests* BIGNUM - BN_init -> BN_new #7086

Closed
vindicatorr opened this issue Nov 24, 2015 · 26 comments · Fixed by #7095
Closed

OpenSSL 1.1 - tests* BIGNUM - BN_init -> BN_new #7086

vindicatorr opened this issue Nov 24, 2015 · 26 comments · Fixed by #7095
Labels

Comments

@vindicatorr
Copy link

https://wiki.openssl.org/index.php/Manual:BN_new(3)

https://www.openssl.org/docs/man1.0.2/crypto/bn.html
void BN_init(BIGNUM *);

https://www.openssl.org/docs/manmaster/crypto/bn.html
BIGNUM *BN_new(void);

  CXX      test/test_test_bitcoin-scriptnum_tests.o
In file included from test/scriptnum_tests.cpp:5:0:
test/bignum.h:26:24: error: invalid use of incomplete type ‘BIGNUM {aka struct bignum_st}’
 class CBigNum : public BIGNUM
                        ^
In file included from /usr/local/ssl/include/openssl/bn.h:132:0,
                 from test/bignum.h:16,
                 from test/scriptnum_tests.cpp:5:
/usr/local/ssl/include/openssl/ossl_typ.h:120:16: error: forward declaration of ‘BIGNUM {aka struct bignum_st}’
 typedef struct bignum_st BIGNUM;
                ^
In file included from test/scriptnum_tests.cpp:5:0:
test/bignum.h: In constructor ‘CBigNum::CBigNum()’:
test/bignum.h:31:21: error: ‘BN_init’ was not declared in this scope
         BN_init(this);
                     ^
test/bignum.h: In copy constructor ‘CBigNum::CBigNum(const CBigNum&)’:
test/bignum.h:36:21: error: ‘BN_init’ was not declared in this scope
         BN_init(this);
                     ^
test/bignum.h:37:30: error: cannot convert ‘CBigNum*’ to ‘BIGNUM* {aka bignum_st*}’ for argument ‘1’ to ‘BIGNUM* BN_copy(BIGNUM*, const BIGNUM*)’
         if (!BN_copy(this, &b))
                              ^
test/bignum.h:39:31: error: cannot convert ‘CBigNum*’ to ‘BIGNUM* {aka bignum_st*}’ for argument ‘1’ to ‘void BN_clear_free(BIGNUM*)’
             BN_clear_free(this);
                               ^
test/bignum.h: In member function ‘CBigNum& CBigNum::operator=(const CBigNum&)’:
test/bignum.h:46:30: error: cannot convert ‘CBigNum*’ to ‘BIGNUM* {aka bignum_st*}’ for argument ‘1’ to ‘BIGNUM* BN_copy(BIGNUM*, const BIGNUM*)’
         if (!BN_copy(this, &b))
                              ^
test/bignum.h: In destructor ‘CBigNum::~CBigNum()’:
test/bignum.h:53:27: error: cannot convert ‘CBigNum*’ to ‘BIGNUM* {aka bignum_st*}’ for argument ‘1’ to ‘void BN_clear_free(BIGNUM*)’
         BN_clear_free(this);
                           ^
test/bignum.h: In constructor ‘CBigNum::CBigNum(long long int)’:
test/bignum.h:56:49: error: ‘BN_init’ was not declared in this scope
     CBigNum(long long n)          { BN_init(this); setint64(n); }
                                                 ^
test/bignum.h: In constructor ‘CBigNum::CBigNum(const std::vector<unsigned char>&)’:
test/bignum.h:60:21: error: ‘BN_init’ was not declared in this scope
         BN_init(this);
                     ^
test/bignum.h: In member function ‘int CBigNum::getint() const’:
test/bignum.h:66:38: error: cannot convert ‘const CBigNum*’ to ‘const BIGNUM* {aka const bignum_st*}’ for argument ‘1’ to ‘unsigned int BN_get_word(const BIGNUM*)’
         BN_ULONG n = BN_get_word(this);
                                      ^
test/bignum.h:67:33: error: cannot convert ‘const CBigNum*’ to ‘const BIGNUM* {aka const bignum_st*}’ for argument ‘1’ to ‘int BN_is_negative(const BIGNUM*)’
         if (!BN_is_negative(this))
                                 ^
In file included from test/scriptnum_tests.cpp:5:0:
test/bignum.h: In member function ‘void CBigNum::setint64(int64_t)’:
test/bignum.h:115:37: error: cannot convert ‘CBigNum*’ to ‘BIGNUM* {aka bignum_st*}’ for argument ‘3’ to ‘BIGNUM* BN_mpi2bn(const unsigned char*, int, BIGNUM*)’
         BN_mpi2bn(pch, p - pch, this);
                                     ^
test/bignum.h: In member function ‘void CBigNum::setvch(const std::vector<unsigned char>&)’:
test/bignum.h:130:46: error: cannot convert ‘CBigNum*’ to ‘BIGNUM* {aka bignum_st*}’ for argument ‘3’ to ‘BIGNUM* BN_mpi2bn(const unsigned char*, int, BIGNUM*)’
         BN_mpi2bn(&vch2[0], vch2.size(), this);
                                              ^
test/bignum.h: In member function ‘std::vector<unsigned char> CBigNum::getvch() const’:
test/bignum.h:135:50: error: cannot convert ‘const CBigNum*’ to ‘const BIGNUM* {aka const bignum_st*}’ for argument ‘1’ to ‘int BN_bn2mpi(const BIGNUM*, unsigned char*)’
         unsigned int nSize = BN_bn2mpi(this, NULL);
                                                  ^
test/bignum.h:139:32: error: cannot convert ‘const CBigNum*’ to ‘const BIGNUM* {aka const bignum_st*}’ for argument ‘1’ to ‘int BN_bn2mpi(const BIGNUM*, unsigned char*)’
         BN_bn2mpi(this, &vch[0]);
                                ^
test/bignum.h: In function ‘const CBigNum operator+(const CBigNum&, const CBigNum&)’:
test/bignum.h: In member function ‘void CBigNum::setint64(int64_t)’:
test/bignum.h:115:37: error: cannot convert ‘CBigNum*’ to ‘BIGNUM* {aka bignum_st*}’ for argument ‘3’ to ‘BIGNUM* BN_mpi2bn(const unsigned char*, int, BIGNUM*)’
         BN_mpi2bn(pch, p - pch, this);
                                     ^
test/bignum.h: In member function ‘void CBigNum::setvch(const std::vector<unsigned char>&)’:
test/bignum.h:130:46: error: cannot convert ‘CBigNum*’ to ‘BIGNUM* {aka bignum_st*}’ for argument ‘3’ to ‘BIGNUM* BN_mpi2bn(const unsigned char*, int, BIGNUM*)’
         BN_mpi2bn(&vch2[0], vch2.size(), this);
                                              ^
test/bignum.h: In member function ‘std::vector<unsigned char> CBigNum::getvch() const’:
test/bignum.h:135:50: error: cannot convert ‘const CBigNum*’ to ‘const BIGNUM* {aka const bignum_st*}’ for argument ‘1’ to ‘int BN_bn2mpi(const BIGNUM*, unsigned char*)’
         unsigned int nSize = BN_bn2mpi(this, NULL);
                                                  ^
test/bignum.h:139:32: error: cannot convert ‘const CBigNum*’ to ‘const BIGNUM* {aka const bignum_st*}’ for argument ‘1’ to ‘int BN_bn2mpi(const BIGNUM*, unsigned char*)’
         BN_bn2mpi(this, &vch[0]);
                                ^
test/bignum.h: In function ‘const CBigNum operator+(const CBigNum&, const CBigNum&)’:
test/bignum.h:153:27: error: cannot convert ‘CBigNum*’ to ‘BIGNUM* {aka bignum_st*}’ for argument ‘1’ to ‘int BN_add(BIGNUM*, const BIGNUM*, const BIGNUM*)’
     if (!BN_add(&r, &a, &b))
                           ^
test/bignum.h: In function ‘const CBigNum operator-(const CBigNum&, const CBigNum&)’:
test/bignum.h:161:27: error: cannot convert ‘CBigNum*’ to ‘BIGNUM* {aka bignum_st*}’ for argument ‘1’ to ‘int BN_sub(BIGNUM*, const BIGNUM*, const BIGNUM*)’
     if (!BN_sub(&r, &a, &b))
                           ^
test/bignum.h: In function ‘const CBigNum operator-(const CBigNum&)’:
test/bignum.h:169:43: error: cannot convert ‘CBigNum*’ to ‘const BIGNUM* {aka const bignum_st*}’ for argument ‘1’ to ‘int BN_is_negative(const BIGNUM*)’
     BN_set_negative(&r, !BN_is_negative(&r));
                                           ^
test/bignum.h: In function ‘bool operator==(const CBigNum&, const CBigNum&)’:
test/bignum.h:173:83: error: cannot convert ‘const CBigNum*’ to ‘const BIGNUM* {aka const bignum_st*}’ for argument ‘1’ to ‘int BN_cmp(const BIGNUM*, const BIGNUM*)’
 inline bool operator==(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) == 0); }
                                                                                   ^
test/bignum.h: In function ‘bool operator!=(const CBigNum&, const CBigNum&)’:
test/bignum.h:174:83: error: cannot convert ‘const CBigNum*’ to ‘const BIGNUM* {aka const bignum_st*}’ for argument ‘1’ to ‘int BN_cmp(const BIGNUM*, const BIGNUM*)’
 inline bool operator!=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) != 0); }
                                                                                   ^
test/bignum.h: In function ‘bool operator<=(const CBigNum&, const CBigNum&)’:
test/bignum.h:175:83: error: cannot convert ‘const CBigNum*’ to ‘const BIGNUM* {aka const bignum_st*}’ for argument ‘1’ to ‘int BN_cmp(const BIGNUM*, const BIGNUM*)’
 inline bool operator<=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) <= 0); }
                                                                                   ^
test/bignum.h: In function ‘bool operator>=(const CBigNum&, const CBigNum&)’:
test/bignum.h:176:83: error: cannot convert ‘const CBigNum*’ to ‘const BIGNUM* {aka const bignum_st*}’ for argument ‘1’ to ‘int BN_cmp(const BIGNUM*, const BIGNUM*)’
 inline bool operator>=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) >= 0); }
                                                                                   ^
test/bignum.h: In function ‘bool operator<(const CBigNum&, const CBigNum&)’:
test/bignum.h:177:83: error: cannot convert ‘const CBigNum*’ to ‘const BIGNUM* {aka const bignum_st*}’ for argument ‘1’ to ‘int BN_cmp(const BIGNUM*, const BIGNUM*)’
 inline bool operator<(const CBigNum& a, const CBigNum& b)  { return (BN_cmp(&a, &b) < 0); }
                                                                                   ^
test/bignum.h: In function ‘bool operator>(const CBigNum&, const CBigNum&)’:test/bignum.h:174:83: error: cannot convert ‘const CBigNum*’ to ‘const BIGNUM* {aka const bignum_st*}’ for argument ‘1’ to ‘int BN_cmp(const BIGNUM*, const BIGNUM*)’
 inline bool operator!=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) != 0); }
                                                                                   ^
test/bignum.h: In function ‘bool operator<=(const CBigNum&, const CBigNum&)’:
test/bignum.h:175:83: error: cannot convert ‘const CBigNum*’ to ‘const BIGNUM* {aka const bignum_st*}’ for argument ‘1’ to ‘int BN_cmp(const BIGNUM*, const BIGNUM*)’
 inline bool operator<=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) <= 0); }
                                                                                   ^
test/bignum.h: In function ‘bool operator>=(const CBigNum&, const CBigNum&)’:
test/bignum.h:176:83: error: cannot convert ‘const CBigNum*’ to ‘const BIGNUM* {aka const bignum_st*}’ for argument ‘1’ to ‘int BN_cmp(const BIGNUM*, const BIGNUM*)’
 inline bool operator>=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) >= 0); }
                                                                                   ^
test/bignum.h: In function ‘bool operator<(const CBigNum&, const CBigNum&)’:
test/bignum.h:177:83: error: cannot convert ‘const CBigNum*’ to ‘const BIGNUM* {aka const bignum_st*}’ for argument ‘1’ to ‘int BN_cmp(const BIGNUM*, const BIGNUM*)’
 inline bool operator<(const CBigNum& a, const CBigNum& b)  { return (BN_cmp(&a, &b) < 0); }
                                                                                   ^
test/bignum.h: In function ‘bool operator>(const CBigNum&, const CBigNum&)’:
test/bignum.h:178:83: error: cannot convert ‘const CBigNum*’ to ‘const BIGNUM* {aka const bignum_st*}’ for argument ‘1’ to ‘int BN_cmp(const BIGNUM*, const BIGNUM*)’
 inline bool operator>(const CBigNum& a, const CBigNum& b)  { return (BN_cmp(&a, &b) > 0); }
                                                                                   ^
In file included from test/scriptnum_tests.cpp:5:0:
test/bignum.h: In member function ‘int CBigNum::getint() const’:
test/bignum.h:71:5: warning: control reaches end of non-void function [-Wreturn-type]
     }
     ^
In file included from test/scriptnum_tests.cpp:5:0:
test/bignum.h: In function ‘bool operator==(const CBigNum&, const CBigNum&)’:
test/bignum.h:173:92: warning: control reaches end of non-void function [-Wreturn-type]
 inline bool operator==(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) == 0); }
                                                                                            ^
test/bignum.h: In function ‘bool operator!=(const CBigNum&, const CBigNum&)’:
test/bignum.h:174:92: warning: control reaches end of non-void function [-Wreturn-type]
 inline bool operator!=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) != 0); }
                                                                                            ^
test/bignum.h: In function ‘bool operator<(const CBigNum&, const CBigNum&)’:
test/bignum.h:177:91: warning: control reaches end of non-void function [-Wreturn-type]
 inline bool operator<(const CBigNum& a, const CBigNum& b)  { return (BN_cmp(&a, &b) < 0); }
                                                                                           ^
test/bignum.h: In function ‘bool operator>(const CBigNum&, const CBigNum&)’:
test/bignum.h:178:91: warning: control reaches end of non-void function [-Wreturn-type]
 inline bool operator>(const CBigNum& a, const CBigNum& b)  { return (BN_cmp(&a, &b) > 0); }
                                                                                           ^
test/bignum.h: In function ‘bool operator>=(const CBigNum&, const CBigNum&)’:
test/bignum.h:176:92: warning: control reaches end of non-void function [-Wreturn-type]
 inline bool operator>=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) >= 0); }
                                                                                            ^
test/bignum.h: In function ‘bool operator<=(const CBigNum&, const CBigNum&)’:
test/bignum.h:175:92: warning: control reaches end of non-void function [-Wreturn-type]
 inline bool operator<=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) <= 0); }
                                                                                            ^
At global scope:
cc1plus: warning: unrecognized command line option "-Wno-self-assign"
Makefile:6494: recipe for target 'test/test_test_bitcoin-scriptnum_tests.o' failed
make[2]: *** [test/test_test_bitcoin-scriptnum_tests.o] Error 1
@laanwj laanwj added the Tests label Nov 24, 2015
@laanwj
Copy link
Member

laanwj commented Nov 24, 2015

Maybe it's time to disable this test?

It's useful testing to compare behavior against OpenSSL's BN, however at some point - probably in the 0.13 cycle (#5949, #5885) - it will be the only place where OpenSSL is still used.

@dcousens
Copy link
Contributor

If this isn't actually being used in the library, the test may be better suited for libsecp256k1 and tested there.

@theuni
Copy link
Member

theuni commented Nov 25, 2015

Agree with @laanwj. These were added to ensure consensus behavior against the pre-0.10 bignum implementation. At this point we'd likely take the new behavior anyway if an inconsistency was discovered.

@laanwj
Copy link
Member

laanwj commented Nov 25, 2015

If this isn't actually being used in the library, the test may be better suited for libsecp256k1 and tested there.

From what I've heard, secp256k1 already does tons of much better tests :)

As @theuni says the test is there to compare our scriptnum values' behavior with OpenSSL. This mattered for 0.10, but indeed, at this point if OpenSSL starts to diverge, we'd take our behavior.

If we still want to do a cross-version test like this usefully we should compare against, say, 0.10's post-OpenSSL CScriptNum implementation.

@gmaxwell
Copy link
Contributor

@dcousens these aren't related to libsec256k1 at all. They're tests of the number implementation used in script, which long ago used OpenSSL but does no more.

I agree these could be removed, today the only value they provide is additional chances of catching our implementation changing between versions. If they did turn up a disagreement with the current code now and OpenSSL, we'd ignore it: I don't believe the openssl based code is in widespread use on the network anymore. This would be better handled by copying an implementation (like wumpus says, 0.10's) into the tests.

laanwj added a commit to laanwj/bitcoin that referenced this issue Nov 25, 2015
Compare against the scriptnum from Bitcoin Core 0.10 instead of OpenSSL.
Closes bitcoin#7086.
@laanwj
Copy link
Member

laanwj commented Nov 26, 2015

Please help testing that #7095 and #7083 solve your compile issue, they're waiting on someone to check with openssl 1.1.

@vindicatorr
Copy link
Author

Sorry @laanwj but this is the first time I've had a request like that and don't know the standard way of testing those pull requests.
I "fetch"ed and "pull"ed

commit be281d8a83ca8fe7cf785a4608d1a8954b193191
Merge: 2b2ddc5 9cf6688
Author: Wladimir J. van der Laan <laanwj@gmail.com>
Date:   Thu Nov 26 08:32:38 2015 +0100

    Merge pull request #7087

but of course that wouldn't be it since those PR's are waiting to be merged into Master.

@laanwj
Copy link
Member

laanwj commented Nov 26, 2015

Start with master then:

git checkout -b test
git fetch https://github.com/bitcoin/bitcoin.git refs/pull/7083/head
git merge FETCH_HEAD
git fetch https://github.com/bitcoin/bitcoin.git refs/pull/7096/head
git merge FETCH_HEAD

Then you can test with the two pulls merged. When you're done, you can switch away from your new branch and delete it

git checkout master
git branch -D test

@vindicatorr
Copy link
Author

Nope

  CXX      wallet/libbitcoin_wallet_a-walletdb.o
  AR       libbitcoin_wallet.a
  CXXLD    bitcoind
libbitcoin_server.a(libbitcoin_server_a-init.o): In function `AppInit2(boost::thread_group&, CScheduler&)':
init.cpp:(.text+0xd5b4): undefined reference to `OpenSSL_version'
collect2: error: ld returned 1 exit status
Makefile:2749: recipe for target 'bitcoind' failed
make[2]: *** [bitcoind] Error 1

init.cpp

    if (fPrintToDebugLog)
        OpenDebugLog();

#if (OPENSSL_VERSION_NUMBER < 0x10100000L)
    LogPrintf("Using OpenSSL version %s\n", SSLeay_version(SSLEAY_VERSION));
#else
    LogPrintf("Using OpenSSL version %s\n", OpenSSL_version(OPENSSL_VERSION));
#endif

#ifdef ENABLE_WALLET
    LogPrintf("Using BerkeleyDB version %s\n", DbEnv::version(0, 0, 0));
#endif
    if (!fLogTimestamps)

crypto.h

# define OPENSSL_MALLOC_MAX_NELEMS(type)  (((1U<<(sizeof(int)*8-1))-1)/sizeof(type))

unsigned long OpenSSL_version_num(void);
const char *OpenSSL_version(int type);
# define OPENSSL_VERSION          0

libcrypto.pc

prefix=/usr/local/ssl
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: OpenSSL-libcrypto
Description: OpenSSL cryptography library
Version: 1.1.0-dev
Requires: 
Libs: -L${libdir} -lcrypto
Libs.private: -ldl
Cflags: -I${includedir}

(at first I messed up because I copied/pasted your commands without noticing you typed 7096 instead of 7095, not that it matters because 7083 should have been the fix regarding OpenSSL_version).

@maflcko
Copy link
Member

maflcko commented Nov 26, 2015

@vindicatorr Can you paste git log --oneline -5 and the commit hash of the version of openSSL you are using?

I am running openssl/openssl@3bbd1d6 and faf12bc. So I get:

$ src/bitcoind -regtest -printtoconsole |grep version
2015-11-26 16:07:22 Bitcoin version v0.11.99.0-faf12bc (2015-11-24 09:07:26 +0100)
2015-11-26 16:07:22 Using OpenSSL version OpenSSL 1.1.0-dev xx XXX xxxx

@vindicatorr
Copy link
Author

@MarcoFalke
bitcoin

# git log --oneline -5
34abe02 Merge commit 'refs/pull/7095/head' of https://github.com/bitcoin/bitcoin into test
3e1d277 Merge commit 'refs/pull/7083/head' of https://github.com/bitcoin/bitcoin into test
be281d8 Merge pull request #7087
4ec3561 Replace scriptnum_test's normative ScriptNum implementation
2b2ddc5 Merge pull request #7088

openssl

# git log --oneline -1
46ddbcf Fix a rebase error

@laanwj
Copy link
Member

laanwj commented Nov 27, 2015

Strange. It looks like it is linking against a different (older) OpenSSL than is described by the headers (one without OpenSSL_version).

@vindicatorr
Copy link
Author

For further completeness of my process:

$ ./autogen.sh
$ CFLAGS="-O3 -pipe -mtune=cortex-a15.cortex-a7 -march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4" \
CXXFLAGS="-O3 -pipe -mtune=cortex-a15.cortex-a7 -march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4" \
PKG_CONFIG_PATH="/usr/local/ssl/lib/pkgconfig" \
./configure --with-incompatible-bdb --without-gui
$ make

The same process I've done with OpenSSL 1.0.2 (and 1.1 with --disable-tests and edited init.cpp to comment version line)
I'm now in the middle of another make, but with V=1

@vindicatorr
Copy link
Author

And the error output with V=1

/usr/bin/ar cru libbitcoin_wallet.a wallet/libbitcoin_wallet_a-crypter.o wallet/libbitcoin_wallet_a-db.o wallet/libbitcoin_wallet_a-rpcdump.o wallet/libbitcoin_wallet_a-rpcwallet.o wallet/libbitcoin_wallet_a-wallet.o wallet/libbitcoin_wallet_a-wallet_ismine.o wallet/libbitcoin_wallet_a-walletdb.o  
/usr/bin/ranlib libbitcoin_wallet.a
/bin/bash ../libtool  --tag=CXX   --mode=link g++ -Wstack-protector -fstack-protector-all -fPIE -O3 -pipe -mtune=cortex-a15.cortex-a7 -march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4  -pthread  -Wl,-z,relro -Wl,-z,now -pie   -o bitcoind bitcoind-bitcoind.o  libbitcoin_server.a libbitcoin_common.a univalue/libunivalue.la libbitcoin_util.a crypto/libbitcoin_crypto.a ./leveldb/libleveldb.a ./leveldb/libmemenv.a secp256k1/libsecp256k1.la  libbitcoin_wallet.a -L/usr/lib/arm-linux-gnueabihf -lboost_system -lboost_filesystem -lboost_program_options -lboost_thread -lboost_chrono -ldb_cxx -L/usr/local/ssl/lib -lssl  -L/usr/local/ssl/lib -lcrypto   -levent_pthreads -levent  -levent  -lanl 
libtool: link: g++ -Wstack-protector -fstack-protector-all -fPIE -O3 -pipe -mtune=cortex-a15.cortex-a7 -march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4 -pthread -Wl,-z -Wl,relro -Wl,-z -Wl,now -pie -o bitcoind bitcoind-bitcoind.o  libbitcoin_server.a libbitcoin_common.a univalue/.libs/libunivalue.a libbitcoin_util.a crypto/libbitcoin_crypto.a ./leveldb/libleveldb.a ./leveldb/libmemenv.a secp256k1/.libs/libsecp256k1.a libbitcoin_wallet.a -L/usr/lib/arm-linux-gnueabihf -lboost_system -lboost_filesystem -lboost_program_options -lboost_thread -lboost_chrono -ldb_cxx -L/usr/local/ssl/lib -lssl -lcrypto -levent_pthreads -levent -lanl -pthread
libbitcoin_server.a(libbitcoin_server_a-init.o): In function `AppInit2(boost::thread_group&, CScheduler&)':
init.cpp:(.text+0xd5b4): undefined reference to `OpenSSL_version'
collect2: error: ld returned 1 exit status
Makefile:2749: recipe for target 'bitcoind' failed
make[2]: *** [bitcoind] Error 1

@maflcko
Copy link
Member

maflcko commented Nov 27, 2015

How did you setup OpenSSL?

@vindicatorr
Copy link
Author

./config threads shared zlib-dynamic
make
make install
ln -s /usr/local/ssl/bin/openssl /usr/local/bin/openssl

And "openssl version" outputs the 1.1
I will also add that I edit the ./Configurations/10-main.conf and add

cflags           => "-O3 -pipe -mtune=cortex-a15.cortex-a7 -march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4 -Wall",

EDIT: and not that it should matter, but you pulled yours from github and I pulled mine straight from git://git.openssl.org/openssl.git

@vindicatorr
Copy link
Author

@MarcoFalke I'm just perplexed. I deleted /usr/local/ssl, rebooted, reinstalled openssl, rebooted, rebuilt bitcoin and I'm still getting that linker error.
"libtool: link: g++" has "-L/usr/local/ssl/lib" and "-lcrypto", so I have no idea why it's saying that "OpenSSL_version is undefined.
Grep even finds matches in "openssl/crypto.h", "bin/openssl","lib/libcrypto.a" and "lib/libcrypto.so.1.1"

@laanwj
Copy link
Member

laanwj commented Dec 1, 2015

@vindicatorr Are there other openSSL libraries installed on your system? My guess is that it tries linking against those.

Note that for linking you need a libcrypto.so and libssl.so in your -L path (usually a symbolic link). Versioned .so.x.y or .so.x won't do, those are only used at run time.

@vindicatorr
Copy link
Author

~# find {/lib,/usr} -name libcrypto.so
/usr/local/lib/libcrypto.so
/usr/local/ssl/lib/libcrypto.so
/usr/lib/arm-linux-gnueabihf/libcrypto.so

~# ls -la /usr/local/lib/lib{crypto,ssl}.*
-rw-r--r-- 1 root root 3098806 Aug 15 09:03 /usr/local/lib/libcrypto.a
lrwxrwxrwx 1 root root      16 Aug 25 20:06 /usr/local/lib/libcrypto.so -> libcrypto.so.1.1
-r-xr-xr-x 1 root root 2116660 Aug 15 09:03 /usr/local/lib/libcrypto.so.1.1
-rw-r--r-- 1 root root  498822 Aug 15 09:03 /usr/local/lib/libssl.a
lrwxrwxrwx 1 root root      13 Aug 25 20:07 /usr/local/lib/libssl.so -> libssl.so.1.1
-r-xr-xr-x 1 root root  407608 Aug 15 09:03 /usr/local/lib/libssl.so.1.1

~# ls -la /usr/local/ssl/lib/lib*.so*
lrwxrwxrwx 1 root root      16 Nov 28 03:33 /usr/local/ssl/lib/libcrypto.so -> libcrypto.so.1.1
-r-xr-xr-x 1 root root 1944804 Nov 28 03:33 /usr/local/ssl/lib/libcrypto.so.1.1
lrwxrwxrwx 1 root root      13 Nov 28 03:33 /usr/local/ssl/lib/libssl.so -> libssl.so.1.1
-r-xr-xr-x 1 root root  365308 Nov 28 03:33 /usr/local/ssl/lib/libssl.so.1.1

~# ls -la /usr/lib/arm-linux-gnueabihf/lib{crypto,ssl}.*
-rw-r--r-- 1 root root 2475958 Jun 11 10:48 /usr/lib/arm-linux-gnueabihf/libcrypto.a
lrwxrwxrwx 1 root root      43 Jun 11 10:48 /usr/lib/arm-linux-gnueabihf/libcrypto.so -> /lib/arm-linux-gnueabihf/libcrypto.so.1.0.0
-rw-r--r-- 1 root root  388728 Jun 11 10:48 /usr/lib/arm-linux-gnueabihf/libssl.a
lrwxrwxrwx 1 root root      40 Jun 11 10:48 /usr/lib/arm-linux-gnueabihf/libssl.so -> /lib/arm-linux-gnueabihf/libssl.so.1.0.0

Not sure why I have openssl stuff in /usr/local/lib and ssl/lib, but it may be due to some build attempt I made when trying to get another program to build (I remember, whatever program it was, saying the version information wasn't found or something, which I confirmed with readelf).
The armhf path is ubuntu's default openssl.

Still, those other paths shouldn't even be a consideration for the compiler since I specified pkg_config and it even showed the local/ssl/lib linker path in the g++ output.
The armhf/lib path is also listed before the ssl/lib path, but that is for boost. But the libcrypto is listed after the ssl/lib path parameter.

@laanwj
Copy link
Member

laanwj commented Dec 1, 2015

The problem is that /usr/lib/arm-linux-gnueabihf/lib{crypto,ssl}.* is your default architecture library path. I'm not sure there is a way to have gcc not look there when linking. @theuni do you have an idea?

If you move /usr/lib/arm-linux-gnueabihf/libcrypto.so and /usr/lib/arm-linux-gnueabihf/libssl.so (but not libcrypto.so.1.0.0 and libssl.so.1.0.0) out of the way it should work.
(alternatively, uninstall e.g. libssl-dev from your distribution, it's what puts those links there in the first place)

@vindicatorr
Copy link
Author

@laanwj I was just about to say you got it right as the build, check and install all completed successfully.
Then, before restarting my bitcoind service, I thought I'd run "bitcoind version" or with --help and they both bork with

/usr/local/bin/bitcoind: symbol lookup error: /usr/local/bin/bitcoind: undefined symbol: OpenSSL_version

fudge. Thought we had it.

# ldd /usr/local/bin/bitcoind
        libboost_system.so.1.55.0 => /usr/lib/arm-linux-gnueabihf/libboost_system.so.1.55.0 (0xb6ae8000)
        libboost_filesystem.so.1.55.0 => /usr/lib/arm-linux-gnueabihf/libboost_filesystem.so.1.55.0 (0xb6ac7000)
        libboost_program_options.so.1.55.0 => /usr/lib/arm-linux-gnueabihf/libboost_program_options.so.1.55.0 (0xb6a66000)
        libboost_thread.so.1.55.0 => /usr/lib/arm-linux-gnueabihf/libboost_thread.so.1.55.0 (0xb6a44000)
        libboost_chrono.so.1.55.0 => /usr/lib/arm-linux-gnueabihf/libboost_chrono.so.1.55.0 (0xb6a2e000)
        libdb_cxx-5.3.so => /usr/lib/arm-linux-gnueabihf/libdb_cxx-5.3.so (0xb68fc000)
        libcrypto.so.1.1 => /usr/local/lib/libcrypto.so.1.1 (0xb6735000)
        libevent_pthreads-2.0.so.5 => /usr/lib/arm-linux-gnueabihf/libevent_pthreads-2.0.so.5 (0xb6723000)
        libevent-2.0.so.5 => /usr/lib/arm-linux-gnueabihf/libevent-2.0.so.5 (0xb66e7000)
        libanl.so.1 => /lib/arm-linux-gnueabihf/libanl.so.1 (0xb66d3000)
        libstdc++.so.6 => /usr/lib/arm-linux-gnueabihf/libstdc++.so.6 (0xb6619000)
        libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0xb65a4000)
        libgcc_s.so.1 => /lib/arm-linux-gnueabihf/libgcc_s.so.1 (0xb657b000)
        libpthread.so.0 => /lib/arm-linux-gnueabihf/libpthread.so.0 (0xb6567000)
        libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6479000)
        /lib/ld-linux-armhf.so.3 (0xb6f6a000)
        librt.so.1 => /lib/arm-linux-gnueabihf/librt.so.1 (0xb6463000)
        libdl.so.2 => /lib/arm-linux-gnueabihf/libdl.so.2 (0xb6450000)
        libevent_core-2.0.so.5 => /usr/lib/arm-linux-gnueabihf/libevent_core-2.0.so.5 (0xb6424000)

Sure looks like libcrypto is being used in the right place.
EDIT:
And what I ended up doing was "# apt-get remove libssl-dev". Also took my server a while to complete since I also had it building a kernel and other stuff was going on at the same time.

@laanwj
Copy link
Member

laanwj commented Dec 1, 2015

OpenSSL_version is in libssl, not in libcrypto, and from that list it appears you're not linking libssl?

@vindicatorr
Copy link
Author

...
/bin/bash ../libtool  --tag=CXX   --mode=link g++ -Wstack-protector -fstack-protector-all -fPIE -O3 -pipe -mtune=cortex-a15.cortex-a7 -march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4  -pthread  -Wl,-z,relro -Wl,-z,now -pie   -o bitcoin-cli bitcoin_cli-bitcoin-cli.o  libbitcoin_cli.a univalue/libunivalue.la libbitcoin_util.a -L/usr/lib/arm-linux-gnueabihf -lboost_system -lboost_filesystem -lboost_program_options -lboost_thread -lboost_chrono -L/usr/local/ssl/lib -lssl  -L/usr/local/ssl/lib -lcrypto  -levent  -lanl 
...
libtool: link: g++ -Wstack-protector -fstack-protector-all -fPIE -O3 -pipe -mtune=cortex-a15.cortex-a7 -march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4 -pthread -Wl,-z -Wl,relro -Wl,-z -Wl,now -pie -o bitcoin-cli bitcoin_cli-bitcoin-cli.o  libbitcoin_cli.a univalue/.libs/libunivalue.a libbitcoin_util.a -L/usr/lib/arm-linux-gnueabihf -lboost_system -lboost_filesystem -lboost_program_options -lboost_thread -lboost_chrono -L/usr/local/ssl/lib -lssl -lcrypto -levent -lanl -pthread
...
/bin/bash ../libtool  --tag=CXX   --mode=link g++ -Wstack-protector -fstack-protector-all -fPIE -O3 -pipe -mtune=cortex-a15.cortex-a7 -march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4  -pthread  -Wl,-z,relro -Wl,-z,now -pie   -o bitcoind bitcoind-bitcoind.o  libbitcoin_server.a libbitcoin_common.a univalue/libunivalue.la libbitcoin_util.a crypto/libbitcoin_crypto.a ./leveldb/libleveldb.a ./leveldb/libmemenv.a secp256k1/libsecp256k1.la  libbitcoin_wallet.a -L/usr/lib/arm-linux-gnueabihf -lboost_system -lboost_filesystem -lboost_program_options -lboost_thread -lboost_chrono -ldb_cxx -L/usr/local/ssl/lib -lssl  -L/usr/local/ssl/lib -lcrypto   -levent_pthreads -levent  -levent  -lanl 
/bin/bash ../libtool  --tag=CXX   --mode=link g++ -Wstack-protector -fstack-protector-all -fPIE -O3 -pipe -mtune=cortex-a15.cortex-a7 -march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4  -pthread  -Wl,-z,relro -Wl,-z,now -pie   -o bench/bench_bitcoin bench/bench_bench_bitcoin-bench_bitcoin.o bench/bench_bench_bitcoin-bench.o bench/bench_bench_bitcoin-Examples.o libbitcoin_server.a libbitcoin_common.a  libbitcoin_util.a crypto/libbitcoin_crypto.a ./leveldb/libleveldb.a ./leveldb/libmemenv.a secp256k1/libsecp256k1.la  libbitcoin_wallet.a -L/usr/lib/arm-linux-gnueabihf -lboost_system -lboost_filesystem -lboost_program_options -lboost_thread -lboost_chrono -ldb_cxx -L/usr/local/ssl/lib -lssl  -L/usr/local/ssl/lib -lcrypto   -levent_pthreads -levent  -levent  -lanl 
/bin/bash ../libtool  --tag=CXX   --mode=link g++ -Wstack-protector -fstack-protector-all -fPIE -O3 -pipe -mtune=cortex-a15.cortex-a7 -march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4  -pthread  -Wl,-z,relro -Wl,-z,now -pie  -static  -o test/test_bitcoin test/test_test_bitcoin-arith_uint256_tests.o test/test_test_bitcoin-addrman_tests.o test/test_test_bitcoin-alert_tests.o test/test_test_bitcoin-allocator_tests.o test/test_test_bitcoin-base32_tests.o test/test_test_bitcoin-base58_tests.o test/test_test_bitcoin-base64_tests.o test/test_test_bitcoin-bip32_tests.o test/test_test_bitcoin-bloom_tests.o test/test_test_bitcoin-checkblock_tests.o test/test_test_bitcoin-Checkpoints_tests.o test/test_test_bitcoin-coins_tests.o test/test_test_bitcoin-compress_tests.o test/test_test_bitcoin-crypto_tests.o test/test_test_bitcoin-DoS_tests.o test/test_test_bitcoin-getarg_tests.o test/test_test_bitcoin-hash_tests.o test/test_test_bitcoin-key_tests.o test/test_test_bitcoin-limitedmap_tests.o test/test_test_bitcoin-dbwrapper_tests.o test/test_test_bitcoin-main_tests.o test/test_test_bitcoin-mempool_tests.o test/test_test_bitcoin-merkle_tests.o test/test_test_bitcoin-miner_tests.o test/test_test_bitcoin-mruset_tests.o test/test_test_bitcoin-multisig_tests.o test/test_test_bitcoin-netbase_tests.o test/test_test_bitcoin-pmt_tests.o test/test_test_bitcoin-policyestimator_tests.o test/test_test_bitcoin-pow_tests.o test/test_test_bitcoin-prevector_tests.o test/test_test_bitcoin-reverselock_tests.o test/test_test_bitcoin-rpc_tests.o test/test_test_bitcoin-sanity_tests.o test/test_test_bitcoin-scheduler_tests.o test/test_test_bitcoin-script_P2SH_tests.o test/test_test_bitcoin-script_tests.o test/test_test_bitcoin-scriptnum_tests.o test/test_test_bitcoin-serialize_tests.o test/test_test_bitcoin-sighash_tests.o test/test_test_bitcoin-sigopcount_tests.o test/test_test_bitcoin-skiplist_tests.o test/test_test_bitcoin-streams_tests.o test/test_test_bitcoin-test_bitcoin.o test/test_test_bitcoin-timedata_tests.o test/test_test_bitcoin-transaction_tests.o test/test_test_bitcoin-txvalidationcache_tests.o test/test_test_bitcoin-uint256_tests.o test/test_test_bitcoin-univalue_tests.o test/test_test_bitcoin-util_tests.o test/test_test_bitcoin-accounting_tests.o wallet/test/test_test_bitcoin-wallet_tests.o test/test_test_bitcoin-rpc_wallet_tests.o     libbitcoin_server.a libbitcoin_cli.a libbitcoin_common.a libbitcoin_util.a crypto/libbitcoin_crypto.a univalue/libunivalue.la ./leveldb/libleveldb.a ./leveldb/libmemenv.a -L/usr/lib/arm-linux-gnueabihf -lboost_system -lboost_filesystem -lboost_program_options -lboost_thread -lboost_chrono -lboost_unit_test_framework secp256k1/libsecp256k1.la libbitcoin_wallet.a libbitcoinconsensus.la -ldb_cxx -L/usr/local/ssl/lib -lssl  -L/usr/local/ssl/lib -lcrypto    -lanl 
...
libtool: link: g++ -Wstack-protector -fstack-protector-all -fPIE -O3 -pipe -mtune=cortex-a15.cortex-a7 -march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4 -pthread -Wl,-z -Wl,relro -Wl,-z -Wl,now -pie -o bench/bench_bitcoin bench/bench_bench_bitcoin-bench_bitcoin.o bench/bench_bench_bitcoin-bench.o bench/bench_bench_bitcoin-Examples.o  libbitcoin_server.a libbitcoin_common.a libbitcoin_util.a crypto/libbitcoin_crypto.a ./leveldb/libleveldb.a ./leveldb/libmemenv.a secp256k1/.libs/libsecp256k1.a libbitcoin_wallet.a -L/usr/lib/arm-linux-gnueabihf -lboost_system -lboost_filesystem -lboost_program_options -lboost_thread -lboost_chrono -ldb_cxx -L/usr/local/ssl/lib -lssl -lcrypto -levent_pthreads -levent -lanl -pthread
libtool: link: g++ -Wstack-protector -fstack-protector-all -fPIE -O3 -pipe -mtune=cortex-a15.cortex-a7 -march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4 -pthread -Wl,-z -Wl,relro -Wl,-z -Wl,now -pie -o bitcoind bitcoind-bitcoind.o  libbitcoin_server.a libbitcoin_common.a univalue/.libs/libunivalue.a libbitcoin_util.a crypto/libbitcoin_crypto.a ./leveldb/libleveldb.a ./leveldb/libmemenv.a secp256k1/.libs/libsecp256k1.a libbitcoin_wallet.a -L/usr/lib/arm-linux-gnueabihf -lboost_system -lboost_filesystem -lboost_program_options -lboost_thread -lboost_chrono -ldb_cxx -L/usr/local/ssl/lib -lssl -lcrypto -levent_pthreads -levent -lanl -pthread
libtool: link: g++ -Wstack-protector -fstack-protector-all -fPIE -O3 -pipe -mtune=cortex-a15.cortex-a7 -march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4 -pthread -Wl,-z -Wl,relro -Wl,-z -Wl,now -pie -o test/test_bitcoin test/test_test_bitcoin-arith_uint256_tests.o test/test_test_bitcoin-addrman_tests.o test/test_test_bitcoin-alert_tests.o test/test_test_bitcoin-allocator_tests.o test/test_test_bitcoin-base32_tests.o test/test_test_bitcoin-base58_tests.o test/test_test_bitcoin-base64_tests.o test/test_test_bitcoin-bip32_tests.o test/test_test_bitcoin-bloom_tests.o test/test_test_bitcoin-checkblock_tests.o test/test_test_bitcoin-Checkpoints_tests.o test/test_test_bitcoin-coins_tests.o test/test_test_bitcoin-compress_tests.o test/test_test_bitcoin-crypto_tests.o test/test_test_bitcoin-DoS_tests.o test/test_test_bitcoin-getarg_tests.o test/test_test_bitcoin-hash_tests.o test/test_test_bitcoin-key_tests.o test/test_test_bitcoin-limitedmap_tests.o test/test_test_bitcoin-dbwrapper_tests.o test/test_test_bitcoin-main_tests.o test/test_test_bitcoin-mempool_tests.o test/test_test_bitcoin-merkle_tests.o test/test_test_bitcoin-miner_tests.o test/test_test_bitcoin-mruset_tests.o test/test_test_bitcoin-multisig_tests.o test/test_test_bitcoin-netbase_tests.o test/test_test_bitcoin-pmt_tests.o test/test_test_bitcoin-policyestimator_tests.o test/test_test_bitcoin-pow_tests.o test/test_test_bitcoin-prevector_tests.o test/test_test_bitcoin-reverselock_tests.o test/test_test_bitcoin-rpc_tests.o test/test_test_bitcoin-sanity_tests.o test/test_test_bitcoin-scheduler_tests.o test/test_test_bitcoin-script_P2SH_tests.o test/test_test_bitcoin-script_tests.o test/test_test_bitcoin-scriptnum_tests.o test/test_test_bitcoin-serialize_tests.o test/test_test_bitcoin-sighash_tests.o test/test_test_bitcoin-sigopcount_tests.o test/test_test_bitcoin-skiplist_tests.o test/test_test_bitcoin-streams_tests.o test/test_test_bitcoin-test_bitcoin.o test/test_test_bitcoin-timedata_tests.o test/test_test_bitcoin-transaction_tests.o test/test_test_bitcoin-txvalidationcache_tests.o test/test_test_bitcoin-uint256_tests.o test/test_test_bitcoin-univalue_tests.o test/test_test_bitcoin-util_tests.o test/test_test_bitcoin-accounting_tests.o wallet/test/test_test_bitcoin-wallet_tests.o test/test_test_bitcoin-rpc_wallet_tests.o  libbitcoin_server.a libbitcoin_cli.a libbitcoin_common.a libbitcoin_util.a crypto/libbitcoin_crypto.a univalue/.libs/libunivalue.a ./leveldb/libleveldb.a ./leveldb/libmemenv.a -L/usr/lib/arm-linux-gnueabihf -lboost_system -lboost_filesystem -lboost_program_options -lboost_thread -lboost_chrono -lboost_unit_test_framework secp256k1/.libs/libsecp256k1.a libbitcoin_wallet.a ./.libs/libbitcoinconsensus.a -ldb_cxx -L/usr/local/ssl/lib -lssl -lcrypto -lanl -pthread
...

I needed to rebuild with V=1 and found those 8 instances where lssl was referenced.
I will say that there may (or not) be an issue with ec.h according to config.log:

...
configure:27040: checking openssl/ec.h presence
configure:27040: g++ -E  -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS -D_FILE_OFFSET_BITS=64 conftest.cpp
conftest.cpp:67:24: fatal error: openssl/ec.h: No such file or directory
 #include <openssl/ec.h>
...
| /* end confdefs.h.  */
| #include <openssl/ec.h>
configure:27040: result: no
configure:27040: WARNING: openssl/ec.h: accepted by the compiler, rejected by the preprocessor!
configure:27040: WARNING: openssl/ec.h: proceeding with the compiler's result
configure:27040: checking for openssl/ec.h
configure:27040: result: yes
...
ac_cv_header_openssl_ec_h=yes
...
pkg_cv_SSL_CFLAGS='-I/usr/local/ssl/include '
pkg_cv_SSL_LIBS='-L/usr/local/ssl/lib -lssl '

@vindicatorr
Copy link
Author

AHHHHHH! Noticing something new. While searching online, I saw something else.
I had NOT run ldd on libcrypto.so.1.1 and just found it's pointing to ubuntu's default path, not mine.
*https://wiki.openssl.org/index.php/Compilation_and_Installation#Using_RPATHs
Going to try this now.

@vindicatorr
Copy link
Author

Step-1 complete (openssl install):
In my case, I had to edit ./Configurations/10-main.conf, find "linux-armv4" and add "lflags => "-ldl -Wl,-rpath,/usr/local/ssl/lib","
After "make", "readelf -d" showed the correct rpath for libssl.so and libcrypto.so.
After install, "ldd" for openssl and libcrypto.so showed the proper lib links.

Now for bitcoin.

@vindicatorr
Copy link
Author

Success. build, check, install, version info, help is all good and the service is back up and running.
I had to include "LDFLAGS="-Wl,-rpath,/usr/local/ssl/lib"" and keep pkg_config_path as well.
Finally.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants