TlsBlockCipherImpl.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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>Interface for block cipher services.</summary>
  8. public interface TlsBlockCipherImpl
  9. {
  10. /// <summary>Set the key to be used by the block cipher implementation supporting this service.</summary>
  11. /// <param name="key">array holding the block 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 operator.</summary>
  20. /// <param name="iv">array holding the initialization vector (IV).</param>
  21. /// <param name="ivOff">offset into the array the IV starts at.</param>
  22. /// <param name="ivLen">length of the IV in the array.</param>
  23. /// <exception cref="IOException">if the parameters are inappropriate.</exception>
  24. void Init(byte[] iv, int ivOff, int ivLen);
  25. #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
  26. void Init(ReadOnlySpan<byte> iv);
  27. #endif
  28. /// <summary>Perform the cipher encryption/decryption returning the output in output.</summary>
  29. /// <remarks>
  30. /// Note: we have to use DoFinal() here as it is the only way to guarantee output from the underlying cipher.
  31. /// </remarks>
  32. /// <param name="input">array holding input data to the cipher.</param>
  33. /// <param name="inputOffset">offset into input array data starts at.</param>
  34. /// <param name="inputLength">length of the input data in the array.</param>
  35. /// <param name="output">array to hold the cipher output.</param>
  36. /// <param name="outputOffset">offset into output array to start saving output.</param>
  37. /// <returns>the amount of data written to output.</returns>
  38. /// <exception cref="IOException">in case of failure.</exception>
  39. int DoFinal(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset);
  40. /// <summary>Return the blocksize (in bytes) of the underlying block cipher.</summary>
  41. /// <returns>the cipher's blocksize.</returns>
  42. int GetBlockSize();
  43. }
  44. }
  45. #pragma warning restore
  46. #endif