Java 类javax.crypto.spec.DHGenParameterSpec 实例源码

项目:BiglyBT    文件:JDKAlgorithmParameterGenerator.java   
@Override
protected void engineInit(
    AlgorithmParameterSpec  genParamSpec,
    SecureRandom            random)
    throws InvalidAlgorithmParameterException
{
    if (!(genParamSpec instanceof DHGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("DH parameter generator requires a DHGenParameterSpec for initialisation");
    }
    DHGenParameterSpec  spec = (DHGenParameterSpec)genParamSpec;

    this.strength = spec.getPrimeSize();
    this.l = spec.getExponentSize();
    this.random = random;
}
项目:javify    文件:DHKeyPairGeneratorSpi.java   
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
    throws InvalidAlgorithmParameterException
{
  HashMap attributes = new HashMap();
  if (params != null)
    {
      if (! (params instanceof DHGenParameterSpec) &&
          ! (params instanceof DHParameterSpec))
        throw new InvalidAlgorithmParameterException("params");

      attributes.put(GnuDHKeyPairGenerator.DH_PARAMETERS, params);
    }

  if (random != null)
    attributes.put(GnuDHKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);

  attributes.put(GnuDHKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
                 Integer.valueOf(Registry.ASN1_ENCODING_ID));
  adaptee.setup(attributes);
}
项目:jvm-stm    文件:DHKeyPairGeneratorSpi.java   
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
    throws InvalidAlgorithmParameterException
{
  HashMap attributes = new HashMap();
  if (params != null)
    {
      if (! (params instanceof DHGenParameterSpec) &&
          ! (params instanceof DHParameterSpec))
        throw new InvalidAlgorithmParameterException("params");

      attributes.put(GnuDHKeyPairGenerator.DH_PARAMETERS, params);
    }

  if (random != null)
    attributes.put(GnuDHKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);

  attributes.put(GnuDHKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
                 Integer.valueOf(Registry.ASN1_ENCODING_ID));
  adaptee.setup(attributes);
}
项目:JamVM-PH    文件:DHKeyPairGeneratorSpi.java   
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
    throws InvalidAlgorithmParameterException
{
  HashMap attributes = new HashMap();
  if (params != null)
    {
      if (! (params instanceof DHGenParameterSpec) &&
          ! (params instanceof DHParameterSpec))
        throw new InvalidAlgorithmParameterException("params");

      attributes.put(GnuDHKeyPairGenerator.DH_PARAMETERS, params);
    }

  if (random != null)
    attributes.put(GnuDHKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);

  attributes.put(GnuDHKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
                 Integer.valueOf(Registry.ASN1_ENCODING_ID));
  adaptee.setup(attributes);
}
项目:classpath    文件:DHKeyPairGeneratorSpi.java   
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
    throws InvalidAlgorithmParameterException
{
  HashMap attributes = new HashMap();
  if (params != null)
    {
      if (! (params instanceof DHGenParameterSpec) &&
          ! (params instanceof DHParameterSpec))
        throw new InvalidAlgorithmParameterException("params");

      attributes.put(GnuDHKeyPairGenerator.DH_PARAMETERS, params);
    }

  if (random != null)
    attributes.put(GnuDHKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);

  attributes.put(GnuDHKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
                 Integer.valueOf(Registry.ASN1_ENCODING_ID));
  adaptee.setup(attributes);
}
项目:ipack    文件:AlgorithmParameterGeneratorSpi.java   
protected void engineInit(
    AlgorithmParameterSpec genParamSpec,
    SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    if (!(genParamSpec instanceof DHGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("DH parameter generator requires a DHGenParameterSpec for initialisation");
    }
    DHGenParameterSpec spec = (DHGenParameterSpec)genParamSpec;

    this.strength = spec.getPrimeSize();
    this.l = spec.getExponentSize();
    this.random = random;
}
项目:ipack    文件:AlgorithmParameterGeneratorSpi.java   
protected void engineInit(
    AlgorithmParameterSpec genParamSpec,
    SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    if (!(genParamSpec instanceof DHGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("DH parameter generator requires a DHGenParameterSpec for initialisation");
    }
    DHGenParameterSpec spec = (DHGenParameterSpec)genParamSpec;

    this.strength = spec.getPrimeSize();
    this.l = spec.getExponentSize();
    this.random = random;
}
项目:OpenJSharp    文件:DHParameterGenerator.java   
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param params the set of 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 DHGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;

    primeSize = dhParamSpec.getPrimeSize();

    // Re-uses DSA parameters and thus have the same range
    checkKeySize(primeSize);

    exponentSize = dhParamSpec.getExponentSize();
    if (exponentSize <= 0) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be greater than zero");
    }

    // Require exponentSize < primeSize
    if (exponentSize >= primeSize) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be less than modulus size");
    }
}
项目:jdk8u-jdk    文件:DHParameterGenerator.java   
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param params the set of 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 DHGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;

    primeSize = dhParamSpec.getPrimeSize();

    // Re-uses DSA parameters and thus have the same range
    try {
        checkKeySize(primeSize);
    } catch (InvalidParameterException ipe) {
        throw new InvalidAlgorithmParameterException(ipe.getMessage());
    }

    exponentSize = dhParamSpec.getExponentSize();
    if (exponentSize <= 0) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be greater than zero");
    }

    // Require exponentSize < primeSize
    if (exponentSize >= primeSize) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be less than modulus size");
    }
}
项目:openjdk-jdk10    文件:DHParameterGenerator.java   
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param genParamSpec the set of parameter generation values
 * @param random the source of randomness
 *
 * @exception InvalidAlgorithmParameterException if the given parameter
 * generation values are inappropriate for this parameter generator
 */
@Override
protected void engineInit(AlgorithmParameterSpec genParamSpec,
        SecureRandom random) throws InvalidAlgorithmParameterException {

    if (!(genParamSpec instanceof DHGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;
    primeSize = dhParamSpec.getPrimeSize();
    exponentSize = dhParamSpec.getExponentSize();
    if ((exponentSize <= 0) || (exponentSize >= primeSize)) {
        throw new InvalidAlgorithmParameterException(
                "Exponent size (" + exponentSize +
                ") must be positive and less than modulus size (" +
                primeSize + ")");
    }
    try {
        checkKeySize(primeSize);
    } catch (InvalidParameterException ipe) {
        throw new InvalidAlgorithmParameterException(ipe.getMessage());
    }

    this.random = random;
}
项目:openjdk9    文件:DHParameterGenerator.java   
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param genParamSpec the set of parameter generation values
 * @param random the source of randomness
 *
 * @exception InvalidAlgorithmParameterException if the given parameter
 * generation values are inappropriate for this parameter generator
 */
@Override
protected void engineInit(AlgorithmParameterSpec genParamSpec,
        SecureRandom random) throws InvalidAlgorithmParameterException {

    if (!(genParamSpec instanceof DHGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;
    primeSize = dhParamSpec.getPrimeSize();
    exponentSize = dhParamSpec.getExponentSize();
    if ((exponentSize <= 0) || (exponentSize >= primeSize)) {
        throw new InvalidAlgorithmParameterException(
                "Exponent size (" + exponentSize +
                ") must be positive and less than modulus size (" +
                primeSize + ")");
    }
    try {
        checkKeySize(primeSize);
    } catch (InvalidParameterException ipe) {
        throw new InvalidAlgorithmParameterException(ipe.getMessage());
    }

    this.random = random;
}
项目:Direct-File-Downloader    文件:JDKAlgorithmParameterGenerator.java   
protected void engineInit(
    AlgorithmParameterSpec  genParamSpec,
    SecureRandom            random)
    throws InvalidAlgorithmParameterException
{
    if (!(genParamSpec instanceof DHGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("DH parameter generator requires a DHGenParameterSpec for initialisation");
    }
    DHGenParameterSpec  spec = (DHGenParameterSpec)genParamSpec;

    this.strength = spec.getPrimeSize();
    this.l = spec.getExponentSize();
    this.random = random;
}
项目:jdk8u_jdk    文件:DHParameterGenerator.java   
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param params the set of 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 DHGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;

    primeSize = dhParamSpec.getPrimeSize();

    // Re-uses DSA parameters and thus have the same range
    try {
        checkKeySize(primeSize);
    } catch (InvalidParameterException ipe) {
        throw new InvalidAlgorithmParameterException(ipe.getMessage());
    }

    exponentSize = dhParamSpec.getExponentSize();
    if (exponentSize <= 0) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be greater than zero");
    }

    // Require exponentSize < primeSize
    if (exponentSize >= primeSize) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be less than modulus size");
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:DHParameterGenerator.java   
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param params the set of 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 DHGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;

    primeSize = dhParamSpec.getPrimeSize();

    // Re-uses DSA parameters and thus have the same range
    try {
        checkKeySize(primeSize);
    } catch (InvalidParameterException ipe) {
        throw new InvalidAlgorithmParameterException(ipe.getMessage());
    }

    exponentSize = dhParamSpec.getExponentSize();
    if (exponentSize <= 0) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be greater than zero");
    }

    // Require exponentSize < primeSize
    if (exponentSize >= primeSize) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be less than modulus size");
    }
}
项目:Aki-SSL    文件:AlgorithmParameterGeneratorSpi.java   
protected void engineInit(
    AlgorithmParameterSpec genParamSpec,
    SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    if (!(genParamSpec instanceof DHGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("DH parameter generator requires a DHGenParameterSpec for initialisation");
    }
    DHGenParameterSpec spec = (DHGenParameterSpec)genParamSpec;

    this.strength = spec.getPrimeSize();
    this.l = spec.getExponentSize();
    this.random = random;
}
项目:Aki-SSL    文件:AlgorithmParameterGeneratorSpi.java   
protected void engineInit(
    AlgorithmParameterSpec genParamSpec,
    SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    if (!(genParamSpec instanceof DHGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("DH parameter generator requires a DHGenParameterSpec for initialisation");
    }
    DHGenParameterSpec spec = (DHGenParameterSpec)genParamSpec;

    this.strength = spec.getPrimeSize();
    this.l = spec.getExponentSize();
    this.random = random;
}
项目:javify    文件:DHParameters.java   
protected AlgorithmParameterSpec engineGetParameterSpec(Class paramSpec)
    throws InvalidParameterSpecException
{
  if (paramSpec.isAssignableFrom(DHParameterSpec.class))
    return new DHParameterSpec(p, g, l);

  if (paramSpec.isAssignableFrom(DHGenParameterSpec.class))
    return new DHGenParameterSpec(p.bitLength(), l);

  throw new InvalidParameterSpecException("Wrong AlgorithmParameterSpec type: "
                                          + paramSpec.getName());
}
项目:jvm-stm    文件:DHParameters.java   
protected AlgorithmParameterSpec engineGetParameterSpec(Class paramSpec)
    throws InvalidParameterSpecException
{
  if (paramSpec.isAssignableFrom(DHParameterSpec.class))
    return new DHParameterSpec(p, g, l);

  if (paramSpec.isAssignableFrom(DHGenParameterSpec.class))
    return new DHGenParameterSpec(p.bitLength(), l);

  throw new InvalidParameterSpecException("Wrong AlgorithmParameterSpec type: "
                                          + paramSpec.getName());
}
项目:openid4java    文件:DiffieHellmanSession.java   
public static DHParameterSpec generateRandomParameter(int primeSize, int keySize)
{
    try
    {
        AlgorithmParameterGenerator paramGen =
                AlgorithmParameterGenerator.getInstance(ALGORITHM);

        DHGenParameterSpec genParameterSpec =
                new DHGenParameterSpec(primeSize, keySize);

        paramGen.init(genParameterSpec);

        AlgorithmParameters params = paramGen.generateParameters();

        DHParameterSpec result = (DHParameterSpec)
                params.getParameterSpec(DHParameterSpec.class);

        if (DEBUG) _log.debug("Generated random DHParameterSpec, base: "
                + result.getG() + ", modulus: " + result.getP());

        return result;
    }
    catch (GeneralSecurityException e)
    {
        _log.error("Cannot generate DH params for primeSize: "
                + primeSize + " keySize: " + keySize, e);
        return null;
    }
}
项目:infobip-open-jdk-8    文件:DHParameterGenerator.java   
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param params the set of 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 DHGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;

    primeSize = dhParamSpec.getPrimeSize();

    // Re-uses DSA parameters and thus have the same range
    checkKeySize(primeSize);

    exponentSize = dhParamSpec.getExponentSize();
    if (exponentSize <= 0) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be greater than zero");
    }

    // Require exponentSize < primeSize
    if (exponentSize >= primeSize) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be less than modulus size");
    }
}
项目:jdk8u-dev-jdk    文件:DHParameterGenerator.java   
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param params the set of 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 DHGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;

    primeSize = dhParamSpec.getPrimeSize();

    // Re-uses DSA parameters and thus have the same range
    checkKeySize(primeSize);

    exponentSize = dhParamSpec.getExponentSize();
    if (exponentSize <= 0) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be greater than zero");
    }

    // Require exponentSize < primeSize
    if (exponentSize >= primeSize) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be less than modulus size");
    }
}
项目:In-the-Box-Fork    文件:DHGenParameterSpecTest.java   
/**
 * DHGenParameterSpec class testing. Tests the equivalence of
 * parameters specified in the constructor with the values returned
 * by getters.
 */
@TestTargets({
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "All functionality tested in one method. Probably it should be divided into several tests.",
        method = "DHGenParameterSpec",
        args = {int.class, int.class}
    ),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "All functionality tested in one method. Probably it should be divided into several tests.",
        method = "getExponentSize",
        args = {}
    ),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "All functionality tested in one method. Probably it should be divided into several tests.",
        method = "getPrimeSize",
        args = {}
    )
})
public void testDHGenParameterSpec() {
    int[] primes = {Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE};
    int[] exponents = {Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE};
    for (int i=0; i<primes.length; i++) {
        DHGenParameterSpec ps = new DHGenParameterSpec(primes[i],
                                                        exponents[i]);
        assertEquals("The value returned by getPrimeSize() must be "
                    + "equal to the value specified in the constructor",
                    ps.getPrimeSize(), primes[i]);
        assertEquals("The value returned by getExponentSize() must be "
                    + "equal to the value specified in the constructor",
                    ps.getPrimeSize(), exponents[i]);
    }
}
项目:jdk7-jdk    文件:DHParameterGenerator.java   
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param params the set of 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 DHGenParameterSpec)) {
            throw new InvalidAlgorithmParameterException
                ("Inappropriate parameter type");
        }

        DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;

        primeSize = dhParamSpec.getPrimeSize();
        if ((primeSize<512) || (primeSize>1024) || (primeSize%64 != 0)) {
            throw new InvalidAlgorithmParameterException
                ("Modulus size must be multiple of 64, and can only range "
                 + "from 512 to 1024 (inclusive)");
        }

        exponentSize = dhParamSpec.getExponentSize();
        if (exponentSize <= 0) {
            throw new InvalidAlgorithmParameterException
                ("Exponent size must be greater than zero");
        }

        // Require exponentSize < primeSize
        if (exponentSize >= primeSize) {
            throw new InvalidAlgorithmParameterException
                ("Exponent size must be less than modulus size");
        }
}
项目:AcademicTorrents-Downloader    文件:JDKAlgorithmParameterGenerator.java   
protected void engineInit(
    AlgorithmParameterSpec  genParamSpec,
    SecureRandom            random)
    throws InvalidAlgorithmParameterException
{
    if (!(genParamSpec instanceof DHGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("DH parameter generator requires a DHGenParameterSpec for initialisation");
    }
    DHGenParameterSpec  spec = (DHGenParameterSpec)genParamSpec;

    this.strength = spec.getPrimeSize();
    this.l = spec.getExponentSize();
    this.random = random;
}
项目:AcademicTorrents-Downloader    文件:JDKAlgorithmParameterGenerator.java   
protected void engineInit(
    AlgorithmParameterSpec  genParamSpec,
    SecureRandom            random)
    throws InvalidAlgorithmParameterException
{
    if (!(genParamSpec instanceof DHGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("DH parameter generator requires a DHGenParameterSpec for initialisation");
    }
    DHGenParameterSpec  spec = (DHGenParameterSpec)genParamSpec;

    this.strength = spec.getPrimeSize();
    this.l = spec.getExponentSize();
    this.random = random;
}
项目:openjdk-source-code-learn    文件:DHParameterGenerator.java   
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param params the set of 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 DHGenParameterSpec)) {
            throw new InvalidAlgorithmParameterException
                ("Inappropriate parameter type");
        }

        DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;

        primeSize = dhParamSpec.getPrimeSize();
        if ((primeSize<512) || (primeSize>1024) || (primeSize%64 != 0)) {
            throw new InvalidAlgorithmParameterException
                ("Modulus size must be multiple of 64, and can only range "
                 + "from 512 to 1024 (inclusive)");
        }

        exponentSize = dhParamSpec.getExponentSize();
        if (exponentSize <= 0) {
            throw new InvalidAlgorithmParameterException
                ("Exponent size must be greater than zero");
        }

        // Require exponentSize < primeSize
        if (exponentSize >= primeSize) {
            throw new InvalidAlgorithmParameterException
                ("Exponent size must be less than modulus size");
        }
}
项目:RipplePower    文件:AlgorithmParameterGeneratorSpi.java   
protected void engineInit(
    AlgorithmParameterSpec genParamSpec,
    SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    if (!(genParamSpec instanceof DHGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("DH parameter generator requires a DHGenParameterSpec for initialisation");
    }
    DHGenParameterSpec spec = (DHGenParameterSpec)genParamSpec;

    this.strength = spec.getPrimeSize();
    this.l = spec.getExponentSize();
    this.random = random;
}
项目:RipplePower    文件:AlgorithmParameterGeneratorSpi.java   
protected void engineInit(
    AlgorithmParameterSpec genParamSpec,
    SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    if (!(genParamSpec instanceof DHGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("DH parameter generator requires a DHGenParameterSpec for initialisation");
    }
    DHGenParameterSpec spec = (DHGenParameterSpec)genParamSpec;

    this.strength = spec.getPrimeSize();
    this.l = spec.getExponentSize();
    this.random = random;
}
项目:OLD-OpenJDK8    文件:DHParameterGenerator.java   
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param params the set of 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 DHGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;

    primeSize = dhParamSpec.getPrimeSize();

    // Re-uses DSA parameters and thus have the same range
    checkKeySize(primeSize);

    exponentSize = dhParamSpec.getExponentSize();
    if (exponentSize <= 0) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be greater than zero");
    }

    // Require exponentSize < primeSize
    if (exponentSize >= primeSize) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be less than modulus size");
    }
}
项目:cn1    文件:DHGenParameterSpecTest.java   
/**
 * DHGenParameterSpec class testing. Tests the equivalence of
 * parameters specified in the constructor with the values returned
 * by getters.
 */
public void testDHGenParameterSpec() {
    int[] primes = {Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE};
    int[] exponents = {Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE};
    for (int i=0; i<primes.length; i++) {
        DHGenParameterSpec ps = new DHGenParameterSpec(primes[i],
                                                        exponents[i]);
        assertEquals("The value returned by getPrimeSize() must be "
                    + "equal to the value specified in the constructor",
                    ps.getPrimeSize(), primes[i]);
        assertEquals("The value returned by getExponentSize() must be "
                    + "equal to the value specified in the constructor",
                    ps.getPrimeSize(), exponents[i]);
    }
}
项目:JamVM-PH    文件:DHParameters.java   
protected AlgorithmParameterSpec engineGetParameterSpec(Class paramSpec)
    throws InvalidParameterSpecException
{
  if (paramSpec.isAssignableFrom(DHParameterSpec.class))
    return new DHParameterSpec(p, g, l);

  if (paramSpec.isAssignableFrom(DHGenParameterSpec.class))
    return new DHGenParameterSpec(p.bitLength(), l);

  throw new InvalidParameterSpecException("Wrong AlgorithmParameterSpec type: "
                                          + paramSpec.getName());
}
项目:CryptMeme    文件:AlgorithmParameterGeneratorSpi.java   
protected void engineInit(
    AlgorithmParameterSpec genParamSpec,
    SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    if (!(genParamSpec instanceof DHGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("DH parameter generator requires a DHGenParameterSpec for initialisation");
    }
    DHGenParameterSpec spec = (DHGenParameterSpec)genParamSpec;

    this.strength = spec.getPrimeSize();
    this.l = spec.getExponentSize();
    this.random = random;
}
项目:CryptMeme    文件:AlgorithmParameterGeneratorSpi.java   
protected void engineInit(
    AlgorithmParameterSpec genParamSpec,
    SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    if (!(genParamSpec instanceof DHGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("DH parameter generator requires a DHGenParameterSpec for initialisation");
    }
    DHGenParameterSpec spec = (DHGenParameterSpec)genParamSpec;

    this.strength = spec.getPrimeSize();
    this.l = spec.getExponentSize();
    this.random = random;
}
项目:openjdk-jdk7u-jdk    文件:DHParameterGenerator.java   
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param params the set of 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 DHGenParameterSpec)) {
            throw new InvalidAlgorithmParameterException
                ("Inappropriate parameter type");
        }

        DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;

        primeSize = dhParamSpec.getPrimeSize();
        if ((primeSize<512) || (primeSize>1024) || (primeSize%64 != 0)) {
            throw new InvalidAlgorithmParameterException
                ("Modulus size must be multiple of 64, and can only range "
                 + "from 512 to 1024 (inclusive)");
        }

        exponentSize = dhParamSpec.getExponentSize();
        if (exponentSize <= 0) {
            throw new InvalidAlgorithmParameterException
                ("Exponent size must be greater than zero");
        }

        // Require exponentSize < primeSize
        if (exponentSize >= primeSize) {
            throw new InvalidAlgorithmParameterException
                ("Exponent size must be less than modulus size");
        }
}
项目:ripple-lib-java    文件:AlgorithmParameterGeneratorSpi.java   
protected void engineInit(
    AlgorithmParameterSpec genParamSpec,
    SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    if (!(genParamSpec instanceof DHGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("DH parameter generator requires a DHGenParameterSpec for initialisation");
    }
    DHGenParameterSpec spec = (DHGenParameterSpec)genParamSpec;

    this.strength = spec.getPrimeSize();
    this.l = spec.getExponentSize();
    this.random = random;
}
项目:ripple-lib-java    文件:AlgorithmParameterGeneratorSpi.java   
protected void engineInit(
    AlgorithmParameterSpec genParamSpec,
    SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    if (!(genParamSpec instanceof DHGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("DH parameter generator requires a DHGenParameterSpec for initialisation");
    }
    DHGenParameterSpec spec = (DHGenParameterSpec)genParamSpec;

    this.strength = spec.getPrimeSize();
    this.l = spec.getExponentSize();
    this.random = random;
}
项目:classpath    文件:DHParameters.java   
protected AlgorithmParameterSpec engineGetParameterSpec(Class paramSpec)
    throws InvalidParameterSpecException
{
  if (paramSpec.isAssignableFrom(DHParameterSpec.class))
    return new DHParameterSpec(p, g, l);

  if (paramSpec.isAssignableFrom(DHGenParameterSpec.class))
    return new DHGenParameterSpec(p.bitLength(), l);

  throw new InvalidParameterSpecException("Wrong AlgorithmParameterSpec type: "
                                          + paramSpec.getName());
}
项目:freeVM    文件:DHGenParameterSpecTest.java   
/**
 * DHGenParameterSpec class testing. Tests the equivalence of
 * parameters specified in the constructor with the values returned
 * by getters.
 */
public void testDHGenParameterSpec() {
    int[] primes = {Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE};
    int[] exponents = {Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE};
    for (int i=0; i<primes.length; i++) {
        DHGenParameterSpec ps = new DHGenParameterSpec(primes[i],
                                                        exponents[i]);
        assertEquals("The value returned by getPrimeSize() must be "
                    + "equal to the value specified in the constructor",
                    ps.getPrimeSize(), primes[i]);
        assertEquals("The value returned by getExponentSize() must be "
                    + "equal to the value specified in the constructor",
                    ps.getPrimeSize(), exponents[i]);
    }
}
项目:freeVM    文件:DHGenParameterSpecTest.java   
/**
 * DHGenParameterSpec class testing. Tests the equivalence of
 * parameters specified in the constructor with the values returned
 * by getters.
 */
public void testDHGenParameterSpec() {
    int[] primes = {Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE};
    int[] exponents = {Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE};
    for (int i=0; i<primes.length; i++) {
        DHGenParameterSpec ps = new DHGenParameterSpec(primes[i],
                                                        exponents[i]);
        assertEquals("The value returned by getPrimeSize() must be "
                    + "equal to the value specified in the constructor",
                    ps.getPrimeSize(), primes[i]);
        assertEquals("The value returned by getExponentSize() must be "
                    + "equal to the value specified in the constructor",
                    ps.getPrimeSize(), exponents[i]);
    }
}
项目:openjdk-icedtea7    文件:DHParameterGenerator.java   
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param params the set of 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 DHGenParameterSpec)) {
            throw new InvalidAlgorithmParameterException
                ("Inappropriate parameter type");
        }

        DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;

        primeSize = dhParamSpec.getPrimeSize();
        if ((primeSize<512) || (primeSize>1024) || (primeSize%64 != 0)) {
            throw new InvalidAlgorithmParameterException
                ("Modulus size must be multiple of 64, and can only range "
                 + "from 512 to 1024 (inclusive)");
        }

        exponentSize = dhParamSpec.getExponentSize();
        if (exponentSize <= 0) {
            throw new InvalidAlgorithmParameterException
                ("Exponent size must be greater than zero");
        }

        // Require exponentSize < primeSize
        if (exponentSize >= primeSize) {
            throw new InvalidAlgorithmParameterException
                ("Exponent size must be less than modulus size");
        }
}