1c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrompackage org.bouncycastle.crypto.modes; 2c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 3c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport org.bouncycastle.crypto.BlockCipher; 4c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport org.bouncycastle.crypto.CipherParameters; 5c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport org.bouncycastle.crypto.DataLengthException; 6c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport org.bouncycastle.crypto.InvalidCipherTextException; 7c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 8c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom/** 9c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * A block cipher mode that includes authenticated encryption with a streaming mode and optional associated data. 10c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @see org.bouncycastle.crypto.params.AEADParameters 11c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom */ 12c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrompublic interface AEADBlockCipher 13c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom{ 14c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom /** 15c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * initialise the underlying cipher. Parameter can either be an AEADParameters or a ParametersWithIV object. 16c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * 17c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @param forEncryption true if we are setting up for encryption, false otherwise. 18c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @param params the necessary parameters for the underlying cipher to be initialised. 19c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @exception IllegalArgumentException if the params argument is inappropriate. 20c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom */ 21c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom public void init(boolean forEncryption, CipherParameters params) 22c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom throws IllegalArgumentException; 23c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 24c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom /** 25c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * Return the name of the algorithm. 26c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * 27c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @return the algorithm name. 28c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom */ 29c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom public String getAlgorithmName(); 30c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 31c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom /** 32c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * return the cipher this object wraps. 33c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * 34c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @return the cipher this object wraps. 35c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom */ 36c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom public BlockCipher getUnderlyingCipher(); 37c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 38c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom /** 39c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * encrypt/decrypt a single byte. 40c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * 41c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @param in the byte to be processed. 42c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @param out the output buffer the processed byte goes into. 43c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @param outOff the offset into the output byte array the processed data starts at. 44c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @return the number of bytes written to out. 45c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @exception DataLengthException if the output buffer is too small. 46c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom */ 47c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom public int processByte(byte in, byte[] out, int outOff) 48c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom throws DataLengthException; 49c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 50c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom /** 51c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * process a block of bytes from in putting the result into out. 52c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * 53c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @param in the input byte array. 54c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @param inOff the offset into the in array where the data to be processed starts. 55c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @param len the number of bytes to be processed. 56c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @param out the output buffer the processed bytes go into. 57c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @param outOff the offset into the output byte array the processed data starts at. 58c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @return the number of bytes written to out. 59c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @exception DataLengthException if the output buffer is too small. 60c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom */ 61c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom public int processBytes(byte[] in, int inOff, int len, byte[] out, int outOff) 62c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom throws DataLengthException; 63c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 64c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom /** 65c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * Finish the operation either appending or verifying the MAC at the end of the data. 66c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * 67c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @param out space for any resulting output data. 68c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @param outOff offset into out to start copying the data at. 69c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @return number of bytes written into out. 70c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @throws IllegalStateException if the cipher is in an inappropriate state. 71c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @throws org.bouncycastle.crypto.InvalidCipherTextException if the MAC fails to match. 72c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom */ 73c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom public int doFinal(byte[] out, int outOff) 74c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom throws IllegalStateException, InvalidCipherTextException; 75c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 76c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom /** 77c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * Return the value of the MAC associated with the last stream processed. 78c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * 79c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @return MAC for plaintext data. 80c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom */ 81c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom public byte[] getMac(); 82c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 83c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom /** 84c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * return the size of the output buffer required for a processBytes 85c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * an input of len bytes. 86c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * 87c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @param len the length of the input. 88c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @return the space required to accommodate a call to processBytes 89c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * with len bytes of input. 90c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom */ 91c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom public int getUpdateOutputSize(int len); 92c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 93c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom /** 94c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * return the size of the output buffer required for a processBytes plus a 95c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * doFinal with an input of len bytes. 96c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * 97c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @param len the length of the input. 98c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @return the space required to accommodate a call to processBytes and doFinal 99c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * with len bytes of input. 100c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom */ 101c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom public int getOutputSize(int len); 102c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 103c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom /** 104c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * Reset the cipher. After resetting the cipher is in the same state 105c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * as it was after the last init (if there was one). 106c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom */ 107c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom public void reset(); 108c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom} 109