提交 d0ae97c9 编写于 作者: M mbalao

8055351: sun/security/provider/DSA/TestAlgParameterGenerator.java failed with...

8055351: sun/security/provider/DSA/TestAlgParameterGenerator.java failed with interrupted! (timed out?)
Reviewed-by: valeriep, andrew, phh
上级 de5549d7
...@@ -23,56 +23,59 @@ ...@@ -23,56 +23,59 @@
/* /*
* @test * @test
* @bug 7044060 8181048 * @bug 7044060 8055351 8181048
* @summary verify that DSA parameter generation works * @summary verify that DSA parameter generation works
* @run main/othervm/timeout=300 TestAlgParameterGenerator * @run main/timeout=600 TestAlgParameterGenerator
*/ */
import java.security.*;
import java.security.spec.*; import java.security.AlgorithmParameterGenerator;
import java.security.interfaces.*; import java.security.AlgorithmParameters;
import java.security.spec.DSAGenParameterSpec;
import java.security.spec.DSAParameterSpec;
public class TestAlgParameterGenerator { public class TestAlgParameterGenerator {
private static void checkParamStrength(AlgorithmParameters param, private static void checkParamStrength(AlgorithmParameters param,
int strength) throws Exception { int strength) throws Exception {
String algo = param.getAlgorithm(); String algo = param.getAlgorithm();
if (!algo.equalsIgnoreCase("DSA")) { if (!algo.equalsIgnoreCase("DSA")) {
throw new Exception("Unexpected type of parameters: " + algo); throw new RuntimeException("Unexpected type of parameters: " + algo);
} }
DSAParameterSpec spec = param.getParameterSpec(DSAParameterSpec.class); DSAParameterSpec spec = param.getParameterSpec(DSAParameterSpec.class);
int valueL = spec.getP().bitLength(); int valueL = spec.getP().bitLength();
if (strength != valueL) { if (strength != valueL) {
System.out.println("Expected " + strength + " but actual " + valueL); System.out.println("Expected " + strength + " but actual " + valueL);
throw new Exception("Wrong P strength"); throw new RuntimeException("Wrong P strength");
} }
} }
private static void checkParamStrength(AlgorithmParameters param, private static void checkParamStrength(AlgorithmParameters param,
DSAGenParameterSpec genParam) DSAGenParameterSpec genParam)
throws Exception { throws Exception {
String algo = param.getAlgorithm(); String algo = param.getAlgorithm();
if (!algo.equalsIgnoreCase("DSA")) { if (!algo.equalsIgnoreCase("DSA")) {
throw new Exception("Unexpected type of parameters: " + algo); throw new RuntimeException("Unexpected type of parameters: " + algo);
} }
DSAParameterSpec spec = param.getParameterSpec(DSAParameterSpec.class); DSAParameterSpec spec = param.getParameterSpec(DSAParameterSpec.class);
int valueL = spec.getP().bitLength(); int valueL = spec.getP().bitLength();
int strength = genParam.getPrimePLength(); int strength = genParam.getPrimePLength();
if (strength != valueL) { if (strength != valueL) {
System.out.println("P: Expected " + strength + " but actual " + valueL); System.out.println("P: Expected " + strength + " but actual " + valueL);
throw new Exception("Wrong P strength"); throw new RuntimeException("Wrong P strength");
} }
int valueN = spec.getQ().bitLength(); int valueN = spec.getQ().bitLength();
strength = genParam.getSubprimeQLength(); strength = genParam.getSubprimeQLength();
if (strength != valueN) { if (strength != valueN) {
System.out.println("Q: Expected " + strength + " but actual " + valueN); System.out.println("Q: Expected " + strength + " but actual " + valueN);
throw new Exception("Wrong Q strength"); throw new RuntimeException("Wrong Q strength");
} }
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
AlgorithmParameterGenerator apg = AlgorithmParameterGenerator apg
AlgorithmParameterGenerator.getInstance("DSA", "SUN"); = AlgorithmParameterGenerator.getInstance("DSA", "SUN");
long start, stop; long start, stop;
// make sure no-init still works // make sure no-init still works
start = System.currentTimeMillis(); start = System.currentTimeMillis();
AlgorithmParameters param = apg.generateParameters(); AlgorithmParameters param = apg.generateParameters();
...@@ -80,9 +83,8 @@ public class TestAlgParameterGenerator { ...@@ -80,9 +83,8 @@ public class TestAlgParameterGenerator {
System.out.println("Time: " + (stop - start) + " ms."); System.out.println("Time: " + (stop - start) + " ms.");
// make sure the old model works // make sure the old model works
int[] strengths = { 512, 768, 1024 }; int[] strengths = {512, 768, 1024};
for (int i = 0; i < strengths.length; i++) { for (int sizeP : strengths) {
int sizeP = strengths[i];
System.out.println("Generating " + sizeP + "-bit DSA Parameters"); System.out.println("Generating " + sizeP + "-bit DSA Parameters");
start = System.currentTimeMillis(); start = System.currentTimeMillis();
apg.init(sizeP); apg.init(sizeP);
...@@ -93,18 +95,17 @@ public class TestAlgParameterGenerator { ...@@ -93,18 +95,17 @@ public class TestAlgParameterGenerator {
} }
// now the newer model // now the newer model
DSAGenParameterSpec spec1 = new DSAGenParameterSpec(1024, 160);
DSAGenParameterSpec spec2 = new DSAGenParameterSpec(2048, 224);
DSAGenParameterSpec spec3 = new DSAGenParameterSpec(2048, 256);
//DSAGenParameterSpec spec4 = new DSAGenParameterSpec(3072, 256);
DSAGenParameterSpec[] specSet = { DSAGenParameterSpec[] specSet = {
spec1, spec2, spec3//, spec4 new DSAGenParameterSpec(1024, 160),
new DSAGenParameterSpec(2048, 224),
new DSAGenParameterSpec(2048, 256)
// no support for prime size 3072
// ,new DSAGenParameterSpec(3072, 256)
}; };
for (int i = 0; i < specSet.length; i++) {
DSAGenParameterSpec genParam = specSet[i]; for (DSAGenParameterSpec genParam : specSet) {
System.out.println("Generating (" + genParam.getPrimePLength() + System.out.println("Generating (" + genParam.getPrimePLength()
", " + genParam.getSubprimeQLength() + + ", " + genParam.getSubprimeQLength() + ") DSA Parameters");
") DSA Parameters");
start = System.currentTimeMillis(); start = System.currentTimeMillis();
apg.init(genParam, null); apg.init(genParam, null);
param = apg.generateParameters(); param = apg.generateParameters();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册