IAeadBlockCipher.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters;
  4. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Modes
  5. {
  6. /// <summary>
  7. /// A block cipher mode that includes authenticated encryption with a streaming mode
  8. /// and optional associated data.</summary>
  9. /// <see cref="AeadParameters"/>
  10. public interface IAeadBlockCipher
  11. {
  12. /// <summary>The name of the algorithm this cipher implements.</summary>
  13. string AlgorithmName { get; }
  14. /// <summary>The block cipher underlying this algorithm.</summary>
  15. IBlockCipher GetUnderlyingCipher();
  16. /// <summary>Initialise the cipher.</summary>
  17. /// <remarks>Parameter can either be an AeadParameters or a ParametersWithIV object.</remarks>
  18. /// <param name="forEncryption">Initialise for encryption if true, for decryption if false.</param>
  19. /// <param name="parameters">The key or other data required by the cipher.</param>
  20. void Init(bool forEncryption, ICipherParameters parameters);
  21. /// <returns>The block size for this cipher, in bytes.</returns>
  22. int GetBlockSize();
  23. /// <summary>Add a single byte to the associated data check.</summary>
  24. /// <remarks>If the implementation supports it, this will be an online operation and will not retain the associated data.</remarks>
  25. /// <param name="input">The byte to be processed.</param>
  26. void ProcessAadByte(byte input);
  27. /// <summary>Add a sequence of bytes to the associated data check.</summary>
  28. /// <remarks>If the implementation supports it, this will be an online operation and will not retain the associated data.</remarks>
  29. /// <param name="inBytes">The input byte array.</param>
  30. /// <param name="inOff">The offset into the input array where the data to be processed starts.</param>
  31. /// <param name="len">The number of bytes to be processed.</param>
  32. void ProcessAadBytes(byte[] inBytes, int inOff, int len);
  33. /**
  34. * Encrypt/decrypt a single byte.
  35. *
  36. * @param input the byte to be processed.
  37. * @param outBytes the output buffer the processed byte goes into.
  38. * @param outOff the offset into the output byte array the processed data starts at.
  39. * @return the number of bytes written to out.
  40. * @exception DataLengthException if the output buffer is too small.
  41. */
  42. int ProcessByte(byte input, byte[] outBytes, int outOff);
  43. /**
  44. * Process a block of bytes from in putting the result into out.
  45. *
  46. * @param inBytes the input byte array.
  47. * @param inOff the offset into the in array where the data to be processed starts.
  48. * @param len the number of bytes to be processed.
  49. * @param outBytes the output buffer the processed bytes go into.
  50. * @param outOff the offset into the output byte array the processed data starts at.
  51. * @return the number of bytes written to out.
  52. * @exception DataLengthException if the output buffer is too small.
  53. */
  54. int ProcessBytes(byte[] inBytes, int inOff, int len, byte[] outBytes, int outOff);
  55. /**
  56. * Finish the operation either appending or verifying the MAC at the end of the data.
  57. *
  58. * @param outBytes space for any resulting output data.
  59. * @param outOff offset into out to start copying the data at.
  60. * @return number of bytes written into out.
  61. * @throws InvalidOperationException if the cipher is in an inappropriate state.
  62. * @throws InvalidCipherTextException if the MAC fails to match.
  63. */
  64. int DoFinal(byte[] outBytes, int outOff);
  65. /**
  66. * Return the value of the MAC associated with the last stream processed.
  67. *
  68. * @return MAC for plaintext data.
  69. */
  70. byte[] GetMac();
  71. /**
  72. * Return the size of the output buffer required for a ProcessBytes
  73. * an input of len bytes.
  74. *
  75. * @param len the length of the input.
  76. * @return the space required to accommodate a call to ProcessBytes
  77. * with len bytes of input.
  78. */
  79. int GetUpdateOutputSize(int len);
  80. /**
  81. * Return the size of the output buffer required for a ProcessBytes plus a
  82. * DoFinal with an input of len bytes.
  83. *
  84. * @param len the length of the input.
  85. * @return the space required to accommodate a call to ProcessBytes and DoFinal
  86. * with len bytes of input.
  87. */
  88. int GetOutputSize(int len);
  89. /// <summary>
  90. /// Reset the cipher to the same state as it was after the last init (if there was one).
  91. /// </summary>
  92. void Reset();
  93. }
  94. }
  95. #pragma warning restore
  96. #endif