Browse Source

2008-08-05 Sebastien Pouliot <[email protected]>

	* CngAlgorithmGroupTest.cs: New. Unit tests.
	* CngAlgorithmTest.cs: New. Unit tests.
	* MD5CngTest.cs: New. MD5 unit tests.
	* SHA1CngTest.cs: New. SHA1 unit tests.
	* SHA256CngTest.cs: New. SHA256 unit tests.
	* SHA256CryptoServiceProviderTest.cs: New. SHA256 unit tests.
	* SHA384CngTest.cs: New. SHA384 unit tests.
	* SHA384CryptoServiceProviderTest.cs: New. SHA384 unit tests.
	* SHA512CngTest.cs: New. SHA512 unit tests.
	* SHA512CryptoServiceProviderTest.cs: New. SHA512 unit tests.

svn path=/trunk/mcs/; revision=109710
Sebastien Pouliot 17 years ago
parent
commit
a7cdf7535e

+ 12 - 0
mcs/class/System.Core/Test/System.Security.Cryptography/ChangeLog

@@ -0,0 +1,12 @@
+2008-08-05  Sebastien Pouliot  <[email protected]>
+
+	* CngAlgorithmGroupTest.cs: New. Unit tests.
+	* CngAlgorithmTest.cs: New. Unit tests.
+	* MD5CngTest.cs: New. MD5 unit tests.
+	* SHA1CngTest.cs: New. SHA1 unit tests.
+	* SHA256CngTest.cs: New. SHA256 unit tests.
+	* SHA256CryptoServiceProviderTest.cs: New. SHA256 unit tests.
+	* SHA384CngTest.cs: New. SHA384 unit tests.
+	* SHA384CryptoServiceProviderTest.cs: New. SHA384 unit tests.
+	* SHA512CngTest.cs: New. SHA512 unit tests.
+	* SHA512CryptoServiceProviderTest.cs: New. SHA512 unit tests.

+ 144 - 0
mcs/class/System.Core/Test/System.Security.Cryptography/CngAlgorithmGroupTest.cs

@@ -0,0 +1,144 @@
+//
+// Unit tests for System.Security.Cryptography.CngAlgorithmGroup
+//
+// Authors:
+//	Sebastien Pouliot  <[email protected]>
+//
+// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Security.Cryptography;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Security.Cryptography {
+
+	[TestFixture]
+	public class CngAlgorithmGroupTest {
+
+		[Test]
+		public void StaticProperties ()
+		{
+			Assert.IsNotNull (CngAlgorithmGroup.DiffieHellman, "DiffieHellman");
+			Assert.IsNotNull (CngAlgorithmGroup.Dsa, "Dsa");
+			Assert.IsNotNull (CngAlgorithmGroup.ECDiffieHellman, "ECDiffieHellman");
+			Assert.IsNotNull (CngAlgorithmGroup.ECDsa, "ECDsa");
+			Assert.IsNotNull (CngAlgorithmGroup.Rsa, "Rsa");
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void ConstructorNull ()
+		{
+			new CngAlgorithmGroup (null);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentException))]
+		public void ConstructorEmpty ()
+		{
+			new CngAlgorithmGroup (String.Empty);
+		}
+
+		static CngAlgorithmGroup mono = new CngAlgorithmGroup ("mono");
+
+		private void Check (CngAlgorithmGroup group)
+		{
+			Assert.AreEqual (group.AlgorithmGroup, group.ToString (), "Algorithm/ToString");
+			Assert.AreEqual (group.GetHashCode (), group.AlgorithmGroup.GetHashCode (), "GetHashCode");
+			Assert.IsTrue (group.Equals (group), "Equals(self)");
+			Assert.IsTrue (group.Equals ((object) group), "Equals((object)self)");
+
+			CngAlgorithmGroup copy = new CngAlgorithmGroup (group.AlgorithmGroup);
+			Assert.AreEqual (group.GetHashCode (), copy.GetHashCode (), "Copy");
+			Assert.IsTrue (group.Equals (copy), "Equals(copy)");
+			Assert.IsTrue (group.Equals ((object) copy), "Equals((object)copy)");
+			Assert.IsTrue (group == copy, "algo==copy");
+			Assert.IsFalse (group != copy, "algo!=copy");
+
+			Assert.IsFalse (group.Equals (mono), "Equals(mono)");
+			Assert.IsFalse (group.Equals ((object) mono), "Equals((object)mono)");
+			Assert.IsFalse (group == mono, "algo==mono");
+			Assert.IsTrue (group != mono, "algo!=mono");
+		}
+
+		[Test]
+		public void ConstructorCustom ()
+		{
+			CngAlgorithmGroup group = new CngAlgorithmGroup ("custom");
+			Check (group);
+			Assert.IsFalse (group.Equals ((CngAlgorithmGroup) null), "Equals((CngAlgorithmGroup)null)");
+			Assert.IsFalse (group.Equals ((object) null), "Equals((object)null)");
+		}
+
+		[Test]
+		public void DiffieHellman ()
+		{
+			CngAlgorithmGroup group = CngAlgorithmGroup.DiffieHellman;
+			Assert.AreEqual ("DH", group.AlgorithmGroup, "AlgorithmGroup");
+			Assert.IsTrue (group.Equals (CngAlgorithmGroup.DiffieHellman), "Equals(static)");
+			Assert.IsTrue (Object.ReferenceEquals (group, CngAlgorithmGroup.DiffieHellman), "ReferenceEquals");
+			Check (group);
+		}
+
+		[Test]
+		public void Dsa ()
+		{
+			CngAlgorithmGroup group = CngAlgorithmGroup.Dsa;
+			Assert.AreEqual ("DSA", group.AlgorithmGroup, "AlgorithmGroup");
+			Assert.IsTrue (group.Equals (CngAlgorithmGroup.Dsa), "Equals(static)");
+			Assert.IsTrue (Object.ReferenceEquals (group, CngAlgorithmGroup.Dsa), "ReferenceEquals");
+			Check (group);
+		}
+
+		[Test]
+		public void ECDiffieHellman ()
+		{
+			CngAlgorithmGroup group = CngAlgorithmGroup.ECDiffieHellman;
+			Assert.AreEqual ("ECDH", group.AlgorithmGroup, "AlgorithmGroup");
+			Assert.IsTrue (group.Equals (CngAlgorithmGroup.ECDiffieHellman), "Equals(static)");
+			Assert.IsTrue (Object.ReferenceEquals (group, CngAlgorithmGroup.ECDiffieHellman), "ReferenceEquals");
+			Check (group);
+		}
+
+		[Test]
+		public void ECDsa ()
+		{
+			CngAlgorithmGroup group = CngAlgorithmGroup.ECDsa;
+			Assert.AreEqual ("ECDSA", group.AlgorithmGroup, "AlgorithmGroup");
+			Assert.IsTrue (group.Equals (CngAlgorithmGroup.ECDsa), "Equals(static)");
+			Assert.IsTrue (Object.ReferenceEquals (group, CngAlgorithmGroup.ECDsa), "ReferenceEquals");
+			Check (group);
+		}
+
+		[Test]
+		public void Rsa ()
+		{
+			CngAlgorithmGroup group = CngAlgorithmGroup.Rsa;
+			Assert.AreEqual ("RSA", group.AlgorithmGroup, "AlgorithmGroup");
+			Assert.IsTrue (group.Equals (CngAlgorithmGroup.Rsa), "Equals(static)");
+			Assert.IsTrue (Object.ReferenceEquals (group, CngAlgorithmGroup.Rsa), "ReferenceEquals");
+			Check (group);
+		}
+	}
+}

+ 210 - 0
mcs/class/System.Core/Test/System.Security.Cryptography/CngAlgorithmTest.cs

@@ -0,0 +1,210 @@
+//
+// Unit tests for System.Security.Cryptography.CngAlgorithm
+//
+// Authors:
+//	Sebastien Pouliot  <[email protected]>
+//
+// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Security.Cryptography;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Security.Cryptography {
+
+	[TestFixture]
+	public class CngAlgorithmTest {
+
+		[Test]
+		public void StaticProperties ()
+		{
+			Assert.IsNotNull (CngAlgorithm.ECDiffieHellmanP256, "ECDiffieHellmanP256");
+			Assert.IsNotNull (CngAlgorithm.ECDiffieHellmanP384, "ECDiffieHellmanP384");
+			Assert.IsNotNull (CngAlgorithm.ECDiffieHellmanP521, "ECDiffieHellmanP521");
+			Assert.IsNotNull (CngAlgorithm.ECDsaP256, "ECDsaP256");
+			Assert.IsNotNull (CngAlgorithm.ECDsaP384, "ECDsaP384");
+			Assert.IsNotNull (CngAlgorithm.ECDsaP521, "ECDsaP521");
+			Assert.IsNotNull (CngAlgorithm.MD5, "MD5");
+			Assert.IsNotNull (CngAlgorithm.Sha1, "Sha1");
+			Assert.IsNotNull (CngAlgorithm.Sha256, "Sha256");
+			Assert.IsNotNull (CngAlgorithm.Sha384, "Sha384");
+			Assert.IsNotNull (CngAlgorithm.Sha512, "Sha512");
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void ConstructorNull ()
+		{
+			new CngAlgorithm (null);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentException))]
+		public void ConstructorEmpty ()
+		{
+			new CngAlgorithm (String.Empty);
+		}
+
+		static CngAlgorithm mono = new CngAlgorithm ("mono");
+
+		private void Check (CngAlgorithm algo)
+		{
+			Assert.AreEqual (algo.Algorithm, algo.ToString (), "Algorithm/ToString");
+			Assert.AreEqual (algo.GetHashCode (), algo.Algorithm.GetHashCode (), "GetHashCode");
+			Assert.IsTrue (algo.Equals (algo), "Equals(self)");
+			Assert.IsTrue (algo.Equals ((object)algo), "Equals((object)self)");
+
+			CngAlgorithm copy = new CngAlgorithm (algo.Algorithm);
+			Assert.AreEqual (algo.GetHashCode (), copy.GetHashCode (), "Copy");
+			Assert.IsTrue (algo.Equals (copy), "Equals(copy)");
+			Assert.IsTrue (algo.Equals ((object)copy), "Equals((object)copy)");
+			Assert.IsTrue (algo == copy, "algo==copy");
+			Assert.IsFalse (algo != copy, "algo!=copy");
+
+			Assert.IsFalse (algo.Equals (mono), "Equals(mono)");
+			Assert.IsFalse (algo.Equals ((object)mono), "Equals((object)mono)");
+			Assert.IsFalse (algo == mono, "algo==mono");
+			Assert.IsTrue (algo != mono, "algo!=mono");
+		}
+
+		[Test]
+		public void ConstructorCustom ()
+		{
+			CngAlgorithm algo = new CngAlgorithm ("custom");
+			Check (algo);
+			Assert.IsFalse (algo.Equals ((CngAlgorithm) null), "Equals((CngAlgorithm)null)");
+			Assert.IsFalse (algo.Equals ((object) null), "Equals((object)null)");
+		}
+
+		[Test]
+		public void ECDiffieHellmanP256 ()
+		{
+			CngAlgorithm algo = CngAlgorithm.ECDiffieHellmanP256;
+			Assert.AreEqual ("ECDH_P256", algo.Algorithm, "Algorithm");
+			Assert.IsTrue (algo.Equals (CngAlgorithm.ECDiffieHellmanP256), "Equals(static)");
+			Assert.IsTrue (Object.ReferenceEquals (algo, CngAlgorithm.ECDiffieHellmanP256), "ReferenceEquals");
+			Check (algo);
+		}
+
+		[Test]
+		public void ECDiffieHellmanP384 ()
+		{
+			CngAlgorithm algo = CngAlgorithm.ECDiffieHellmanP384;
+			Assert.AreEqual ("ECDH_P384", algo.Algorithm, "Algorithm");
+			Assert.IsTrue (algo.Equals (CngAlgorithm.ECDiffieHellmanP384), "Equals(static)");
+			Assert.IsTrue (Object.ReferenceEquals (algo, CngAlgorithm.ECDiffieHellmanP384), "ReferenceEquals");
+			Check (algo);
+		}
+
+		[Test]
+		public void ECDiffieHellmanP521 ()
+		{
+			CngAlgorithm algo = CngAlgorithm.ECDiffieHellmanP521;
+			Assert.AreEqual ("ECDH_P521", algo.Algorithm, "Algorithm");
+			Assert.IsTrue (algo.Equals (CngAlgorithm.ECDiffieHellmanP521), "Equals(static)");
+			Assert.IsTrue (Object.ReferenceEquals (algo, CngAlgorithm.ECDiffieHellmanP521), "ReferenceEquals");
+			Check (algo);
+		}
+
+		[Test]
+		public void ECDsaP256 ()
+		{
+			CngAlgorithm algo = CngAlgorithm.ECDsaP256;
+			Assert.AreEqual ("ECDSA_P256", algo.Algorithm, "Algorithm");
+			Assert.IsTrue (algo.Equals (CngAlgorithm.ECDsaP256), "Equals(static)");
+			Assert.IsTrue (Object.ReferenceEquals (algo, CngAlgorithm.ECDsaP256), "ReferenceEquals");
+			Check (algo);
+		}
+
+		[Test]
+		public void ECDsaP384 ()
+		{
+			CngAlgorithm algo = CngAlgorithm.ECDsaP384;
+			Assert.AreEqual ("ECDSA_P384", algo.Algorithm, "Algorithm");
+			Assert.IsTrue (algo.Equals (CngAlgorithm.ECDsaP384), "Equals(static)");
+			Assert.IsTrue (Object.ReferenceEquals (algo, CngAlgorithm.ECDsaP384), "ReferenceEquals");
+			Check (algo);
+		}
+
+		[Test]
+		public void ECDsaP521 ()
+		{
+			CngAlgorithm algo = CngAlgorithm.ECDsaP521;
+			Assert.AreEqual ("ECDSA_P521", algo.Algorithm, "Algorithm");
+			Assert.IsTrue (algo.Equals (CngAlgorithm.ECDsaP521), "Equals(static)");
+			Assert.IsTrue (Object.ReferenceEquals (algo, CngAlgorithm.ECDsaP521), "ReferenceEquals");
+			Check (algo);
+		}
+
+		[Test]
+		public void MD5 ()
+		{
+			CngAlgorithm algo = CngAlgorithm.MD5;
+			Assert.AreEqual ("MD5", algo.Algorithm, "Algorithm");
+			Assert.IsTrue (algo.Equals (CngAlgorithm.MD5), "Equals(static)");
+			Assert.IsTrue (Object.ReferenceEquals (algo, CngAlgorithm.MD5), "ReferenceEquals");
+			Check (algo);
+		}
+
+		[Test]
+		public void Sha1 ()
+		{
+			CngAlgorithm algo = CngAlgorithm.Sha1;
+			Assert.AreEqual ("SHA1", algo.Algorithm, "Algorithm");
+			Assert.IsTrue (algo.Equals (CngAlgorithm.Sha1), "Equals(static)");
+			Assert.IsTrue (Object.ReferenceEquals (algo, CngAlgorithm.Sha1), "ReferenceEquals");
+			Check (algo);
+		}
+
+		[Test]
+		public void Sha256 ()
+		{
+			CngAlgorithm algo = CngAlgorithm.Sha256;
+			Assert.AreEqual ("SHA256", algo.Algorithm, "Algorithm");
+			Assert.IsTrue (algo.Equals (CngAlgorithm.Sha256), "Equals(static)");
+			Assert.IsTrue (Object.ReferenceEquals (algo, CngAlgorithm.Sha256), "ReferenceEquals");
+			Check (algo);
+		}
+
+		[Test]
+		public void Sha384 ()
+		{
+			CngAlgorithm algo = CngAlgorithm.Sha384;
+			Assert.AreEqual ("SHA384", algo.Algorithm, "Algorithm");
+			Assert.IsTrue (algo.Equals (CngAlgorithm.Sha384), "Equals(static)");
+			Assert.IsTrue (Object.ReferenceEquals (algo, CngAlgorithm.Sha384), "ReferenceEquals");
+			Check (algo);
+		}
+
+		[Test]
+		public void Sha512 ()
+		{
+			CngAlgorithm algo = CngAlgorithm.Sha512;
+			Assert.AreEqual ("SHA512", algo.Algorithm, "Algorithm");
+			Assert.IsTrue (algo.Equals (CngAlgorithm.Sha512), "Equals(static)");
+			Assert.IsTrue (Object.ReferenceEquals (algo, CngAlgorithm.Sha512), "ReferenceEquals");
+			Check (algo);
+		}
+	}
+}

+ 73 - 0
mcs/class/System.Core/Test/System.Security.Cryptography/MD5CngTest.cs

@@ -0,0 +1,73 @@
+//
+// MD5Test.cs - NUnit Test Cases for System.Security.Cryptography.MD5
+// 
+// Authors
+//	Eduardo Garcia Cebollero ([email protected])
+//	Sebastien Pouliot  <[email protected]>
+//
+// (C)  Eduardo Garcia Cebollero.
+// (C)  Ximian, Inc.  http://www.ximian.com
+// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
+//
+
+using NUnit.Framework;
+using System;
+using System.Security.Cryptography;
+
+namespace MonoTests.System.Security.Cryptography {
+
+	[TestFixture]
+	public class MD5Test : Assertion {
+
+		private MD5 md5;
+
+		[SetUp]
+		public void SetUp ()
+		{
+			md5 = new MD5Cng ();
+		}
+
+		[Test]
+		public void ComputeHashNull () 
+		{
+			byte [] dato_vacio = {};
+			string MD5_dato_vacio = "d41d8cd98f00b204e9800998ecf8427e";
+
+			string result_str = "";
+			
+			byte [] result = md5.ComputeHash (dato_vacio);
+			
+			foreach(byte i in result)
+				result_str += Convert.ToInt32 (i).ToString ("x2");
+
+			AssertEquals ("#01 MD5 Of {} is wrong", result_str, MD5_dato_vacio);
+		}
+
+		[Test]
+		public void ComputeHashA ()
+		{
+			byte [] dato_a = { Convert.ToByte ('a') };
+			string MD5_dato_a = "0cc175b9c0f1b6a831c399e269772661";
+			string result_str = "";
+			byte [] result = md5.ComputeHash (dato_a);
+			foreach (byte i in result)
+				result_str += Convert.ToInt32 (i).ToString ("x2");
+
+			AssertEquals ("#02 MD5 Of 'a' is wrong", result_str, MD5_dato_a);
+		}
+
+		[Test]
+		public void ComputeHashB ()
+		{
+			byte[] dato_b = { Convert.ToByte ('\u00F1') };
+			string MD5_dato_b = "edb907361219fb8d50279eabab0b83b1";
+			string result_str = "";
+
+			byte[] result = md5.ComputeHash (dato_b);
+			foreach(byte i in result)
+				result_str += Convert.ToInt32 (i).ToString ("x2");
+
+			AssertEquals ("#03 MD5 Of '\u00F1' is wrong", result_str, MD5_dato_b);
+		}
+	}
+}

+ 63 - 0
mcs/class/System.Core/Test/System.Security.Cryptography/SHA1CngTest.cs

@@ -0,0 +1,63 @@
+//
+// SHA1CngTest.cs - NUnit Test Cases for SHA1Cng
+//
+// Author:
+//	Sebastien Pouliot  <[email protected]>
+//
+// (C) 2002 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004, 2007 Novell, Inc (http://www.novell.com)
+//
+
+using NUnit.Framework;
+using System;
+using System.Security.Cryptography;
+using System.Text;
+
+namespace MonoTests.System.Security.Cryptography {
+
+	// References:
+	// a.	FIPS PUB 180-1: Secure Hash Standard
+	//	http://csrc.nist.gov/publications/fips/fips180-1/fip180-1.txt
+
+	// we inherit from SHA1Test because all SHA1 implementation must return the 
+	// same results (hence should run a common set of unit tests).
+
+	[TestFixture]
+	public class SHA1CngTest : SHA1Test {
+
+		[SetUp]
+		protected override void SetUp ()
+		{
+			hash = new SHA1Cng ();
+		}
+
+		[Test]
+		public override void Create ()
+		{
+			// no need to repeat this test
+		}
+
+		// none of those values changes for a particuliar implementation of SHA1
+		[Test]
+		public override void StaticInfo ()
+		{
+			// test all values static for SHA1
+			base.StaticInfo ();
+			string className = hash.ToString ();
+			Assert.IsTrue (hash.CanReuseTransform, className + ".CanReuseTransform");
+			Assert.IsTrue (hash.CanTransformMultipleBlocks, className + ".CanTransformMultipleBlocks");
+			Assert.AreEqual ("System.Security.Cryptography.SHA1Cng", className, className + ".ToString()");
+		}
+
+		public void TestSHA1CSPforFIPSCompliance ()
+		{
+			SHA1 sha = (SHA1) hash;
+			// First test, we hash the string "abc"
+			FIPS186_Test1 (sha);
+			// Second test, we hash the string "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
+			FIPS186_Test2 (sha);
+			// Third test, we hash 1,000,000 times the character "a"
+			FIPS186_Test3 (sha);
+		}
+	}
+}

+ 76 - 0
mcs/class/System.Core/Test/System.Security.Cryptography/SHA256CngTest.cs

@@ -0,0 +1,76 @@
+//
+// SHA256CngTest.cs - NUnit Test Cases for SHA256Cng
+//
+// Author:
+//	Sebastien Pouliot  <[email protected]>
+//
+// (C) 2002 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004, 2007-2008 Novell, Inc (http://www.novell.com)
+//
+
+using NUnit.Framework;
+using System;
+using System.Security.Cryptography;
+using System.Text;
+
+namespace MonoTests.System.Security.Cryptography {
+
+	// References:
+	// a.	FIPS PUB 180-2: Secure Hash Standard
+	//	http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
+
+	// we inherit from SHA256Test because all SHA256 implementation must return the 
+	// same results (hence should run a common set of unit tests).
+
+	[TestFixture]
+	public class SHA256CngTest : SHA256Test {
+
+		[SetUp]
+		protected override void SetUp ()
+		{
+			hash = new SHA256Cng ();
+		}
+
+		[Test]
+		public override void Create ()
+		{
+			// no need to repeat this test
+		}
+
+		// none of those values changes for a particuliar implementation of SHA256
+		[Test]
+		public override void StaticInfo ()
+		{
+			// test all values static for SHA256
+			base.StaticInfo ();
+			string className = hash.ToString ();
+			Assert.IsTrue (hash.CanReuseTransform, className + ".CanReuseTransform");
+			Assert.IsTrue (hash.CanTransformMultipleBlocks, className + ".CanTransformMultipleBlocks");
+			Assert.AreEqual ("System.Security.Cryptography.SHA256Cng", className, className + ".ToString()");
+		}
+
+		[Test]
+		public void FIPSCompliance_Test1 ()
+		{
+			SHA256 sha = (SHA256) hash;
+			// First test, we hash the string "abc"
+			FIPS186_Test1 (sha);
+		}
+
+		[Test]
+		public void FIPSCompliance_Test2 ()
+		{
+			SHA256 sha = (SHA256) hash;
+			// Second test, we hash the string "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
+			FIPS186_Test2 (sha);
+		}
+
+		[Test]
+		public void FIPSCompliance_Test3 ()
+		{
+			SHA256 sha = (SHA256) hash;
+			// Third test, we hash 1,000,000 times the character "a"
+			FIPS186_Test3 (sha);
+		}
+	}
+}

+ 76 - 0
mcs/class/System.Core/Test/System.Security.Cryptography/SHA256CryptoServiceProviderTest.cs

@@ -0,0 +1,76 @@
+//
+// SHA256CryptoServiceProviderTest.cs - NUnit Test Cases for SHA256CryptoServiceProvider
+//
+// Author:
+//	Sebastien Pouliot  <[email protected]>
+//
+// (C) 2002 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004, 2007-2008 Novell, Inc (http://www.novell.com)
+//
+
+using NUnit.Framework;
+using System;
+using System.Security.Cryptography;
+using System.Text;
+
+namespace MonoTests.System.Security.Cryptography {
+
+	// References:
+	// a.	FIPS PUB 180-2: Secure Hash Standard
+	//	http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
+
+	// we inherit from SHA256Test because all SHA256 implementation must return the 
+	// same results (hence should run a common set of unit tests).
+
+	[TestFixture]
+	public class SHA256CryptoServiceProviderTest : SHA256Test {
+
+		[SetUp]
+		protected override void SetUp ()
+		{
+			hash = new SHA256CryptoServiceProvider ();
+		}
+
+		[Test]
+		public override void Create ()
+		{
+			// no need to repeat this test
+		}
+
+		// none of those values changes for a particuliar implementation of SHA256
+		[Test]
+		public override void StaticInfo ()
+		{
+			// test all values static for SHA256
+			base.StaticInfo ();
+			string className = hash.ToString ();
+			Assert.IsTrue (hash.CanReuseTransform, className + ".CanReuseTransform");
+			Assert.IsTrue (hash.CanTransformMultipleBlocks, className + ".CanTransformMultipleBlocks");
+			Assert.AreEqual ("System.Security.Cryptography.SHA256CryptoServiceProvider", className, className + ".ToString()");
+		}
+
+		[Test]
+		public void FIPSCompliance_Test1 ()
+		{
+			SHA256 sha = (SHA256) hash;
+			// First test, we hash the string "abc"
+			FIPS186_Test1 (sha);
+		}
+
+		[Test]
+		public void FIPSCompliance_Test2 ()
+		{
+			SHA256 sha = (SHA256) hash;
+			// Second test, we hash the string "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
+			FIPS186_Test2 (sha);
+		}
+
+		[Test]
+		public void FIPSCompliance_Test3 ()
+		{
+			SHA256 sha = (SHA256) hash;
+			// Third test, we hash 1,000,000 times the character "a"
+			FIPS186_Test3 (sha);
+		}
+	}
+}

+ 76 - 0
mcs/class/System.Core/Test/System.Security.Cryptography/SHA384CngTest.cs

@@ -0,0 +1,76 @@
+//
+// SHA384CngTest.cs - NUnit Test Cases for SHA384Cng
+//
+// Author:
+//	Sebastien Pouliot  <[email protected]>
+//
+// (C) 2002 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004, 2007-2008 Novell, Inc (http://www.novell.com)
+//
+
+using NUnit.Framework;
+using System;
+using System.Security.Cryptography;
+using System.Text;
+
+namespace MonoTests.System.Security.Cryptography {
+
+	// References:
+	// a.	FIPS PUB 180-2: Secure Hash Standard
+	//	http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
+
+	// we inherit from SHA384Test because all SHA384 implementation must return the 
+	// same results (hence should run a common set of unit tests).
+
+	[TestFixture]
+	public class SHA384CngTest : SHA384Test {
+
+		[SetUp]
+		protected override void SetUp ()
+		{
+			hash = new SHA384Cng ();
+		}
+
+		[Test]
+		public override void Create ()
+		{
+			// no need to repeat this test
+		}
+
+		// none of those values changes for a particuliar implementation of SHA384
+		[Test]
+		public override void StaticInfo ()
+		{
+			// test all values static for SHA384
+			base.StaticInfo ();
+			string className = hash.ToString ();
+			Assert.IsTrue (hash.CanReuseTransform, className + ".CanReuseTransform");
+			Assert.IsTrue (hash.CanTransformMultipleBlocks, className + ".CanTransformMultipleBlocks");
+			Assert.AreEqual ("System.Security.Cryptography.SHA384Cng", className, className + ".ToString()");
+		}
+
+		[Test]
+		public void FIPSCompliance_Test1 ()
+		{
+			SHA384 sha = (SHA384) hash;
+			// First test, we hash the string "abc"
+			FIPS186_Test1 (sha);
+		}
+
+		[Test]
+		public void FIPSCompliance_Test2 ()
+		{
+			SHA384 sha = (SHA384) hash;
+			// Second test, we hash the string "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
+			FIPS186_Test2 (sha);
+		}
+
+		[Test]
+		public void FIPSCompliance_Test3 ()
+		{
+			SHA384 sha = (SHA384) hash;
+			// Third test, we hash 1,000,000 times the character "a"
+			FIPS186_Test3 (sha);
+		}
+	}
+}

+ 76 - 0
mcs/class/System.Core/Test/System.Security.Cryptography/SHA384CryptoServiceProviderTest.cs

@@ -0,0 +1,76 @@
+//
+// SHA384CryptoServiceProviderTest.cs - NUnit Test Cases for SHA384CryptoServiceProvider
+//
+// Author:
+//	Sebastien Pouliot  <[email protected]>
+//
+// (C) 2002 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004, 2007-2008 Novell, Inc (http://www.novell.com)
+//
+
+using NUnit.Framework;
+using System;
+using System.Security.Cryptography;
+using System.Text;
+
+namespace MonoTests.System.Security.Cryptography {
+
+	// References:
+	// a.	FIPS PUB 180-2: Secure Hash Standard
+	//	http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
+
+	// we inherit from SHA384Test because all SHA384 implementation must return the 
+	// same results (hence should run a common set of unit tests).
+
+	[TestFixture]
+	public class SHA384CryptoServiceProviderTest : SHA384Test {
+
+		[SetUp]
+		protected override void SetUp ()
+		{
+			hash = new SHA384CryptoServiceProvider ();
+		}
+
+		[Test]
+		public override void Create ()
+		{
+			// no need to repeat this test
+		}
+
+		// none of those values changes for a particuliar implementation of SHA384
+		[Test]
+		public override void StaticInfo ()
+		{
+			// test all values static for SHA384
+			base.StaticInfo ();
+			string className = hash.ToString ();
+			Assert.IsTrue (hash.CanReuseTransform, className + ".CanReuseTransform");
+			Assert.IsTrue (hash.CanTransformMultipleBlocks, className + ".CanTransformMultipleBlocks");
+			Assert.AreEqual ("System.Security.Cryptography.SHA384CryptoServiceProvider", className, className + ".ToString()");
+		}
+
+		[Test]
+		public void FIPSCompliance_Test1 ()
+		{
+			SHA384 sha = (SHA384) hash;
+			// First test, we hash the string "abc"
+			FIPS186_Test1 (sha);
+		}
+
+		[Test]
+		public void FIPSCompliance_Test2 ()
+		{
+			SHA384 sha = (SHA384) hash;
+			// Second test, we hash the string "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
+			FIPS186_Test2 (sha);
+		}
+
+		[Test]
+		public void FIPSCompliance_Test3 ()
+		{
+			SHA384 sha = (SHA384) hash;
+			// Third test, we hash 1,000,000 times the character "a"
+			FIPS186_Test3 (sha);
+		}
+	}
+}

+ 76 - 0
mcs/class/System.Core/Test/System.Security.Cryptography/SHA512CngTest.cs

@@ -0,0 +1,76 @@
+//
+// SHA512CngTest.cs - NUnit Test Cases for SHA512Cng
+//
+// Author:
+//	Sebastien Pouliot  <[email protected]>
+//
+// (C) 2002 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004, 2007-2008 Novell, Inc (http://www.novell.com)
+//
+
+using NUnit.Framework;
+using System;
+using System.Security.Cryptography;
+using System.Text;
+
+namespace MonoTests.System.Security.Cryptography {
+
+	// References:
+	// a.	FIPS PUB 180-2: Secure Hash Standard
+	//	http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
+
+	// we inherit from SHA512Test because all SHA512 implementation must return the 
+	// same results (hence should run a common set of unit tests).
+
+	[TestFixture]
+	public class SHA512CngTest : SHA512Test {
+
+		[SetUp]
+		protected override void SetUp ()
+		{
+			hash = new SHA512Cng ();
+		}
+
+		[Test]
+		public override void Create ()
+		{
+			// no need to repeat this test
+		}
+
+		// none of those values changes for a particuliar implementation of SHA512
+		[Test]
+		public override void StaticInfo ()
+		{
+			// test all values static for SHA512
+			base.StaticInfo ();
+			string className = hash.ToString ();
+			Assert.IsTrue (hash.CanReuseTransform, className + ".CanReuseTransform");
+			Assert.IsTrue (hash.CanTransformMultipleBlocks, className + ".CanTransformMultipleBlocks");
+			Assert.AreEqual ("System.Security.Cryptography.SHA512Cng", className, className + ".ToString()");
+		}
+
+		[Test]
+		public void FIPSCompliance_Test1 ()
+		{
+			SHA512 sha = (SHA512) hash;
+			// First test, we hash the string "abc"
+			FIPS186_Test1 (sha);
+		}
+
+		[Test]
+		public void FIPSCompliance_Test2 ()
+		{
+			SHA512 sha = (SHA512) hash;
+			// Second test, we hash the string "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
+			FIPS186_Test2 (sha);
+		}
+
+		[Test]
+		public void FIPSCompliance_Test3 ()
+		{
+			SHA512 sha = (SHA512) hash;
+			// Third test, we hash 1,000,000 times the character "a"
+			FIPS186_Test3 (sha);
+		}
+	}
+}

+ 76 - 0
mcs/class/System.Core/Test/System.Security.Cryptography/SHA512CryptoServiceProviderTest.cs

@@ -0,0 +1,76 @@
+//
+// SHA512CryptoServiceProviderTest.cs - NUnit Test Cases for SHA512CryptoServiceProvider
+//
+// Author:
+//	Sebastien Pouliot  <[email protected]>
+//
+// (C) 2002 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004, 2007-2008 Novell, Inc (http://www.novell.com)
+//
+
+using NUnit.Framework;
+using System;
+using System.Security.Cryptography;
+using System.Text;
+
+namespace MonoTests.System.Security.Cryptography {
+
+	// References:
+	// a.	FIPS PUB 180-2: Secure Hash Standard
+	//	http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
+
+	// we inherit from SHA512Test because all SHA512 implementation must return the 
+	// same results (hence should run a common set of unit tests).
+
+	[TestFixture]
+	public class SHA512CryptoServiceProviderTest : SHA512Test {
+
+		[SetUp]
+		protected override void SetUp ()
+		{
+			hash = new SHA512CryptoServiceProvider ();
+		}
+
+		[Test]
+		public override void Create ()
+		{
+			// no need to repeat this test
+		}
+
+		// none of those values changes for a particuliar implementation of SHA512
+		[Test]
+		public override void StaticInfo ()
+		{
+			// test all values static for SHA512
+			base.StaticInfo ();
+			string className = hash.ToString ();
+			Assert.IsTrue (hash.CanReuseTransform, className + ".CanReuseTransform");
+			Assert.IsTrue (hash.CanTransformMultipleBlocks, className + ".CanTransformMultipleBlocks");
+			Assert.AreEqual ("System.Security.Cryptography.SHA512CryptoServiceProvider", className, className + ".ToString()");
+		}
+
+		[Test]
+		public void FIPSCompliance_Test1 ()
+		{
+			SHA512 sha = (SHA512) hash;
+			// First test, we hash the string "abc"
+			FIPS186_Test1 (sha);
+		}
+
+		[Test]
+		public void FIPSCompliance_Test2 ()
+		{
+			SHA512 sha = (SHA512) hash;
+			// Second test, we hash the string "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
+			FIPS186_Test2 (sha);
+		}
+
+		[Test]
+		public void FIPSCompliance_Test3 ()
+		{
+			SHA512 sha = (SHA512) hash;
+			// Third test, we hash 1,000,000 times the character "a"
+			FIPS186_Test3 (sha);
+		}
+	}
+}