From: Debian R Packages Maintainers Date: Wed, 6 Oct 2021 10:38:58 +0000 (+0100) Subject: Fix BN_ext_get_uint64 for OpenSSL >= 1.1 32bit X-Git-Tag: archive/raspbian/1.1.0-1+rpi1~1^2~2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=6241ccefe91b6f2bebf2231ab062622cc41497bb;p=r-cran-s2.git Fix BN_ext_get_uint64 for OpenSSL >= 1.1 32bit Origin: upstream Bug: https://github.com/google/s2geometry/pull/183 Forwarded: no Reviewed-by: Étienne Mollier Last-Update: 2021-10-04 Suggested changes fix compilation error with OpenSSL >= 1.0 for 32bit target. The algorithm is similar to what is currently being done in BN_ext_set_uint64, but in the opposite direction. Last-Update: 2021-10-04 Gbp-Pq: Name fix-ftbfs-on-32bit.patch --- diff --git a/src/s2/util/math/exactfloat/exactfloat.cc b/src/s2/util/math/exactfloat/exactfloat.cc index 2300ea0..f98f8ba 100644 --- a/src/s2/util/math/exactfloat/exactfloat.cc +++ b/src/s2/util/math/exactfloat/exactfloat.cc @@ -93,6 +93,8 @@ inline static void BN_ext_set_uint64(BIGNUM* bn, uint64 v) { #endif } +#if OPENSSL_VERSION_NUMBER < 0x10100000L + // Return the absolute value of a BIGNUM as a 64-bit unsigned integer. // Requires that BIGNUM fits into 64 bits. inline static uint64 BN_ext_get_uint64(const BIGNUM* bn) { @@ -108,8 +110,6 @@ inline static uint64 BN_ext_get_uint64(const BIGNUM* bn) { #endif } -#if OPENSSL_VERSION_NUMBER < 0x10100000L - // Count the number of low-order zero bits in the given BIGNUM (ignoring its // sign). Returns 0 if the argument is zero. static int BN_ext_count_low_zero_bits(const BIGNUM* bn) { @@ -130,6 +130,22 @@ static int BN_ext_count_low_zero_bits(const BIGNUM* bn) { #else // OPENSSL_VERSION_NUMBER >= 0x10100000L +// Return the absolute value of a BIGNUM as a 64-bit unsigned integer. +// Requires that BIGNUM fits into 64 bits. +inline static uint64 BN_ext_get_uint64(const BIGNUM* bn) { + uint64 r; +#ifdef IS_LITTLE_ENDIAN + S2_CHECK_EQ(BN_bn2lebinpad(bn, reinterpret_cast(&r), + sizeof(r)), sizeof(r)); +#elif IS_BIG_ENDIAN + S2_CHECK_EQ(BN_bn2binpad(bn, reinterpret_cast(&r), + sizeof(r)), sizeof(r)); +#else +#error one of IS_LITTLE_ENDIAN or IS_BIG_ENDIAN should be defined! +#endif + return r; +} + static int BN_ext_count_low_zero_bits(const BIGNUM* bn) { // In OpenSSL >= 1.1, BIGNUM is an opaque type, so d and top // cannot be accessed. The bytes must be copied out at a ~25%