Skip to content

Commit

Permalink
Benchmark for CO OT.
Browse files Browse the repository at this point in the history
  • Loading branch information
markkurossi committed Feb 16, 2023
1 parent 365fa16 commit 3d543f5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 11 deletions.
11 changes: 0 additions & 11 deletions ot/co.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"crypto/sha256"
"encoding/binary"
"errors"
"fmt"
"hash"
"math/big"
)
Expand Down Expand Up @@ -64,7 +63,6 @@ func (s *COSender) NewTransfer(m0, m1 []byte) (*COSenderXfer, error) {
if err != nil {
return nil, err
}
fmt.Printf("a=%v\n", a)

// A = G->mul_gen(a)
//
Expand All @@ -78,20 +76,13 @@ func (s *COSender) NewTransfer(m0, m1 []byte) (*COSenderXfer, error) {
// => gen*n + q*m => r=gen*n

Ax, Ay := curveParams.ScalarBaseMult(a.Bytes())
fmt.Printf("A=%v\n %v\n", Ax, Ay)

Aax, Aay := curveParams.ScalarMult(Ax, Ay, a.Bytes())
fmt.Printf("Aa=%v\n %v\n", Aax, Aay)

// BN_usub(point->y, group->field, point->y)
// => result = group->field - point->y

AaInvx := big.NewInt(0).Set(Aax)
AaInvy := big.NewInt(0).Sub(curveParams.P, Aay)
fmt.Printf("Aa'=%v\n %v\n", AaInvx, AaInvy)

x, y := curveParams.Add(Aax, Aay, AaInvx, AaInvy)
fmt.Printf("Aa+AaInv=%v\n %v\n", x, y)

return &COSenderXfer{
sender: s,
Expand Down Expand Up @@ -136,8 +127,6 @@ func (s *COSenderXfer) ReceiveB(x, y []byte) error {
s.e0 = xor(s.kdf(bx, by, 0), s.m0)
s.e1 = xor(s.kdf(bax, bay, 0), s.m1)

fmt.Printf("e0=%x, e1=%x\n", s.e0, s.e1)

return nil
}

Expand Down
55 changes: 55 additions & 0 deletions ot/co_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package ot

import (
"bytes"
"crypto/rand"
"fmt"
"testing"
Expand Down Expand Up @@ -56,3 +57,57 @@ func TestCO(t *testing.T) {
fmt.Printf("data1: %x\n", l1Data)
fmt.Printf("result: %x\n", result)
}

func BenchmarkCO(b *testing.B) {
l0, _ := NewLabel(rand.Reader)
l1, _ := NewLabel(rand.Reader)

sender, err := NewCOSender()
if err != nil {
b.Fatalf("NewCOSender: %v", err)
}

receiver, err := NewCOReceiver(sender.CurveParams())
if err != nil {
b.Fatalf("NewCOReceiver: %v", err)
}

b.ResetTimer()

var l0Buf, l1Buf LabelData
for i := 0; i < b.N; i++ {
l0Data := l0.Bytes(&l0Buf)
l1Data := l1.Bytes(&l1Buf)
sXfer, err := sender.NewTransfer(l0Data, l1Data)
if err != nil {
b.Fatalf("COSender.NewTransfer: %v", err)
}
var bit uint = 1

rXfer, err := receiver.NewTransfer(bit)
if err != nil {
b.Fatalf("COReceiver.NewTransfer: %v", err)
}
err = rXfer.ReceiveA(sXfer.A())
if err != nil {
b.Fatalf("rXfer.ReceiveA: %v", err)
}
err = sXfer.ReceiveB(rXfer.B())
if err != nil {
b.Fatalf("sXfer.ReceiveB: %v", err)
}
result, err := rXfer.ReceiveE(sXfer.E())
if err != nil {
b.Fatalf("rXfer.ReceiveE: %v", err)
}
var ret int
if bit == 0 {
ret = bytes.Compare(l0Data[:], result)
} else {
ret = bytes.Compare(l1Data[:], result)
}
if ret != 0 {
b.Fatal("Verify failed")
}
}
}

0 comments on commit 3d543f5

Please sign in to comment.