Skip to content

Commit 6c83bfe

Browse files
committed
Add bignum.h and port exactfloat to use it.
This removes the dependency on OpenSSL for its bignum library. The main benefit of this is that targetting things like WASM are much simpler since we don't need to compile OpenSSL to WASM. I didn't try as hard for performance optimization as OpenSSL (which also has a hard requirement around constant-time operation for security purposes), but benchmarks indicate addition and subtraction is generally the same and multiplication is within a factor of two. For the size of bignums we expect in S2 there shouldn't be a noticeable difference in performance.
1 parent 5b5fbc0 commit 6c83bfe

File tree

7 files changed

+1766
-249
lines changed

7 files changed

+1766
-249
lines changed

CMakeLists.txt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ add_definitions(-DABSL_MIN_LOG_LEVEL=1)
6060
if (NOT TARGET absl::base)
6161
find_package(absl REQUIRED)
6262
endif()
63-
find_package(OpenSSL REQUIRED)
6463
# pthreads isn't used directly, but this is still required for std::thread.
6564
find_package(Threads REQUIRED)
6665

@@ -99,10 +98,6 @@ else()
9998
add_compile_options(-fsized-deallocation)
10099
endif()
101100

102-
# If OpenSSL is installed in a non-standard location, configure with
103-
# something like:
104-
# OPENSSL_ROOT_DIR=/usr/local/opt/openssl cmake ..
105-
include_directories(${OPENSSL_INCLUDE_DIR})
106101

107102
if (WITH_PYTHON)
108103
include_directories(${Python3_INCLUDE_DIRS})
@@ -230,7 +225,6 @@ endif()
230225

231226
target_link_libraries(
232227
s2
233-
${OPENSSL_LIBRARIES}
234228
absl::absl_vlog_is_on
235229
absl::base
236230
absl::btree
@@ -617,6 +611,7 @@ if (BUILD_TESTS)
617611
src/s2/s2shapeutil_shape_edge_id_test.cc
618612
src/s2/s2shapeutil_visit_crossing_edge_pairs_test.cc
619613
src/s2/s2text_format_test.cc
614+
src/s2/util/math/exactfloat/bignum_test.cc
620615
src/s2/s2validation_query_test.cc
621616
src/s2/s2wedge_relations_test.cc
622617
src/s2/s2winding_operation_test.cc
@@ -645,7 +640,8 @@ if (BUILD_TESTS)
645640
absl::status
646641
absl::strings
647642
absl::synchronization
648-
gmock_main)
643+
gmock_main
644+
crypto)
649645
add_test(${test} ${test})
650646
endforeach()
651647
endif()

README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ This issue may require revision of boringssl or exactfloat.
5959
* [Abseil](https://github.com/abseil/abseil-cpp) >= LTS
6060
[`20250512`](https://github.com/abseil/abseil-cpp/releases/tag/20250512.1)
6161
(standard library extensions)
62-
* [OpenSSL](https://github.com/openssl/openssl) (for its bignum library)
6362
* [googletest testing framework >= 1.10](https://github.com/google/googletest)
6463
(to build tests and example programs, optional)
6564

@@ -139,11 +138,6 @@ Disable building of shared libraries with `-DBUILD_SHARED_LIBS=OFF`.
139138

140139
Enable the python interface with `-DWITH_PYTHON=ON`.
141140

142-
If OpenSSL is installed in a non-standard location set `OPENSSL_ROOT_DIR`
143-
before running configure, for example on macOS:
144-
```
145-
OPENSSL_ROOT_DIR=/opt/homebrew/Cellar/openssl@3/3.1.0 cmake -DCMAKE_PREFIX_PATH=/opt/homebrew -DCMAKE_CXX_STANDARD=17
146-
```
147141

148142
## Installing
149143

@@ -218,8 +212,6 @@ python -m build
218212

219213
The resulting wheel will be in the `dist` directory.
220214

221-
> If OpenSSL is in a non-standard location make sure to set `OPENSSL_ROOT_DIR`;
222-
> see above for more information.
223215

224216
## Other S2 implementations
225217

src/s2/util/math/exactfloat/BUILD

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ package(default_visibility = ["//visibility:public"])
33
cc_library(
44
name = "exactfloat",
55
srcs = ["exactfloat.cc"],
6-
hdrs = ["exactfloat.h"],
6+
hdrs = ["exactfloat.h", "bignum.h"],
77
deps = [
88
"//s2/base:types",
99
"//s2/base:port",
1010
"//s2/base:logging",
1111
"@abseil-cpp//absl/log:log",
1212
"@abseil-cpp//absl/log:absl_check",
13-
"@boringssl//:crypto",
13+
"@abseil-cpp//absl/strings:str_format",
14+
"@abseil-cpp//absl/container:inlined_vector",
15+
"@abseil-cpp//absl/numeric:bits",
16+
"@abseil-cpp//absl/numeric:int128",
17+
"@abseil-cpp//absl/strings:ascii",
1418
],
1519
)

0 commit comments

Comments
 (0)