01: package org.bouncycastle.crypto.test;
02:
03: import org.bouncycastle.crypto.CipherParameters;
04: import org.bouncycastle.crypto.StreamCipher;
05: import org.bouncycastle.util.encoders.Hex;
06: import org.bouncycastle.util.test.SimpleTest;
07:
08: /**
09: * a basic test that takes a stream cipher, key parameter, and an input
10: * and output string.
11: */
12: public class StreamCipherVectorTest extends SimpleTest {
13: int id;
14: StreamCipher cipher;
15: CipherParameters param;
16: byte[] input;
17: byte[] output;
18:
19: public StreamCipherVectorTest(int id, StreamCipher cipher,
20: CipherParameters param, String input, String output) {
21: this .id = id;
22: this .cipher = cipher;
23: this .param = param;
24: this .input = Hex.decode(input);
25: this .output = Hex.decode(output);
26: }
27:
28: public String getName() {
29: return cipher.getAlgorithmName() + " Vector Test " + id;
30: }
31:
32: public void performTest() {
33: cipher.init(true, param);
34:
35: byte[] out = new byte[input.length];
36:
37: cipher.processBytes(input, 0, input.length, out, 0);
38:
39: if (!areEqual(out, output)) {
40: fail("failed.", new String(Hex.encode(output)), new String(
41: Hex.encode(out)));
42: }
43:
44: cipher.init(false, param);
45:
46: cipher.processBytes(output, 0, output.length, out, 0);
47:
48: if (!areEqual(input, out)) {
49: fail("failed reversal");
50: }
51: }
52: }
|