From eac2a4f8cf6025b7be8c1e7974785a5f968b4eba Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Wed, 2 Nov 2022 14:30:18 +0700 Subject: A few span opts. --- crypto/src/tls/crypto/impl/bc/BcChaCha20Poly1305.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'crypto/src/tls') diff --git a/crypto/src/tls/crypto/impl/bc/BcChaCha20Poly1305.cs b/crypto/src/tls/crypto/impl/bc/BcChaCha20Poly1305.cs index 6b87c100a..f8e36a245 100644 --- a/crypto/src/tls/crypto/impl/bc/BcChaCha20Poly1305.cs +++ b/crypto/src/tls/crypto/impl/bc/BcChaCha20Poly1305.cs @@ -106,16 +106,23 @@ namespace Org.BouncyCastle.Tls.Crypto.Impl.BC public void SetKey(ReadOnlySpan key) { KeyParameter cipherKey = new KeyParameter(key); - m_cipher.Init(m_isEncrypting, new ParametersWithIV(cipherKey, Zeroes[..12])); + m_cipher.Init(m_isEncrypting, new ParametersWithIV(cipherKey, Zeroes.AsSpan(0, 12))); } #endif private void InitMac() { +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + Span firstBlock = stackalloc byte[64]; + m_cipher.ProcessBytes(firstBlock, firstBlock); + m_mac.Init(new KeyParameter(firstBlock[..32])); + firstBlock.Fill(0x00); +#else byte[] firstBlock = new byte[64]; m_cipher.ProcessBytes(firstBlock, 0, 64, firstBlock, 0); m_mac.Init(new KeyParameter(firstBlock, 0, 32)); Array.Clear(firstBlock, 0, firstBlock.Length); +#endif } private void UpdateMac(byte[] buf, int off, int len) -- cgit 1.4.1