Imported GNU Classpath 0.90
[official-gcc.git] / libjava / classpath / gnu / javax / crypto / cipher / IBlockCipherSpi.java
blob6fe07ca7f509a79752a2196a6c7e489d91245ee9
1 /* IBlockCipherSpi.java --
2 Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc.
4 This file is a part of GNU Classpath.
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.
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.
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
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.
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. */
39 package gnu.javax.crypto.cipher;
41 import java.security.InvalidKeyException;
42 import java.util.Iterator;
44 /**
45 * <p>Package-private interface exposing mandatory methods to be implemented by
46 * concrete {@link gnu.crypto.cipher.BaseCipher} sub-classes.</p>
48 interface IBlockCipherSpi extends Cloneable
51 // Constants
52 // -------------------------------------------------------------------------
54 // Methods
55 // -------------------------------------------------------------------------
57 /**
58 * <p>Returns an {@link java.util.Iterator} over the supported block sizes.
59 * Each element returned by this object is a {@link java.lang.Integer}.</p>
61 * @return an <code>Iterator</code> over the supported block sizes.
63 Iterator blockSizes();
65 /**
66 * <p>Returns an {@link java.util.Iterator} over the supported key sizes.
67 * Each element returned by this object is a {@link java.lang.Integer}.</p>
69 * @return an <code>Iterator</code> over the supported key sizes.
71 Iterator keySizes();
73 /**
74 * <p>Expands a user-supplied key material into a session key for a
75 * designated <i>block size</i>.</p>
77 * @param k the user-supplied key material.
78 * @param bs the desired block size in bytes.
79 * @return an Object encapsulating the session key.
80 * @exception IllegalArgumentException if the block size is invalid.
81 * @exception InvalidKeyException if the key data is invalid.
83 Object makeKey(byte[] k, int bs) throws InvalidKeyException;
85 /**
86 * <p>Encrypts exactly one block of plaintext.</p>
88 * @param in the plaintext.
89 * @param inOffset index of <code>in</code> from which to start considering
90 * data.
91 * @param out the ciphertext.
92 * @param outOffset index of <code>out</code> from which to store the result.
93 * @param k the session key to use.
94 * @param bs the block size to use.
95 * @exception IllegalArgumentException if the block size is invalid.
96 * @exception ArrayIndexOutOfBoundsException if there is not enough room in
97 * either the plaintext or ciphertext buffers.
99 void encrypt(byte[] in, int inOffset, byte[] out, int outOffset, Object k,
100 int bs);
103 * <p>Decrypts exactly one block of ciphertext.</p>
105 * @param in the ciphertext.
106 * @param inOffset index of <code>in</code> from which to start considering
107 * data.
108 * @param out the plaintext.
109 * @param outOffset index of <code>out</code> from which to store the result.
110 * @param k the session key to use.
111 * @param bs the block size to use.
112 * @exception IllegalArgumentException if the block size is invalid.
113 * @exception ArrayIndexOutOfBoundsException if there is not enough room in
114 * either the plaintext or ciphertext buffers.
116 void decrypt(byte[] in, int inOffset, byte[] out, int outOffset, Object k,
117 int bs);
120 * <p>A <i>correctness</i> test that consists of basic symmetric encryption /
121 * decryption test(s) for all supported block and key sizes, as well as one
122 * (1) variable key Known Answer Test (KAT).</p>
124 * @return <code>true</code> if the implementation passes simple
125 * <i>correctness</i> tests. Returns <code>false</code> otherwise.
127 boolean selfTest();