summaryrefslogtreecommitdiffstats
path: root/bcprov/src/main/java/org/bouncycastle/jce/provider/test/ECIESTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'bcprov/src/main/java/org/bouncycastle/jce/provider/test/ECIESTest.java')
-rw-r--r--bcprov/src/main/java/org/bouncycastle/jce/provider/test/ECIESTest.java100
1 files changed, 73 insertions, 27 deletions
diff --git a/bcprov/src/main/java/org/bouncycastle/jce/provider/test/ECIESTest.java b/bcprov/src/main/java/org/bouncycastle/jce/provider/test/ECIESTest.java
index 9af0670..ad2b8b2 100644
--- a/bcprov/src/main/java/org/bouncycastle/jce/provider/test/ECIESTest.java
+++ b/bcprov/src/main/java/org/bouncycastle/jce/provider/test/ECIESTest.java
@@ -1,5 +1,6 @@
package org.bouncycastle.jce.provider.test;
+import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
@@ -85,8 +86,30 @@ public class ECIESTest
// Testing ECIES with 256-bit curve using DES
g.initialize(256, new SecureRandom());
doTest("256-bit", g, "ECIESwithDESEDE", params);
-
-
+
+ // Testing ECIES with 256-bit curve using DES-CBC
+ g.initialize(256, new SecureRandom());
+ doTest("256-bit", g, "ECIESwithDESEDE-CBC", params);
+
+ params = new IESParameterSpec(derivation, encoding, 128, 128, Hex.decode("0001020304050607"));
+ g.initialize(256, new SecureRandom());
+ doTest("256-bit", g, "ECIESwithDESEDE-CBC", params);
+
+ try
+ {
+ params = new IESParameterSpec(derivation, encoding, 128, 128, new byte[10]);
+ g.initialize(256, new SecureRandom());
+ doTest("256-bit", g, "ECIESwithDESEDE-CBC", params);
+ fail("DESEDE no exception!");
+ }
+ catch (InvalidAlgorithmParameterException e)
+ {
+ if (!e.getMessage().equals("NONCE in IES Parameters needs to be 8 bytes long"))
+ {
+ fail("DESEDE wrong message!");
+ }
+ }
+
c1 = new org.bouncycastle.jcajce.provider.asymmetric.ec.IESCipher.ECIESwithAES();
c2 = new org.bouncycastle.jcajce.provider.asymmetric.ec.IESCipher.ECIESwithAES();
params = new IESParameterSpec(derivation, encoding, 128, 128);
@@ -102,7 +125,29 @@ public class ECIESTest
// Testing ECIES with 256-bit curve using AES
g.initialize(256, new SecureRandom());
doTest("256-bit", g, "ECIESwithAES", params);
-
+
+ // Testing ECIES with 256-bit curve using AES-CBC
+ g.initialize(256, new SecureRandom());
+ doTest("256-bit", g, "ECIESwithAES-CBC", params);
+
+ params = new IESParameterSpec(derivation, encoding, 128, 128, Hex.decode("000102030405060708090a0b0c0d0e0f"));
+ g.initialize(256, new SecureRandom());
+ doTest("256-bit", g, "ECIESwithAES-CBC", params);
+
+ try
+ {
+ params = new IESParameterSpec(derivation, encoding, 128, 128, new byte[10]);
+ g.initialize(256, new SecureRandom());
+ doTest("256-bit", g, "ECIESwithAES-CBC", params);
+ fail("AES no exception!");
+ }
+ catch (InvalidAlgorithmParameterException e)
+ {
+ if (!e.getMessage().equals("NONCE in IES Parameters needs to be 16 bytes long"))
+ {
+ fail("AES wrong message!");
+ }
+ }
}
public void doTest(
@@ -112,7 +157,7 @@ public class ECIESTest
IESParameterSpec p)
throws Exception
{
-
+
byte[] message = Hex.decode("0102030405060708090a0b0c0d0e0f10111213141516");
byte[] out1, out2;
@@ -142,29 +187,30 @@ public class ECIESTest
fail(testname + " test failed with non-null parameters, DHAES mode false.");
- c1 = Cipher.getInstance(cipher + "/DHAES/PKCS7Padding","BC");
- c2 = Cipher.getInstance(cipher + "/DHAES/PKCS7Padding","BC");
-
- // Testing with null parameters and DHAES mode on
- c1.init(Cipher.ENCRYPT_MODE, Pub, new SecureRandom());
- c2.init(Cipher.DECRYPT_MODE, Priv, new SecureRandom());
-
- out1 = c1.doFinal(message, 0, message.length);
- out2 = c2.doFinal(out1, 0, out1.length);
- if (!areEqual(out2, message))
- fail(testname + " test failed with null parameters, DHAES mode true.");
-
- c1 = Cipher.getInstance(cipher + "/DHAES/PKCS7Padding");
- c2 = Cipher.getInstance(cipher + "/DHAES/PKCS7Padding");
-
- // Testing with given parameters and DHAES mode on
- c1.init(Cipher.ENCRYPT_MODE, Pub, p, new SecureRandom());
- c2.init(Cipher.DECRYPT_MODE, Priv, p, new SecureRandom());
-
- out1 = c1.doFinal(message, 0, message.length);
- out2 = c2.doFinal(out1, 0, out1.length);
- if (!areEqual(out2, message))
- fail(testname + " test failed with non-null parameters, DHAES mode true.");
+// TODO: DHAES mode is not currently implemented, perhaps it shouldn't be...
+// c1 = Cipher.getInstance(cipher + "/DHAES/PKCS7Padding","BC");
+// c2 = Cipher.getInstance(cipher + "/DHAES/PKCS7Padding","BC");
+//
+// // Testing with null parameters and DHAES mode on
+// c1.init(Cipher.ENCRYPT_MODE, Pub, new SecureRandom());
+// c2.init(Cipher.DECRYPT_MODE, Priv, new SecureRandom());
+//
+// out1 = c1.doFinal(message, 0, message.length);
+// out2 = c2.doFinal(out1, 0, out1.length);
+// if (!areEqual(out2, message))
+// fail(testname + " test failed with null parameters, DHAES mode true.");
+//
+// c1 = Cipher.getInstance(cipher + "/DHAES/PKCS7Padding");
+// c2 = Cipher.getInstance(cipher + "/DHAES/PKCS7Padding");
+//
+// // Testing with given parameters and DHAES mode on
+// c1.init(Cipher.ENCRYPT_MODE, Pub, p, new SecureRandom());
+// c2.init(Cipher.DECRYPT_MODE, Priv, p, new SecureRandom());
+//
+// out1 = c1.doFinal(message, 0, message.length);
+// out2 = c2.doFinal(out1, 0, out1.length);
+// if (!areEqual(out2, message))
+// fail(testname + " test failed with non-null parameters, DHAES mode true.");
}