summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorJakob Unterwurzacher2021-09-07 12:44:42 +0200
committerJakob Unterwurzacher2021-09-07 18:14:58 +0200
commitd9510d0c0ba2ef31145499f4d49ab1d10c03de94 (patch)
tree7320743431e14df60f711172e9a79a0c6e247373 /internal
parent39b1070506436dcf35ac83c7f8cee65067856062 (diff)
stupidgcm: NewChacha20poly1305: avoid slice append
I noticed that growslice() shows up in the cpuprofile. Avoiding slice append for the private jey copy gives a 0.6% speedup: gocryptfs/internal/speed$ benchstat old new name old time/op new time/op delta StupidXchacha-4 5.68µs ± 0% 5.65µs ± 0% -0.63% (p=0.008 n=5+5) name old speed new speed delta StupidXchacha-4 721MB/s ± 0% 725MB/s ± 0% +0.63% (p=0.008 n=5+5)
Diffstat (limited to 'internal')
-rw-r--r--internal/stupidgcm/chacha.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/internal/stupidgcm/chacha.go b/internal/stupidgcm/chacha.go
index c90d721..30d57e3 100644
--- a/internal/stupidgcm/chacha.go
+++ b/internal/stupidgcm/chacha.go
@@ -39,9 +39,12 @@ func NewChacha20poly1305(key []byte) *stupidChacha20poly1305 {
if len(key) != chacha20poly1305.KeySize {
log.Panicf("Only %d-byte keys are supported, you passed %d bytes", chacha20poly1305.KeySize, len(key))
}
+ // private copy
+ key2 := make([]byte, chacha20poly1305.KeySize)
+ copy(key2, key)
return &stupidChacha20poly1305{
stupidAEADCommon{
- key: append([]byte{}, key...), // private copy
+ key: key2,
openSSLEVPCipher: _EVP_chacha20_poly1305,
nonceSize: chacha20poly1305.NonceSize,
},