2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
5506
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
package com.sun.crypto.provider;
|
|
27 |
|
|
28 |
import java.security.InvalidKeyException;
|
|
29 |
|
|
30 |
/**
|
|
31 |
* This abstract class represents the core of all block ciphers. It allows to
|
|
32 |
* intialize the cipher and encrypt/decrypt single blocks. Larger quantities
|
|
33 |
* are handled by modes, which are subclasses of FeedbackCipher.
|
|
34 |
*
|
|
35 |
* @author Gigi Ankeny
|
|
36 |
* @author Jan Luehe
|
|
37 |
*
|
|
38 |
*
|
|
39 |
* @see AESCrypt
|
|
40 |
* @see DESCrypt
|
|
41 |
* @see DESedeCrypt
|
|
42 |
* @see BlowfishCrypt
|
|
43 |
* @see FeedbackCipher
|
|
44 |
*/
|
|
45 |
abstract class SymmetricCipher {
|
|
46 |
|
|
47 |
SymmetricCipher() {
|
|
48 |
// empty
|
|
49 |
}
|
|
50 |
|
|
51 |
/**
|
|
52 |
* Retrieves this cipher's block size.
|
|
53 |
*
|
|
54 |
* @return the block size of this cipher
|
|
55 |
*/
|
|
56 |
abstract int getBlockSize();
|
|
57 |
|
|
58 |
/**
|
|
59 |
* Initializes the cipher in the specified mode with the given key.
|
|
60 |
*
|
|
61 |
* @param decrypting flag indicating encryption or decryption
|
|
62 |
* @param algorithm the algorithm name
|
|
63 |
* @param key the key
|
|
64 |
*
|
|
65 |
* @exception InvalidKeyException if the given key is inappropriate for
|
|
66 |
* initializing this cipher
|
|
67 |
*/
|
|
68 |
abstract void init(boolean decrypting, String algorithm, byte[] key)
|
|
69 |
throws InvalidKeyException;
|
|
70 |
|
|
71 |
/**
|
|
72 |
* Encrypt one cipher block.
|
|
73 |
*
|
|
74 |
* <p>The input <code>plain</code>, starting at <code>plainOffset</code>
|
|
75 |
* and ending at <code>(plainOffset+blockSize-1)</code>, is encrypted.
|
|
76 |
* The result is stored in <code>cipher</code>, starting at
|
|
77 |
* <code>cipherOffset</code>.
|
|
78 |
*
|
|
79 |
* @param plain the input buffer with the data to be encrypted
|
|
80 |
* @param plainOffset the offset in <code>plain</code>
|
|
81 |
* @param cipher the buffer for the encryption result
|
|
82 |
* @param cipherOffset the offset in <code>cipher</code>
|
|
83 |
*/
|
|
84 |
abstract void encryptBlock(byte[] plain, int plainOffset,
|
|
85 |
byte[] cipher, int cipherOffset);
|
|
86 |
|
|
87 |
/**
|
|
88 |
* Decrypt one cipher block.
|
|
89 |
*
|
|
90 |
* <p>The input <code>cipher</code>, starting at <code>cipherOffset</code>
|
|
91 |
* and ending at <code>(cipherOffset+blockSize-1)</code>, is decrypted.
|
|
92 |
* The result is stored in <code>plain</code>, starting at
|
|
93 |
* <code>plainOffset</code>.
|
|
94 |
*
|
|
95 |
* @param cipher the input buffer with the data to be decrypted
|
|
96 |
* @param cipherOffset the offset in <code>cipher</code>
|
|
97 |
* @param plain the buffer for the decryption result
|
|
98 |
* @param plainOffset the offset in <code>plain</code>
|
|
99 |
*/
|
|
100 |
abstract void decryptBlock(byte[] cipher, int cipherOffset,
|
|
101 |
byte[] plain, int plainOffset);
|
|
102 |
}
|