IAeadBlockCipher.cs 4.2 KB

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