Sha384Digest.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Digests
  7. {
  8. /**
  9. * Draft FIPS 180-2 implementation of SHA-384. <b>Note:</b> As this is
  10. * based on a draft this implementation is subject to change.
  11. *
  12. * <pre>
  13. * block word digest
  14. * SHA-1 512 32 160
  15. * SHA-256 512 32 256
  16. * SHA-384 1024 64 384
  17. * SHA-512 1024 64 512
  18. * </pre>
  19. */
  20. [BestHTTP.PlatformSupport.IL2CPP.Il2CppSetOption(BestHTTP.PlatformSupport.IL2CPP.Option.NullChecks, false)]
  21. [BestHTTP.PlatformSupport.IL2CPP.Il2CppSetOption(BestHTTP.PlatformSupport.IL2CPP.Option.ArrayBoundsChecks, false)]
  22. [BestHTTP.PlatformSupport.IL2CPP.Il2CppSetOption(BestHTTP.PlatformSupport.IL2CPP.Option.DivideByZeroChecks, false)]
  23. [BestHTTP.PlatformSupport.IL2CPP.Il2CppEagerStaticClassConstructionAttribute]
  24. public class Sha384Digest
  25. : LongDigest
  26. {
  27. private const int DigestLength = 48;
  28. public Sha384Digest()
  29. {
  30. }
  31. /**
  32. * Copy constructor. This will copy the state of the provided
  33. * message digest.
  34. */
  35. public Sha384Digest(
  36. Sha384Digest t)
  37. : base(t)
  38. {
  39. }
  40. public override string AlgorithmName
  41. {
  42. get { return "SHA-384"; }
  43. }
  44. public override int GetDigestSize()
  45. {
  46. return DigestLength;
  47. }
  48. public override int DoFinal(
  49. byte[] output,
  50. int outOff)
  51. {
  52. Finish();
  53. Pack.UInt64_To_BE(H1, output, outOff);
  54. Pack.UInt64_To_BE(H2, output, outOff + 8);
  55. Pack.UInt64_To_BE(H3, output, outOff + 16);
  56. Pack.UInt64_To_BE(H4, output, outOff + 24);
  57. Pack.UInt64_To_BE(H5, output, outOff + 32);
  58. Pack.UInt64_To_BE(H6, output, outOff + 40);
  59. Reset();
  60. return DigestLength;
  61. }
  62. /**
  63. * reset the chaining variables
  64. */
  65. public override void Reset()
  66. {
  67. base.Reset();
  68. /* SHA-384 initial hash value
  69. * The first 64 bits of the fractional parts of the square roots
  70. * of the 9th through 16th prime numbers
  71. */
  72. H1 = 0xcbbb9d5dc1059ed8;
  73. H2 = 0x629a292a367cd507;
  74. H3 = 0x9159015a3070dd17;
  75. H4 = 0x152fecd8f70e5939;
  76. H5 = 0x67332667ffc00b31;
  77. H6 = 0x8eb44a8768581511;
  78. H7 = 0xdb0c2e0d64f98fa7;
  79. H8 = 0x47b5481dbefa4fa4;
  80. }
  81. public override IMemoable Copy()
  82. {
  83. return new Sha384Digest(this);
  84. }
  85. public override void Reset(IMemoable other)
  86. {
  87. Sha384Digest d = (Sha384Digest)other;
  88. CopyIn(d);
  89. }
  90. }
  91. }
  92. #pragma warning restore
  93. #endif