Skip to content

Commit

Permalink
Optimizing garbling.
Browse files Browse the repository at this point in the history
  • Loading branch information
markkurossi committed Apr 7, 2020
1 parent 8e1925c commit 7850154
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion apps/garbled/examples/rsasign.mpcl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
// msg: 0x6d7472
// cipher: 0x61f9ef88

type Size = uint1024
type Size = uint256

type Garbler struct {
msg Size
Expand Down
5 changes: 2 additions & 3 deletions circuit/garble.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@ func encrypt(alg cipher.Block, a, b, c ot.Label, t uint32) ot.Label {
k := makeK(a, b, t)
kData := k.Data()

var crypted ot.LabelData
alg.Encrypt(crypted[:], kData[:])
alg.Encrypt(kData[:], kData[:])

pi := ot.LabelFromData(crypted)
pi := ot.LabelFromData(kData)
pi.Xor(k)
pi.Xor(c)

Expand Down
11 changes: 6 additions & 5 deletions circuit/garble_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ func (c *Circuit) GarbleStream(key []byte, r ot.Label) error {
}

// Garble gates.
buf := make([]ot.Label, 4)
for i := 0; i < len(c.Gates); i++ {
gate := &c.Gates[i]
data, err := gate.GarbleStream(wires, alg, r, uint32(i))
data, err := gate.GarbleStream(wires, alg, r, uint32(i), buf)
if err != nil {
return err
}
Expand All @@ -100,7 +101,7 @@ func (c *Circuit) GarbleStream(key []byte, r ot.Label) error {
}

func (g *Gate) GarbleStream(wires *StreamWires, enc cipher.Block,
r ot.Label, id uint32) ([]ot.Label, error) {
r ot.Label, id uint32, buf []ot.Label) ([]ot.Label, error) {

var a, b, c ot.Wire
var err error
Expand Down Expand Up @@ -198,10 +199,10 @@ func (g *Gate) GarbleStream(wires *StreamWires, enc cipher.Block,

sort.Sort(ByIndex(table[:count]))

result := make([]ot.Label, count)
buf = buf[:count]
for idx, entry := range table[:count] {
result[idx] = entry.Data
buf[idx] = entry.Data
}

return result, nil
return buf, nil
}
4 changes: 0 additions & 4 deletions compiler/ssa/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ func (prog *Program) allocWires(bits int) (result []*circuits.Wire) {
// Assign wire IDs.
for i := 0; i < bits; i++ {
result[i].ID = prog.nextWireID + uint32(i)
fmt.Printf("Program: assigned wire %d\n", result[i].ID)
if result[i].ID == 2 {
panic(42)
}
}
prog.nextWireID += uint32(bits)
}
Expand Down
8 changes: 5 additions & 3 deletions compiler/ssa/streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (prog *Program) StreamCircuit(params *utils.Params) error {
if err != nil {
return err
}
prog.assignWires = false
prog.assignWires = true

var numGates uint64
var numNonXOR uint64
Expand All @@ -130,7 +130,7 @@ func (prog *Program) StreamCircuit(params *utils.Params) error {
r.SetS(true)

for idx, step := range prog.Steps {
if idx%100 == 0 {
if idx%1000 == 0 {
fmt.Printf("%d/%d\n", idx, len(prog.Steps))
}
instr := step.Instr
Expand Down Expand Up @@ -216,7 +216,9 @@ func (prog *Program) StreamCircuit(params *utils.Params) error {
if false {
circ.Dump()
}
fmt.Printf("%05d: - garble %d gates\n", idx, circ.NumGates)
if false {
fmt.Printf("%05d: - garble %d gates\n", idx, circ.NumGates)
}
err := circ.GarbleStream(key[:], r)
if err != nil {
return err
Expand Down

0 comments on commit 7850154

Please sign in to comment.