Skip to content

Commit 87ea150

Browse files
committed
Add a copy of libsecp256k1.
1 parent a8e1cce commit 87ea150

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+11542
-0
lines changed

secp256k1/.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
bench_inv
2+
bench_sign
3+
bench_verify
4+
bench_recover
5+
bench_internal
6+
tests
7+
*.exe
8+
*.so
9+
*.a
10+
!.gitignore
11+
12+
Makefile
13+
configure
14+
.libs/
15+
Makefile.in
16+
aclocal.m4
17+
autom4te.cache/
18+
config.log
19+
config.status
20+
*.tar.gz
21+
*.la
22+
libtool
23+
.deps/
24+
.dirstamp
25+
build-aux/
26+
*.lo
27+
*.o
28+
*~
29+
src/libsecp256k1-config.h
30+
src/libsecp256k1-config.h.in
31+
m4/libtool.m4
32+
m4/ltoptions.m4
33+
m4/ltsugar.m4
34+
m4/ltversion.m4
35+
m4/lt~obsolete.m4
36+
src/stamp-h1
37+
libsecp256k1.pc

secp256k1/.travis.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
language: c
2+
sudo: false
3+
addons:
4+
apt:
5+
packages: libgmp-dev
6+
compiler:
7+
- clang
8+
- gcc
9+
env:
10+
global:
11+
- FIELD=auto BIGNUM=auto SCALAR=auto ENDOMORPHISM=no ASM=no BUILD=check EXTRAFLAGS= HOST=
12+
matrix:
13+
- SCALAR=32bit
14+
- SCALAR=64bit
15+
- FIELD=64bit
16+
- FIELD=64bit ENDOMORPHISM=yes
17+
- FIELD=64bit ASM=x86_64
18+
- FIELD=64bit ENDOMORPHISM=yes ASM=x86_64
19+
- FIELD=32bit
20+
- FIELD=32bit ENDOMORPHISM=yes
21+
- BIGNUM=no
22+
- BIGNUM=no ENDOMORPHISM=yes
23+
- BUILD=distcheck
24+
- EXTRAFLAGS=CFLAGS=-DDETERMINISTIC
25+
matrix:
26+
fast_finish: true
27+
include:
28+
- compiler: clang
29+
env: HOST=i686-linux-gnu ENDOMORPHISM=yes
30+
addons:
31+
apt:
32+
packages:
33+
- gcc-multilib
34+
- libgmp-dev:i386
35+
- compiler: clang
36+
env: HOST=i686-linux-gnu
37+
addons:
38+
apt:
39+
packages:
40+
- gcc-multilib
41+
- compiler: gcc
42+
env: HOST=i686-linux-gnu ENDOMORPHISM=yes
43+
addons:
44+
apt:
45+
packages:
46+
- gcc-multilib
47+
- compiler: gcc
48+
env: HOST=i686-linux-gnu
49+
addons:
50+
apt:
51+
packages:
52+
- gcc-multilib
53+
- libgmp-dev:i386
54+
before_script: ./autogen.sh
55+
script:
56+
- if [ -n "$HOST" ]; then export USE_HOST="--host=$HOST"; fi
57+
- if [ "x$HOST" = "xi686-linux-gnu" ]; then export CC="$CC -m32"; fi
58+
- ./configure --enable-endomorphism=$ENDOMORPHISM --with-field=$FIELD --with-bignum=$BIGNUM --with-scalar=$SCALAR $EXTRAFLAGS $USE_HOST && make -j2 $BUILD
59+
os: linux

secp256k1/COPYING

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2013 Pieter Wuille
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

secp256k1/Makefile.am

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
ACLOCAL_AMFLAGS = -I build-aux/m4
2+
3+
lib_LTLIBRARIES = libsecp256k1.la
4+
include_HEADERS = include/secp256k1.h
5+
noinst_HEADERS =
6+
noinst_HEADERS += src/scalar.h
7+
noinst_HEADERS += src/scalar_4x64.h
8+
noinst_HEADERS += src/scalar_8x32.h
9+
noinst_HEADERS += src/scalar_impl.h
10+
noinst_HEADERS += src/scalar_4x64_impl.h
11+
noinst_HEADERS += src/scalar_8x32_impl.h
12+
noinst_HEADERS += src/group.h
13+
noinst_HEADERS += src/group_impl.h
14+
noinst_HEADERS += src/num_gmp.h
15+
noinst_HEADERS += src/num_gmp_impl.h
16+
noinst_HEADERS += src/ecdsa.h
17+
noinst_HEADERS += src/ecdsa_impl.h
18+
noinst_HEADERS += src/eckey.h
19+
noinst_HEADERS += src/eckey_impl.h
20+
noinst_HEADERS += src/ecmult.h
21+
noinst_HEADERS += src/ecmult_impl.h
22+
noinst_HEADERS += src/ecmult_gen.h
23+
noinst_HEADERS += src/ecmult_gen_impl.h
24+
noinst_HEADERS += src/num.h
25+
noinst_HEADERS += src/num_impl.h
26+
noinst_HEADERS += src/field_10x26.h
27+
noinst_HEADERS += src/field_10x26_impl.h
28+
noinst_HEADERS += src/field_5x52.h
29+
noinst_HEADERS += src/field_5x52_impl.h
30+
noinst_HEADERS += src/field_5x52_int128_impl.h
31+
noinst_HEADERS += src/field_5x52_asm_impl.h
32+
noinst_HEADERS += src/java/org_bitcoin_NativeSecp256k1.h
33+
noinst_HEADERS += src/util.h
34+
noinst_HEADERS += src/testrand.h
35+
noinst_HEADERS += src/testrand_impl.h
36+
noinst_HEADERS += src/hash.h
37+
noinst_HEADERS += src/hash_impl.h
38+
noinst_HEADERS += src/field.h
39+
noinst_HEADERS += src/field_impl.h
40+
noinst_HEADERS += src/bench.h
41+
42+
pkgconfigdir = $(libdir)/pkgconfig
43+
pkgconfig_DATA = libsecp256k1.pc
44+
45+
libsecp256k1_la_SOURCES = src/secp256k1.c
46+
libsecp256k1_la_CPPFLAGS = -I$(top_srcdir)/include $(SECP_INCLUDES)
47+
libsecp256k1_la_LIBADD = $(SECP_LIBS)
48+
49+
50+
noinst_PROGRAMS =
51+
if USE_BENCHMARK
52+
noinst_PROGRAMS += bench_verify bench_recover bench_sign bench_internal
53+
bench_verify_SOURCES = src/bench_verify.c
54+
bench_verify_LDADD = libsecp256k1.la $(SECP_LIBS)
55+
bench_verify_LDFLAGS = -static
56+
bench_recover_SOURCES = src/bench_recover.c
57+
bench_recover_LDADD = libsecp256k1.la $(SECP_LIBS)
58+
bench_recover_LDFLAGS = -static
59+
bench_sign_SOURCES = src/bench_sign.c
60+
bench_sign_LDADD = libsecp256k1.la $(SECP_LIBS)
61+
bench_sign_LDFLAGS = -static
62+
bench_internal_SOURCES = src/bench_internal.c
63+
bench_internal_LDADD = $(SECP_LIBS)
64+
bench_internal_LDFLAGS = -static
65+
bench_internal_CPPFLAGS = $(SECP_INCLUDES)
66+
endif
67+
68+
if USE_TESTS
69+
noinst_PROGRAMS += tests
70+
tests_SOURCES = src/tests.c
71+
tests_CPPFLAGS = -DVERIFY $(SECP_INCLUDES) $(SECP_TEST_INCLUDES)
72+
tests_LDADD = $(SECP_LIBS) $(SECP_TEST_LIBS)
73+
tests_LDFLAGS = -static
74+
TESTS = tests
75+
endif
76+
77+
EXTRA_DIST = autogen.sh

secp256k1/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
libsecp256k1
2+
============
3+
4+
[![Build Status](https://travis-ci.org/bitcoin/secp256k1.svg?branch=master)](https://travis-ci.org/bitcoin/secp256k1)
5+
6+
Optimized C library for EC operations on curve secp256k1.
7+
8+
This library is a work in progress and is being used to research best practices. Use at your own risk.
9+
10+
Features:
11+
* secp256k1 ECDSA signing/verification and key generation.
12+
* Adding/multiplying private/public keys.
13+
* Serialization/parsing of private keys, public keys, signatures.
14+
* Constant time, constant memory access signing and pubkey generation.
15+
* Derandomized DSA (via RFC6979 or with a caller provided function.)
16+
* Very efficient implementation.
17+
18+
Implementation details
19+
----------------------
20+
21+
* General
22+
* No runtime heap allocation.
23+
* Extensive testing infrastructure.
24+
* Structured to facilitate review and analysis.
25+
* Intended to be portable to any system with a C89 compiler and uint64_t support.
26+
* Expose only higher level interfaces to minimize the API surface and improve application security. ("Be difficult to use insecurely.")
27+
* Field operations
28+
* Optimized implementation of arithmetic modulo the curve's field size (2^256 - 0x1000003D1).
29+
* Using 5 52-bit limbs (including hand-optimized assembly for x86_64, by Diederik Huys).
30+
* Using 10 26-bit limbs.
31+
* Field inverses and square roots using a sliding window over blocks of 1s (by Peter Dettman).
32+
* Scalar operations
33+
* Optimized implementation without data-dependent branches of arithmetic modulo the curve's order.
34+
* Using 4 64-bit limbs (relying on __int128 support in the compiler).
35+
* Using 8 32-bit limbs.
36+
* Group operations
37+
* Point addition formula specifically simplified for the curve equation (y^2 = x^3 + 7).
38+
* Use addition between points in Jacobian and affine coordinates where possible.
39+
* Use a unified addition/doubling formula where necessary to avoid data-dependent branches.
40+
* Point/x comparison without a field inversion by comparison in the Jacobian coordinate space.
41+
* Point multiplication for verification (a*P + b*G).
42+
* Use wNAF notation for point multiplicands.
43+
* Use a much larger window for multiples of G, using precomputed multiples.
44+
* Use Shamir's trick to do the multiplication with the public key and the generator simultaneously.
45+
* Optionally (off by default) use secp256k1's efficiently-computable endomorphism to split the P multiplicand into 2 half-sized ones.
46+
* Point multiplication for signing
47+
* Use a precomputed table of multiples of powers of 16 multiplied with the generator, so general multiplication becomes a series of additions.
48+
* Access the table with branch-free conditional moves so memory access is uniform.
49+
* No data-dependent branches
50+
* 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.
51+
52+
Build steps
53+
-----------
54+
55+
libsecp256k1 is built using autotools:
56+
57+
$ ./autogen.sh
58+
$ ./configure
59+
$ make
60+
$ ./tests
61+
$ sudo make install # optional

secp256k1/TODO

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* Unit tests for fieldelem/groupelem, including ones intended to
2+
trigger fieldelem's boundary cases.
3+
* Complete constant-time operations for signing/keygen

secp256k1/autogen.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
set -e
3+
autoreconf -if --warnings=all

0 commit comments

Comments
 (0)