speed: add BenchmarkStupidChacha

gocryptfs/internal/speed$ go test -bench .
goos: linux
goarch: amd64
pkg: github.com/rfjakob/gocryptfs/v2/internal/speed
cpu: Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz
BenchmarkStupidGCM-4              	  249396	      4722 ns/op	 867.50 MB/s
BenchmarkStupidGCMDecrypt-4       	  257872	      4616 ns/op	 887.35 MB/s
BenchmarkGoGCM-4                  	  290952	      4097 ns/op	 999.83 MB/s
BenchmarkGoGCMDecrypt-4           	  294106	      4060 ns/op	1008.84 MB/s
BenchmarkAESSIV-4                 	   46520	     25532 ns/op	 160.42 MB/s
BenchmarkAESSIVDecrypt-4          	   46974	     25478 ns/op	 160.76 MB/s
BenchmarkXchacha-4                	  244108	      4881 ns/op	 839.14 MB/s
BenchmarkXchachaDecrypt-4         	  249658	      4786 ns/op	 855.86 MB/s
BenchmarkStupidXchacha-4          	  205339	      5768 ns/op	 710.11 MB/s
BenchmarkStupidXchachaDecrypt-4   	  204577	      5836 ns/op	 701.84 MB/s
BenchmarkStupidChacha-4           	  227510	      5224 ns/op	 784.06 MB/s
BenchmarkStupidChachaDecrypt-4    	  222787	      5359 ns/op	 764.34 MB/s
PASS
ok  	github.com/rfjakob/gocryptfs/v2/internal/speed	15.328s
This commit is contained in:
Jakob Unterwurzacher 2021-09-04 19:18:42 +02:00
parent b8c56ccffc
commit a2eaa5e3d1
5 changed files with 12 additions and 6 deletions

2
go.sum
View File

@ -1,7 +1,5 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/hanwen/go-fuse/v2 v2.1.1-0.20210825070001-74a933d6e856 h1:rQb7H5igQ2oIeT+Ul1UtIsGhUiSGeCoyLg84otnHdXU=
github.com/hanwen/go-fuse/v2 v2.1.1-0.20210825070001-74a933d6e856/go.mod h1:B1nGE/6RBFyBRC1RRnf23UpwCdyJ31eukw34oAKukAc=
github.com/hanwen/go-fuse/v2 v2.1.1-0.20210825171523-3ab5d95a30ae h1:4CB6T4YTUVvnro5ba8ju1QCbOuyGAeF3vvKlo50EJ4k= github.com/hanwen/go-fuse/v2 v2.1.1-0.20210825171523-3ab5d95a30ae h1:4CB6T4YTUVvnro5ba8ju1QCbOuyGAeF3vvKlo50EJ4k=
github.com/hanwen/go-fuse/v2 v2.1.1-0.20210825171523-3ab5d95a30ae/go.mod h1:B1nGE/6RBFyBRC1RRnf23UpwCdyJ31eukw34oAKukAc= github.com/hanwen/go-fuse/v2 v2.1.1-0.20210825171523-3ab5d95a30ae/go.mod h1:B1nGE/6RBFyBRC1RRnf23UpwCdyJ31eukw34oAKukAc=
github.com/jacobsa/crypto v0.0.0-20190317225127-9f44e2d11115 h1:YuDUUFNM21CAbyPOpOP8BicaTD/0klJEKt5p8yuw+uY= github.com/jacobsa/crypto v0.0.0-20190317225127-9f44e2d11115 h1:YuDUUFNM21CAbyPOpOP8BicaTD/0klJEKt5p8yuw+uY=

View File

@ -74,3 +74,11 @@ func BenchmarkStupidXchacha(b *testing.B) {
func BenchmarkStupidXchachaDecrypt(b *testing.B) { func BenchmarkStupidXchachaDecrypt(b *testing.B) {
bDecrypt(b, stupidgcm.NewXchacha20poly1305(randBytes(32))) bDecrypt(b, stupidgcm.NewXchacha20poly1305(randBytes(32)))
} }
func BenchmarkStupidChacha(b *testing.B) {
bEncrypt(b, stupidgcm.NewChacha20poly1305(randBytes(32)))
}
func BenchmarkStupidChachaDecrypt(b *testing.B) {
bDecrypt(b, stupidgcm.NewChacha20poly1305(randBytes(32)))
}

View File

@ -21,7 +21,7 @@ type stupidChacha20poly1305 struct {
// Verify that we satisfy the cipher.AEAD interface // Verify that we satisfy the cipher.AEAD interface
var _ cipher.AEAD = &stupidChacha20poly1305{} var _ cipher.AEAD = &stupidChacha20poly1305{}
func newChacha20poly1305(key []byte) *stupidChacha20poly1305 { func NewChacha20poly1305(key []byte) *stupidChacha20poly1305 {
if len(key) != chacha20poly1305.KeySize { if len(key) != chacha20poly1305.KeySize {
log.Panicf("Only %d-byte keys are supported, you passed %d bytes", chacha20poly1305.KeySize, len(key)) log.Panicf("Only %d-byte keys are supported, you passed %d bytes", chacha20poly1305.KeySize, len(key))
} }

View File

@ -10,7 +10,7 @@ import (
func TestStupidChacha20poly1305(t *testing.T) { func TestStupidChacha20poly1305(t *testing.T) {
key := randBytes(32) key := randBytes(32)
c := newChacha20poly1305(key) c := NewChacha20poly1305(key)
ref, err := chacha20poly1305.New(key) ref, err := chacha20poly1305.New(key)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View File

@ -67,7 +67,7 @@ func (x *stupidXchacha20poly1305) Seal(dst, nonce, plaintext, additionalData []b
} }
hKey, _ := chacha20.HChaCha20(x.key[:], nonce[0:16]) hKey, _ := chacha20.HChaCha20(x.key[:], nonce[0:16])
c := newChacha20poly1305(hKey) c := NewChacha20poly1305(hKey)
defer c.Wipe() defer c.Wipe()
// The first 4 bytes of the final nonce are unused counter space. // The first 4 bytes of the final nonce are unused counter space.
@ -92,7 +92,7 @@ func (x *stupidXchacha20poly1305) Open(dst, nonce, ciphertext, additionalData []
} }
hKey, _ := chacha20.HChaCha20(x.key[:], nonce[0:16]) hKey, _ := chacha20.HChaCha20(x.key[:], nonce[0:16])
c := newChacha20poly1305(hKey) c := NewChacha20poly1305(hKey)
defer c.Wipe() defer c.Wipe()
// The first 4 bytes of the final nonce are unused counter space. // The first 4 bytes of the final nonce are unused counter space.