Commit 62fbeb29 authored by Anders Jensen Løvig's avatar Anders Jensen Løvig
Browse files

Dealer

parent 17b17e91
......@@ -113,9 +113,32 @@ func (p *Party) XOR2W(xwire, ywire int) int {
return p.Push(p.wires[xwire] != p.wires[ywire])
}
type Dealer struct {
}
func NewDealer() *Dealer {
return &Dealer{}
}
func (d *Dealer) Deal() (bool, bool, bool, bool, bool, bool) {
u := rand.Intn(2) == 1
ua := rand.Intn(2) == 1
ub := u != ua // x XOR xb
v := rand.Intn(2) == 1
va := rand.Intn(2) == 1
vb := v != va // x XOR xb
w := u && v
wa := rand.Intn(2) == 1
wb := w != wa
return ua, ub, va, vb, wa, wb
}
type Protocol struct {
A *Party
B *Party
Dealer *Dealer
}
func NewProtocol() *Protocol {
......@@ -124,21 +147,14 @@ func NewProtocol() *Protocol {
return &Protocol{
A: NewParty(b2a, a2b),
B: NewParty(a2b, b2a),
Dealer: NewDealer(),
}
}
func (P *Protocol) AND(xwire, ywire int) int {
A, B := P.A, P.B
func (p *Protocol) AND(xwire, ywire int) int {
A, B := p.A, p.B
//1a. Generate [u], [v] and [w]
u := rand.Intn(2) == 1
ua := rand.Intn(2) == 1
ub := u != ua // x XOR xb
v := rand.Intn(2) == 1
va := rand.Intn(2) == 1
vb := v != va // x XOR xb
w := u && v
wa := rand.Intn(2) == 1
wb := w != wa
ua, ub, va, vb, wa, wb := p.Dealer.Deal()
//1b. send shares to parties
A.in <- ua
......@@ -152,10 +168,10 @@ func (P *Protocol) AND(xwire, ywire int) int {
idx_w, _ := A.Receive(), B.Receive()
//2 compute [d] = [x] XOR [u]
idx_d1 := P.XOR2W(xwire, idx_u) //A.XOR2W(xwire, idx_u), B.XOR2W(xwire, idx_u)
idx_d1 := p.XOR2W(xwire, idx_u) //A.XOR2W(xwire, idx_u), B.XOR2W(xwire, idx_u)
//3. compute [e] = [y] XOR [v]
idx_e1 := P.XOR2W(ywire, idx_v) //A.XOR2W(ywire, idx_v), B.XOR2W(ywire, idx_v)
idx_e1 := p.XOR2W(ywire, idx_v) //A.XOR2W(ywire, idx_v), B.XOR2W(ywire, idx_v)
//4. Open d
A.Send(idx_d1)
......@@ -168,8 +184,8 @@ func (P *Protocol) AND(xwire, ywire int) int {
idx_e2, _ := A.Receive(), B.Receive()
//6a. Compute d and e
idx_d := P.XOR2W(idx_d1, idx_d2) //A.XOR2W(idx_d1, idx_d2), B.XOR2W(idx_d1, idx_d2)
idx_e := P.XOR2W(idx_e1, idx_e2) //A.XOR2W(idx_e1, idx_e2), B.XOR2W(idx_e1, idx_e2)
idx_d := p.XOR2W(idx_d1, idx_d2) //A.XOR2W(idx_d1, idx_d2), B.XOR2W(idx_d1, idx_d2)
idx_e := p.XOR2W(idx_e1, idx_e2) //A.XOR2W(idx_e1, idx_e2), B.XOR2W(idx_e1, idx_e2)
//6b. Compute [z]-parts
idx_z1, _ := A.ANDC(xwire, A.wires[idx_e]), B.ANDC(xwire, B.wires[idx_e])
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment