src/java.base/share/classes/java/security/spec/RSAPrivateCrtKeySpec.java
author wetmore
Fri, 11 May 2018 15:53:12 -0700
branchJDK-8145252-TLS13-branch
changeset 56542 56aaa6cb3693
parent 47216 71c04702a3d5
permissions -rw-r--r--
Initial TLSv1.3 Implementation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
     2
 * Copyright (c) 1998, 2018, 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.spec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.math.BigInteger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    31
 * This class specifies an RSA private key, as defined in the
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    32
 * <a href="https://tools.ietf.org/rfc/rfc8017.txt">PKCS#1 v2.2</a> standard,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    33
 * using the Chinese Remainder Theorem (CRT) information values for efficiency.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * @author Jan Luehe
45434
4582657c7260 8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents: 25859
diff changeset
    36
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @see java.security.Key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @see java.security.KeyFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @see KeySpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @see PKCS8EncodedKeySpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @see RSAPrivateKeySpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @see RSAPublicKeySpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
public class RSAPrivateCrtKeySpec extends RSAPrivateKeySpec {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private final BigInteger publicExponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private final BigInteger primeP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private final BigInteger primeQ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private final BigInteger primeExponentP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private final BigInteger primeExponentQ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private final BigInteger crtCoefficient;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
   /**
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    57
    * Creates a new {@code RSAPrivateCrtKeySpec}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    * @param modulus the modulus n
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    * @param publicExponent the public exponent e
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    * @param privateExponent the private exponent d
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    * @param primeP the prime factor p of n
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    * @param primeQ the prime factor q of n
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    * @param primeExponentP this is d mod (p-1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    * @param primeExponentQ this is d mod (q-1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    * @param crtCoefficient the Chinese Remainder Theorem
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    * coefficient q-1 mod p
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public RSAPrivateCrtKeySpec(BigInteger modulus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                                BigInteger publicExponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                                BigInteger privateExponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                                BigInteger primeP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                                BigInteger primeQ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                                BigInteger primeExponentP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                                BigInteger primeExponentQ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                                BigInteger crtCoefficient) {
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    77
        this(modulus, publicExponent, privateExponent, primeP, primeQ,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    78
             primeExponentP, primeExponentQ, crtCoefficient, null);
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    79
    }
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    80
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    81
   /**
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    82
    * Creates a new {@code RSAPrivateCrtKeySpec} with additional
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    83
    * key parameters.
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    84
    *
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    85
    * @param modulus the modulus n
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    86
    * @param publicExponent the public exponent e
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    87
    * @param privateExponent the private exponent d
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    88
    * @param primeP the prime factor p of n
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    89
    * @param primeQ the prime factor q of n
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    90
    * @param primeExponentP this is d mod (p-1)
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    91
    * @param primeExponentQ this is d mod (q-1)
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    92
    * @param crtCoefficient the Chinese Remainder Theorem
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    93
    * coefficient q-1 mod p
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    94
    * @param keyParams the parameters associated with key
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    95
    * @since 11
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    96
    */
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    97
    public RSAPrivateCrtKeySpec(BigInteger modulus,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    98
                                BigInteger publicExponent,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    99
                                BigInteger privateExponent,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   100
                                BigInteger primeP,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   101
                                BigInteger primeQ,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   102
                                BigInteger primeExponentP,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   103
                                BigInteger primeExponentQ,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   104
                                BigInteger crtCoefficient,
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   105
                                AlgorithmParameterSpec keyParams) {
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   106
        super(modulus, privateExponent, keyParams);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        this.publicExponent = publicExponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        this.primeP = primeP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        this.primeQ = primeQ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        this.primeExponentP = primeExponentP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        this.primeExponentQ = primeExponentQ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        this.crtCoefficient = crtCoefficient;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Returns the public exponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @return the public exponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public BigInteger getPublicExponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        return this.publicExponent;
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 primeP.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @return the primeP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public BigInteger getPrimeP() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        return this.primeP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * Returns the primeQ.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @return the primeQ
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public BigInteger getPrimeQ() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        return this.primeQ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * Returns the primeExponentP.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @return the primeExponentP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public BigInteger getPrimeExponentP() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        return this.primeExponentP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * Returns the primeExponentQ.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @return the primeExponentQ
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public BigInteger getPrimeExponentQ() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        return this.primeExponentQ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * Returns the crtCoefficient.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @return the crtCoefficient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public BigInteger getCrtCoefficient() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        return this.crtCoefficient;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
}