src/java.base/share/classes/java/security/spec/DSAGenParameterSpec.java
author jboes
Fri, 20 Sep 2019 11:07:52 +0100
changeset 58242 94bb65cb37d3
parent 47216 71c04702a3d5
permissions -rw-r--r--
8230648: Replace @exception tag with @throws in java.base Summary: Minor coding style update of javadoc tag in any file in java.base Reviewed-by: prappo, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13672
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
     1
/*
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
     2
 * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
13672
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
     4
 *
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    10
 *
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    15
 * accompanied this code).
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    16
 *
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    20
 *
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    23
 * questions.
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    24
 */
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    25
package java.security.spec;
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    26
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    27
/**
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    28
 * This immutable class specifies the set of parameters used for
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    29
 * generating DSA parameters as specified in
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    30
 * <a href="http://csrc.nist.gov/publications/fips/fips186-3/fips_186-3.pdf">FIPS 186-3 Digital Signature Standard (DSS)</a>.
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    31
 *
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    32
 * @see AlgorithmParameterSpec
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    33
 *
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 18552
diff changeset
    34
 * @since 1.8
13672
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    35
 */
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    36
public final class DSAGenParameterSpec implements AlgorithmParameterSpec {
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    37
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    38
    private final int pLen;
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    39
    private final int qLen;
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    40
    private final int seedLen;
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    41
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    42
    /**
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    43
     * Creates a domain parameter specification for DSA parameter
18552
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 13672
diff changeset
    44
     * generation using {@code primePLen} and {@code subprimeQLen}.
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 13672
diff changeset
    45
     * The value of {@code subprimeQLen} is also used as the default
13672
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    46
     * length of the domain parameter seed in bits.
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    47
     * @param primePLen the desired length of the prime P in bits.
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    48
     * @param subprimeQLen the desired length of the sub-prime Q in bits.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
    49
     * @throws    IllegalArgumentException if {@code primePLen}
18552
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 13672
diff changeset
    50
     * or {@code subprimeQLen} is illegal per the specification of
13672
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    51
     * FIPS 186-3.
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    52
     */
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    53
    public DSAGenParameterSpec(int primePLen, int subprimeQLen) {
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    54
        this(primePLen, subprimeQLen, subprimeQLen);
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    55
    }
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    56
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    57
    /**
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    58
     * Creates a domain parameter specification for DSA parameter
18552
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 13672
diff changeset
    59
     * generation using {@code primePLen}, {@code subprimeQLen},
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 13672
diff changeset
    60
     * and {@code seedLen}.
13672
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    61
     * @param primePLen the desired length of the prime P in bits.
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    62
     * @param subprimeQLen the desired length of the sub-prime Q in bits.
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    63
     * @param seedLen the desired length of the domain parameter seed in bits,
18552
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 13672
diff changeset
    64
     * shall be equal to or greater than {@code subprimeQLen}.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
    65
     * @throws    IllegalArgumentException if {@code primePLenLen},
18552
005e115dc6ee 8017326: Cleanup of the javadoc <code> tag in java.security.spec
juh
parents: 13672
diff changeset
    66
     * {@code subprimeQLen}, or {@code seedLen} is illegal per the
13672
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    67
     * specification of FIPS 186-3.
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    68
     */
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    69
    public DSAGenParameterSpec(int primePLen, int subprimeQLen, int seedLen) {
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    70
        switch (primePLen) {
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    71
        case 1024:
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    72
            if (subprimeQLen != 160) {
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    73
                throw new IllegalArgumentException
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    74
                    ("subprimeQLen must be 160 when primePLen=1024");
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    75
            }
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    76
            break;
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    77
        case 2048:
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    78
            if (subprimeQLen != 224 && subprimeQLen != 256) {
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    79
               throw new IllegalArgumentException
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    80
                   ("subprimeQLen must be 224 or 256 when primePLen=2048");
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    81
            }
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    82
            break;
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    83
        case 3072:
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    84
            if (subprimeQLen != 256) {
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    85
                throw new IllegalArgumentException
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    86
                    ("subprimeQLen must be 256 when primePLen=3072");
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    87
            }
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    88
            break;
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    89
        default:
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    90
            throw new IllegalArgumentException
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    91
                ("primePLen must be 1024, 2048, or 3072");
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    92
        }
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    93
        if (seedLen < subprimeQLen) {
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    94
            throw new IllegalArgumentException
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    95
                ("seedLen must be equal to or greater than subprimeQLen");
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    96
        }
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    97
        this.pLen = primePLen;
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    98
        this.qLen = subprimeQLen;
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
    99
        this.seedLen = seedLen;
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   100
    }
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   101
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   102
    /**
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   103
     * Returns the desired length of the prime P of the
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   104
     * to-be-generated DSA domain parameters in bits.
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   105
     * @return the length of the prime P.
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   106
     */
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   107
    public int getPrimePLength() {
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   108
        return pLen;
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   109
    }
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   110
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   111
    /**
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   112
     * Returns the desired length of the sub-prime Q of the
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   113
     * to-be-generated DSA domain parameters in bits.
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   114
     * @return the length of the sub-prime Q.
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   115
     */
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   116
    public int getSubprimeQLength() {
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   117
        return qLen;
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   118
    }
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   119
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   120
    /**
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   121
     * Returns the desired length of the domain parameter seed in bits.
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   122
     * @return the length of the domain parameter seed.
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   123
     */
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   124
    public int getSeedLength() {
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   125
        return seedLen;
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   126
    }
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents:
diff changeset
   127
}