diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-05-16 19:32:00 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-05-16 19:32:00 +0700 |
commit | 8dac4e77544c556e1e28bbfdaf8a760cab9ff837 (patch) | |
tree | d952f1a06694cc335b3b5f18e80f55df075aada9 | |
parent | DTLS: Remove the need to reset AEAD ciphers (diff) | |
download | BouncyCastle.NET-ed25519-8dac4e77544c556e1e28bbfdaf8a760cab9ff837.tar.xz |
Perf. opts. in CipherStream
-rw-r--r-- | crypto/src/crypto/io/CipherStream.cs | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/crypto/src/crypto/io/CipherStream.cs b/crypto/src/crypto/io/CipherStream.cs index 3ae828664..a06f74190 100644 --- a/crypto/src/crypto/io/CipherStream.cs +++ b/crypto/src/crypto/io/CipherStream.cs @@ -221,15 +221,13 @@ namespace Org.BouncyCastle.Crypto.IO int outputSize = m_writeCipher.GetUpdateOutputSize(buffer.Length); - byte[] output = null; - if (outputSize > 0) - { - output = new byte[outputSize]; - } + Span<byte> output = outputSize <= Streams.DefaultBufferSize + ? stackalloc byte[outputSize] + : new byte[outputSize]; try { - int length = m_writeCipher.ProcessBytes(buffer, Spans.FromNullable(output)); + int length = m_writeCipher.ProcessBytes(buffer, output); if (length > 0) { m_stream.Write(output[..length]); @@ -237,10 +235,7 @@ namespace Org.BouncyCastle.Crypto.IO } finally { - if (output != null) - { - Array.Clear(output, 0, output.Length); - } + output.Fill(0x00); } } |