SHA1CngTest.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. using NUnit.Framework;
  11. using System;
  12. using System.Security.Cryptography;
  13. using System.Text;
  14. namespace MonoTests.System.Security.Cryptography {
  15. // References:
  16. // a. FIPS PUB 180-1: Secure Hash Standard
  17. // http://csrc.nist.gov/publications/fips/fips180-1/fip180-1.txt
  18. // we inherit from SHA1Test because all SHA1 implementation must return the
  19. // same results (hence should run a common set of unit tests).
  20. [TestFixture]
  21. public class SHA1CngTest : SHA1Test {
  22. [SetUp]
  23. protected override void SetUp ()
  24. {
  25. hash = new SHA1Cng ();
  26. }
  27. [Test]
  28. public override void Create ()
  29. {
  30. // no need to repeat this test
  31. }
  32. // none of those values changes for a particuliar implementation of SHA1
  33. [Test]
  34. public override void StaticInfo ()
  35. {
  36. // test all values static for SHA1
  37. base.StaticInfo ();
  38. string className = hash.ToString ();
  39. Assert.IsTrue (hash.CanReuseTransform, className + ".CanReuseTransform");
  40. Assert.IsTrue (hash.CanTransformMultipleBlocks, className + ".CanTransformMultipleBlocks");
  41. Assert.AreEqual ("System.Security.Cryptography.SHA1Cng", className, className + ".ToString()");
  42. }
  43. public void TestSHA1CSPforFIPSCompliance ()
  44. {
  45. SHA1 sha = (SHA1) hash;
  46. // First test, we hash the string "abc"
  47. FIPS186_Test1 (sha);
  48. // Second test, we hash the string "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
  49. FIPS186_Test2 (sha);
  50. // Third test, we hash 1,000,000 times the character "a"
  51. FIPS186_Test3 (sha);
  52. }
  53. }
  54. }