summaryrefslogtreecommitdiffstats
path: root/bcprov/src/main/java/org/bouncycastle/crypto/digests
diff options
context:
space:
mode:
Diffstat (limited to 'bcprov/src/main/java/org/bouncycastle/crypto/digests')
-rw-r--r--bcprov/src/main/java/org/bouncycastle/crypto/digests/AndroidDigestFactory.java7
-rw-r--r--bcprov/src/main/java/org/bouncycastle/crypto/digests/GeneralDigest.java9
-rw-r--r--bcprov/src/main/java/org/bouncycastle/crypto/digests/LongDigest.java9
-rw-r--r--bcprov/src/main/java/org/bouncycastle/crypto/digests/MD5Digest.java21
-rw-r--r--bcprov/src/main/java/org/bouncycastle/crypto/digests/OpenSSLDigest.java2
-rw-r--r--bcprov/src/main/java/org/bouncycastle/crypto/digests/SHA1Digest.java21
-rw-r--r--bcprov/src/main/java/org/bouncycastle/crypto/digests/SHA256Digest.java21
-rw-r--r--bcprov/src/main/java/org/bouncycastle/crypto/digests/SHA384Digest.java14
-rw-r--r--bcprov/src/main/java/org/bouncycastle/crypto/digests/SHA512Digest.java13
9 files changed, 109 insertions, 8 deletions
diff --git a/bcprov/src/main/java/org/bouncycastle/crypto/digests/AndroidDigestFactory.java b/bcprov/src/main/java/org/bouncycastle/crypto/digests/AndroidDigestFactory.java
index 3dc7059..b7bac28 100644
--- a/bcprov/src/main/java/org/bouncycastle/crypto/digests/AndroidDigestFactory.java
+++ b/bcprov/src/main/java/org/bouncycastle/crypto/digests/AndroidDigestFactory.java
@@ -34,15 +34,18 @@ public final class AndroidDigestFactory {
try {
factoryImplementationClass = Class.forName(OpenSSLFactoryClassName);
// Double check for NativeCrypto in case we are running on RI for testing
- Class.forName("org.apache.harmony.xnet.provider.jsse.NativeCrypto");
+ Class.forName("com.android.org.conscrypt.NativeCrypto");
} catch (ClassNotFoundException e1) {
try {
factoryImplementationClass = Class.forName(BouncyCastleFactoryClassName);
} catch (ClassNotFoundException e2) {
- throw new AssertionError("Failed to load AndroidDigestFactoryInterface "
+ AssertionError e = new AssertionError("Failed to load "
+ + "AndroidDigestFactoryInterface "
+ "implementation. Looked for "
+ OpenSSLFactoryClassName + " and "
+ BouncyCastleFactoryClassName);
+ e.initCause(e1);
+ throw e;
}
}
if (!AndroidDigestFactoryInterface.class.isAssignableFrom(factoryImplementationClass)) {
diff --git a/bcprov/src/main/java/org/bouncycastle/crypto/digests/GeneralDigest.java b/bcprov/src/main/java/org/bouncycastle/crypto/digests/GeneralDigest.java
index f2c9967..15f3ebb 100644
--- a/bcprov/src/main/java/org/bouncycastle/crypto/digests/GeneralDigest.java
+++ b/bcprov/src/main/java/org/bouncycastle/crypto/digests/GeneralDigest.java
@@ -1,13 +1,14 @@
package org.bouncycastle.crypto.digests;
import org.bouncycastle.crypto.ExtendedDigest;
+import org.bouncycastle.util.Memoable;
/**
* base implementation of MD4 family style digest as outlined in
* "Handbook of Applied Cryptography", pages 344 - 347.
*/
public abstract class GeneralDigest
- implements ExtendedDigest
+ implements ExtendedDigest, Memoable
{
private static final int BYTE_LENGTH = 64;
private byte[] xBuf;
@@ -32,6 +33,12 @@ public abstract class GeneralDigest
protected GeneralDigest(GeneralDigest t)
{
xBuf = new byte[t.xBuf.length];
+
+ copyIn(t);
+ }
+
+ protected void copyIn(GeneralDigest t)
+ {
System.arraycopy(t.xBuf, 0, xBuf, 0, t.xBuf.length);
xBufOff = t.xBufOff;
diff --git a/bcprov/src/main/java/org/bouncycastle/crypto/digests/LongDigest.java b/bcprov/src/main/java/org/bouncycastle/crypto/digests/LongDigest.java
index 22d457b..5c79e4e 100644
--- a/bcprov/src/main/java/org/bouncycastle/crypto/digests/LongDigest.java
+++ b/bcprov/src/main/java/org/bouncycastle/crypto/digests/LongDigest.java
@@ -2,12 +2,13 @@ package org.bouncycastle.crypto.digests;
import org.bouncycastle.crypto.ExtendedDigest;
import org.bouncycastle.crypto.util.Pack;
+import org.bouncycastle.util.Memoable;
/**
* Base class for SHA-384 and SHA-512.
*/
public abstract class LongDigest
- implements ExtendedDigest
+ implements ExtendedDigest, Memoable
{
private static final int BYTE_LENGTH = 128;
@@ -41,6 +42,12 @@ public abstract class LongDigest
protected LongDigest(LongDigest t)
{
xBuf = new byte[t.xBuf.length];
+
+ copyIn(t);
+ }
+
+ protected void copyIn(LongDigest t)
+ {
System.arraycopy(t.xBuf, 0, xBuf, 0, t.xBuf.length);
xBufOff = t.xBufOff;
diff --git a/bcprov/src/main/java/org/bouncycastle/crypto/digests/MD5Digest.java b/bcprov/src/main/java/org/bouncycastle/crypto/digests/MD5Digest.java
index 05ed27a..ff9cedf 100644
--- a/bcprov/src/main/java/org/bouncycastle/crypto/digests/MD5Digest.java
+++ b/bcprov/src/main/java/org/bouncycastle/crypto/digests/MD5Digest.java
@@ -1,6 +1,8 @@
package org.bouncycastle.crypto.digests;
+import org.bouncycastle.util.Memoable;
+
/**
* implementation of MD5 as outlined in "Handbook of Applied Cryptography", pages 346 - 347.
*/
@@ -30,6 +32,13 @@ public class MD5Digest
{
super(t);
+ copyIn(t);
+ }
+
+ private void copyIn(MD5Digest t)
+ {
+ super.copyIn(t);
+
H1 = t.H1;
H2 = t.H2;
H3 = t.H3;
@@ -299,4 +308,16 @@ public class MD5Digest
X[i] = 0;
}
}
+
+ public Memoable copy()
+ {
+ return new MD5Digest(this);
+ }
+
+ public void reset(Memoable other)
+ {
+ MD5Digest d = (MD5Digest)other;
+
+ copyIn(d);
+ }
}
diff --git a/bcprov/src/main/java/org/bouncycastle/crypto/digests/OpenSSLDigest.java b/bcprov/src/main/java/org/bouncycastle/crypto/digests/OpenSSLDigest.java
index 3e7c0e7..07b4e50 100644
--- a/bcprov/src/main/java/org/bouncycastle/crypto/digests/OpenSSLDigest.java
+++ b/bcprov/src/main/java/org/bouncycastle/crypto/digests/OpenSSLDigest.java
@@ -16,7 +16,7 @@
package org.bouncycastle.crypto.digests;
-import org.apache.harmony.xnet.provider.jsse.NativeCrypto;
+import com.android.org.conscrypt.NativeCrypto;
import org.bouncycastle.crypto.ExtendedDigest;
/**
diff --git a/bcprov/src/main/java/org/bouncycastle/crypto/digests/SHA1Digest.java b/bcprov/src/main/java/org/bouncycastle/crypto/digests/SHA1Digest.java
index 7f8d30a..21b1024 100644
--- a/bcprov/src/main/java/org/bouncycastle/crypto/digests/SHA1Digest.java
+++ b/bcprov/src/main/java/org/bouncycastle/crypto/digests/SHA1Digest.java
@@ -1,12 +1,13 @@
package org.bouncycastle.crypto.digests;
import org.bouncycastle.crypto.util.Pack;
+import org.bouncycastle.util.Memoable;
/**
* implementation of SHA-1 as outlined in "Handbook of Applied Cryptography", pages 346 - 349.
*
* It is interesting to ponder why the, apart from the extra IV, the other difference here from MD5
- * is the "endienness" of the word processing!
+ * is the "endianness" of the word processing!
*/
public class SHA1Digest
extends GeneralDigest
@@ -34,6 +35,11 @@ public class SHA1Digest
{
super(t);
+ copyIn(t);
+ }
+
+ private void copyIn(SHA1Digest t)
+ {
H1 = t.H1;
H2 = t.H2;
H3 = t.H3;
@@ -283,6 +289,19 @@ public class SHA1Digest
X[i] = 0;
}
}
+
+ public Memoable copy()
+ {
+ return new SHA1Digest(this);
+ }
+
+ public void reset(Memoable other)
+ {
+ SHA1Digest d = (SHA1Digest)other;
+
+ super.copyIn(d);
+ copyIn(d);
+ }
}
diff --git a/bcprov/src/main/java/org/bouncycastle/crypto/digests/SHA256Digest.java b/bcprov/src/main/java/org/bouncycastle/crypto/digests/SHA256Digest.java
index abd9c1b..a2ceda3 100644
--- a/bcprov/src/main/java/org/bouncycastle/crypto/digests/SHA256Digest.java
+++ b/bcprov/src/main/java/org/bouncycastle/crypto/digests/SHA256Digest.java
@@ -1,8 +1,8 @@
package org.bouncycastle.crypto.digests;
-import org.bouncycastle.crypto.digests.GeneralDigest;
import org.bouncycastle.crypto.util.Pack;
+import org.bouncycastle.util.Memoable;
/**
@@ -42,6 +42,13 @@ public class SHA256Digest
{
super(t);
+ copyIn(t);
+ }
+
+ private void copyIn(SHA256Digest t)
+ {
+ super.copyIn(t);
+
H1 = t.H1;
H2 = t.H2;
H3 = t.H3;
@@ -291,5 +298,17 @@ public class SHA256Digest
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
};
+
+ public Memoable copy()
+ {
+ return new SHA256Digest(this);
+ }
+
+ public void reset(Memoable other)
+ {
+ SHA256Digest d = (SHA256Digest)other;
+
+ copyIn(d);
+ }
}
diff --git a/bcprov/src/main/java/org/bouncycastle/crypto/digests/SHA384Digest.java b/bcprov/src/main/java/org/bouncycastle/crypto/digests/SHA384Digest.java
index cdd979a..75d195d 100644
--- a/bcprov/src/main/java/org/bouncycastle/crypto/digests/SHA384Digest.java
+++ b/bcprov/src/main/java/org/bouncycastle/crypto/digests/SHA384Digest.java
@@ -1,6 +1,7 @@
package org.bouncycastle.crypto.digests;
import org.bouncycastle.crypto.util.Pack;
+import org.bouncycastle.util.Memoable;
/**
@@ -17,7 +18,6 @@ import org.bouncycastle.crypto.util.Pack;
public class SHA384Digest
extends LongDigest
{
-
private static final int DIGEST_LENGTH = 48;
/**
@@ -84,4 +84,16 @@ public class SHA384Digest
H7 = 0xdb0c2e0d64f98fa7l;
H8 = 0x47b5481dbefa4fa4l;
}
+
+ public Memoable copy()
+ {
+ return new SHA384Digest(this);
+ }
+
+ public void reset(Memoable other)
+ {
+ SHA384Digest d = (SHA384Digest)other;
+
+ super.copyIn(d);
+ }
}
diff --git a/bcprov/src/main/java/org/bouncycastle/crypto/digests/SHA512Digest.java b/bcprov/src/main/java/org/bouncycastle/crypto/digests/SHA512Digest.java
index 34a8e4e..7db63ad 100644
--- a/bcprov/src/main/java/org/bouncycastle/crypto/digests/SHA512Digest.java
+++ b/bcprov/src/main/java/org/bouncycastle/crypto/digests/SHA512Digest.java
@@ -1,6 +1,7 @@
package org.bouncycastle.crypto.digests;
import org.bouncycastle.crypto.util.Pack;
+import org.bouncycastle.util.Memoable;
/**
@@ -85,5 +86,17 @@ public class SHA512Digest
H7 = 0x1f83d9abfb41bd6bL;
H8 = 0x5be0cd19137e2179L;
}
+
+ public Memoable copy()
+ {
+ return new SHA512Digest(this);
+ }
+
+ public void reset(Memoable other)
+ {
+ SHA512Digest d = (SHA512Digest)other;
+
+ copyIn(d);
+ }
}