01: package org.bouncycastle.crypto.test;
02:
03: import org.bouncycastle.asn1.DERObjectIdentifier;
04: import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
05: import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
06: import org.bouncycastle.crypto.DerivationFunction;
07: import org.bouncycastle.crypto.DerivationParameters;
08: import org.bouncycastle.crypto.agreement.kdf.DHKDFParameters;
09: import org.bouncycastle.crypto.agreement.kdf.ECDHKEKGenerator;
10: import org.bouncycastle.crypto.digests.SHA1Digest;
11: import org.bouncycastle.util.encoders.Hex;
12: import org.bouncycastle.util.test.SimpleTest;
13:
14: /**
15: * ECDHKEK Generator tests.
16: */
17: public class ECDHKEKGeneratorTest extends SimpleTest {
18: private byte[] seed1 = Hex
19: .decode("db4a8daba1f98791d54e940175dd1a5f3a0826a1066aa9b668d4dc1e1e0790158dcad1533c03b44214d1b61fefa8b579");
20: private DERObjectIdentifier alg1 = NISTObjectIdentifiers.id_aes256_wrap;
21: private byte[] result1 = Hex
22: .decode("8ecc6d85caf25eaba823a7d620d4ab0d33e4c645f2");
23:
24: private byte[] seed2 = Hex
25: .decode("75d7487b5d3d2bfb3c69ce0365fe64e3bfab5d0d63731628a9f47eb8fddfa28c65decaf228a0b38f0c51c6a3356d7c56");
26: private DERObjectIdentifier alg2 = NISTObjectIdentifiers.id_aes128_wrap;
27: private byte[] result2 = Hex
28: .decode("042be1faca3a4a8fc859241bfb87ba35");
29:
30: private byte[] seed3 = Hex
31: .decode("fdeb6d809f997e8ac174d638734dc36d37aaf7e876e39967cd82b1cada3de772449788461ee7f856bad9305627f8e48b");
32: private DERObjectIdentifier alg3 = PKCSObjectIdentifiers.id_alg_CMS3DESwrap;
33: private byte[] result3 = Hex
34: .decode("bcd701fc92109b1b9d6f3b6497ad5ca9627fa8a597010305");
35:
36: public ECDHKEKGeneratorTest() {
37: }
38:
39: public void performTest() {
40: checkMask(1, new ECDHKEKGenerator(new SHA1Digest()),
41: new DHKDFParameters(alg1, 256, seed1), result1);
42: checkMask(2, new ECDHKEKGenerator(new SHA1Digest()),
43: new DHKDFParameters(alg2, 128, seed2), result2);
44: checkMask(3, new ECDHKEKGenerator(new SHA1Digest()),
45: new DHKDFParameters(alg3, 192, seed3), result3);
46: }
47:
48: private void checkMask(int count, DerivationFunction kdf,
49: DerivationParameters params, byte[] result) {
50: byte[] data = new byte[result.length];
51:
52: kdf.init(params);
53:
54: kdf.generateBytes(data, 0, data.length);
55:
56: if (!areEqual(result, data)) {
57: fail("ECDHKEKGenerator failed generator test " + count);
58: }
59: }
60:
61: public String getName() {
62: return "ECDHKEKGenerator";
63: }
64:
65: public static void main(String[] args) {
66: runTest(new ECDHKEKGeneratorTest());
67: }
68: }
|