diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-01-27 14:00:22 +0100 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-01-27 14:00:22 +0100 |
commit | 5aec25ac0501352e4cb6645c86869dde6e91f0d0 (patch) | |
tree | ee9adfd55cddf25f098e5e028d585a72de7cd70c /libraries/spongycastle/core/src/main/jdk1.2/java | |
parent | 8ca42b9bf953c6195ee0c17ef48a3154c126cc04 (diff) | |
download | open-keychain-5aec25ac0501352e4cb6645c86869dde6e91f0d0.tar.gz open-keychain-5aec25ac0501352e4cb6645c86869dde6e91f0d0.tar.bz2 open-keychain-5aec25ac0501352e4cb6645c86869dde6e91f0d0.zip |
Add spongy castle sources to libraries folder
Diffstat (limited to 'libraries/spongycastle/core/src/main/jdk1.2/java')
5 files changed, 386 insertions, 0 deletions
diff --git a/libraries/spongycastle/core/src/main/jdk1.2/java/security/interfaces/RSAMultiPrimePrivateCrtKey.java b/libraries/spongycastle/core/src/main/jdk1.2/java/security/interfaces/RSAMultiPrimePrivateCrtKey.java new file mode 100644 index 000000000..042eb3eb2 --- /dev/null +++ b/libraries/spongycastle/core/src/main/jdk1.2/java/security/interfaces/RSAMultiPrimePrivateCrtKey.java @@ -0,0 +1,67 @@ + +package java.security.interfaces; + +import java.math.BigInteger; +import java.security.spec.RSAOtherPrimeInfo; + +/** + * The interface to an RSA multi-prime private key, as defined in the + * PKCS#1 v2.1, using the Chinese Remainder Theorem (CRT) information values. + * + * @since 1.4 + * @see RSAPrivateKeySpec, RSAMultiPrimePrivateCrtKeySpec, RSAPrivateKey, + * RSAPrivateCrtKey + */ +public interface RSAMultiPrimePrivateCrtKey +extends RSAPrivateKey +{ + /** + * Returns the public exponent. + * + * @returns the public exponent. + */ + public BigInteger getPublicExponent(); + + /** + * Returns the primeP. + * + * @returns the primeP. + */ + public BigInteger getPrimeP(); + + /** + * Returns the primeQ. + * + * @returns the primeQ. + */ + public BigInteger getPrimeQ(); + + /** + * Returns the primeExponentP. + * + * @returns the primeExponentP. + */ + public BigInteger getPrimeExponentP(); + + /** + * Returns the primeExponentQ. + * + * @returns the primeExponentQ. + */ + public BigInteger getPrimeExponentQ(); + + /** + * Returns the crtCoefficient. + * + * @returns the crtCoefficient. + */ + public BigInteger getCrtCoefficient(); + + /** + * Returns the otherPrimeInfo or null if there are only two prime + * factors (p and q). + * + * @returns the otherPrimeInfo. + */ + public RSAOtherPrimeInfo[] getOtherPrimeInfo(); +} diff --git a/libraries/spongycastle/core/src/main/jdk1.2/java/security/spec/PSSParameterSpec.java b/libraries/spongycastle/core/src/main/jdk1.2/java/security/spec/PSSParameterSpec.java new file mode 100644 index 000000000..f58d83b78 --- /dev/null +++ b/libraries/spongycastle/core/src/main/jdk1.2/java/security/spec/PSSParameterSpec.java @@ -0,0 +1,45 @@ + +package java.security.spec; + +/** + * This class specifies a parameter spec for RSA PSS encoding scheme, + * as defined in the PKCS#1 v2.1. + * + * @since 1.4 + * @see AlgorithmParameterSpec, Signature + */ +public class PSSParameterSpec + extends Object + implements AlgorithmParameterSpec +{ + private int saltLen; + + /** + * Creates a new PSSParameterSpec given the salt length as defined + * in PKCS#1. + * + * @param saltLen - the length of salt in bits to be used in PKCS#1 + * PSS encoding. + * @throws IllegalArgumentException - if saltLen is less than 0. + */ + public PSSParameterSpec(int saltLen) + { + if ( saltLen < 0 ) + { + throw new IllegalArgumentException("Salt length must be >= 0"); + } + + this.saltLen = saltLen; + } + + /** + * Returns the salt length in bits. + * + * @returns the salt length. + */ + public int getSaltLength() + { + return saltLen; + } +} + diff --git a/libraries/spongycastle/core/src/main/jdk1.2/java/security/spec/RSAKeyGenParameterSpec.java b/libraries/spongycastle/core/src/main/jdk1.2/java/security/spec/RSAKeyGenParameterSpec.java new file mode 100644 index 000000000..756c6c0fd --- /dev/null +++ b/libraries/spongycastle/core/src/main/jdk1.2/java/security/spec/RSAKeyGenParameterSpec.java @@ -0,0 +1,35 @@ +package java.security.spec; + +import java.math.BigInteger; + +/** + * specifies parameters to be used for the generation of + * a RSA key pair. + */ +public class RSAKeyGenParameterSpec + implements AlgorithmParameterSpec +{ + static BigInteger F0 = BigInteger.valueOf(3); + static BigInteger F4 = BigInteger.valueOf(65537); + + private int keysize; + private BigInteger publicExponent; + + public RSAKeyGenParameterSpec( + int keysize, + BigInteger publicExponent) + { + this.keysize = keysize; + this.publicExponent = publicExponent; + } + + public int getKeysize() + { + return keysize; + } + + public BigInteger getPublicExponent() + { + return publicExponent; + } +} diff --git a/libraries/spongycastle/core/src/main/jdk1.2/java/security/spec/RSAMultiPrimePrivateCrtKeySpec.java b/libraries/spongycastle/core/src/main/jdk1.2/java/security/spec/RSAMultiPrimePrivateCrtKeySpec.java new file mode 100644 index 000000000..1339b4f6d --- /dev/null +++ b/libraries/spongycastle/core/src/main/jdk1.2/java/security/spec/RSAMultiPrimePrivateCrtKeySpec.java @@ -0,0 +1,159 @@ + +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. + * + * @since 1.4 + * @see Key, KeyFactory, KeySpec, PKCS8EncodedKeySpec, RSAPrivateKeySpec, + * RSAPublicKeySpec, RSAOtherPrimeInfo + */ +public class RSAMultiPrimePrivateCrtKeySpec + extends RSAPrivateKeySpec +{ + private BigInteger publicExponent; + private BigInteger privateExponent; + private BigInteger primeP; + private BigInteger primeQ; + private BigInteger primeExponentP; + private BigInteger primeExponentQ; + private BigInteger crtCoefficient; + private RSAOtherPrimeInfo[] otherPrimeInfo; + + /** + * Creates a new RSAMultiPrimePrivateCrtKeySpec given the modulus, + * publicExponent, privateExponent, primeP, primeQ, primeExponentP, + * primeExponentQ, crtCoefficient, and otherPrimeInfo as defined in + * PKCS#1 v2.1. + * + * Note that otherPrimeInfo is cloned 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). + * @throws NullPointerException - if any of the parameters, i.e. modulus, + * publicExponent, privateExponent, primeP, primeQ, primeExponentP, + * primeExponentQ, crtCoefficient, is null. + * @throws IllegalArgumentException - if an empty, i.e. 0-length, + * 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 ( publicExponent == null || primeP == null || primeQ == null + || primeExponentP == null || primeExponentQ == null + || crtCoefficient == null ) + { + throw new NullPointerException("Invalid null argument"); + } + + if ( otherPrimeInfo != null ) + { + if ( otherPrimeInfo.length == 0 ) + { + throw new IllegalArgumentException("Invalid length for otherPrimeInfo"); + } + + this.otherPrimeInfo = (RSAOtherPrimeInfo[])otherPrimeInfo.clone(); + } + } + + /** + * Returns the public exponent. + * + * @returns the public exponent. + */ + public BigInteger getPublicExponent() + { + return publicExponent; + } + + /** + * Returns the primeP. + * + * @returns the primeP. + */ + public BigInteger getPrimeP() + { + return primeP; + } + + /** + * Returns the primeQ. + * + * @returns the primeQ. + */ + public BigInteger getPrimeQ() + { + return primeQ; + } + + /** + * Returns the primeExponentP. + * + * @returns the primeExponentP. + */ + public BigInteger getPrimeExponentP() + { + return primeExponentP; + } + + /** + * Returns the primeExponentQ. + * + * @returns the primeExponentQ. + */ + public BigInteger getPrimeExponentQ() + { + return primeExponentQ; + } + + /** + * Returns the crtCofficient. + * + * @returns the crtCofficient. + */ + public BigInteger getCrtCoefficient() + { + return crtCoefficient; + } + + /** + * Returns a copy of the otherPrimeInfo or null if there are only + * two prime factors (p and q). + * + * @returns the otherPrimeInfo. + */ + public RSAOtherPrimeInfo[] getOtherPrimeInfo() + { + if ( otherPrimeInfo != null ) + { + return (RSAOtherPrimeInfo[])otherPrimeInfo.clone(); + } + + return null; + } +} + diff --git a/libraries/spongycastle/core/src/main/jdk1.2/java/security/spec/RSAOtherPrimeInfo.java b/libraries/spongycastle/core/src/main/jdk1.2/java/security/spec/RSAOtherPrimeInfo.java new file mode 100644 index 000000000..42a4fce6d --- /dev/null +++ b/libraries/spongycastle/core/src/main/jdk1.2/java/security/spec/RSAOtherPrimeInfo.java @@ -0,0 +1,80 @@ + +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> + */ +public class RSAOtherPrimeInfo +extends Object +{ + private BigInteger prime; + private BigInteger primeExponent; + private BigInteger crtCoefficient; + + /** + * Creates a new 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. + * @throws NullPointerException - if any of the parameters, i.e. prime, + * primeExponent, crtCoefficient, is null. + */ + public RSAOtherPrimeInfo( + BigInteger prime, + BigInteger primeExponent, + BigInteger crtCoefficient) + { + if ( prime == null || primeExponent == null || crtCoefficient == null ) + { + throw new NullPointerException("Null parameter"); + } + + this.prime = prime; + this.primeExponent = primeExponent; + this.crtCoefficient = crtCoefficient; + } + + /** + * Returns the prime. + * + * @returns the prime. + */ + public final BigInteger getPrime() + { + return prime; + } + + /** + * Returns the prime's exponent. + * + * @returns the primeExponent. + */ + public final BigInteger getExponent() + { + return primeExponent; + } + + /** + * Returns the prime's crtCoefficient. + * + * @returns the crtCoefficient. + */ + public final BigInteger getCrtCoefficient() + { + return crtCoefficient; + } +} |