1b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallampackage org.bouncycastle.crypto.macs;
2b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
3b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.crypto.BlockCipher;
4b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.crypto.CipherParameters;
5b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.crypto.Mac;
6b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.crypto.modes.CBCBlockCipher;
7b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport org.bouncycastle.crypto.paddings.BlockCipherPadding;
8b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
9b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam/**
10b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * standard CBC Block Cipher MAC - if no padding is specified the default of
11b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * pad of zeroes is used.
12b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */
13b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallampublic class CBCBlockCipherMac
14b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    implements Mac
15b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam{
16b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    private byte[]              mac;
17b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
18b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    private byte[]              buf;
19b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    private int                 bufOff;
20b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    private BlockCipher         cipher;
21b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    private BlockCipherPadding  padding;
22b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
23b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    private int                 macSize;
24b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
25b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    /**
26b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * create a standard MAC based on a CBC block cipher. This will produce an
27b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * authentication code half the length of the block size of the cipher.
28b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     *
29b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * @param cipher the cipher to be used as the basis of the MAC generation.
30b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     */
31b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public CBCBlockCipherMac(
32b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        BlockCipher     cipher)
33b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
34b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        this(cipher, (cipher.getBlockSize() * 8) / 2, null);
35b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
36b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
37b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    /**
38b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * create a standard MAC based on a CBC block cipher. This will produce an
39b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * authentication code half the length of the block size of the cipher.
40b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     *
41b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * @param cipher the cipher to be used as the basis of the MAC generation.
42b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * @param padding the padding to be used to complete the last block.
43b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     */
44b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public CBCBlockCipherMac(
45b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        BlockCipher         cipher,
46b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        BlockCipherPadding  padding)
47b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
48b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        this(cipher, (cipher.getBlockSize() * 8) / 2, padding);
49b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
50b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
51b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    /**
52b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * create a standard MAC based on a block cipher with the size of the
53b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * MAC been given in bits. This class uses CBC mode as the basis for the
54b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * MAC generation.
55b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * <p>
56b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * Note: the size of the MAC must be at least 24 bits (FIPS Publication 81),
57b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * or 16 bits if being used as a data authenticator (FIPS Publication 113),
58b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * and in general should be less than the size of the block cipher as it reduces
59b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * the chance of an exhaustive attack (see Handbook of Applied Cryptography).
60b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     *
61b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * @param cipher the cipher to be used as the basis of the MAC generation.
62b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * @param macSizeInBits the size of the MAC in bits, must be a multiple of 8.
63b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     */
64b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public CBCBlockCipherMac(
65b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        BlockCipher     cipher,
66b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        int             macSizeInBits)
67b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
68b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        this(cipher, macSizeInBits, null);
69b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
70b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
71b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    /**
72b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * create a standard MAC based on a block cipher with the size of the
73b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * MAC been given in bits. This class uses CBC mode as the basis for the
74b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * MAC generation.
75b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * <p>
76b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * Note: the size of the MAC must be at least 24 bits (FIPS Publication 81),
77b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * or 16 bits if being used as a data authenticator (FIPS Publication 113),
78b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * and in general should be less than the size of the block cipher as it reduces
79b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * the chance of an exhaustive attack (see Handbook of Applied Cryptography).
80b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     *
81b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * @param cipher the cipher to be used as the basis of the MAC generation.
82b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * @param macSizeInBits the size of the MAC in bits, must be a multiple of 8.
83b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * @param padding the padding to be used to complete the last block.
84b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     */
85b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public CBCBlockCipherMac(
86b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        BlockCipher         cipher,
87b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        int                 macSizeInBits,
88b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        BlockCipherPadding  padding)
89b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
90b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        if ((macSizeInBits % 8) != 0)
91b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        {
92b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            throw new IllegalArgumentException("MAC size must be multiple of 8");
93b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        }
94b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
95b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        this.cipher = new CBCBlockCipher(cipher);
96b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        this.padding = padding;
97b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        this.macSize = macSizeInBits / 8;
98b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
99b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        mac = new byte[cipher.getBlockSize()];
100b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
101b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        buf = new byte[cipher.getBlockSize()];
102b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        bufOff = 0;
103b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
104b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
105b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public String getAlgorithmName()
106b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
107b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        return cipher.getAlgorithmName();
108b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
109b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
110b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public void init(
111b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        CipherParameters    params)
112b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
113b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        reset();
114b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
115b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        cipher.init(true, params);
116b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
117b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
118b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public int getMacSize()
119b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
120b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        return macSize;
121b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
122b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
123b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public void update(
124b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        byte        in)
125b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
126b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        if (bufOff == buf.length)
127b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        {
128c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom            cipher.processBlock(buf, 0, mac, 0);
129b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            bufOff = 0;
130b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        }
131b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
132b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        buf[bufOff++] = in;
133b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
134b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
135b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public void update(
136b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        byte[]      in,
137b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        int         inOff,
138b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        int         len)
139b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
140b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        if (len < 0)
141b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        {
142b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            throw new IllegalArgumentException("Can't have a negative input length!");
143b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        }
144b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
145b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        int blockSize = cipher.getBlockSize();
146b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        int gapLen = blockSize - bufOff;
147b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
148b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        if (len > gapLen)
149b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        {
150b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            System.arraycopy(in, inOff, buf, bufOff, gapLen);
151b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
152c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom            cipher.processBlock(buf, 0, mac, 0);
153b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
154b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            bufOff = 0;
155b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            len -= gapLen;
156b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            inOff += gapLen;
157b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
158b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            while (len > blockSize)
159b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            {
160c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom                cipher.processBlock(in, inOff, mac, 0);
161b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
162b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam                len -= blockSize;
163b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam                inOff += blockSize;
164b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            }
165b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        }
166b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
167b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        System.arraycopy(in, inOff, buf, bufOff, len);
168b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
169b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        bufOff += len;
170b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
171b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
172b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public int doFinal(
173b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        byte[]  out,
174b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        int     outOff)
175b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
176b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        int blockSize = cipher.getBlockSize();
177b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
178b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        if (padding == null)
179b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        {
180b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            //
181b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            // pad with zeroes
182b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            //
183b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            while (bufOff < blockSize)
184b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            {
185b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam                buf[bufOff] = 0;
186b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam                bufOff++;
187b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            }
188b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        }
189b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        else
190b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        {
191b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            if (bufOff == blockSize)
192b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            {
193b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam                cipher.processBlock(buf, 0, mac, 0);
194b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam                bufOff = 0;
195b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            }
196b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
197b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            padding.addPadding(buf, bufOff);
198b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        }
199b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
200b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        cipher.processBlock(buf, 0, mac, 0);
201b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
202b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        System.arraycopy(mac, 0, out, outOff, macSize);
203b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
204b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        reset();
205b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
206b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        return macSize;
207b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
208b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
209b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    /**
210b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * Reset the mac generator.
211b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     */
212b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public void reset()
213b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
214b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        /*
215b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam         * clean the buffer.
216b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam         */
217b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        for (int i = 0; i < buf.length; i++)
218b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        {
219b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            buf[i] = 0;
220b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        }
221b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
222b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        bufOff = 0;
223b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
224b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        /*
225b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam         * reset the underlying cipher.
226b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam         */
227b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        cipher.reset();
228b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
229b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam}
230