Skip to content

Commit

Permalink
Add benchmarks for all OPRF suites
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-wood authored and armfazh committed Jul 22, 2022
1 parent 9de48e3 commit 750ca5e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
13 changes: 8 additions & 5 deletions oprf/oprf.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,19 @@ type Suite interface {
ID() int
Group() group.Group
Hash() crypto.Hash
Name() string
cannotBeImplementedExternally()
}

var (
// SuiteRistretto255 represents the OPRF with Ristretto255 and SHA-512.
SuiteRistretto255 Suite = params{id: 1, group: group.Ristretto255, hash: crypto.SHA512}
// SuiteRistretto255 represents the OPRF with Ristretto255 and SHA-512
SuiteRistretto255 Suite = params{id: 1, group: group.Ristretto255, hash: crypto.SHA512, name: "OPRF(ristretto255, SHA-512)"}
// SuiteP256 represents the OPRF with P-256 and SHA-256.
SuiteP256 Suite = params{id: 3, group: group.P256, hash: crypto.SHA256}
SuiteP256 Suite = params{id: 3, group: group.P256, hash: crypto.SHA256, name: "OPRF(P-256, SHA-256)"}
// SuiteP384 represents the OPRF with P-384 and SHA-384.
SuiteP384 Suite = params{id: 4, group: group.P384, hash: crypto.SHA384}
SuiteP384 Suite = params{id: 4, group: group.P384, hash: crypto.SHA384, name: "OPRF(P-384, SHA-384)"}
// SuiteP521 represents the OPRF with P-521 and SHA-512.
SuiteP521 Suite = params{id: 5, group: group.P521, hash: crypto.SHA512}
SuiteP521 Suite = params{id: 5, group: group.P521, hash: crypto.SHA512, name: "OPRF(P-521, SHA-512)"}
)

func GetSuite(id int) (Suite, error) {
Expand Down Expand Up @@ -177,6 +178,7 @@ type params struct {
m Mode
group group.Group
hash crypto.Hash
name string
}

func (p params) cannotBeImplementedExternally() {}
Expand All @@ -185,6 +187,7 @@ func (p params) String() string { return fmt.Sprintf("Suite%v", p.group) }
func (p params) ID() int { return int(p.id) }
func (p params) Group() group.Group { return p.group }
func (p params) Hash() crypto.Hash { return p.hash }
func (p params) Name() string { return p.name }

func (p params) getDST(name string) []byte {
return append(append(append([]byte{},
Expand Down
44 changes: 25 additions & 19 deletions oprf/oprf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,28 +276,34 @@ func Example_oprf() {
}

func BenchmarkAPI(b *testing.B) {
suite := SuiteP256
key, err := GenerateKey(suite, rand.Reader)
test.CheckNoErr(b, err, "failed key generation")
for _, suite := range []Suite{
SuiteRistretto255,
SuiteP256,
SuiteP384,
SuiteP521,
} {
key, err := GenerateKey(suite, rand.Reader)
test.CheckNoErr(b, err, "failed key generation")

b.Run("OPRF", func(b *testing.B) {
s := NewServer(suite, key)
c := NewClient(suite)
benchAPI(b, s, c)
})
b.Run("OPRF/"+suite.Name(), func(b *testing.B) {
s := NewServer(suite, key)
c := NewClient(suite)
benchAPI(b, s, c)
})

b.Run("VOPRF", func(b *testing.B) {
s := NewVerifiableServer(suite, key)
c := NewVerifiableClient(suite, s.PublicKey())
benchAPI(b, s, c)
})
b.Run("VOPRF/"+suite.Name(), func(b *testing.B) {
s := NewVerifiableServer(suite, key)
c := NewVerifiableClient(suite, s.PublicKey())
benchAPI(b, s, c)
})

b.Run("POPRF", func(b *testing.B) {
info := []byte("shared info")
s := &s1{NewPartialObliviousServer(suite, key), info}
c := &c1{NewPartialObliviousClient(suite, s.PublicKey()), info}
benchAPI(b, s, c)
})
b.Run("POPRF/"+suite.Name(), func(b *testing.B) {
info := []byte("shared info")
s := &s1{NewPartialObliviousServer(suite, key), info}
c := &c1{NewPartialObliviousClient(suite, s.PublicKey()), info}
benchAPI(b, s, c)
})
}
}

func benchAPI(b *testing.B, server commonServer, client commonClient) {
Expand Down

0 comments on commit 750ca5e

Please sign in to comment.