aboutsummaryrefslogtreecommitdiff
path: root/cryptfs/openssl_aead.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2015-12-08 13:22:57 +0100
committerJakob Unterwurzacher2015-12-08 13:22:57 +0100
commitf4ae0304aff2f721ebe6088aa4f4c83f872f1ee9 (patch)
treeeb6ff6100c9530e93454302e0e9a61a0e6dbb5e1 /cryptfs/openssl_aead.go
parentc6a6641b58d4bd8fd9e64ad7a653eff9886ee6e2 (diff)
opensslGCM: preallocate buffer space, improves performance by 11%
Results of cryptfs/openssl_benchmark.bash : Before: BenchmarkEnc_OpenSSL_4k_AES256_nonce96-2 50000 31802 ns/op 127.28 MB/s BenchmarkEnc_OpenSSL_4k_AES256_nonce128-2 50000 32110 ns/op 126.06 MB/s After: BenchmarkEnc_OpenSSL_4k_AES256_nonce96-2 50000 28612 ns/op 141.47 MB/s BenchmarkEnc_OpenSSL_4k_AES256_nonce128-2 50000 28613 ns/op 141.47 MB/s
Diffstat (limited to 'cryptfs/openssl_aead.go')
-rw-r--r--cryptfs/openssl_aead.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/cryptfs/openssl_aead.go b/cryptfs/openssl_aead.go
index 1ec7c48..c70bd1f 100644
--- a/cryptfs/openssl_aead.go
+++ b/cryptfs/openssl_aead.go
@@ -25,7 +25,11 @@ func (be opensslGCM) NonceSize() int {
// time, for a given key.
func (be opensslGCM) Seal(dst, nonce, plaintext, data []byte) []byte {
- cipherBuf := bytes.NewBuffer(dst)
+ // Preallocate output buffer
+ var cipherBuf bytes.Buffer
+ cipherBuf.Grow(len(dst) + len(plaintext) + AUTH_TAG_LEN)
+ // Output will be appended to dst
+ cipherBuf.Write(dst)
ectx, err := openssl.NewGCMEncryptionCipherCtx(KEY_LEN*8, nil, be.key, nonce)
if err != nil {