summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-11-17 10:39:02 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-11-17 10:39:02 +0700
commit20ed63bdf95801371d276eab7d91775adbc451d3 (patch)
tree41ea5483f35a4e31af43037d3dcf20376890bad2
parentRefactor LMS parsing (diff)
downloadBouncyCastle.NET-ed25519-20ed63bdf95801371d276eab7d91775adbc451d3.tar.xz
Refactoring in Tls
-rw-r--r--crypto/src/tls/ByteQueue.cs2
-rw-r--r--crypto/src/tls/crypto/impl/TlsSuiteHmac.cs4
-rw-r--r--crypto/src/tls/crypto/impl/bc/BcTlsCrypto.cs8
3 files changed, 11 insertions, 3 deletions
diff --git a/crypto/src/tls/ByteQueue.cs b/crypto/src/tls/ByteQueue.cs
index a92f79baf..6d29a2d3e 100644
--- a/crypto/src/tls/ByteQueue.cs
+++ b/crypto/src/tls/ByteQueue.cs
@@ -164,7 +164,7 @@ namespace Org.BouncyCastle.Tls
             if ((m_available - skip) < buffer.Length)
                 throw new InvalidOperationException("Not enough data to read");
 
-            buffer.CopyFrom(m_databuf.AsSpan(m_skipped + skip));
+            m_databuf.AsSpan(m_skipped + skip, buffer.Length).CopyTo(buffer);
         }
 #endif
 
diff --git a/crypto/src/tls/crypto/impl/TlsSuiteHmac.cs b/crypto/src/tls/crypto/impl/TlsSuiteHmac.cs
index f008fc759..3e4b6f0f2 100644
--- a/crypto/src/tls/crypto/impl/TlsSuiteHmac.cs
+++ b/crypto/src/tls/crypto/impl/TlsSuiteHmac.cs
@@ -66,7 +66,9 @@ namespace Org.BouncyCastle.Tls.Crypto.Impl
             int msgLen)
         {
 #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
-            return CalculateMac(seqNo, type, Spans.FromNullableReadOnly(connectionID), msg.AsSpan(msgOff, msgLen));
+            var connIDSpan = connectionID == null ? Span<byte>.Empty : connectionID.AsSpan();
+
+            return CalculateMac(seqNo, type, connIDSpan, msg.AsSpan(msgOff, msgLen));
 #else
             ProtocolVersion serverVersion = m_cryptoParams.ServerVersion;
 
diff --git a/crypto/src/tls/crypto/impl/bc/BcTlsCrypto.cs b/crypto/src/tls/crypto/impl/bc/BcTlsCrypto.cs
index 39df32ed8..0686d8ece 100644
--- a/crypto/src/tls/crypto/impl/bc/BcTlsCrypto.cs
+++ b/crypto/src/tls/crypto/impl/bc/BcTlsCrypto.cs
@@ -156,8 +156,14 @@ namespace Org.BouncyCastle.Tls.Crypto.Impl.BC
 
         public override TlsNonceGenerator CreateNonceGenerator(byte[] additionalSeedMaterial)
         {
+            // TODO[api] Require non-null additionalSeedMaterial
+            //if (additionalSeedMaterial == null)
+            //    throw new ArgumentNullException(nameof(additionalSeedMaterial));
+
 #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
-            return CreateNonceGenerator(Spans.FromNullableReadOnly(additionalSeedMaterial));
+            var seed = additionalSeedMaterial == null ? Span<byte>.Empty : additionalSeedMaterial.AsSpan();
+
+            return CreateNonceGenerator(seed);
 #else
             int cryptoHashAlgorithm = CryptoHashAlgorithm.sha256;
             IDigest digest = CreateDigest(cryptoHashAlgorithm);