01: package org.bouncycastle.crypto.test;
02:
03: import org.bouncycastle.asn1.DERObjectIdentifier;
04: import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
05: import org.bouncycastle.crypto.DerivationFunction;
06: import org.bouncycastle.crypto.DerivationParameters;
07: import org.bouncycastle.crypto.agreement.kdf.DHKDFParameters;
08: import org.bouncycastle.crypto.agreement.kdf.DHKEKGenerator;
09: import org.bouncycastle.crypto.digests.SHA1Digest;
10: import org.bouncycastle.util.encoders.Hex;
11: import org.bouncycastle.util.test.SimpleTest;
12:
13: /**
14: * DHKEK Generator tests - from RFC 2631.
15: */
16: public class DHKEKGeneratorTest extends SimpleTest {
17: private byte[] seed1 = Hex
18: .decode("000102030405060708090a0b0c0d0e0f10111213");
19: private DERObjectIdentifier alg1 = PKCSObjectIdentifiers.id_alg_CMS3DESwrap;
20: private byte[] result1 = Hex
21: .decode("a09661392376f7044d9052a397883246b67f5f1ef63eb5fb");
22:
23: private byte[] seed2 = Hex
24: .decode("000102030405060708090a0b0c0d0e0f10111213");
25: private DERObjectIdentifier alg2 = PKCSObjectIdentifiers.id_alg_CMSRC2wrap;
26: private byte[] partyAInfo = Hex
27: .decode("0123456789abcdeffedcba9876543201"
28: + "0123456789abcdeffedcba9876543201"
29: + "0123456789abcdeffedcba9876543201"
30: + "0123456789abcdeffedcba9876543201");
31: private byte[] result2 = Hex
32: .decode("48950c46e0530075403cce72889604e0");
33:
34: public DHKEKGeneratorTest() {
35: }
36:
37: public void performTest() {
38: checkMask(1, new DHKEKGenerator(new SHA1Digest()),
39: new DHKDFParameters(alg1, 192, seed1), result1);
40: checkMask(2, new DHKEKGenerator(new SHA1Digest()),
41: new DHKDFParameters(alg2, 128, seed2, partyAInfo),
42: result2);
43: }
44:
45: private void checkMask(int count, DerivationFunction kdf,
46: DerivationParameters params, byte[] result) {
47: byte[] data = new byte[result.length];
48:
49: kdf.init(params);
50:
51: kdf.generateBytes(data, 0, data.length);
52:
53: if (!areEqual(result, data)) {
54: fail("DHKEKGenerator failed generator test " + count);
55: }
56: }
57:
58: public String getName() {
59: return "DHKEKGenerator";
60: }
61:
62: public static void main(String[] args) {
63: runTest(new DHKEKGeneratorTest());
64: }
65: }
|