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
This commit is contained in:
parent
c6a6641b58
commit
f4ae0304af
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user