Source for java.security.spec.RSAMultiPrimePrivateCrtKeySpec

   1: /* PSSParameterSpec.java --
   2:    Copyright (C) 2003, Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   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.
  10: 
  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.
  15: 
  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.
  20: 
  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.
  25: 
  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. */
  37: 
  38: package java.security.spec;
  39: 
  40: import java.math.BigInteger;
  41: 
  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.
  46:  *
  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
  55:  */
  56: public class RSAMultiPrimePrivateCrtKeySpec extends RSAPrivateKeySpec
  57: {
  58:   // Constants and fields
  59:   // --------------------------------------------------------------------------
  60: 
  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;
  68: 
  69:   // Constructor(s)
  70:   // --------------------------------------------------------------------------
  71: 
  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>
  77:    *
  78:    * <p>Note that <code>otherPrimeInfo</code> is cloned when constructing this
  79:    * object.</p>
  80:    *
  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.
  96:    */
  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)
 106:   {
 107:     super(modulus, privateExponent);
 108: 
 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();
 130: 
 131:     this.publicExponent = publicExponent;
 132:     this.primeP = primeP;
 133:     this.primeQ = primeQ;
 134:     this.primeExponentP = primeExponentP;
 135:     this.primeExponentQ = primeExponentQ;
 136:     this.crtCoefficient = crtCoefficient;
 137:   }
 138: 
 139:   // Class methods
 140:   // --------------------------------------------------------------------------
 141: 
 142:   // Instance methods
 143:   // --------------------------------------------------------------------------
 144: 
 145:   /**
 146:    * Returns the public exponent.
 147:    *
 148:    * @return the public exponent.
 149:    */
 150:   public BigInteger getPublicExponent()
 151:   {
 152:     return this.publicExponent;
 153:   }
 154: 
 155:   /**
 156:    * Returns the primeP.
 157:    *
 158:    * @return the primeP.
 159:    */
 160:   public BigInteger getPrimeP()
 161:   {
 162:     return this.primeP;
 163:   }
 164: 
 165:   /**
 166:    * Returns the primeQ.
 167:    *
 168:    * @return the primeQ.
 169:    */
 170:   public BigInteger getPrimeQ()
 171:   {
 172:     return this.primeQ;
 173:   }
 174: 
 175:   /**
 176:    * Returns the primeExponentP.
 177:    *
 178:    * @return the primeExponentP.
 179:    */
 180:   public BigInteger getPrimeExponentP()
 181:   {
 182:     return this.primeExponentP;
 183:   }
 184: 
 185:   /**
 186:    * Returns the primeExponentQ.
 187:    *
 188:    * @return the primeExponentQ.
 189:    */
 190:   public BigInteger getPrimeExponentQ()
 191:   {
 192:     return this.primeExponentQ;
 193:   }
 194: 
 195:   /**
 196:    * Returns the crtCoefficient.
 197:    *
 198:    * @return the crtCoefficient.
 199:    */
 200:   public BigInteger getCrtCoefficient()
 201:   {
 202:     return this.crtCoefficient;
 203:   }
 204: 
 205:   /**
 206:    * Returns a copy of the otherPrimeInfo or <code>null</code> if there are
 207:    * only two prime factors (p and q).
 208:    *
 209:    * @return the otherPrimeInfo.
 210:    */
 211:   public RSAOtherPrimeInfo[] getOtherPrimeInfo()
 212:   {
 213:     return this.otherPrimeInfo == null
 214:         ? null
 215:         : (RSAOtherPrimeInfo[]) this.otherPrimeInfo.clone();
 216:   }
 217: }