/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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.
*/
/**
* KeyPairGenerator implementation class. This class currently supports
* RSA, DSA, DH, and EC.
*
* Note that for DSA and DH we rely on the Sun and SunJCE providers to
* obtain the parameters from.
*
* @author Andreas Sterbenz
* @since 1.5
*/
// token instance
// algorithm name
// mechanism id
private final long mechanism;
// selected or default key size, always valid
private int keySize;
// parameters specified via init, if any
// for RSA, selected or default value of public exponent, always valid
// SecureRandom instance, if specified in init
throws PKCS11Exception {
super();
} else {
}
}
// see JCA spec
token.ensureValid();
try {
} catch (InvalidAlgorithmParameterException e) {
throw new InvalidParameterException(e.getMessage());
}
throw new InvalidParameterException(
"No EC parameters available for key size "
+ keySize + " bits");
}
}
}
// see JCA spec
throws InvalidAlgorithmParameterException {
token.ensureValid();
if (params instanceof DHParameterSpec == false) {
throw new InvalidAlgorithmParameterException
("DHParameterSpec required for Diffie-Hellman");
}
this.keySize = tmpKeySize;
// XXX sanity check params
if (params instanceof RSAKeyGenParameterSpec == false) {
throw new InvalidAlgorithmParameterException
("RSAKeyGenParameterSpec required for RSA");
}
this.keySize = tmpKeySize;
// XXX sanity check params
if (params instanceof DSAParameterSpec == false) {
throw new InvalidAlgorithmParameterException
("DSAParameterSpec required for DSA");
}
this.keySize = tmpKeySize;
// XXX sanity check params
if (params instanceof ECParameterSpec) {
throw new InvalidAlgorithmParameterException
("Unsupported curve: " + params);
}
} else if (params instanceof ECGenParameterSpec) {
throw new InvalidAlgorithmParameterException
("Unknown curve name: " + name);
}
} else {
throw new InvalidAlgorithmParameterException
("ECParameterSpec or ECGenParameterSpec required for EC");
}
this.keySize = tmpKeySize;
} else {
}
}
throws InvalidAlgorithmParameterException {
if (keySize < 112) {
throw new InvalidAlgorithmParameterException
("Key size must be at least 112 bit");
}
if (keySize > 2048) {
// sanity check, nobody really wants keys this large
throw new InvalidAlgorithmParameterException
("Key size must be at most 2048 bit");
}
return;
// Already tested for instanceof RSAKeyGenParameterSpec above
}
try {
// This provider supports 64K or less.
512, 64 * 1024);
} catch (InvalidKeyException e) {
throw new InvalidAlgorithmParameterException(e.getMessage());
}
return;
}
if (keySize < 512) {
throw new InvalidAlgorithmParameterException
("Key size must be at least 512 bit");
}
// sanity check, nobody really wants keys this large
throw new InvalidAlgorithmParameterException
("Key size must be at most 65536 bit");
}
} else {
// this restriction is in the spec for DSA
// since we currently use DSA parameters for DH as well,
// it also applies to DH if no parameters are specified
throw new InvalidAlgorithmParameterException
("Key size must be a multiple of 64 and at most 1024 bit");
}
}
}
// see JCA spec
token.ensureValid();
long keyType;
publicKeyTemplate = new CK_ATTRIBUTE[] {
};
privateKeyTemplate = new CK_ATTRIBUTE[] {
// empty
};
try {
} catch (GeneralSecurityException e) {
throw new ProviderException
("Could not generate DSA parameters", e);
}
} else {
}
publicKeyTemplate = new CK_ATTRIBUTE[] {
};
privateKeyTemplate = new CK_ATTRIBUTE[] {
// empty
};
int privateBits;
try {
} catch (GeneralSecurityException e) {
throw new ProviderException
("Could not generate DH parameters", e);
}
privateBits = 0;
} else {
}
if (privateBits <= 0) {
// XXX find better defaults
}
publicKeyTemplate = new CK_ATTRIBUTE[] {
};
privateKeyTemplate = new CK_ATTRIBUTE[] {
};
byte[] encodedParams =
publicKeyTemplate = new CK_ATTRIBUTE[] {
};
privateKeyTemplate = new CK_ATTRIBUTE[] {
// empty
};
} else {
}
try {
} catch (PKCS11Exception e) {
throw new ProviderException(e);
} finally {
}
}
}