From 53236ab726f2cb84436bc0cc39769e610cad136d Mon Sep 17 00:00:00 2001 From: jsing <> Date: Sat, 17 Mar 2018 14:55:39 +0000 Subject: Provide X509_PUBKEY_get0() by splitting X509_PUBKEY_get() and turning it into a wrapper that calls X509_PUBKEY_get0() and up refs. --- src/lib/libcrypto/Symbols.list | 1 + src/lib/libcrypto/asn1/x_pubkey.c | 22 ++++++++++++++++------ src/lib/libcrypto/x509/x509.h | 3 ++- 3 files changed, 19 insertions(+), 7 deletions(-) (limited to 'src/lib') diff --git a/src/lib/libcrypto/Symbols.list b/src/lib/libcrypto/Symbols.list index 1b330c7dbf..ea1f420475 100644 --- a/src/lib/libcrypto/Symbols.list +++ b/src/lib/libcrypto/Symbols.list @@ -2759,6 +2759,7 @@ X509_PKEY_new X509_POLICY_NODE_print X509_PUBKEY_free X509_PUBKEY_get +X509_PUBKEY_get0 X509_PUBKEY_get0_param X509_PUBKEY_it X509_PUBKEY_new diff --git a/src/lib/libcrypto/asn1/x_pubkey.c b/src/lib/libcrypto/asn1/x_pubkey.c index 738507bbb6..ea67419cb2 100644 --- a/src/lib/libcrypto/asn1/x_pubkey.c +++ b/src/lib/libcrypto/asn1/x_pubkey.c @@ -1,4 +1,4 @@ -/* $OpenBSD: x_pubkey.c,v 1.26 2017/01/29 17:49:22 beck Exp $ */ +/* $OpenBSD: x_pubkey.c,v 1.27 2018/03/17 14:55:39 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -175,17 +175,15 @@ error: } EVP_PKEY * -X509_PUBKEY_get(X509_PUBKEY *key) +X509_PUBKEY_get0(X509_PUBKEY *key) { EVP_PKEY *ret = NULL; if (key == NULL) goto error; - if (key->pkey != NULL) { - CRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY); + if (key->pkey != NULL) return key->pkey; - } if (key->public_key == NULL) goto error; @@ -220,7 +218,6 @@ X509_PUBKEY_get(X509_PUBKEY *key) key->pkey = ret; CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY); } - CRYPTO_add(&ret->references, 1, CRYPTO_LOCK_EVP_PKEY); return ret; @@ -229,6 +226,19 @@ error: return (NULL); } +EVP_PKEY * +X509_PUBKEY_get(X509_PUBKEY *key) +{ + EVP_PKEY *pkey; + + if ((pkey = X509_PUBKEY_get0(key)) == NULL) + return (NULL); + + CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY); + + return pkey; +} + /* Now two pseudo ASN1 routines that take an EVP_PKEY structure * and encode or decode as X509_PUBKEY */ diff --git a/src/lib/libcrypto/x509/x509.h b/src/lib/libcrypto/x509/x509.h index 2b096ed3b3..a4aa849e31 100644 --- a/src/lib/libcrypto/x509/x509.h +++ b/src/lib/libcrypto/x509/x509.h @@ -1,4 +1,4 @@ -/* $OpenBSD: x509.h,v 1.42 2018/03/17 14:33:20 jsing Exp $ */ +/* $OpenBSD: x509.h,v 1.43 2018/03/17 14:55:39 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -806,6 +806,7 @@ extern const ASN1_ITEM X509_PUBKEY_it; int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey); EVP_PKEY * X509_PUBKEY_get(X509_PUBKEY *key); +EVP_PKEY * X509_PUBKEY_get0(X509_PUBKEY *key); int X509_get_pubkey_parameters(EVP_PKEY *pkey, STACK_OF(X509) *chain); int i2d_PUBKEY(EVP_PKEY *a,unsigned char **pp); -- cgit v1.2.3-55-g6feb