Skip to content

Commit

Permalink
pbkdf2: add benchmarks
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
magical authored and FiloSottile committed Dec 19, 2017
1 parent 244f6ce commit d585fd2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pbkdf2/pbkdf2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,22 @@ func TestWithHMACSHA1(t *testing.T) {
func TestWithHMACSHA256(t *testing.T) {
testHash(t, sha256.New, "SHA256", sha256TestVectors)
}

var sink uint8

func benchmark(b *testing.B, h func() hash.Hash) {
password := make([]byte, h().Size())
salt := make([]byte, 8)
for i := 0; i < b.N; i++ {
password = Key(password, salt, 4096, len(password), h)
}
sink += password[0]
}

func BenchmarkHMACSHA1(b *testing.B) {
benchmark(b, sha1.New)
}

func BenchmarkHMACSHA256(b *testing.B) {
benchmark(b, sha256.New)
}

0 comments on commit d585fd2

Please sign in to comment.