forked from Zerocoin/libzerocoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoin.h
139 lines (128 loc) · 4.01 KB
/
Coin.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* @file Coin.h
*
* @brief PublicCoin and PrivateCoin classes for the Zerocoin library.
*
* @author Ian Miers, Christina Garman and Matthew Green
* @date June 2013
*
* @copyright Copyright 2013 Ian Miers, Christina Garman and Matthew Green
* @license This project is released under the MIT license.
**/
#ifndef COIN_H_
#define COIN_H_
#include "bitcoin_bignum/bignum.h"
#include "Params.h"
namespace libzerocoin {
enum CoinDenomination {
ZQ_LOVELACE = 1,
ZQ_GOLDWASSER = 10,
ZQ_RACKOFF = 25,
ZQ_PEDERSEN = 50,
ZQ_WILLIAMSON = 100 // Malcolm J. Williamson,
// the scientist who actually invented
// Public key cryptography
};
/** A Public coin is the part of a coin that
* is published to the network and what is handled
* by other clients. It contains only the value
* of commitment to a serial number and the
* denomination of the coin.
*/
class PublicCoin {
public:
template<typename Stream>
PublicCoin(const Params* p, Stream& strm): params(p) {
strm >> *this;
}
PublicCoin( const Params* p);
/**Generates a public coin
*
* @param p cryptographic paramters
* @param coin the value of the commitment.
* @param denomination The denomination of the coin. Defaults to ZQ_LOVELACE
*/
PublicCoin( const Params* p, const Bignum& coin, const CoinDenomination d = ZQ_LOVELACE);
const Bignum& getValue() const;
const CoinDenomination getDenomination() const;
bool operator==(const PublicCoin& rhs) const;
bool operator!=(const PublicCoin& rhs) const;
/** Checks that a coin prime
* and in the appropriate range
* given the parameters
* @return true if valid
*/
bool validate() const;
IMPLEMENT_SERIALIZE
(
READWRITE(value);
READWRITE(denomination);
)
private:
const Params* params;
Bignum value;
// Denomination is stored as an INT because storing
// and enum raises amigiuities in the serialize code //FIXME if possible
int denomination;
};
/**
* A private coin. As the name implies, the content
* of this should stay private except PublicCoin.
*
* Contains a coin's serial number, a commitment to it,
* and opening randomness for the commitment.
*
* @warning Failure to keep this secret(or safe),
* @warning will result in the theft of your coins
* @warning and a TOTAL loss of anonymity.
*/
class PrivateCoin {
public:
template<typename Stream>
PrivateCoin(const Params* p, Stream& strm): params(p) {
strm >> *this;
}
PrivateCoin(const Params* p,const CoinDenomination denomination = ZQ_LOVELACE);
const PublicCoin& getPublicCoin() const;
const Bignum& getSerialNumber() const;
const Bignum& getRandomness() const;
IMPLEMENT_SERIALIZE
(
READWRITE(publicCoin);
READWRITE(randomness);
READWRITE(serialNumber);
)
private:
const Params* params;
PublicCoin publicCoin;
Bignum randomness;
Bignum serialNumber;
/**
* @brief Mint a new coin.
* @param denomination the denomination of the coin to mint
* @throws ZerocoinException if the process takes too long
*
* Generates a new Zerocoin by (a) selecting a random serial
* number, (b) committing to this serial number and repeating until
* the resulting commitment is prime. Stores the
* resulting commitment (coin) and randomness (trapdoor).
**/
void mintCoin(const CoinDenomination denomination);
/**
* @brief Mint a new coin using a faster process.
* @param denomination the denomination of the coin to mint
* @throws ZerocoinException if the process takes too long
*
* Generates a new Zerocoin by (a) selecting a random serial
* number, (b) committing to this serial number and repeating until
* the resulting commitment is prime. Stores the
* resulting commitment (coin) and randomness (trapdoor).
* This routine is substantially faster than the
* mintCoin() routine, but could be more vulnerable
* to timing attacks. Don't use it if you think someone
* could be timing your coin minting.
**/
void mintCoinFast(const CoinDenomination denomination);
};
} /* namespace libzerocoin */
#endif /* COIN_H_ */