Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Thomas Hoffmann
CryComp
Commits
62fbeb29
Commit
62fbeb29
authored
Sep 19, 2021
by
Anders Jensen Løvig
Browse files
Dealer
parent
17b17e91
Changes
1
Hide whitespace changes
Inline
Side-by-side
cmd/handin3/main.go
View file @
62fbeb29
...
@@ -113,23 +113,14 @@ func (p *Party) XOR2W(xwire, ywire int) int {
...
@@ -113,23 +113,14 @@ func (p *Party) XOR2W(xwire, ywire int) int {
return
p
.
Push
(
p
.
wires
[
xwire
]
!=
p
.
wires
[
ywire
])
return
p
.
Push
(
p
.
wires
[
xwire
]
!=
p
.
wires
[
ywire
])
}
}
type
Protocol
struct
{
type
Dealer
struct
{
A
*
Party
B
*
Party
}
}
func
NewProtocol
()
*
Protocol
{
func
NewDealer
()
*
Dealer
{
a2b
:=
make
(
chan
bool
,
1
)
//Directional non-blocking channels
return
&
Dealer
{}
b2a
:=
make
(
chan
bool
,
1
)
return
&
Protocol
{
A
:
NewParty
(
b2a
,
a2b
),
B
:
NewParty
(
a2b
,
b2a
),
}
}
}
func
(
P
*
Protocol
)
AND
(
xwire
,
ywire
int
)
int
{
func
(
d
*
Dealer
)
Deal
()
(
bool
,
bool
,
bool
,
bool
,
bool
,
bool
)
{
A
,
B
:=
P
.
A
,
P
.
B
//1a. Generate [u], [v] and [w]
u
:=
rand
.
Intn
(
2
)
==
1
u
:=
rand
.
Intn
(
2
)
==
1
ua
:=
rand
.
Intn
(
2
)
==
1
ua
:=
rand
.
Intn
(
2
)
==
1
ub
:=
u
!=
ua
// x XOR xb
ub
:=
u
!=
ua
// x XOR xb
...
@@ -140,6 +131,31 @@ func (P *Protocol) AND(xwire, ywire int) int {
...
@@ -140,6 +131,31 @@ func (P *Protocol) AND(xwire, ywire int) int {
wa
:=
rand
.
Intn
(
2
)
==
1
wa
:=
rand
.
Intn
(
2
)
==
1
wb
:=
w
!=
wa
wb
:=
w
!=
wa
return
ua
,
ub
,
va
,
vb
,
wa
,
wb
}
type
Protocol
struct
{
A
*
Party
B
*
Party
Dealer
*
Dealer
}
func
NewProtocol
()
*
Protocol
{
a2b
:=
make
(
chan
bool
,
1
)
//Directional non-blocking channels
b2a
:=
make
(
chan
bool
,
1
)
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
//1a. Generate [u], [v] and [w]
ua
,
ub
,
va
,
vb
,
wa
,
wb
:=
p
.
Dealer
.
Deal
()
//1b. send shares to parties
//1b. send shares to parties
A
.
in
<-
ua
A
.
in
<-
ua
B
.
in
<-
ub
B
.
in
<-
ub
...
@@ -152,10 +168,10 @@ func (P *Protocol) AND(xwire, ywire int) int {
...
@@ -152,10 +168,10 @@ func (P *Protocol) AND(xwire, ywire int) int {
idx_w
,
_
:=
A
.
Receive
(),
B
.
Receive
()
idx_w
,
_
:=
A
.
Receive
(),
B
.
Receive
()
//2 compute [d] = [x] XOR [u]
//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]
//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
//4. Open d
A
.
Send
(
idx_d1
)
A
.
Send
(
idx_d1
)
...
@@ -168,8 +184,8 @@ func (P *Protocol) AND(xwire, ywire int) int {
...
@@ -168,8 +184,8 @@ func (P *Protocol) AND(xwire, ywire int) int {
idx_e2
,
_
:=
A
.
Receive
(),
B
.
Receive
()
idx_e2
,
_
:=
A
.
Receive
(),
B
.
Receive
()
//6a. Compute d and e
//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_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_e
:=
p
.
XOR2W
(
idx_e1
,
idx_e2
)
//A.XOR2W(idx_e1, idx_e2), B.XOR2W(idx_e1, idx_e2)
//6b. Compute [z]-parts
//6b. Compute [z]-parts
idx_z1
,
_
:=
A
.
ANDC
(
xwire
,
A
.
wires
[
idx_e
]),
B
.
ANDC
(
xwire
,
B
.
wires
[
idx_e
])
idx_z1
,
_
:=
A
.
ANDC
(
xwire
,
A
.
wires
[
idx_e
]),
B
.
ANDC
(
xwire
,
B
.
wires
[
idx_e
])
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment