• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..08-Sep-2021-

build-aux/m4/H08-Sep-2021-211198

ci/H08-Sep-2021-10179

contrib/H08-Sep-2021-447257

doc/H08-Sep-2021-766647

include/H08-Sep-2021-1,437433

obj/H08-Sep-2021-

sage/H08-Sep-2021-1,1771,016

src/H08-Sep-2021-23,72718,124

.cirrus.ymlH A D08-Sep-20215.8 KiB199192

.gitignoreH A D08-Sep-2021741 5452

COPYINGH A D08-Sep-20211 KiB2016

Makefile.amH A D08-Sep-20215.2 KiB165143

README.mdH A D08-Sep-20214.9 KiB10578

SECURITY.mdH A D08-Sep-2021683 1610

autogen.shH A D08-Sep-202147 42

configure.acH A D08-Sep-202118.6 KiB545477

libsecp256k1.pc.inH A D08-Sep-2021327 1411

README.md

1libsecp256k1
2============
3
4[![Build Status](https://api.cirrus-ci.com/github/bitcoin-core/secp256k1.svg?branch=master)](https://cirrus-ci.com/github/bitcoin-core/secp256k1)
5
6Optimized C library for ECDSA signatures and secret/public key operations on curve secp256k1.
7
8This 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.
9
10Features:
11* secp256k1 ECDSA signing/verification and key generation.
12* Additive and multiplicative tweaking of secret/public keys.
13* Serialization/parsing of secret keys, public keys, signatures.
14* Constant time, constant memory access signing and public key generation.
15* Derandomized ECDSA (via RFC6979 or with a caller provided function.)
16* Very efficient implementation.
17* Suitable for embedded systems.
18* Optional module for public key recovery.
19* Optional module for ECDH key exchange.
20
21Experimental 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.
22
23Implementation details
24----------------------
25
26* General
27  * No runtime heap allocation.
28  * Extensive testing infrastructure.
29  * Structured to facilitate review and analysis.
30  * Intended to be portable to any system with a C89 compiler and uint64_t support.
31  * No use of floating types.
32  * Expose only higher level interfaces to minimize the API surface and improve application security. ("Be difficult to use insecurely.")
33* Field operations
34  * Optimized implementation of arithmetic modulo the curve's field size (2^256 - 0x1000003D1).
35    * Using 5 52-bit limbs (including hand-optimized assembly for x86_64, by Diederik Huys).
36    * Using 10 26-bit limbs (including hand-optimized assembly for 32-bit ARM, by Wladimir J. van der Laan).
37* Scalar operations
38  * Optimized implementation without data-dependent branches of arithmetic modulo the curve's order.
39    * Using 4 64-bit limbs (relying on __int128 support in the compiler).
40    * Using 8 32-bit limbs.
41* Modular inverses (both field elements and scalars) based on [safegcd](https://gcd.cr.yp.to/index.html) with some modifications, and a variable-time variant (by Peter Dettman).
42* Group operations
43  * Point addition formula specifically simplified for the curve equation (y^2 = x^3 + 7).
44  * Use addition between points in Jacobian and affine coordinates where possible.
45  * Use a unified addition/doubling formula where necessary to avoid data-dependent branches.
46  * Point/x comparison without a field inversion by comparison in the Jacobian coordinate space.
47* Point multiplication for verification (a*P + b*G).
48  * Use wNAF notation for point multiplicands.
49  * Use a much larger window for multiples of G, using precomputed multiples.
50  * Use Shamir's trick to do the multiplication with the public key and the generator simultaneously.
51  * Use secp256k1's efficiently-computable endomorphism to split the P multiplicand into 2 half-sized ones.
52* Point multiplication for signing
53  * Use a precomputed table of multiples of powers of 16 multiplied with the generator, so general multiplication becomes a series of additions.
54  * Intended to be completely free of timing sidechannels for secret-key operations (on reasonable hardware/toolchains)
55    * Access the table with branch-free conditional moves so memory access is uniform.
56    * No data-dependent branches
57  * Optional runtime blinding which attempts to frustrate differential power analysis.
58  * 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.
59
60Build steps
61-----------
62
63libsecp256k1 is built using autotools:
64
65    $ ./autogen.sh
66    $ ./configure
67    $ make
68    $ make check
69    $ sudo make install  # optional
70
71Exhaustive tests
72-----------
73
74    $ ./exhaustive_tests
75
76With valgrind, you might need to increase the max stack size:
77
78    $ valgrind --max-stackframe=2500000 ./exhaustive_tests
79
80Test coverage
81-----------
82
83This library aims to have full coverage of the reachable lines and branches.
84
85To create a test coverage report, configure with `--enable-coverage` (use of GCC is necessary):
86
87    $ ./configure --enable-coverage
88
89Run the tests:
90
91    $ make check
92
93To create a report, `gcovr` is recommended, as it includes branch coverage reporting:
94
95    $ gcovr --exclude 'src/bench*' --print-summary
96
97To create a HTML report with coloured and annotated source code:
98
99    $ gcovr --exclude 'src/bench*' --html --html-details -o coverage.html
100
101Reporting a vulnerability
102------------
103
104See [SECURITY.md](SECURITY.md)
105