8187443: Forest Consolidation: Move files to unified layout

Reviewed-by: darcy, ihse
This commit is contained in:
Erik Joelsson 2017-09-12 19:03:39 +02:00
parent 270fe13182
commit 3789983e89
56923 changed files with 3 additions and 15727 deletions

View file

@ -0,0 +1,44 @@
/*
* Copyright (c) 1997, 1999, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
/**
* A (transparent) specification of cryptographic parameters.
*
* <P> This interface contains no methods or constants. Its only purpose
* is to group (and provide type safety for) all parameter specifications.
* All parameter specifications must implement this interface.
*
* @author Jan Luehe
*
*
* @see java.security.AlgorithmParameters
* @see DSAParameterSpec
*
* @since 1.2
*/
public interface AlgorithmParameterSpec { }

View file

@ -0,0 +1,127 @@
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
/**
* This immutable class specifies the set of parameters used for
* generating DSA parameters as specified in
* <a href="http://csrc.nist.gov/publications/fips/fips186-3/fips_186-3.pdf">FIPS 186-3 Digital Signature Standard (DSS)</a>.
*
* @see AlgorithmParameterSpec
*
* @since 1.8
*/
public final class DSAGenParameterSpec implements AlgorithmParameterSpec {
private final int pLen;
private final int qLen;
private final int seedLen;
/**
* Creates a domain parameter specification for DSA parameter
* generation using {@code primePLen} and {@code subprimeQLen}.
* The value of {@code subprimeQLen} is also used as the default
* length of the domain parameter seed in bits.
* @param primePLen the desired length of the prime P in bits.
* @param subprimeQLen the desired length of the sub-prime Q in bits.
* @exception IllegalArgumentException if {@code primePLen}
* or {@code subprimeQLen} is illegal per the specification of
* FIPS 186-3.
*/
public DSAGenParameterSpec(int primePLen, int subprimeQLen) {
this(primePLen, subprimeQLen, subprimeQLen);
}
/**
* Creates a domain parameter specification for DSA parameter
* generation using {@code primePLen}, {@code subprimeQLen},
* and {@code seedLen}.
* @param primePLen the desired length of the prime P in bits.
* @param subprimeQLen the desired length of the sub-prime Q in bits.
* @param seedLen the desired length of the domain parameter seed in bits,
* shall be equal to or greater than {@code subprimeQLen}.
* @exception IllegalArgumentException if {@code primePLenLen},
* {@code subprimeQLen}, or {@code seedLen} is illegal per the
* specification of FIPS 186-3.
*/
public DSAGenParameterSpec(int primePLen, int subprimeQLen, int seedLen) {
switch (primePLen) {
case 1024:
if (subprimeQLen != 160) {
throw new IllegalArgumentException
("subprimeQLen must be 160 when primePLen=1024");
}
break;
case 2048:
if (subprimeQLen != 224 && subprimeQLen != 256) {
throw new IllegalArgumentException
("subprimeQLen must be 224 or 256 when primePLen=2048");
}
break;
case 3072:
if (subprimeQLen != 256) {
throw new IllegalArgumentException
("subprimeQLen must be 256 when primePLen=3072");
}
break;
default:
throw new IllegalArgumentException
("primePLen must be 1024, 2048, or 3072");
}
if (seedLen < subprimeQLen) {
throw new IllegalArgumentException
("seedLen must be equal to or greater than subprimeQLen");
}
this.pLen = primePLen;
this.qLen = subprimeQLen;
this.seedLen = seedLen;
}
/**
* Returns the desired length of the prime P of the
* to-be-generated DSA domain parameters in bits.
* @return the length of the prime P.
*/
public int getPrimePLength() {
return pLen;
}
/**
* Returns the desired length of the sub-prime Q of the
* to-be-generated DSA domain parameters in bits.
* @return the length of the sub-prime Q.
*/
public int getSubprimeQLength() {
return qLen;
}
/**
* Returns the desired length of the domain parameter seed in bits.
* @return the length of the domain parameter seed.
*/
public int getSeedLength() {
return seedLen;
}
}

View file

@ -0,0 +1,89 @@
/*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
import java.math.BigInteger;
/**
* This class specifies the set of parameters used with the DSA algorithm.
*
* @author Jan Luehe
*
*
* @see AlgorithmParameterSpec
*
* @since 1.2
*/
public class DSAParameterSpec implements AlgorithmParameterSpec,
java.security.interfaces.DSAParams {
BigInteger p;
BigInteger q;
BigInteger g;
/**
* Creates a new DSAParameterSpec with the specified parameter values.
*
* @param p the prime.
*
* @param q the sub-prime.
*
* @param g the base.
*/
public DSAParameterSpec(BigInteger p, BigInteger q, BigInteger g) {
this.p = p;
this.q = q;
this.g = g;
}
/**
* Returns the prime {@code p}.
*
* @return the prime {@code p}.
*/
public BigInteger getP() {
return this.p;
}
/**
* Returns the sub-prime {@code q}.
*
* @return the sub-prime {@code q}.
*/
public BigInteger getQ() {
return this.q;
}
/**
* Returns the base {@code g}.
*
* @return the base {@code g}.
*/
public BigInteger getG() {
return this.g;
}
}

View file

@ -0,0 +1,106 @@
/*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
import java.math.BigInteger;
/**
* This class specifies a DSA private key with its associated parameters.
*
* @author Jan Luehe
*
*
* @see java.security.Key
* @see java.security.KeyFactory
* @see KeySpec
* @see DSAPublicKeySpec
* @see PKCS8EncodedKeySpec
*
* @since 1.2
*/
public class DSAPrivateKeySpec implements KeySpec {
private BigInteger x;
private BigInteger p;
private BigInteger q;
private BigInteger g;
/**
* Creates a new DSAPrivateKeySpec with the specified parameter values.
*
* @param x the private key.
*
* @param p the prime.
*
* @param q the sub-prime.
*
* @param g the base.
*/
public DSAPrivateKeySpec(BigInteger x, BigInteger p, BigInteger q,
BigInteger g) {
this.x = x;
this.p = p;
this.q = q;
this.g = g;
}
/**
* Returns the private key {@code x}.
*
* @return the private key {@code x}.
*/
public BigInteger getX() {
return this.x;
}
/**
* Returns the prime {@code p}.
*
* @return the prime {@code p}.
*/
public BigInteger getP() {
return this.p;
}
/**
* Returns the sub-prime {@code q}.
*
* @return the sub-prime {@code q}.
*/
public BigInteger getQ() {
return this.q;
}
/**
* Returns the base {@code g}.
*
* @return the base {@code g}.
*/
public BigInteger getG() {
return this.g;
}
}

View file

@ -0,0 +1,106 @@
/*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
import java.math.BigInteger;
/**
* This class specifies a DSA public key with its associated parameters.
*
* @author Jan Luehe
*
*
* @see java.security.Key
* @see java.security.KeyFactory
* @see KeySpec
* @see DSAPrivateKeySpec
* @see X509EncodedKeySpec
*
* @since 1.2
*/
public class DSAPublicKeySpec implements KeySpec {
private BigInteger y;
private BigInteger p;
private BigInteger q;
private BigInteger g;
/**
* Creates a new DSAPublicKeySpec with the specified parameter values.
*
* @param y the public key.
*
* @param p the prime.
*
* @param q the sub-prime.
*
* @param g the base.
*/
public DSAPublicKeySpec(BigInteger y, BigInteger p, BigInteger q,
BigInteger g) {
this.y = y;
this.p = p;
this.q = q;
this.g = g;
}
/**
* Returns the public key {@code y}.
*
* @return the public key {@code y}.
*/
public BigInteger getY() {
return this.y;
}
/**
* Returns the prime {@code p}.
*
* @return the prime {@code p}.
*/
public BigInteger getP() {
return this.p;
}
/**
* Returns the sub-prime {@code q}.
*
* @return the sub-prime {@code q}.
*/
public BigInteger getQ() {
return this.q;
}
/**
* Returns the base {@code g}.
*
* @return the base {@code g}.
*/
public BigInteger getG() {
return this.g;
}
}

View file

@ -0,0 +1,49 @@
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
import java.math.BigInteger;
import java.util.Arrays;
/**
* This interface represents an elliptic curve (EC) finite field.
* All specialized EC fields must implements this interface.
*
* @see ECFieldFp
* @see ECFieldF2m
*
* @author Valerie Peng
*
* @since 1.5
*/
public interface ECField {
/**
* Returns the field size in bits. Note: For prime finite
* field ECFieldFp, size of prime p in bits is returned.
* For characteristic 2 finite field ECFieldF2m, m is returned.
* @return the field size in bits.
*/
int getFieldSize();
}

View file

@ -0,0 +1,241 @@
/*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
import java.math.BigInteger;
import java.util.Arrays;
/**
* This immutable class defines an elliptic curve (EC)
* characteristic 2 finite field.
*
* @see ECField
*
* @author Valerie Peng
*
* @since 1.5
*/
public class ECFieldF2m implements ECField {
private int m;
private int[] ks;
private BigInteger rp;
/**
* Creates an elliptic curve characteristic 2 finite
* field which has 2^{@code m} elements with normal basis.
* @param m with 2^{@code m} being the number of elements.
* @exception IllegalArgumentException if {@code m}
* is not positive.
*/
public ECFieldF2m(int m) {
if (m <= 0) {
throw new IllegalArgumentException("m is not positive");
}
this.m = m;
this.ks = null;
this.rp = null;
}
/**
* Creates an elliptic curve characteristic 2 finite
* field which has 2^{@code m} elements with
* polynomial basis.
* The reduction polynomial for this field is based
* on {@code rp} whose i-th bit corresponds to
* the i-th coefficient of the reduction polynomial.<p>
* Note: A valid reduction polynomial is either a
* trinomial (X^{@code m} + X^{@code k} + 1
* with {@code m} &gt; {@code k} &gt;= 1) or a
* pentanomial (X^{@code m} + X^{@code k3}
* + X^{@code k2} + X^{@code k1} + 1 with
* {@code m} &gt; {@code k3} &gt; {@code k2}
* &gt; {@code k1} &gt;= 1).
* @param m with 2^{@code m} being the number of elements.
* @param rp the BigInteger whose i-th bit corresponds to
* the i-th coefficient of the reduction polynomial.
* @exception NullPointerException if {@code rp} is null.
* @exception IllegalArgumentException if {@code m}
* is not positive, or {@code rp} does not represent
* a valid reduction polynomial.
*/
public ECFieldF2m(int m, BigInteger rp) {
// check m and rp
this.m = m;
this.rp = rp;
if (m <= 0) {
throw new IllegalArgumentException("m is not positive");
}
int bitCount = this.rp.bitCount();
if (!this.rp.testBit(0) || !this.rp.testBit(m) ||
((bitCount != 3) && (bitCount != 5))) {
throw new IllegalArgumentException
("rp does not represent a valid reduction polynomial");
}
// convert rp into ks
BigInteger temp = this.rp.clearBit(0).clearBit(m);
this.ks = new int[bitCount-2];
for (int i = this.ks.length-1; i >= 0; i--) {
int index = temp.getLowestSetBit();
this.ks[i] = index;
temp = temp.clearBit(index);
}
}
/**
* Creates an elliptic curve characteristic 2 finite
* field which has 2^{@code m} elements with
* polynomial basis. The reduction polynomial for this
* field is based on {@code ks} whose content
* contains the order of the middle term(s) of the
* reduction polynomial.
* Note: A valid reduction polynomial is either a
* trinomial (X^{@code m} + X^{@code k} + 1
* with {@code m} &gt; {@code k} &gt;= 1) or a
* pentanomial (X^{@code m} + X^{@code k3}
* + X^{@code k2} + X^{@code k1} + 1 with
* {@code m} &gt; {@code k3} &gt; {@code k2}
* &gt; {@code k1} &gt;= 1), so {@code ks} should
* have length 1 or 3.
* @param m with 2^{@code m} being the number of elements.
* @param ks the order of the middle term(s) of the
* reduction polynomial. Contents of this array are copied
* to protect against subsequent modification.
* @exception NullPointerException if {@code ks} is null.
* @exception IllegalArgumentException if{@code m}
* is not positive, or the length of {@code ks}
* is neither 1 nor 3, or values in {@code ks}
* are not between {@code m}-1 and 1 (inclusive)
* and in descending order.
*/
public ECFieldF2m(int m, int[] ks) {
// check m and ks
this.m = m;
this.ks = ks.clone();
if (m <= 0) {
throw new IllegalArgumentException("m is not positive");
}
if ((this.ks.length != 1) && (this.ks.length != 3)) {
throw new IllegalArgumentException
("length of ks is neither 1 nor 3");
}
for (int i = 0; i < this.ks.length; i++) {
if ((this.ks[i] < 1) || (this.ks[i] > m-1)) {
throw new IllegalArgumentException
("ks["+ i + "] is out of range");
}
if ((i != 0) && (this.ks[i] >= this.ks[i-1])) {
throw new IllegalArgumentException
("values in ks are not in descending order");
}
}
// convert ks into rp
this.rp = BigInteger.ONE;
this.rp = rp.setBit(m);
for (int j = 0; j < this.ks.length; j++) {
rp = rp.setBit(this.ks[j]);
}
}
/**
* Returns the field size in bits which is {@code m}
* for this characteristic 2 finite field.
* @return the field size in bits.
*/
public int getFieldSize() {
return m;
}
/**
* Returns the value {@code m} of this characteristic
* 2 finite field.
* @return {@code m} with 2^{@code m} being the
* number of elements.
*/
public int getM() {
return m;
}
/**
* Returns a BigInteger whose i-th bit corresponds to the
* i-th coefficient of the reduction polynomial for polynomial
* basis or null for normal basis.
* @return a BigInteger whose i-th bit corresponds to the
* i-th coefficient of the reduction polynomial for polynomial
* basis or null for normal basis.
*/
public BigInteger getReductionPolynomial() {
return rp;
}
/**
* Returns an integer array which contains the order of the
* middle term(s) of the reduction polynomial for polynomial
* basis or null for normal basis.
* @return an integer array which contains the order of the
* middle term(s) of the reduction polynomial for polynomial
* basis or null for normal basis. A new array is returned
* each time this method is called.
*/
public int[] getMidTermsOfReductionPolynomial() {
if (ks == null) {
return null;
} else {
return ks.clone();
}
}
/**
* Compares this finite field for equality with the
* specified object.
* @param obj the object to be compared.
* @return true if {@code obj} is an instance
* of ECFieldF2m and both {@code m} and the reduction
* polynomial match, false otherwise.
*/
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj instanceof ECFieldF2m) {
// no need to compare rp here since ks and rp
// should be equivalent
return ((m == ((ECFieldF2m)obj).m) &&
(Arrays.equals(ks, ((ECFieldF2m) obj).ks)));
}
return false;
}
/**
* Returns a hash code value for this characteristic 2
* finite field.
* @return a hash code value.
*/
public int hashCode() {
int value = m << 5;
value += (rp==null? 0:rp.hashCode());
// no need to involve ks here since ks and rp
// should be equivalent.
return value;
}
}

View file

@ -0,0 +1,98 @@
/*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
import java.math.BigInteger;
import java.util.Arrays;
/**
* This immutable class defines an elliptic curve (EC) prime
* finite field.
*
* @see ECField
*
* @author Valerie Peng
*
* @since 1.5
*/
public class ECFieldFp implements ECField {
private BigInteger p;
/**
* Creates an elliptic curve prime finite field
* with the specified prime {@code p}.
* @param p the prime.
* @exception NullPointerException if {@code p} is null.
* @exception IllegalArgumentException if {@code p}
* is not positive.
*/
public ECFieldFp(BigInteger p) {
if (p.signum() != 1) {
throw new IllegalArgumentException("p is not positive");
}
this.p = p;
}
/**
* Returns the field size in bits which is size of prime p
* for this prime finite field.
* @return the field size in bits.
*/
public int getFieldSize() {
return p.bitLength();
};
/**
* Returns the prime {@code p} of this prime finite field.
* @return the prime.
*/
public BigInteger getP() {
return p;
}
/**
* Compares this prime finite field for equality with the
* specified object.
* @param obj the object to be compared.
* @return true if {@code obj} is an instance
* of ECFieldFp and the prime value match, false otherwise.
*/
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj instanceof ECFieldFp) {
return (p.equals(((ECFieldFp)obj).p));
}
return false;
}
/**
* Returns a hash code value for this prime finite field.
* @return a hash code value.
*/
public int hashCode() {
return p.hashCode();
}
}

View file

@ -0,0 +1,68 @@
/*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
/**
* This immutable class specifies the set of parameters used for
* generating elliptic curve (EC) domain parameters.
*
* @see AlgorithmParameterSpec
*
* @author Valerie Peng
*
* @since 1.5
*/
public class ECGenParameterSpec implements AlgorithmParameterSpec {
private String name;
/**
* Creates a parameter specification for EC parameter
* generation using a standard (or predefined) name
* {@code stdName} in order to generate the corresponding
* (precomputed) elliptic curve domain parameters. For the
* list of supported names, please consult the documentation
* of provider whose implementation will be used.
* @param stdName the standard name of the to-be-generated EC
* domain parameters.
* @exception NullPointerException if {@code stdName}
* is null.
*/
public ECGenParameterSpec(String stdName) {
if (stdName == null) {
throw new NullPointerException("stdName is null");
}
this.name = stdName;
}
/**
* Returns the standard or predefined name of the
* to-be-generated EC domain parameters.
* @return the standard or predefined name.
*/
public String getName() {
return name;
}
}

View file

@ -0,0 +1,113 @@
/*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
import java.math.BigInteger;
/**
* This immutable class specifies the set of domain parameters
* used with elliptic curve cryptography (ECC).
*
* @see AlgorithmParameterSpec
*
* @author Valerie Peng
*
* @since 1.5
*/
public class ECParameterSpec implements AlgorithmParameterSpec {
private final EllipticCurve curve;
private final ECPoint g;
private final BigInteger n;
private final int h;
/**
* Creates elliptic curve domain parameters based on the
* specified values.
* @param curve the elliptic curve which this parameter
* defines.
* @param g the generator which is also known as the base point.
* @param n the order of the generator {@code g}.
* @param h the cofactor.
* @exception NullPointerException if {@code curve},
* {@code g}, or {@code n} is null.
* @exception IllegalArgumentException if {@code n}
* or {@code h} is not positive.
*/
public ECParameterSpec(EllipticCurve curve, ECPoint g,
BigInteger n, int h) {
if (curve == null) {
throw new NullPointerException("curve is null");
}
if (g == null) {
throw new NullPointerException("g is null");
}
if (n == null) {
throw new NullPointerException("n is null");
}
if (n.signum() != 1) {
throw new IllegalArgumentException("n is not positive");
}
if (h <= 0) {
throw new IllegalArgumentException("h is not positive");
}
this.curve = curve;
this.g = g;
this.n = n;
this.h = h;
}
/**
* Returns the elliptic curve that this parameter defines.
* @return the elliptic curve that this parameter defines.
*/
public EllipticCurve getCurve() {
return curve;
}
/**
* Returns the generator which is also known as the base point.
* @return the generator which is also known as the base point.
*/
public ECPoint getGenerator() {
return g;
}
/**
* Returns the order of the generator.
* @return the order of the generator.
*/
public BigInteger getOrder() {
return n;
}
/**
* Returns the cofactor.
* @return the cofactor.
*/
public int getCofactor() {
return h;
}
}

View file

@ -0,0 +1,114 @@
/*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
import java.math.BigInteger;
/**
* This immutable class represents a point on an elliptic curve (EC)
* in affine coordinates. Other coordinate systems can
* extend this class to represent this point in other
* coordinates.
*
* @author Valerie Peng
*
* @since 1.5
*/
public class ECPoint {
private final BigInteger x;
private final BigInteger y;
/**
* This defines the point at infinity.
*/
public static final ECPoint POINT_INFINITY = new ECPoint();
// private constructor for constructing point at infinity
private ECPoint() {
this.x = null;
this.y = null;
}
/**
* Creates an ECPoint from the specified affine x-coordinate
* {@code x} and affine y-coordinate {@code y}.
* @param x the affine x-coordinate.
* @param y the affine y-coordinate.
* @exception NullPointerException if {@code x} or
* {@code y} is null.
*/
public ECPoint(BigInteger x, BigInteger y) {
if ((x==null) || (y==null)) {
throw new NullPointerException("affine coordinate x or y is null");
}
this.x = x;
this.y = y;
}
/**
* Returns the affine x-coordinate {@code x}.
* Note: POINT_INFINITY has a null affine x-coordinate.
* @return the affine x-coordinate.
*/
public BigInteger getAffineX() {
return x;
}
/**
* Returns the affine y-coordinate {@code y}.
* Note: POINT_INFINITY has a null affine y-coordinate.
* @return the affine y-coordinate.
*/
public BigInteger getAffineY() {
return y;
}
/**
* Compares this elliptic curve point for equality with
* the specified object.
* @param obj the object to be compared.
* @return true if {@code obj} is an instance of
* ECPoint and the affine coordinates match, false otherwise.
*/
public boolean equals(Object obj) {
if (this == obj) return true;
if (this == POINT_INFINITY) return false;
if (obj instanceof ECPoint) {
return ((x.equals(((ECPoint)obj).x)) &&
(y.equals(((ECPoint)obj).y)));
}
return false;
}
/**
* Returns a hash code value for this elliptic curve point.
* @return a hash code value.
*/
public int hashCode() {
if (this == POINT_INFINITY) return 0;
return x.hashCode() << 5 + y.hashCode();
}
}

View file

@ -0,0 +1,81 @@
/*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
import java.math.BigInteger;
/**
* This immutable class specifies an elliptic curve private key with
* its associated parameters.
*
* @see KeySpec
* @see ECParameterSpec
*
* @author Valerie Peng
*
* @since 1.5
*/
public class ECPrivateKeySpec implements KeySpec {
private BigInteger s;
private ECParameterSpec params;
/**
* Creates a new ECPrivateKeySpec with the specified
* parameter values.
* @param s the private value.
* @param params the associated elliptic curve domain
* parameters.
* @exception NullPointerException if {@code s}
* or {@code params} is null.
*/
public ECPrivateKeySpec(BigInteger s, ECParameterSpec params) {
if (s == null) {
throw new NullPointerException("s is null");
}
if (params == null) {
throw new NullPointerException("params is null");
}
this.s = s;
this.params = params;
}
/**
* Returns the private value S.
* @return the private value S.
*/
public BigInteger getS() {
return s;
}
/**
* Returns the associated elliptic curve domain
* parameters.
* @return the EC domain parameters.
*/
public ECParameterSpec getParams() {
return params;
}
}

View file

@ -0,0 +1,85 @@
/*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
/**
* This immutable class specifies an elliptic curve public key with
* its associated parameters.
*
* @see KeySpec
* @see ECPoint
* @see ECParameterSpec
*
* @author Valerie Peng
*
* @since 1.5
*/
public class ECPublicKeySpec implements KeySpec {
private ECPoint w;
private ECParameterSpec params;
/**
* Creates a new ECPublicKeySpec with the specified
* parameter values.
* @param w the public point.
* @param params the associated elliptic curve domain
* parameters.
* @exception NullPointerException if {@code w}
* or {@code params} is null.
* @exception IllegalArgumentException if {@code w}
* is point at infinity, i.e. ECPoint.POINT_INFINITY
*/
public ECPublicKeySpec(ECPoint w, ECParameterSpec params) {
if (w == null) {
throw new NullPointerException("w is null");
}
if (params == null) {
throw new NullPointerException("params is null");
}
if (w == ECPoint.POINT_INFINITY) {
throw new IllegalArgumentException("w is ECPoint.POINT_INFINITY");
}
this.w = w;
this.params = params;
}
/**
* Returns the public point W.
* @return the public point W.
*/
public ECPoint getW() {
return w;
}
/**
* Returns the associated elliptic curve domain
* parameters.
* @return the EC domain parameters.
*/
public ECParameterSpec getParams() {
return params;
}
}

View file

@ -0,0 +1,196 @@
/*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
import java.math.BigInteger;
import java.util.Arrays;
/**
* This immutable class holds the necessary values needed to represent
* an elliptic curve.
*
* @see ECField
* @see ECFieldFp
* @see ECFieldF2m
*
* @author Valerie Peng
*
* @since 1.5
*/
public class EllipticCurve {
private final ECField field;
private final BigInteger a;
private final BigInteger b;
private final byte[] seed;
// Check coefficient c is a valid element in ECField field.
private static void checkValidity(ECField field, BigInteger c,
String cName) {
// can only perform check if field is ECFieldFp or ECFieldF2m.
if (field instanceof ECFieldFp) {
BigInteger p = ((ECFieldFp)field).getP();
if (p.compareTo(c) != 1) {
throw new IllegalArgumentException(cName + " is too large");
} else if (c.signum() < 0) {
throw new IllegalArgumentException(cName + " is negative");
}
} else if (field instanceof ECFieldF2m) {
int m = ((ECFieldF2m)field).getM();
if (c.bitLength() > m) {
throw new IllegalArgumentException(cName + " is too large");
}
}
}
/**
* Creates an elliptic curve with the specified elliptic field
* {@code field} and the coefficients {@code a} and
* {@code b}.
* @param field the finite field that this elliptic curve is over.
* @param a the first coefficient of this elliptic curve.
* @param b the second coefficient of this elliptic curve.
* @exception NullPointerException if {@code field},
* {@code a}, or {@code b} is null.
* @exception IllegalArgumentException if {@code a}
* or {@code b} is not null and not in {@code field}.
*/
public EllipticCurve(ECField field, BigInteger a,
BigInteger b) {
this(field, a, b, null);
}
/**
* Creates an elliptic curve with the specified elliptic field
* {@code field}, the coefficients {@code a} and
* {@code b}, and the {@code seed} used for curve generation.
* @param field the finite field that this elliptic curve is over.
* @param a the first coefficient of this elliptic curve.
* @param b the second coefficient of this elliptic curve.
* @param seed the bytes used during curve generation for later
* validation. Contents of this array are copied to protect against
* subsequent modification.
* @exception NullPointerException if {@code field},
* {@code a}, or {@code b} is null.
* @exception IllegalArgumentException if {@code a}
* or {@code b} is not null and not in {@code field}.
*/
public EllipticCurve(ECField field, BigInteger a,
BigInteger b, byte[] seed) {
if (field == null) {
throw new NullPointerException("field is null");
}
if (a == null) {
throw new NullPointerException("first coefficient is null");
}
if (b == null) {
throw new NullPointerException("second coefficient is null");
}
checkValidity(field, a, "first coefficient");
checkValidity(field, b, "second coefficient");
this.field = field;
this.a = a;
this.b = b;
if (seed != null) {
this.seed = seed.clone();
} else {
this.seed = null;
}
}
/**
* Returns the finite field {@code field} that this
* elliptic curve is over.
* @return the field {@code field} that this curve
* is over.
*/
public ECField getField() {
return field;
}
/**
* Returns the first coefficient {@code a} of the
* elliptic curve.
* @return the first coefficient {@code a}.
*/
public BigInteger getA() {
return a;
}
/**
* Returns the second coefficient {@code b} of the
* elliptic curve.
* @return the second coefficient {@code b}.
*/
public BigInteger getB() {
return b;
}
/**
* Returns the seeding bytes {@code seed} used
* during curve generation. May be null if not specified.
* @return the seeding bytes {@code seed}. A new
* array is returned each time this method is called.
*/
public byte[] getSeed() {
if (seed == null) return null;
else return seed.clone();
}
/**
* Compares this elliptic curve for equality with the
* specified object.
* @param obj the object to be compared.
* @return true if {@code obj} is an instance of
* EllipticCurve and the field, A, and B match, false otherwise.
*/
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj instanceof EllipticCurve) {
EllipticCurve curve = (EllipticCurve) obj;
if ((field.equals(curve.field)) &&
(a.equals(curve.a)) &&
(b.equals(curve.b))) {
return true;
}
}
return false;
}
/**
* Returns a hash code value for this elliptic curve.
* @return a hash code value computed from the hash codes of the field, A,
* and B, as follows:
* <pre>{@code
* (field.hashCode() << 6) + (a.hashCode() << 4) + (b.hashCode() << 2)
* }</pre>
*/
public int hashCode() {
return (field.hashCode() << 6 +
(a.hashCode() << 4) +
(b.hashCode() << 2));
}
}

View file

@ -0,0 +1,128 @@
/*
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
/**
* This class represents a public or private key in encoded format.
*
* @author Jan Luehe
*
*
* @see java.security.Key
* @see java.security.KeyFactory
* @see KeySpec
* @see X509EncodedKeySpec
* @see PKCS8EncodedKeySpec
*
* @since 1.2
*/
public abstract class EncodedKeySpec implements KeySpec {
private byte[] encodedKey;
private String algorithmName;
/**
* Creates a new {@code EncodedKeySpec} with the given encoded key.
*
* @param encodedKey the encoded key. The contents of the
* array are copied to protect against subsequent modification.
* @throws NullPointerException if {@code encodedKey}
* is null.
*/
public EncodedKeySpec(byte[] encodedKey) {
this.encodedKey = encodedKey.clone();
}
/**
* Creates a new {@code EncodedKeySpec} with the given encoded key.
* This constructor is useful when subsequent callers of the
* {@code EncodedKeySpec} object might not know the algorithm
* of the key.
*
* @param encodedKey the encoded key. The contents of the
* array are copied to protect against subsequent modification.
* @param algorithm the algorithm name of the encoded key
* See the KeyFactory section in the <a href=
* "{@docRoot}/../specs/security/standard-names.html#keyfactory-algorithms">
* Java Security Standard Algorithm Names Specification</a>
* for information about standard algorithm names.
* @throws NullPointerException if {@code encodedKey}
* or {@code algorithm} is null.
* @throws IllegalArgumentException if {@code algorithm} is
* the empty string {@code ""}
* @since 9
*/
protected EncodedKeySpec(byte[] encodedKey, String algorithm) {
if (algorithm == null) {
throw new NullPointerException("algorithm name may not be null");
}
if (algorithm.isEmpty()) {
throw new IllegalArgumentException("algorithm name "
+ "may not be empty");
}
this.encodedKey = encodedKey.clone();
this.algorithmName = algorithm;
}
/**
* Returns the name of the algorithm of the encoded key.
*
* @return the name of the algorithm, or null if not specified
* @since 9
*/
public String getAlgorithm() {
return algorithmName;
}
/**
* Returns the encoded key.
*
* @return the encoded key. Returns a new array each time
* this method is called.
*/
public byte[] getEncoded() {
return this.encodedKey.clone();
}
/**
* Returns the name of the encoding format associated with this
* key specification.
*
* <p>If the opaque representation of a key
* (see {@link java.security.Key Key}) can be transformed
* (see {@link java.security.KeyFactory KeyFactory})
* into this key specification (or a subclass of it),
* {@code getFormat} called
* on the opaque key returns the same value as the
* {@code getFormat} method
* of this key specification.
*
* @return a string representation of the encoding format.
*/
public abstract String getFormat();
}

View file

@ -0,0 +1,94 @@
/*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
import java.security.GeneralSecurityException;
/**
* This is the exception for invalid key specifications.
*
* @author Jan Luehe
*
*
* @see KeySpec
*
* @since 1.2
*/
public class InvalidKeySpecException extends GeneralSecurityException {
private static final long serialVersionUID = 3546139293998810778L;
/**
* Constructs an InvalidKeySpecException with no detail message. A
* detail message is a String that describes this particular
* exception.
*/
public InvalidKeySpecException() {
super();
}
/**
* Constructs an InvalidKeySpecException with the specified detail
* message. A detail message is a String that describes this
* particular exception.
*
* @param msg the detail message.
*/
public InvalidKeySpecException(String msg) {
super(msg);
}
/**
* Creates an {@code InvalidKeySpecException} with the specified
* detail message and cause.
*
* @param message the detail message (which is saved for later retrieval
* by the {@link #getMessage()} method).
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A {@code null} value is permitted,
* and indicates that the cause is nonexistent or unknown.)
* @since 1.5
*/
public InvalidKeySpecException(String message, Throwable cause) {
super(message, cause);
}
/**
* Creates an {@code InvalidKeySpecException} with the specified cause
* and a detail message of {@code (cause==null ? null : cause.toString())}
* (which typically contains the class and detail message of
* {@code cause}).
*
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A {@code null} value is permitted,
* and indicates that the cause is nonexistent or unknown.)
* @since 1.5
*/
public InvalidKeySpecException(Throwable cause) {
super(cause);
}
}

View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
import java.security.GeneralSecurityException;
/**
* This is the exception for invalid parameter specifications.
*
* @author Jan Luehe
*
*
* @see java.security.AlgorithmParameters
* @see AlgorithmParameterSpec
* @see DSAParameterSpec
*
* @since 1.2
*/
public class InvalidParameterSpecException extends GeneralSecurityException {
private static final long serialVersionUID = -970468769593399342L;
/**
* Constructs an InvalidParameterSpecException with no detail message. A
* detail message is a String that describes this particular
* exception.
*/
public InvalidParameterSpecException() {
super();
}
/**
* Constructs an InvalidParameterSpecException with the specified detail
* message. A detail message is a String that describes this
* particular exception.
*
* @param msg the detail message.
*/
public InvalidParameterSpecException(String msg) {
super(msg);
}
}

View file

@ -0,0 +1,62 @@
/*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
/**
* A (transparent) specification of the key material
* that constitutes a cryptographic key.
*
* <p>If the key is stored on a hardware device, its
* specification may contain information that helps identify the key on the
* device.
*
* <P> A key may be specified in an algorithm-specific way, or in an
* algorithm-independent encoding format (such as ASN.1).
* For example, a DSA private key may be specified by its components
* {@code x}, {@code p}, {@code q}, and {@code g}
* (see {@link DSAPrivateKeySpec}), or it may be
* specified using its DER encoding
* (see {@link PKCS8EncodedKeySpec}).
*
* <P> This interface contains no methods or constants. Its only purpose
* is to group (and provide type safety for) all key specifications.
* All key specifications must implement this interface.
*
* @author Jan Luehe
*
*
* @see java.security.Key
* @see java.security.KeyFactory
* @see EncodedKeySpec
* @see X509EncodedKeySpec
* @see PKCS8EncodedKeySpec
* @see DSAPrivateKeySpec
* @see DSAPublicKeySpec
*
* @since 1.2
*/
public interface KeySpec { }

View file

@ -0,0 +1,113 @@
/*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
import java.security.spec.AlgorithmParameterSpec;
/**
* This class specifies the set of parameters used with mask generation
* function MGF1 in OAEP Padding and RSA-PSS signature scheme, as
* defined in the
* <a href="http://www.ietf.org/rfc/rfc3447.txt">PKCS #1 v2.1</a>
* standard.
*
* <p>Its ASN.1 definition in PKCS#1 standard is described below:
* <pre>
* MGF1Parameters ::= OAEP-PSSDigestAlgorthms
* </pre>
* where
* <pre>
* OAEP-PSSDigestAlgorithms ALGORITHM-IDENTIFIER ::= {
* { OID id-sha1 PARAMETERS NULL }|
* { OID id-sha224 PARAMETERS NULL }|
* { OID id-sha256 PARAMETERS NULL }|
* { OID id-sha384 PARAMETERS NULL }|
* { OID id-sha512 PARAMETERS NULL },
* ... -- Allows for future expansion --
* }
* </pre>
* @see PSSParameterSpec
* @see javax.crypto.spec.OAEPParameterSpec
*
* @author Valerie Peng
*
* @since 1.5
*/
public class MGF1ParameterSpec implements AlgorithmParameterSpec {
/**
* The MGF1ParameterSpec which uses "SHA-1" message digest.
*/
public static final MGF1ParameterSpec SHA1 =
new MGF1ParameterSpec("SHA-1");
/**
* The MGF1ParameterSpec which uses "SHA-224" message digest.
*/
public static final MGF1ParameterSpec SHA224 =
new MGF1ParameterSpec("SHA-224");
/**
* The MGF1ParameterSpec which uses "SHA-256" message digest.
*/
public static final MGF1ParameterSpec SHA256 =
new MGF1ParameterSpec("SHA-256");
/**
* The MGF1ParameterSpec which uses "SHA-384" message digest.
*/
public static final MGF1ParameterSpec SHA384 =
new MGF1ParameterSpec("SHA-384");
/**
* The MGF1ParameterSpec which uses SHA-512 message digest.
*/
public static final MGF1ParameterSpec SHA512 =
new MGF1ParameterSpec("SHA-512");
private String mdName;
/**
* Constructs a parameter set for mask generation function MGF1
* as defined in the PKCS #1 standard.
*
* @param mdName the algorithm name for the message digest
* used in this mask generation function MGF1.
* @exception NullPointerException if {@code mdName} is null.
*/
public MGF1ParameterSpec(String mdName) {
if (mdName == null) {
throw new NullPointerException("digest algorithm is null");
}
this.mdName = mdName;
}
/**
* Returns the algorithm name of the message digest used by the mask
* generation function.
*
* @return the algorithm name of the message digest.
*/
public String getDigestAlgorithm() {
return mdName;
}
}

View file

@ -0,0 +1,120 @@
/*
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
/**
* This class represents the ASN.1 encoding of a private key,
* encoded according to the ASN.1 type {@code PrivateKeyInfo}.
* The {@code PrivateKeyInfo} syntax is defined in the PKCS#8 standard
* as follows:
*
* <pre>
* PrivateKeyInfo ::= SEQUENCE {
* version Version,
* privateKeyAlgorithm PrivateKeyAlgorithmIdentifier,
* privateKey PrivateKey,
* attributes [0] IMPLICIT Attributes OPTIONAL }
*
* Version ::= INTEGER
*
* PrivateKeyAlgorithmIdentifier ::= AlgorithmIdentifier
*
* PrivateKey ::= OCTET STRING
*
* Attributes ::= SET OF Attribute
* </pre>
*
* @author Jan Luehe
*
*
* @see java.security.Key
* @see java.security.KeyFactory
* @see KeySpec
* @see EncodedKeySpec
* @see X509EncodedKeySpec
*
* @since 1.2
*/
public class PKCS8EncodedKeySpec extends EncodedKeySpec {
/**
* Creates a new {@code PKCS8EncodedKeySpec} with the given encoded key.
*
* @param encodedKey the key, which is assumed to be
* encoded according to the PKCS #8 standard. The contents of
* the array are copied to protect against subsequent modification.
* @throws NullPointerException if {@code encodedKey}
* is null.
*/
public PKCS8EncodedKeySpec(byte[] encodedKey) {
super(encodedKey);
}
/**
* Creates a new {@code PKCS8EncodedKeySpec} with the given encoded key and
* algorithm. This constructor is useful when subsequent callers of
* the {@code PKCS8EncodedKeySpec} object might not know the
* algorithm of the private key.
*
* @param encodedKey the key, which is assumed to be
* encoded according to the PKCS #8 standard. The contents of
* the array are copied to protect against subsequent modification.
* @param algorithm the algorithm name of the encoded private key
* See the KeyFactory section in the <a href=
* "{@docRoot}/../specs/security/standard-names.html#keyfactory-algorithms">
* Java Security Standard Algorithm Names Specification</a>
* for information about standard algorithm names.
* @throws NullPointerException if {@code encodedKey}
* or {@code algorithm} is null.
* @throws IllegalArgumentException if {@code algorithm} is
* the empty string {@code ""}
* @since 9
*/
public PKCS8EncodedKeySpec(byte[] encodedKey, String algorithm) {
super(encodedKey, algorithm);
}
/**
* Returns the key bytes, encoded according to the PKCS #8 standard.
*
* @return the PKCS #8 encoding of the key. Returns a new array
* each time this method is called.
*/
public byte[] getEncoded() {
return super.getEncoded();
}
/**
* Returns the name of the encoding format associated with this
* key specification.
*
* @return the string {@code "PKCS#8"}.
*/
public final String getFormat() {
return "PKCS#8";
}
}

View file

@ -0,0 +1,212 @@
/*
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
import java.math.BigInteger;
import java.security.spec.MGF1ParameterSpec;
/**
* This class specifies a parameter spec for RSA-PSS signature scheme,
* as defined in the
* <a href="http://www.ietf.org/rfc/rfc3447.txt">PKCS#1 v2.1</a>
* standard.
*
* <p>Its ASN.1 definition in PKCS#1 standard is described below:
* <pre>
* RSASSA-PSS-params ::= SEQUENCE {
* hashAlgorithm [0] OAEP-PSSDigestAlgorithms DEFAULT sha1,
* maskGenAlgorithm [1] PKCS1MGFAlgorithms DEFAULT mgf1SHA1,
* saltLength [2] INTEGER DEFAULT 20,
* trailerField [3] INTEGER DEFAULT 1
* }
* </pre>
* where
* <pre>
* OAEP-PSSDigestAlgorithms ALGORITHM-IDENTIFIER ::= {
* { OID id-sha1 PARAMETERS NULL }|
* { OID id-sha224 PARAMETERS NULL }|
* { OID id-sha256 PARAMETERS NULL }|
* { OID id-sha384 PARAMETERS NULL }|
* { OID id-sha512 PARAMETERS NULL },
* ... -- Allows for future expansion --
* }
*
* PKCS1MGFAlgorithms ALGORITHM-IDENTIFIER ::= {
* { OID id-mgf1 PARAMETERS OAEP-PSSDigestAlgorithms },
* ... -- Allows for future expansion --
* }
* </pre>
* <p>Note: the PSSParameterSpec.DEFAULT uses the following:
* message digest -- "SHA-1"
* mask generation function (mgf) -- "MGF1"
* parameters for mgf -- MGF1ParameterSpec.SHA1
* SaltLength -- 20
* TrailerField -- 1
*
* @see MGF1ParameterSpec
* @see AlgorithmParameterSpec
* @see java.security.Signature
*
* @author Valerie Peng
*
*
* @since 1.4
*/
public class PSSParameterSpec implements AlgorithmParameterSpec {
private String mdName = "SHA-1";
private String mgfName = "MGF1";
private AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1;
private int saltLen = 20;
private int trailerField = 1;
/**
* The PSS parameter set with all default values.
* @since 1.5
*/
public static final PSSParameterSpec DEFAULT = new PSSParameterSpec();
/**
* Constructs a new {@code PSSParameterSpec} as defined in
* the PKCS #1 standard using the default values.
*/
private PSSParameterSpec() {
}
/**
* Creates a new {@code PSSParameterSpec} as defined in
* the PKCS #1 standard using the specified message digest,
* mask generation function, parameters for mask generation
* function, salt length, and trailer field values.
*
* @param mdName the algorithm name of the hash function.
* @param mgfName the algorithm name of the mask generation
* function.
* @param mgfSpec the parameters for the mask generation
* function. If null is specified, null will be returned by
* getMGFParameters().
* @param saltLen the length of salt.
* @param trailerField the value of the trailer field.
* @exception NullPointerException if {@code mdName},
* or {@code mgfName} is null.
* @exception IllegalArgumentException if {@code saltLen}
* or {@code trailerField} is less than 0.
* @since 1.5
*/
public PSSParameterSpec(String mdName, String mgfName,
AlgorithmParameterSpec mgfSpec,
int saltLen, int trailerField) {
if (mdName == null) {
throw new NullPointerException("digest algorithm is null");
}
if (mgfName == null) {
throw new NullPointerException("mask generation function " +
"algorithm is null");
}
if (saltLen < 0) {
throw new IllegalArgumentException("negative saltLen value: " +
saltLen);
}
if (trailerField < 0) {
throw new IllegalArgumentException("negative trailerField: " +
trailerField);
}
this.mdName = mdName;
this.mgfName = mgfName;
this.mgfSpec = mgfSpec;
this.saltLen = saltLen;
this.trailerField = trailerField;
}
/**
* Creates a new {@code PSSParameterSpec}
* using the specified salt length and other default values as
* defined in PKCS#1.
*
* @param saltLen the length of salt in bits to be used in PKCS#1
* PSS encoding.
* @exception IllegalArgumentException if {@code saltLen} is
* less than 0.
*/
public PSSParameterSpec(int saltLen) {
if (saltLen < 0) {
throw new IllegalArgumentException("negative saltLen value: " +
saltLen);
}
this.saltLen = saltLen;
}
/**
* Returns the message digest algorithm name.
*
* @return the message digest algorithm name.
* @since 1.5
*/
public String getDigestAlgorithm() {
return mdName;
}
/**
* Returns the mask generation function algorithm name.
*
* @return the mask generation function algorithm name.
*
* @since 1.5
*/
public String getMGFAlgorithm() {
return mgfName;
}
/**
* Returns the parameters for the mask generation function.
*
* @return the parameters for the mask generation function.
* @since 1.5
*/
public AlgorithmParameterSpec getMGFParameters() {
return mgfSpec;
}
/**
* Returns the salt length in bits.
*
* @return the salt length.
*/
public int getSaltLength() {
return saltLen;
}
/**
* Returns the value for the trailer field, i.e. bc in PKCS#1 v2.1.
*
* @return the value for the trailer field, i.e. bc in PKCS#1 v2.1.
* @since 1.5
*/
public int getTrailerField() {
return trailerField;
}
}

View file

@ -0,0 +1,86 @@
/*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
import java.math.BigInteger;
import java.security.spec.AlgorithmParameterSpec;
/**
* This class specifies the set of parameters used to generate an RSA
* key pair.
*
* @author Jan Luehe
*
* @see java.security.KeyPairGenerator#initialize(java.security.spec.AlgorithmParameterSpec)
*
* @since 1.3
*/
public class RSAKeyGenParameterSpec implements AlgorithmParameterSpec {
private int keysize;
private BigInteger publicExponent;
/**
* The public-exponent value F0 = 3.
*/
public static final BigInteger F0 = BigInteger.valueOf(3);
/**
* The public exponent-value F4 = 65537.
*/
public static final BigInteger F4 = BigInteger.valueOf(65537);
/**
* Constructs a new {@code RSAParameterSpec} object from the
* given keysize and public-exponent value.
*
* @param keysize the modulus size (specified in number of bits)
* @param publicExponent the public exponent
*/
public RSAKeyGenParameterSpec(int keysize, BigInteger publicExponent) {
this.keysize = keysize;
this.publicExponent = publicExponent;
}
/**
* Returns the keysize.
*
* @return the keysize.
*/
public int getKeysize() {
return keysize;
}
/**
* Returns the public-exponent value.
*
* @return the public-exponent value.
*/
public BigInteger getPublicExponent() {
return publicExponent;
}
}

View file

@ -0,0 +1,212 @@
/*
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
import java.math.BigInteger;
/**
* This class specifies an RSA multi-prime private key, as defined in the
* PKCS#1 v2.1, using the Chinese Remainder Theorem (CRT) information
* values for efficiency.
*
* @author Valerie Peng
*
*
* @see java.security.Key
* @see java.security.KeyFactory
* @see KeySpec
* @see PKCS8EncodedKeySpec
* @see RSAPrivateKeySpec
* @see RSAPublicKeySpec
* @see RSAOtherPrimeInfo
*
* @since 1.4
*/
public class RSAMultiPrimePrivateCrtKeySpec extends RSAPrivateKeySpec {
private final BigInteger publicExponent;
private final BigInteger primeP;
private final BigInteger primeQ;
private final BigInteger primeExponentP;
private final BigInteger primeExponentQ;
private final BigInteger crtCoefficient;
private final RSAOtherPrimeInfo[] otherPrimeInfo;
/**
* Creates a new {@code RSAMultiPrimePrivateCrtKeySpec}
* given the modulus, publicExponent, privateExponent,
* primeP, primeQ, primeExponentP, primeExponentQ,
* crtCoefficient, and otherPrimeInfo as defined in PKCS#1 v2.1.
*
* <p>Note that the contents of {@code otherPrimeInfo}
* are copied to protect against subsequent modification when
* constructing this object.
*
* @param modulus the modulus n.
* @param publicExponent the public exponent e.
* @param privateExponent the private exponent d.
* @param primeP the prime factor p of n.
* @param primeQ the prime factor q of n.
* @param primeExponentP this is d mod (p-1).
* @param primeExponentQ this is d mod (q-1).
* @param crtCoefficient the Chinese Remainder Theorem
* coefficient q-1 mod p.
* @param otherPrimeInfo triplets of the rest of primes, null can be
* specified if there are only two prime factors (p and q).
* @exception NullPointerException if any of the parameters, i.e.
* {@code modulus},
* {@code publicExponent}, {@code privateExponent},
* {@code primeP}, {@code primeQ},
* {@code primeExponentP}, {@code primeExponentQ},
* {@code crtCoefficient}, is null.
* @exception IllegalArgumentException if an empty, i.e. 0-length,
* {@code otherPrimeInfo} is specified.
*/
public RSAMultiPrimePrivateCrtKeySpec(BigInteger modulus,
BigInteger publicExponent,
BigInteger privateExponent,
BigInteger primeP,
BigInteger primeQ,
BigInteger primeExponentP,
BigInteger primeExponentQ,
BigInteger crtCoefficient,
RSAOtherPrimeInfo[] otherPrimeInfo) {
super(modulus, privateExponent);
if (modulus == null) {
throw new NullPointerException("the modulus parameter must be " +
"non-null");
}
if (publicExponent == null) {
throw new NullPointerException("the publicExponent parameter " +
"must be non-null");
}
if (privateExponent == null) {
throw new NullPointerException("the privateExponent parameter " +
"must be non-null");
}
if (primeP == null) {
throw new NullPointerException("the primeP parameter " +
"must be non-null");
}
if (primeQ == null) {
throw new NullPointerException("the primeQ parameter " +
"must be non-null");
}
if (primeExponentP == null) {
throw new NullPointerException("the primeExponentP parameter " +
"must be non-null");
}
if (primeExponentQ == null) {
throw new NullPointerException("the primeExponentQ parameter " +
"must be non-null");
}
if (crtCoefficient == null) {
throw new NullPointerException("the crtCoefficient parameter " +
"must be non-null");
}
this.publicExponent = publicExponent;
this.primeP = primeP;
this.primeQ = primeQ;
this.primeExponentP = primeExponentP;
this.primeExponentQ = primeExponentQ;
this.crtCoefficient = crtCoefficient;
if (otherPrimeInfo == null) {
this.otherPrimeInfo = null;
} else if (otherPrimeInfo.length == 0) {
throw new IllegalArgumentException("the otherPrimeInfo " +
"parameter must not be empty");
} else {
this.otherPrimeInfo = otherPrimeInfo.clone();
}
}
/**
* Returns the public exponent.
*
* @return the public exponent.
*/
public BigInteger getPublicExponent() {
return this.publicExponent;
}
/**
* Returns the primeP.
*
* @return the primeP.
*/
public BigInteger getPrimeP() {
return this.primeP;
}
/**
* Returns the primeQ.
*
* @return the primeQ.
*/
public BigInteger getPrimeQ() {
return this.primeQ;
}
/**
* Returns the primeExponentP.
*
* @return the primeExponentP.
*/
public BigInteger getPrimeExponentP() {
return this.primeExponentP;
}
/**
* Returns the primeExponentQ.
*
* @return the primeExponentQ.
*/
public BigInteger getPrimeExponentQ() {
return this.primeExponentQ;
}
/**
* Returns the crtCoefficient.
*
* @return the crtCoefficient.
*/
public BigInteger getCrtCoefficient() {
return this.crtCoefficient;
}
/**
* Returns a copy of the otherPrimeInfo or null if there are
* only two prime factors (p and q).
*
* @return the otherPrimeInfo. Returns a new array each
* time this method is called.
*/
public RSAOtherPrimeInfo[] getOtherPrimeInfo() {
if (otherPrimeInfo == null) return null;
return otherPrimeInfo.clone();
}
}

View file

@ -0,0 +1,120 @@
/*
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
import java.math.BigInteger;
/**
* This class represents the triplet (prime, exponent, and coefficient)
* inside RSA's OtherPrimeInfo structure, as defined in the PKCS#1 v2.1.
* The ASN.1 syntax of RSA's OtherPrimeInfo is as follows:
*
* <pre>
* OtherPrimeInfo ::= SEQUENCE {
* prime INTEGER,
* exponent INTEGER,
* coefficient INTEGER
* }
*
* </pre>
*
* @author Valerie Peng
*
*
* @see RSAPrivateCrtKeySpec
* @see java.security.interfaces.RSAMultiPrimePrivateCrtKey
*
* @since 1.4
*/
public class RSAOtherPrimeInfo {
private BigInteger prime;
private BigInteger primeExponent;
private BigInteger crtCoefficient;
/**
* Creates a new {@code RSAOtherPrimeInfo}
* given the prime, primeExponent, and
* crtCoefficient as defined in PKCS#1.
*
* @param prime the prime factor of n.
* @param primeExponent the exponent.
* @param crtCoefficient the Chinese Remainder Theorem
* coefficient.
* @exception NullPointerException if any of the parameters, i.e.
* {@code prime}, {@code primeExponent},
* {@code crtCoefficient}, is null.
*
*/
public RSAOtherPrimeInfo(BigInteger prime,
BigInteger primeExponent,
BigInteger crtCoefficient) {
if (prime == null) {
throw new NullPointerException("the prime parameter must be " +
"non-null");
}
if (primeExponent == null) {
throw new NullPointerException("the primeExponent parameter " +
"must be non-null");
}
if (crtCoefficient == null) {
throw new NullPointerException("the crtCoefficient parameter " +
"must be non-null");
}
this.prime = prime;
this.primeExponent = primeExponent;
this.crtCoefficient = crtCoefficient;
}
/**
* Returns the prime.
*
* @return the prime.
*/
public final BigInteger getPrime() {
return this.prime;
}
/**
* Returns the prime's exponent.
*
* @return the primeExponent.
*/
public final BigInteger getExponent() {
return this.primeExponent;
}
/**
* Returns the prime's crtCoefficient.
*
* @return the crtCoefficient.
*/
public final BigInteger getCrtCoefficient() {
return this.crtCoefficient;
}
}

View file

@ -0,0 +1,144 @@
/*
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
import java.math.BigInteger;
/**
* This class specifies an RSA private key, as defined in the PKCS#1
* standard, using the Chinese Remainder Theorem (CRT) information values for
* efficiency.
*
* @author Jan Luehe
* @since 1.2
*
*
* @see java.security.Key
* @see java.security.KeyFactory
* @see KeySpec
* @see PKCS8EncodedKeySpec
* @see RSAPrivateKeySpec
* @see RSAPublicKeySpec
*/
public class RSAPrivateCrtKeySpec extends RSAPrivateKeySpec {
private final BigInteger publicExponent;
private final BigInteger primeP;
private final BigInteger primeQ;
private final BigInteger primeExponentP;
private final BigInteger primeExponentQ;
private final BigInteger crtCoefficient;
/**
* Creates a new {@code RSAPrivateCrtKeySpec}
* given the modulus, publicExponent, privateExponent,
* primeP, primeQ, primeExponentP, primeExponentQ, and
* crtCoefficient as defined in PKCS#1.
*
* @param modulus the modulus n
* @param publicExponent the public exponent e
* @param privateExponent the private exponent d
* @param primeP the prime factor p of n
* @param primeQ the prime factor q of n
* @param primeExponentP this is d mod (p-1)
* @param primeExponentQ this is d mod (q-1)
* @param crtCoefficient the Chinese Remainder Theorem
* coefficient q-1 mod p
*/
public RSAPrivateCrtKeySpec(BigInteger modulus,
BigInteger publicExponent,
BigInteger privateExponent,
BigInteger primeP,
BigInteger primeQ,
BigInteger primeExponentP,
BigInteger primeExponentQ,
BigInteger crtCoefficient) {
super(modulus, privateExponent);
this.publicExponent = publicExponent;
this.primeP = primeP;
this.primeQ = primeQ;
this.primeExponentP = primeExponentP;
this.primeExponentQ = primeExponentQ;
this.crtCoefficient = crtCoefficient;
}
/**
* Returns the public exponent.
*
* @return the public exponent
*/
public BigInteger getPublicExponent() {
return this.publicExponent;
}
/**
* Returns the primeP.
* @return the primeP
*/
public BigInteger getPrimeP() {
return this.primeP;
}
/**
* Returns the primeQ.
*
* @return the primeQ
*/
public BigInteger getPrimeQ() {
return this.primeQ;
}
/**
* Returns the primeExponentP.
*
* @return the primeExponentP
*/
public BigInteger getPrimeExponentP() {
return this.primeExponentP;
}
/**
* Returns the primeExponentQ.
*
* @return the primeExponentQ
*/
public BigInteger getPrimeExponentQ() {
return this.primeExponentQ;
}
/**
* Returns the crtCoefficient.
*
* @return the crtCoefficient
*/
public BigInteger getCrtCoefficient() {
return this.crtCoefficient;
}
}

View file

@ -0,0 +1,78 @@
/*
* Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
import java.math.BigInteger;
/**
* This class specifies an RSA private key.
*
* @author Jan Luehe
* @since 1.2
*
*
* @see java.security.Key
* @see java.security.KeyFactory
* @see KeySpec
* @see PKCS8EncodedKeySpec
* @see RSAPublicKeySpec
* @see RSAPrivateCrtKeySpec
*/
public class RSAPrivateKeySpec implements KeySpec {
private BigInteger modulus;
private BigInteger privateExponent;
/**
* Creates a new RSAPrivateKeySpec.
*
* @param modulus the modulus
* @param privateExponent the private exponent
*/
public RSAPrivateKeySpec(BigInteger modulus, BigInteger privateExponent) {
this.modulus = modulus;
this.privateExponent = privateExponent;
}
/**
* Returns the modulus.
*
* @return the modulus
*/
public BigInteger getModulus() {
return this.modulus;
}
/**
* Returns the private exponent.
*
* @return the private exponent
*/
public BigInteger getPrivateExponent() {
return this.privateExponent;
}
}

View file

@ -0,0 +1,78 @@
/*
* Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
import java.math.BigInteger;
/**
* This class specifies an RSA public key.
*
* @author Jan Luehe
* @since 1.2
*
*
* @see java.security.Key
* @see java.security.KeyFactory
* @see KeySpec
* @see X509EncodedKeySpec
* @see RSAPrivateKeySpec
* @see RSAPrivateCrtKeySpec
*/
public class RSAPublicKeySpec implements KeySpec {
private BigInteger modulus;
private BigInteger publicExponent;
/**
* Creates a new RSAPublicKeySpec.
*
* @param modulus the modulus
* @param publicExponent the public exponent
*/
public RSAPublicKeySpec(BigInteger modulus, BigInteger publicExponent) {
this.modulus = modulus;
this.publicExponent = publicExponent;
}
/**
* Returns the modulus.
*
* @return the modulus
*/
public BigInteger getModulus() {
return this.modulus;
}
/**
* Returns the public exponent.
*
* @return the public exponent
*/
public BigInteger getPublicExponent() {
return this.publicExponent;
}
}

View file

@ -0,0 +1,110 @@
/*
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.security.spec;
/**
* This class represents the ASN.1 encoding of a public key,
* encoded according to the ASN.1 type {@code SubjectPublicKeyInfo}.
* The {@code SubjectPublicKeyInfo} syntax is defined in the X.509
* standard as follows:
*
* <pre>
* SubjectPublicKeyInfo ::= SEQUENCE {
* algorithm AlgorithmIdentifier,
* subjectPublicKey BIT STRING }
* </pre>
*
* @author Jan Luehe
*
*
* @see java.security.Key
* @see java.security.KeyFactory
* @see KeySpec
* @see EncodedKeySpec
* @see PKCS8EncodedKeySpec
*
* @since 1.2
*/
public class X509EncodedKeySpec extends EncodedKeySpec {
/**
* Creates a new {@code X509EncodedKeySpec} with the given encoded key.
*
* @param encodedKey the key, which is assumed to be
* encoded according to the X.509 standard. The contents of the
* array are copied to protect against subsequent modification.
* @throws NullPointerException if {@code encodedKey}
* is null.
*/
public X509EncodedKeySpec(byte[] encodedKey) {
super(encodedKey);
}
/**
* Creates a new {@code X509EncodedKeySpec} with the given encoded key.
* This constructor is useful when subsequent callers of the
* {@code X509EncodedKeySpec} object might not know the algorithm
* of the key.
*
* @param encodedKey the key, which is assumed to be
* encoded according to the X.509 standard. The contents of the
* array are copied to protect against subsequent modification.
* @param algorithm the algorithm name of the encoded public key
* See the KeyFactory section in the <a href=
* "{@docRoot}/../specs/security/standard-names.html#keyfactory-algorithms">
* Java Security Standard Algorithm Names Specification</a>
* for information about standard algorithm names.
* @throws NullPointerException if {@code encodedKey}
* or {@code algorithm} is null.
* @throws IllegalArgumentException if {@code algorithm} is
* the empty string {@code ""}
* @since 9
*/
public X509EncodedKeySpec(byte[] encodedKey, String algorithm) {
super(encodedKey, algorithm);
}
/**
* Returns the key bytes, encoded according to the X.509 standard.
*
* @return the X.509 encoding of the key. Returns a new array
* each time this method is called.
*/
public byte[] getEncoded() {
return super.getEncoded();
}
/**
* Returns the name of the encoding format associated with this
* key specification.
*
* @return the string {@code "X.509"}.
*/
public final String getFormat() {
return "X.509";
}
}

View file

@ -0,0 +1,65 @@
/*
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Provides classes and interfaces for key specifications and algorithm
* parameter specifications.
*
* <p>A key specification is a transparent representation of the key material
* that constitutes a key. A key may be specified in an algorithm-specific
* way, or in an algorithm-independent encoding format (such as ASN.1).
* This package contains key specifications for DSA public and private keys,
* RSA public and private keys, PKCS #8 private keys in DER-encoded format,
* and X.509 public and private keys in DER-encoded format.
*
* <p>An algorithm parameter specification is a transparent representation
* of the sets of parameters used with an algorithm. This package contains
* an algorithm parameter specification for parameters used with the
* DSA algorithm.
*
* <h2>Package Specification</h2>
*
* <ul>
* <li>PKCS #1: RSA Encryption Standard, Version 1.5, November 1993</li>
* <li>PKCS #8: Private-Key Information Syntax Standard,
* Version 1.2, November 1993</li>
* <li>Federal Information Processing Standards Publication (FIPS PUB) 186:
* Digital Signature Standard (DSS)</li>
* </ul>
*
* <h2>Related Documentation</h2>
*
* For documentation that includes information about algorithm parameter
* and key specifications, please see:
* <ul>
* <li> {@extLink security_guide_jca
* Java Cryptography Architecture (JCA) Reference Guide}</li>
* <li> {@extLink security_guide_impl_provider
* How to Implement a Provider in the Java Cryptography Architecture}</li>
* </ul>
*
* @since 1.2
*/
package java.security.spec;