IStreamCipher.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. /// <summary>The interface stream ciphers conform to.</summary>
  7. public interface IStreamCipher
  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">If true the cipher is initialised for encryption,
  13. /// if false for decryption.</param>
  14. /// <param name="parameters">The key and other data required by the cipher.</param>
  15. /// <exception cref="ArgumentException">
  16. /// If the parameters argument is inappropriate.
  17. /// </exception>
  18. void Init(bool forEncryption, ICipherParameters parameters);
  19. /// <summary>encrypt/decrypt a single byte returning the result.</summary>
  20. /// <param name="input">the byte to be processed.</param>
  21. /// <returns>the result of processing the input byte.</returns>
  22. byte ReturnByte(byte input);
  23. /// <summary>
  24. /// Process a block of bytes from <paramref name="input"/>, putting the result into <paramref name="output"/>.
  25. /// </summary>
  26. /// <param name="input">The input byte array.</param>
  27. /// <param name="inOff">
  28. /// The offset into <c>input</c> where the data to be processed starts.
  29. /// </param>
  30. /// <param name="length">The number of bytes to be processed.</param>
  31. /// <param name="output">The output buffer the processed bytes go into.</param>
  32. /// <param name="outOff">
  33. /// The offset into <c>output</c> the processed data starts at.
  34. /// </param>
  35. /// <exception cref="DataLengthException">If the input buffer is too small.</exception>
  36. /// <exception cref="OutputLengthException">If the output buffer is too small.</exception>
  37. void ProcessBytes(byte[] input, int inOff, int length, byte[] output, int outOff);
  38. #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
  39. /// <summary>
  40. /// Process a block of bytes from <paramref name="input"/>, putting the result into <paramref name="output"/>.
  41. /// </summary>
  42. /// <param name="input">The input span.</param>
  43. /// <param name="output">The output span.</param>
  44. /// <exception cref="OutputLengthException">If the output span is too small.</exception>
  45. void ProcessBytes(ReadOnlySpan<byte> input, Span<byte> output);
  46. #endif
  47. /// <summary>
  48. /// Reset the cipher to the same state as it was after the last init (if there was one).
  49. /// </summary>
  50. void Reset();
  51. }
  52. }
  53. #pragma warning restore
  54. #endif