Fix LLVM compilation issues
[novacoin.git] / src / zerocoin / Commitment.h
1 /**
2  * @file       Commitment.h
3  *
4  * @brief      Commitment and CommitmentProof classes for the Zerocoin library.
5  *
6  * @author     Ian Miers, Christina Garman and Matthew Green
7  * @date       June 2013
8  *
9  * @copyright  Copyright 2013 Ian Miers, Christina Garman and Matthew Green
10  * @license    This project is released under the MIT license.
11  **/
12
13 #ifndef COMMITMENT_H_
14 #define COMMITMENT_H_
15
16 #include "Params.h"
17 #include "../serialize.h"
18
19 // We use a SHA256 hash for our PoK challenges. Update the following
20 // if we ever change hash functions.
21 #define COMMITMENT_EQUALITY_CHALLENGE_SIZE  256
22
23 // A 512-bit security parameter for the statistical ZK PoK.
24 #define COMMITMENT_EQUALITY_SECMARGIN       512
25
26 namespace libzerocoin {
27
28 /**
29  * A commitment, complete with contents and opening randomness.
30  * These should remain secret. Publish only the commitment value.
31  */
32 class Commitment {
33 public:
34         /**Generates a Pedersen commitment to the given value.
35          *
36          * @param p the group parameters for the coin
37          * @param value the value to commit to
38          */
39         Commitment(const IntegerGroupParams* p, const Bignum& value);
40         const Bignum& getCommitmentValue() const;
41         const Bignum& getRandomness() const;
42         const Bignum& getContents() const;
43 private:
44         const IntegerGroupParams *params;
45         Bignum commitmentValue;
46         Bignum randomness;
47         const Bignum contents;
48         IMPLEMENT_SERIALIZE
49         (
50             READWRITE(commitmentValue);
51             READWRITE(randomness);
52             READWRITE(contents);
53         )
54 };
55
56 /**Proof that two commitments open to the same value.
57  *
58  */
59 class CommitmentProofOfKnowledge {
60 public:
61         CommitmentProofOfKnowledge(const IntegerGroupParams* ap, const IntegerGroupParams* bp);
62         /** Generates a proof that two commitments, a and b, open to the same value.
63          *
64          * @param ap the IntegerGroup for commitment a
65          * @param bp the IntegerGroup for commitment b
66          * @param a the first commitment
67          * @param b the second commitment
68          */
69         CommitmentProofOfKnowledge(const IntegerGroupParams* aParams, const IntegerGroupParams* bParams, const Commitment& a, const Commitment& b);
70         //FIXME: is it best practice that this is here?
71         template<typename Stream>
72         CommitmentProofOfKnowledge(const IntegerGroupParams* aParams,
73                                    const IntegerGroupParams* bParams, Stream& strm): ap(aParams), bp(bParams)
74         {
75                 strm >> *this;
76         }
77
78         const Bignum calculateChallenge(const Bignum& a, const Bignum& b, const Bignum &commitOne, const Bignum &commitTwo) const;
79
80         /**Verifies the proof
81          *
82          * @return true if the proof is valid.
83          */
84         /**Verifies the proof of equality of the two commitments
85          *
86          * @param A value of commitment one
87          * @param B value of commitment two
88          * @return
89          */
90         bool Verify(const Bignum& A, const Bignum& B) const;
91         IMPLEMENT_SERIALIZE
92         (
93             READWRITE(S1);
94             READWRITE(S2);
95             READWRITE(S3);
96             READWRITE(challenge);
97         )
98 private:
99         const IntegerGroupParams *ap, *bp;
100
101         Bignum S1, S2, S3, challenge;
102 };
103
104 } /* namespace libzerocoin */
105 #endif /* COMMITMENT_H_ */