1 |
769 |
jeremybenn |
/* IBlockCipherSpi.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.cipher;
|
40 |
|
|
|
41 |
|
|
import java.security.InvalidKeyException;
|
42 |
|
|
import java.util.Iterator;
|
43 |
|
|
|
44 |
|
|
/**
|
45 |
|
|
* Package-private interface exposing mandatory methods to be implemented by
|
46 |
|
|
* concrete {@link BaseCipher} sub-classes.
|
47 |
|
|
*/
|
48 |
|
|
interface IBlockCipherSpi
|
49 |
|
|
extends Cloneable
|
50 |
|
|
{
|
51 |
|
|
/**
|
52 |
|
|
* Returns an {@link Iterator} over the supported block sizes. Each element
|
53 |
|
|
* returned by this object is a {@link java.lang.Integer}.
|
54 |
|
|
*
|
55 |
|
|
* @return an <code>Iterator</code> over the supported block sizes.
|
56 |
|
|
*/
|
57 |
|
|
Iterator blockSizes();
|
58 |
|
|
|
59 |
|
|
/**
|
60 |
|
|
* Returns an {@link Iterator} over the supported key sizes. Each element
|
61 |
|
|
* returned by this object is a {@link java.lang.Integer}.
|
62 |
|
|
*
|
63 |
|
|
* @return an <code>Iterator</code> over the supported key sizes.
|
64 |
|
|
*/
|
65 |
|
|
Iterator keySizes();
|
66 |
|
|
|
67 |
|
|
/**
|
68 |
|
|
* Expands a user-supplied key material into a session key for a designated
|
69 |
|
|
* <i>block size</i>.
|
70 |
|
|
*
|
71 |
|
|
* @param k the user-supplied key material.
|
72 |
|
|
* @param bs the desired block size in bytes.
|
73 |
|
|
* @return an Object encapsulating the session key.
|
74 |
|
|
* @exception IllegalArgumentException if the block size is invalid.
|
75 |
|
|
* @exception InvalidKeyException if the key data is invalid.
|
76 |
|
|
*/
|
77 |
|
|
Object makeKey(byte[] k, int bs) throws InvalidKeyException;
|
78 |
|
|
|
79 |
|
|
/**
|
80 |
|
|
* Encrypts exactly one block of plaintext.
|
81 |
|
|
*
|
82 |
|
|
* @param in the plaintext.
|
83 |
|
|
* @param inOffset index of <code>in</code> from which to start considering
|
84 |
|
|
* data.
|
85 |
|
|
* @param out the ciphertext.
|
86 |
|
|
* @param outOffset index of <code>out</code> from which to store the
|
87 |
|
|
* result.
|
88 |
|
|
* @param k the session key to use.
|
89 |
|
|
* @param bs the block size to use.
|
90 |
|
|
* @exception IllegalArgumentException if the block size is invalid.
|
91 |
|
|
* @exception ArrayIndexOutOfBoundsException if there is not enough room in
|
92 |
|
|
* either the plaintext or ciphertext buffers.
|
93 |
|
|
*/
|
94 |
|
|
void encrypt(byte[] in, int inOffset, byte[] out, int outOffset, Object k,
|
95 |
|
|
int bs);
|
96 |
|
|
|
97 |
|
|
/**
|
98 |
|
|
* Decrypts exactly one block of ciphertext.
|
99 |
|
|
*
|
100 |
|
|
* @param in the ciphertext.
|
101 |
|
|
* @param inOffset index of <code>in</code> from which to start considering
|
102 |
|
|
* data.
|
103 |
|
|
* @param out the plaintext.
|
104 |
|
|
* @param outOffset index of <code>out</code> from which to store the
|
105 |
|
|
* result.
|
106 |
|
|
* @param k the session key to use.
|
107 |
|
|
* @param bs the block size to use.
|
108 |
|
|
* @exception IllegalArgumentException if the block size is invalid.
|
109 |
|
|
* @exception ArrayIndexOutOfBoundsException if there is not enough room in
|
110 |
|
|
* either the plaintext or ciphertext buffers.
|
111 |
|
|
*/
|
112 |
|
|
void decrypt(byte[] in, int inOffset, byte[] out, int outOffset, Object k,
|
113 |
|
|
int bs);
|
114 |
|
|
|
115 |
|
|
/**
|
116 |
|
|
* A <i>correctness</i> test that consists of basic symmetric encryption /
|
117 |
|
|
* decryption test(s) for all supported block and key sizes, as well as one
|
118 |
|
|
* (1) variable key Known Answer Test (KAT).
|
119 |
|
|
*
|
120 |
|
|
* @return <code>true</code> if the implementation passes simple
|
121 |
|
|
* <i>correctness</i> tests. Returns <code>false</code> otherwise.
|
122 |
|
|
*/
|
123 |
|
|
boolean selfTest();
|
124 |
|
|
}
|