diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-05-17 01:52:14 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-05-17 01:52:14 +0700 |
commit | f0004636e1ab9d4dd2b617f8405e264cf8bbaf52 (patch) | |
tree | e68a04dbfbd6e189566ff26c8f823b2573622bb9 | |
parent | Avoid dummy cipher init (diff) | |
download | BouncyCastle.NET-ed25519-f0004636e1ab9d4dd2b617f8405e264cf8bbaf52.tar.xz |
Refactoring in Tls.Crypto.Impl.BC
-rw-r--r-- | crypto/src/tls/crypto/impl/bc/BcChaCha20Poly1305.cs | 14 | ||||
-rw-r--r-- | crypto/src/tls/crypto/impl/bc/BcTlsAeadCipherImpl.cs | 3 |
2 files changed, 11 insertions, 6 deletions
diff --git a/crypto/src/tls/crypto/impl/bc/BcChaCha20Poly1305.cs b/crypto/src/tls/crypto/impl/bc/BcChaCha20Poly1305.cs index dc5672814..3ed6b3365 100644 --- a/crypto/src/tls/crypto/impl/bc/BcChaCha20Poly1305.cs +++ b/crypto/src/tls/crypto/impl/bc/BcChaCha20Poly1305.cs @@ -4,6 +4,7 @@ using Org.BouncyCastle.Crypto.Engines; using Org.BouncyCastle.Crypto.Macs; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Crypto.Utilities; +using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Tls.Crypto.Impl.BC { @@ -76,9 +77,12 @@ namespace Org.BouncyCastle.Tls.Crypto.Impl.BC public int DoFinal(byte[] additionalData, byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset) { - if (additionalData != null) + if (!Arrays.IsNullOrEmpty(additionalData)) { - this.m_additionalDataLength += additionalData.Length; + if (m_additionalDataLength != 0) + throw new InvalidOperationException(); + + m_additionalDataLength = additionalData.Length; UpdateMac(additionalData, 0, additionalData.Length); } @@ -97,13 +101,13 @@ namespace Org.BouncyCastle.Tls.Crypto.Impl.BC m_cipher.Init(m_isEncrypting, new ParametersWithIV(null, nonce)); InitMac(); - if (additionalData == null) + if (Arrays.IsNullOrEmpty(additionalData)) { - this.m_additionalDataLength = 0; + m_additionalDataLength = 0; } else { - this.m_additionalDataLength = additionalData.Length; + m_additionalDataLength = additionalData.Length; UpdateMac(additionalData, 0, additionalData.Length); } } diff --git a/crypto/src/tls/crypto/impl/bc/BcTlsAeadCipherImpl.cs b/crypto/src/tls/crypto/impl/bc/BcTlsAeadCipherImpl.cs index 7dfa737d9..4ffe52b02 100644 --- a/crypto/src/tls/crypto/impl/bc/BcTlsAeadCipherImpl.cs +++ b/crypto/src/tls/crypto/impl/bc/BcTlsAeadCipherImpl.cs @@ -3,6 +3,7 @@ using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Crypto.Modes; using Org.BouncyCastle.Crypto.Parameters; +using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Tls.Crypto.Impl.BC { @@ -61,7 +62,7 @@ namespace Org.BouncyCastle.Tls.Crypto.Impl.BC public virtual int DoFinal(byte[] additionalData, byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset) { - if (additionalData != null) + if (!Arrays.IsNullOrEmpty(additionalData)) { m_cipher.ProcessAadBytes(additionalData, 0, additionalData.Length); } |