1010 Commits

Author SHA1 Message Date
Gregory Sanders
0593861cc5 Enable more builds with rest of experimental flags 2019-05-30 14:04:38 +00:00
Jonas Nick
e9fea74278 Add explanation about how BIP32 unhardened derivation can be used to simplify whitelisting 2019-05-30 14:04:38 +00:00
Jonas Nick
dec1b9ce27 Add comment to explain effect of max_n_iterations in surjectionproof_init 2019-05-30 14:04:38 +00:00
Andrew Poelstra
ea62bfe221 add unit test for generator and pedersen commitment roundtripping 2019-05-30 14:04:38 +00:00
Andrew Poelstra
e32924f0ee rangeproof: fix serialization of pedersen commintments 2019-05-30 14:04:38 +00:00
Andrew Poelstra
972d056fac rangeproof: verify correctness of pedersen commitments when parsing 2019-05-30 14:04:38 +00:00
Andrew Poelstra
2cc4c6fef1 generator: verify correctness of point when parsing 2019-05-30 14:04:38 +00:00
Andrew Poelstra
65ffea43d5 rangeproof: check that points deserialize correctly when verifying rangeproof 2019-05-30 14:04:38 +00:00
Andrew Poelstra
cb786d6d1a rangeproof: add fixed vector test case 2019-05-30 14:04:38 +00:00
Frank V. Castellucci
b387ba0389 Expose generator in shared library
Was failing linking to `*.so` library
2019-05-30 14:04:38 +00:00
Gregory Sanders
8da432855c fix spelling in documentation 2019-05-30 14:04:38 +00:00
Tim Ruffing
6f14fe40d9 Test for rejection of trailing bytes in range proofs 2019-05-30 14:04:38 +00:00
Tim Ruffing
ab4fbc1be8 Test for rejection of trailing bytes in surjection proofs 2019-05-30 14:04:38 +00:00
Tim Ruffing
c908c97d67 Reject surjection proofs with trailing garbage 2019-05-30 14:04:38 +00:00
datavetaren
f723bf5b37 Minor bugfix. Wrong length due to NUL character. 2019-05-30 14:04:38 +00:00
Jonas Nick
6872069de9 Add whitelisting benchmark 2019-05-30 14:04:38 +00:00
Gregory Sanders
6ceccb75be add whitelist_impl.h to include for dist 2019-05-30 14:04:38 +00:00
Andrew Poelstra
a3ad4a8668 generator: add API tests 2019-05-30 14:04:38 +00:00
Andrew Poelstra
e93e886cb4 generator: remove unnecessary ARG_CHECK from generate() 2019-05-30 14:04:38 +00:00
Gregory Sanders
f1d6e4b831 Fix generator makefile
Include test_impl.h
2019-05-30 14:04:38 +00:00
Jonas Nick
68be611317 Fix pedersen_blind_generator_blind_sum return value documentation 2019-05-30 14:04:38 +00:00
Jonas Nick
51fc58ae6b Add n_keys argument to whitelist_verify 2019-05-30 14:04:38 +00:00
Jonas Nick
36b100c779 Fix checks of whitelist serialize/parse arguments 2019-05-30 14:04:38 +00:00
Andrew Poelstra
c8f54e12ec whitelist: fix serialize/parse API to take serialized length 2019-05-30 14:04:38 +00:00
Jonas Nick
56fca50778 Fix include/secp256k1_rangeproof.h function argument documentation. 2019-05-30 14:04:38 +00:00
Andrew Poelstra
4617f04784 rangeproof: add API tests 2019-05-30 14:04:38 +00:00
Andrew Poelstra
cd4e438a3a surjectionproof: rename unit test functions to be more consistent with other modules 2019-05-30 14:04:38 +00:00
Andrew Poelstra
2cc7f1e045 surjectionproof: add API unit tests 2019-05-30 14:04:38 +00:00
Andrew Poelstra
c4097f758f surjectionproof: tests_impl.h s/assert/CHECK/g 2019-05-30 14:04:38 +00:00
Andrew Poelstra
5ee6bf3418 rangeproof: fix memory leak in unit tests 2019-05-30 14:04:38 +00:00
Andrew Poelstra
94e81a250e add surjection proof module
Includes fix and tests by Jonas Nick.
2019-05-30 14:04:38 +00:00
Andrew Poelstra
a66ea35227 Implement ring-signature based whitelist delegation scheme 2019-05-30 14:04:38 +00:00
Andrew Poelstra
2bb5133615 rangeproof: several API changes
* add summing function for blinded generators
* drop `excess` and `gen` from `verify_tally`
* add extra_commit to rangeproof sign and verify
2019-05-30 14:04:38 +00:00
Pieter Wuille
9b00b61d9d Expose generator in pedersen/rangeproof API 2019-05-30 14:04:38 +00:00
Pieter Wuille
54fa2639e1 Constant-time generator module 2019-05-30 14:04:38 +00:00
Andrew Poelstra
023aa86ac0 rangeproof: expose sidechannel message field in the signing API
Including a fix by Jonas Nick.
2019-05-30 14:04:38 +00:00
Andrew Poelstra
89e7451d42 [RANGEPROOF BREAK] Use quadratic residue for tie break and modularity cleanup
Switch to secp256k1_pedersen_commitment by Andrew Poelstra.
Switch to quadratic residue based disambiguation by Pieter Wuille.
2019-05-30 14:04:38 +00:00
Gregory Maxwell
f126331bc9 Pedersen commitments, borromean ring signatures, and ZK range proofs.
This commit adds three new cryptosystems to libsecp256k1:

Pedersen commitments are a system for making blinded commitments
 to a value.  Functionally they work like:
  commit_b,v = H(blind_b || value_v),
 except they are additively homorphic, e.g.
  C(b1, v1) - C(b2, v2) = C(b1 - b2, v1 - v2) and
  C(b1, v1) - C(b1, v1) = 0, etc.
 The commitments themselves are EC points, serialized as 33 bytes.
 In addition to the commit function this implementation includes
 utility functions for verifying that a set of commitments sums
 to zero, and for picking blinding factors that sum to zero.
 If the blinding factors are uniformly random, pedersen commitments
 have information theoretic privacy.

Borromean ring signatures are a novel efficient ring signature
 construction for AND/OR admissions policies (the code here implements
 an AND of ORs, each of any size).  This construction requires
 32 bytes of signature per pubkey used plus 32 bytes of constant
 overhead. With these you can construct signatures like "Given pubkeys
 A B C D E F G, the signer knows the discrete logs
 satisifying (A || B) & (C || D || E) & (F || G)".

ZK range proofs allow someone to prove a pedersen commitment is in
 a particular range (e.g. [0..2^64)) without revealing the specific
 value.  The construction here is based on the above borromean
 ring signature and uses a radix-4 encoding and other optimizations
 to maximize efficiency.  It also supports encoding proofs with a
 non-private base-10 exponent and minimum-value to allow trading
 off secrecy for size and speed (or just avoiding wasting space
 keeping data private that was already public due to external
 constraints).

A proof for a 32-bit mantissa takes 2564 bytes, but 2048 bytes of
 this can be used to communicate a private message to a receiver
 who shares a secret random seed with the prover.

Also: get rid of precomputed H tables (Pieter Wuille)
2019-05-30 14:04:38 +00:00
Greg Maxwell
e1fb4af90b Add 64-bit integer utilities 2019-05-30 14:04:38 +00:00
Gregory Maxwell
e541a90ef6
Merge #629: Avoid calling _is_zero when _set_b32 fails.
cd473e0 Avoid calling secp256k1_*_is_zero when secp256k1_*_set_b32 fails. (Gregory Maxwell)

Pull request description:

  Most of the codebase correctly used short-cutting to avoid calling
   _is_zero on possibly incompletely initialized elements, but a few
   places were missed.

ACKs for commit cd473e:
  sipa:
    utACK cd473e02c372217c3a6608ce5afaa543ed78f891
  jonasnick:
    utACK cd473e02c372217c3a6608ce5afaa543ed78f891

Tree-SHA512: d6af2863f6795d2df26f2bd05a4e33085e88c45f7794601ea57e67238a2073ef1ee3ba0feab62a7fcbc0636c48dfd80eea07d0ca4f194414127f914b0478c732
2019-05-29 21:47:45 +00:00
Gregory Maxwell
f34b0c3f35
Merge #630: Note intention of timing sidechannel freeness.
8d1563b Note intention of timing sidechannel freeness. (Gregory Maxwell)

Pull request description:

  Resolves #238

ACKs for commit 8d1563:

Tree-SHA512: 2b0ca945d70e5975291ed9a0884eddfd771fd06dfed37c9711f8b57d431c28b974e5a5d86ae6e70e5e37c5f208bcb74e9ab18fcf9d7b78849fcf3cff9ba7623b
2019-05-29 20:30:35 +00:00
Gregory Maxwell
8d1563b0ff Note intention of timing sidechannel freeness.
Resolves #238
2019-05-29 18:43:13 +00:00
Gregory Maxwell
1669bb2865
Merge #628: Fix ability to compile tests without -DVERIFY.
dcf3920 Fix ability to compile tests without -DVERIFY. (Gregory Maxwell)

Pull request description:

  Broken by 3f3964e4.

  It's important that the tests are also run without -DVERIFY due to
   the possibility that side-effects of a VERIFY_CHECK fix a bug that
   would otherwise be detected.

  Use of the verify_check macro in tests isn't sufficient.

ACKs for commit dcf392:

Tree-SHA512: ff7ca0e89e33f845656a4d7d18c0195d1378b020d67f89e900b18cf3d702aa81dd91ffd05a98953a481b83e4247eaf0c484bea12eab020efb3c966a456e8129f
2019-05-29 14:24:42 +00:00
Gregory Maxwell
ecc94abcc8
Merge #627: Guard memcmp in tests against mixed size inputs.
248bffb Guard memcmp in tests against mixed size inputs. (Gregory Maxwell)

Pull request description:

  Reported by real-or-random.

  Fixes #623.

ACKs for commit 248bff:
  practicalswift:
    utACK 248bffb0526ce8d829ce22f4d63d0d4a9ccfe137

Tree-SHA512: 29867c79d2d6852f495334a5a9129c7feac2df639dd7f752067380689b0ce9f9b35e94524834c01e698df5c0b83dc9855204ec09f5dfe488a388b509c9b861d9
2019-05-29 14:23:58 +00:00
Gregory Maxwell
544435fc90
Merge #578: Avoid implementation-defined and undefined behavior when dealing with sizes
14c7dbd Simplify control flow in DER parsing (Tim Ruffing)
ec8f20b Avoid out-of-bound pointers and integer overflows in size comparisons (Tim Ruffing)
01ee1b3 Parse DER-enconded length into a size_t instead of an int (Tim Ruffing)
3cb057f Fix possible integer overflow in DER parsing (Tim Ruffing)

Pull request description:

  This is a result of auditing the code for overflow issues at random places. None of this is critical but I think all of it should be fixed.

  I know this touches "red" code. I double-checked and triple-checked this but I can understand if some of the changes are not desirable because they change well-tested code.

  Best reviewed in individual commits.

ACKs for commit 14c7db:

Tree-SHA512: 312dd3f961739752e1a861e75bd755920f634f87ee9668793e102c224434e8d21367452e114de729322c71a89f4fa82126aa5d32742f2bbbc091777c99515e10
2019-05-29 11:06:19 +00:00
Gregory Maxwell
143dc6e9ee
Merge #595: Allow to use external default callbacks
e49f799 Add missing #(un)defines to base-config.h (Tim Ruffing)
77defd2 Add secp256k1_ prefix to default callback functions (Tim Ruffing)
908bdce Include stdio.h and stdlib.h explicitly in secp256k1.c (Tim Ruffing)
5db782e Allow usage of external default callbacks (Tim Ruffing)
6095a86 Replace CHECKs for no_precomp ctx by ARG_CHECKs without a return (Tim Ruffing)

Pull request description:

  This is intended for environments without implementations for `abort()`, `fprintf()`, and `stderr`. e.g., embedded systems. Those can provide their own implementations of `default_illegal_callback_fn` and `default_error_callback_fn` at compile time.

  If you want to use your own default callback, things will be somewhat inconsistent unfortunately: We cannot make the callback data `extern` too, because then the initialization lists for `default_illegal_callback` won't contain only constants. (`const` variables are not compile-time constants). So you cannot take callback data in your own default callback function.

  As a more drastic/breaking alternative I suggest to remove the callback data entirely. I don't think it's a big loss and I would be surprised if anyone uses it. Additionally, we could even remove the possibility to set the callback function at runtime after this PR. This will simplify things a lot, and again I don't think it's a big loss.

  Note that `abort()`, `fprintf()`, and `stderr` are also used in `CHECK`, which is still used in production code if we rely on gmp for scalar and field inversions (e.g.,  https://github.com/bitcoin-core/secp256k1/blob/master/src/scalar_impl.h#L240). This is not an issue for embedded system which probably don't want to use gmp anyway, but it is probably an issue for the reasons explained in https://github.com/bitcoin-core/secp256k1/pull/566#issuecomment-469111901.

  (related downstream: https://github.com/rust-bitcoin/rust-secp256k1/pull/100 @elichai)

ACKs for commit e49f79:

Tree-SHA512: 4dec0821eef4156cbe162bd8cdf0531c1fae8c98cd9db8438170ff1aa0e59b199739eeab293695bb582246812bea5309959f02f1fb74bb57872da54ebc52313f
2019-05-27 07:43:07 +00:00
Tim Ruffing
e49f7991c2 Add missing #(un)defines to base-config.h 2019-05-26 22:32:36 +02:00
Tim Ruffing
77defd2c3b Add secp256k1_ prefix to default callback functions 2019-05-26 22:32:36 +02:00
Tim Ruffing
908bdce64e Include stdio.h and stdlib.h explicitly in secp256k1.c 2019-05-26 22:32:36 +02:00
Tim Ruffing
5db782e655 Allow usage of external default callbacks 2019-05-26 22:32:36 +02:00