SHA1CngTest.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // SHA1CngTest.cs - NUnit Test Cases for SHA1Cng
  3. //
  4. // Author:
  5. // Sebastien Pouliot <[email protected]>
  6. //
  7. // (C) 2002 Motus Technologies Inc. (http://www.motus.com)
  8. // Copyright (C) 2004, 2007 Novell, Inc (http://www.novell.com)
  9. //
  10. #if !MOBILE
  11. using NUnit.Framework;
  12. using System;
  13. using System.Security.Cryptography;
  14. using System.Text;
  15. namespace MonoTests.System.Security.Cryptography {
  16. // References:
  17. // a. FIPS PUB 180-1: Secure Hash Standard
  18. // http://csrc.nist.gov/publications/fips/fips180-1/fip180-1.txt
  19. // we inherit from SHA1Test because all SHA1 implementation must return the
  20. // same results (hence should run a common set of unit tests).
  21. [TestFixture]
  22. public class SHA1CngTest : SHA1Test {
  23. [SetUp]
  24. public override void SetUp ()
  25. {
  26. hash = new SHA1Cng ();
  27. }
  28. [Test]
  29. public override void Create ()
  30. {
  31. // no need to repeat this test
  32. }
  33. // none of those values changes for a particuliar implementation of SHA1
  34. [Test]
  35. public override void StaticInfo ()
  36. {
  37. // test all values static for SHA1
  38. base.StaticInfo ();
  39. string className = hash.ToString ();
  40. Assert.IsTrue (hash.CanReuseTransform, className + ".CanReuseTransform");
  41. Assert.IsTrue (hash.CanTransformMultipleBlocks, className + ".CanTransformMultipleBlocks");
  42. Assert.AreEqual ("System.Security.Cryptography.SHA1Cng", className, className + ".ToString()");
  43. }
  44. public void TestSHA1CSPforFIPSCompliance ()
  45. {
  46. SHA1 sha = (SHA1) hash;
  47. // First test, we hash the string "abc"
  48. FIPS186_Test1 (sha);
  49. // Second test, we hash the string "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
  50. FIPS186_Test2 (sha);
  51. // Third test, we hash 1,000,000 times the character "a"
  52. FIPS186_Test3 (sha);
  53. }
  54. }
  55. }
  56. #endif