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