1
package org.bouncycastle.crypto.test;
3
import org.bouncycastle.crypto.BlockCipher;
4
import org.bouncycastle.crypto.BufferedBlockCipher;
5
import org.bouncycastle.crypto.CipherParameters;
6
import org.bouncycastle.crypto.engines.DESEngine;
7
import org.bouncycastle.crypto.engines.SkipjackEngine;
8
import org.bouncycastle.crypto.modes.CBCBlockCipher;
9
import org.bouncycastle.crypto.modes.CTSBlockCipher;
10
import org.bouncycastle.crypto.params.KeyParameter;
11
import org.bouncycastle.crypto.params.ParametersWithIV;
12
import org.bouncycastle.util.encoders.Hex;
13
import org.bouncycastle.util.test.SimpleTest;
21
static byte[] in1 = Hex.decode("4e6f7720697320746865207420");
22
static byte[] in2 = Hex.decode("000102030405060708090a0b0c0d0e0fff0102030405060708090a0b0c0d0e0f0aaa");
23
static byte[] out1 = Hex.decode("9952f131588465033fa40e8a98");
24
static byte[] out2 = Hex.decode("358f84d01eb42988dc34efb994");
25
static byte[] out3 = Hex.decode("170171cfad3f04530c509b0c1f0be0aefbd45a8e3755a873bff5ea198504b71683c6");
30
CipherParameters params,
35
byte[] out = new byte[input.length];
36
BufferedBlockCipher engine = new CTSBlockCipher(cipher);
38
engine.init(true, params);
40
int len = engine.processBytes(input, 0, input.length, out, 0);
42
engine.doFinal(out, len);
44
if (!areEqual(output, out))
46
fail("failed encryption expected " + new String(Hex.encode(output)) + " got " + new String(Hex.encode(out)));
49
engine.init(false, params);
51
len = engine.processBytes(output, 0, output.length, out, 0);
53
engine.doFinal(out, len);
55
if (!areEqual(input, out))
57
fail("failed encryption expected " + new String(Hex.encode(input)) + " got " + new String(Hex.encode(out)));
61
public String getName()
66
public void performTest()
69
byte[] key1 = { (byte)0x01, (byte)0x23, (byte)0x45, (byte)0x67, (byte)0x89, (byte)0xAB, (byte)0xCD, (byte)0xEF };
70
byte[] key2 = { (byte)0x01, (byte)0x23, (byte)0x45, (byte)0x67, (byte)0x89, (byte)0xAB, (byte)0xCD, (byte)0xEF, (byte)0xee, (byte)0xff };
71
byte[] iv = { 1, 2, 3, 4, 5, 6, 7, 8 };
73
testCTS(1, new DESEngine(), new KeyParameter(key1), in1, out1);
74
testCTS(2, new CBCBlockCipher(new DESEngine()), new ParametersWithIV(new KeyParameter(key1), iv), in1, out2);
75
testCTS(3, new CBCBlockCipher(new SkipjackEngine()), new ParametersWithIV(new KeyParameter(key2), iv), in2, out3);
78
public static void main(
81
runTest(new CTSTest());