The blockchain that provides the digital content namespace for the LBRY protocol
Find a file
Pieter Wuille ecae2acb06 Squashed 'src/secp256k1/' changes from b0210a9..bccaf86
bccaf86 Merge pull request #150
2a53a47 Merge pull request #151
5f5a31f Merge pull request #149
3907277 Merge pull request #142
a3e0611 Enable tests in x86 travis builds
45da235 x86 builder
8bb0e93 Merge pull request #155
971fe81 build: fix openssl detection for cross builds
f22d73e Explicitly access %0..%2 as 64-bit so we use the right registers for x32 ABI
e66d4d6 Avoid the stack in assembly and use explicit registers
cf7b2b4 Fix ECDSA message hashes to 32 bytes
056ad31 Really compile with -O3 by default
74ad63a Merge pull request #146
9000458 Merge pull request #145
1f46b00 build: fix __builtin_expect detection for clang
aaba2e0 Merge pull request #136
8a0775c Merge pull request #144
ee1eaa7 Merge pull request #141
c88e2b8 Compile with -O3 by default
6558a26 Make the benchmarks print out stats
000bdf6 Rename bench_verify to bench_recovery
7c6fed2 Add a few more additional tests.
992e03b travis: add clang to the test matrix
b43b79a Merge pull request #143
e06a924 Include time.h header for time().
8d11164 Add some additional tests.
3545627 Merge pull request #118
6a9901e Merge pull request #137
376b28b Merge pull request #128
1728806 Merge pull request #138
a5759c5 Check return value of malloc
39bd94d Variable time normalize
ad86bdf Merge pull request #140
54b768c Another redundant secp256k1_fe_normalize
69dcaab Merge pull request #139
1c29f2e Remove redundant secp256k1_fe_normalize from secp256k1_gej_add_ge_var.
2b9388b Remove unused secp256k1_fe_inv_all
f461b76 Allocate precomputation arrays on the heap
b2c9681 Make {mul,sqr}_inner use the same argument order as {mul,sqr}
6793505 Convert YASM code into inline assembly
f048615 Rewrite field assembly to match the C version
3ce74b1 Tweak precomputed table size for G

git-subtree-dir: src/secp256k1
git-subtree-split: bccaf86caa9c44166e5a66600b742c516e03c3f0
2014-12-11 01:58:25 +01:00
build-aux/m4 Squashed 'src/secp256k1/' changes from b0210a9..bccaf86 2014-12-11 01:58:25 +01:00
include Squashed 'src/secp256k1/' changes from b0210a9..bccaf86 2014-12-11 01:58:25 +01:00
obj Squashed 'src/secp256k1/' content from commit ad2028f 2014-11-18 18:06:36 +01:00
src Squashed 'src/secp256k1/' changes from b0210a9..bccaf86 2014-12-11 01:58:25 +01:00
.gitignore Squashed 'src/secp256k1/' content from commit ad2028f 2014-11-18 18:06:36 +01:00
.travis.yml Squashed 'src/secp256k1/' changes from b0210a9..bccaf86 2014-12-11 01:58:25 +01:00
autogen.sh Squashed 'src/secp256k1/' content from commit ad2028f 2014-11-18 18:06:36 +01:00
configure.ac Squashed 'src/secp256k1/' changes from b0210a9..bccaf86 2014-12-11 01:58:25 +01:00
COPYING Squashed 'src/secp256k1/' content from commit ad2028f 2014-11-18 18:06:36 +01:00
libsecp256k1.pc.in Squashed 'src/secp256k1/' content from commit ad2028f 2014-11-18 18:06:36 +01:00
Makefile.am Squashed 'src/secp256k1/' changes from b0210a9..bccaf86 2014-12-11 01:58:25 +01:00
README.md Squashed 'src/secp256k1/' content from commit ad2028f 2014-11-18 18:06:36 +01:00
TODO Squashed 'src/secp256k1/' content from commit ad2028f 2014-11-18 18:06:36 +01:00

libsecp256k1

Build Status

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).
  • 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.
  • 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