Skip to content

Commit d585fd2

Browse files
magicalFiloSottile
authored andcommitted
pbkdf2: add benchmarks
Add benchmarks for PBKDF2-HMAC-SHA1 and PBKDF2-HMAC-SHA256. This is to help measure the crypto/hmac changes in CL 27458. Change-Id: I17ef12f3a4641ba44f7bb917a9d87a3ed7c97c67 Reviewed-on: https://go-review.googlesource.com/84380 Reviewed-by: Filippo Valsorda <hi@filippo.io>
1 parent 244f6ce commit d585fd2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Diff for: pbkdf2/pbkdf2_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,22 @@ func TestWithHMACSHA1(t *testing.T) {
155155
func TestWithHMACSHA256(t *testing.T) {
156156
testHash(t, sha256.New, "SHA256", sha256TestVectors)
157157
}
158+
159+
var sink uint8
160+
161+
func benchmark(b *testing.B, h func() hash.Hash) {
162+
password := make([]byte, h().Size())
163+
salt := make([]byte, 8)
164+
for i := 0; i < b.N; i++ {
165+
password = Key(password, salt, 4096, len(password), h)
166+
}
167+
sink += password[0]
168+
}
169+
170+
func BenchmarkHMACSHA1(b *testing.B) {
171+
benchmark(b, sha1.New)
172+
}
173+
174+
func BenchmarkHMACSHA256(b *testing.B) {
175+
benchmark(b, sha256.New)
176+
}

0 commit comments

Comments
 (0)