/
FEResponder.h
146 lines (113 loc) · 4.75 KB
/
FEResponder.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
140
141
142
143
144
145
146
#ifndef _FERESPONDER_H_
#define _FERESPONDER_H_
#include "Coin.h"
#include "MerkleProof.h"
#include "MerkleProver.h"
#include "FEResolutionMessage.h"
/*! \brief This class can run the response side of either the buy or barter
* protocols */
class FEResponder {
public:
static const int TYPE_NONE = -1;
static const int TYPE_BUY = 0;
static const int TYPE_BARTER = 1;
/*! constructor takes in various parameters and the public key of
* the arbiter */
FEResponder(const int timeoutLength, const int timeoutTolerance,
const VEPublicKey* pk, const VEPublicKey* repk,
const int stat);
/*! copy constructor */
FEResponder(const FEResponder &o);
/*! destructor */
~FEResponder();
/*! check a setup message received from FEInitiator */
bool setup(const FESetupMessage* setup, const ZZ& R);
/*! encrypt and start the next round (including first round) */
EncBuffer* startRound(const Buffer* ptextR, const cipher_t& encAlgR);
vector<EncBuffer*> startRound(const vector<const Buffer*>& ptextR,
const cipher_t& encAlgR);
/*! set responder files (only for BT client use) */
void setResponderFiles(const Buffer* ptextR, EncBuffer* ctextR);
void setResponderFiles(const vector<const Buffer*>& ptextR,
const vector<EncBuffer*>& ctextR);
// the following should be used for sell only
/*! if the contract is formed correctly and the signature on the
* contract is valid, return the decryption key */
vector<string> sell(const FEMessage& message, const hash_t& ptHashR);
vector<string> sell(const FEMessage& message,
const vector<hash_t>& ptHashR);
/*! endorse the coin from the setup message using the provided
* endorsement. return false if the endorsement is not correct for
* the coin */
bool endorseCoin(const vector<ZZ> &endorsement);
// the following should be used for barter only
/*! if the contract is correctly and the signature on the escrow
* verifies, return the decryption key */
vector<string> giveKeys(const FEMessage& signedEscrow,
EncBuffer* ctextI, const hash_t& ptHashI,
const hash_t& ptHashR);
vector<string> giveKeys(const FEMessage& signedEscrow,
const vector<EncBuffer*>& ctextI,
const vector<hash_t>& ptHashI,
const vector<hash_t>& ptHashR);
/*! check that the key received from the initiator is valid for the
* ciphertext; return false if it is not */
bool checkKey(const string& keyI);
bool checkKey(const vector<string>& keysI);
/*! Send a request to the arbiter to resolve*/
FEResolutionMessage* resolveI();
/*! Send proofs that you know the plaintext of the blocks
* indicated by the challengs to the Arbiter */
MerkleProof* resolveII(vector<unsigned> &challenges);
/*! Check that the keys sent by the Arbiter enable you to decrypt
* the Initiator's ciphertext. If they don't, send a proof of this */
MerkleProof* resolveIII(vector<string> &keys);
/*! If the proof of the initiator's keys not decrypting the
* ciphertext correctly is valid
* the Arbiter sends the endorsement for the coin*/
// XXX: why does this have to be a function?
bool resolveIV(vector<ZZ> &endorsement);
// getters
const vector<Buffer*>& getPtextA() const { return ptextA; }
const Coin& getCoinPrime() const { return coinPrime; }
// these are only needed for testing
FESetupMessage* getSetupMessage() const;
FEMessage* getMessage() const { return message; }
bool canAbortLocally() {return TYPE_NONE == exchangeType;}
// setters
void setTimeout() {timeout = time(NULL) + timeoutLength;}
void setTimeoutTolerance(const int newtimeoutTolerance)
{timeoutTolerance = newtimeoutTolerance;}
void setSecurity(const int newstat) {stat = newstat;}
void setVerifiablePublicKey(const VEPublicKey* newpk)
{verifiablePK = newpk;}
void setRegularPublicKey(const VEPublicKey* newpk) {regularPK = newpk;}
void reset();
protected:
vector<EncBuffer*> encrypt(const vector<const Buffer*>& ptextR,
const cipher_t& encAlgR) const;
bool check(const FEMessage& message, const string& label,
const vector<hash_t>& ptHashR);
vector<string> getKeys() const;
/*! Prove the initiator's keys are not correct for the ciphertext */
MerkleProof* proveIncorrectKeys(const vector<string> &keys);
private:
int timeoutLength;
int timeoutTolerance;
int timeout;
int stat;
const VEPublicKey* verifiablePK;
const VEPublicKey* regularPK;
vector<const Buffer*> ptextB;
vector<EncBuffer*> ctextB;
vector</*const*/EncBuffer*> ctextA;
vector<Buffer*> ptextA;
Coin coinPrime;
FEContract* contract;
VECiphertext* escrow;
Signature::Key* initiatorSignPK;
// 0 is buy, 1 is barter
int exchangeType;
FEMessage* message;
};
#endif /*_FERESPONDER_H_*/