From 194030f18ae623fbf5b0bb805b780f81fe9ec7a7 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sat, 29 Feb 2020 21:27:05 +0100 Subject: speed: add XChaCha20-Poly1305-Go https://github.com/rfjakob/gocryptfs/issues/452 --- internal/speed/speed.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'internal/speed') diff --git a/internal/speed/speed.go b/internal/speed/speed.go index 2f1e0f6..6cfe511 100644 --- a/internal/speed/speed.go +++ b/internal/speed/speed.go @@ -12,6 +12,8 @@ import ( "log" "testing" + "golang.org/x/crypto/chacha20poly1305" + "github.com/rfjakob/gocryptfs/internal/siv_aead" "github.com/rfjakob/gocryptfs/internal/stupidgcm" ) @@ -32,6 +34,7 @@ func Run() { {name: "AES-GCM-256-OpenSSL", f: bStupidGCM, preferred: stupidgcm.PreferOpenSSL()}, {name: "AES-GCM-256-Go", f: bGoGCM, preferred: !stupidgcm.PreferOpenSSL()}, {name: "AES-SIV-512-Go", f: bAESSIV, preferred: false}, + {name: "XChaCha20-Poly1305-Go", f: bChacha20poly1305, preferred: false}, } for _, b := range bTable { fmt.Printf("%-20s\t", b.name) @@ -125,3 +128,19 @@ func bAESSIV(b *testing.B) { gGCM.Seal(iv, iv, in, authData) } } + +// bChacha20poly1305 benchmarks XChaCha20 from golang.org/x/crypto/chacha20poly1305 +func bChacha20poly1305(b *testing.B) { + key := randBytes(32) + authData := randBytes(adLen) + iv := randBytes(chacha20poly1305.NonceSizeX) + in := make([]byte, blockSize) + b.SetBytes(int64(len(in))) + c, _ := chacha20poly1305.NewX(key) + + b.ResetTimer() + for i := 0; i < b.N; i++ { + // Encrypt and append to nonce + c.Seal(iv, iv, in, authData) + } +} -- cgit v1.2.3