TlsSuiteMac.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl
  5. {
  6. /// <summary>Base interface for a generic TLS MAC implementation for use with a bulk cipher.</summary>
  7. public interface TlsSuiteMac
  8. {
  9. /// <summary>Return the output length (in bytes) of this MAC.</summary>
  10. /// <returns>The output length of this MAC.</returns>
  11. int Size { get; }
  12. /// <summary>Calculate the MAC for some given data.</summary>
  13. /// <param name="seqNo">The sequence number of the record.</param>
  14. /// <param name="type">The content type of the message.</param>
  15. /// <param name="message">A byte array containing the message.</param>
  16. /// <param name="offset">The number of bytes to skip, before the message starts.</param>
  17. /// <param name="length">The length of the message.</param>
  18. /// <returns>A new byte array containing the MAC value.</returns>
  19. byte[] CalculateMac(long seqNo, short type, byte[] message, int offset, int length);
  20. #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
  21. byte[] CalculateMac(long seqNo, short type, ReadOnlySpan<byte> message);
  22. #endif
  23. /// <summary>Constant time calculation of the MAC for some given data with a given expected length.</summary>
  24. /// <param name="seqNo">The sequence number of the record.</param>
  25. /// <param name="type">The content type of the message.</param>
  26. /// <param name="message">A byte array containing the message.</param>
  27. /// <param name="offset">The number of bytes to skip, before the message starts.</param>
  28. /// <param name="length">The length of the message.</param>
  29. /// <param name="expectedLength">The expected length of the full message.</param>
  30. /// <param name="randomData">Random data for padding out the MAC calculation if required.</param>
  31. /// <returns>A new byte array containing the MAC value.</returns>
  32. byte[] CalculateMacConstantTime(long seqNo, short type, byte[] message, int offset, int length,
  33. int expectedLength, byte[] randomData);
  34. }
  35. }
  36. #pragma warning restore
  37. #endif