jdk/src/share/classes/java/security/spec/RSAMultiPrimePrivateCrtKeySpec.java
author never
Mon, 12 Jul 2010 22:27:18 -0700
changeset 5926 a36f90d986b6
parent 5506 202f599c92aa
child 18552 005e115dc6ee
permissions -rw-r--r--
6968385: malformed xml in sweeper logging Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2001, 2003, 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
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * This class specifies an RSA multi-prime private key, as defined in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * PKCS#1 v2.1, using the Chinese Remainder Theorem (CRT) information
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * values for efficiency.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * @author Valerie Peng
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @see java.security.Key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @see java.security.KeyFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @see KeySpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @see PKCS8EncodedKeySpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @see RSAPrivateKeySpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @see RSAPublicKeySpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @see RSAOtherPrimeInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
public class RSAMultiPrimePrivateCrtKeySpec extends RSAPrivateKeySpec {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private final BigInteger publicExponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private final BigInteger primeP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private final BigInteger primeQ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private final BigInteger primeExponentP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private final BigInteger primeExponentQ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private final BigInteger crtCoefficient;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private final RSAOtherPrimeInfo otherPrimeInfo[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    * Creates a new <code>RSAMultiPrimePrivateCrtKeySpec</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    * given the modulus, publicExponent, privateExponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    * primeP, primeQ, primeExponentP, primeExponentQ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    * crtCoefficient, and otherPrimeInfo as defined in PKCS#1 v2.1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    * <p>Note that the contents of <code>otherPrimeInfo</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    * are copied to protect against subsequent modification when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    * constructing this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    * @param modulus the modulus n.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    * @param publicExponent the public exponent e.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    * @param privateExponent the private exponent d.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    * @param primeP the prime factor p of n.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    * @param primeQ the prime factor q of n.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    * @param primeExponentP this is d mod (p-1).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    * @param primeExponentQ this is d mod (q-1).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    * @param crtCoefficient the Chinese Remainder Theorem
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    * coefficient q-1 mod p.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    * @param otherPrimeInfo triplets of the rest of primes, null can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    * specified if there are only two prime factors (p and q).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    * @exception NullPointerException if any of the parameters, i.e.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    * <code>modulus</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    * <code>publicExponent</code>, <code>privateExponent</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    * <code>primeP</code>, <code>primeQ</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    * <code>primeExponentP</code>, <code>primeExponentQ</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    * <code>crtCoefficient</code>, is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    * @exception IllegalArgumentException if an empty, i.e. 0-length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    * <code>otherPrimeInfo</code> is specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                BigInteger publicExponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                                BigInteger privateExponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                                BigInteger primeP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                                BigInteger primeQ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                                BigInteger primeExponentP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                                BigInteger primeExponentQ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                                BigInteger crtCoefficient,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                                RSAOtherPrimeInfo[] otherPrimeInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        super(modulus, privateExponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        if (modulus == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            throw new NullPointerException("the modulus parameter must be " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                                            "non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        if (publicExponent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            throw new NullPointerException("the publicExponent parameter " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                                            "must be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        if (privateExponent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            throw new NullPointerException("the privateExponent parameter " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                                            "must be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        if (primeP == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            throw new NullPointerException("the primeP parameter " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                                            "must be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (primeQ == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            throw new NullPointerException("the primeQ parameter " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                            "must be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        if (primeExponentP == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            throw new NullPointerException("the primeExponentP parameter " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                                            "must be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        if (primeExponentQ == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            throw new NullPointerException("the primeExponentQ parameter " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                                            "must be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if (crtCoefficient == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            throw new NullPointerException("the crtCoefficient parameter " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                                            "must be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        this.publicExponent = publicExponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        this.primeP = primeP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        this.primeQ = primeQ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        this.primeExponentP = primeExponentP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        this.primeExponentQ = primeExponentQ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        this.crtCoefficient = crtCoefficient;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (otherPrimeInfo == null)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            this.otherPrimeInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        } else if (otherPrimeInfo.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            throw new IllegalArgumentException("the otherPrimeInfo " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                                                "parameter must not be empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            this.otherPrimeInfo = otherPrimeInfo.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * Returns the public exponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @return the public exponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public BigInteger getPublicExponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        return this.publicExponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Returns the primeP.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @return the primeP.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public BigInteger getPrimeP() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        return this.primeP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * Returns the primeQ.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @return the primeQ.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public BigInteger getPrimeQ() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        return this.primeQ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Returns the primeExponentP.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @return the primeExponentP.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public BigInteger getPrimeExponentP() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        return this.primeExponentP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * Returns the primeExponentQ.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @return the primeExponentQ.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public BigInteger getPrimeExponentQ() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        return this.primeExponentQ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Returns the crtCoefficient.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @return the crtCoefficient.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public BigInteger getCrtCoefficient() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        return this.crtCoefficient;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * Returns a copy of the otherPrimeInfo or null if there are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * only two prime factors (p and q).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @return the otherPrimeInfo. Returns a new array each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * time this method is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public RSAOtherPrimeInfo[] getOtherPrimeInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        if (otherPrimeInfo == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        return otherPrimeInfo.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
}