PRCYCoin  2.0.0.7rc1
P2P Digital Currency
bench_rangeproof.c
Go to the documentation of this file.
1 /**********************************************************************
2  * Copyright (c) 2014, 2015 Pieter Wuille, Gregory Maxwell *
3  * Distributed under the MIT software license, see the accompanying *
4  * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
5  **********************************************************************/
6 
7 #include <stdint.h>
8 
11 #include "util.h"
12 #include "bench.h"
13 
14 typedef struct {
15  secp256k1_context2* ctx;
17  unsigned char proof[5134];
18  unsigned char blind[32];
19  size_t len;
20  int min_bits;
21  uint64_t v;
23 
24 static void bench_rangeproof_setup(void* arg) {
25  int i;
26  uint64_t minv;
27  uint64_t maxv;
29 
30  data->v = 0;
31  for (i = 0; i < 32; i++) data->blind[i] = i + 1;
33  data->len = 5134;
34  CHECK(secp256k1_rangeproof_sign(data->ctx, data->proof, &data->len, 0, &data->commit, data->blind, (const unsigned char*)&data->commit, 0, data->min_bits, data->v, NULL, 0, NULL, 0, &secp256k1_generator_const_h));
35  CHECK(secp256k1_rangeproof_verify(data->ctx, &minv, &maxv, &data->commit, data->proof, data->len, NULL, 0, &secp256k1_generator_const_h));
36 }
37 
38 static void bench_rangeproof(void* arg) {
39  int i;
41 
42  for (i = 0; i < 1000; i++) {
43  int j;
44  uint64_t minv;
45  uint64_t maxv;
46  j = secp256k1_rangeproof_verify(data->ctx, &minv, &maxv, &data->commit, data->proof, data->len, NULL, 0, &secp256k1_generator_const_h);
47  for (j = 0; j < 4; j++) {
48  data->proof[j + 2 + 32 *((data->min_bits + 1) >> 1) - 4] = (i >> 8)&255;
49  }
50  }
51 }
52 
53 int main(void) {
54  bench_rangeproof_t data;
55 
57 
58  data.min_bits = 32;
59 
60  run_benchmark("rangeproof_verify_bit", bench_rangeproof, bench_rangeproof_setup, NULL, &data, 10, 1000 * data.min_bits);
61 
63  return 0;
64 }
secp256k1_pedersen_commit
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_pedersen_commit(const secp256k1_context2 *ctx, secp256k1_pedersen_commitment *commit, const unsigned char *blind, uint64_t value, const secp256k1_generator *value_gen, const secp256k1_generator *blind_gen) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(6)
Generate a Pedersen commitment.
Definition: main_impl.h:93
bench.h
util.h
bench_rangeproof_t::ctx
secp256k1_context2 * ctx
Definition: bench_rangeproof.c:19
bench_rangeproof_t::v
uint64_t v
Definition: bench_rangeproof.c:25
secp256k1_context_destroy
SECP256K1_API void secp256k1_context_destroy(secp256k1_context2 *ctx)
Destroy a secp256k1 context object.
Definition: secp256k1_2.c:110
secp256k1_rangeproof_verify
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_rangeproof_verify(const secp256k1_context2 *ctx, uint64_t *min_value, uint64_t *max_value, const secp256k1_pedersen_commitment *commit, const unsigned char *proof, size_t plen, const unsigned char *extra_commit, size_t extra_commit_len, const secp256k1_generator *gen) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(9)
Verify a proof that a committed value is within a range.
Definition: main_impl.h:55
run_benchmark
void run_benchmark(char *name, void(*benchmark)(void *), void(*setup)(void *), void(*teardown)(void *), void *data, int count, int iter)
Definition: bench.h:34
bench_rangeproof_t::commit
secp256k1_pedersen_commitment commit
Definition: bench_rangeproof.c:20
bench_rangeproof_t::proof
unsigned char proof[5134]
Definition: bench_rangeproof.c:21
secp256k1_rangeproof_sign
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_rangeproof_sign(const secp256k1_context2 *ctx, unsigned char *proof, size_t *plen, uint64_t min_value, const secp256k1_pedersen_commitment *commit, const unsigned char *blind, const unsigned char *nonce, int exp, int min_bits, uint64_t value, const unsigned char *message, size_t msg_len, const unsigned char *extra_commit, size_t extra_commit_len, const secp256k1_generator *gen) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(6) SECP256K1_ARG_NONNULL(7) SECP256K1_ARG_NONNULL(15)
Author a proof that a committed value is within a range.
Definition: main_impl.h:73
secp256k1_rangeproof.h
bench_rangeproof_t::blind
unsigned char blind[32]
Definition: bench_rangeproof.c:22
secp256k1_context_struct2
Definition: secp256k1_types.h:15
bench_rangeproof_t::len
size_t len
Definition: bench_rangeproof.c:23
secp256k1_pedersen_commitment
Opaque data structure that stores a Pedersen commitment.
Definition: secp256k1_commitment.h:22
secp256k1_generator_const_g
const SECP256K1_API secp256k1_generator secp256k1_generator_const_g
Standard secp256k1 generator G.
Definition: main_impl.h:18
secp256k1_generator_const_h
const SECP256K1_API secp256k1_generator secp256k1_generator_const_h
Alternate secp256k1 generator from Elements Alpha.
Definition: main_impl.h:32
bench_rangeproof_t::min_bits
int min_bits
Definition: bench_rangeproof.c:24
secp256k1_context_create2
SECP256K1_API secp256k1_context2 * secp256k1_context_create2(unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
Create a secp256k1 context object.
Definition: secp256k1_2.c:75
bench_rangeproof_t
Definition: bench_rangeproof.c:14
SECP256K1_CONTEXT_VERIFY
#define SECP256K1_CONTEXT_VERIFY
Flags to pass to secp256k1_context_create2.
Definition: secp256k1_2.h:167
main
int main(void)
Definition: bench_rangeproof.c:53
CHECK
#define CHECK(cond)
Definition: util.h:43
secp256k1_commitment.h
SECP256K1_CONTEXT_SIGN
#define SECP256K1_CONTEXT_SIGN
Definition: secp256k1_2.h:168