2017-02-22 23:55:43 +01:00
|
|
|
package speed
|
|
|
|
|
2021-09-03 18:30:42 +02:00
|
|
|
import (
|
|
|
|
"crypto/aes"
|
|
|
|
"crypto/cipher"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"golang.org/x/crypto/chacha20poly1305"
|
|
|
|
|
|
|
|
"github.com/rfjakob/gocryptfs/v2/internal/siv_aead"
|
|
|
|
"github.com/rfjakob/gocryptfs/v2/internal/stupidgcm"
|
|
|
|
)
|
|
|
|
|
2017-02-22 23:55:43 +01:00
|
|
|
/*
|
|
|
|
Make the "-speed" benchmarks also accessible to the standard test system.
|
|
|
|
Example run:
|
|
|
|
|
|
|
|
$ go test -bench .
|
|
|
|
BenchmarkStupidGCM-2 100000 22552 ns/op 181.62 MB/s
|
|
|
|
BenchmarkGoGCM-2 20000 81871 ns/op 50.03 MB/s
|
|
|
|
BenchmarkAESSIV-2 10000 104623 ns/op 39.15 MB/s
|
|
|
|
PASS
|
2021-08-23 15:05:15 +02:00
|
|
|
ok github.com/rfjakob/gocryptfs/v2/internal/speed 6.022s
|
2017-02-22 23:55:43 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
func BenchmarkStupidGCM(b *testing.B) {
|
|
|
|
bStupidGCM(b)
|
|
|
|
}
|
|
|
|
|
2021-09-03 18:30:42 +02:00
|
|
|
func BenchmarkStupidGCMDecrypt(b *testing.B) {
|
|
|
|
if stupidgcm.BuiltWithoutOpenssl {
|
|
|
|
b.Skip("openssl has been disabled at compile-time")
|
|
|
|
}
|
|
|
|
bDecrypt(b, stupidgcm.New(randBytes(32), false))
|
|
|
|
}
|
|
|
|
|
2017-02-22 23:55:43 +01:00
|
|
|
func BenchmarkGoGCM(b *testing.B) {
|
|
|
|
bGoGCM(b)
|
|
|
|
}
|
|
|
|
|
2021-09-03 18:30:42 +02:00
|
|
|
func BenchmarkGoGCMDecrypt(b *testing.B) {
|
|
|
|
gAES, err := aes.NewCipher(randBytes(32))
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
gGCM, err := cipher.NewGCMWithNonceSize(gAES, 16)
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
bDecrypt(b, gGCM)
|
|
|
|
}
|
|
|
|
|
2017-02-22 23:55:43 +01:00
|
|
|
func BenchmarkAESSIV(b *testing.B) {
|
|
|
|
bAESSIV(b)
|
|
|
|
}
|
2021-09-02 11:33:06 +02:00
|
|
|
|
2021-09-03 18:30:42 +02:00
|
|
|
func BenchmarkAESSIVDecrypt(b *testing.B) {
|
|
|
|
bEncrypt(b, siv_aead.New(randBytes(64)))
|
|
|
|
}
|
|
|
|
|
2021-09-02 11:33:06 +02:00
|
|
|
func BenchmarkXchacha(b *testing.B) {
|
|
|
|
bXchacha20poly1305(b)
|
|
|
|
}
|
|
|
|
|
2021-09-03 18:30:42 +02:00
|
|
|
func BenchmarkXchachaDecrypt(b *testing.B) {
|
|
|
|
c, _ := chacha20poly1305.NewX(randBytes(32))
|
|
|
|
bDecrypt(b, c)
|
|
|
|
}
|
|
|
|
|
2021-09-02 11:33:06 +02:00
|
|
|
func BenchmarkStupidXchacha(b *testing.B) {
|
|
|
|
bStupidXchacha(b)
|
|
|
|
}
|
2021-09-03 18:30:42 +02:00
|
|
|
|
|
|
|
func BenchmarkStupidXchachaDecrypt(b *testing.B) {
|
|
|
|
bDecrypt(b, stupidgcm.NewXchacha20poly1305(randBytes(32)))
|
|
|
|
}
|