b7ebe6436cd9ea6e91829589b2010c587a033c40 Test APIs of funcs that need an ecmult_gen ctx with static ctx (Jonas Nick) e82144edfb7673d9a5eeb2b556d08be5223835ac Fixup skew before global Z fixup (Peter Dettman) 40b624c90bff7a40aa28c4d942b0382c300386b8 Add tests for _gej_cmov (Peter Dettman) 8c13a9bfe16c426c082b8df401098c02db53c9a0 ECDH skews by 0 or 1 (Peter Dettman) 15150994333c872a20a1902aa01e1a60dbb1393d Simpler and faster ecdh skew fixup (Peter Dettman) 3d7cbafb5fd7f152fc47dc907af5df03150accc0 tests: Fix test whose result is implementation-defined (Tim Ruffing) 77a19750b46916b93bb6a08837c26f585bd940fa Use xoshiro256++ PRNG instead of RFC6979 in tests (Pieter Wuille) 5f2efe684ecca8f767f98ee0ace813103cc88ade secp256k1_testrand_int(2**N) -> secp256k1_testrand_bits(N) (Pieter Wuille) 3ed0d02bf7690c68ba3ba74da765614809352049 doc: add CHANGELOG template (Jonas Nick) 6f42dc16c8483ff4c5f34cfc3aeae794ca2c660d doc: add release_process.md (Jonas Nick) 0bd3e4243caa3c000e6afe3ea5533b97565557c4 build: set library version to 0.0.0 explicitly (Jonas Nick) b4b02fd8c4276779f115af5985508f54ef9e51be build: change libsecp version from 0.1 to 0.1.0-pre (Jonas Nick) 05e049b73c69002f498c3c9c21555fd91f95ccac ecmult: move `_ecmult_odd_multiples_table_globalz_windowa` (siv2r) b4ac1a1d5f4d51b9836ac310b78bc9d4256580c2 ci: Run valgrind/memcheck tasks with 2 CPUs (Tim Ruffing) e70acab601aecf3c5a8affb5a4dce5612b298964 ci: Use Cirrus "greedy" flag to use idle CPU time when available (Tim Ruffing) d07e30176e084334081fa53be81e75c064375f36 ci: Update brew on macOS (Tim Ruffing) 22382f0ea0e234242e248720b9d1d171cb2de0f8 ci: Test different ecmult window sizes (Tim Ruffing) 26a022a3a0e3fceb1cd2e882e1476c950cabc2e8 ci: Remove STATICPRECOMPUTATION (Tim Ruffing) 10461d8bd3ce3ee8ca443ccad20915217ee74397 precompute_ecmult: Always compute all tables up to default WINDOW_G (Tim Ruffing) 1287786c7a97eff520ffbd6b0d8b2f99dbfc6371 doc: Add comment to top of field_10x26_impl.h (Elliott Jin) 58da5bd589f61b0e0e9b58388ee3e0da8a2c3c3a doc: Fix upper bounds + cleanup in field_5x52_impl.h comment (Elliott Jin) 22d25c8e0ab1d24f0f4a80fe016cbd71cd889866 Add another ecmult_multi test (Pieter Wuille) 515e7953cab4eb3be063fa3991e4e0663d3f04ae Improve checks at top of _fe_negate methods (Peter Dettman) e05da9e480de34129a170510a311abb204eefeb3 Fix c++ build (Pieter Wuille) c45386d994b48f44009c139c7351a521261e8363 Cleanup preprocessor indentation in precompute{,d}_ecmult{,_gen} (Pieter Wuille) 19d96e15f9b657483c42258568eb70874179d835 Split off .c file from precomputed_ecmult.h (Pieter Wuille) 1a6691adaead20ed55b5400fd4d36f91eb5a3686 Split off .c file from precomputed_ecmult_gen.h (Pieter Wuille) bb36331412ed68999ac73c871d402e3b03f65700 Simplify precompute_ecmult_print_* (Pieter Wuille) 38cd84a0cb56e031fe43b47e9bdf60349ac9c0a7 Compute ecmult tables at runtime for tests_exhaustive (Pieter Wuille) e458ec26d61619eafa9fc2b466c1a7b51f794b1f Move ecmult table computation code to separate file (Pieter Wuille) fc1bf9f15fbe93cb0223c05ee8592ec9bc3070dd Split ecmult table computation and printing (Pieter Wuille) 31feab053b72bfd7ab05347ef7df81b381c92261 Rename function secp256k1_ecmult_gen_{create_prec -> compute}_table (Pieter Wuille) 725370c3f21ad1327b76127784734ffab1f21f97 Rename ecmult_gen_prec -> ecmult_gen_compute_table (Pieter Wuille) 075252c1b7948522455c907ddc97b26f861288eb Rename ecmult_static_pre_g -> precomputed_ecmult (Pieter Wuille) 7cf47f72bc3c2f99e9ac6b050c78b0155a826f74 Rename ecmult_gen_static_prec_table -> precomputed_ecmult_gen (Pieter Wuille) f95b8106d02f8dd4088609a38647033de217bb5a Rename gen_ecmult_static_pre_g -> precompute_ecmult (Pieter Wuille) bae77685ebc3ae695e3a50e1c4dbe7aa936ae7a5 Rename gen_ecmult_gen_static_prec_table -> precompute_ecmult_gen (Pieter Wuille) 7dfceceea692c4118829c06128c41623b2373ac2 build: Remove #undef hack for ASM in the precomputation programs (Tim Ruffing) bb36fe9be0998c81ebc9f18e122bb7617d919877 ci: Test `make precomp` (Tim Ruffing) d94a37a20c3b5b44f1bcf60d309ffc50727e18e4 build: Remove CC_FOR_BUILD stuff (Tim Ruffing) ad63bb4c296e6007dab22cda05fd599b20139362 build: Prebuild and distribute ecmult_gen table (Tim Ruffing) ac49361ed0a342e01eafb1410c5b43e1214efaac prealloc: Get rid of manual memory management for prealloc contexts (Tim Ruffing) 6573c08f656f8ec305a2db801d57bfe6441e83e0 ecmult_gen: Tidy precomputed file and save space (Tim Ruffing) 5eba83f17c5aa1cf3698bb057a4b3ee35f3b6c30 ecmult_gen: Precompute tables for all values of ECMULT_GEN_PREC_BITS (Tim Ruffing) fdb33dd1227f935ca95c7f8bd9429f42e18a870e refactor: Make PREC_BITS a parameter of ecmult_gen_build_prec_table (Tim Ruffing) a4875e30a631d67b77b41f37fc3bf06ffb8ff11f refactor: Move default callbacks to util.h (Tim Ruffing) 4c94c55bce9e1fae8fd2e8993726c8ec74cc0f7d doc: Remove obsolete hint for valgrind stack size (Tim Ruffing) 5106226991117da78f85ca88b7ea66c2ac8fe0b3 exhaustive_tests: Fix with ecmult_gen table with custom generator (Tim Ruffing) e1a76530db40b8aa8953717d9f984b6bdf845308 refactor: Make generator a parameter of ecmult_gen_create_prec_table (Tim Ruffing) 9ad09f6911906a1fa9af2c5540a8004e44f3ccc6 refactor: Rename program that generates static ecmult_gen table (Tim Ruffing) 8ae18f1ab3dce4c487bab75c2f0cdf4fe311b318 refactor: Rename file that contains static ecmult_gen table (Tim Ruffing) 00d2fa116ed7a8c2d049723aca8d8b6d1c49f6a8 ecmult_gen: Make code consistent with comment (Tim Ruffing) 3b0c2185eab0fe5cb910fffee4c88e134f6d3cad ecmult_gen: Simplify ecmult_gen context after making table static (Tim Ruffing) e43ba02cfc836dba48c8c9a483e79b7589ce9ae1 refactor: Decouple table generation and ecmult_gen context (Tim Ruffing) 22dc2c0a0dc3b321e72253f492cfa8bcbf00169b ecmult_gen: Move table creation to new file and force static prec (Tim Ruffing) 099bad945e9a7c5237cdd764eca420285a9de279 Comment and check a parameter for inf in secp256k1_ecmult_const. (Russell O'Connor) 6c0be857f8fee7807a2a704465d2e0f6b1f021e3 Verify that secp256k1_ge_set_gej_zinv does not operate on infinity. a->x and a->y should not be used if the infinity flag is set. (Russell O'Connor) 5eb519e1f60c305e9240946d5773a635192d2a1a ci: reduce TEST_ITERS in memcheck run (Pieter Wuille) e2cf77328a07c9d972db6a4a65f65424634b54ab Test ecmult functions for all i*2^j for j=0..255 and odd i=1..255. (Pieter Wuille) c0cd7de6d4e497c0e678f7098079727188e81de8 build: add -no-undefined to libtool LDFLAGS (fanquake) fe32a79d354dfc7f341dbfdd6b8f0d408bd76e5b build: pass win32-dll to LT_INIT (fanquake) 7c7ce872a53f386f7c6a3a8ea04442840902193b build: Add a check that Valgrind actually supports a host platform (Hennadii Stepanov) 592661c22f56736099f83700be8cf280f8a963ff ci: move test environment variable declaration to .cirrus.yml (siv2r) dcbe84b84182bb077bc8639536a778a3129b1b3e bench: add --help option to bench. (siv2r) 2b7c7497ef66eae3a178b666fe17af40495322a6 build: replace backtick command substitution with $() (fanquake) 60bf8890df5360148df921f26d8dc4d667dd5926 ecmult: fix definition of STRAUSS_SCRATCH_OBJECTS (Jonas Nick) 214042a170c860523b7aad2a251b0dbfbaefb235 build: don't append valgrind CPPFLAGS if not installed (fanquake) 812ff5c74745e451f1a9de83b5bd0d0c18c75e5f doc: remove use of 0xa0 "no break space" (fanquake) dc9b6853b72b9a492cad230623670e89157525ca doc: Minor fixes in safegcd_implementation.md (Elliott Jin) 233297579db61ffe6bf7e882b2ee1c3796f874d8 Fix typos (Dimitris Apostolou) 72de1359e953390dc2f1ab5a59dd1a4057000acb ci: Enable -g if we set CFLAGS manually (Tim Ruffing) 16d132215cab68e57798927301268518bc1c3bf8 refactor: Use (int)&(int) in boolean context to avoid compiler warning (MarcoFalke) 3b157c48edb8ab080683232125dc7ec058bbd24c doc: Suggest keys.openpgp.org as keyserver in SECURITY.md (Tim Ruffing) 73a7472cd0335f2aa7eaf2c514e909ce36aba291 doc: Replace apoelstra's GPG key by jonasnick's GPG key (Tim Ruffing) af6abcb3d0097a7f7892fb8b54a4c6363e5c2c7f Make bench support selecting which benchmarks to run (Pieter Wuille) 9f56bdf5b9ba2e22e77c6adaaeb8302398732df3 Merge bench_schnorrsig into bench (Pieter Wuille) 3208557ae1062f7fcce25d5f2c5a29dc34a18895 Merge bench_recover into bench (Pieter Wuille) 855e18d8a809b98a622ab55765792aca132ea640 Merge bench_ecdh into bench (Pieter Wuille) 2a7be678a660d58742b1e767444c0fe75fa22592 Combine bench_sign and bench_verify into single bench (Pieter Wuille) 5324f8942dd322448fae6c9b225ecac2854fa7e2 Make aux_rnd32==NULL behave identical to 0x0000..00. (Pieter Wuille) 2888640132eb64ed30a8a208931f27447c3e0366 VERIFY_CHECK precondition for secp256k1_fe_set_int. (Russell O'Connor) d49011f54c2b31807158bdf06364f331558cccc7 Make _set_fe_int( . , 0 ) set magnitude to 0 (Tim Ruffing) 23e2f66726f930ac01d5075106aa16a4073442b4 bench: don't return 1 in have_flag() if argc = 1 (Jonas Nick) 96b1ad2ea9f9d9419e566b95162487c48902c3eb bench_ecmult: improve clarity of output (Jonas Nick) b4b130678db31a7cabc2cde091bc4acbca92b7a3 create csv file from the benchmark output (siv2r) 26a255beb673217c839dcc51790d9a484f9a292d Shared benchmark format for command line and CSV outputs (siv2r) 044d95630556dda5492a70af056bc277f0b79ebc Fix G.y parity in sage code (Pieter Wuille) b53e0cd61fce0bcef178f317537c91efc9afd04d Avoid overly-wide multiplications (Peter Dettman) 9be7b0f08340a063d961547b5d2663405f3fc162 Avoid computing out-of-bounds pointer. (Tim Ruffing) bc08599e776aff33c834ef829843ec5f629d1f39 Remove OpenSSL testing support (Pieter Wuille) db4667d5e0e13d1359991379df3400f64918b4e8 Make aux_rand32 arg to secp256k1_schnorrsig_sign const (Pieter Wuille) 189f6bcfef6578b89e21f937b24060f74bd18f00 Fix unused parameter warnings when building without VERIFY (Jonas Nick) d43993724deb5fdc1d2162f7423f8e8398103dd5 tests: remove `secp256k1_fe_verify` from tests.c and modify `secp256k1_fe_from_storage` to call `secp256k1_fe_verify` (siv2r) Pull request description: [bitcoin-core/secp256k1#986]: tests: remove `secp256k1_fe_verify` from tests.c and modify `_fe_from_storage` to call `_fe_verify` [bitcoin-core/secp256k1#987]: Fix unused parameter warnings when building without VERIFY [bitcoin-core/secp256k1#966]: Make aux_rand32 arg to secp256k1_schnorrsig_sign const [bitcoin-core/secp256k1#983]: [RFC] Remove OpenSSL testing support [bitcoin-core/secp256k1#952]: Avoid computing out-of-bounds pointer. [bitcoin-core/secp256k1#810]: Avoid overly-wide multiplications in 5x52 field mul/sqr [bitcoin-core/secp256k1#996]: Fix G.y parity in sage code [bitcoin-core/secp256k1#989]: Shared benchmark format for command line and CSV outputs [bitcoin-core/secp256k1#999]: bench_ecmult: improve clarity of output [bitcoin-core/secp256k1#943]: VERIFY_CHECK precondition for secp256k1_fe_set_int. [bitcoin-core/secp256k1#1002]: Make aux_rnd32==NULL behave identical to 0x0000..00. [bitcoin-core/secp256k1#991]: Merge all "external" benchmarks into a single bench binary [bitcoin-core/secp256k1#1007]: doc: Replace apoelstra's GPG key by jonasnick's GPG key [bitcoin-core/secp256k1#1009]: refactor: Use (int)&(int) in boolean context to avoid compiler warning [bitcoin-core/secp256k1#1011]: ci: Enable -g if we set CFLAGS manually [bitcoin-core/secp256k1#1012]: Fix typos [bitcoin-core/secp256k1#1010]: doc: Minor fixes in safegcd_implementation.md [bitcoin-core/secp256k1#1020]: doc: remove use of <0xa0> "no break space" [bitcoin-core/secp256k1#1019]: build: don't append valgrind CPPFLAGS if not installed (macOS) [bitcoin-core/secp256k1#1004]: ecmult: fix definition of STRAUSS_SCRATCH_OBJECTS [bitcoin-core/secp256k1#1025]: build: replace backtick command substitution with $() [bitcoin-core/secp256k1#1008]: bench.c: add `--help` option and ci: move env variables [bitcoin-core/secp256k1#1027]: build: Add a check that Valgrind actually supports a host platform [bitcoin-core/secp256k1#1022]: build: Windows DLL additions [bitcoin-core/secp256k1#920]: Test all ecmult functions with many j*2^i combinations [bitcoin-core/secp256k1#942]: Verify that secp256k1_ge_set_gej_zinv does not operate on infinity. [bitcoin-core/secp256k1#988]: Make signing table fully static [bitcoin-core/secp256k1#1042]: Follow-ups to making all tables fully static [bitcoin-core/secp256k1#816]: Improve checks at top of _fe_negate methods [bitcoin-core/secp256k1#1044]: Add another ecmult_multi test [bitcoin-core/secp256k1#1030]: doc: Fix upper bounds + cleanup in field_5x52_impl.h comment [bitcoin-core/secp256k1#1047]: ci: Various improvements [bitcoin-core/secp256k1#1053]: ecmult: move `_ecmult_odd_multiples_table_globalz_windowa` [bitcoin-core/secp256k1#964]: Add release-process.md [bitcoin-core/secp256k1#1052]: Use xoshiro256++ instead of RFC6979 for tests [bitcoin-core/secp256k1#1054]: tests: Fix test whose result is implementation-defined [bitcoin-core/secp256k1#1029]: Simpler and faster ecdh skew fixup This PR can be recreated with `./contrib/sync-upstream.sh range a1102b12196ea27f44d6201de4d25926a2ae9640`. ACKs for top commit: apoelstra: utACK b7ebe6436cd9ea6e91829589b2010c587a033c40 real-or-random: ACK b7ebe6436cd9ea6e91829589b2010c587a033c40 diff looks good. tested on my machine, also on valgrind. Tree-SHA512: 8b01347bbb9ac35cb93df628eaaf2a997fc8182046588bccc48a0623e9595d40cad2d46102a9c62c819ff77069331f344361138fd8ad0afc81bba9c1690bb541
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 Schnorr signatures according to BIP-340 (experimental).
- 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 # run the test suite
$ sudo make install # optional
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
Benchmark
If configured with --enable-benchmark
(which is the default), binaries for benchmarking the libsecp256k1 functions will be present in the root directory after the build.
To print the benchmark result to the command line:
$ ./bench_name
To create a CSV file for the benchmark result :
$ ./bench_name | sed '2d;s/ \{1,\}//g' > bench_name.csv
Reporting a vulnerability
See SECURITY.md