Skip to content

Commit

Permalink
Optimized memory allocations in OT.Receive().
Browse files Browse the repository at this point in the history
  • Loading branch information
markkurossi committed Feb 18, 2023
1 parent 8d860ec commit b437cc8
Showing 1 changed file with 33 additions and 20 deletions.
53 changes: 33 additions & 20 deletions ot/rsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,19 +353,25 @@ func (r *RSA) Receive(flags []bool, result []Label) error {
return err
}
// Receive random messages.
x0, err := ReceiveBigInt(r.io)
if err != nil {
return err
}
x1, err := ReceiveBigInt(r.io)
if err != nil {
return err
}
var xb *big.Int
if flags[i] {
xb = x1
_, err = r.io.ReceiveData()
if err != nil {
return err
}
xb, err = ReceiveBigInt(r.io)
if err != nil {
return err
}
} else {
xb = x0
xb, err = ReceiveBigInt(r.io)
if err != nil {
return err
}
_, err = r.io.ReceiveData()
if err != nil {
return err
}
}

// Create and send V.
Expand All @@ -379,20 +385,27 @@ func (r *RSA) Receive(flags []bool, result []Label) error {
}

// Receive transfer messages.
m0p, err := ReceiveBigInt(r.io)
if err != nil {
return err
}
m1p, err := ReceiveBigInt(r.io)
if err != nil {
return err
}
var mbp *big.Int
if flags[i] {
mbp = m1p
_, err = ReceiveBigInt(r.io)
if err != nil {
return err
}
mbp, err = ReceiveBigInt(r.io)
if err != nil {
return err
}
} else {
mbp = m0p
mbp, err = ReceiveBigInt(r.io)
if err != nil {
return err
}
_, err = ReceiveBigInt(r.io)
if err != nil {
return err
}
}

mbBytes := make([]byte, r.messageSize())
mbIntBytes := mpint.Sub(mbp, k).Bytes()
ofs := len(mbBytes) - len(mbIntBytes)
Expand Down

0 comments on commit b437cc8

Please sign in to comment.