Since https://github.com/bitcoin-core/secp256k1/pull//1777 , libsecp256k1 allows an externally provided SHA256 compression function. This PR plug ours in, so it runs on our SHA-NI/ARMv8/SSE4 hardware optimized implementation instead of the libsecp bare internal one.
The biggest gains are at the signing side, not at the verification side.
The first commits restructure how the libsecp context is encapsulated and initialized. ECC_Context now properly handles the libsecp context lifecycle and fully behaves as a singleton, getting decoupled from the key.h/cpp primitive (which is no longer accessed by upper layers just to init ECC), allowing us to introduce a verification context within the same object, and moving the singleton initialization to ecc_init.h which simplifies usage to a single entry point for all users.
Benchmarks at the bench introduction commit (43c9bdbf8ada1b581b5ab1f0a102517c243a60da) and at the tip:
On ARM64, arm_shani implementation
| benchmark | before | after | change |
|---|---|---|---|
ECDSASign |
79.2 µs | 69.3 µs | -13% |
SchnorrSign |
39.9 µs | 37.1 µs | -7% |
ECDSAVerify |
27.4 µs | 27.3 µs | -0% |
SchnorrVerify |
28.1 µs | 27.8 µs | -1% |
EllSwiftCreate |
29.8 µs | 28.8 µs | -3% |
BIP324_ECDH |
30.4 µs | 30.1 µs | -1% |