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

compilation error because of deprecated BIGNUM functions in openssl 1.1 #5

Closed
akhenakh opened this issue Jan 18, 2018 · 11 comments
Closed
Assignees

Comments

@akhenakh
Copy link

as of 8a8746c

compilation is failing on Arch because of openssl 1.1:

In file included from /home/akh/tmp/s2geometry/src/s2/s2predicates_internal.h:29:0,
                 from /home/akh/tmp/s2geometry/src/s2/s2edge_crossings.cc:28:
/home/akh/tmp/s2geometry/src/s2/util/math/exactfloat/exactfloat.h:516:10: error: field ‘bn_’ has incomplete type ‘BIGNUM {aka bignum_st}’
   BIGNUM bn_;
          ^~~
In file included from /usr/include/openssl/bn.h:32:0,
                 from /home/akh/tmp/s2geometry/src/s2/util/math/exactfloat/exactfloat.h:119,
                 from /home/akh/tmp/s2geometry/src/s2/s2predicates_internal.h:29,
                 from /home/akh/tmp/s2geometry/src/s2/s2edge_crossings.cc:28:
/usr/include/openssl/ossl_typ.h:80:16: note: forward declaration of ‘BIGNUM {aka struct bignum_st}’
 typedef struct bignum_st BIGNUM;
                ^~~~~~~~~
In file included from /home/akh/tmp/s2geometry/src/s2/s2predicates_internal.h:29:0,
                 from /home/akh/tmp/s2geometry/src/s2/s2edge_crossings.cc:28:
/home/akh/tmp/s2geometry/src/s2/util/math/exactfloat/exactfloat.h: In constructor ‘ExactFloat::ExactFloat()’:
/home/akh/tmp/s2geometry/src/s2/util/math/exactfloat/exactfloat.h:576:3: error: ‘BN_init’ was not declared in this scope
   BN_init(&bn_);
   ^~~~~~~
/home/akh/tmp/s2geometry/src/s2/util/math/exactfloat/exactfloat.h:576:3: note: suggested alternative: ‘BN_print’
   BN_init(&bn_);
   ^~~~~~~
   BN_print
make[2]: *** [CMakeFiles/s2.dir/build.make:879: CMakeFiles/s2.dir/src/s2/s2edge_crossings.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:105: CMakeFiles/s2.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

BN_init() was removed in OpenSSL 1.1.0; use BN_new() instead.
source https://www.openssl.org/docs/man1.1.0/crypto/BN_new.html

Solution for Arch is:
cmake -DOPENSSL_INCLUDE_DIR="/usr/include/openssl-1.0" -DOPENSSL_SSL_LIBRARY=/usr/lib/openssl-1.0/libssl.so ..

It will become an issue for every distribution with recent openssl.

@jmr jmr self-assigned this Jan 18, 2018
@jmr
Copy link
Member

jmr commented Jan 18, 2018

Ok, working on it.

@akhenakh
Copy link
Author

in the meantime here is an AUR pkg for Arch https://aur.archlinux.org/packages/s2geometry-git

@jmr
Copy link
Member

jmr commented Jan 18, 2018

We're seeing a ~40% slowdown and 75% more allocs on some ExactFloat benchmarks with a simple BN_init -> BN_new fix. Do you know if there's an easy fix?

@akhenakh
Copy link
Author

I don't, I've only tried this without any performance measurement:

BN_init() is no longer available as of OpenSSL 1.1.0. It was used to initialize an existing uninitialized BIGNUM. Typically this would be done as follows:

 BIGNUM a;
 BN_init(&a);

Applications should replace use of BN_init with BN_new instead:

 BIGNUM *a;
 a = BN_new();
 if(!a) /* Handle error */
 ...
 BN_free(a);

@jmr
Copy link
Member

jmr commented Jan 19, 2018

Can you put this before ExactFloat::ExactFloat in exactfloat.h and let me know if it works / what the error is?

#if defined(OPENSSL_API_COMPAT) && OPENSSL_API_COMPAT >= 0x10100000L
extern "C" void bn_init(BIGNUM *a);
#define BN_init bn_init
#endif

@akhenakh
Copy link
Author

diff --git a/src/s2/util/math/exactfloat/exactfloat.h b/src/s2/util/math/exactfloat/exactfloat.h
index 050b75f..ab849d2 100644
--- a/src/s2/util/math/exactfloat/exactfloat.h
+++ b/src/s2/util/math/exactfloat/exactfloat.h
@@ -571,6 +571,10 @@ class ExactFloat {
 
 /////////////////////////////////////////////////////////////////////////
 // Implementation details follow:
+#if defined(OPENSSL_API_COMPAT) && OPENSSL_API_COMPAT >= 0x10100000L
+extern "C" void bn_init(BIGNUM *a);
+#define BN_init bn_init
+#endif
 
 inline ExactFloat::ExactFloat() : sign_(1), bn_exp_(kExpZero) {
   BN_init(&bn_);
In file included from /home/akh/tmp/s2geometry/src/s2/s2predicates_internal.h:29:0,
                 from /home/akh/tmp/s2geometry/src/s2/s2edge_crossings.cc:28:
/home/akh/tmp/s2geometry/src/s2/util/math/exactfloat/exactfloat.h:516:10: error: field ‘bn_’ has incomplete type ‘BIGNUM {aka bignum_st}’
   BIGNUM bn_;
          ^~~
In file included from /usr/include/openssl/bn.h:32:0,
                 from /home/akh/tmp/s2geometry/src/s2/util/math/exactfloat/exactfloat.h:119,
                 from /home/akh/tmp/s2geometry/src/s2/s2predicates_internal.h:29,
                 from /home/akh/tmp/s2geometry/src/s2/s2edge_crossings.cc:28:
/usr/include/openssl/ossl_typ.h:80:16: note: forward declaration of ‘BIGNUM {aka struct bignum_st}’
 typedef struct bignum_st BIGNUM;
                ^~~~~~~~~
In file included from /home/akh/tmp/s2geometry/src/s2/s2predicates_internal.h:29:0,
                 from /home/akh/tmp/s2geometry/src/s2/s2edge_crossings.cc:28:
/home/akh/tmp/s2geometry/src/s2/util/math/exactfloat/exactfloat.h: In constructor ‘ExactFloat::ExactFloat()’:
/home/akh/tmp/s2geometry/src/s2/util/math/exactfloat/exactfloat.h:580:3: error: ‘BN_init’ was not declared in this scope
   BN_init(&bn_);
   ^~~~~~~
/home/akh/tmp/s2geometry/src/s2/util/math/exactfloat/exactfloat.h:580:3: note: suggested alternative: ‘BN_print’
   BN_init(&bn_);
   ^~~~~~~
   BN_print
make[2]: *** [CMakeFiles/s2.dir/build.make:879: CMakeFiles/s2.dir/src/s2/s2edge_crossings.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:105: CMakeFiles/s2.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

@jmr
Copy link
Member

jmr commented Mar 6, 2018

Ok, now there's support for both BN_init and BN_new, depending on the OpenSSL version.

@jmr jmr closed this as completed Mar 6, 2018
@jmr
Copy link
Member

jmr commented Apr 4, 2018

@akhenakh Does this actually work for you with openssl 1.1? I'm seeing errors for bn->top and bn->d since BIGNUM is an incomplete type.

@jmr jmr reopened this Apr 4, 2018
@mkatsevVR
Copy link

yup, also getting the same errors with 1.1

@jmr
Copy link
Member

jmr commented May 11, 2018

Now it should be working. Let me know if you find otherwise.

@jmr jmr closed this as completed May 11, 2018
@mkatsevVR
Copy link

works for me now, thanks

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

No branches or pull requests

3 participants