Skip to content
This repository was archived by the owner on Apr 17, 2024. It is now read-only.

Commit 131b96f

Browse files
juergwcopybara-github
authored andcommitted
Add Benchmark tests for Deterministic AEAD in Golang.
It tests encrypting and decrypting 16k data. Output: cpu: AMD EPYC 7B12 BenchmarkAESSIV/AES256_SIV-8 6500 176030 ns/op 54657 B/op 23 allocs/op PiperOrigin-RevId: 625278908
1 parent 36a5643 commit 131b96f

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

go/daead/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ go_test(
3636
name = "daead_test",
3737
srcs = [
3838
"aes_siv_key_manager_test.go",
39+
"daead_benchmark_test.go",
3940
"daead_factory_test.go",
4041
"daead_init_test.go",
4142
"daead_key_templates_test.go",

go/daead/daead_benchmark_test.go

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// //////////////////////////////////////////////////////////////////////////////
16+
17+
package daead_test
18+
19+
import (
20+
"testing"
21+
22+
"github.com/google/tink/go/daead"
23+
"github.com/google/tink/go/keyset"
24+
"github.com/google/tink/go/subtle/random"
25+
tinkpb "github.com/google/tink/go/proto/tink_go_proto"
26+
)
27+
28+
// Benchmarks for Deterministic AEAD algorithms.
29+
30+
func BenchmarkAESSIV(b *testing.B) {
31+
const (
32+
plaintextSize = 16 * 1024
33+
associatedDataSize = 256
34+
)
35+
testCases := []struct {
36+
name string
37+
template *tinkpb.KeyTemplate
38+
}{
39+
{
40+
name: "AES256_SIV",
41+
template: daead.AESSIVKeyTemplate(),
42+
},
43+
}
44+
for _, tc := range testCases {
45+
b.Run(tc.name, func(b *testing.B) {
46+
b.ReportAllocs()
47+
48+
handle, err := keyset.NewHandle(tc.template)
49+
if err != nil {
50+
b.Fatal(err)
51+
}
52+
primitive, err := daead.New(handle)
53+
if err != nil {
54+
b.Fatal(err)
55+
}
56+
plaintext := random.GetRandomBytes(plaintextSize)
57+
associatedData := random.GetRandomBytes(associatedDataSize)
58+
b.ResetTimer()
59+
for i := 0; i < b.N; i++ {
60+
ciphertext, err := primitive.EncryptDeterministically(plaintext, associatedData)
61+
if err != nil {
62+
b.Fatal(err)
63+
}
64+
_, err = primitive.DecryptDeterministically(ciphertext, associatedData)
65+
if err != nil {
66+
b.Error(err)
67+
}
68+
}
69+
})
70+
}
71+
}

0 commit comments

Comments
 (0)