jdk/src/share/classes/java/security/interfaces/DSAKeyPairGenerator.java
author valeriep
Tue, 04 Sep 2012 18:41:06 -0700
changeset 13672 604588823b5a
parent 5506 202f599c92aa
child 18579 b678846778ad
permissions -rw-r--r--
7044060: Need to support NSA Suite B Cryptography algorithms Summary: Add support for DSA parameter generation and OIDs for NSA Suite B algorithms. Reviewed-by: vinnie
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
13672
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 5506
diff changeset
     2
 * Copyright (c) 1997, 2012, 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.interfaces;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * An interface to an object capable of generating DSA key pairs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * <p>The <code>initialize</code> methods may each be called any number
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * of times. If no <code>initialize</code> method is called on a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * DSAKeyPairGenerator, the default is to generate 1024-bit keys, using
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * precomputed p, q and g parameters and an instance of SecureRandom as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * the random bit source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <p>Users wishing to indicate DSA-specific parameters, and to generate a key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * pair suitable for use with the DSA algorithm typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <li>Get a key pair generator for the DSA algorithm by calling the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * KeyPairGenerator <code>getInstance</code> method with "DSA"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * as its argument.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <li>Initialize the generator by casting the result to a DSAKeyPairGenerator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * and calling one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <code>initialize</code> methods from this DSAKeyPairGenerator interface.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <li>Generate a key pair by calling the <code>generateKeyPair</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * method from the KeyPairGenerator class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>Note: it is not always necessary to do do algorithm-specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * initialization for a DSA key pair generator. That is, it is not always
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * necessary to call an <code>initialize</code> method in this interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * Algorithm-independent initialization using the <code>initialize</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * in the KeyPairGenerator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * interface is all that is needed when you accept defaults for algorithm-specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
13672
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 5506
diff changeset
    65
 * <p>Note: Some earlier implementations of this interface may not support
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 5506
diff changeset
    66
 * larger sizes of DSA parameters such as 2048 and 3072-bit.
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 5506
diff changeset
    67
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * @see java.security.KeyPairGenerator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
public interface DSAKeyPairGenerator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Initializes the key pair generator using the DSA family parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * (p,q and g) and an optional SecureRandom bit source. If a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * SecureRandom bit source is needed but not supplied, i.e. null, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * default SecureRandom instance will be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @param params the parameters to use to generate the keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @param random the random bit source to use to generate key bits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * can be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @exception InvalidParameterException if the <code>params</code>
13672
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 5506
diff changeset
    84
     * value is invalid, null, or unsupported.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
   public void initialize(DSAParams params, SecureRandom random)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
   throws InvalidParameterException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Initializes the key pair generator for a given modulus length
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * (instead of parameters), and an optional SecureRandom bit source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * If a SecureRandom bit source is needed but not supplied, i.e.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * null, a default SecureRandom instance will be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * <p>If <code>genParams</code> is true, this method generates new
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * p, q and g parameters. If it is false, the method uses precomputed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * parameters for the modulus length requested. If there are no
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * precomputed parameters for that modulus length, an exception will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * thrown. It is guaranteed that there will always be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * default parameters for modulus lengths of 512 and 1024 bits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @param modlen the modulus length in bits. Valid values are any
13672
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 5506
diff changeset
   103
     * multiple of 64 between 512 and 1024, inclusive, 2048, and 3072.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @param random the random bit source to use to generate key bits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * can be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @param genParams whether or not to generate new parameters for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * the modulus length requested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *
13672
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 5506
diff changeset
   111
     * @exception InvalidParameterException if <code>modlen</code> is
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 5506
diff changeset
   112
     * invalid, or unsupported, or if <code>genParams</code> is false and there
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 5506
diff changeset
   113
     * are no precomputed parameters for the requested modulus length.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public void initialize(int modlen, boolean genParams, SecureRandom random)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    throws InvalidParameterException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
}