Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'prov/src/main/java/org/bouncycastle/pqc/jcajce/provider/rainbow')
-rw-r--r--prov/src/main/java/org/bouncycastle/pqc/jcajce/provider/rainbow/BCRainbowPrivateKey.java243
-rw-r--r--prov/src/main/java/org/bouncycastle/pqc/jcajce/provider/rainbow/BCRainbowPublicKey.java170
-rw-r--r--prov/src/main/java/org/bouncycastle/pqc/jcajce/provider/rainbow/RainbowKeyFactorySpi.java236
-rw-r--r--prov/src/main/java/org/bouncycastle/pqc/jcajce/provider/rainbow/RainbowKeyPairGeneratorSpi.java72
-rw-r--r--prov/src/main/java/org/bouncycastle/pqc/jcajce/provider/rainbow/RainbowKeysToParams.java49
-rw-r--r--prov/src/main/java/org/bouncycastle/pqc/jcajce/provider/rainbow/SignatureSpi.java164
6 files changed, 0 insertions, 934 deletions
diff --git a/prov/src/main/java/org/bouncycastle/pqc/jcajce/provider/rainbow/BCRainbowPrivateKey.java b/prov/src/main/java/org/bouncycastle/pqc/jcajce/provider/rainbow/BCRainbowPrivateKey.java
deleted file mode 100644
index 62ea4e2b..00000000
--- a/prov/src/main/java/org/bouncycastle/pqc/jcajce/provider/rainbow/BCRainbowPrivateKey.java
+++ /dev/null
@@ -1,243 +0,0 @@
-package org.bouncycastle.pqc.jcajce.provider.rainbow;
-
-import java.io.IOException;
-import java.security.PrivateKey;
-import java.util.Arrays;
-
-import org.bouncycastle.asn1.DERNull;
-import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
-import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
-import org.bouncycastle.pqc.asn1.PQCObjectIdentifiers;
-import org.bouncycastle.pqc.asn1.RainbowPrivateKey;
-import org.bouncycastle.pqc.crypto.rainbow.Layer;
-import org.bouncycastle.pqc.crypto.rainbow.RainbowPrivateKeyParameters;
-import org.bouncycastle.pqc.crypto.rainbow.util.RainbowUtil;
-import org.bouncycastle.pqc.jcajce.spec.RainbowPrivateKeySpec;
-
-/**
- * The Private key in Rainbow consists of the linear affine maps L1, L2 and the
- * map F, consisting of quadratic polynomials. In this implementation, we
- * denote: L1 = A1*x + b1 L2 = A2*x + b2
- * <p/>
- * The coefficients of the polynomials in F are stored in 3-dimensional arrays
- * per layer. The indices of these arrays denote the polynomial, and the
- * variables.
- * <p/>
- * More detailed information about the private key is to be found in the paper
- * of Jintai Ding, Dieter Schmidt: Rainbow, a New Multivariable Polynomial
- * Signature Scheme. ACNS 2005: 164-175 (http://dx.doi.org/10.1007/11496137_12)
- */
-public class BCRainbowPrivateKey
- implements PrivateKey
-{
- private static final long serialVersionUID = 1L;
-
- // the inverse of L1
- private short[][] A1inv;
-
- // translation vector element of L1
- private short[] b1;
-
- // the inverse of L2
- private short[][] A2inv;
-
- // translation vector of L2
- private short[] b2;
-
- /*
- * components of F
- */
- private Layer[] layers;
-
- // set of vinegar vars per layer.
- private int[] vi;
-
-
- /**
- * Constructor.
- *
- * @param A1inv
- * @param b1
- * @param A2inv
- * @param b2
- * @param layers
- */
- public BCRainbowPrivateKey(short[][] A1inv, short[] b1, short[][] A2inv,
- short[] b2, int[] vi, Layer[] layers)
- {
- this.A1inv = A1inv;
- this.b1 = b1;
- this.A2inv = A2inv;
- this.b2 = b2;
- this.vi = vi;
- this.layers = layers;
- }
-
- /**
- * Constructor (used by the {@link RainbowKeyFactorySpi}).
- *
- * @param keySpec a {@link RainbowPrivateKeySpec}
- */
- public BCRainbowPrivateKey(RainbowPrivateKeySpec keySpec)
- {
- this(keySpec.getInvA1(), keySpec.getB1(), keySpec.getInvA2(), keySpec
- .getB2(), keySpec.getVi(), keySpec.getLayers());
- }
-
- public BCRainbowPrivateKey(
- RainbowPrivateKeyParameters params)
- {
- this(params.getInvA1(), params.getB1(), params.getInvA2(), params.getB2(), params.getVi(), params.getLayers());
- }
-
- /**
- * Getter for the inverse matrix of A1.
- *
- * @return the A1inv inverse
- */
- public short[][] getInvA1()
- {
- return this.A1inv;
- }
-
- /**
- * Getter for the translation part of the private quadratic map L1.
- *
- * @return b1 the translation part of L1
- */
- public short[] getB1()
- {
- return this.b1;
- }
-
- /**
- * Getter for the translation part of the private quadratic map L2.
- *
- * @return b2 the translation part of L2
- */
- public short[] getB2()
- {
- return this.b2;
- }
-
- /**
- * Getter for the inverse matrix of A2
- *
- * @return the A2inv
- */
- public short[][] getInvA2()
- {
- return this.A2inv;
- }
-
- /**
- * Returns the layers contained in the private key
- *
- * @return layers
- */
- public Layer[] getLayers()
- {
- return this.layers;
- }
-
- /**
- * Returns the array of vi-s
- *
- * @return the vi
- */
- public int[] getVi()
- {
- return vi;
- }
-
- /**
- * Compare this Rainbow private key with another object.
- *
- * @param other the other object
- * @return the result of the comparison
- */
- public boolean equals(Object other)
- {
- if (other == null || !(other instanceof BCRainbowPrivateKey))
- {
- return false;
- }
- BCRainbowPrivateKey otherKey = (BCRainbowPrivateKey)other;
-
- boolean eq = true;
- // compare using shortcut rule ( && instead of &)
- eq = eq && RainbowUtil.equals(A1inv, otherKey.getInvA1());
- eq = eq && RainbowUtil.equals(A2inv, otherKey.getInvA2());
- eq = eq && RainbowUtil.equals(b1, otherKey.getB1());
- eq = eq && RainbowUtil.equals(b2, otherKey.getB2());
- eq = eq && Arrays.equals(vi, otherKey.getVi());
- if (layers.length != otherKey.getLayers().length)
- {
- return false;
- }
- for (int i = layers.length - 1; i >= 0; i--)
- {
- eq &= layers[i].equals(otherKey.getLayers()[i]);
- }
- return eq;
- }
-
- public int hashCode()
- {
- int hash = layers.length;
-
- hash = hash * 37 + org.bouncycastle.util.Arrays.hashCode(A1inv);
- hash = hash * 37 + org.bouncycastle.util.Arrays.hashCode(b1);
- hash = hash * 37 + org.bouncycastle.util.Arrays.hashCode(A2inv);
- hash = hash * 37 + org.bouncycastle.util.Arrays.hashCode(b2);
- hash = hash * 37 + org.bouncycastle.util.Arrays.hashCode(vi);
-
- for (int i = layers.length - 1; i >= 0; i--)
- {
- hash = hash * 37 + layers[i].hashCode();
- }
-
-
- return hash;
- }
-
- /**
- * @return name of the algorithm - "Rainbow"
- */
- public final String getAlgorithm()
- {
- return "Rainbow";
- }
-
- public byte[] getEncoded()
- {
- RainbowPrivateKey privateKey = new RainbowPrivateKey(A1inv, b1, A2inv, b2, vi, layers);
-
- PrivateKeyInfo pki;
- try
- {
- AlgorithmIdentifier algorithmIdentifier = new AlgorithmIdentifier(PQCObjectIdentifiers.rainbow, DERNull.INSTANCE);
- pki = new PrivateKeyInfo(algorithmIdentifier, privateKey);
- }
- catch (IOException e)
- {
- e.printStackTrace();
- return null;
- }
- try
- {
- byte[] encoded = pki.getEncoded();
- return encoded;
- }
- catch (IOException e)
- {
- e.printStackTrace();
- return null;
- }
- }
-
- public String getFormat()
- {
- return "PKCS#8";
- }
-}
diff --git a/prov/src/main/java/org/bouncycastle/pqc/jcajce/provider/rainbow/BCRainbowPublicKey.java b/prov/src/main/java/org/bouncycastle/pqc/jcajce/provider/rainbow/BCRainbowPublicKey.java
deleted file mode 100644
index 453cb615..00000000
--- a/prov/src/main/java/org/bouncycastle/pqc/jcajce/provider/rainbow/BCRainbowPublicKey.java
+++ /dev/null
@@ -1,170 +0,0 @@
-package org.bouncycastle.pqc.jcajce.provider.rainbow;
-
-import java.security.PublicKey;
-
-import org.bouncycastle.asn1.DERNull;
-import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
-import org.bouncycastle.pqc.asn1.PQCObjectIdentifiers;
-import org.bouncycastle.pqc.asn1.RainbowPublicKey;
-import org.bouncycastle.pqc.crypto.rainbow.RainbowParameters;
-import org.bouncycastle.pqc.crypto.rainbow.RainbowPublicKeyParameters;
-import org.bouncycastle.pqc.crypto.rainbow.util.RainbowUtil;
-import org.bouncycastle.pqc.jcajce.provider.util.KeyUtil;
-import org.bouncycastle.pqc.jcajce.spec.RainbowPublicKeySpec;
-import org.bouncycastle.util.Arrays;
-
-/**
- * This class implements CipherParameters and PublicKey.
- * <p/>
- * The public key in Rainbow consists of n - v1 polynomial components of the
- * private key's F and the field structure of the finite field k.
- * <p/>
- * The quadratic (or mixed) coefficients of the polynomials from the public key
- * are stored in the 2-dimensional array in lexicographical order, requiring n *
- * (n + 1) / 2 entries for each polynomial. The singular terms are stored in a
- * 2-dimensional array requiring n entries per polynomial, the scalar term of
- * each polynomial is stored in a 1-dimensional array.
- * <p/>
- * More detailed information on the public key is to be found in the paper of
- * Jintai Ding, Dieter Schmidt: Rainbow, a New Multivariable Polynomial
- * Signature Scheme. ACNS 2005: 164-175 (http://dx.doi.org/10.1007/11496137_12)
- */
-public class BCRainbowPublicKey
- implements PublicKey
-{
- private static final long serialVersionUID = 1L;
-
- private short[][] coeffquadratic;
- private short[][] coeffsingular;
- private short[] coeffscalar;
- private int docLength; // length of possible document to sign
-
- private RainbowParameters rainbowParams;
-
- /**
- * Constructor
- *
- * @param docLength
- * @param coeffQuadratic
- * @param coeffSingular
- * @param coeffScalar
- */
- public BCRainbowPublicKey(int docLength,
- short[][] coeffQuadratic, short[][] coeffSingular,
- short[] coeffScalar)
- {
- this.docLength = docLength;
- this.coeffquadratic = coeffQuadratic;
- this.coeffsingular = coeffSingular;
- this.coeffscalar = coeffScalar;
- }
-
- /**
- * Constructor (used by the {@link RainbowKeyFactorySpi}).
- *
- * @param keySpec a {@link RainbowPublicKeySpec}
- */
- public BCRainbowPublicKey(RainbowPublicKeySpec keySpec)
- {
- this(keySpec.getDocLength(), keySpec.getCoeffQuadratic(), keySpec
- .getCoeffSingular(), keySpec.getCoeffScalar());
- }
-
- public BCRainbowPublicKey(
- RainbowPublicKeyParameters params)
- {
- this(params.getDocLength(), params.getCoeffQuadratic(), params.getCoeffSingular(), params.getCoeffScalar());
- }
-
- /**
- * @return the docLength
- */
- public int getDocLength()
- {
- return this.docLength;
- }
-
- /**
- * @return the coeffQuadratic
- */
- public short[][] getCoeffQuadratic()
- {
- return coeffquadratic;
- }
-
- /**
- * @return the coeffSingular
- */
- public short[][] getCoeffSingular()
- {
- short[][] copy = new short[coeffsingular.length][];
-
- for (int i = 0; i != coeffsingular.length; i++)
- {
- copy[i] = Arrays.clone(coeffsingular[i]);
- }
-
- return copy;
- }
-
-
- /**
- * @return the coeffScalar
- */
- public short[] getCoeffScalar()
- {
- return Arrays.clone(coeffscalar);
- }
-
- /**
- * Compare this Rainbow public key with another object.
- *
- * @param other the other object
- * @return the result of the comparison
- */
- public boolean equals(Object other)
- {
- if (other == null || !(other instanceof BCRainbowPublicKey))
- {
- return false;
- }
- BCRainbowPublicKey otherKey = (BCRainbowPublicKey)other;
-
- return docLength == otherKey.getDocLength()
- && RainbowUtil.equals(coeffquadratic, otherKey.getCoeffQuadratic())
- && RainbowUtil.equals(coeffsingular, otherKey.getCoeffSingular())
- && RainbowUtil.equals(coeffscalar, otherKey.getCoeffScalar());
- }
-
- public int hashCode()
- {
- int hash = docLength;
-
- hash = hash * 37 + Arrays.hashCode(coeffquadratic);
- hash = hash * 37 + Arrays.hashCode(coeffsingular);
- hash = hash * 37 + Arrays.hashCode(coeffscalar);
-
- return hash;
- }
-
- /**
- * @return name of the algorithm - "Rainbow"
- */
- public final String getAlgorithm()
- {
- return "Rainbow";
- }
-
- public String getFormat()
- {
- return "X.509";
- }
-
- public byte[] getEncoded()
- {
- RainbowPublicKey key = new RainbowPublicKey(docLength, coeffquadratic, coeffsingular, coeffscalar);
- AlgorithmIdentifier algorithmIdentifier = new AlgorithmIdentifier(PQCObjectIdentifiers.rainbow, DERNull.INSTANCE);
-
- return KeyUtil.getEncodedSubjectPublicKeyInfo(algorithmIdentifier, key);
- }
-}
diff --git a/prov/src/main/java/org/bouncycastle/pqc/jcajce/provider/rainbow/RainbowKeyFactorySpi.java b/prov/src/main/java/org/bouncycastle/pqc/jcajce/provider/rainbow/RainbowKeyFactorySpi.java
deleted file mode 100644
index c08fb8b0..00000000
--- a/prov/src/main/java/org/bouncycastle/pqc/jcajce/provider/rainbow/RainbowKeyFactorySpi.java
+++ /dev/null
@@ -1,236 +0,0 @@
-package org.bouncycastle.pqc.jcajce.provider.rainbow;
-
-import java.io.IOException;
-import java.security.InvalidKeyException;
-import java.security.Key;
-import java.security.KeyFactorySpi;
-import java.security.PrivateKey;
-import java.security.PublicKey;
-import java.security.spec.InvalidKeySpecException;
-import java.security.spec.KeySpec;
-import java.security.spec.PKCS8EncodedKeySpec;
-import java.security.spec.X509EncodedKeySpec;
-
-import org.bouncycastle.asn1.ASN1Primitive;
-import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
-import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
-import org.bouncycastle.jcajce.provider.util.AsymmetricKeyInfoConverter;
-import org.bouncycastle.pqc.asn1.RainbowPrivateKey;
-import org.bouncycastle.pqc.asn1.RainbowPublicKey;
-import org.bouncycastle.pqc.jcajce.spec.RainbowPrivateKeySpec;
-import org.bouncycastle.pqc.jcajce.spec.RainbowPublicKeySpec;
-
-
-/**
- * This class transforms Rainbow keys and Rainbow key specifications.
- *
- * @see BCRainbowPublicKey
- * @see RainbowPublicKeySpec
- * @see BCRainbowPrivateKey
- * @see RainbowPrivateKeySpec
- */
-public class RainbowKeyFactorySpi
- extends KeyFactorySpi
- implements AsymmetricKeyInfoConverter
-{
- /**
- * Converts, if possible, a key specification into a
- * {@link BCRainbowPrivateKey}. Currently, the following key specifications
- * are supported: {@link RainbowPrivateKeySpec}, {@link PKCS8EncodedKeySpec}.
- * <p/>
- * <p/>
- * <p/>
- * The ASN.1 definition of the key structure is
- * <p/>
- * <pre>
- * RainbowPrivateKey ::= SEQUENCE {
- * oid OBJECT IDENTIFIER -- OID identifying the algorithm
- * A1inv SEQUENCE OF OCTET STRING -- inversed matrix of L1
- * b1 OCTET STRING -- translation vector of L1
- * A2inv SEQUENCE OF OCTET STRING -- inversed matrix of L2
- * b2 OCTET STRING -- translation vector of L2
- * vi OCTET STRING -- num of elmts in each Set S
- * layers SEQUENCE OF Layer -- layers of F
- * }
- *
- * Layer ::= SEQUENCE OF Poly
- * Poly ::= SEQUENCE {
- * alpha SEQUENCE OF OCTET STRING
- * beta SEQUENCE OF OCTET STRING
- * gamma OCTET STRING
- * eta OCTET
- * }
- * </pre>
- * <p/>
- * <p/>
- *
- * @param keySpec the key specification
- * @return the Rainbow private key
- * @throws InvalidKeySpecException if the KeySpec is not supported.
- */
- public PrivateKey engineGeneratePrivate(KeySpec keySpec)
- throws InvalidKeySpecException
- {
- if (keySpec instanceof RainbowPrivateKeySpec)
- {
- return new BCRainbowPrivateKey((RainbowPrivateKeySpec)keySpec);
- }
- else if (keySpec instanceof PKCS8EncodedKeySpec)
- {
- // get the DER-encoded Key according to PKCS#8 from the spec
- byte[] encKey = ((PKCS8EncodedKeySpec)keySpec).getEncoded();
-
- try
- {
- return generatePrivate(PrivateKeyInfo.getInstance(ASN1Primitive.fromByteArray(encKey)));
- }
- catch (Exception e)
- {
- throw new InvalidKeySpecException(e.toString());
- }
- }
-
- throw new InvalidKeySpecException("Unsupported key specification: "
- + keySpec.getClass() + ".");
- }
-
- /**
- * Converts, if possible, a key specification into a
- * {@link BCRainbowPublicKey}. Currently, the following key specifications are
- * supported:{@link X509EncodedKeySpec}.
- * <p/>
- * <p/>
- * <p/>
- * The ASN.1 definition of a public key's structure is
- * <p/>
- * <pre>
- * RainbowPublicKey ::= SEQUENCE {
- * oid OBJECT IDENTIFIER -- OID identifying the algorithm
- * docLength Integer -- length of signable msg
- * coeffquadratic SEQUENCE OF OCTET STRING -- quadratic (mixed) coefficients
- * coeffsingular SEQUENCE OF OCTET STRING -- singular coefficients
- * coeffscalar OCTET STRING -- scalar coefficients
- * }
- * </pre>
- * <p/>
- * <p/>
- *
- * @param keySpec the key specification
- * @return the Rainbow public key
- * @throws InvalidKeySpecException if the KeySpec is not supported.
- */
- public PublicKey engineGeneratePublic(KeySpec keySpec)
- throws InvalidKeySpecException
- {
- if (keySpec instanceof RainbowPublicKeySpec)
- {
- return new BCRainbowPublicKey((RainbowPublicKeySpec)keySpec);
- }
- else if (keySpec instanceof X509EncodedKeySpec)
- {
- // get the DER-encoded Key according to X.509 from the spec
- byte[] encKey = ((X509EncodedKeySpec)keySpec).getEncoded();
-
- // decode the SubjectPublicKeyInfo data structure to the pki object
- try
- {
- return generatePublic(SubjectPublicKeyInfo.getInstance(encKey));
- }
- catch (Exception e)
- {
- throw new InvalidKeySpecException(e.toString());
- }
- }
-
- throw new InvalidKeySpecException("Unknown key specification: " + keySpec + ".");
- }
-
- /**
- * Converts a given key into a key specification, if possible. Currently the
- * following specs are supported:
- * <ul>
- * <li>for RainbowPublicKey: X509EncodedKeySpec, RainbowPublicKeySpec
- * <li>for RainbowPrivateKey: PKCS8EncodedKeySpec, RainbowPrivateKeySpec
- * </ul>
- *
- * @param key the key
- * @param keySpec the key specification
- * @return the specification of the CMSS key
- * @throws InvalidKeySpecException if the key type or key specification is not supported.
- */
- public final KeySpec engineGetKeySpec(Key key, Class keySpec)
- throws InvalidKeySpecException
- {
- if (key instanceof BCRainbowPrivateKey)
- {
- if (PKCS8EncodedKeySpec.class.isAssignableFrom(keySpec))
- {
- return new PKCS8EncodedKeySpec(key.getEncoded());
- }
- else if (RainbowPrivateKeySpec.class.isAssignableFrom(keySpec))
- {
- BCRainbowPrivateKey privKey = (BCRainbowPrivateKey)key;
- return new RainbowPrivateKeySpec(privKey.getInvA1(), privKey
- .getB1(), privKey.getInvA2(), privKey.getB2(), privKey
- .getVi(), privKey.getLayers());
- }
- }
- else if (key instanceof BCRainbowPublicKey)
- {
- if (X509EncodedKeySpec.class.isAssignableFrom(keySpec))
- {
- return new X509EncodedKeySpec(key.getEncoded());
- }
- else if (RainbowPublicKeySpec.class.isAssignableFrom(keySpec))
- {
- BCRainbowPublicKey pubKey = (BCRainbowPublicKey)key;
- return new RainbowPublicKeySpec(pubKey.getDocLength(), pubKey
- .getCoeffQuadratic(), pubKey.getCoeffSingular(), pubKey
- .getCoeffScalar());
- }
- }
- else
- {
- throw new InvalidKeySpecException("Unsupported key type: "
- + key.getClass() + ".");
- }
-
- throw new InvalidKeySpecException("Unknown key specification: "
- + keySpec + ".");
- }
-
- /**
- * Translates a key into a form known by the FlexiProvider. Currently the
- * following key types are supported: RainbowPrivateKey, RainbowPublicKey.
- *
- * @param key the key
- * @return a key of a known key type
- * @throws InvalidKeyException if the key is not supported.
- */
- public final Key engineTranslateKey(Key key)
- throws InvalidKeyException
- {
- if (key instanceof BCRainbowPrivateKey || key instanceof BCRainbowPublicKey)
- {
- return key;
- }
-
- throw new InvalidKeyException("Unsupported key type");
- }
-
- public PrivateKey generatePrivate(PrivateKeyInfo keyInfo)
- throws IOException
- {
- RainbowPrivateKey pKey = RainbowPrivateKey.getInstance(keyInfo.parsePrivateKey());
-
- return new BCRainbowPrivateKey(pKey.getInvA1(), pKey.getB1(), pKey.getInvA2(), pKey.getB2(), pKey.getVi(), pKey.getLayers());
- }
-
- public PublicKey generatePublic(SubjectPublicKeyInfo keyInfo)
- throws IOException
- {
- RainbowPublicKey pKey = RainbowPublicKey.getInstance(keyInfo.parsePublicKey());
-
- return new BCRainbowPublicKey(pKey.getDocLength(), pKey.getCoeffQuadratic(), pKey.getCoeffSingular(), pKey.getCoeffScalar());
- }
-}
diff --git a/prov/src/main/java/org/bouncycastle/pqc/jcajce/provider/rainbow/RainbowKeyPairGeneratorSpi.java b/prov/src/main/java/org/bouncycastle/pqc/jcajce/provider/rainbow/RainbowKeyPairGeneratorSpi.java
deleted file mode 100644
index e64d53be..00000000
--- a/prov/src/main/java/org/bouncycastle/pqc/jcajce/provider/rainbow/RainbowKeyPairGeneratorSpi.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package org.bouncycastle.pqc.jcajce.provider.rainbow;
-
-import java.security.InvalidAlgorithmParameterException;
-import java.security.KeyPair;
-import java.security.SecureRandom;
-import java.security.spec.AlgorithmParameterSpec;
-
-import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
-import org.bouncycastle.pqc.crypto.rainbow.RainbowKeyGenerationParameters;
-import org.bouncycastle.pqc.crypto.rainbow.RainbowKeyPairGenerator;
-import org.bouncycastle.pqc.crypto.rainbow.RainbowParameters;
-import org.bouncycastle.pqc.crypto.rainbow.RainbowPrivateKeyParameters;
-import org.bouncycastle.pqc.crypto.rainbow.RainbowPublicKeyParameters;
-import org.bouncycastle.pqc.jcajce.spec.RainbowParameterSpec;
-
-public class RainbowKeyPairGeneratorSpi
- extends java.security.KeyPairGenerator
-{
- RainbowKeyGenerationParameters param;
- RainbowKeyPairGenerator engine = new RainbowKeyPairGenerator();
- int strength = 1024;
- SecureRandom random = new SecureRandom();
- boolean initialised = false;
-
- public RainbowKeyPairGeneratorSpi()
- {
- super("Rainbow");
- }
-
- public void initialize(
- int strength,
- SecureRandom random)
- {
- this.strength = strength;
- this.random = random;
- }
-
- public void initialize(
- AlgorithmParameterSpec params,
- SecureRandom random)
- throws InvalidAlgorithmParameterException
- {
- if (!(params instanceof RainbowParameterSpec))
- {
- throw new InvalidAlgorithmParameterException("parameter object not a RainbowParameterSpec");
- }
- RainbowParameterSpec rainbowParams = (RainbowParameterSpec)params;
-
- param = new RainbowKeyGenerationParameters(random, new RainbowParameters(rainbowParams.getVi()));
-
- engine.init(param);
- initialised = true;
- }
-
- public KeyPair generateKeyPair()
- {
- if (!initialised)
- {
- param = new RainbowKeyGenerationParameters(random, new RainbowParameters(new RainbowParameterSpec().getVi()));
-
- engine.init(param);
- initialised = true;
- }
-
- AsymmetricCipherKeyPair pair = engine.generateKeyPair();
- RainbowPublicKeyParameters pub = (RainbowPublicKeyParameters)pair.getPublic();
- RainbowPrivateKeyParameters priv = (RainbowPrivateKeyParameters)pair.getPrivate();
-
- return new KeyPair(new BCRainbowPublicKey(pub),
- new BCRainbowPrivateKey(priv));
- }
-}
diff --git a/prov/src/main/java/org/bouncycastle/pqc/jcajce/provider/rainbow/RainbowKeysToParams.java b/prov/src/main/java/org/bouncycastle/pqc/jcajce/provider/rainbow/RainbowKeysToParams.java
deleted file mode 100644
index f5c573a4..00000000
--- a/prov/src/main/java/org/bouncycastle/pqc/jcajce/provider/rainbow/RainbowKeysToParams.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package org.bouncycastle.pqc.jcajce.provider.rainbow;
-
-import java.security.InvalidKeyException;
-import java.security.PrivateKey;
-import java.security.PublicKey;
-
-import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
-import org.bouncycastle.pqc.crypto.rainbow.RainbowPrivateKeyParameters;
-import org.bouncycastle.pqc.crypto.rainbow.RainbowPublicKeyParameters;
-
-
-/**
- * utility class for converting jce/jca Rainbow objects
- * objects into their org.bouncycastle.crypto counterparts.
- */
-
-public class RainbowKeysToParams
-{
- static public AsymmetricKeyParameter generatePublicKeyParameter(
- PublicKey key)
- throws InvalidKeyException
- {
- if (key instanceof BCRainbowPublicKey)
- {
- BCRainbowPublicKey k = (BCRainbowPublicKey)key;
-
- return new RainbowPublicKeyParameters(k.getDocLength(), k.getCoeffQuadratic(),
- k.getCoeffSingular(), k.getCoeffScalar());
- }
-
- throw new InvalidKeyException("can't identify Rainbow public key: " + key.getClass().getName());
- }
-
- static public AsymmetricKeyParameter generatePrivateKeyParameter(
- PrivateKey key)
- throws InvalidKeyException
- {
- if (key instanceof BCRainbowPrivateKey)
- {
- BCRainbowPrivateKey k = (BCRainbowPrivateKey)key;
- return new RainbowPrivateKeyParameters(k.getInvA1(), k.getB1(),
- k.getInvA2(), k.getB2(), k.getVi(), k.getLayers());
- }
-
- throw new InvalidKeyException("can't identify Rainbow private key.");
- }
-}
-
-
diff --git a/prov/src/main/java/org/bouncycastle/pqc/jcajce/provider/rainbow/SignatureSpi.java b/prov/src/main/java/org/bouncycastle/pqc/jcajce/provider/rainbow/SignatureSpi.java
deleted file mode 100644
index e118ed68..00000000
--- a/prov/src/main/java/org/bouncycastle/pqc/jcajce/provider/rainbow/SignatureSpi.java
+++ /dev/null
@@ -1,164 +0,0 @@
-package org.bouncycastle.pqc.jcajce.provider.rainbow;
-
-import java.security.InvalidKeyException;
-import java.security.PrivateKey;
-import java.security.PublicKey;
-import java.security.SecureRandom;
-import java.security.SignatureException;
-import java.security.spec.AlgorithmParameterSpec;
-
-import org.bouncycastle.crypto.CipherParameters;
-import org.bouncycastle.crypto.Digest;
-import org.bouncycastle.crypto.digests.SHA224Digest;
-import org.bouncycastle.crypto.digests.SHA256Digest;
-import org.bouncycastle.crypto.digests.SHA384Digest;
-import org.bouncycastle.crypto.digests.SHA512Digest;
-import org.bouncycastle.crypto.params.ParametersWithRandom;
-import org.bouncycastle.pqc.crypto.rainbow.RainbowSigner;
-
-/**
- * Rainbow Signature class, extending the jce SignatureSpi.
- */
-public class SignatureSpi
- extends java.security.SignatureSpi
-{
- private Digest digest;
- private RainbowSigner signer;
- private SecureRandom random;
-
- protected SignatureSpi(Digest digest, RainbowSigner signer)
- {
- this.digest = digest;
- this.signer = signer;
- }
-
- protected void engineInitVerify(PublicKey publicKey)
- throws InvalidKeyException
- {
- CipherParameters param;
- param = RainbowKeysToParams.generatePublicKeyParameter(publicKey);
-
- digest.reset();
- signer.init(false, param);
- }
-
- protected void engineInitSign(PrivateKey privateKey, SecureRandom random)
- throws InvalidKeyException
- {
- this.random = random;
- engineInitSign(privateKey);
- }
-
- protected void engineInitSign(PrivateKey privateKey)
- throws InvalidKeyException
- {
- CipherParameters param;
- param = RainbowKeysToParams.generatePrivateKeyParameter(privateKey);
-
- if (random != null)
- {
- param = new ParametersWithRandom(param, random);
- }
-
- digest.reset();
- signer.init(true, param);
-
- }
-
- protected void engineUpdate(byte b)
- throws SignatureException
- {
- digest.update(b);
- }
-
- protected void engineUpdate(byte[] b, int off, int len)
- throws SignatureException
- {
- digest.update(b, off, len);
- }
-
- protected byte[] engineSign()
- throws SignatureException
- {
- byte[] hash = new byte[digest.getDigestSize()];
- digest.doFinal(hash, 0);
- try
- {
- byte[] sig = signer.generateSignature(hash);
-
- return sig;
- }
- catch (Exception e)
- {
- throw new SignatureException(e.toString());
- }
- }
-
- protected boolean engineVerify(byte[] sigBytes)
- throws SignatureException
- {
- byte[] hash = new byte[digest.getDigestSize()];
- digest.doFinal(hash, 0);
- return signer.verifySignature(hash, sigBytes);
- }
-
- protected void engineSetParameter(AlgorithmParameterSpec params)
- {
- throw new UnsupportedOperationException("engineSetParameter unsupported");
- }
-
- /**
- * @deprecated replaced with <a href =
- * "#engineSetParameter(java.security.spec.AlgorithmParameterSpec)"
- * >
- */
- protected void engineSetParameter(String param, Object value)
- {
- throw new UnsupportedOperationException("engineSetParameter unsupported");
- }
-
- /**
- * @deprecated
- */
- protected Object engineGetParameter(String param)
- {
- throw new UnsupportedOperationException("engineSetParameter unsupported");
- }
-
-
- static public class withSha224
- extends SignatureSpi
- {
- public withSha224()
- {
- super(new SHA224Digest(), new RainbowSigner());
- }
- }
-
- static public class withSha256
- extends SignatureSpi
- {
- public withSha256()
- {
- super(new SHA256Digest(), new RainbowSigner());
- }
- }
-
- static public class withSha384
- extends SignatureSpi
- {
- public withSha384()
- {
- super(new SHA384Digest(), new RainbowSigner());
- }
- }
-
- static public class withSha512
- extends SignatureSpi
- {
- public withSha512()
- {
- super(new SHA512Digest(), new RainbowSigner());
- }
- }
-}