1b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallampackage org.bouncycastle.crypto; 2b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 3b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 4b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam/** 5b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * The base interface for implementations of message authentication codes (MACs). 6b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 7b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallampublic interface Mac 8b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam{ 9b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 10b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Initialise the MAC. 11b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * 12b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param params the key and other data required by the MAC. 13b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @exception IllegalArgumentException if the params argument is 14b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * inappropriate. 15b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 16b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public void init(CipherParameters params) 17b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam throws IllegalArgumentException; 18b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 19b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 20b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Return the name of the algorithm the MAC implements. 21b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * 22b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @return the name of the algorithm the MAC implements. 23b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 24b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public String getAlgorithmName(); 25b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 26b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 27b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Return the block size for this MAC (in bytes). 28b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * 29b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @return the block size for this MAC in bytes. 30b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 31b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public int getMacSize(); 32b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 33b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 34b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * add a single byte to the mac for processing. 35b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * 36b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param in the byte to be processed. 37b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @exception IllegalStateException if the MAC is not initialised. 38b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 39b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public void update(byte in) 40b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam throws IllegalStateException; 41b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 42b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 43b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param in the array containing the input. 44b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param inOff the index in the array the data begins at. 45b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param len the length of the input starting at inOff. 46b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @exception IllegalStateException if the MAC is not initialised. 47b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @exception DataLengthException if there isn't enough data in in. 48b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 49b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public void update(byte[] in, int inOff, int len) 50b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam throws DataLengthException, IllegalStateException; 51b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 52b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 53c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * Compute the final stage of the MAC writing the output to the out 54b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * parameter. 55b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * <p> 56b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * doFinal leaves the MAC in the same state it was after the last init. 57b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * 58b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param out the array the MAC is to be output to. 59b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param outOff the offset into the out buffer the output is to start at. 60b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @exception DataLengthException if there isn't enough space in out. 61b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @exception IllegalStateException if the MAC is not initialised. 62b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 63b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public int doFinal(byte[] out, int outOff) 64b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam throws DataLengthException, IllegalStateException; 65b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 66b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 67b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Reset the MAC. At the end of resetting the MAC should be in the 68b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * in the same state it was after the last init (if there was one). 69b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 70b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public void reset(); 71b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam} 72