GOST3411_2012_256Digest.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  5. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Digests
  6. {
  7. public class Gost3411_2012_256Digest : Gost3411_2012Digest
  8. {
  9. private readonly static byte[] IV = {
  10. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  11. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  12. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  13. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  14. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  15. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  16. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  17. 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
  18. };
  19. public override string AlgorithmName
  20. {
  21. get { return "GOST3411-2012-256"; }
  22. }
  23. public Gost3411_2012_256Digest() : base(IV)
  24. {
  25. }
  26. public Gost3411_2012_256Digest(Gost3411_2012_256Digest other) : base(IV)
  27. {
  28. Reset(other);
  29. }
  30. public override int GetDigestSize()
  31. {
  32. return 32;
  33. }
  34. public override int DoFinal(byte[] output, int outOff)
  35. {
  36. byte[] result = new byte[64];
  37. base.DoFinal(result, 0);
  38. Array.Copy(result, 32, output, outOff, 32);
  39. return 32;
  40. }
  41. #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
  42. public override int DoFinal(Span<byte> output)
  43. {
  44. Span<byte> result = stackalloc byte[64];
  45. base.DoFinal(result);
  46. result[32..].CopyTo(output);
  47. return 32;
  48. }
  49. #endif
  50. public override IMemoable Copy()
  51. {
  52. return new Gost3411_2012_256Digest(this);
  53. }
  54. }
  55. }
  56. #pragma warning restore
  57. #endif