From 2eff55068c5414d9c62a592021480456759bdebf Mon Sep 17 00:00:00 2001 From: ChrisBii Date: Fri, 15 Sep 2023 19:19:20 +0000 Subject: [PATCH] small tests from bcrypt_test added --- biicrypt/biicrypt_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/biicrypt/biicrypt_test.go b/biicrypt/biicrypt_test.go index c078472b1e..e72d59e0ad 100644 --- a/biicrypt/biicrypt_test.go +++ b/biicrypt/biicrypt_test.go @@ -55,3 +55,30 @@ func TestBiiCryptReformatSecret(t *testing.T) { t.Fatalf("Expected password and password generated from new secret do not match") } } + +func BenchmarkEqual(b *testing.B) { + b.StopTimer() + passwd := []byte("somepasswordyoulike") + hash, secret, _ := GenerateFromPassword(passwd, DefaultCost) + b.StartTimer() + for i := 0; i < b.N; i++ { + other_hash, _ := GenerateWithSecret(passwd, secret) + subtle.ConstantTimeCompare(hash, other_hash) + } +} + +func BenchmarkDefaultCost(b *testing.B) { + b.StopTimer() + passwd := []byte("mylongpassword1234") + b.StartTimer() + for i := 0; i < b.N; i++ { + GenerateFromPassword(passwd, DefaultCost) + } +} + +func TestPasswordTooLong(t *testing.T) { + _, _, err := GenerateFromPassword(make([]byte, 73), 1) + if err != ErrPasswordTooLong { + t.Errorf("unexpected error: got %q, want %q", err, ErrPasswordTooLong) + } +}