2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / java / security / spec / RSAMultiPrimePrivateCrtKeySpec.java
blobf2cb88bafd124f1503523f0fdcb8ce03989558f1
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., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 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;
41 import java.security.spec.RSAOtherPrimeInfo;
43 /**
44 * This class specifies an RSA multi-prime private key, as defined in the
45 * PKCS#1 v2.1, using the <i>Chinese Remainder Theorem</i> (CRT) information
46 * values for efficiency.
48 * @since 1.4
49 * @see java.security.Key
50 * @see java.security.KeyFactory
51 * @see KeySpec
52 * @see PKCS8EncodedKeySpec
53 * @see RSAPrivateKeySpec
54 * @see RSAPublicKeySpec
55 * @see RSAOtherPrimeInfo
57 public class RSAMultiPrimePrivateCrtKeySpec extends RSAPrivateKeySpec
59 // Constants and fields
60 // --------------------------------------------------------------------------
62 private BigInteger publicExponent;
63 private BigInteger primeP;
64 private BigInteger primeQ;
65 private BigInteger primeExponentP;
66 private BigInteger primeExponentQ;
67 private BigInteger crtCoefficient;
68 private RSAOtherPrimeInfo[] otherPrimeInfo;
70 // Constructor(s)
71 // --------------------------------------------------------------------------
73 /**
74 * <p>Creates a new <code>RSAMultiPrimePrivateCrtKeySpec</code> given the
75 * modulus, publicExponent, privateExponent, primeP, primeQ, primeExponentP,
76 * primeExponentQ, crtCoefficient, and otherPrimeInfo as defined in PKCS#1
77 * v2.1.</p>
79 * <p>Note that <code>otherPrimeInfo</code> is cloned when constructing this
80 * object.</p>
82 * @param modulus the modulus n.
83 * @param publicExponent the public exponent e.
84 * @param privateExponent the private exponent d.
85 * @param primeP the prime factor p of n.
86 * @param primeQ the prime factor q of n.
87 * @param primeExponentP this is d mod (p-1).
88 * @param primeExponentQ this is d mod (q-1).
89 * @param crtCoefficient the Chinese Remainder Theorem coefficient q-1 mod p.
90 * @param otherPrimeInfo triplets of the rest of primes, <code>null</code>
91 * can be specified if there are only two prime factors (p and q).
92 * @throws NullPointerException if any of the parameters, i.e. modulus,
93 * publicExponent, privateExponent, primeP, primeQ, primeExponentP,
94 * primeExponentQ, crtCoefficient, is <code>null</code>.
95 * @throws IllegalArgumentException if an empty, i.e. 0-length,
96 * otherPrimeInfo is specified.
98 public RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus,
99 BigInteger publicExponent,
100 BigInteger privateExponent,
101 BigInteger primeP,
102 BigInteger primeQ,
103 BigInteger primeExponentP,
104 BigInteger primeExponentQ,
105 BigInteger crtCoefficient,
106 RSAOtherPrimeInfo[] otherPrimeInfo)
108 super(modulus, privateExponent);
110 if (modulus == null)
111 throw new NullPointerException("modulus");
112 if (publicExponent == null)
113 throw new NullPointerException("publicExponent");
114 if (privateExponent == null)
115 throw new NullPointerException("privateExponent");
116 if (primeP == null)
117 throw new NullPointerException("primeP");
118 if (primeQ == null)
119 throw new NullPointerException("primeQ");
120 if (primeExponentP == null)
121 throw new NullPointerException("primeExponentP");
122 if (primeExponentQ == null)
123 throw new NullPointerException("primeExponentQ");
124 if (crtCoefficient == null)
125 throw new NullPointerException("crtCoefficient");
126 if (otherPrimeInfo != null)
127 if (otherPrimeInfo.length == 0)
128 throw new IllegalArgumentException();
129 else
130 this.otherPrimeInfo = (RSAOtherPrimeInfo[]) otherPrimeInfo.clone();
132 this.publicExponent = publicExponent;
133 this.primeP = primeP;
134 this.primeQ = primeQ;
135 this.primeExponentP = primeExponentP;
136 this.primeExponentQ = primeExponentQ;
137 this.crtCoefficient = crtCoefficient;
140 // Class methods
141 // --------------------------------------------------------------------------
143 // Instance methods
144 // --------------------------------------------------------------------------
147 * Returns the public exponent.
149 * @return the public exponent.
151 public BigInteger getPublicExponent()
153 return this.publicExponent;
157 * Returns the primeP.
159 * @return the primeP.
161 public BigInteger getPrimeP()
163 return this.primeP;
167 * Returns the primeQ.
169 * @return the primeQ.
171 public BigInteger getPrimeQ()
173 return this.primeQ;
177 * Returns the primeExponentP.
179 * @return the primeExponentP.
181 public BigInteger getPrimeExponentP()
183 return this.primeExponentP;
187 * Returns the primeExponentQ.
189 * @return the primeExponentQ.
191 public BigInteger getPrimeExponentQ()
193 return this.primeExponentQ;
197 * Returns the crtCoefficient.
199 * @return the crtCoefficient.
201 public BigInteger getCrtCoefficient()
203 return this.crtCoefficient;
207 * Returns a copy of the otherPrimeInfo or <code>null</code> if there are
208 * only two prime factors (p and q).
210 * @return the otherPrimeInfo.
212 public RSAOtherPrimeInfo[] getOtherPrimeInfo()
214 return this.otherPrimeInfo == null
215 ? null
216 : (RSAOtherPrimeInfo[]) this.otherPrimeInfo.clone();