Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / java / security / spec / RSAMultiPrimePrivateCrtKeySpec.java
blob519a02913737d6e7eaf79443143238651c37a06a
1 /* PSSParameterSpec.java --
2 Copyright (C) 2003, Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package java.security.spec;
40 import java.math.BigInteger;
42 /**
43 * This class specifies an RSA multi-prime private key, as defined in the
44 * PKCS#1 v2.1, using the <i>Chinese Remainder Theorem</i> (CRT) information
45 * values for efficiency.
47 * @since 1.4
48 * @see java.security.Key
49 * @see java.security.KeyFactory
50 * @see KeySpec
51 * @see PKCS8EncodedKeySpec
52 * @see RSAPrivateKeySpec
53 * @see RSAPublicKeySpec
54 * @see RSAOtherPrimeInfo
56 public class RSAMultiPrimePrivateCrtKeySpec extends RSAPrivateKeySpec
58 // Constants and fields
59 // --------------------------------------------------------------------------
61 private BigInteger publicExponent;
62 private BigInteger primeP;
63 private BigInteger primeQ;
64 private BigInteger primeExponentP;
65 private BigInteger primeExponentQ;
66 private BigInteger crtCoefficient;
67 private RSAOtherPrimeInfo[] otherPrimeInfo;
69 // Constructor(s)
70 // --------------------------------------------------------------------------
72 /**
73 * <p>Creates a new <code>RSAMultiPrimePrivateCrtKeySpec</code> given the
74 * modulus, publicExponent, privateExponent, primeP, primeQ, primeExponentP,
75 * primeExponentQ, crtCoefficient, and otherPrimeInfo as defined in PKCS#1
76 * v2.1.</p>
78 * <p>Note that <code>otherPrimeInfo</code> is cloned when constructing this
79 * object.</p>
81 * @param modulus the modulus n.
82 * @param publicExponent the public exponent e.
83 * @param privateExponent the private exponent d.
84 * @param primeP the prime factor p of n.
85 * @param primeQ the prime factor q of n.
86 * @param primeExponentP this is d mod (p-1).
87 * @param primeExponentQ this is d mod (q-1).
88 * @param crtCoefficient the Chinese Remainder Theorem coefficient q-1 mod p.
89 * @param otherPrimeInfo triplets of the rest of primes, <code>null</code>
90 * can be specified if there are only two prime factors (p and q).
91 * @throws NullPointerException if any of the parameters, i.e. modulus,
92 * publicExponent, privateExponent, primeP, primeQ, primeExponentP,
93 * primeExponentQ, crtCoefficient, is <code>null</code>.
94 * @throws IllegalArgumentException if an empty, i.e. 0-length,
95 * otherPrimeInfo is specified.
97 public RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus,
98 BigInteger publicExponent,
99 BigInteger privateExponent,
100 BigInteger primeP,
101 BigInteger primeQ,
102 BigInteger primeExponentP,
103 BigInteger primeExponentQ,
104 BigInteger crtCoefficient,
105 RSAOtherPrimeInfo[] otherPrimeInfo)
107 super(modulus, privateExponent);
109 if (modulus == null)
110 throw new NullPointerException("modulus");
111 if (publicExponent == null)
112 throw new NullPointerException("publicExponent");
113 if (privateExponent == null)
114 throw new NullPointerException("privateExponent");
115 if (primeP == null)
116 throw new NullPointerException("primeP");
117 if (primeQ == null)
118 throw new NullPointerException("primeQ");
119 if (primeExponentP == null)
120 throw new NullPointerException("primeExponentP");
121 if (primeExponentQ == null)
122 throw new NullPointerException("primeExponentQ");
123 if (crtCoefficient == null)
124 throw new NullPointerException("crtCoefficient");
125 if (otherPrimeInfo != null)
126 if (otherPrimeInfo.length == 0)
127 throw new IllegalArgumentException();
128 else
129 this.otherPrimeInfo = (RSAOtherPrimeInfo[]) otherPrimeInfo.clone();
131 this.publicExponent = publicExponent;
132 this.primeP = primeP;
133 this.primeQ = primeQ;
134 this.primeExponentP = primeExponentP;
135 this.primeExponentQ = primeExponentQ;
136 this.crtCoefficient = crtCoefficient;
139 // Class methods
140 // --------------------------------------------------------------------------
142 // Instance methods
143 // --------------------------------------------------------------------------
146 * Returns the public exponent.
148 * @return the public exponent.
150 public BigInteger getPublicExponent()
152 return this.publicExponent;
156 * Returns the primeP.
158 * @return the primeP.
160 public BigInteger getPrimeP()
162 return this.primeP;
166 * Returns the primeQ.
168 * @return the primeQ.
170 public BigInteger getPrimeQ()
172 return this.primeQ;
176 * Returns the primeExponentP.
178 * @return the primeExponentP.
180 public BigInteger getPrimeExponentP()
182 return this.primeExponentP;
186 * Returns the primeExponentQ.
188 * @return the primeExponentQ.
190 public BigInteger getPrimeExponentQ()
192 return this.primeExponentQ;
196 * Returns the crtCoefficient.
198 * @return the crtCoefficient.
200 public BigInteger getCrtCoefficient()
202 return this.crtCoefficient;
206 * Returns a copy of the otherPrimeInfo or <code>null</code> if there are
207 * only two prime factors (p and q).
209 * @return the otherPrimeInfo.
211 public RSAOtherPrimeInfo[] getOtherPrimeInfo()
213 return this.otherPrimeInfo == null
214 ? null
215 : (RSAOtherPrimeInfo[]) this.otherPrimeInfo.clone();