1
0
Fork 0
mirror of https://github.com/Luzifer/go-openssl.git synced 2024-10-18 06:14:21 +00:00

Add benchmarks

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-09-11 12:11:16 +02:00
parent b3de9a97f1
commit eb0c38a83d
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
2 changed files with 51 additions and 1 deletions

View file

@ -10,4 +10,4 @@ go:
script:
- go vet
- go test
- go test -v -bench . -cover

View file

@ -211,3 +211,53 @@ func TestSaltValidation(t *testing.T) {
t.Errorf("Salt with 8 byte unprintable characters was not accepted")
}
}
func benchmarkDecrypt(ciphertext string, b *testing.B) {
passphrase := "z4yH36a6zerhfE5427ZV"
o := New()
for n := 0; n < b.N; n++ {
o.DecryptString(passphrase, ciphertext)
}
}
func BenchmarkDecryptMD5(b *testing.B) {
benchmarkDecrypt("U2FsdGVkX19ZM5qQJGe/d5A/4pccgH+arBGTp+QnWPU=", b)
}
func BenchmarkDecryptSHA1(b *testing.B) {
benchmarkDecrypt("U2FsdGVkX1/Yy9kegseq2Ewd4UvjFYCpIEA1cltTA1Q=", b)
}
func BenchmarkDecryptSHA256(b *testing.B) {
benchmarkDecrypt("U2FsdGVkX1+O68d7BO9ibP8nB5+xtb/27IHlyjJWpl8=", b)
}
func benchmarkEncrypt(plaintext string, hashFunc DigestFunc, b *testing.B) {
passphrase := "z4yH36a6zerhfE5427ZV"
o := New()
salt, _ := o.GenerateSalt()
for n := 0; n < b.N; n++ {
o.EncryptBytesWithSaltAndDigestFunc(passphrase, salt, []byte(plaintext), hashFunc)
}
}
func BenchmarkEncryptMD5(b *testing.B) {
benchmarkEncrypt("hallowelt", DigestMD5Sum, b)
}
func BenchmarkEncryptSHA1(b *testing.B) {
benchmarkEncrypt("hallowelt", DigestSHA1Sum, b)
}
func BenchmarkEncryptSHA256(b *testing.B) {
benchmarkEncrypt("hallowelt", DigestSHA256Sum, b)
}
func BenchmarkGenerateSalt(b *testing.B) {
o := New()
for n := 0; n < b.N; n++ {
o.GenerateSalt()
}
}