IBlockCipher.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto
  5. {
  6. /// <remarks>Base interface for a symmetric key block cipher.</remarks>
  7. public interface IBlockCipher
  8. {
  9. /// <summary>The name of the algorithm this cipher implements.</summary>
  10. string AlgorithmName { get; }
  11. /// <summary>Initialise the cipher.</summary>
  12. /// <param name="forEncryption">Initialise for encryption if true, for decryption if false.</param>
  13. /// <param name="parameters">The key or other data required by the cipher.</param>
  14. void Init(bool forEncryption, ICipherParameters parameters);
  15. /// <returns>The block size for this cipher, in bytes.</returns>
  16. int GetBlockSize();
  17. /// <summary>Process a block.</summary>
  18. /// <param name="inBuf">The input buffer.</param>
  19. /// <param name="inOff">The offset into <paramref>inBuf</paramref> that the input block begins.</param>
  20. /// <param name="outBuf">The output buffer.</param>
  21. /// <param name="outOff">The offset into <paramref>outBuf</paramref> to write the output block.</param>
  22. /// <exception cref="DataLengthException">If input block is wrong size, or outBuf too small.</exception>
  23. /// <returns>The number of bytes processed and produced.</returns>
  24. int ProcessBlock(byte[] inBuf, int inOff, byte[] outBuf, int outOff);
  25. #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
  26. /// <summary>Process a block.</summary>
  27. /// <param name="input">The input block as a span.</param>
  28. /// <param name="output">The output span.</param>
  29. /// <exception cref="DataLengthException">If input block is wrong size, or output span too small.</exception>
  30. /// <returns>The number of bytes processed and produced.</returns>
  31. int ProcessBlock(ReadOnlySpan<byte> input, Span<byte> output);
  32. #endif
  33. }
  34. }
  35. #pragma warning restore
  36. #endif