aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenny Root <kroot@google.com>2015-06-15 15:05:38 -0700
committerKenny Root <kroot@google.com>2015-06-15 15:18:31 -0700
commit72bcff84496c3cf1f8f3e7bf59fbb6f71154cfa2 (patch)
tree2a0f33cebc78eef0bf8957faffee3015a1bd39e1
parentca1c60be1f4fcb6904691522918e8ebdf271f553 (diff)
downloadopenssl-72bcff84496c3cf1f8f3e7bf59fbb6f71154cfa2.tar.gz
Add BIO_up_ref and EVP_PKEY_up_ref
To have parity with BoringSSL, we add this patch so we can properly ref-count BIO and EVP_PKEY objects in Conscrypt. Change-Id: I857663e1aaf81f6e797a0e0f6f5b256940e4859b
-rw-r--r--crypto/bio/bio.h1
-rw-r--r--crypto/bio/bio_lib.c6
-rw-r--r--crypto/evp/evp.h1
-rw-r--r--crypto/evp/p_lib.c9
-rw-r--r--include/openssl/bio.h1
-rw-r--r--include/openssl/evp.h1
-rw-r--r--patches/0019-up_ref.patch96
7 files changed, 113 insertions, 2 deletions
diff --git a/crypto/bio/bio.h b/crypto/bio/bio.h
index 3ff67275e7..ae144a98cb 100644
--- a/crypto/bio/bio.h
+++ b/crypto/bio/bio.h
@@ -645,6 +645,7 @@ BIO * BIO_new(BIO_METHOD *type);
int BIO_set(BIO *a,BIO_METHOD *type);
int BIO_free(BIO *a);
void BIO_vfree(BIO *a);
+BIO * BIO_up_ref(BIO *bio);
int BIO_read(BIO *b, void *data, int len);
int BIO_gets(BIO *bp,char *buf, int size);
int BIO_write(BIO *b, const void *data, int len);
diff --git a/crypto/bio/bio_lib.c b/crypto/bio/bio_lib.c
index 4793a453e4..7f1e8a4252 100644
--- a/crypto/bio/bio_lib.c
+++ b/crypto/bio/bio_lib.c
@@ -141,6 +141,12 @@ int BIO_free(BIO *a)
void BIO_vfree(BIO *a)
{ BIO_free(a); }
+BIO *BIO_up_ref(BIO *bio)
+{
+ CRYPTO_add(&bio->references, 1, CRYPTO_LOCK_BIO);
+ return bio;
+}
+
void BIO_clear_flags(BIO *b, int flags)
{
b->flags &= ~flags;
diff --git a/crypto/evp/evp.h b/crypto/evp/evp.h
index e43a58e69e..ce7cda35d3 100644
--- a/crypto/evp/evp.h
+++ b/crypto/evp/evp.h
@@ -923,6 +923,7 @@ struct ec_key_st *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey);
EVP_PKEY * EVP_PKEY_new(void);
EVP_PKEY * EVP_PKEY_dup(EVP_PKEY *pkey);
void EVP_PKEY_free(EVP_PKEY *pkey);
+EVP_PKEY * EVP_PKEY_up_ref(EVP_PKEY *pkey);
EVP_PKEY * d2i_PublicKey(int type,EVP_PKEY **a, const unsigned char **pp,
long length);
diff --git a/crypto/evp/p_lib.c b/crypto/evp/p_lib.c
index 8ee53c1d57..ee2dd0a973 100644
--- a/crypto/evp/p_lib.c
+++ b/crypto/evp/p_lib.c
@@ -202,8 +202,7 @@ EVP_PKEY *EVP_PKEY_new(void)
EVP_PKEY *EVP_PKEY_dup(EVP_PKEY *pkey)
{
- CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
- return pkey;
+ return EVP_PKEY_up_ref(pkey);
}
/* Setup a public key ASN1 method and ENGINE from a NID or a string.
@@ -414,6 +413,12 @@ void EVP_PKEY_free(EVP_PKEY *x)
OPENSSL_free(x);
}
+EVP_PKEY *EVP_PKEY_up_ref(EVP_PKEY *pkey)
+ {
+ CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
+ return pkey;
+ }
+
static void EVP_PKEY_free_it(EVP_PKEY *x)
{
if (x->ameth && x->ameth->pkey_free)
diff --git a/include/openssl/bio.h b/include/openssl/bio.h
index 3ff67275e7..ae144a98cb 100644
--- a/include/openssl/bio.h
+++ b/include/openssl/bio.h
@@ -645,6 +645,7 @@ BIO * BIO_new(BIO_METHOD *type);
int BIO_set(BIO *a,BIO_METHOD *type);
int BIO_free(BIO *a);
void BIO_vfree(BIO *a);
+BIO * BIO_up_ref(BIO *bio);
int BIO_read(BIO *b, void *data, int len);
int BIO_gets(BIO *bp,char *buf, int size);
int BIO_write(BIO *b, const void *data, int len);
diff --git a/include/openssl/evp.h b/include/openssl/evp.h
index e43a58e69e..ce7cda35d3 100644
--- a/include/openssl/evp.h
+++ b/include/openssl/evp.h
@@ -923,6 +923,7 @@ struct ec_key_st *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey);
EVP_PKEY * EVP_PKEY_new(void);
EVP_PKEY * EVP_PKEY_dup(EVP_PKEY *pkey);
void EVP_PKEY_free(EVP_PKEY *pkey);
+EVP_PKEY * EVP_PKEY_up_ref(EVP_PKEY *pkey);
EVP_PKEY * d2i_PublicKey(int type,EVP_PKEY **a, const unsigned char **pp,
long length);
diff --git a/patches/0019-up_ref.patch b/patches/0019-up_ref.patch
new file mode 100644
index 0000000000..efc4c40667
--- /dev/null
+++ b/patches/0019-up_ref.patch
@@ -0,0 +1,96 @@
+From: Adam Langley <agl@google.com>
+Date: Tue, 5 May 2015 10:35:22 -0700
+Subject: [PATCH] Add |BIO_up_ref| and |EVP_PKEY_up_ref|.
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+This avoids callers having to worry about |CRYPTO_add| and what the
+correct lock to use it with is.
+
+The function |EVP_PKEY_dup| already does exactly what the new
+|EVP_PKEY_up_ref| does. But that means that it's a “dup” that doesn't
+duplicate! BoringSSL has deprecated this and added |EVP_PKEY_up_ref| to
+be clearer and this change allows internal OpenSSL users to do the same.
+---
+ crypto/bio/bio.h | 1 +
+ crypto/bio/bio_lib.c | 6 ++++++
+ crypto/evp/evp.h | 1 +
+ crypto/evp/p_lib.c | 8 ++++++--
+ 4 files changed, 14 insertions(+), 2 deletions(-)
+
+diff --git a/crypto/bio/bio.h b/crypto/bio/bio.h
+index c947abb..d1b4aa0 100644
+--- a/crypto/bio/bio.h
++++ b/crypto/bio/bio.h
+@@ -642,6 +645,7 @@
+ int BIO_set(BIO *a,BIO_METHOD *type);
+ int BIO_free(BIO *a);
+ void BIO_vfree(BIO *a);
++BIO * BIO_up_ref(BIO *bio);
+ int BIO_read(BIO *b, void *data, int len);
+ int BIO_gets(BIO *bp,char *buf, int size);
+ int BIO_write(BIO *b, const void *data, int len);
+diff --git a/crypto/bio/bio_lib.c b/crypto/bio/bio_lib.c
+index 5267010..a021f38 100644
+--- a/crypto/bio/bio_lib.c
++++ b/crypto/bio/bio_lib.c
+@@ -140,6 +140,12 @@ void BIO_vfree(BIO *a)
+ BIO_free(a);
+ }
+
++BIO *BIO_up_ref(BIO *bio)
++{
++ CRYPTO_add(&bio->references, 1, CRYPTO_LOCK_BIO);
++ return bio;
++}
++
+ void BIO_clear_flags(BIO *b, int flags)
+ {
+ b->flags &= ~flags;
+diff --git a/crypto/evp/evp.h b/crypto/evp/evp.h
+index 48f865a..5f253da 100644
+--- a/crypto/evp/evp.h
++++ b/crypto/evp/evp.h
+@@ -921,8 +921,9 @@
+ #endif
+
+ EVP_PKEY * EVP_PKEY_new(void);
+ EVP_PKEY * EVP_PKEY_dup(EVP_PKEY *pkey);
+ void EVP_PKEY_free(EVP_PKEY *pkey);
++EVP_PKEY * EVP_PKEY_up_ref(EVP_PKEY *pkey);
+
+ EVP_PKEY * d2i_PublicKey(int type,EVP_PKEY **a, const unsigned char **pp,
+ long length);
+diff --git a/crypto/evp/p_lib.c b/crypto/evp/p_lib.c
+index 8ab8f62..628697b 100644
+--- a/crypto/evp/p_lib.c
++++ b/crypto/evp/p_lib.c
+@@ -200,12 +200,11 @@
+ return(ret);
+ }
+
+ EVP_PKEY *EVP_PKEY_dup(EVP_PKEY *pkey)
+ {
+- CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
+- return pkey;
++ return EVP_PKEY_up_ref(pkey);
+ }
+
+ /* Setup a public key ASN1 method and ENGINE from a NID or a string.
+ * If pkey is NULL just return 1 or 0 if the algorithm exists.
+ */
+@@ -408,6 +413,12 @@
+ OPENSSL_free(x);
+ }
+
++EVP_PKEY *EVP_PKEY_up_ref(EVP_PKEY *pkey)
++ {
++ CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
++ return pkey;
++ }
++
+ static void EVP_PKEY_free_it(EVP_PKEY *x)
+ {
+ if (x->ameth && x->ameth->pkey_free)
+--