PRCYCoin  2.0.0.7rc1
P2P Digital Currency
main_impl.h
Go to the documentation of this file.
1 /**********************************************************************
2  * Copyright (c) 2014-2015 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 #ifndef SECP256K1_MODULE_RANGEPROOF_MAIN
8 #define SECP256K1_MODULE_RANGEPROOF_MAIN
9 
10 #include "group.h"
11 
13 
16 
17 int secp256k1_rangeproof_info(const secp256k1_context2* ctx, int *exp, int *mantissa,
18  uint64_t *min_value, uint64_t *max_value, const unsigned char *proof, size_t plen) {
19  size_t offset;
20  uint64_t scale;
21  ARG_CHECK(exp != NULL);
22  ARG_CHECK(mantissa != NULL);
23  ARG_CHECK(min_value != NULL);
24  ARG_CHECK(max_value != NULL);
25  ARG_CHECK(proof != NULL);
26  offset = 0;
27  scale = 1;
28  (void)ctx;
29  return secp256k1_rangeproof_getheader_impl(&offset, exp, mantissa, &scale, min_value, max_value, proof, plen);
30 }
31 
33  unsigned char *blind_out, uint64_t *value_out, unsigned char *message_out, size_t *outlen, const unsigned char *nonce,
34  uint64_t *min_value, uint64_t *max_value,
35  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) {
36  secp256k1_ge commitp;
37  secp256k1_ge genp;
38  VERIFY_CHECK(ctx != NULL);
39  ARG_CHECK(commit != NULL);
40  ARG_CHECK(proof != NULL);
41  ARG_CHECK(min_value != NULL);
42  ARG_CHECK(max_value != NULL);
43  ARG_CHECK(message_out != NULL || outlen == NULL);
44  ARG_CHECK(nonce != NULL);
45  ARG_CHECK(extra_commit != NULL || extra_commit_len == 0);
46  ARG_CHECK(gen != NULL);
47  ARG_CHECK(secp256k1_ecmult_context_is_built(&ctx->ecmult_ctx));
48  ARG_CHECK(secp256k1_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx));
49  secp256k1_pedersen_commitment_load(&commitp, commit);
50  secp256k1_generator_load(&genp, gen);
51  return secp256k1_rangeproof_verify_impl(&ctx->ecmult_ctx, &ctx->ecmult_gen_ctx,
52  blind_out, value_out, message_out, outlen, nonce, min_value, max_value, &commitp, proof, plen, extra_commit, extra_commit_len, &genp);
53 }
54 
55 int secp256k1_rangeproof_verify(const secp256k1_context2* ctx, uint64_t *min_value, uint64_t *max_value,
56  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) {
57  secp256k1_ge commitp;
58  secp256k1_ge genp;
59  VERIFY_CHECK(ctx != NULL);
60  ARG_CHECK(commit != NULL);
61  ARG_CHECK(proof != NULL);
62  ARG_CHECK(min_value != NULL);
63  ARG_CHECK(max_value != NULL);
64  ARG_CHECK(extra_commit != NULL || extra_commit_len == 0);
65  ARG_CHECK(gen != NULL);
66  ARG_CHECK(secp256k1_ecmult_context_is_built(&ctx->ecmult_ctx));
67  secp256k1_pedersen_commitment_load(&commitp, commit);
68  secp256k1_generator_load(&genp, gen);
69  return secp256k1_rangeproof_verify_impl(&ctx->ecmult_ctx, NULL,
70  NULL, NULL, NULL, NULL, NULL, min_value, max_value, &commitp, proof, plen, extra_commit, extra_commit_len, &genp);
71 }
72 
73 int secp256k1_rangeproof_sign(const secp256k1_context2* ctx, unsigned char *proof, size_t *plen, uint64_t min_value,
74  const secp256k1_pedersen_commitment *commit, const unsigned char *blind, const unsigned char *nonce, int exp, int min_bits, uint64_t value,
75  const unsigned char *message, size_t msg_len, const unsigned char *extra_commit, size_t extra_commit_len, const secp256k1_generator* gen){
76  secp256k1_ge commitp;
77  secp256k1_ge genp;
78  VERIFY_CHECK(ctx != NULL);
79  ARG_CHECK(proof != NULL);
80  ARG_CHECK(plen != NULL);
81  ARG_CHECK(commit != NULL);
82  ARG_CHECK(blind != NULL);
83  ARG_CHECK(nonce != NULL);
84  ARG_CHECK(message != NULL || msg_len == 0);
85  ARG_CHECK(extra_commit != NULL || extra_commit_len == 0);
86  ARG_CHECK(gen != NULL);
87  ARG_CHECK(secp256k1_ecmult_context_is_built(&ctx->ecmult_ctx));
88  ARG_CHECK(secp256k1_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx));
89  secp256k1_pedersen_commitment_load(&commitp, commit);
90  secp256k1_generator_load(&genp, gen);
91  return secp256k1_rangeproof_sign_impl(&ctx->ecmult_ctx, &ctx->ecmult_gen_ctx,
92  proof, plen, min_value, &commitp, blind, nonce, exp, min_bits, value, message, msg_len, extra_commit, extra_commit_len, &genp);
93 }
94 
95 #endif
VERIFY_CHECK
#define VERIFY_CHECK(cond)
Definition: util.h:61
main_impl.h
secp256k1_context_struct2::ecmult_ctx
secp256k1_ecmult_context ecmult_ctx
Definition: secp256k1_types.h:16
secp256k1_rangeproof_sign
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)
Author a proof that a committed value is within a range.
Definition: main_impl.h:73
secp256k1_generator
Opaque data structure that stores a base point.
Definition: secp256k1_generator.h:20
secp256k1_rangeproof_verify
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)
Verify a proof that a committed value is within a range.
Definition: main_impl.h:55
secp256k1_rangeproof_info
int secp256k1_rangeproof_info(const secp256k1_context2 *ctx, int *exp, int *mantissa, uint64_t *min_value, uint64_t *max_value, const unsigned char *proof, size_t plen)
Extract some basic information from a range-proof.
Definition: main_impl.h:17
rangeproof_impl.h
borromean_impl.h
secp256k1_context_struct2
Definition: secp256k1_types.h:15
secp256k1_pedersen_commitment
Opaque data structure that stores a Pedersen commitment.
Definition: secp256k1_commitment.h:22
secp256k1_rangeproof_rewind
int secp256k1_rangeproof_rewind(const secp256k1_context2 *ctx, unsigned char *blind_out, uint64_t *value_out, unsigned char *message_out, size_t *outlen, const unsigned char *nonce, 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)
Verify a range proof proof and rewind the proof to recover information sent by its author.
Definition: main_impl.h:32
secp256k1_ge
A group element of the secp256k1 curve, in affine coordinates.
Definition: group.h:14
secp256k1_context_struct2::ecmult_gen_ctx
secp256k1_ecmult_gen_context ecmult_gen_ctx
Definition: secp256k1_types.h:17
ARG_CHECK
#define ARG_CHECK(cond)
Definition: secp256k1_2.c:38