summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-08-29 22:35:42 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-08-29 22:35:42 +0700
commitf8a54ed24a06a522700e002fd29e15ff024c9cc7 (patch)
treeb7c0b4cbe53ff5b86f19193d27bb4658cc1655c8
parentSpan-based variants for IBlockCipherPadding (diff)
downloadBouncyCastle.NET-ed25519-f8a54ed24a06a522700e002fd29e15ff024c9cc7.tar.xz
SecureRandom fixups in tests
-rw-r--r--crypto/test/src/crypto/test/GOST3410Test.cs6
-rw-r--r--crypto/test/src/crypto/test/OAEPTest.cs1
-rw-r--r--crypto/test/src/crypto/test/PSSBlindTest.cs4
-rw-r--r--crypto/test/src/crypto/test/PSSTest.cs14
-rw-r--r--crypto/test/src/crypto/test/RC2WrapTest.cs5
-rw-r--r--crypto/test/src/pqc/crypto/lms/HSSTests.cs7
-rw-r--r--crypto/test/src/pqc/crypto/test/NistSecureRandom.cs1
-rw-r--r--crypto/test/src/test/BlockCipherTest.cs7
-rw-r--r--crypto/test/src/test/DESedeTest.cs7
-rw-r--r--crypto/test/src/test/PSSTest.cs4
-rw-r--r--crypto/test/src/test/RSATest.cs9
-rw-r--r--crypto/test/src/util/test/FixedSecureRandom.cs38
12 files changed, 58 insertions, 45 deletions
diff --git a/crypto/test/src/crypto/test/GOST3410Test.cs b/crypto/test/src/crypto/test/GOST3410Test.cs
index 130fdaf92..03e16382d 100644
--- a/crypto/test/src/crypto/test/GOST3410Test.cs
+++ b/crypto/test/src/crypto/test/GOST3410Test.cs
@@ -258,7 +258,6 @@ namespace Org.BouncyCastle.Crypto.Tests
 
 				public override void NextBytes(byte[] bytes)
 				{
-
 					byte[] d = Hex.Decode("02");
 
 					Array.Copy(d, 0, bytes, bytes.Length-d.Length, d.Length);
@@ -1594,6 +1593,11 @@ namespace Org.BouncyCastle.Crypto.Tests
 
 		internal class SecureRandomImpl : SecureRandom
 		{
+			internal SecureRandomImpl()
+				: base(null)
+			{
+			}
+
 			public override void NextBytes(byte[] buf, int off, int len)
 			{
 				byte[] bytes = new byte[len];
diff --git a/crypto/test/src/crypto/test/OAEPTest.cs b/crypto/test/src/crypto/test/OAEPTest.cs
index b2cbde8b3..6228c4ad6 100644
--- a/crypto/test/src/crypto/test/OAEPTest.cs
+++ b/crypto/test/src/crypto/test/OAEPTest.cs
@@ -289,6 +289,7 @@ namespace Org.BouncyCastle.Crypto.Tests
             private readonly byte[] seed;
 
             internal VecRand(byte[] seed)
+                : base(null)
             {
                 this.seed = seed;
             }
diff --git a/crypto/test/src/crypto/test/PSSBlindTest.cs b/crypto/test/src/crypto/test/PSSBlindTest.cs
index 1cd74bb70..2f227cb68 100644
--- a/crypto/test/src/crypto/test/PSSBlindTest.cs
+++ b/crypto/test/src/crypto/test/PSSBlindTest.cs
@@ -30,8 +30,8 @@ namespace Org.BouncyCastle.Crypto.Tests
 		{
 			private readonly byte[] vals;
 
-			public FixedRandom(
-				byte[] vals)
+			public FixedRandom(byte[] vals)
+				: base(null)
 			{
 				this.vals = vals;
 			}
diff --git a/crypto/test/src/crypto/test/PSSTest.cs b/crypto/test/src/crypto/test/PSSTest.cs
index aeaf85a53..599c2c8c7 100644
--- a/crypto/test/src/crypto/test/PSSTest.cs
+++ b/crypto/test/src/crypto/test/PSSTest.cs
@@ -26,8 +26,8 @@ namespace Org.BouncyCastle.Crypto.Tests
 		{
 			private readonly byte[] vals;
 
-			public FixedRandom(
-				byte[] vals)
+			public FixedRandom(byte[] vals)
+				: base(null)
 			{
 				this.vals = vals;
 			}
@@ -41,12 +41,12 @@ namespace Org.BouncyCastle.Crypto.Tests
 			{
 				Array.Copy(vals, 0, buf, off, len);
 			}
-		}
+        }
 
-		//
-		// Example 1: A 1024-bit RSA keypair
-		//
-		private RsaKeyParameters pub1 = new RsaKeyParameters(false,
+        //
+        // Example 1: A 1024-bit RSA keypair
+        //
+        private RsaKeyParameters pub1 = new RsaKeyParameters(false,
 			new BigInteger("a56e4a0e701017589a5187dc7ea841d156f2ec0e36ad52a44dfeb1e61f7ad991d8c51056ffedb162b4c0f283a12a88a394dff526ab7291cbb307ceabfce0b1dfd5cd9508096d5b2b8b6df5d671ef6377c0921cb23c270a70e2598e6ff89d19f105acc2d3f0cb35f29280e1386b6f64c4ef22e1e1f20d0ce8cffb2249bd9a2137",16),
 			new BigInteger("010001",16));
 
diff --git a/crypto/test/src/crypto/test/RC2WrapTest.cs b/crypto/test/src/crypto/test/RC2WrapTest.cs
index 7d98ee9af..37cd70160 100644
--- a/crypto/test/src/crypto/test/RC2WrapTest.cs
+++ b/crypto/test/src/crypto/test/RC2WrapTest.cs
@@ -22,6 +22,11 @@ namespace Org.BouncyCastle.Crypto.Tests
 		private class RFCRandom
 			: SecureRandom
 		{
+			internal RFCRandom()
+				: base(null)
+			{
+			}
+
 			public override void NextBytes(byte[] buf)
 			{
 				NextBytes(buf, 0, buf.Length);
diff --git a/crypto/test/src/pqc/crypto/lms/HSSTests.cs b/crypto/test/src/pqc/crypto/lms/HSSTests.cs
index 2045f7693..53491f2a3 100644
--- a/crypto/test/src/pqc/crypto/lms/HSSTests.cs
+++ b/crypto/test/src/pqc/crypto/lms/HSSTests.cs
@@ -728,9 +728,14 @@ namespace Org.BouncyCastle.Pqc.Crypto.Lms
          *
          * @
          */
-        class HSSSecureRandom
+        internal class HSSSecureRandom
             : SecureRandom
         {
+            internal HSSSecureRandom()
+                : base(null)
+            {
+            }
+
             public override void NextBytes(byte[] buf)
             {
                 NextBytes(buf, 0, buf.Length);
diff --git a/crypto/test/src/pqc/crypto/test/NistSecureRandom.cs b/crypto/test/src/pqc/crypto/test/NistSecureRandom.cs
index aac73c4ee..0c47d42ce 100644
--- a/crypto/test/src/pqc/crypto/test/NistSecureRandom.cs
+++ b/crypto/test/src/pqc/crypto/test/NistSecureRandom.cs
@@ -56,6 +56,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Tests
         }
 
         public NistSecureRandom(byte[] seed, byte[] personalization)
+            : base(null)
         {
             this.seed = seed;
             this.personalization = personalization;
diff --git a/crypto/test/src/test/BlockCipherTest.cs b/crypto/test/src/test/BlockCipherTest.cs
index e57a8ad09..855e3a3da 100644
--- a/crypto/test/src/test/BlockCipherTest.cs
+++ b/crypto/test/src/test/BlockCipherTest.cs
@@ -395,13 +395,18 @@ namespace Org.BouncyCastle.Tests
         private class FixedSecureRandom
             : SecureRandom
         {
-            byte[] seed = {
+            private static readonly byte[] seed = {
                     (byte)0xaa, (byte)0xfd, (byte)0x12, (byte)0xf6, (byte)0x59,
                     (byte)0xca, (byte)0xe6, (byte)0x34, (byte)0x89, (byte)0xb4,
                     (byte)0x79, (byte)0xe5, (byte)0x07, (byte)0x6d, (byte)0xde,
                     (byte)0xc2, (byte)0xf0, (byte)0x6c, (byte)0xb5, (byte)0x8f
             };
 
+            internal FixedSecureRandom()
+                : base(null)
+            {
+            }
+
             public override void NextBytes(byte[] buf)
             {
                 NextBytes(buf, 0, buf.Length);
diff --git a/crypto/test/src/test/DESedeTest.cs b/crypto/test/src/test/DESedeTest.cs
index 39d55e424..6e2d98851 100644
--- a/crypto/test/src/test/DESedeTest.cs
+++ b/crypto/test/src/test/DESedeTest.cs
@@ -45,7 +45,7 @@ namespace Org.BouncyCastle.Tests
         private class FixedSecureRandom
             : SecureRandom
         {
-            private byte[] seed =
+            private static readonly byte[] seed =
             {
                 (byte)0xaa, (byte)0xfd, (byte)0x12, (byte)0xf6, (byte)0x59,
                 (byte)0xca, (byte)0xe6, (byte)0x34, (byte)0x89, (byte)0xb4,
@@ -53,6 +53,11 @@ namespace Org.BouncyCastle.Tests
                 (byte)0xc2, (byte)0xf0, (byte)0x6c, (byte)0xb5, (byte)0x8f
             };
 
+            internal FixedSecureRandom()
+                : base(null)
+            {
+            }
+
             public override void NextBytes(byte[] buf)
             {
                 NextBytes(buf, 0, buf.Length);
diff --git a/crypto/test/src/test/PSSTest.cs b/crypto/test/src/test/PSSTest.cs
index fa6f54e31..de56886dd 100644
--- a/crypto/test/src/test/PSSTest.cs
+++ b/crypto/test/src/test/PSSTest.cs
@@ -27,8 +27,8 @@ namespace Org.BouncyCastle.Tests
 		{
 			private readonly byte[] vals;
 
-			public FixedRandom(
-				byte[] vals)
+			internal FixedRandom(byte[] vals)
+				: base(null)
 			{
 				this.vals = vals;
 			}
diff --git a/crypto/test/src/test/RSATest.cs b/crypto/test/src/test/RSATest.cs
index 94c1fb816..eabb763fc 100644
--- a/crypto/test/src/test/RSATest.cs
+++ b/crypto/test/src/test/RSATest.cs
@@ -31,7 +31,7 @@ namespace Org.BouncyCastle.Tests
 		private class MyFixedSecureRandom
 			: SecureRandom
 		{
-			byte[] seed =
+			private static readonly byte[] seed =
 			{
 				(byte)0xaa, (byte)0xfd, (byte)0x12, (byte)0xf6, (byte)0x59,
 				(byte)0xca, (byte)0xe6, (byte)0x34, (byte)0x89, (byte)0xb4,
@@ -39,7 +39,12 @@ namespace Org.BouncyCastle.Tests
 				(byte)0xc2, (byte)0xf0, (byte)0x6c, (byte)0xb5, (byte)0x8f
 			};
 
-			public override void NextBytes(byte[] buf)
+			internal MyFixedSecureRandom()
+				: base(null)
+			{
+			}
+
+            public override void NextBytes(byte[] buf)
 			{
 				NextBytes(buf, 0, buf.Length);
 			}
diff --git a/crypto/test/src/util/test/FixedSecureRandom.cs b/crypto/test/src/util/test/FixedSecureRandom.cs
index d29159a62..a7f3c1f3b 100644
--- a/crypto/test/src/util/test/FixedSecureRandom.cs
+++ b/crypto/test/src/util/test/FixedSecureRandom.cs
@@ -85,14 +85,13 @@ namespace Org.BouncyCastle.Utilities.Test
             }
         }
 
-        protected FixedSecureRandom(
-			byte[] data)
+        protected FixedSecureRandom(byte[] data)
+            : base(null)
 		{
 			_data = data;
 		}
 
-		public static FixedSecureRandom From(
-			params byte[][] values)
+		public static FixedSecureRandom From(params byte[][] values)
 		{
 			MemoryStream bOut = new MemoryStream();
 
@@ -112,8 +111,8 @@ namespace Org.BouncyCastle.Utilities.Test
 			return new FixedSecureRandom(bOut.ToArray());
 		}
 
-        public FixedSecureRandom(
-            Source[] sources)
+        public FixedSecureRandom(Source[] sources)
+            : base(null)
         {
             MemoryStream bOut = new MemoryStream();
 
@@ -226,17 +225,6 @@ namespace Org.BouncyCastle.Utilities.Test
 			_index += len;
 		}
 
-        // NOTE: .NET Core 2.1 has Span<T>, but is tested against our .NET Standard 2.0 assembly.
-        //#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
-#if NET6_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
-        public override void NextBytes(Span<byte> buffer)
-        {
-            _data.AsSpan(_index, buffer.Length).CopyTo(buffer);
-
-            _index += buffer.Length;
-        }
-#endif
-
         public bool IsExhausted
 		{
 			get { return _index == _data.Length; }
@@ -248,6 +236,11 @@ namespace Org.BouncyCastle.Utilities.Test
             byte[] data = Hex.Decode("01020304ffffffff0506070811111111");
             int    index = 0;
 
+            internal RandomChecker()
+                : base(null)
+            {
+            }
+
             public override void NextBytes(byte[] buf)
             {
                 NextBytes(buf, 0, buf.Length);
@@ -259,17 +252,6 @@ namespace Org.BouncyCastle.Utilities.Test
 
                 index += len;
             }
-
-            // NOTE: .NET Core 2.1 has Span<T>, but is tested against our .NET Standard 2.0 assembly.
-//#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
-#if NET6_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
-            public override void NextBytes(Span<byte> buffer)
-            {
-                data.AsSpan(index, buffer.Length).CopyTo(buffer);
-
-                index += buffer.Length;
-            }
-#endif
         }
 
         private static byte[] ExpandToBitLength(int bitLength, byte[] v)