Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add benchmarks for all OPRF suites (including a new Ristretto255 suite) #350

Merged
merged 1 commit into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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