TlsAeadCipherImpl.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.IO;
  5. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls.Crypto.Impl
  6. {
  7. /// <summary>Base interface for services supporting AEAD encryption/decryption.</summary>
  8. public interface TlsAeadCipherImpl
  9. {
  10. /// <summary>Set the key to be used by the AEAD cipher implementation supporting this service.</summary>
  11. /// <param name="key">array holding the AEAD cipher key.</param>
  12. /// <param name="keyOff">offset into the array the key starts at.</param>
  13. /// <param name="keyLen">length of the key in the array.</param>
  14. /// <exception cref="IOException"/>
  15. void SetKey(byte[] key, int keyOff, int keyLen);
  16. #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
  17. void SetKey(ReadOnlySpan<byte> key);
  18. #endif
  19. /// <summary>Initialise the parameters for the AEAD operator.</summary>
  20. /// <param name="nonce">the nonce.</param>
  21. /// <param name="macSize">MAC size in bytes.</param>
  22. /// <param name="additionalData">any additional data to be included in the MAC calculation.</param>
  23. /// <exception cref="IOException">if the parameters are inappropriate.</exception>
  24. void Init(byte[] nonce, int macSize, byte[] additionalData);
  25. /// <summary>Return the maximum size of the output for input of inputLength bytes.</summary>
  26. /// <param name="inputLength">the length (in bytes) of the proposed input.</param>
  27. /// <returns>the maximum size of the output.</returns>
  28. int GetOutputSize(int inputLength);
  29. /// <summary>Perform the cipher encryption/decryption returning the output in output.</summary>
  30. /// <remarks>
  31. /// Note: we have to use DoFinal() here as it is the only way to guarantee output from the underlying cipher.
  32. /// </remarks>
  33. /// <param name="input">array holding input data to the cipher.</param>
  34. /// <param name="inputOffset">offset into input array data starts at.</param>
  35. /// <param name="inputLength">length of the input data in the array.</param>
  36. /// <param name="output">array to hold the cipher output.</param>
  37. /// <param name="outputOffset">offset into output array to start saving output.</param>
  38. /// <returns>the amount of data written to output.</returns>
  39. /// <exception cref="IOException">in case of failure.</exception>
  40. int DoFinal(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset);
  41. void Reset();
  42. }
  43. }
  44. #pragma warning restore
  45. #endif