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:
-rwxr-xr-xcore/src/main/java/org/bouncycastle/crypto/engines/IESEngine.java75
-rw-r--r--core/src/test/java/org/bouncycastle/crypto/test/ECIESTest.java36
-rw-r--r--prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/EC.java4
-rw-r--r--prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/ec/IESCipher.java58
-rw-r--r--prov/src/main/java/org/bouncycastle/jce/spec/IESParameterSpec.java37
-rwxr-xr-xprov/src/test/java/org/bouncycastle/jce/provider/test/ECIESTest.java100
6 files changed, 221 insertions, 89 deletions
diff --git a/core/src/main/java/org/bouncycastle/crypto/engines/IESEngine.java b/core/src/main/java/org/bouncycastle/crypto/engines/IESEngine.java
index d146d832..479dc44f 100755
--- a/core/src/main/java/org/bouncycastle/crypto/engines/IESEngine.java
+++ b/core/src/main/java/org/bouncycastle/crypto/engines/IESEngine.java
@@ -19,7 +19,6 @@ import org.bouncycastle.crypto.params.IESWithCipherParameters;
import org.bouncycastle.crypto.params.KDFParameters;
import org.bouncycastle.crypto.params.KeyParameter;
import org.bouncycastle.crypto.params.ParametersWithIV;
-import org.bouncycastle.crypto.prng.RandomGenerator;
import org.bouncycastle.crypto.util.Pack;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.BigIntegers;
@@ -35,7 +34,6 @@ public class IESEngine
DerivationFunction kdf;
Mac mac;
BufferedBlockCipher cipher;
- RandomGenerator nonceGenerator;
byte[] macBuf;
boolean forEncryption;
@@ -45,7 +43,7 @@ public class IESEngine
byte[] V;
private EphemeralKeyPairGenerator keyPairGenerator;
private KeyParser keyParser;
-
+ private byte[] IV;
/**
* set up for use with stream mode, where the key derivation function
@@ -91,50 +89,25 @@ public class IESEngine
}
/**
- * set up for use in conjunction with a block cipher mode of operating using
- * a nonce/IV to handle the message.
- *
- * @param agree the key agreement used as the basis for the encryption
- * @param kdf the key derivation function used for byte generation
- * @param mac the message authentication code generator for the message
- * @param cipher the cipher to used for encrypting the message
- * @param nonceGenerator the random generator that produces IVs used by the
- * block cipher, must be initialized.
- */
- public IESEngine(
- BasicAgreement agree,
- DerivationFunction kdf,
- Mac mac,
- BufferedBlockCipher cipher,
- RandomGenerator nonceGenerator)
- {
- this.agree = agree;
- this.kdf = kdf;
- this.mac = mac;
- this.macBuf = new byte[mac.getMacSize()];
- this.cipher = cipher;
- this.nonceGenerator = nonceGenerator;
- }
-
- /**
* Initialise the encryptor.
*
* @param forEncryption whether or not this is encryption/decryption.
* @param privParam our private key parameters
* @param pubParam the recipient's/sender's public key parameters
- * @param param encoding and derivation parameters.
+ * @param params encoding and derivation parameters, may be wrapped to include an IV for an underlying block cipher.
*/
public void init(
boolean forEncryption,
CipherParameters privParam,
CipherParameters pubParam,
- CipherParameters param)
+ CipherParameters params)
{
this.forEncryption = forEncryption;
this.privParam = privParam;
this.pubParam = pubParam;
- this.param = (IESParameters)param;
this.V = new byte[0];
+
+ extractParams(params);
}
@@ -142,30 +115,46 @@ public class IESEngine
* Initialise the encryptor.
*
* @param publicKey the recipient's/sender's public key parameters
- * @param params encoding and derivation parameters.
+ * @param params encoding and derivation parameters, may be wrapped to include an IV for an underlying block cipher.
* @param ephemeralKeyPairGenerator the ephemeral key pair generator to use.
*/
public void init(AsymmetricKeyParameter publicKey, CipherParameters params, EphemeralKeyPairGenerator ephemeralKeyPairGenerator)
{
this.forEncryption = true;
this.pubParam = publicKey;
- this.param = (IESParameters)params;
this.keyPairGenerator = ephemeralKeyPairGenerator;
+
+ extractParams(params);
}
/**
* Initialise the encryptor.
*
* @param privateKey the recipient's private key.
- * @param params encoding and derivation parameters.
+ * @param params encoding and derivation parameters, may be wrapped to include an IV for an underlying block cipher.
* @param publicKeyParser the parser for reading the ephemeral public key.
*/
public void init(AsymmetricKeyParameter privateKey, CipherParameters params, KeyParser publicKeyParser)
{
this.forEncryption = false;
this.privParam = privateKey;
- this.param = (IESParameters)params;
this.keyParser = publicKeyParser;
+
+ extractParams(params);
+ }
+
+ private void extractParams(CipherParameters params)
+ {
+ if (params instanceof ParametersWithIV)
+ {
+ this.IV = ((ParametersWithIV)params).getIV();
+ this.param = (IESParameters)((ParametersWithIV)params).getParameters();
+ }
+ else
+ {
+ this.IV = null;
+ this.param = (IESParameters)params;
+ }
}
public BufferedBlockCipher getCipher()
@@ -226,12 +215,9 @@ public class IESEngine
System.arraycopy(K, 0, K1, 0, K1.length);
System.arraycopy(K, K1.length, K2, 0, K2.length);
- // If nonceGenerator provided get an IV and initialize the cipher
- if (nonceGenerator != null)
+ // If iv provided use it to initialise the cipher
+ if (IV != null)
{
- byte[] IV = new byte[K1.length];
-
- nonceGenerator.nextBytes(IV);
cipher.init(true, new ParametersWithIV(new KeyParameter(K1), IV));
}
else
@@ -333,12 +319,9 @@ public class IESEngine
System.arraycopy(K, 0, K1, 0, K1.length);
System.arraycopy(K, K1.length, K2, 0, K2.length);
- // If nonceGenerator provided get an IV and initialize the cipher
- if (nonceGenerator != null)
+ // If IV provide use it to initialize the cipher
+ if (IV != null)
{
- byte[] IV = new byte[K1.length];
-
- nonceGenerator.nextBytes(IV);
cipher.init(false, new ParametersWithIV(new KeyParameter(K1), IV));
}
else
diff --git a/core/src/test/java/org/bouncycastle/crypto/test/ECIESTest.java b/core/src/test/java/org/bouncycastle/crypto/test/ECIESTest.java
index 488cb697..737cd860 100644
--- a/core/src/test/java/org/bouncycastle/crypto/test/ECIESTest.java
+++ b/core/src/test/java/org/bouncycastle/crypto/test/ECIESTest.java
@@ -5,6 +5,7 @@ import java.security.SecureRandom;
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
import org.bouncycastle.crypto.BufferedBlockCipher;
+import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.crypto.KeyEncoder;
import org.bouncycastle.crypto.KeyGenerationParameters;
import org.bouncycastle.crypto.agreement.ECDHBasicAgreement;
@@ -24,6 +25,7 @@ import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
import org.bouncycastle.crypto.params.IESParameters;
import org.bouncycastle.crypto.params.IESWithCipherParameters;
+import org.bouncycastle.crypto.params.ParametersWithIV;
import org.bouncycastle.crypto.parsers.ECIESPublicKeyParser;
import org.bouncycastle.math.ec.ECConstants;
import org.bouncycastle.math.ec.ECCurve;
@@ -36,6 +38,8 @@ import org.bouncycastle.util.test.SimpleTest;
public class ECIESTest
extends SimpleTest
{
+ private static byte[] TWOFISH_IV = Hex.decode("000102030405060708090a0b0c0d0e0f");
+
ECIESTest()
{
}
@@ -45,7 +49,7 @@ public class ECIESTest
return "ECIES";
}
- private void staticTest()
+ private void doStaticTest(byte[] iv)
throws Exception
{
BigInteger n = new BigInteger("6277101735386680763835789423176059013767194773182842284081");
@@ -85,7 +89,7 @@ public class ECIESTest
new HMac(new SHA1Digest()));
byte[] d = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
byte[] e = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 };
- IESParameters p = new IESParameters(d, e, 64);
+ CipherParameters p = new IESParameters(d, e, 64);
i1.init(true, p1.getPrivate(), p2.getPublic(), p);
i2.init(false, p2.getPrivate(), p1.getPublic(), p);
@@ -127,6 +131,11 @@ public class ECIESTest
e = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 };
p = new IESWithCipherParameters(d, e, 64, 128);
+ if (iv != null)
+ {
+ p = new ParametersWithIV(p, iv);
+ }
+
i1.init(true, p1.getPrivate(), p2.getPublic(), p);
i2.init(false, p2.getPrivate(), p1.getPublic(), p);
@@ -134,7 +143,9 @@ public class ECIESTest
out1 = i1.processBlock(message, 0, message.length);
- if (!areEqual(out1, Hex.decode("b8a06ea5c2b9df28b58a0a90a734cde8c9c02903e5c220021fe4417410d1e53a32a71696")))
+ if (!areEqual(out1, (iv == null) ?
+ Hex.decode("b8a06ea5c2b9df28b58a0a90a734cde8c9c02903e5c220021fe4417410d1e53a32a71696")
+ : Hex.decode("f246b0e26a2711992cac9c590d08e45c5e730b7c0f4218bb064e27b7dd7c8a3bd8bf01c3")))
{
fail("twofish cipher test failed on enc");
}
@@ -147,7 +158,7 @@ public class ECIESTest
}
}
- private void doEphemeralTest()
+ private void doEphemeralTest(byte[] iv)
throws Exception
{
BigInteger n = new BigInteger("6277101735386680763835789423176059013767194773182842284081");
@@ -198,9 +209,9 @@ public class ECIESTest
new KDF2BytesGenerator(new SHA1Digest()),
new HMac(new SHA1Digest()));
- byte[] d = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
- byte[] e = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 };
- IESParameters p = new IESParameters(d, e, 64);
+ byte[] d = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
+ byte[] e = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 };
+ CipherParameters p = new IESParameters(d, e, 64);
i1.init(p2.getPublic(), p, ephKeyGen);
i2.init(p2.getPrivate(), p, new ECIESPublicKeyParser(params));
@@ -237,6 +248,11 @@ public class ECIESTest
e = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 };
p = new IESWithCipherParameters(d, e, 64, 128);
+ if (iv != null)
+ {
+ p = new ParametersWithIV(p, iv);
+ }
+
i1.init(p2.getPublic(), p, ephKeyGen);
i2.init(p2.getPrivate(), p, new ECIESPublicKeyParser(params));
@@ -323,7 +339,8 @@ public class ECIESTest
public void performTest()
throws Exception
{
- staticTest();
+ doStaticTest(null);
+ doStaticTest(TWOFISH_IV);
BigInteger n = new BigInteger("6277101735386680763835789423176059013767194773182842284081");
@@ -348,7 +365,8 @@ public class ECIESTest
doTest(p1, p2);
- doEphemeralTest();
+ doEphemeralTest(null);
+ doEphemeralTest(TWOFISH_IV);
}
public static void main(
diff --git a/prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/EC.java b/prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/EC.java
index bc61744f..ff4c13e2 100644
--- a/prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/EC.java
+++ b/prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/EC.java
@@ -56,6 +56,10 @@ public class EC
provider.addAlgorithm("Cipher.ECIESWITHAES", PREFIX + "IESCipher$ECIESwithAES");
provider.addAlgorithm("Cipher.ECIESwithDESEDE", PREFIX + "IESCipher$ECIESwithDESede");
provider.addAlgorithm("Cipher.ECIESWITHDESEDE", PREFIX + "IESCipher$ECIESwithDESede");
+ provider.addAlgorithm("Cipher.ECIESwithAES-CBC", PREFIX + "IESCipher$ECIESwithAESCBC");
+ provider.addAlgorithm("Cipher.ECIESWITHAES-CBC", PREFIX + "IESCipher$ECIESwithAESCBC");
+ provider.addAlgorithm("Cipher.ECIESwithDESEDE-CBC", PREFIX + "IESCipher$ECIESwithDESedeCBC");
+ provider.addAlgorithm("Cipher.ECIESWITHDESEDE-CBC", PREFIX + "IESCipher$ECIESwithDESedeCBC");
provider.addAlgorithm("Signature.ECDSA", PREFIX + "SignatureSpi$ecDSA");
provider.addAlgorithm("Signature.NONEwithECDSA", PREFIX + "SignatureSpi$ecDSAnone");
diff --git a/prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/ec/IESCipher.java b/prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/ec/IESCipher.java
index 4ad05123..77c50b4d 100644
--- a/prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/ec/IESCipher.java
+++ b/prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/ec/IESCipher.java
@@ -18,6 +18,7 @@ import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.ShortBufferException;
+import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.crypto.InvalidCipherTextException;
import org.bouncycastle.crypto.KeyEncoder;
import org.bouncycastle.crypto.agreement.ECDHBasicAgreement;
@@ -29,14 +30,15 @@ import org.bouncycastle.crypto.generators.ECKeyPairGenerator;
import org.bouncycastle.crypto.generators.EphemeralKeyPairGenerator;
import org.bouncycastle.crypto.generators.KDF2BytesGenerator;
import org.bouncycastle.crypto.macs.HMac;
+import org.bouncycastle.crypto.modes.CBCBlockCipher;
import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher;
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
import org.bouncycastle.crypto.params.ECDomainParameters;
import org.bouncycastle.crypto.params.ECKeyGenerationParameters;
import org.bouncycastle.crypto.params.ECKeyParameters;
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
-import org.bouncycastle.crypto.params.IESParameters;
import org.bouncycastle.crypto.params.IESWithCipherParameters;
+import org.bouncycastle.crypto.params.ParametersWithIV;
import org.bouncycastle.crypto.parsers.ECIESPublicKeyParser;
import org.bouncycastle.jcajce.provider.asymmetric.util.ECUtil;
import org.bouncycastle.jcajce.provider.asymmetric.util.IESUtil;
@@ -52,6 +54,7 @@ import org.bouncycastle.util.Strings;
public class IESCipher
extends CipherSpi
{
+ private final int ivLength;
private IESEngine engine;
private int state = -1;
private ByteArrayOutputStream buffer = new ByteArrayOutputStream();
@@ -64,9 +67,14 @@ public class IESCipher
public IESCipher(IESEngine engine)
{
- this.engine = engine;
+ this(engine, 0);
}
+ public IESCipher(IESEngine engine, int ivLength)
+ {
+ this.engine = engine;
+ this.ivLength = ivLength;
+ }
public int engineGetBlockSize()
{
@@ -99,7 +107,6 @@ public class IESCipher
return null;
}
-
public AlgorithmParameters engineGetParameters()
{
if (engineParam == null && engineSpec != null)
@@ -259,6 +266,20 @@ public class IESCipher
throw new InvalidAlgorithmParameterException("must be passed IES parameters");
}
+ byte[] nonce = this.engineSpec.getNonce();
+
+ if (nonce != null)
+ {
+ if (ivLength == 0)
+ {
+ throw new InvalidAlgorithmParameterException("NONCE present in IES Parameters when none required");
+ }
+ else if (nonce.length != ivLength)
+ {
+ throw new InvalidAlgorithmParameterException("NONCE in IES Parameters needs to be " + ivLength + " bytes long");
+ }
+ }
+
// Parse the recipient's key
if (opmode == Cipher.ENCRYPT_MODE || opmode == Cipher.WRAP_MODE)
{
@@ -368,11 +389,16 @@ public class IESCipher
buffer.reset();
// Convert parameters for use in IESEngine
- IESParameters params = new IESWithCipherParameters(engineSpec.getDerivationV(),
+ CipherParameters params = new IESWithCipherParameters(engineSpec.getDerivationV(),
engineSpec.getEncodingV(),
engineSpec.getMacKeySize(),
engineSpec.getCipherKeySize());
+ if (engineSpec.getNonce() != null)
+ {
+ params = new ParametersWithIV(params, engineSpec.getNonce());
+ }
+
final ECDomainParameters ecParams = ((ECKeyParameters)key).getParameters();
final byte[] V;
@@ -498,4 +524,28 @@ public class IESCipher
new PaddedBufferedBlockCipher(new AESEngine())));
}
}
+
+ static public class ECIESwithDESedeCBC
+ extends IESCipher
+ {
+ public ECIESwithDESedeCBC()
+ {
+ super(new IESEngine(new ECDHBasicAgreement(),
+ new KDF2BytesGenerator(new SHA1Digest()),
+ new HMac(new SHA1Digest()),
+ new PaddedBufferedBlockCipher(new CBCBlockCipher(new DESedeEngine()))), 8);
+ }
+ }
+
+ static public class ECIESwithAESCBC
+ extends IESCipher
+ {
+ public ECIESwithAESCBC()
+ {
+ super(new IESEngine(new ECDHBasicAgreement(),
+ new KDF2BytesGenerator(new SHA1Digest()),
+ new HMac(new SHA1Digest()),
+ new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESEngine()))), 16);
+ }
+ }
}
diff --git a/prov/src/main/java/org/bouncycastle/jce/spec/IESParameterSpec.java b/prov/src/main/java/org/bouncycastle/jce/spec/IESParameterSpec.java
index 165df9f1..16a5fa2f 100644
--- a/prov/src/main/java/org/bouncycastle/jce/spec/IESParameterSpec.java
+++ b/prov/src/main/java/org/bouncycastle/jce/spec/IESParameterSpec.java
@@ -2,6 +2,8 @@ package org.bouncycastle.jce.spec;
import java.security.spec.AlgorithmParameterSpec;
+import org.bouncycastle.util.Arrays;
+
/**
* Parameter spec for an integrated encryptor, as in IEEE P1363a
*/
@@ -12,6 +14,7 @@ public class IESParameterSpec
private byte[] encoding;
private int macKeySize;
private int cipherKeySize;
+ private byte[] nonce;
/**
@@ -44,6 +47,25 @@ public class IESParameterSpec
int macKeySize,
int cipherKeySize)
{
+ this(derivation, encoding, macKeySize, cipherKeySize, null);
+ }
+
+ /**
+ * Set the IES engine parameters.
+ *
+ * @param derivation the optional derivation vector for the KDF.
+ * @param encoding the optional encoding vector for the KDF.
+ * @param macKeySize the key size (in bits) for the MAC.
+ * @param cipherKeySize the key size (in bits) for the block cipher.
+ * @param nonce an IV to use initialising the block cipher.
+ */
+ public IESParameterSpec(
+ byte[] derivation,
+ byte[] encoding,
+ int macKeySize,
+ int cipherKeySize,
+ byte[] nonce)
+ {
if (derivation != null)
{
this.derivation = new byte[derivation.length];
@@ -66,15 +88,15 @@ public class IESParameterSpec
this.macKeySize = macKeySize;
this.cipherKeySize = cipherKeySize;
+ this.nonce = Arrays.clone(nonce);
}
-
/**
* return the derivation vector.
*/
public byte[] getDerivationV()
{
- return derivation;
+ return Arrays.clone(derivation);
}
/**
@@ -82,7 +104,7 @@ public class IESParameterSpec
*/
public byte[] getEncodingV()
{
- return encoding;
+ return Arrays.clone(encoding);
}
/**
@@ -101,4 +123,13 @@ public class IESParameterSpec
return cipherKeySize;
}
+ /**
+ * Return the nonce (IV) value to be associated with message.
+ *
+ * @return block cipher IV for message.
+ */
+ public byte[] getNonce()
+ {
+ return Arrays.clone(nonce);
+ }
}
diff --git a/prov/src/test/java/org/bouncycastle/jce/provider/test/ECIESTest.java b/prov/src/test/java/org/bouncycastle/jce/provider/test/ECIESTest.java
index 9af0670a..ad2b8b25 100755
--- a/prov/src/test/java/org/bouncycastle/jce/provider/test/ECIESTest.java
+++ b/prov/src/test/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.");
}