SHA512CngTest.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // SHA512CngTest.cs - NUnit Test Cases for SHA512Cng
  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. #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-2: Secure Hash Standard
  18. // http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
  19. // we inherit from SHA512Test because all SHA512 implementation must return the
  20. // same results (hence should run a common set of unit tests).
  21. [TestFixture]
  22. public class SHA512CngTest : SHA512Test {
  23. [SetUp]
  24. public override void SetUp ()
  25. {
  26. hash = new SHA512Cng ();
  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 SHA512
  34. [Test]
  35. public override void StaticInfo ()
  36. {
  37. // test all values static for SHA512
  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.SHA512Cng", className, className + ".ToString()");
  43. }
  44. [Test]
  45. public void FIPSCompliance_Test1 ()
  46. {
  47. SHA512 sha = (SHA512) hash;
  48. // First test, we hash the string "abc"
  49. FIPS186_Test1 (sha);
  50. }
  51. [Test]
  52. public void FIPSCompliance_Test2 ()
  53. {
  54. SHA512 sha = (SHA512) hash;
  55. // Second test, we hash the string "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
  56. FIPS186_Test2 (sha);
  57. }
  58. [Test]
  59. public void FIPSCompliance_Test3 ()
  60. {
  61. SHA512 sha = (SHA512) hash;
  62. // Third test, we hash 1,000,000 times the character "a"
  63. FIPS186_Test3 (sha);
  64. }
  65. }
  66. }
  67. #endif