summaryrefslogtreecommitdiffstats
path: root/luni
diff options
context:
space:
mode:
authorKenny Root <kroot@google.com>2014-07-10 16:08:49 -0700
committerKenny Root <kroot@google.com>2014-07-10 16:11:32 -0700
commitcd0bcc9441320473ab80bf4154526a38630a82d2 (patch)
tree1c69a450fd3acad8b19145fc4ababe04a5c58255 /luni
parent69f8370ab94822ee77b6fe26b3f32b7e1786467d (diff)
downloadlibcore-cd0bcc9441320473ab80bf4154526a38630a82d2.zip
libcore-cd0bcc9441320473ab80bf4154526a38630a82d2.tar.gz
libcore-cd0bcc9441320473ab80bf4154526a38630a82d2.tar.bz2
KeyPairGeneratorTest: add back some DH tests
Add back the DH tests that uses a pre-defined Diffie-Hellman prime and generator. Keep the tests that try to find safe prime disabled. Bug: 5513723 Bug: 16188130 Change-Id: If77b14287855528964665e7782be45c5f57434db
Diffstat (limited to 'luni')
-rw-r--r--luni/src/test/java/libcore/java/security/KeyPairGeneratorTest.java29
1 files changed, 23 insertions, 6 deletions
diff --git a/luni/src/test/java/libcore/java/security/KeyPairGeneratorTest.java b/luni/src/test/java/libcore/java/security/KeyPairGeneratorTest.java
index 09a18e2..e7fdb1f 100644
--- a/luni/src/test/java/libcore/java/security/KeyPairGeneratorTest.java
+++ b/luni/src/test/java/libcore/java/security/KeyPairGeneratorTest.java
@@ -47,6 +47,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.crypto.interfaces.DHPrivateKey;
+import javax.crypto.interfaces.DHPublicKey;
import javax.crypto.spec.DHParameterSpec;
import junit.framework.TestCase;
@@ -126,12 +128,8 @@ public class KeyPairGeneratorTest extends TestCase {
AlgorithmParameterSpec params = null;
- // TODO: detect if we're running in vogar and run the full test
if ("DH".equals(algorithm)) {
- // Disabled because this takes too long on devices.
- // TODO: Re-enable DH test. http://b/5513723.
- // params = getDHParams();
- continue;
+ params = getDHParams();
}
try {
@@ -218,6 +216,14 @@ public class KeyPairGeneratorTest extends TestCase {
test_KeyPair(kpg, kpg.generateKeyPair());
String algorithm = kpg.getAlgorithm();
+
+ // TODO: detect if we're running in vogar and run the full test
+ if ("DH".equals(algorithm)) {
+ // Disabled because this takes too long on devices.
+ // TODO: Re-enable DH test. http://b/5513723.
+ return;
+ }
+
List<Integer> keySizes = getKeySizes(algorithm);
for (int keySize : keySizes) {
kpg.initialize(keySize);
@@ -263,6 +269,17 @@ public class KeyPairGeneratorTest extends TestCase {
expectedAlgorithm = "DH";
}
assertEquals(expectedAlgorithm, k.getAlgorithm().toUpperCase());
+ if (expectedAlgorithm.equals("DH")) {
+ if (k instanceof DHPublicKey) {
+ DHPublicKey dhPub = (DHPublicKey) k;
+ assertEquals(dhPub.getParams().getP(), getDHParams().getP());
+ } else if (k instanceof DHPrivateKey) {
+ DHPrivateKey dhPriv = (DHPrivateKey) k;
+ assertEquals(dhPriv.getParams().getP(), getDHParams().getP());
+ } else {
+ fail("not a public or private key!?");
+ }
+ }
assertNotNull(k.getEncoded());
assertNotNull(k.getFormat());
@@ -344,7 +361,7 @@ public class KeyPairGeneratorTest extends TestCase {
*
* openssl gendh 512 | openssl dhparams -C
*/
- private static AlgorithmParameterSpec getDHParams() {
+ private static DHParameterSpec getDHParams() {
BigInteger p = new BigInteger("E7AB1768BD75CD24700960FFA32D3F1557344E587101237532CC641646ED7A7C104743377F6D46251698B665CE2A6CBAB6714C2569A7D2CA22C0CF03FA40AC93", 16);
BigInteger g = new BigInteger("02", 16);
return new DHParameterSpec(p, g, 512);