1 |
769 |
jeremybenn |
/* IPad.java --
|
2 |
|
|
Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc.
|
3 |
|
|
|
4 |
|
|
This file is a part of GNU Classpath.
|
5 |
|
|
|
6 |
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
7 |
|
|
it under the terms of the GNU General Public License as published by
|
8 |
|
|
the Free Software Foundation; either version 2 of the License, or (at
|
9 |
|
|
your option) any later version.
|
10 |
|
|
|
11 |
|
|
GNU Classpath is distributed in the hope that it will be useful, but
|
12 |
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
|
|
General Public License for more details.
|
15 |
|
|
|
16 |
|
|
You should have received a copy of the GNU General Public License
|
17 |
|
|
along with GNU Classpath; if not, write to the Free Software
|
18 |
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
|
19 |
|
|
USA
|
20 |
|
|
|
21 |
|
|
Linking this library statically or dynamically with other modules is
|
22 |
|
|
making a combined work based on this library. Thus, the terms and
|
23 |
|
|
conditions of the GNU General Public License cover the whole
|
24 |
|
|
combination.
|
25 |
|
|
|
26 |
|
|
As a special exception, the copyright holders of this library give you
|
27 |
|
|
permission to link this library with independent modules to produce an
|
28 |
|
|
executable, regardless of the license terms of these independent
|
29 |
|
|
modules, and to copy and distribute the resulting executable under
|
30 |
|
|
terms of your choice, provided that you also meet, for each linked
|
31 |
|
|
independent module, the terms and conditions of the license of that
|
32 |
|
|
module. An independent module is a module which is not derived from
|
33 |
|
|
or based on this library. If you modify this library, you may extend
|
34 |
|
|
this exception to your version of the library, but you are not
|
35 |
|
|
obligated to do so. If you do not wish to do so, delete this
|
36 |
|
|
exception statement from your version. */
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
package gnu.javax.crypto.pad;
|
40 |
|
|
|
41 |
|
|
import java.util.Map;
|
42 |
|
|
|
43 |
|
|
/**
|
44 |
|
|
* The basic visible methods, and attribute names, of every padding algorithm.
|
45 |
|
|
* <p>
|
46 |
|
|
* Padding algorithms serve to <i>pad</i> and <i>unpad</i> byte arrays usually
|
47 |
|
|
* as the last step in an <i>encryption</i> or respectively a <i>decryption</i>
|
48 |
|
|
* operation. Their input buffers are usually those processed by instances of
|
49 |
|
|
* {@link gnu.javax.crypto.mode.IMode} and/or
|
50 |
|
|
* {@link gnu.javax.crypto.cipher.IBlockCipher}.
|
51 |
|
|
*/
|
52 |
|
|
public interface IPad
|
53 |
|
|
{
|
54 |
|
|
/**
|
55 |
|
|
* Property name of the block size in which to operate the padding algorithm.
|
56 |
|
|
* The value associated with this property name is taken to be a positive
|
57 |
|
|
* {@link Integer} greater than zero.
|
58 |
|
|
*/
|
59 |
|
|
String PADDING_BLOCK_SIZE = "gnu.crypto.pad.block.size";
|
60 |
|
|
|
61 |
|
|
/** @return the canonical name of this instance. */
|
62 |
|
|
String name();
|
63 |
|
|
|
64 |
|
|
/**
|
65 |
|
|
* Initialises the padding scheme with a designated block size.
|
66 |
|
|
*
|
67 |
|
|
* @param bs the designated block size.
|
68 |
|
|
* @exception IllegalStateException if the instance is already initialised.
|
69 |
|
|
* @exception IllegalArgumentException if the block size value is invalid.
|
70 |
|
|
*/
|
71 |
|
|
void init(int bs) throws IllegalStateException;
|
72 |
|
|
|
73 |
|
|
/**
|
74 |
|
|
* Initialises the algorithm with designated attributes. Names, valid and/or
|
75 |
|
|
* recognisable by all concrete implementations are described in the class
|
76 |
|
|
* documentation above. Other algorithm-specific attributes MUST be documented
|
77 |
|
|
* in the implementation class of that padding algorithm.
|
78 |
|
|
*
|
79 |
|
|
* @param attributes a set of name-value pairs that describes the desired
|
80 |
|
|
* future behaviour of this instance.
|
81 |
|
|
* @exception IllegalStateException if the instance is already initialised.
|
82 |
|
|
* @exception IllegalArgumentException if the block size value is invalid.
|
83 |
|
|
*/
|
84 |
|
|
void init(Map attributes) throws IllegalStateException;
|
85 |
|
|
|
86 |
|
|
/**
|
87 |
|
|
* Returns the byte sequence that should be appended to the designated input.
|
88 |
|
|
*
|
89 |
|
|
* @param in the input buffer containing the bytes to pad.
|
90 |
|
|
* @param offset the starting index of meaningful data in <i>in</i>.
|
91 |
|
|
* @param length the number of meaningful bytes in <i>in</i>.
|
92 |
|
|
* @return the possibly 0-byte long sequence to be appended to the designated
|
93 |
|
|
* input.
|
94 |
|
|
*/
|
95 |
|
|
byte[] pad(byte[] in, int offset, int length);
|
96 |
|
|
|
97 |
|
|
/**
|
98 |
|
|
* Returns the number of bytes to discard from a designated input buffer.
|
99 |
|
|
*
|
100 |
|
|
* @param in the input buffer containing the bytes to unpad.
|
101 |
|
|
* @param offset the starting index of meaningful data in <i>in</i>.
|
102 |
|
|
* @param length the number of meaningful bytes in <i>in</i>.
|
103 |
|
|
* @return the number of bytes to discard, to the left of index position
|
104 |
|
|
* <code>offset + length</code> in <i>in</i>. In other words, if
|
105 |
|
|
* the return value of a successful invocation of this method is
|
106 |
|
|
* <code>result</code>, then the unpadded byte sequence will be
|
107 |
|
|
* <code>offset + length - result</code> bytes in <i>in</i>,
|
108 |
|
|
* starting from index position <code>offset</code>.
|
109 |
|
|
* @exception WrongPaddingException if the data is not terminated with the
|
110 |
|
|
* expected padding bytes.
|
111 |
|
|
*/
|
112 |
|
|
int unpad(byte[] in, int offset, int length) throws WrongPaddingException;
|
113 |
|
|
|
114 |
|
|
/**
|
115 |
|
|
* Resets the scheme instance for re-initialisation and use with other
|
116 |
|
|
* characteristics. This method always succeeds.
|
117 |
|
|
*/
|
118 |
|
|
void reset();
|
119 |
|
|
|
120 |
|
|
/**
|
121 |
|
|
* A basic symmetric pad/unpad test.
|
122 |
|
|
*
|
123 |
|
|
* @return <code>true</code> if the implementation passes a basic symmetric
|
124 |
|
|
* self-test. Returns <code>false</code> otherwise.
|
125 |
|
|
*/
|
126 |
|
|
boolean selfTest();
|
127 |
|
|
}
|