SHA384Hash.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. namespace Renci.SshNet.Security.Cryptography
  2. {
  3. public class SHA384Hash : SHA2HashBase
  4. {
  5. private const int DIGEST_SIZE = 48;
  6. /// <summary>
  7. /// Gets the size, in bits, of the computed hash code.
  8. /// </summary>
  9. /// <returns>The size, in bits, of the computed hash code.</returns>
  10. public override int HashSize
  11. {
  12. get
  13. {
  14. return DIGEST_SIZE * 8;
  15. }
  16. }
  17. /// <summary>
  18. /// When overridden in a derived class, gets the input block size.
  19. /// </summary>
  20. /// <returns>The input block size.</returns>
  21. public override int InputBlockSize
  22. {
  23. get
  24. {
  25. return DIGEST_SIZE * 2;
  26. }
  27. }
  28. /// <summary>
  29. /// When overridden in a derived class, gets the output block size.
  30. /// </summary>
  31. /// <returns>The output block size.</returns>
  32. public override int OutputBlockSize
  33. {
  34. get
  35. {
  36. return DIGEST_SIZE * 2;
  37. }
  38. }
  39. protected override byte[] HashFinal()
  40. {
  41. var output = new byte[DIGEST_SIZE];
  42. this.Finish();
  43. SHA2HashBase.UInt64_To_BE(H1, output, 0);
  44. SHA2HashBase.UInt64_To_BE(H2, output, 8);
  45. SHA2HashBase.UInt64_To_BE(H3, output, 16);
  46. SHA2HashBase.UInt64_To_BE(H4, output, 24);
  47. SHA2HashBase.UInt64_To_BE(H5, output, 32);
  48. SHA2HashBase.UInt64_To_BE(H6, output, 40);
  49. this.Initialize();
  50. return output;
  51. }
  52. public override void Initialize()
  53. {
  54. base.Initialize();
  55. /* SHA-384 initial hash value
  56. * The first 64 bits of the fractional parts of the square roots
  57. * of the 9th through 16th prime numbers
  58. */
  59. H1 = 0xcbbb9d5dc1059ed8;
  60. H2 = 0x629a292a367cd507;
  61. H3 = 0x9159015a3070dd17;
  62. H4 = 0x152fecd8f70e5939;
  63. H5 = 0x67332667ffc00b31;
  64. H6 = 0x8eb44a8768581511;
  65. H7 = 0xdb0c2e0d64f98fa7;
  66. H8 = 0x47b5481dbefa4fa4;
  67. }
  68. }
  69. }