1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
package org.bouncycastle.crypto.test;
import org.bouncycastle.crypto.BlockCipher;
import org.bouncycastle.crypto.DataLengthException;
import org.bouncycastle.crypto.params.KeyParameter;
import org.bouncycastle.util.test.SimpleTest;
public abstract class CipherTest
extends SimpleTest
{
private SimpleTest[] _tests;
private BlockCipher _engine;
private KeyParameter _validKey;
// protected CipherTest(
// SimpleTest[] tests)
// {
// _tests = tests;
// }
protected CipherTest(
SimpleTest[] tests,
BlockCipher engine,
KeyParameter validKey)
{
_tests = tests;
_engine = engine;
_validKey = validKey;
}
public abstract String getName();
public void performTest()
throws Exception
{
for (int i = 0; i != _tests.length; i++)
{
_tests[i].performTest();
}
if (_engine != null)
{
//
// state tests
//
byte[] buf = new byte[128];
try
{
_engine.processBlock(buf, 0, buf, 0);
fail("failed initialisation check");
}
catch (IllegalStateException e)
{
// expected
}
bufferSizeCheck((_engine));
}
}
private void bufferSizeCheck(
BlockCipher engine)
{
byte[] correctBuf = new byte[engine.getBlockSize()];
byte[] shortBuf = new byte[correctBuf.length / 2];
engine.init(true, _validKey);
try
{
engine.processBlock(shortBuf, 0, correctBuf, 0);
fail("failed short input check");
}
catch (DataLengthException e)
{
// expected
}
try
{
engine.processBlock(correctBuf, 0, shortBuf, 0);
fail("failed short output check");
}
catch (DataLengthException e)
{
// expected
}
engine.init(false, _validKey);
try
{
engine.processBlock(shortBuf, 0, correctBuf, 0);
fail("failed short input check");
}
catch (DataLengthException e)
{
// expected
}
try
{
engine.processBlock(correctBuf, 0, shortBuf, 0);
fail("failed short output check");
}
catch (DataLengthException e)
{
// expected
}
}
}
|