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