jdk/src/java.base/share/classes/java/security/AlgorithmParameterGenerator.java
author coleenp
Wed, 30 Aug 2017 19:18:22 -0400
changeset 47098 e704f55561c3
parent 45665 6f21cd7ec80e
permissions -rw-r--r--
8164207: Checking missing load-acquire in relation to _pd_set in dictionary.cpp Summary: Use load_acquire for accessing DictionaryEntry::_pd_set since it's accessed outside the SystemDictionary_lock Reviewed-by: zgu, twisti, dholmes, adinn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
43298
1793bf7f30fe 8172869: 4096 is not supported yet for the DH Parameter Generator
xuelei
parents: 41826
diff changeset
     2
 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.security;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.security.spec.AlgorithmParameterSpec;
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
    29
import java.util.Objects;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
    32
 * The {@code AlgorithmParameterGenerator} class is used to generate a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * parameters to be used with a certain algorithm. Parameter generators
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
    35
 * are constructed using the {@code getInstance} factory methods
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * (static methods that return instances of a given class).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <P>The object that will generate the parameters can be initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * in two different ways: in an algorithm-independent manner, or in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * algorithm-specific manner:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <li>The algorithm-independent approach uses the fact that all parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * generators share the concept of a "size" and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * source of randomness. The measure of size is universally shared
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * by all algorithm parameters, though it is interpreted differently
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * for different algorithms. For example, in the case of parameters for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * the <i>DSA</i> algorithm, "size" corresponds to the size
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * of the prime modulus (in bits).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * When using this approach, algorithm-specific parameter generation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * values - if any - default to some standard values, unless they can be
21334
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 18579
diff changeset
    52
 * derived from the specified size.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <li>The other approach initializes a parameter generator object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * using algorithm-specific semantics, which are represented by a set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * algorithm-specific parameter generation values. To generate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * Diffie-Hellman system parameters, for example, the parameter generation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * values usually
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * consist of the size of the prime modulus and the size of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * random exponent, both specified in number of bits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <P>In case the client does not explicitly initialize the
45435
7a91c865edd4 8180635: (doc) Clarify the compatibility and interoperability issue when using provider default values
valeriep
parents: 45118
diff changeset
    64
 * AlgorithmParameterGenerator (via a call to an {@code init} method),
7a91c865edd4 8180635: (doc) Clarify the compatibility and interoperability issue when using provider default values
valeriep
parents: 45118
diff changeset
    65
 * each provider must supply (and document) a default initialization.
7a91c865edd4 8180635: (doc) Clarify the compatibility and interoperability issue when using provider default values
valeriep
parents: 45118
diff changeset
    66
 * See the Keysize Restriction sections of the
45665
6f21cd7ec80e 8178114: Fix guide links in security APIs
wetmore
parents: 45435
diff changeset
    67
 * {@extLink security_guide_jdk_providers JDK Providers}
45435
7a91c865edd4 8180635: (doc) Clarify the compatibility and interoperability issue when using provider default values
valeriep
parents: 45118
diff changeset
    68
 * document for information on the AlgorithmParameterGenerator defaults
7a91c865edd4 8180635: (doc) Clarify the compatibility and interoperability issue when using provider default values
valeriep
parents: 45118
diff changeset
    69
 * used by JDK providers.
7a91c865edd4 8180635: (doc) Clarify the compatibility and interoperability issue when using provider default values
valeriep
parents: 45118
diff changeset
    70
 * However, note that defaults may vary across different providers.
7a91c865edd4 8180635: (doc) Clarify the compatibility and interoperability issue when using provider default values
valeriep
parents: 45118
diff changeset
    71
 * Additionally, the default value for a provider may change in a future
7a91c865edd4 8180635: (doc) Clarify the compatibility and interoperability issue when using provider default values
valeriep
parents: 45118
diff changeset
    72
 * version. Therefore, it is recommended to explicitly initialize the
7a91c865edd4 8180635: (doc) Clarify the compatibility and interoperability issue when using provider default values
valeriep
parents: 45118
diff changeset
    73
 * AlgorithmParameterGenerator instead of relying on provider-specific defaults.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    75
 * <p> Every implementation of the Java platform is required to support the
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
    76
 * following standard {@code AlgorithmParameterGenerator} algorithms and
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    77
 * keysizes in parentheses:
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    78
 * <ul>
43298
1793bf7f30fe 8172869: 4096 is not supported yet for the DH Parameter Generator
xuelei
parents: 41826
diff changeset
    79
 * <li>{@code DiffieHellman} (1024, 2048)</li>
32647
53b8fd1f3840 8015388: Required algorithms for JDK 9
mullan
parents: 25859
diff changeset
    80
 * <li>{@code DSA} (1024, 2048)</li>
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    81
 * </ul>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    82
 * These algorithms are described in the <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 43298
diff changeset
    83
 * "{@docRoot}/../specs/security/standard-names.html#algorithmparametergenerator-algorithms">
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    84
 * AlgorithmParameterGenerator section</a> of the
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 43298
diff changeset
    85
 * Java Security Standard Algorithm Names Specification.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    86
 * Consult the release documentation for your implementation to see if any
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    87
 * other algorithms are supported.
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    88
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * @author Jan Luehe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * @see AlgorithmParameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * @see java.security.spec.AlgorithmParameterSpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
public class AlgorithmParameterGenerator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    // The provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private Provider provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    // The provider implementation (delegate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private AlgorithmParameterGeneratorSpi paramGenSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    // The algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private String algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Creates an AlgorithmParameterGenerator object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @param paramGenSpi the delegate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @param provider the provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @param algorithm the algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    protected AlgorithmParameterGenerator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    (AlgorithmParameterGeneratorSpi paramGenSpi, Provider provider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     String algorithm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        this.paramGenSpi = paramGenSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        this.provider = provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        this.algorithm = algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * Returns the standard name of the algorithm this parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * generator is associated with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @return the string name of the algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public final String getAlgorithm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        return this.algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Returns an AlgorithmParameterGenerator object for generating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * a set of parameters to be used with the specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * <p> This method traverses the list of registered security Providers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * starting with the most preferred Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * A new AlgorithmParameterGenerator object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * AlgorithmParameterGeneratorSpi implementation from the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Provider that supports the specified algorithm is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32647
diff changeset
   147
     * @implNote
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32647
diff changeset
   148
     * The JDK Reference Implementation additionally uses the
37348
9ccec3170d5e 8152205: jdk.security.provider.preferred is ambiguously documented
ascarpino
parents: 33241
diff changeset
   149
     * {@code jdk.security.provider.preferred}
9ccec3170d5e 8152205: jdk.security.provider.preferred is ambiguously documented
ascarpino
parents: 33241
diff changeset
   150
     * {@link Security#getProperty(String) Security} property to determine
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32647
diff changeset
   151
     * the preferred provider order for the specified algorithm. This
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32647
diff changeset
   152
     * may be different than the order of providers returned by
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32647
diff changeset
   153
     * {@link Security#getProviders() Security.getProviders()}.
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32647
diff changeset
   154
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @param algorithm the name of the algorithm this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * parameter generator is associated with.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   157
     * See the AlgorithmParameterGenerator section in the <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 43298
diff changeset
   158
     * "{@docRoot}/../specs/security/standard-names.html#algorithmparametergenerator-algorithms">
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 43298
diff changeset
   159
     * Java Security Standard Algorithm Names Specification</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   162
     * @return the new {@code AlgorithmParameterGenerator} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   164
     * @throws NoSuchAlgorithmException if no {@code Provider} supports an
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   165
     *         {@code AlgorithmParameterGeneratorSpi} implementation for the
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   166
     *         specified algorithm
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   167
     *
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   168
     * @throws NullPointerException if {@code algorithm} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @see Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public static AlgorithmParameterGenerator getInstance(String algorithm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        throws NoSuchAlgorithmException {
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   174
            Objects.requireNonNull(algorithm, "null algorithm name");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                Object[] objs = Security.getImpl(algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                                                 "AlgorithmParameterGenerator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                                                 (String)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                return new AlgorithmParameterGenerator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    ((AlgorithmParameterGeneratorSpi)objs[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                     (Provider)objs[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                     algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            } catch(NoSuchProviderException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                throw new NoSuchAlgorithmException(algorithm + " not found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * Returns an AlgorithmParameterGenerator object for generating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * a set of parameters to be used with the specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * <p> A new AlgorithmParameterGenerator object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * AlgorithmParameterGeneratorSpi implementation from the specified provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * is returned.  The specified provider must be registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @param algorithm the name of the algorithm this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * parameter generator is associated with.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   202
     * See the AlgorithmParameterGenerator section in the <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 43298
diff changeset
   203
     * "{@docRoot}/../specs/security/standard-names.html#algorithmparametergenerator-algorithms">
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 43298
diff changeset
   204
     * Java Security Standard Algorithm Names Specification</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @param provider the string name of the Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   209
     * @return the new {@code AlgorithmParameterGenerator} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   211
     * @throws IllegalArgumentException if the provider name is {@code null}
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   212
     *         or empty
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   214
     * @throws NoSuchAlgorithmException if an
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   215
     *         {@code AlgorithmParameterGeneratorSpi}
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   216
     *         implementation for the specified algorithm is not
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   217
     *         available from the specified provider
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   219
     * @throws NoSuchProviderException if the specified provider is not
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   220
     *         registered in the security provider list
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   221
     *
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   222
     * @throws NullPointerException if {@code algorithm} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @see Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public static AlgorithmParameterGenerator getInstance(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                                                          String provider)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        throws NoSuchAlgorithmException, NoSuchProviderException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    {
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   230
        Objects.requireNonNull(algorithm, "null algorithm name");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        if (provider == null || provider.length() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            throw new IllegalArgumentException("missing provider");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        Object[] objs = Security.getImpl(algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                                         "AlgorithmParameterGenerator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                                         provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        return new AlgorithmParameterGenerator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            ((AlgorithmParameterGeneratorSpi)objs[0], (Provider)objs[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
             algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * Returns an AlgorithmParameterGenerator object for generating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * a set of parameters to be used with the specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * <p> A new AlgorithmParameterGenerator object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * AlgorithmParameterGeneratorSpi implementation from the specified Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * object is returned.  Note that the specified Provider object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * does not have to be registered in the provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @param algorithm the string name of the algorithm this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * parameter generator is associated with.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   252
     * See the AlgorithmParameterGenerator section in the <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 43298
diff changeset
   253
     * "{@docRoot}/../specs/security/standard-names.html#algorithmparametergenerator-algorithms">
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 43298
diff changeset
   254
     * Java Security Standard Algorithm Names Specification</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   257
     * @param provider the {@code Provider} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   259
     * @return the new {@code AlgorithmParameterGenerator} object
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   260
     *
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   261
     * @throws IllegalArgumentException if the specified provider is
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   262
     *         {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   264
     * @throws NoSuchAlgorithmException if an
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   265
     *         {@code AlgorithmParameterGeneratorSpi}
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   266
     *         implementation for the specified algorithm is not available
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   267
     *         from the specified {@code Provider} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   269
     * @throws NullPointerException if {@code algorithm} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @see Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    public static AlgorithmParameterGenerator getInstance(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                                                          Provider provider)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        throws NoSuchAlgorithmException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    {
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   279
        Objects.requireNonNull(algorithm, "null algorithm name");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        if (provider == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            throw new IllegalArgumentException("missing provider");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        Object[] objs = Security.getImpl(algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                                         "AlgorithmParameterGenerator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                                         provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        return new AlgorithmParameterGenerator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            ((AlgorithmParameterGeneratorSpi)objs[0], (Provider)objs[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
             algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * Returns the provider of this algorithm parameter generator object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @return the provider of this algorithm parameter generator object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public final Provider getProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return this.provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * Initializes this parameter generator for a certain size.
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
   301
     * To create the parameters, the {@code SecureRandom}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * implementation of the highest-priority installed provider is used as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * the source of randomness.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * (If none of the installed providers supply an implementation of
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
   305
     * {@code SecureRandom}, a system-provided source of randomness is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * used.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @param size the size (number of bits).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    public final void init(int size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        paramGenSpi.engineInit(size, new SecureRandom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * Initializes this parameter generator for a certain size and source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * of randomness.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * @param size the size (number of bits).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * @param random the source of randomness.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    public final void init(int size, SecureRandom random) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        paramGenSpi.engineInit(size, random);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * Initializes this parameter generator with a set of algorithm-specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * parameter generation values.
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
   328
     * To generate the parameters, the {@code SecureRandom}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * implementation of the highest-priority installed provider is used as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * the source of randomness.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * (If none of the installed providers supply an implementation of
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 9035
diff changeset
   332
     * {@code SecureRandom}, a system-provided source of randomness is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * used.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @param genParamSpec the set of algorithm-specific parameter generation values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @exception InvalidAlgorithmParameterException if the given parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * generation values are inappropriate for this parameter generator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    public final void init(AlgorithmParameterSpec genParamSpec)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        throws InvalidAlgorithmParameterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            paramGenSpi.engineInit(genParamSpec, new SecureRandom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * Initializes this parameter generator with a set of algorithm-specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * parameter generation values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * @param genParamSpec the set of algorithm-specific parameter generation values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @param random the source of randomness.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @exception InvalidAlgorithmParameterException if the given parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * generation values are inappropriate for this parameter generator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    public final void init(AlgorithmParameterSpec genParamSpec,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                           SecureRandom random)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        throws InvalidAlgorithmParameterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            paramGenSpi.engineInit(genParamSpec, random);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * Generates the parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * @return the new AlgorithmParameters object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    public final AlgorithmParameters generateParameters() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        return paramGenSpi.engineGenerateParameters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
}