mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 23:29:12 +01:00
ecae2acb06d44509425a9cdad38ed9a5bce15cbe
bccaf86Merge pull request #1502a53a47Merge pull request #1515f5a31fMerge pull request #1493907277Merge pull request #142a3e0611Enable tests in x86 travis builds45da235x86 builder8bb0e93Merge pull request #155971fe81build: fix openssl detection for cross buildsf22d73eExplicitly access %0..%2 as 64-bit so we use the right registers for x32 ABIe66d4d6Avoid the stack in assembly and use explicit registerscf7b2b4Fix ECDSA message hashes to 32 bytes056ad31Really compile with -O3 by default74ad63aMerge pull request #1469000458Merge pull request #1451f46b00build: fix __builtin_expect detection for clangaaba2e0Merge pull request #1368a0775cMerge pull request #144ee1eaa7Merge pull request #141c88e2b8Compile with -O3 by default6558a26Make the benchmarks print out stats000bdf6Rename bench_verify to bench_recovery7c6fed2Add a few more additional tests.992e03btravis: add clang to the test matrixb43b79aMerge pull request #143e06a924Include time.h header for time().8d11164Add some additional tests.3545627Merge pull request #1186a9901eMerge pull request #137376b28bMerge pull request #1281728806Merge pull request #138a5759c5Check return value of malloc39bd94dVariable time normalizead86bdfMerge pull request #14054b768cAnother redundant secp256k1_fe_normalize69dcaabMerge pull request #1391c29f2eRemove redundant secp256k1_fe_normalize from secp256k1_gej_add_ge_var.2b9388bRemove unused secp256k1_fe_inv_allf461b76Allocate precomputation arrays on the heapb2c9681Make {mul,sqr}_inner use the same argument order as {mul,sqr}6793505Convert YASM code into inline assemblyf048615Rewrite field assembly to match the C version3ce74b1Tweak precomputed table size for G git-subtree-dir: src/secp256k1 git-subtree-split:bccaf86caa
libsecp256k1
Optimized C library for EC operations on curve secp256k1.
This library is experimental, so use at your own risk.
Features:
- Low-level field and group operations on secp256k1.
- ECDSA signing/verification and key generation.
- Adding/multiplying private/public keys.
- Serialization/parsing of private keys, public keys, signatures.
- Very efficient implementation.
Implementation details
- General
- Avoid dynamic memory usage almost everywhere.
- 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.
- Using GMP.
- Field inverses and square roots using a sliding window over blocks of 1s (by Peter Dettman).
- 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.
- 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 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.
- Optionally use secp256k1's efficiently-computable endomorphism to split the multiplicands into 4 half-sized ones first.
- 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.
- Slice the precomputed table in memory per byte, so memory access to the table becomes uniform.
- No data-dependent branches
- The precomputed tables add and eventually subtract points for which no known scalar (private key) is known, preventing even an attacker with control over the private key used to control the data internally.
Build steps
libsecp256k1 is built using autotools:
$ ./autogen.sh
$ ./configure
$ make
$ sudo make install # optional
Description
Languages
C++
65%
Python
19%
C
12.2%
CMake
1.3%
Shell
0.8%
Other
1.6%