1 2 package ch.ethz.ssh2.crypto.cipher; 3 4 29 30 37 public class DESede extends DES 38 { 39 private int[] key1 = null; 40 private int[] key2 = null; 41 private int[] key3 = null; 42 43 private boolean encrypt; 44 45 48 public DESede() 49 { 50 } 51 52 62 public void init(boolean encrypting, byte[] key) 63 { 64 key1 = generateWorkingKey(encrypting, key, 0); 65 key2 = generateWorkingKey(!encrypting, key, 8); 66 key3 = generateWorkingKey(encrypting, key, 16); 67 68 encrypt = encrypting; 69 } 70 71 public String getAlgorithmName() 72 { 73 return "DESede"; 74 } 75 76 public int getBlockSize() 77 { 78 return 8; 79 } 80 81 public void transformBlock(byte[] in, int inOff, byte[] out, int outOff) 82 { 83 if (key1 == null) 84 { 85 throw new IllegalStateException ("DESede engine not initialised!"); 86 } 87 88 if (encrypt) 89 { 90 desFunc(key1, in, inOff, out, outOff); 91 desFunc(key2, out, outOff, out, outOff); 92 desFunc(key3, out, outOff, out, outOff); 93 } 94 else 95 { 96 desFunc(key3, in, inOff, out, outOff); 97 desFunc(key2, out, outOff, out, outOff); 98 desFunc(key1, out, outOff, out, outOff); 99 } 100 } 101 102 public void reset() 103 { 104 } 105 } 106 | Popular Tags |