1package org.bouncycastle.crypto.paddings;
2
3import java.security.SecureRandom;
4
5import org.bouncycastle.crypto.InvalidCipherTextException;
6
7/**
8 * Block cipher padders are expected to conform to this interface
9 */
10public interface BlockCipherPadding
11{
12    /**
13     * Initialise the padder.
14     *
15     * @param random the source of randomness for the padding, if required.
16     */
17    public void init(SecureRandom random)
18        throws IllegalArgumentException;
19
20    /**
21     * Return the name of the algorithm the cipher implements.
22     *
23     * @return the name of the algorithm the cipher implements.
24     */
25    public String getPaddingName();
26
27    /**
28     * add the pad bytes to the passed in block, returning the
29     * number of bytes added.
30     * <p>
31     * Note: this assumes that the last block of plain text is always
32     * passed to it inside in. i.e. if inOff is zero, indicating the
33     * entire block is to be overwritten with padding the value of in
34     * should be the same as the last block of plain text. The reason
35     * for this is that some modes such as "trailing bit compliment"
36     * base the padding on the last byte of plain text.
37     * </p>
38     */
39    public int addPadding(byte[] in, int inOff);
40
41    /**
42     * return the number of pad bytes present in the block.
43     * @exception InvalidCipherTextException if the padding is badly formed
44     * or invalid.
45     */
46    public int padCount(byte[] in)
47        throws InvalidCipherTextException;
48}
49