SHA384Test.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // System.Security.Cryptography.Test SHA384 NUnit test classes.
  3. //
  4. // Author:
  5. // Matthew S. Ford ([email protected])
  6. //
  7. // Copyright 2001 by Matthew S. Ford.
  8. //
  9. using NUnit.Framework;
  10. using System;
  11. using System.Security.Cryptography;
  12. using System.Text;
  13. namespace System.Security.Cryptography.Test {
  14. public class SHA384HashingTest : TestCase {
  15. byte[] _dataToHash;
  16. byte[] _expectedHash;
  17. public SHA384HashingTest (string name, byte[] dataToHash, byte[] expectedHash) : base(name) {
  18. _dataToHash = dataToHash;
  19. _expectedHash = expectedHash;
  20. }
  21. public static bool ArrayEquals (byte[] arr1, byte[] arr2) {
  22. int i;
  23. if (arr1.GetLength(0) != arr2.GetLength(0))
  24. return false;
  25. for (i=0; i<arr1.GetLength(0); i++) {
  26. if (arr1[i] != arr2[i])
  27. return false;
  28. }
  29. return true;
  30. }
  31. protected override void RunTest () {
  32. SHA384 sha = new SHA384Managed ();
  33. byte[] hash;
  34. hash = sha.ComputeHash (_dataToHash);
  35. Assert (ArrayEquals (hash, _expectedHash));
  36. }
  37. }
  38. public class SHA384TestSet {
  39. public SHA384TestSet () {
  40. }
  41. public static void Main () {
  42. }
  43. public static ITest Suite {
  44. get {
  45. TestSuite suite = new TestSuite ();
  46. byte[] hash0 = {0xCB, 0x00, 0x75, 0x3F, 0x45, 0xA3, 0x5E, 0x8B, 0xB5, 0xA0, 0x3D, 0x69, 0x9A, 0xC6, 0x50, 0x07, 0x27, 0x2C, 0x32, 0xAB, 0x0E, 0xDE, 0xD1, 0x63, 0x1A, 0x8B, 0x60, 0x5A, 0x43, 0xFF, 0x5B, 0xED, 0x80, 0x86, 0x07, 0x2B, 0xA1, 0xE7, 0xCC, 0x23, 0x58, 0xBA, 0xEC, 0xA1, 0x34, 0xC8, 0x25, 0xA7};
  47. suite.AddTest (new SHA384HashingTest ("abc", Encoding.UTF8.GetBytes("abc"), hash0));
  48. byte[] hash1 = {0x09, 0x33, 0x0C, 0x33, 0xF7, 0x11, 0x47, 0xE8, 0x3D, 0x19, 0x2F, 0xC7, 0x82, 0xCD, 0x1B, 0x47, 0x53, 0x11, 0x1B, 0x17, 0x3B, 0x3B, 0x05, 0xD2, 0x2F, 0xA0, 0x80, 0x86, 0xE3, 0xB0, 0xF7, 0x12, 0xFC, 0xC7, 0xC7, 0x1A, 0x55, 0x7E, 0x2D, 0xB9, 0x66, 0xC3, 0xE9, 0xFA, 0x91, 0x74, 0x60, 0x39};
  49. suite.AddTest (new SHA384HashingTest ("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", Encoding.UTF8.GetBytes("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"), hash1));
  50. //byte[] hash2 = {};
  51. //suite.AddTest (new SHA384HashingTest ("abc", Encoding.UTF8.GetBytes("abc"), hash2));
  52. //byte[] hash3 = {};
  53. //suite.AddTest (new SHA384HashingTest ("abcdefghijklmnopqrstuvwxyz", Encoding.UTF8.GetBytes("abcdefghijklmnopqrstuvwxyz"), hash3));
  54. //byte[] hash4 = {};
  55. //suite.AddTest (new SHA384HashingTest ("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", Encoding.UTF8.GetBytes("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"), hash4));
  56. return suite;
  57. }
  58. }
  59. }
  60. }