Search in sources :

Example 1 with DSAGenParameterSpec

use of java.security.spec.DSAGenParameterSpec in project jdk8u_jdk by JetBrains.

the class DSAParameterGenerator method engineInit.

/**
     * Initializes this parameter generator with a set of
     * algorithm-specific parameter generation values.
     *
     * @param genParamSpec the set of algorithm-specific parameter generation values
     * @param random the source of randomness
     *
     * @exception InvalidAlgorithmParameterException if the given parameter
     * generation values are inappropriate for this parameter generator
     */
protected void engineInit(AlgorithmParameterSpec genParamSpec, SecureRandom random) throws InvalidAlgorithmParameterException {
    if (!(genParamSpec instanceof DSAGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException("Invalid parameter");
    }
    DSAGenParameterSpec dsaGenParams = (DSAGenParameterSpec) genParamSpec;
    int primePLen = dsaGenParams.getPrimePLength();
    if (primePLen > 2048) {
        throw new InvalidParameterException("No support for prime size " + primePLen);
    }
    // directly initialize using the already validated values
    this.valueL = primePLen;
    this.valueN = dsaGenParams.getSubprimeQLength();
    this.seedLen = dsaGenParams.getSeedLength();
    this.random = random;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) DSAGenParameterSpec(java.security.spec.DSAGenParameterSpec)

Example 2 with DSAGenParameterSpec

use of java.security.spec.DSAGenParameterSpec in project jdk8u_jdk by JetBrains.

the class TestDSAGenParameterSpec method testDSAGenParameterSpec.

private static void testDSAGenParameterSpec(DataTuple dataTuple) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidParameterSpecException, InvalidAlgorithmParameterException {
    System.out.printf("Test case: primePLen=%d, " + "subprimeQLen=%d%n", dataTuple.primePLen, dataTuple.subprimeQLen);
    AlgorithmParameterGenerator apg = AlgorithmParameterGenerator.getInstance(ALGORITHM_NAME, PROVIDER_NAME);
    DSAGenParameterSpec genParamSpec = createGenParameterSpec(dataTuple);
    // genParamSpec will be null if IllegalAE is thrown when expected.
    if (genParamSpec == null) {
        return;
    }
    try {
        apg.init(genParamSpec, null);
        AlgorithmParameters param = apg.generateParameters();
        checkParam(param, genParamSpec);
        System.out.println("Test case passed");
    } catch (InvalidParameterException ipe) {
        // implementation in SUN doesn't
        if (!dataTuple.isSunProviderSupported) {
            System.out.println("Test case passed: expected " + "InvalidParameterException is caught");
        } else {
            throw new RuntimeException("Test case failed.", ipe);
        }
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) DSAGenParameterSpec(java.security.spec.DSAGenParameterSpec) AlgorithmParameterGenerator(java.security.AlgorithmParameterGenerator) AlgorithmParameters(java.security.AlgorithmParameters)

Aggregations

InvalidParameterException (java.security.InvalidParameterException)2 DSAGenParameterSpec (java.security.spec.DSAGenParameterSpec)2 AlgorithmParameterGenerator (java.security.AlgorithmParameterGenerator)1 AlgorithmParameters (java.security.AlgorithmParameters)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1