SHA256ManagedTest.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // SHA256ManagedTest.cs - NUnit Test Cases for SHA256Managed
  3. //
  4. // Author:
  5. // Sebastien Pouliot ([email protected])
  6. //
  7. // (C) 2002 Motus Technologies Inc. (http://www.motus.com)
  8. //
  9. using NUnit.Framework;
  10. using System;
  11. using System.Security.Cryptography;
  12. using System.Text;
  13. namespace MonoTests.System.Security.Cryptography {
  14. // References:
  15. // a. FIPS PUB 180-2: Secure Hash Standard
  16. // http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
  17. // we inherit from SHA256Test because all SHA256 implementation must return the
  18. // same results (hence should run a common set of unit tests).
  19. public class SHA256ManagedTest : SHA256Test {
  20. protected override void SetUp ()
  21. {
  22. hash = new SHA256Managed ();
  23. }
  24. protected override void TearDown () {}
  25. public override void TestCreate ()
  26. {
  27. // no need to repeat this test
  28. }
  29. // none of those values changes for a particuliar implementation of SHA256
  30. public override void TestStaticInfo ()
  31. {
  32. // test all values static for SHA256
  33. base.TestStaticInfo ();
  34. string className = hash.ToString ();
  35. AssertEquals (className + ".CanReuseTransform", true, hash.CanReuseTransform);
  36. AssertEquals (className + ".CanTransformMultipleBlocks", true, hash.CanTransformMultipleBlocks);
  37. AssertEquals (className + ".ToString()", "System.Security.Cryptography.SHA256Managed", className);
  38. }
  39. public void TestSHA256forFIPSCompliance ()
  40. {
  41. SHA256 sha = (SHA256) hash;
  42. // First test, we hash the string "abc"
  43. FIPS186_Test1 (sha);
  44. // Second test, we hash the string "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
  45. FIPS186_Test2 (sha);
  46. // Third test, we hash 1,000,000 times the character "a"
  47. FIPS186_Test3 (sha);
  48. }
  49. }
  50. }