1 /*
2  * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package java.security.interfaces;
27 
28 import java.security.*;
29 
30 /**
31  * An interface to an object capable of generating DSA key pairs.
32  *
33  * <p>The {@code initialize} methods may each be called any number
34  * of times. If no {@code initialize} method is called on a
35  * DSAKeyPairGenerator, each provider that implements this interface
36  * should supply (and document) a default initialization. Note that
37  * defaults may vary across different providers. Additionally, the default
38  * value for a provider may change in a future version. Therefore, it is
39  * recommended to explicitly initialize the DSAKeyPairGenerator instead
40  * of relying on provider-specific defaults.
41  *
42  * <p>Users wishing to indicate DSA-specific parameters, and to generate a key
43  * pair suitable for use with the DSA algorithm typically
44  *
45  * <ol>
46  *
47  * <li>Get a key pair generator for the DSA algorithm by calling the
48  * KeyPairGenerator {@code getInstance} method with "DSA"
49  * as its argument.
50  *
51  * <li>Check if the returned key pair generator is an instance of
52  * DSAKeyPairGenerator before casting the result to a DSAKeyPairGenerator
53  * and calling one of the {@code initialize} methods from this
54  * DSAKeyPairGenerator interface.
55  *
56  * <li>Generate a key pair by calling the {@code generateKeyPair}
57  * method of the KeyPairGenerator class.
58  *
59  * </ol>
60  *
61  * <p>Note: it is not always necessary to do algorithm-specific
62  * initialization for a DSA key pair generator. That is, it is not always
63  * necessary to call an {@code initialize} method in this interface.
64  * Algorithm-independent initialization using the {@code initialize} method
65  * in the KeyPairGenerator
66  * interface is all that is needed when you accept defaults for algorithm-specific
67  * parameters.
68  *
69  * <p>Note: Some earlier implementations of this interface may not support
70  * larger values of DSA parameters such as 3072-bit.
71  *
72  * @since 1.1
73  * @see java.security.KeyPairGenerator
74  */
75 public interface DSAKeyPairGenerator {
76 
77     /**
78      * Initializes the key pair generator using the DSA family parameters
79      * (p,q and g) and an optional SecureRandom bit source. If a
80      * SecureRandom bit source is needed but not supplied, i.e. null, a
81      * default SecureRandom instance will be used.
82      *
83      * @param params the parameters to use to generate the keys.
84      *
85      * @param random the random bit source to use to generate key bits;
86      * can be null.
87      *
88      * @throws    InvalidParameterException if the {@code params}
89      * value is invalid, null, or unsupported.
90      */
initialize(DSAParams params, SecureRandom random)91    public void initialize(DSAParams params, SecureRandom random)
92    throws InvalidParameterException;
93 
94     /**
95      * Initializes the key pair generator for a given modulus length
96      * (instead of parameters), and an optional SecureRandom bit source.
97      * If a SecureRandom bit source is needed but not supplied, i.e.
98      * null, a default SecureRandom instance will be used.
99      *
100      * <p>If {@code genParams} is true, this method generates new
101      * p, q and g parameters. If it is false, the method uses precomputed
102      * parameters for the modulus length requested. If there are no
103      * precomputed parameters for that modulus length, an exception will be
104      * thrown.
105      *
106      * @param modlen the modulus length in bits. Valid values are any
107      * multiple of 64 between 512 and 1024, inclusive, 2048, and 3072.
108      *
109      * @param random the random bit source to use to generate key bits;
110      * can be null.
111      *
112      * @param genParams whether or not to generate new parameters for
113      * the modulus length requested.
114      *
115      * @throws    InvalidParameterException if {@code modlen} is
116      * invalid, or unsupported, or if {@code genParams} is false and there
117      * are no precomputed parameters for the requested modulus length.
118      */
initialize(int modlen, boolean genParams, SecureRandom random)119     public void initialize(int modlen, boolean genParams, SecureRandom random)
120     throws InvalidParameterException;
121 }
122