blob: b10ad367f8ca35095744f7b707f87291c4c6dd81 (
plain)
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
|
package org.spongycastle.crypto.prng.test;
import org.spongycastle.crypto.prng.FixedSecureRandom;
import org.spongycastle.util.Arrays;
import org.spongycastle.util.encoders.Hex;
import org.spongycastle.util.test.SimpleTest;
public class FixedSecureRandomTest
extends SimpleTest
{
byte[] base = Hex.decode("deadbeefdeadbeef");
byte[] r1 = Hex.decode("cafebabecafebabe");
byte[] r2 = Hex.decode("ffffffffcafebabedeadbeef");
public String getName()
{
return "FixedSecureRandom";
}
public void performTest()
throws Exception
{
FixedSecureRandom fixed = new FixedSecureRandom(base);
byte[] buf = new byte[8];
fixed.nextBytes(buf);
if (!Arrays.areEqual(buf, base))
{
fail("wrong data returned");
}
fixed = new FixedSecureRandom(base);
byte[] seed = fixed.generateSeed(8);
if (!Arrays.areEqual(seed, base))
{
fail("wrong seed data returned");
}
if (!fixed.isExhausted())
{
fail("not exhausted");
}
fixed = new FixedSecureRandom(new byte[][] { r1, r2 });
seed = fixed.generateSeed(12);
if (!Arrays.areEqual(seed, Hex.decode("cafebabecafebabeffffffff")))
{
fail("wrong seed data returned - composite");
}
fixed.nextBytes(buf);
if (!Arrays.areEqual(buf, Hex.decode("cafebabedeadbeef")))
{
fail("wrong data returned");
}
}
public static void main(String[] args)
{
runTest(new FixedSecureRandomTest());
}
}
|