1b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallampackage org.bouncycastle.crypto; 2b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 3b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 4b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam/** 5b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Block cipher engines are expected to conform to this interface. 6b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 7b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallampublic interface BlockCipher 8b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam{ 9b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 10b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Initialise the cipher. 11b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * 12b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param forEncryption if true the cipher is initialised for 13b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * encryption, if false for decryption. 14b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param params the key and other data required by the cipher. 15b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @exception IllegalArgumentException if the params argument is 16b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * inappropriate. 17b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 18b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public void init(boolean forEncryption, CipherParameters params) 19b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam throws IllegalArgumentException; 20b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 21b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 22b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Return the name of the algorithm the cipher implements. 23b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * 24b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @return the name of the algorithm the cipher implements. 25b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 26b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public String getAlgorithmName(); 27b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 28b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 29b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Return the block size for this cipher (in bytes). 30b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * 31b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @return the block size for this cipher in bytes. 32b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 33b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public int getBlockSize(); 34b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 35b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 36b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Process one block of input from the array in and write it to 37b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * the out array. 38b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * 39b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param in the array containing the input data. 40b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param inOff offset into the in array the data starts at. 41b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param out the array the output data will be copied into. 42b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param outOff the offset into the out array the output will start at. 43b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @exception DataLengthException if there isn't enough data in in, or 44b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * space in out. 45b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @exception IllegalStateException if the cipher isn't initialised. 46b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @return the number of bytes processed and produced. 47b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 48b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public int processBlock(byte[] in, int inOff, byte[] out, int outOff) 49b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam throws DataLengthException, IllegalStateException; 50b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 51b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 52b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Reset the cipher. After resetting the cipher is in the same state 53b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * as it was after the last init (if there was one). 54b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 55b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public void reset(); 56b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam} 57