summaryrefslogtreecommitdiffstats
path: root/patches
diff options
context:
space:
mode:
authorKenny Root <kroot@google.com>2014-02-24 15:25:15 -0800
committerKenny Root <kroot@google.com>2014-02-25 09:06:26 -0800
commited8b1c77e5a631584cd74382a645c9ada09c155f (patch)
tree213d3de0461fe6768265f1f6834185fc6547f9ed /patches
parent703b75a22dee71d6c1ca0ae61a4be92b83e4a0e0 (diff)
downloadandroid_external_bouncycastle-ed8b1c77e5a631584cd74382a645c9ada09c155f.tar.gz
android_external_bouncycastle-ed8b1c77e5a631584cd74382a645c9ada09c155f.tar.bz2
android_external_bouncycastle-ed8b1c77e5a631584cd74382a645c9ada09c155f.zip
OpenSSLDigest: use delegate model
Instead of invoking NativeCrypto directly, delegate to the JCE subsystem to select the AndroidOpenSSL provider. Change-Id: I91c01fc5c21c6d674203226a89a9f4fb2f30426f
Diffstat (limited to 'patches')
-rw-r--r--patches/bcprov.patch132
1 files changed, 27 insertions, 105 deletions
diff --git a/patches/bcprov.patch b/patches/bcprov.patch
index 25de3dc..8bd81d6 100644
--- a/patches/bcprov.patch
+++ b/patches/bcprov.patch
@@ -569,8 +569,8 @@ diff -Naur bcprov-jdk15on-150.orig/org/bouncycastle/crypto/digests/AndroidDigest
+}
diff -Naur bcprov-jdk15on-150.orig/org/bouncycastle/crypto/digests/OpenSSLDigest.java bcprov-jdk15on-150/org/bouncycastle/crypto/digests/OpenSSLDigest.java
--- bcprov-jdk15on-150.orig/org/bouncycastle/crypto/digests/OpenSSLDigest.java 1970-01-01 00:00:00.000000000 +0000
-+++ bcprov-jdk15on-150/org/bouncycastle/crypto/digests/OpenSSLDigest.java 2013-09-26 18:06:21.000000000 +0000
-@@ -0,0 +1,166 @@
++++ bcprov-jdk15on-150/org/bouncycastle/crypto/digests/OpenSSLDigest.java 2014-02-24 23:25:15.000000000 +0000
+@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
@@ -589,152 +589,74 @@ diff -Naur bcprov-jdk15on-150.orig/org/bouncycastle/crypto/digests/OpenSSLDigest
+
+package org.bouncycastle.crypto.digests;
+
-+import com.android.org.conscrypt.NativeCrypto;
-+import org.bouncycastle.crypto.ExtendedDigest;
++import org.bouncycastle.crypto.Digest;
++import java.security.DigestException;
++import java.security.MessageDigest;
+
+/**
+ * Implements the BouncyCastle Digest interface using OpenSSL's EVP API.
+ */
-+public class OpenSSLDigest implements ExtendedDigest {
-+
-+ /**
-+ * Holds the standard name of the hashing algorithm, e.g. "SHA-1";
-+ */
-+ private final String algorithm;
-+
-+ /**
-+ * Holds the EVP_MD for the hashing algorithm, e.g. EVP_get_digestbyname("sha1");
-+ */
-+ private final long evp_md;
-+
-+ /**
-+ * Holds the output size of the message digest.
-+ */
-+ private final int size;
-+
-+ /**
-+ * Holds the block size of the message digest.
-+ */
-+ private final int blockSize;
-+
-+ /**
-+ * Holds a pointer to the native message digest context. It is
-+ * lazily initialized to avoid having to reallocate on reset when
-+ * its unlikely to be reused.
-+ */
-+ private long ctx;
-+
-+ /**
-+ * Holds a dummy buffer for writing single bytes to the digest.
-+ */
-+ private final byte[] singleByte = new byte[1];
++public class OpenSSLDigest implements Digest {
++ private final MessageDigest delegate;
+
-+ /**
-+ * Creates a new OpenSSLMessageDigest instance for the given algorithm
-+ * name.
-+ */
-+ private OpenSSLDigest(String algorithm, long evp_md, int size, int blockSize) {
-+ this.algorithm = algorithm;
-+ this.evp_md = evp_md;
-+ this.size = size;
-+ this.blockSize = blockSize;
++ public OpenSSLDigest(String algorithm) {
++ try {
++ delegate = MessageDigest.getInstance(algorithm, "AndroidOpenSSL");
++ } catch (Exception e) {
++ throw new RuntimeException(e);
++ }
+ }
+
+ public String getAlgorithmName() {
-+ return algorithm;
++ return delegate.getAlgorithm();
+ }
+
+ public int getDigestSize() {
-+ return size;
-+ }
-+
-+ public int getByteLength() {
-+ return blockSize;
++ return delegate.getDigestLength();
+ }
+
+ public void reset() {
-+ free();
++ delegate.reset();
+ }
+
+ public void update(byte in) {
-+ singleByte[0] = in;
-+ update(singleByte, 0, 1);
++ delegate.update(in);
+ }
+
+ public void update(byte[] in, int inOff, int len) {
-+ NativeCrypto.EVP_DigestUpdate(getCtx(), in, inOff, len);
++ delegate.update(in, inOff, len);
+ }
+
+ public int doFinal(byte[] out, int outOff) {
-+ int i = NativeCrypto.EVP_DigestFinal(getCtx(), out, outOff);
-+ ctx = 0; // EVP_DigestFinal frees the context as a side effect
-+ reset();
-+ return i;
-+ }
-+
-+ private long getCtx() {
-+ if (ctx == 0) {
-+ ctx = NativeCrypto.EVP_DigestInit(evp_md);
-+ }
-+ return ctx;
-+ }
-+
-+ private void free() {
-+ if (ctx != 0) {
-+ NativeCrypto.EVP_MD_CTX_destroy(ctx);
-+ ctx = 0;
-+ }
-+ }
-+
-+ @Override
-+ protected void finalize() throws Throwable {
+ try {
-+ free();
-+ } finally {
-+ super.finalize();
++ return delegate.digest(out, outOff, out.length);
++ } catch (DigestException e) {
++ throw new RuntimeException(e);
+ }
+ }
+
+ public static class MD5 extends OpenSSLDigest {
-+ private static final long EVP_MD = NativeCrypto.EVP_get_digestbyname("md5");
-+ private static final int SIZE = NativeCrypto.EVP_MD_size(EVP_MD);
-+ private static final int BLOCK_SIZE = NativeCrypto.EVP_MD_block_size(EVP_MD);
-+ public MD5() { super("MD5", EVP_MD, SIZE, BLOCK_SIZE); }
++ public MD5() { super("MD5"); }
+ }
+
+ public static class SHA1 extends OpenSSLDigest {
-+ private static final long EVP_MD = NativeCrypto.EVP_get_digestbyname("sha1");
-+ private static final int SIZE = NativeCrypto.EVP_MD_size(EVP_MD);
-+ private static final int BLOCK_SIZE = NativeCrypto.EVP_MD_block_size(EVP_MD);
-+ public SHA1() { super("SHA-1", EVP_MD, SIZE, BLOCK_SIZE); }
++ public SHA1() { super("SHA-1"); }
+ }
+
+ public static class SHA224 extends OpenSSLDigest {
-+ private static final long EVP_MD = NativeCrypto.EVP_get_digestbyname("sha224");
-+ private static final int SIZE = NativeCrypto.EVP_MD_size(EVP_MD);
-+ private static final int BLOCK_SIZE = NativeCrypto.EVP_MD_block_size(EVP_MD);
-+ public SHA224() { super("SHA-224", EVP_MD, SIZE, BLOCK_SIZE); }
++ public SHA224() { super("SHA-224"); }
+ }
+
+ public static class SHA256 extends OpenSSLDigest {
-+ private static final long EVP_MD = NativeCrypto.EVP_get_digestbyname("sha256");
-+ private static final int SIZE = NativeCrypto.EVP_MD_size(EVP_MD);
-+ private static final int BLOCK_SIZE = NativeCrypto.EVP_MD_block_size(EVP_MD);
-+ public SHA256() { super("SHA-256", EVP_MD, SIZE, BLOCK_SIZE); }
++ public SHA256() { super("SHA-256"); }
+ }
+
+ public static class SHA384 extends OpenSSLDigest {
-+ private static final long EVP_MD = NativeCrypto.EVP_get_digestbyname("sha384");
-+ private static final int SIZE = NativeCrypto.EVP_MD_size(EVP_MD);
-+ private static final int BLOCK_SIZE = NativeCrypto.EVP_MD_block_size(EVP_MD);
-+ public SHA384() { super("SHA-384", EVP_MD, SIZE, BLOCK_SIZE); }
++ public SHA384() { super("SHA-384"); }
+ }
+
+ public static class SHA512 extends OpenSSLDigest {
-+ private static final long EVP_MD = NativeCrypto.EVP_get_digestbyname("sha512");
-+ private static final int SIZE = NativeCrypto.EVP_MD_size(EVP_MD);
-+ private static final int BLOCK_SIZE = NativeCrypto.EVP_MD_block_size(EVP_MD);
-+ public SHA512() { super("SHA-512", EVP_MD, SIZE, BLOCK_SIZE); }
++ public SHA512() { super("SHA-512"); }
+ }
+}
diff -Naur bcprov-jdk15on-150.orig/org/bouncycastle/crypto/encodings/OAEPEncoding.java bcprov-jdk15on-150/org/bouncycastle/crypto/encodings/OAEPEncoding.java