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