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)
2015-08-05 19:04:14 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* Copyright (c) 2015 Gregory Maxwell *
|
|
|
|
* Distributed under the MIT software license, see the accompanying *
|
|
|
|
* file COPYING or http://www.opensource.org/licenses/mit-license.php. *
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
#ifndef _SECP256K1_PEDERSEN_IMPL_H_
|
|
|
|
#define _SECP256K1_PEDERSEN_IMPL_H_
|
|
|
|
|
2016-07-04 13:04:57 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "eckey.h"
|
|
|
|
#include "ecmult_const.h"
|
|
|
|
#include "ecmult_gen.h"
|
|
|
|
#include "group.h"
|
|
|
|
#include "field.h"
|
|
|
|
#include "scalar.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
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)
2015-08-05 19:04:14 +02:00
|
|
|
/** Alternative generator for secp256k1.
|
|
|
|
* This is the sha256 of 'g' after DER encoding (without compression),
|
|
|
|
* which happens to be a point on the curve.
|
|
|
|
* sage: G2 = EllipticCurve ([F (0), F (7)]).lift_x(int(hashlib.sha256('0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8'.decode('hex')).hexdigest(),16))
|
|
|
|
* sage: '%x %x'%G2.xy()
|
|
|
|
*/
|
|
|
|
static const secp256k1_ge secp256k1_ge_const_g2 = SECP256K1_GE_CONST(
|
|
|
|
0x50929b74UL, 0xc1a04954UL, 0xb78b4b60UL, 0x35e97a5eUL,
|
|
|
|
0x078a5a0fUL, 0x28ec96d5UL, 0x47bfee9aUL, 0xce803ac0UL,
|
|
|
|
0x31d3c686UL, 0x3973926eUL, 0x049e637cUL, 0xb1b5f40aUL,
|
|
|
|
0x36dac28aUL, 0xf1766968UL, 0xc30c2313UL, 0xf3a38904UL
|
|
|
|
);
|
|
|
|
|
|
|
|
static void secp256k1_pedersen_scalar_set_u64(secp256k1_scalar *sec, uint64_t value) {
|
|
|
|
unsigned char data[32];
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < 24; i++) {
|
|
|
|
data[i] = 0;
|
|
|
|
}
|
|
|
|
for (; i < 32; i++) {
|
|
|
|
data[i] = value >> 56;
|
|
|
|
value <<= 8;
|
|
|
|
}
|
|
|
|
secp256k1_scalar_set_b32(sec, data, NULL);
|
|
|
|
memset(data, 0, 32);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void secp256k1_pedersen_ecmult_small(secp256k1_gej *r, uint64_t gn) {
|
|
|
|
secp256k1_scalar s;
|
|
|
|
secp256k1_pedersen_scalar_set_u64(&s, gn);
|
|
|
|
secp256k1_ecmult_const(r, &secp256k1_ge_const_g2, &s, 64);
|
|
|
|
secp256k1_scalar_clear(&s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sec * G + value * G2. */
|
|
|
|
SECP256K1_INLINE static void secp256k1_pedersen_ecmult(const secp256k1_ecmult_gen_context *ecmult_gen_ctx, secp256k1_gej *rj, const secp256k1_scalar *sec, uint64_t value) {
|
|
|
|
secp256k1_gej vj;
|
|
|
|
secp256k1_ecmult_gen(ecmult_gen_ctx, rj, sec);
|
|
|
|
secp256k1_pedersen_ecmult_small(&vj, value);
|
|
|
|
/* FIXME: constant time. */
|
|
|
|
secp256k1_gej_add_var(rj, rj, &vj, NULL);
|
|
|
|
secp256k1_gej_clear(&vj);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|