Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Hook <dgh@cryptoworkshop.com>2013-12-08 04:33:19 +0400
committerDavid Hook <dgh@cryptoworkshop.com>2013-12-08 04:33:19 +0400
commit35c8113aa1c698e18595466177a5e38e43cddb43 (patch)
tree62f215cbd7eaa1fdbe982eb3e8fd28354e16bb6d /prov/src/test/java/org/bouncycastle/jce/provider/test/DHTest.java
parentb8e38c629e9d81df3e7c1bf7a8b2311a18ce5e20 (diff)
added provider alias for ECDHwithSHA1KDF, added key length support to engine generate secret.
removed other uses of DERObjectIdentifier.
Diffstat (limited to 'prov/src/test/java/org/bouncycastle/jce/provider/test/DHTest.java')
-rw-r--r--prov/src/test/java/org/bouncycastle/jce/provider/test/DHTest.java56
1 files changed, 56 insertions, 0 deletions
diff --git a/prov/src/test/java/org/bouncycastle/jce/provider/test/DHTest.java b/prov/src/test/java/org/bouncycastle/jce/provider/test/DHTest.java
index 4ab21edf..6b9ad4e5 100644
--- a/prov/src/test/java/org/bouncycastle/jce/provider/test/DHTest.java
+++ b/prov/src/test/java/org/bouncycastle/jce/provider/test/DHTest.java
@@ -33,9 +33,11 @@ import javax.crypto.spec.DHPublicKeySpec;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.jcajce.provider.config.ConfigurableProvider;
+import org.bouncycastle.jce.ECNamedCurveTable;
import org.bouncycastle.jce.ECPointUtil;
import org.bouncycastle.jce.interfaces.PKCS12BagAttributeCarrier;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.encoders.Base64;
import org.bouncycastle.util.encoders.Hex;
@@ -567,6 +569,53 @@ public class DHTest
fail(size + " bit 3-way test failed (c and b differ)");
}
}
+
+ private void testECDH(String algorithm, String cipher, int keyLen)
+ throws Exception
+ {
+ ECNamedCurveParameterSpec parameterSpec = ECNamedCurveTable.getParameterSpec("secp521r1");
+ KeyPairGenerator g = KeyPairGenerator.getInstance(algorithm, "BC");
+
+ g.initialize(parameterSpec);
+
+ //
+ // a side
+ //
+ KeyPair aKeyPair = g.generateKeyPair();
+
+ KeyAgreement aKeyAgree = KeyAgreement.getInstance(algorithm, "BC");
+
+ aKeyAgree.init(aKeyPair.getPrivate());
+
+ //
+ // b side
+ //
+ KeyPair bKeyPair = g.generateKeyPair();
+
+ KeyAgreement bKeyAgree = KeyAgreement.getInstance(algorithm, "BC");
+
+ bKeyAgree.init(bKeyPair.getPrivate());
+
+ //
+ // agreement
+ //
+ aKeyAgree.doPhase(bKeyPair.getPublic(), true);
+ bKeyAgree.doPhase(aKeyPair.getPublic(), true);
+
+ SecretKey k1 = aKeyAgree.generateSecret(cipher);
+ SecretKey k2 = bKeyAgree.generateSecret(cipher);
+
+ if (!k1.equals(k2))
+ {
+ fail(algorithm + " 2-way test failed");
+ }
+
+ if (k1.getEncoded().length != keyLen / 8)
+ {
+ fail("key for " + cipher + " the wrong size expected " + keyLen / 8 + " got " + k1.getEncoded().length);
+ }
+ }
+
private void testECDH(String algorithm)
throws Exception
{
@@ -915,8 +964,15 @@ public class DHTest
testGP("DIFFIEHELLMAN", 1024, 256, g1024, p1024);
testExplicitWrapping(512, 0, g512, p512);
testRandom(256);
+
testECDH("ECDH");
testECDH("ECDHC");
+ testECDH("ECDH", "AES", 256);
+ testECDH("ECDH", "DESEDE", 192);
+ testECDH("ECDH", "DES", 64);
+ testECDH("ECDHwithSHA1KDF", "AES", 256);
+ testECDH("ECDHwithSHA1KDF", "DESEDE", 192);
+
testExceptions();
testDESAndDESede(g768, p768);
testInitialise();