Fix LLVM compilation issues
[novacoin.git] / src / zerocoin / Params.h
1 /**
2 * @file       Params.h
3 *
4 * @brief      Parameter classes for Zerocoin.
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 #ifndef PARAMS_H_
13 #define PARAMS_H_
14
15 namespace libzerocoin {
16
17 class IntegerGroupParams {
18 public:
19         /** @brief Integer group class, default constructor
20         *
21         * Allocates an empty (uninitialized) set of parameters.
22         **/
23         IntegerGroupParams();
24
25         /**
26          * Generates a random group element
27          * @return a random element in the group.
28          */
29         Bignum randomElement() const;
30         bool initialized;
31
32         /**
33          * A generator for the group.
34          */
35         Bignum g;
36
37         /**
38          * A second generator for the group.
39          * Note log_g(h) and log_h(g) must
40          * be unknown.
41          */
42         Bignum h;
43
44         /**
45          * The modulus for the group.
46          */
47         Bignum modulus;
48
49         /**
50          * The order of the group
51          */
52         Bignum groupOrder;
53
54         IMPLEMENT_SERIALIZE
55         (
56             READWRITE(initialized);
57             READWRITE(g);
58             READWRITE(h);
59             READWRITE(modulus);
60             READWRITE(groupOrder);
61         )
62 };
63
64 class AccumulatorAndProofParams {
65 public:
66         /** @brief Construct a set of Zerocoin parameters from a modulus "N".
67         * @param N                A trusted RSA modulus
68         * @param securityLevel    A security level expressed in symmetric bits (default 80)
69         *
70         * Allocates and derives a set of Zerocoin parameters from
71         * a trustworthy RSA modulus "N". This routine calculates all
72         * of the remaining parameters (group descriptions etc.) from N
73         * using a verifiable, deterministic procedure.
74         *
75         * Note: this constructor makes the fundamental assumption that "N"
76         * encodes a valid RSA-style modulus of the form "e1 * e2" where
77         * "e1" and "e2" are safe primes. The factors "e1", "e2" MUST NOT
78         * be known to any party, or the security of Zerocoin is
79         * compromised. The integer "N" must be a MINIMUM of 1024
80         * in length. 3072 bits is strongly recommended.
81         **/
82         AccumulatorAndProofParams();
83
84         //AccumulatorAndProofParams(Bignum accumulatorModulus);
85
86         bool initialized;
87
88         /**
89          * Modulus used for the accumulator.
90          * Product of two safe primes who's factorization is unknown.
91          */
92         Bignum accumulatorModulus;
93
94         /**
95          * The initial value for the accumulator
96          * A random Quadratic residue mod n thats not 1
97          */
98         Bignum accumulatorBase;
99
100         /**
101          * Lower bound on the value for committed coin.
102          * Required by the accumulator proof.
103          */
104         Bignum minCoinValue;
105
106         /**
107          * Upper bound on the value for a comitted coin.
108          * Required by the accumulator proof.
109          */
110         Bignum maxCoinValue;
111
112         /**
113          * The second of two groups used to form a commitment to
114          * a coin (which it self is a commitment to a serial number).
115          * This one differs from serialNumberSokCommitment due to
116          * restrictions from Camenisch and Lysyanskaya's paper.
117          */
118         IntegerGroupParams accumulatorPoKCommitmentGroup;
119
120         /**
121          * Hidden order quadratic residue group mod N.
122          * Used in the accumulator proof.
123          */
124         IntegerGroupParams accumulatorQRNCommitmentGroup;
125
126         /**
127          * Security parameter.
128          * Bit length of the challenges used in the accumulator proof.
129          */
130         uint32_t k_prime;
131
132         /**
133          * Security parameter.
134          * The statistical zero-knowledgeness of the accumulator proof.
135          */
136         uint32_t k_dprime;
137
138         IMPLEMENT_SERIALIZE
139         (
140             READWRITE(initialized);
141             READWRITE(accumulatorModulus);
142             READWRITE(accumulatorBase);
143             READWRITE(accumulatorPoKCommitmentGroup);
144             READWRITE(accumulatorQRNCommitmentGroup);
145             READWRITE(minCoinValue);
146             READWRITE(maxCoinValue);
147             READWRITE(k_prime);
148             READWRITE(k_dprime);
149         )
150 };
151
152 class Params {
153 public:
154         /** @brief Construct a set of Zerocoin parameters from a modulus "N".
155         * @param N                A trusted RSA modulus
156         * @param securityLevel    A security level expressed in symmetric bits (default 80)
157         *
158         * Allocates and derives a set of Zerocoin parameters from
159         * a trustworthy RSA modulus "N". This routine calculates all
160         * of the remaining parameters (group descriptions etc.) from N
161         * using a verifiable, deterministic procedure.
162         *
163         * Note: this constructor makes the fundamental assumption that "N"
164         * encodes a valid RSA-style modulus of the form "e1 * e2" where
165         * "e1" and "e2" are safe primes. The factors "e1", "e2" MUST NOT
166         * be known to any party, or the security of Zerocoin is
167         * compromised. The integer "N" must be a MINIMUM of 1024
168         * in length. 3072 bits is strongly recommended.
169         **/
170         Params(Bignum accumulatorModulus,
171                uint32_t securityLevel = ZEROCOIN_DEFAULT_SECURITYLEVEL);
172
173         bool initialized;
174
175         AccumulatorAndProofParams accumulatorParams;
176
177         /**
178          * The Quadratic Residue group from which we form
179          * a coin as a commitment  to a serial number.
180          */
181         IntegerGroupParams coinCommitmentGroup;
182
183         /**
184          * One of two groups used to form a commitment to
185          * a coin (which it self is a commitment to a serial number).
186          * This is the one used in the serial number poof.
187          * It's order must be equal to the modulus of coinCommitmentGroup.
188          */
189         IntegerGroupParams serialNumberSoKCommitmentGroup;
190
191         /**
192          * The number of iterations to use in the serial
193          * number proof.
194          */
195         uint32_t zkp_iterations;
196
197         /**
198          * The amount of the hash function we use for
199          * proofs.
200          */
201         uint32_t zkp_hash_len;
202
203         IMPLEMENT_SERIALIZE
204         (
205             READWRITE(initialized);
206             READWRITE(accumulatorParams);
207             READWRITE(coinCommitmentGroup);
208             READWRITE(serialNumberSoKCommitmentGroup);
209             READWRITE(zkp_iterations);
210             READWRITE(zkp_hash_len);
211         )
212 };
213
214 } /* namespace libzerocoin */
215
216 #endif /* PARAMS_H_ */