diff options
Diffstat (limited to 'prov/src/main/java/org/spongycastle/jce/spec')
22 files changed, 1387 insertions, 0 deletions
diff --git a/prov/src/main/java/org/spongycastle/jce/spec/ECKeySpec.java b/prov/src/main/java/org/spongycastle/jce/spec/ECKeySpec.java new file mode 100644 index 00000000..42ff1db3 --- /dev/null +++ b/prov/src/main/java/org/spongycastle/jce/spec/ECKeySpec.java @@ -0,0 +1,26 @@ +package org.spongycastle.jce.spec; + +import java.security.spec.KeySpec; + +/** + * base class for an Elliptic Curve Key Spec + */ +public class ECKeySpec + implements KeySpec +{ + private ECParameterSpec spec; + + protected ECKeySpec( + ECParameterSpec spec) + { + this.spec = spec; + } + + /** + * return the domain parameters for the curve + */ + public ECParameterSpec getParams() + { + return spec; + } +} diff --git a/prov/src/main/java/org/spongycastle/jce/spec/ECNamedCurveGenParameterSpec.java b/prov/src/main/java/org/spongycastle/jce/spec/ECNamedCurveGenParameterSpec.java new file mode 100644 index 00000000..2b1d0404 --- /dev/null +++ b/prov/src/main/java/org/spongycastle/jce/spec/ECNamedCurveGenParameterSpec.java @@ -0,0 +1,28 @@ +package org.spongycastle.jce.spec; + +import java.security.spec.AlgorithmParameterSpec; + +/** + * Named curve generation spec + * <p> + * If you are using JDK 1.5 you should be looking at ECGenParameterSpec. + */ +public class ECNamedCurveGenParameterSpec + implements AlgorithmParameterSpec +{ + private String name; + + public ECNamedCurveGenParameterSpec( + String name) + { + this.name = name; + } + + /** + * return the name of the curve the EC domain parameters belong to. + */ + public String getName() + { + return name; + } +} diff --git a/prov/src/main/java/org/spongycastle/jce/spec/ECNamedCurveParameterSpec.java b/prov/src/main/java/org/spongycastle/jce/spec/ECNamedCurveParameterSpec.java new file mode 100644 index 00000000..f10a0b41 --- /dev/null +++ b/prov/src/main/java/org/spongycastle/jce/spec/ECNamedCurveParameterSpec.java @@ -0,0 +1,62 @@ +package org.spongycastle.jce.spec; + +import java.math.BigInteger; + +import org.spongycastle.math.ec.ECCurve; +import org.spongycastle.math.ec.ECPoint; + +/** + * specification signifying that the curve parameters can also be + * referred to by name. + * <p> + * If you are using JDK 1.5 you should be looking at {@link ECNamedCurveSpec}. + */ +public class ECNamedCurveParameterSpec + extends ECParameterSpec +{ + private String name; + + public ECNamedCurveParameterSpec( + String name, + ECCurve curve, + ECPoint G, + BigInteger n) + { + super(curve, G, n); + + this.name = name; + } + + public ECNamedCurveParameterSpec( + String name, + ECCurve curve, + ECPoint G, + BigInteger n, + BigInteger h) + { + super(curve, G, n, h); + + this.name = name; + } + + public ECNamedCurveParameterSpec( + String name, + ECCurve curve, + ECPoint G, + BigInteger n, + BigInteger h, + byte[] seed) + { + super(curve, G, n, h, seed); + + this.name = name; + } + + /** + * return the name of the curve the EC domain parameters belong to. + */ + public String getName() + { + return name; + } +} diff --git a/prov/src/main/java/org/spongycastle/jce/spec/ECNamedCurveSpec.java b/prov/src/main/java/org/spongycastle/jce/spec/ECNamedCurveSpec.java new file mode 100644 index 00000000..681d7070 --- /dev/null +++ b/prov/src/main/java/org/spongycastle/jce/spec/ECNamedCurveSpec.java @@ -0,0 +1,123 @@ +package org.spongycastle.jce.spec; + +import java.math.BigInteger; +import java.security.spec.ECFieldF2m; +import java.security.spec.ECFieldFp; +import java.security.spec.ECPoint; +import java.security.spec.EllipticCurve; + +import org.spongycastle.math.ec.ECAlgorithms; +import org.spongycastle.math.ec.ECCurve; + +/** + * specification signifying that the curve parameters can also be + * referred to by name. + */ +public class ECNamedCurveSpec + extends java.security.spec.ECParameterSpec +{ + private String name; + + private static EllipticCurve convertCurve( + ECCurve curve, + byte[] seed) + { + if (ECAlgorithms.isFpCurve(curve)) + { + return new EllipticCurve(new ECFieldFp(curve.getField().getCharacteristic()), curve.getA().toBigInteger(), curve.getB().toBigInteger(), seed); + } + else + { + ECCurve.F2m curveF2m = (ECCurve.F2m)curve; + int ks[]; + + if (curveF2m.isTrinomial()) + { + ks = new int[] { curveF2m.getK1() }; + + return new EllipticCurve(new ECFieldF2m(curveF2m.getM(), ks), curve.getA().toBigInteger(), curve.getB().toBigInteger(), seed); + } + else + { + ks = new int[] { curveF2m.getK3(), curveF2m.getK2(), curveF2m.getK1() }; + + return new EllipticCurve(new ECFieldF2m(curveF2m.getM(), ks), curve.getA().toBigInteger(), curve.getB().toBigInteger(), seed); + } + } + + } + + private static ECPoint convertPoint( + org.spongycastle.math.ec.ECPoint g) + { + g = g.normalize(); + return new ECPoint(g.getAffineXCoord().toBigInteger(), g.getAffineYCoord().toBigInteger()); + } + + public ECNamedCurveSpec( + String name, + ECCurve curve, + org.spongycastle.math.ec.ECPoint g, + BigInteger n) + { + super(convertCurve(curve, null), convertPoint(g), n, 1); + + this.name = name; + } + + public ECNamedCurveSpec( + String name, + EllipticCurve curve, + ECPoint g, + BigInteger n) + { + super(curve, g, n, 1); + + this.name = name; + } + + public ECNamedCurveSpec( + String name, + ECCurve curve, + org.spongycastle.math.ec.ECPoint g, + BigInteger n, + BigInteger h) + { + super(convertCurve(curve, null), convertPoint(g), n, h.intValue()); + + this.name = name; + } + + public ECNamedCurveSpec( + String name, + EllipticCurve curve, + ECPoint g, + BigInteger n, + BigInteger h) + { + super(curve, g, n, h.intValue()); + + this.name = name; + } + + public ECNamedCurveSpec( + String name, + ECCurve curve, + org.spongycastle.math.ec.ECPoint g, + BigInteger n, + BigInteger h, + byte[] seed) + { + super(convertCurve(curve, seed), convertPoint(g), n, h.intValue()); + + this.name = name; + } + + /** + * return the name of the curve the EC domain parameters belong to. + */ + public String getName() + { + return name; + } +} diff --git a/prov/src/main/java/org/spongycastle/jce/spec/ECParameterSpec.java b/prov/src/main/java/org/spongycastle/jce/spec/ECParameterSpec.java new file mode 100644 index 00000000..f0f00e8c --- /dev/null +++ b/prov/src/main/java/org/spongycastle/jce/spec/ECParameterSpec.java @@ -0,0 +1,121 @@ +package org.spongycastle.jce.spec; + +import org.spongycastle.math.ec.ECCurve; +import org.spongycastle.math.ec.ECPoint; + +import java.math.BigInteger; +import java.security.spec.AlgorithmParameterSpec; + +/** + * basic domain parameters for an Elliptic Curve public or private key. + */ +public class ECParameterSpec + implements AlgorithmParameterSpec +{ + private ECCurve curve; + private byte[] seed; + private ECPoint G; + private BigInteger n; + private BigInteger h; + + public ECParameterSpec( + ECCurve curve, + ECPoint G, + BigInteger n) + { + this.curve = curve; + this.G = G.normalize(); + this.n = n; + this.h = BigInteger.valueOf(1); + this.seed = null; + } + + public ECParameterSpec( + ECCurve curve, + ECPoint G, + BigInteger n, + BigInteger h) + { + this.curve = curve; + this.G = G.normalize(); + this.n = n; + this.h = h; + this.seed = null; + } + + public ECParameterSpec( + ECCurve curve, + ECPoint G, + BigInteger n, + BigInteger h, + byte[] seed) + { + this.curve = curve; + this.G = G.normalize(); + this.n = n; + this.h = h; + this.seed = seed; + } + + /** + * return the curve along which the base point lies. + * @return the curve + */ + public ECCurve getCurve() + { + return curve; + } + + /** + * return the base point we are using for these domain parameters. + * @return the base point. + */ + public ECPoint getG() + { + return G; + } + + /** + * return the order N of G + * @return the order + */ + public BigInteger getN() + { + return n; + } + + /** + * return the cofactor H to the order of G. + * @return the cofactor + */ + public BigInteger getH() + { + return h; + } + + /** + * return the seed used to generate this curve (if available). + * @return the random seed + */ + public byte[] getSeed() + { + return seed; + } + + public boolean equals(Object o) + { + if (!(o instanceof ECParameterSpec)) + { + return false; + } + + ECParameterSpec other = (ECParameterSpec)o; + + return this.getCurve().equals(other.getCurve()) && this.getG().equals(other.getG()); + } + + public int hashCode() + { + return this.getCurve().hashCode() ^ this.getG().hashCode(); + } +} diff --git a/prov/src/main/java/org/spongycastle/jce/spec/ECPrivateKeySpec.java b/prov/src/main/java/org/spongycastle/jce/spec/ECPrivateKeySpec.java new file mode 100644 index 00000000..36b0db12 --- /dev/null +++ b/prov/src/main/java/org/spongycastle/jce/spec/ECPrivateKeySpec.java @@ -0,0 +1,35 @@ +package org.spongycastle.jce.spec; + +import java.math.BigInteger; + +/** + * Elliptic Curve private key specification. + */ +public class ECPrivateKeySpec + extends ECKeySpec +{ + private BigInteger d; + + /** + * base constructor + * + * @param d the private number for the key. + * @param spec the domain parameters for the curve being used. + */ + public ECPrivateKeySpec( + BigInteger d, + ECParameterSpec spec) + { + super(spec); + + this.d = d; + } + + /** + * return the private number D + */ + public BigInteger getD() + { + return d; + } +} diff --git a/prov/src/main/java/org/spongycastle/jce/spec/ECPublicKeySpec.java b/prov/src/main/java/org/spongycastle/jce/spec/ECPublicKeySpec.java new file mode 100644 index 00000000..e2888d38 --- /dev/null +++ b/prov/src/main/java/org/spongycastle/jce/spec/ECPublicKeySpec.java @@ -0,0 +1,42 @@ +package org.spongycastle.jce.spec; + +import org.spongycastle.math.ec.ECPoint; + +/** + * Elliptic Curve public key specification + */ +public class ECPublicKeySpec + extends ECKeySpec +{ + private ECPoint q; + + /** + * base constructor + * + * @param q the public point on the curve. + * @param spec the domain parameters for the curve. + */ + public ECPublicKeySpec( + ECPoint q, + ECParameterSpec spec) + { + super(spec); + + if (q.getCurve() != null) + { + this.q = q.normalize(); + } + else + { + this.q = q; + } + } + + /** + * return the public point q + */ + public ECPoint getQ() + { + return q; + } +} diff --git a/prov/src/main/java/org/spongycastle/jce/spec/ElGamalGenParameterSpec.java b/prov/src/main/java/org/spongycastle/jce/spec/ElGamalGenParameterSpec.java new file mode 100644 index 00000000..3e45484d --- /dev/null +++ b/prov/src/main/java/org/spongycastle/jce/spec/ElGamalGenParameterSpec.java @@ -0,0 +1,28 @@ +package org.spongycastle.jce.spec; + +import java.security.spec.AlgorithmParameterSpec; + +public class ElGamalGenParameterSpec + implements AlgorithmParameterSpec +{ + private int primeSize; + + /* + * @param primeSize the size (in bits) of the prime modulus. + */ + public ElGamalGenParameterSpec( + int primeSize) + { + this.primeSize = primeSize; + } + + /** + * Returns the size in bits of the prime modulus. + * + * @return the size in bits of the prime modulus + */ + public int getPrimeSize() + { + return primeSize; + } +} diff --git a/prov/src/main/java/org/spongycastle/jce/spec/ElGamalKeySpec.java b/prov/src/main/java/org/spongycastle/jce/spec/ElGamalKeySpec.java new file mode 100644 index 00000000..49d3f2f0 --- /dev/null +++ b/prov/src/main/java/org/spongycastle/jce/spec/ElGamalKeySpec.java @@ -0,0 +1,20 @@ +package org.spongycastle.jce.spec; + +import java.security.spec.KeySpec; + +public class ElGamalKeySpec + implements KeySpec +{ + private ElGamalParameterSpec spec; + + public ElGamalKeySpec( + ElGamalParameterSpec spec) + { + this.spec = spec; + } + + public ElGamalParameterSpec getParams() + { + return spec; + } +} diff --git a/prov/src/main/java/org/spongycastle/jce/spec/ElGamalParameterSpec.java b/prov/src/main/java/org/spongycastle/jce/spec/ElGamalParameterSpec.java new file mode 100644 index 00000000..276790f8 --- /dev/null +++ b/prov/src/main/java/org/spongycastle/jce/spec/ElGamalParameterSpec.java @@ -0,0 +1,46 @@ +package org.spongycastle.jce.spec; + +import java.math.BigInteger; +import java.security.spec.AlgorithmParameterSpec; + +public class ElGamalParameterSpec + implements AlgorithmParameterSpec +{ + private BigInteger p; + private BigInteger g; + + /** + * Constructs a parameter set for Diffie-Hellman, using a prime modulus + * <code>p</code> and a base generator <code>g</code>. + * + * @param p the prime modulus + * @param g the base generator + */ + public ElGamalParameterSpec( + BigInteger p, + BigInteger g) + { + this.p = p; + this.g = g; + } + + /** + * Returns the prime modulus <code>p</code>. + * + * @return the prime modulus <code>p</code> + */ + public BigInteger getP() + { + return p; + } + + /** + * Returns the base generator <code>g</code>. + * + * @return the base generator <code>g</code> + */ + public BigInteger getG() + { + return g; + } +} diff --git a/prov/src/main/java/org/spongycastle/jce/spec/ElGamalPrivateKeySpec.java b/prov/src/main/java/org/spongycastle/jce/spec/ElGamalPrivateKeySpec.java new file mode 100644 index 00000000..be023e34 --- /dev/null +++ b/prov/src/main/java/org/spongycastle/jce/spec/ElGamalPrivateKeySpec.java @@ -0,0 +1,33 @@ +package org.spongycastle.jce.spec; + +import java.math.BigInteger; + +/** + * This class specifies an ElGamal private key with its associated parameters. + * + * @see ElGamalPublicKeySpec + */ +public class ElGamalPrivateKeySpec + extends ElGamalKeySpec +{ + private BigInteger x; + + public ElGamalPrivateKeySpec( + BigInteger x, + ElGamalParameterSpec spec) + { + super(spec); + + this.x = x; + } + + /** + * Returns the private value <code>x</code>. + * + * @return the private value <code>x</code> + */ + public BigInteger getX() + { + return x; + } +} diff --git a/prov/src/main/java/org/spongycastle/jce/spec/ElGamalPublicKeySpec.java b/prov/src/main/java/org/spongycastle/jce/spec/ElGamalPublicKeySpec.java new file mode 100644 index 00000000..558730e5 --- /dev/null +++ b/prov/src/main/java/org/spongycastle/jce/spec/ElGamalPublicKeySpec.java @@ -0,0 +1,33 @@ +package org.spongycastle.jce.spec; + +import java.math.BigInteger; + +/** + * This class specifies an ElGamal public key with its associated parameters. + * + * @see ElGamalPrivateKeySpec + */ +public class ElGamalPublicKeySpec + extends ElGamalKeySpec +{ + private BigInteger y; + + public ElGamalPublicKeySpec( + BigInteger y, + ElGamalParameterSpec spec) + { + super(spec); + + this.y = y; + } + + /** + * Returns the public value <code>y</code>. + * + * @return the public value <code>y</code> + */ + public BigInteger getY() + { + return y; + } +} diff --git a/prov/src/main/java/org/spongycastle/jce/spec/GOST28147ParameterSpec.java b/prov/src/main/java/org/spongycastle/jce/spec/GOST28147ParameterSpec.java new file mode 100644 index 00000000..a721db93 --- /dev/null +++ b/prov/src/main/java/org/spongycastle/jce/spec/GOST28147ParameterSpec.java @@ -0,0 +1,48 @@ +package org.spongycastle.jce.spec; + +/** + * A parameter spec for the GOST-28147 cipher. + * @deprecated use org.spongycastle.jcajce.spec.GOST28147ParameterSpec + */ +public class GOST28147ParameterSpec + extends org.spongycastle.jcajce.spec.GOST28147ParameterSpec +{ + /** + * @deprecated + */ + public GOST28147ParameterSpec( + byte[] sBox) + { + super(sBox); + } + + /** + * @deprecated + */ + public GOST28147ParameterSpec( + byte[] sBox, + byte[] iv) + { + super(sBox, iv); + + } + + /** + * @deprecated + */ + public GOST28147ParameterSpec( + String sBoxName) + { + super(sBoxName); + } + + /** + * @deprecated + */ + public GOST28147ParameterSpec( + String sBoxName, + byte[] iv) + { + super(sBoxName, iv); + } +}
\ No newline at end of file diff --git a/prov/src/main/java/org/spongycastle/jce/spec/GOST3410ParameterSpec.java b/prov/src/main/java/org/spongycastle/jce/spec/GOST3410ParameterSpec.java new file mode 100644 index 00000000..755a5284 --- /dev/null +++ b/prov/src/main/java/org/spongycastle/jce/spec/GOST3410ParameterSpec.java @@ -0,0 +1,133 @@ +package org.spongycastle.jce.spec; + +import java.security.spec.AlgorithmParameterSpec; + +import org.spongycastle.asn1.ASN1ObjectIdentifier; +import org.spongycastle.asn1.cryptopro.CryptoProObjectIdentifiers; +import org.spongycastle.asn1.cryptopro.GOST3410NamedParameters; +import org.spongycastle.asn1.cryptopro.GOST3410ParamSetParameters; +import org.spongycastle.asn1.cryptopro.GOST3410PublicKeyAlgParameters; +import org.spongycastle.jce.interfaces.GOST3410Params; + +/** + * ParameterSpec for a GOST 3410-94 key. + */ +public class GOST3410ParameterSpec + implements AlgorithmParameterSpec, GOST3410Params +{ + private GOST3410PublicKeyParameterSetSpec keyParameters; + private String keyParamSetOID; + private String digestParamSetOID; + private String encryptionParamSetOID; + + public GOST3410ParameterSpec( + String keyParamSetID, + String digestParamSetOID, + String encryptionParamSetOID) + { + GOST3410ParamSetParameters ecP = null; + + try + { + ecP = GOST3410NamedParameters.getByOID(new ASN1ObjectIdentifier(keyParamSetID)); + } + catch (IllegalArgumentException e) + { + ASN1ObjectIdentifier oid = GOST3410NamedParameters.getOID(keyParamSetID); + if (oid != null) + { + keyParamSetID = oid.getId(); + ecP = GOST3410NamedParameters.getByOID(oid); + } + } + + if (ecP == null) + { + throw new IllegalArgumentException("no key parameter set for passed in name/OID."); + } + + this.keyParameters = new GOST3410PublicKeyParameterSetSpec( + ecP.getP(), + ecP.getQ(), + ecP.getA()); + + this.keyParamSetOID = keyParamSetID; + this.digestParamSetOID = digestParamSetOID; + this.encryptionParamSetOID = encryptionParamSetOID; + } + + public GOST3410ParameterSpec( + String keyParamSetID, + String digestParamSetOID) + { + this(keyParamSetID, digestParamSetOID, null); + } + + public GOST3410ParameterSpec( + String keyParamSetID) + { + this(keyParamSetID, CryptoProObjectIdentifiers.gostR3411_94_CryptoProParamSet.getId(), null); + } + + public GOST3410ParameterSpec( + GOST3410PublicKeyParameterSetSpec spec) + { + this.keyParameters = spec; + this.digestParamSetOID = CryptoProObjectIdentifiers.gostR3411_94_CryptoProParamSet.getId(); + this.encryptionParamSetOID = null; + } + + public String getPublicKeyParamSetOID() + { + return this.keyParamSetOID; + } + + public GOST3410PublicKeyParameterSetSpec getPublicKeyParameters() + { + return keyParameters; + } + + public String getDigestParamSetOID() + { + return this.digestParamSetOID; + } + + public String getEncryptionParamSetOID() + { + return this.encryptionParamSetOID; + } + + public boolean equals(Object o) + { + if (o instanceof GOST3410ParameterSpec) + { + GOST3410ParameterSpec other = (GOST3410ParameterSpec)o; + + return this.keyParameters.equals(other.keyParameters) + && this.digestParamSetOID.equals(other.digestParamSetOID) + && (this.encryptionParamSetOID == other.encryptionParamSetOID + || (this.encryptionParamSetOID != null && this.encryptionParamSetOID.equals(other.encryptionParamSetOID))); + } + + return false; + } + + public int hashCode() + { + return this.keyParameters.hashCode() ^ this.digestParamSetOID.hashCode() + ^ (this.encryptionParamSetOID != null ? this.encryptionParamSetOID.hashCode() : 0); + } + + public static GOST3410ParameterSpec fromPublicKeyAlg( + GOST3410PublicKeyAlgParameters params) + { + if (params.getEncryptionParamSet() != null) + { + return new GOST3410ParameterSpec(params.getPublicKeyParamSet().getId(), params.getDigestParamSet().getId(), params.getEncryptionParamSet().getId()); + } + else + { + return new GOST3410ParameterSpec(params.getPublicKeyParamSet().getId(), params.getDigestParamSet().getId()); + } + } +} diff --git a/prov/src/main/java/org/spongycastle/jce/spec/GOST3410PrivateKeySpec.java b/prov/src/main/java/org/spongycastle/jce/spec/GOST3410PrivateKeySpec.java new file mode 100644 index 00000000..42822146 --- /dev/null +++ b/prov/src/main/java/org/spongycastle/jce/spec/GOST3410PrivateKeySpec.java @@ -0,0 +1,70 @@ +package org.spongycastle.jce.spec; + +import java.math.BigInteger; +import java.security.spec.KeySpec; + +/** + * This class specifies a GOST3410-94 private key with its associated parameters. + */ + +public class GOST3410PrivateKeySpec + implements KeySpec +{ + private BigInteger x; + private BigInteger p; + private BigInteger q; + private BigInteger a; + + /** + * Creates a new GOST3410PrivateKeySpec with the specified parameter values. + * + * @param x the private key. + * @param p the prime. + * @param q the sub-prime. + * @param a the base. + */ + public GOST3410PrivateKeySpec(BigInteger x, BigInteger p, BigInteger q, + BigInteger a) + { + this.x = x; + this.p = p; + this.q = q; + this.a = a; + } + + /** + * Returns the private key <code>x</code>. + * @return the private key <code>x</code>. + */ + public BigInteger getX() + { + return this.x; + } + + /** + * Returns the prime <code>p</code>. + * @return the prime <code>p</code>. + */ + public BigInteger getP() + { + return this.p; + } + + /** + * Returns the sub-prime <code>q</code>. + * @return the sub-prime <code>q</code>. + */ + public BigInteger getQ() + { + return this.q; + } + + /** + * Returns the base <code>a</code>. + * @return the base <code>a</code>. + */ + public BigInteger getA() + { + return this.a; + } +} diff --git a/prov/src/main/java/org/spongycastle/jce/spec/GOST3410PublicKeyParameterSetSpec.java b/prov/src/main/java/org/spongycastle/jce/spec/GOST3410PublicKeyParameterSetSpec.java new file mode 100644 index 00000000..0b7af57e --- /dev/null +++ b/prov/src/main/java/org/spongycastle/jce/spec/GOST3410PublicKeyParameterSetSpec.java @@ -0,0 +1,78 @@ +package org.spongycastle.jce.spec; + +import java.math.BigInteger; + +/** + * ParameterSpec for a GOST 3410-94 key parameters. + */ +public class GOST3410PublicKeyParameterSetSpec +{ + private BigInteger p; + private BigInteger q; + private BigInteger a; + + /** + * Creates a new GOST3410ParameterSpec with the specified parameter values. + * + * @param p the prime. + * @param q the sub-prime. + * @param a the base. + */ + public GOST3410PublicKeyParameterSetSpec( + BigInteger p, + BigInteger q, + BigInteger a) + { + this.p = p; + this.q = q; + this.a = a; + } + + /** + * Returns the prime <code>p</code>. + * + * @return the prime <code>p</code>. + */ + public BigInteger getP() + { + return this.p; + } + + /** + * Returns the sub-prime <code>q</code>. + * + * @return the sub-prime <code>q</code>. + */ + public BigInteger getQ() + { + return this.q; + } + + /** + * Returns the base <code>a</code>. + * + * @return the base <code>a</code>. + */ + public BigInteger getA() + { + return this.a; + } + + public boolean equals( + Object o) + { + if (o instanceof GOST3410PublicKeyParameterSetSpec) + { + GOST3410PublicKeyParameterSetSpec other = (GOST3410PublicKeyParameterSetSpec)o; + + return this.a.equals(other.a) && this.p.equals(other.p) && this.q.equals(other.q); + } + + return false; + } + + public int hashCode() + { + return a.hashCode() ^ p.hashCode() ^ q.hashCode(); + } +} diff --git a/prov/src/main/java/org/spongycastle/jce/spec/GOST3410PublicKeySpec.java b/prov/src/main/java/org/spongycastle/jce/spec/GOST3410PublicKeySpec.java new file mode 100644 index 00000000..a16d36ce --- /dev/null +++ b/prov/src/main/java/org/spongycastle/jce/spec/GOST3410PublicKeySpec.java @@ -0,0 +1,78 @@ +package org.spongycastle.jce.spec; + +import java.math.BigInteger; +import java.security.spec.KeySpec; + +/** + * This class specifies a GOST3410-94 public key with its associated parameters. + */ + +public class GOST3410PublicKeySpec + implements KeySpec +{ + + private BigInteger y; + private BigInteger p; + private BigInteger q; + private BigInteger a; + + /** + * Creates a new GOST3410PublicKeySpec with the specified parameter values. + * + * @param y the public key. + * @param p the prime. + * @param q the sub-prime. + * @param a the base. + */ + public GOST3410PublicKeySpec( + BigInteger y, + BigInteger p, + BigInteger q, + BigInteger a) + { + this.y = y; + this.p = p; + this.q = q; + this.a = a; + } + + /** + * Returns the public key <code>y</code>. + * + * @return the public key <code>y</code>. + */ + public BigInteger getY() + { + return this.y; + } + + /** + * Returns the prime <code>p</code>. + * + * @return the prime <code>p</code>. + */ + public BigInteger getP() + { + return this.p; + } + + /** + * Returns the sub-prime <code>q</code>. + * + * @return the sub-prime <code>q</code>. + */ + public BigInteger getQ() + { + return this.q; + } + + /** + * Returns the base <code>g</code>. + * + * @return the base <code>g</code>. + */ + public BigInteger getA() + { + return this.a; + } +} diff --git a/prov/src/main/java/org/spongycastle/jce/spec/IEKeySpec.java b/prov/src/main/java/org/spongycastle/jce/spec/IEKeySpec.java new file mode 100644 index 00000000..050760f7 --- /dev/null +++ b/prov/src/main/java/org/spongycastle/jce/spec/IEKeySpec.java @@ -0,0 +1,70 @@ +package org.spongycastle.jce.spec; + +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.spec.KeySpec; + +import org.spongycastle.jce.interfaces.IESKey; + +/** + * key pair for use with an integrated encryptor - together + * they provide what's required to generate the message. + */ +public class IEKeySpec + implements KeySpec, IESKey +{ + private PublicKey pubKey; + private PrivateKey privKey; + + /** + * @param privKey our private key. + * @param pubKey the public key of the sender/recipient. + */ + public IEKeySpec( + PrivateKey privKey, + PublicKey pubKey) + { + this.privKey = privKey; + this.pubKey = pubKey; + } + + /** + * return the intended recipient's/sender's public key. + */ + public PublicKey getPublic() + { + return pubKey; + } + + /** + * return the local private key. + */ + public PrivateKey getPrivate() + { + return privKey; + } + + /** + * return "IES" + */ + public String getAlgorithm() + { + return "IES"; + } + + /** + * return null + */ + public String getFormat() + { + return null; + } + + /** + * returns null + */ + public byte[] getEncoded() + { + return null; + } +} diff --git a/prov/src/main/java/org/spongycastle/jce/spec/IESParameterSpec.java b/prov/src/main/java/org/spongycastle/jce/spec/IESParameterSpec.java new file mode 100644 index 00000000..d3fc0835 --- /dev/null +++ b/prov/src/main/java/org/spongycastle/jce/spec/IESParameterSpec.java @@ -0,0 +1,135 @@ +package org.spongycastle.jce.spec; + +import java.security.spec.AlgorithmParameterSpec; + +import org.spongycastle.util.Arrays; + +/** + * Parameter spec for an integrated encryptor, as in IEEE P1363a + */ +public class IESParameterSpec + implements AlgorithmParameterSpec +{ + private byte[] derivation; + private byte[] encoding; + private int macKeySize; + private int cipherKeySize; + private byte[] nonce; + + + /** + * Set the IES engine parameters. + * + * @param derivation the optional derivation vector for the KDF. + * @param encoding the optional encoding vector for the KDF. + * @param macKeySize the key size (in bits) for the MAC. + */ + public IESParameterSpec( + byte[] derivation, + byte[] encoding, + int macKeySize) + { + this(derivation, encoding, macKeySize, -1); + } + + + /** + * Set the IES engine parameters. + * + * @param derivation the optional derivation vector for the KDF. + * @param encoding the optional encoding vector for the KDF. + * @param macKeySize the key size (in bits) for the MAC. + * @param cipherKeySize the key size (in bits) for the block cipher. + */ + public IESParameterSpec( + byte[] derivation, + byte[] encoding, + int macKeySize, + int cipherKeySize) + { + this(derivation, encoding, macKeySize, cipherKeySize, null); + } + + /** + * Set the IES engine parameters. + * + * @param derivation the optional derivation vector for the KDF. + * @param encoding the optional encoding vector for the KDF. + * @param macKeySize the key size (in bits) for the MAC. + * @param cipherKeySize the key size (in bits) for the block cipher. + * @param nonce an IV to use initialising the block cipher. + */ + public IESParameterSpec( + byte[] derivation, + byte[] encoding, + int macKeySize, + int cipherKeySize, + byte[] nonce) + { + if (derivation != null) + { + this.derivation = new byte[derivation.length]; + System.arraycopy(derivation, 0, this.derivation, 0, derivation.length); + } + else + { + this.derivation = null; + } + + if (encoding != null) + { + this.encoding = new byte[encoding.length]; + System.arraycopy(encoding, 0, this.encoding, 0, encoding.length); + } + else + { + this.encoding = null; + } + + this.macKeySize = macKeySize; + this.cipherKeySize = cipherKeySize; + this.nonce = Arrays.clone(nonce); + } + + /** + * return the derivation vector. + */ + public byte[] getDerivationV() + { + return Arrays.clone(derivation); + } + + /** + * return the encoding vector. + */ + public byte[] getEncodingV() + { + return Arrays.clone(encoding); + } + + /** + * return the key size in bits for the MAC used with the message + */ + public int getMacKeySize() + { + return macKeySize; + } + + /** + * return the key size in bits for the block cipher used with the message + */ + public int getCipherKeySize() + { + return cipherKeySize; + } + + /** + * Return the nonce (IV) value to be associated with message. + * + * @return block cipher IV for message. + */ + public byte[] getNonce() + { + return Arrays.clone(nonce); + } +} diff --git a/prov/src/main/java/org/spongycastle/jce/spec/MQVPrivateKeySpec.java b/prov/src/main/java/org/spongycastle/jce/spec/MQVPrivateKeySpec.java new file mode 100644 index 00000000..84172600 --- /dev/null +++ b/prov/src/main/java/org/spongycastle/jce/spec/MQVPrivateKeySpec.java @@ -0,0 +1,93 @@ +package org.spongycastle.jce.spec; + +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.spec.KeySpec; + +import org.spongycastle.jce.interfaces.MQVPrivateKey; + +/** + * Static/ephemeral private key (pair) for use with ECMQV key agreement + * (Optionally provides the ephemeral public key) + */ +public class MQVPrivateKeySpec + implements KeySpec, MQVPrivateKey +{ + private PrivateKey staticPrivateKey; + private PrivateKey ephemeralPrivateKey; + private PublicKey ephemeralPublicKey; + + /** + * @param staticPrivateKey the static private key. + * @param ephemeralPrivateKey the ephemeral private key. + */ + public MQVPrivateKeySpec( + PrivateKey staticPrivateKey, + PrivateKey ephemeralPrivateKey) + { + this(staticPrivateKey, ephemeralPrivateKey, null); + } + + /** + * @param staticPrivateKey the static private key. + * @param ephemeralPrivateKey the ephemeral private key. + * @param ephemeralPublicKey the ephemeral public key (may be null). + */ + public MQVPrivateKeySpec( + PrivateKey staticPrivateKey, + PrivateKey ephemeralPrivateKey, + PublicKey ephemeralPublicKey) + { + this.staticPrivateKey = staticPrivateKey; + this.ephemeralPrivateKey = ephemeralPrivateKey; + this.ephemeralPublicKey = ephemeralPublicKey; + } + + /** + * return the static private key + */ + public PrivateKey getStaticPrivateKey() + { + return staticPrivateKey; + } + + /** + * return the ephemeral private key + */ + public PrivateKey getEphemeralPrivateKey() + { + return ephemeralPrivateKey; + } + + /** + * return the ephemeral public key (may be null) + */ + public PublicKey getEphemeralPublicKey() + { + return ephemeralPublicKey; + } + + /** + * return "ECMQV" + */ + public String getAlgorithm() + { + return "ECMQV"; + } + + /** + * return null + */ + public String getFormat() + { + return null; + } + + /** + * returns null + */ + public byte[] getEncoded() + { + return null; + } +} diff --git a/prov/src/main/java/org/spongycastle/jce/spec/MQVPublicKeySpec.java b/prov/src/main/java/org/spongycastle/jce/spec/MQVPublicKeySpec.java new file mode 100644 index 00000000..f32c46fd --- /dev/null +++ b/prov/src/main/java/org/spongycastle/jce/spec/MQVPublicKeySpec.java @@ -0,0 +1,68 @@ +package org.spongycastle.jce.spec; + +import java.security.PublicKey; +import java.security.spec.KeySpec; + +import org.spongycastle.jce.interfaces.MQVPublicKey; + +/** + * Static/ephemeral public key pair for use with ECMQV key agreement + */ +public class MQVPublicKeySpec + implements KeySpec, MQVPublicKey +{ + private PublicKey staticKey; + private PublicKey ephemeralKey; + + /** + * @param staticKey the static public key. + * @param ephemeralKey the ephemeral public key. + */ + public MQVPublicKeySpec( + PublicKey staticKey, + PublicKey ephemeralKey) + { + this.staticKey = staticKey; + this.ephemeralKey = ephemeralKey; + } + + /** + * return the static public key + */ + public PublicKey getStaticKey() + { + return staticKey; + } + + /** + * return the ephemeral public key + */ + public PublicKey getEphemeralKey() + { + return ephemeralKey; + } + + /** + * return "ECMQV" + */ + public String getAlgorithm() + { + return "ECMQV"; + } + + /** + * return null + */ + public String getFormat() + { + return null; + } + + /** + * returns null + */ + public byte[] getEncoded() + { + return null; + } +} diff --git a/prov/src/main/java/org/spongycastle/jce/spec/RepeatedSecretKeySpec.java b/prov/src/main/java/org/spongycastle/jce/spec/RepeatedSecretKeySpec.java new file mode 100644 index 00000000..d3012ecd --- /dev/null +++ b/prov/src/main/java/org/spongycastle/jce/spec/RepeatedSecretKeySpec.java @@ -0,0 +1,17 @@ +package org.spongycastle.jce.spec; + +/** + * A simple object to indicate that a symmetric cipher should reuse the + * last key provided. + * @deprecated use super class org.spongycastle.jcajce.spec.RepeatedSecretKeySpec + */ +public class RepeatedSecretKeySpec + extends org.spongycastle.jcajce.spec.RepeatedSecretKeySpec +{ + private String algorithm; + + public RepeatedSecretKeySpec(String algorithm) + { + super(algorithm); + } +} |