1 /*
2  * Copyright (c) 1997, 2013, 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, the default is to generate 1024-bit keys, using
36  * precomputed p, q and g parameters and an instance of SecureRandom as
37  * the random bit source.
38  *
39  * <p>Users wishing to indicate DSA-specific parameters, and to generate a key
40  * pair suitable for use with the DSA algorithm typically
41  *
42  * <ol>
43  *
44  * <li>Get a key pair generator for the DSA algorithm by calling the
45  * KeyPairGenerator {@code getInstance} method with "DSA"
46  * as its argument.
47  *
48  * <li>Initialize the generator by casting the result to a DSAKeyPairGenerator
49  * and calling one of the
50  * {@code initialize} methods from this DSAKeyPairGenerator interface.
51  *
52  * <li>Generate a key pair by calling the {@code generateKeyPair}
53  * method from the KeyPairGenerator class.
54  *
55  * </ol>
56  *
57  * <p>Note: it is not always necessary to do do algorithm-specific
58  * initialization for a DSA key pair generator. That is, it is not always
59  * necessary to call an {@code initialize} method in this interface.
60  * Algorithm-independent initialization using the {@code initialize} method
61  * in the KeyPairGenerator
62  * interface is all that is needed when you accept defaults for algorithm-specific
63  * parameters.
64  *
65  * <p>Note: Some earlier implementations of this interface may not support
66  * larger sizes of DSA parameters such as 2048 and 3072-bit.
67  *
68  * @see java.security.KeyPairGenerator
69  */
70 public interface DSAKeyPairGenerator {
71 
72     /**
73      * Initializes the key pair generator using the DSA family parameters
74      * (p,q and g) and an optional SecureRandom bit source. If a
75      * SecureRandom bit source is needed but not supplied, i.e. null, a
76      * default SecureRandom instance will be used.
77      *
78      * @param params the parameters to use to generate the keys.
79      *
80      * @param random the random bit source to use to generate key bits;
81      * can be null.
82      *
83      * @exception InvalidParameterException if the {@code params}
84      * value is invalid, null, or unsupported.
85      */
initialize(DSAParams params, SecureRandom random)86    public void initialize(DSAParams params, SecureRandom random)
87    throws InvalidParameterException;
88 
89     /**
90      * Initializes the key pair generator for a given modulus length
91      * (instead of parameters), and an optional SecureRandom bit source.
92      * If a SecureRandom bit source is needed but not supplied, i.e.
93      * null, a default SecureRandom instance will be used.
94      *
95      * <p>If {@code genParams} is true, this method generates new
96      * p, q and g parameters. If it is false, the method uses precomputed
97      * parameters for the modulus length requested. If there are no
98      * precomputed parameters for that modulus length, an exception will be
99      * thrown. It is guaranteed that there will always be
100      * default parameters for modulus lengths of 512 and 1024 bits.
101      *
102      * @param modlen the modulus length in bits. Valid values are any
103      * multiple of 64 between 512 and 1024, inclusive, 2048, and 3072.
104      *
105      * @param random the random bit source to use to generate key bits;
106      * can be null.
107      *
108      * @param genParams whether or not to generate new parameters for
109      * the modulus length requested.
110      *
111      * @exception InvalidParameterException if {@code modlen} is
112      * invalid, or unsupported, or if {@code genParams} is false and there
113      * are no precomputed parameters for the requested modulus length.
114      */
initialize(int modlen, boolean genParams, SecureRandom random)115     public void initialize(int modlen, boolean genParams, SecureRandom random)
116     throws InvalidParameterException;
117 }
118