Mercurial > 510Connectbot
comparison src/ch/ethz/ssh2/crypto/cipher/DESede.java @ 307:071eccdff8ea ganymed
fix java formatting
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Wed, 30 Jul 2014 14:16:58 -0700 |
parents | 91a31873c42a |
children |
comparison
equal
deleted
inserted
replaced
305:d2b303406d63 | 307:071eccdff8ea |
---|---|
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
26 THE SOFTWARE. | 26 THE SOFTWARE. |
27 */ | 27 */ |
28 | 28 |
29 /** | 29 /** |
30 * DESede. | 30 * DESede. |
31 * | 31 * |
32 * @author See comments in the source file | 32 * @author See comments in the source file |
33 * @version 2.50, 03/15/10 | 33 * @version 2.50, 03/15/10 |
34 * | 34 * |
35 */ | 35 */ |
36 public class DESede extends DES | 36 public class DESede extends DES { |
37 { | 37 private int[] key1 = null; |
38 private int[] key1 = null; | 38 private int[] key2 = null; |
39 private int[] key2 = null; | 39 private int[] key3 = null; |
40 private int[] key3 = null; | |
41 | 40 |
42 private boolean encrypt; | 41 private boolean encrypt; |
43 | 42 |
44 /** | 43 /** |
45 * standard constructor. | 44 * standard constructor. |
46 */ | 45 */ |
47 public DESede() | 46 public DESede() { |
48 { | 47 } |
49 } | |
50 | 48 |
51 /** | 49 /** |
52 * initialise a DES cipher. | 50 * initialise a DES cipher. |
53 * | 51 * |
54 * @param encrypting | 52 * @param encrypting |
55 * whether or not we are for encryption. | 53 * whether or not we are for encryption. |
56 * @param key | 54 * @param key |
57 * the parameters required to set up the cipher. | 55 * the parameters required to set up the cipher. |
58 * @exception IllegalArgumentException | 56 * @exception IllegalArgumentException |
59 * if the params argument is inappropriate. | 57 * if the params argument is inappropriate. |
60 */ | 58 */ |
61 @Override | 59 @Override |
62 public void init(boolean encrypting, byte[] key) | 60 public void init(boolean encrypting, byte[] key) { |
63 { | 61 key1 = generateWorkingKey(encrypting, key, 0); |
64 key1 = generateWorkingKey(encrypting, key, 0); | 62 key2 = generateWorkingKey(!encrypting, key, 8); |
65 key2 = generateWorkingKey(!encrypting, key, 8); | 63 key3 = generateWorkingKey(encrypting, key, 16); |
66 key3 = generateWorkingKey(encrypting, key, 16); | 64 encrypt = encrypting; |
65 } | |
67 | 66 |
68 encrypt = encrypting; | 67 @Override |
69 } | 68 public String getAlgorithmName() { |
69 return "DESede"; | |
70 } | |
70 | 71 |
71 @Override | 72 @Override |
72 public String getAlgorithmName() | 73 public int getBlockSize() { |
73 { | 74 return 8; |
74 return "DESede"; | 75 } |
75 } | |
76 | 76 |
77 @Override | 77 @Override |
78 public int getBlockSize() | 78 public void transformBlock(byte[] in, int inOff, byte[] out, int outOff) { |
79 { | 79 if (key1 == null) { |
80 return 8; | 80 throw new IllegalStateException("DESede engine not initialised!"); |
81 } | 81 } |
82 | 82 |
83 @Override | 83 if (encrypt) { |
84 public void transformBlock(byte[] in, int inOff, byte[] out, int outOff) | 84 desFunc(key1, in, inOff, out, outOff); |
85 { | 85 desFunc(key2, out, outOff, out, outOff); |
86 if (key1 == null) | 86 desFunc(key3, out, outOff, out, outOff); |
87 { | 87 } |
88 throw new IllegalStateException("DESede engine not initialised!"); | 88 else { |
89 } | 89 desFunc(key3, in, inOff, out, outOff); |
90 desFunc(key2, out, outOff, out, outOff); | |
91 desFunc(key1, out, outOff, out, outOff); | |
92 } | |
93 } | |
90 | 94 |
91 if (encrypt) | 95 @Override |
92 { | 96 public void reset() { |
93 desFunc(key1, in, inOff, out, outOff); | 97 } |
94 desFunc(key2, out, outOff, out, outOff); | |
95 desFunc(key3, out, outOff, out, outOff); | |
96 } | |
97 else | |
98 { | |
99 desFunc(key3, in, inOff, out, outOff); | |
100 desFunc(key2, out, outOff, out, outOff); | |
101 desFunc(key1, out, outOff, out, outOff); | |
102 } | |
103 } | |
104 | |
105 @Override | |
106 public void reset() | |
107 { | |
108 } | |
109 } | 98 } |