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