f09497ea3eCI: tweak cirrus.yml to prevent OOM and timeout w sanitizer/valgrind (Jonas Nick)7226cf215aecdsa_adaptor: fix too small buffer in tests (Jonas Nick)b053e853d4ecdsa_adaptor: fix test case with invalid signature (Jonas Nick)d27e459861Revert "Remove unused Jacobi symbol support" (Jonas Nick)c58c4ea470ci: Add ppc64le build (Tim Ruffing)8f879c2887Fix array size in bench_ecmult (Jonas Nick)2fe1b50df1Add ecmult_gen, ecmult_const and ecmult to benchmark (Jonas Nick)593e6bad9cClean up ecmult_bench to make space for more benchmarks (Jonas Nick)a35fdd3478ci: Run PRs on merge result even for i686 (Tim Ruffing)02dcea1ad9ci: Make test iterations configurable and tweak for sanitizer builds (Tim Ruffing)489ff5c20atests: Treat empty SECP2561_TEST_ITERS as if it was unset (Tim Ruffing)fcfcb97e74ci: Simplify to use generic wrapper for QEMU, Valgrind, etc (Tim Ruffing)de4157f13aci: Run ASan/LSan and reorganize sanitizer and Valgrind jobs (Tim Ruffing)09b3bb8648Clean up git tree (Tim Ruffing)8bbad7a18eAdd asm build to ARM32 CI (Pieter Wuille)7d65ed5214Add ARM32/ARM64 CI (Pieter Wuille)6eceec6d56add `secp256k1_xonly_pubkey_cmp` method (Andrew Poelstra)0d9561ae87add `secp256k1_ec_pubkey_cmp` method (Andrew Poelstra)22a9ea154acontrib: Explain explicit header guards (Tim Ruffing)0881633dfdsecp256k1.h: clarify that by default arguments must be != NULL (Jonas Nick)14c9739a1ftests: Improve secp256k1_ge_set_all_gej_var for some infinity inputs (Tim Ruffing)4a19668c37tests: Test secp256k1_ge_set_all_gej_var for all infinity inputs (Tim Ruffing)45b6468d7eHave secp256k1_ge_set_all_gej_var initialize all fields. Previous behaviour would not initialize r->y values in the case where infinity is passed in. Furthermore, the previous behaviour wouldn't initialize anything in the case where all inputs were infinity. (Russell O'Connor)31c0f6de41Have secp256k1_gej_double_var initialize all fields. Previous behaviour would not initialize r->x and r->y values in the case where infinity is passed in. (Russell O'Connor)dd6c3de322Have secp256k1_ge_set_gej_var initialize all fields. Previous behaviour would not initialize r->x and r->y values in the case where infinity is passed in. (Russell O'Connor)3c90bdda95change local lib headers to be relative for those pointing at "include/" dir (William Bright)c8483520c9Makefile.am: Don't pass a variable twice (Tim Ruffing)2161f31785Makefile.am: Honor config when building gen_context (Tim Ruffing)99f47c20ecgen_context: Don't use external ASM because it complicates the build (Tim Ruffing)99e2d5be0dAvoids a missing brace warning in schnorrsig/tests_impl.h on old compilers. (Gregory Maxwell)ed5a199bedtests: fopen /dev/urandom in binary mode (Tim Ruffing)4dc37bf81bAdd mingw32-w64/wine CI build (Pieter Wuille)ae9e648526Define SECP256K1_BUILD in secp256k1.c directly. (Gregory Maxwell)be0609fd54Add unit tests for edge cases with delta=1/2 variant of divsteps (Pieter Wuille)cd393ce228Optimization: only do 59 hddivsteps per iteration instead of 62 (Pieter Wuille)277b224b6aUse modified divsteps with initial delta=1/2 for constant-time (Pieter Wuille)376ca366dbFix typo in explanation (Pieter Wuille)07067967eeadd ECMULT_GEN_PREC_BITS to basic_config.h (Aaron Voisine)a3aa2628c7gen_context: Don't include basic-config.h (Tim Ruffing)99a1cfec17print warnings for conditional-uninitialized (PiRK)3d2cf6c5bdinitialize variable in tests (PiRK)23c3fb629bMake argument of fe_normalizes_to_zero{_var} const (Pieter Wuille)4504472269changed import to use brackets <> for openssl as they are not local to the project (William Bright)24ad04fc06Make scalar_inverse{,_var} benchmark scale with SECP256K1_BENCH_ITERS (Pieter Wuille)ebc1af700fOptimization: track f,g limb count and pass to new variable-time update_fg_var (Peter Dettman)b306935ac1Optimization: use formulas instead of lookup tables for cancelling g bits (Peter Dettman)9164a1b658Optimization: special-case zero modulus limbs in modinv64 (Pieter Wuille)1f233b3fa0Remove num/gmp support (Pieter Wuille)20448b8d09Remove unused Jacobi symbol support (Pieter Wuille)5437e7bdfbRemove unused scalar_sqr (Pieter Wuille)aa9cc52180Improve field/scalar inverse tests (Pieter Wuille)1e0e885c8aMake field/scalar code use the new modinv modules for inverses (Pieter Wuille)436281afdcMove secp256k1_fe_inverse{_var} to per-impl files (Pieter Wuille)aa404d53beMove secp256k1_scalar_{inverse{_var},is_even} to per-impl files (Pieter Wuille)08d54964e5Improve bounds checks in modinv modules (Pieter Wuille)151aac00d3Add tests for modinv modules (Pieter Wuille)d8a92fcc4cAdd extensive comments on the safegcd algorithm and implementation (Pieter Wuille)8e415acba2Add safegcd based modular inverse modules (Peter Dettman)de0a643c3dAdd secp256k1_ctz{32,64}_var functions (Pieter Wuille) Pull request description: ACKs for top commit: real-or-random: ACKf09497ea3eTree-SHA512: 6cf3e96c5974e9aa17bd649fa7fdd738090ec3ab8c99e144fec397c086a24adc2ace9a5218a3c527989fc07e1d5c669027e4c895caf92d22771c8414b2a9bf35
6e898534 c083cc6e 1e5d50fa cc2c09e3 efad3506 7012a188 34388af6 98e0358d d0bd2693 185a6af2 6c52ae87 69394879 1e78c18d 202a030f bf0ac460 399722a6 3dc8c072 50f33677 7973576f 1758a92f ' into temp-merge-950
6e898534 c083cc6e 1e5d50fa cc2c09e3 efad3506 7012a188 34388af6 98e0358d d0bd2693 185a6af2 6c52ae87 69394879 1e78c18d 202a030f bf0ac460 399722a6 3dc8c072 50f33677 7973576f 1758a92f ' into temp-merge-950
2d9e7175 b61f9da5 98dac878 8c727b90 328aaef2 f2d9aeae b732701f db726782 5671e5f3 a4abaab7 659d0d47 f8c0b57e 24d1656c 3a8b47bc ebdba03c 4c3ba88c ' into temp-merge-901
6e898534 c083cc6e 1e5d50fa cc2c09e3 efad3506 7012a188 34388af6 98e0358d d0bd2693 185a6af2 6c52ae87 69394879 1e78c18d 202a030f bf0ac460 399722a6 3dc8c072 50f33677 7973576f 1758a92f ' into temp-merge-950
6e898534 c083cc6e 1e5d50fa cc2c09e3 efad3506 7012a188 34388af6 98e0358d d0bd2693 185a6af2 6c52ae87 69394879 1e78c18d 202a030f bf0ac460 399722a6 3dc8c072 50f33677 7973576f 1758a92f ' into temp-merge-950
6e898534 c083cc6e 1e5d50fa cc2c09e3 efad3506 7012a188 34388af6 98e0358d d0bd2693 185a6af2 6c52ae87 69394879 1e78c18d 202a030f bf0ac460 399722a6 3dc8c072 50f33677 7973576f 1758a92f ' into temp-merge-950
libsecp256k1
Optimized C library for ECDSA signatures and secret/public key operations on curve secp256k1.
This library is intended to be the highest quality publicly available library for cryptography on the secp256k1 curve. However, the primary focus of its development has been for usage in the Bitcoin system and usage unlike Bitcoin's may be less well tested, verified, or suffer from a less well thought out interface. Correct usage requires some care and consideration that the library is fit for your application's purpose.
Features:
- secp256k1 ECDSA signing/verification and key generation.
- Additive and multiplicative tweaking of secret/public keys.
- Serialization/parsing of secret keys, public keys, signatures.
- Constant time, constant memory access signing and public key generation.
- Derandomized ECDSA (via RFC6979 or with a caller provided function.)
- Very efficient implementation.
- Suitable for embedded systems.
- Optional module for public key recovery.
- Optional module for ECDH key exchange.
- Optional module for ECDSA adaptor signatures (experimental).
Experimental features have not received enough scrutiny to satisfy the standard of quality of this library but are made available for testing and review by the community. The APIs of these features should not be considered stable.
Implementation details
- General
- No runtime heap allocation.
- Extensive testing infrastructure.
- Structured to facilitate review and analysis.
- Intended to be portable to any system with a C89 compiler and uint64_t support.
- No use of floating types.
- Expose only higher level interfaces to minimize the API surface and improve application security. ("Be difficult to use insecurely.")
- Field operations
- Optimized implementation of arithmetic modulo the curve's field size (2^256 - 0x1000003D1).
- Using 5 52-bit limbs (including hand-optimized assembly for x86_64, by Diederik Huys).
- Using 10 26-bit limbs (including hand-optimized assembly for 32-bit ARM, by Wladimir J. van der Laan).
- Optimized implementation of arithmetic modulo the curve's field size (2^256 - 0x1000003D1).
- Scalar operations
- Optimized implementation without data-dependent branches of arithmetic modulo the curve's order.
- Using 4 64-bit limbs (relying on __int128 support in the compiler).
- Using 8 32-bit limbs.
- Optimized implementation without data-dependent branches of arithmetic modulo the curve's order.
- Modular inverses (both field elements and scalars) based on safegcd with some modifications, and a variable-time variant (by Peter Dettman).
- Group operations
- Point addition formula specifically simplified for the curve equation (y^2 = x^3 + 7).
- Use addition between points in Jacobian and affine coordinates where possible.
- Use a unified addition/doubling formula where necessary to avoid data-dependent branches.
- Point/x comparison without a field inversion by comparison in the Jacobian coordinate space.
- Point multiplication for verification (aP + bG).
- Use wNAF notation for point multiplicands.
- Use a much larger window for multiples of G, using precomputed multiples.
- Use Shamir's trick to do the multiplication with the public key and the generator simultaneously.
- Use secp256k1's efficiently-computable endomorphism to split the P multiplicand into 2 half-sized ones.
- Point multiplication for signing
- Use a precomputed table of multiples of powers of 16 multiplied with the generator, so general multiplication becomes a series of additions.
- Intended to be completely free of timing sidechannels for secret-key operations (on reasonable hardware/toolchains)
- Access the table with branch-free conditional moves so memory access is uniform.
- No data-dependent branches
- Optional runtime blinding which attempts to frustrate differential power analysis.
- The precomputed tables add and eventually subtract points for which no known scalar (secret key) is known, preventing even an attacker with control over the secret key used to control the data internally.
Build steps
libsecp256k1 is built using autotools:
$ ./autogen.sh
$ ./configure
$ make
$ make check
$ sudo make install # optional
Exhaustive tests
$ ./exhaustive_tests
With valgrind, you might need to increase the max stack size:
$ valgrind --max-stackframe=2500000 ./exhaustive_tests
Test coverage
This library aims to have full coverage of the reachable lines and branches.
To create a test coverage report, configure with --enable-coverage (use of GCC is necessary):
$ ./configure --enable-coverage
Run the tests:
$ make check
To create a report, gcovr is recommended, as it includes branch coverage reporting:
$ gcovr --exclude 'src/bench*' --print-summary
To create a HTML report with coloured and annotated source code:
$ mkdir -p coverage
$ gcovr --exclude 'src/bench*' --html --html-details -o coverage/coverage.html
Reporting a vulnerability
See SECURITY.md