2
0

SHA256CryptoServiceProviderTest.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // SHA256CryptoServiceProviderTest.cs - NUnit Test Cases for SHA256CryptoServiceProvider
  3. //
  4. // Author:
  5. // Sebastien Pouliot <[email protected]>
  6. //
  7. // (C) 2002 Motus Technologies Inc. (http://www.motus.com)
  8. // Copyright (C) 2004, 2007-2008 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-2: Secure Hash Standard
  17. // http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
  18. // we inherit from SHA256Test because all SHA256 implementation must return the
  19. // same results (hence should run a common set of unit tests).
  20. [TestFixture]
  21. public class SHA256CryptoServiceProviderTest : SHA256Test {
  22. [SetUp]
  23. protected override void SetUp ()
  24. {
  25. hash = new SHA256CryptoServiceProvider ();
  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 SHA256
  33. [Test]
  34. public override void StaticInfo ()
  35. {
  36. // test all values static for SHA256
  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.SHA256CryptoServiceProvider", className, className + ".ToString()");
  42. }
  43. [Test]
  44. public void FIPSCompliance_Test1 ()
  45. {
  46. SHA256 sha = (SHA256) hash;
  47. // First test, we hash the string "abc"
  48. FIPS186_Test1 (sha);
  49. }
  50. [Test]
  51. public void FIPSCompliance_Test2 ()
  52. {
  53. SHA256 sha = (SHA256) hash;
  54. // Second test, we hash the string "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
  55. FIPS186_Test2 (sha);
  56. }
  57. [Test]
  58. public void FIPSCompliance_Test3 ()
  59. {
  60. SHA256 sha = (SHA256) hash;
  61. // Third test, we hash 1,000,000 times the character "a"
  62. FIPS186_Test3 (sha);
  63. }
  64. }
  65. }