001/* PSSParameterSpec.java -- 002 Copyright (C) 2003, Free Software Foundation, Inc. 003 004This file is part of GNU Classpath. 005 006GNU Classpath is free software; you can redistribute it and/or modify 007it under the terms of the GNU General Public License as published by 008the Free Software Foundation; either version 2, or (at your option) 009any later version. 010 011GNU Classpath is distributed in the hope that it will be useful, but 012WITHOUT ANY WARRANTY; without even the implied warranty of 013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014General Public License for more details. 015 016You should have received a copy of the GNU General Public License 017along with GNU Classpath; see the file COPYING. If not, write to the 018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 01902110-1301 USA. 020 021Linking this library statically or dynamically with other modules is 022making a combined work based on this library. Thus, the terms and 023conditions of the GNU General Public License cover the whole 024combination. 025 026As a special exception, the copyright holders of this library give you 027permission to link this library with independent modules to produce an 028executable, regardless of the license terms of these independent 029modules, and to copy and distribute the resulting executable under 030terms of your choice, provided that you also meet, for each linked 031independent module, the terms and conditions of the license of that 032module. An independent module is a module which is not derived from 033or based on this library. If you modify this library, you may extend 034this exception to your version of the library, but you are not 035obligated to do so. If you do not wish to do so, delete this 036exception statement from your version. */ 037 038package java.security.spec; 039 040import java.math.BigInteger; 041 042/** 043 * This class represents an RSA multi-prime private key, as defined in the 044 * PKCS#1 v2.1, using the <i>Chinese Remainder Theorem</i> (CRT) information 045 * values. 046 * 047 * @since 1.4 048 * @see java.security.Key 049 * @see java.security.KeyFactory 050 * @see KeySpec 051 * @see PKCS8EncodedKeySpec 052 * @see RSAPrivateKeySpec 053 * @see RSAPublicKeySpec 054 * @see RSAOtherPrimeInfo 055 */ 056public class RSAMultiPrimePrivateCrtKeySpec extends RSAPrivateKeySpec 057{ 058 // Constants and fields 059 // -------------------------------------------------------------------------- 060 061 private BigInteger publicExponent; 062 private BigInteger primeP; 063 private BigInteger primeQ; 064 private BigInteger primeExponentP; 065 private BigInteger primeExponentQ; 066 private BigInteger crtCoefficient; 067 private RSAOtherPrimeInfo[] otherPrimeInfo; 068 069 // Constructor(s) 070 // -------------------------------------------------------------------------- 071 072 /** 073 * Constructs a new instance of <code>RSAMultiPrimePrivateCrtKeySpec</code> 074 * given the various PKCS#1 v2.1 parameters. 075 * 076 * <p>Note that <code>otherPrimeInfo</code> is cloned when constructing this 077 * object.</p> 078 * 079 * @param modulus 080 * the modulus n. 081 * @param publicExponent 082 * the public exponent e. 083 * @param privateExponent 084 * the private exponent d. 085 * @param primeP 086 * the prime factor p of n. 087 * @param primeQ 088 * the prime factor q of n. 089 * @param primeExponentP 090 * this is d mod (p-1). 091 * @param primeExponentQ 092 * this is d mod (q-1). 093 * @param crtCoefficient 094 * the Chinese Remainder Theorem coefficient q-1 mod p. 095 * @param otherPrimeInfo 096 * triplets of the rest of primes, <code>null</code> can be 097 * specified if there are only two prime factors (p and q). 098 * @throws NullPointerException 099 * if any of the parameters is <code>null</code>. 100 * @throws IllegalArgumentException 101 * if an empty <code>otherPrimeInfo</code> is specified. 102 */ 103 public RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus, 104 BigInteger publicExponent, 105 BigInteger privateExponent, 106 BigInteger primeP, 107 BigInteger primeQ, 108 BigInteger primeExponentP, 109 BigInteger primeExponentQ, 110 BigInteger crtCoefficient, 111 RSAOtherPrimeInfo[] otherPrimeInfo) 112 { 113 super(modulus, privateExponent); 114 115 if (modulus == null) 116 throw new NullPointerException("modulus"); 117 if (publicExponent == null) 118 throw new NullPointerException("publicExponent"); 119 if (privateExponent == null) 120 throw new NullPointerException("privateExponent"); 121 if (primeP == null) 122 throw new NullPointerException("primeP"); 123 if (primeQ == null) 124 throw new NullPointerException("primeQ"); 125 if (primeExponentP == null) 126 throw new NullPointerException("primeExponentP"); 127 if (primeExponentQ == null) 128 throw new NullPointerException("primeExponentQ"); 129 if (crtCoefficient == null) 130 throw new NullPointerException("crtCoefficient"); 131 if (otherPrimeInfo != null) 132 if (otherPrimeInfo.length == 0) 133 throw new IllegalArgumentException(); 134 else 135 this.otherPrimeInfo = (RSAOtherPrimeInfo[]) otherPrimeInfo.clone(); 136 137 this.publicExponent = publicExponent; 138 this.primeP = primeP; 139 this.primeQ = primeQ; 140 this.primeExponentP = primeExponentP; 141 this.primeExponentQ = primeExponentQ; 142 this.crtCoefficient = crtCoefficient; 143 } 144 145 // Class methods 146 // -------------------------------------------------------------------------- 147 148 // Instance methods 149 // -------------------------------------------------------------------------- 150 151 /** 152 * Returns the public exponent. 153 * 154 * @return the public exponent. 155 */ 156 public BigInteger getPublicExponent() 157 { 158 return this.publicExponent; 159 } 160 161 /** 162 * Returns the prime p. 163 * 164 * @return the prime p. 165 */ 166 public BigInteger getPrimeP() 167 { 168 return this.primeP; 169 } 170 171 /** 172 * Returns the prime q. 173 * 174 * @return the prime q. 175 */ 176 public BigInteger getPrimeQ() 177 { 178 return this.primeQ; 179 } 180 181 /** 182 * Returns d mod (p-1). 183 * 184 * @return d mod (p-1). 185 */ 186 public BigInteger getPrimeExponentP() 187 { 188 return this.primeExponentP; 189 } 190 191 /** 192 * Returns d mod (q-1). 193 * 194 * @return d mod (q-1). 195 */ 196 public BigInteger getPrimeExponentQ() 197 { 198 return this.primeExponentQ; 199 } 200 201 /** 202 * Returns the CRT Coefficient q-1 mod p. 203 * 204 * @return the CRT Coefficient q-1 mod p. 205 */ 206 public BigInteger getCrtCoefficient() 207 { 208 return this.crtCoefficient; 209 } 210 211 /** 212 * Returns a clone of <code>otherPrimeInfo</code> or <code>null</code> if 213 * it was <code>null</code> at construction time. 214 * 215 * @return a cloned copy of <code>otherPrimeInfo</code>. 216 */ 217 public RSAOtherPrimeInfo[] getOtherPrimeInfo() 218 { 219 return this.otherPrimeInfo == null 220 ? null 221 : (RSAOtherPrimeInfo[]) this.otherPrimeInfo.clone(); 222 } 223}