summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-04-13 15:32:29 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-04-13 15:32:29 +0700
commitddc7a559a2943c49e3cc248f8b464ed356c37a5a (patch)
tree32a1e2f36feecc01b71a44ee6b13c710e817c4da
parentRound out Span-based Pack methods (diff)
downloadBouncyCastle.NET-ed25519-ddc7a559a2943c49e3cc248f8b464ed356c37a5a.tar.xz
Guard against null nonce and clone returned nonce
-rw-r--r--crypto/src/crypto/parameters/AEADParameters.cs19
1 files changed, 11 insertions, 8 deletions
diff --git a/crypto/src/crypto/parameters/AEADParameters.cs b/crypto/src/crypto/parameters/AEADParameters.cs
index 825d6b7f2..5b0ce33f2 100644
--- a/crypto/src/crypto/parameters/AEADParameters.cs
+++ b/crypto/src/crypto/parameters/AEADParameters.cs
@@ -30,13 +30,12 @@ namespace Org.BouncyCastle.Crypto.Parameters
 		 * @param nonce nonce to be used
 		 * @param associatedText associated text, if any
 		 */
-		public AeadParameters(
-			KeyParameter	key,
-			int				macSize,
-			byte[]			nonce,
-			byte[]			associatedText)
+		public AeadParameters(KeyParameter key, int macSize, byte[] nonce, byte[] associatedText)
 		{
-			this.key = key;
+            if (nonce == null)
+                throw new ArgumentNullException(nameof(nonce));
+
+            this.key = key;
 			this.nonce = nonce;
 			this.macSize = macSize;
 			this.associatedText = associatedText;
@@ -59,7 +58,11 @@ namespace Org.BouncyCastle.Crypto.Parameters
 
 		public virtual byte[] GetNonce()
 		{
-			return nonce;
+			return (byte[])nonce.Clone();
 		}
-	}
+
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
+        internal ReadOnlySpan<byte> Nonce => nonce;
+#endif
+    }
 }