summaryrefslogtreecommitdiffstats
path: root/bcprov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/ec/SignatureSpi.java
diff options
context:
space:
mode:
Diffstat (limited to 'bcprov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/ec/SignatureSpi.java')
-rw-r--r--bcprov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/ec/SignatureSpi.java477
1 files changed, 224 insertions, 253 deletions
diff --git a/bcprov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/ec/SignatureSpi.java b/bcprov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/ec/SignatureSpi.java
index 26811d1..5e2bb4e 100644
--- a/bcprov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/ec/SignatureSpi.java
+++ b/bcprov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/ec/SignatureSpi.java
@@ -16,23 +16,16 @@ import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.crypto.DSA;
import org.bouncycastle.crypto.Digest;
import org.bouncycastle.crypto.digests.NullDigest;
-// BEGIN android-added
-import org.bouncycastle.crypto.digests.AndroidDigestFactory;
-// END android-added
-// BEGIN android-removed
-// import org.bouncycastle.crypto.digests.RIPEMD160Digest;
-// import org.bouncycastle.crypto.digests.SHA1Digest;
-// import org.bouncycastle.crypto.digests.SHA224Digest;
-// import org.bouncycastle.crypto.digests.SHA256Digest;
-// import org.bouncycastle.crypto.digests.SHA384Digest;
-// import org.bouncycastle.crypto.digests.SHA512Digest;
-// END android-removed
+import org.bouncycastle.crypto.digests.RIPEMD160Digest;
+import org.bouncycastle.crypto.digests.SHA1Digest;
+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.crypto.signers.ECDSASigner;
-// BEGIN android-removed
-// import org.bouncycastle.crypto.signers.ECNRSigner;
-// import org.bouncycastle.crypto.signers.HMacDSAKCalculator;
-// END android-removed
+import org.bouncycastle.crypto.signers.ECNRSigner;
+import org.bouncycastle.crypto.signers.HMacDSAKCalculator;
import org.bouncycastle.jcajce.provider.asymmetric.util.DSABase;
import org.bouncycastle.jcajce.provider.asymmetric.util.DSAEncoder;
import org.bouncycastle.jcajce.provider.asymmetric.util.ECUtil;
@@ -77,22 +70,18 @@ public class SignatureSpi
{
public ecDSA()
{
- // BEGIN android-changed
- super(AndroidDigestFactory.getSHA1(), new ECDSASigner(), new StdDSAEncoder());
- // END android-changed
+ super(new SHA1Digest(), new ECDSASigner(), new StdDSAEncoder());
}
}
- // BEGIN android-removed
- // static public class ecDetDSA
- // extends SignatureSpi
- // {
- // public ecDetDSA()
- // {
- // super(new SHA1Digest(), new ECDSASigner(new HMacDSAKCalculator(new SHA1Digest())), new StdDSAEncoder());
- // }
- // }
- // END android-removed
+ static public class ecDetDSA
+ extends SignatureSpi
+ {
+ public ecDetDSA()
+ {
+ super(new SHA1Digest(), new ECDSASigner(new HMacDSAKCalculator(new SHA1Digest())), new StdDSAEncoder());
+ }
+ }
static public class ecDSAnone
extends SignatureSpi
@@ -108,196 +97,180 @@ public class SignatureSpi
{
public ecDSA224()
{
- // BEGIN android-changed
- super(AndroidDigestFactory.getSHA224(), new ECDSASigner(), new StdDSAEncoder());
- // END android-changed
+ super(new SHA224Digest(), new ECDSASigner(), new StdDSAEncoder());
}
}
- // BEGIN android-removed
- // static public class ecDetDSA224
- // extends SignatureSpi
- // {
- // public ecDetDSA224()
- // {
- // super(new SHA224Digest(), new ECDSASigner(new HMacDSAKCalculator(new SHA224Digest())), new StdDSAEncoder());
- // }
- // }
- // END android-removed
+ static public class ecDetDSA224
+ extends SignatureSpi
+ {
+ public ecDetDSA224()
+ {
+ super(new SHA224Digest(), new ECDSASigner(new HMacDSAKCalculator(new SHA224Digest())), new StdDSAEncoder());
+ }
+ }
static public class ecDSA256
extends SignatureSpi
{
public ecDSA256()
{
- // BEGIN android-changed
- super(AndroidDigestFactory.getSHA256(), new ECDSASigner(), new StdDSAEncoder());
- // END android-changed
+ super(new SHA256Digest(), new ECDSASigner(), new StdDSAEncoder());
}
}
- // BEGIN android-removed
- // static public class ecDetDSA256
- // extends SignatureSpi
- // {
- // public ecDetDSA256()
- // {
- // super(new SHA256Digest(), new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest())), new StdDSAEncoder());
- // }
- // }
- // END android-removed
+ static public class ecDetDSA256
+ extends SignatureSpi
+ {
+ public ecDetDSA256()
+ {
+ super(new SHA256Digest(), new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest())), new StdDSAEncoder());
+ }
+ }
static public class ecDSA384
extends SignatureSpi
{
public ecDSA384()
{
- // BEGIN android-changed
- super(AndroidDigestFactory.getSHA384(), new ECDSASigner(), new StdDSAEncoder());
- // END android-changed
+ super(new SHA384Digest(), new ECDSASigner(), new StdDSAEncoder());
}
}
- // BEGIN android-removed
- // static public class ecDetDSA384
- // extends SignatureSpi
- // {
- // public ecDetDSA384()
- // {
- // super(new SHA384Digest(), new ECDSASigner(new HMacDSAKCalculator(new SHA384Digest())), new StdDSAEncoder());
- // }
- // }
- // END android-removed
+ static public class ecDetDSA384
+ extends SignatureSpi
+ {
+ public ecDetDSA384()
+ {
+ super(new SHA384Digest(), new ECDSASigner(new HMacDSAKCalculator(new SHA384Digest())), new StdDSAEncoder());
+ }
+ }
static public class ecDSA512
extends SignatureSpi
{
public ecDSA512()
{
- // BEGIN android-changed
- super(AndroidDigestFactory.getSHA512(), new ECDSASigner(), new StdDSAEncoder());
- // END android-changed
+ super(new SHA512Digest(), new ECDSASigner(), new StdDSAEncoder());
+ }
+ }
+
+ static public class ecDetDSA512
+ extends SignatureSpi
+ {
+ public ecDetDSA512()
+ {
+ super(new SHA512Digest(), new ECDSASigner(new HMacDSAKCalculator(new SHA512Digest())), new StdDSAEncoder());
}
}
- // BEGIN android-removed
- // static public class ecDetDSA512
- // extends SignatureSpi
- // {
- // public ecDetDSA512()
- // {
- // super(new SHA512Digest(), new ECDSASigner(new HMacDSAKCalculator(new SHA512Digest())), new StdDSAEncoder());
- // }
- // }
- //
- // static public class ecDSARipeMD160
- // extends SignatureSpi
- // {
- // public ecDSARipeMD160()
- // {
- // super(new RIPEMD160Digest(), new ECDSASigner(), new StdDSAEncoder());
- // }
- // }
- //
- // static public class ecNR
- // extends SignatureSpi
- // {
- // public ecNR()
- // {
- // super(new SHA1Digest(), new ECNRSigner(), new StdDSAEncoder());
- // }
- // }
- //
- // static public class ecNR224
- // extends SignatureSpi
- // {
- // public ecNR224()
- // {
- // super(new SHA224Digest(), new ECNRSigner(), new StdDSAEncoder());
- // }
- // }
- //
- // static public class ecNR256
- // extends SignatureSpi
- // {
- // public ecNR256()
- // {
- // super(new SHA256Digest(), new ECNRSigner(), new StdDSAEncoder());
- // }
- // }
- //
- // static public class ecNR384
- // extends SignatureSpi
- // {
- // public ecNR384()
- // {
- // super(new SHA384Digest(), new ECNRSigner(), new StdDSAEncoder());
- // }
- // }
- //
- // static public class ecNR512
- // extends SignatureSpi
- // {
- // public ecNR512()
- // {
- // super(new SHA512Digest(), new ECNRSigner(), new StdDSAEncoder());
- // }
- // }
- //
- // static public class ecCVCDSA
- // extends SignatureSpi
- // {
- // public ecCVCDSA()
- // {
- // super(new SHA1Digest(), new ECDSASigner(), new PlainDSAEncoder());
- // }
- // }
- //
- // static public class ecCVCDSA224
- // extends SignatureSpi
- // {
- // public ecCVCDSA224()
- // {
- // super(new SHA224Digest(), new ECDSASigner(), new PlainDSAEncoder());
- // }
- // }
- //
- // static public class ecCVCDSA256
- // extends SignatureSpi
- // {
- // public ecCVCDSA256()
- // {
- // super(new SHA256Digest(), new ECDSASigner(), new PlainDSAEncoder());
- // }
- // }
- //
- // static public class ecCVCDSA384
- // extends SignatureSpi
- // {
- // public ecCVCDSA384()
- // {
- // super(new SHA384Digest(), new ECDSASigner(), new PlainDSAEncoder());
- // }
- // }
- //
- // static public class ecCVCDSA512
- // extends SignatureSpi
- // {
- // public ecCVCDSA512()
- // {
- // super(new SHA512Digest(), new ECDSASigner(), new PlainDSAEncoder());
- // }
- // }
- //
- // static public class ecPlainDSARP160
- // extends SignatureSpi
- // {
- // public ecPlainDSARP160()
- // {
- // super(new RIPEMD160Digest(), new ECDSASigner(), new PlainDSAEncoder());
- // }
- // }
- // END android-removed
+ static public class ecDSARipeMD160
+ extends SignatureSpi
+ {
+ public ecDSARipeMD160()
+ {
+ super(new RIPEMD160Digest(), new ECDSASigner(), new StdDSAEncoder());
+ }
+ }
+
+ static public class ecNR
+ extends SignatureSpi
+ {
+ public ecNR()
+ {
+ super(new SHA1Digest(), new ECNRSigner(), new StdDSAEncoder());
+ }
+ }
+
+ static public class ecNR224
+ extends SignatureSpi
+ {
+ public ecNR224()
+ {
+ super(new SHA224Digest(), new ECNRSigner(), new StdDSAEncoder());
+ }
+ }
+
+ static public class ecNR256
+ extends SignatureSpi
+ {
+ public ecNR256()
+ {
+ super(new SHA256Digest(), new ECNRSigner(), new StdDSAEncoder());
+ }
+ }
+
+ static public class ecNR384
+ extends SignatureSpi
+ {
+ public ecNR384()
+ {
+ super(new SHA384Digest(), new ECNRSigner(), new StdDSAEncoder());
+ }
+ }
+
+ static public class ecNR512
+ extends SignatureSpi
+ {
+ public ecNR512()
+ {
+ super(new SHA512Digest(), new ECNRSigner(), new StdDSAEncoder());
+ }
+ }
+
+ static public class ecCVCDSA
+ extends SignatureSpi
+ {
+ public ecCVCDSA()
+ {
+ super(new SHA1Digest(), new ECDSASigner(), new PlainDSAEncoder());
+ }
+ }
+
+ static public class ecCVCDSA224
+ extends SignatureSpi
+ {
+ public ecCVCDSA224()
+ {
+ super(new SHA224Digest(), new ECDSASigner(), new PlainDSAEncoder());
+ }
+ }
+
+ static public class ecCVCDSA256
+ extends SignatureSpi
+ {
+ public ecCVCDSA256()
+ {
+ super(new SHA256Digest(), new ECDSASigner(), new PlainDSAEncoder());
+ }
+ }
+
+ static public class ecCVCDSA384
+ extends SignatureSpi
+ {
+ public ecCVCDSA384()
+ {
+ super(new SHA384Digest(), new ECDSASigner(), new PlainDSAEncoder());
+ }
+ }
+
+ static public class ecCVCDSA512
+ extends SignatureSpi
+ {
+ public ecCVCDSA512()
+ {
+ super(new SHA512Digest(), new ECDSASigner(), new PlainDSAEncoder());
+ }
+ }
+
+ static public class ecPlainDSARP160
+ extends SignatureSpi
+ {
+ public ecPlainDSARP160()
+ {
+ super(new RIPEMD160Digest(), new ECDSASigner(), new PlainDSAEncoder());
+ }
+ }
private static class StdDSAEncoder
implements DSAEncoder
@@ -329,68 +302,66 @@ public class SignatureSpi
}
}
- // BEGIN android-removed
- // private static class PlainDSAEncoder
- // implements DSAEncoder
- // {
- // public byte[] encode(
- // BigInteger r,
- // BigInteger s)
- // throws IOException
- // {
- // byte[] first = makeUnsigned(r);
- // byte[] second = makeUnsigned(s);
- // byte[] res;
- //
- // if (first.length > second.length)
- // {
- // res = new byte[first.length * 2];
- // }
- // else
- // {
- // res = new byte[second.length * 2];
- // }
- //
- // System.arraycopy(first, 0, res, res.length / 2 - first.length, first.length);
- // System.arraycopy(second, 0, res, res.length - second.length, second.length);
- //
- // return res;
- // }
- //
- //
- // private byte[] makeUnsigned(BigInteger val)
- // {
- // byte[] res = val.toByteArray();
- //
- // if (res[0] == 0)
- // {
- // byte[] tmp = new byte[res.length - 1];
- //
- // System.arraycopy(res, 1, tmp, 0, tmp.length);
- //
- // return tmp;
- // }
- //
- // return res;
- // }
- //
- // public BigInteger[] decode(
- // byte[] encoding)
- // throws IOException
- // {
- // BigInteger[] sig = new BigInteger[2];
- //
- // byte[] first = new byte[encoding.length / 2];
- // byte[] second = new byte[encoding.length / 2];
- //
- // System.arraycopy(encoding, 0, first, 0, first.length);
- // System.arraycopy(encoding, first.length, second, 0, second.length);
- //
- // sig[0] = new BigInteger(1, first);
- // sig[1] = new BigInteger(1, second);
- //
- // return sig;
- // }
- // }
- // END android-removed
-}
+ private static class PlainDSAEncoder
+ implements DSAEncoder
+ {
+ public byte[] encode(
+ BigInteger r,
+ BigInteger s)
+ throws IOException
+ {
+ byte[] first = makeUnsigned(r);
+ byte[] second = makeUnsigned(s);
+ byte[] res;
+
+ if (first.length > second.length)
+ {
+ res = new byte[first.length * 2];
+ }
+ else
+ {
+ res = new byte[second.length * 2];
+ }
+
+ System.arraycopy(first, 0, res, res.length / 2 - first.length, first.length);
+ System.arraycopy(second, 0, res, res.length - second.length, second.length);
+
+ return res;
+ }
+
+
+ private byte[] makeUnsigned(BigInteger val)
+ {
+ byte[] res = val.toByteArray();
+
+ if (res[0] == 0)
+ {
+ byte[] tmp = new byte[res.length - 1];
+
+ System.arraycopy(res, 1, tmp, 0, tmp.length);
+
+ return tmp;
+ }
+
+ return res;
+ }
+
+ public BigInteger[] decode(
+ byte[] encoding)
+ throws IOException
+ {
+ BigInteger[] sig = new BigInteger[2];
+
+ byte[] first = new byte[encoding.length / 2];
+ byte[] second = new byte[encoding.length / 2];
+
+ System.arraycopy(encoding, 0, first, 0, first.length);
+ System.arraycopy(encoding, first.length, second, 0, second.length);
+
+ sig[0] = new BigInteger(1, first);
+ sig[1] = new BigInteger(1, second);
+
+ return sig;
+ }
+ }
+} \ No newline at end of file