1 package javax.crypto; 2 3 import java.security.Key; 4 import java.security.InvalidKeyException; 5 import java.security.InvalidAlgorithmParameterException; 6 import java.security.spec.AlgorithmParameterSpec; 7 8 /** 9 * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) 10 * for the <code>Mac</code> class. 11 * All the abstract methods in this class must be implemented by each 12 * cryptographic service provider who wishes to supply the implementation 13 * of a particular MAC algorithm. 14 * <p> 15 * Implementations are free to implement the Cloneable interface. 16 */ 17 public abstract class MacSpi 18 { MacSpi()19 public MacSpi() 20 { 21 } 22 23 /** 24 * Returns the length of the MAC in bytes. 25 * 26 * @return the MAC length in bytes. 27 */ engineGetMacLength()28 protected abstract int engineGetMacLength(); 29 30 /** 31 * Initializes the MAC with the given (secret) key and algorithm 32 * parameters. 33 * 34 * @param key - the (secret) key. 35 * @param params - the algorithm parameters. 36 * @exception InvalidKeyException if the given key is inappropriate for initializing this MAC. 37 * @exception InvalidAlgorithmParameterException - if the given algorithm parameters are inappropriate 38 * for this MAC. 39 */ engineInit( Key key, AlgorithmParameterSpec params)40 protected abstract void engineInit( 41 Key key, 42 AlgorithmParameterSpec params) 43 throws InvalidKeyException, InvalidAlgorithmParameterException; 44 45 /** 46 * Processes the given byte. 47 * 48 * @param input - the input byte to be processed. 49 */ engineUpdate( byte input)50 protected abstract void engineUpdate( 51 byte input); 52 53 /** 54 * Processes the first <code>len</code> bytes in <code>input</code>, 55 * starting at <code>offset</code> inclusive. 56 * 57 * @param input the input buffer. 58 * @param offset the offset in <code>input</code> where the input starts. 59 * @param len the number of bytes to process. 60 */ engineUpdate( byte[] input, int offset, int len)61 protected abstract void engineUpdate( 62 byte[] input, 63 int offset, 64 int len); 65 66 /** 67 * Completes the MAC computation and resets the MAC for further use, 68 * maintaining the secret key that the MAC was initialized with. 69 * 70 * @return the MAC result. 71 */ engineDoFinal()72 protected abstract byte[] engineDoFinal(); 73 74 /** 75 * Resets the MAC for further use, maintaining the secret key that the 76 * MAC was initialized with. 77 */ engineReset()78 protected abstract void engineReset(); 79 80 /** 81 * Returns a clone if the implementation is cloneable. 82 * 83 * @return a clone if the implementation is cloneable. 84 * @exception CloneNotSupportedException if this is called on an implementation that does not support 85 * <code>Cloneable</code>. 86 */ clone()87 public Object clone() 88 throws CloneNotSupportedException 89 { 90 throw new CloneNotSupportedException("Underlying MAC does not support cloning"); 91 } 92 } 93