forked from ldsec/CS523-Project1
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mpc_protocol.go
46 lines (37 loc) · 1.23 KB
/
mpc_protocol.go
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
package main
import (
"github.com/ldsec/lattigo/ring"
"math/big"
)
// Computation modulus for the circuits
var q = ring.NewUint(Params.T)
// Structure of network message to carry the output value of a specific wire
type MPCMessage struct {
Out WireID
Value uint64
}
type Protocol struct {
*LocalParty
Input uint64
Output uint64
Circuit Circuit
WireOutput map[WireID]*big.Int // store each the output of each wire
BeaverTriplets map[WireID]BeaverTriplet // store the triplet used for each multiplication gate
}
// Create a new protocol to compute the value produced by 'Circuit' when fed with 'input'. The number of beaver triplets given must be >= to the number of multiplication gate present in the circuit
func (lp *LocalParty) NewProtocol(input uint64, circuit Circuit, beaverTriplets map[WireID]BeaverTriplet) *Protocol {
cep := new(Protocol)
cep.LocalParty = lp
cep.WireOutput = make(map[WireID]*big.Int)
cep.BeaverTriplets = beaverTriplets
cep.Circuit = circuit
cep.Input = input
return cep
}
// Start the circuit computation
func (cep *Protocol) Run() {
for _, op := range cep.Circuit {
op.Eval(cep)
}
cep.Output = cep.WireOutput[cep.Circuit[len(cep.Circuit)-1].Output()].Uint64()
}