]> Git Repo - secp256k1.git/blame - README.md
Stop treating ECDH as experimental
[secp256k1.git] / README.md
CommitLineData
3f37bcc2
PW
1libsecp256k1
2============
3
faa2a11c 4[![Build Status](https://travis-ci.org/bitcoin-core/secp256k1.svg?branch=master)](https://travis-ci.org/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.
2e759ec7
TR
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.
8622cc25 22
3f37bcc2
PW
23Implementation details
24----------------------
25
26* General
b5bbce62
GM
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.
bde2a322 31 * No use of floating types.
b5bbce62 32 * Expose only higher level interfaces to minimize the API surface and improve application security. ("Be difficult to use insecurely.")
3f37bcc2
PW
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).
2e759ec7 36 * Using 10 26-bit limbs (including hand-optimized assembly for 32-bit ARM, by Wladimir J. van der Laan).
3f37bcc2 37 * Field inverses and square roots using a sliding window over blocks of 1s (by Peter Dettman).
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.
3f37bcc2
PW
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.
6c7f0c62 45 * Use a unified addition/doubling formula where necessary to avoid data-dependent branches.
b5bbce62 46 * Point/x comparison without a field inversion by comparison in the Jacobian coordinate space.
3f37bcc2
PW
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.
4232e5b7 51 * Use secp256k1's efficiently-computable endomorphism to split the P multiplicand into 2 half-sized ones.
3f37bcc2
PW
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.
8d1563b0
GM
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.
2e759ec7 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.
7fc1fb4f
JD
59
60Build steps
61-----------
62
63libsecp256k1 is built using autotools:
64
62c58902 65 $ ./autogen.sh
7fc1fb4f
JD
66 $ ./configure
67 $ make
ce6d4382 68 $ make check
7fc1fb4f 69 $ sudo make install # optional
dcb2e3b3 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
78c38363 79
acb7f97e
MB
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
78c38363
JN
101Reporting a vulnerability
102------------
103
104See [SECURITY.md](SECURITY.md)
This page took 0.044047 seconds and 4 git commands to generate.