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 represents 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.
  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:    * Constructs a new instance of <code>RSAMultiPrimePrivateCrtKeySpec</code>
  74:    * given the various PKCS#1 v2.1 parameters.
  75:    *
  76:    * <p>Note that <code>otherPrimeInfo</code> is cloned when constructing this
  77:    * object.</p>
  78:    *
  79:    * @param modulus
  80:    *          the modulus n.
  81:    * @param publicExponent
  82:    *          the public exponent e.
  83:    * @param privateExponent
  84:    *          the private exponent d.
  85:    * @param primeP
  86:    *          the prime factor p of n.
  87:    * @param primeQ
  88:    *          the prime factor q of n.
  89:    * @param primeExponentP
  90:    *          this is d mod (p-1).
  91:    * @param primeExponentQ
  92:    *          this is d mod (q-1).
  93:    * @param crtCoefficient
  94:    *          the Chinese Remainder Theorem coefficient q-1 mod p.
  95:    * @param otherPrimeInfo
  96:    *          triplets of the rest of primes, <code>null</code> can be
  97:    *          specified if there are only two prime factors (p and q).
  98:    * @throws NullPointerException
  99:    *           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: }