comparison src/com/trilead/ssh2/crypto/cipher/DESede.java @ 0:0ce5cc452d02

initial version
author Carl Byington <carl@five-ten-sg.com>
date Thu, 22 May 2014 10:41:19 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:0ce5cc452d02
1
2 package com.trilead.ssh2.crypto.cipher;
3
4 /*
5 This file was shamelessly taken (and modified) from the Bouncy Castle Crypto package.
6 Their licence file states the following:
7
8 Copyright (c) 2000 - 2004 The Legion Of The Bouncy Castle
9 (http://www.bouncycastle.org)
10
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is
16 furnished to do so, subject to the following conditions:
17
18 The above copyright notice and this permission notice shall be included in
19 all copies or substantial portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 THE SOFTWARE.
28 */
29
30 /**
31 * DESede.
32 *
33 * @author See comments in the source file
34 * @version $Id: DESede.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
35 *
36 */
37 public class DESede extends DES {
38 private int[] key1 = null;
39 private int[] key2 = null;
40 private int[] key3 = null;
41
42 private boolean encrypt;
43
44 /**
45 * standard constructor.
46 */
47 public DESede() {
48 }
49
50 /**
51 * initialise a DES cipher.
52 *
53 * @param encrypting
54 * whether or not we are for encryption.
55 * @param key
56 * the parameters required to set up the cipher.
57 * @exception IllegalArgumentException
58 * if the params argument is inappropriate.
59 */
60 public void init(boolean encrypting, byte[] key) {
61 key1 = generateWorkingKey(encrypting, key, 0);
62 key2 = generateWorkingKey(!encrypting, key, 8);
63 key3 = generateWorkingKey(encrypting, key, 16);
64 encrypt = encrypting;
65 }
66
67 public String getAlgorithmName() {
68 return "DESede";
69 }
70
71 public int getBlockSize() {
72 return 8;
73 }
74
75 public void transformBlock(byte[] in, int inOff, byte[] out, int outOff) {
76 if (key1 == null) {
77 throw new IllegalStateException("DESede engine not initialised!");
78 }
79
80 if (encrypt) {
81 desFunc(key1, in, inOff, out, outOff);
82 desFunc(key2, out, outOff, out, outOff);
83 desFunc(key3, out, outOff, out, outOff);
84 }
85 else {
86 desFunc(key3, in, inOff, out, outOff);
87 desFunc(key2, out, outOff, out, outOff);
88 desFunc(key1, out, outOff, out, outOff);
89 }
90 }
91
92 public void reset() {
93 }
94 }