summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1
diff options
context:
space:
mode:
authorjsing <>2018-03-17 14:55:39 +0000
committerjsing <>2018-03-17 14:55:39 +0000
commit53236ab726f2cb84436bc0cc39769e610cad136d (patch)
tree5be15ff9269fc26dff6867c5918dcb7f2e3f9d19 /src/lib/libcrypto/asn1
parent5d52c81e051f774e2609496afe66914cc601d068 (diff)
downloadopenbsd-53236ab726f2cb84436bc0cc39769e610cad136d.tar.gz
openbsd-53236ab726f2cb84436bc0cc39769e610cad136d.tar.bz2
openbsd-53236ab726f2cb84436bc0cc39769e610cad136d.zip
Provide X509_PUBKEY_get0() by splitting X509_PUBKEY_get() and turning it
into a wrapper that calls X509_PUBKEY_get0() and up refs.
Diffstat (limited to 'src/lib/libcrypto/asn1')
-rw-r--r--src/lib/libcrypto/asn1/x_pubkey.c22
1 files changed, 16 insertions, 6 deletions
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 @@
1/* $OpenBSD: x_pubkey.c,v 1.26 2017/01/29 17:49:22 beck Exp $ */ 1/* $OpenBSD: x_pubkey.c,v 1.27 2018/03/17 14:55:39 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -175,17 +175,15 @@ error:
175} 175}
176 176
177EVP_PKEY * 177EVP_PKEY *
178X509_PUBKEY_get(X509_PUBKEY *key) 178X509_PUBKEY_get0(X509_PUBKEY *key)
179{ 179{
180 EVP_PKEY *ret = NULL; 180 EVP_PKEY *ret = NULL;
181 181
182 if (key == NULL) 182 if (key == NULL)
183 goto error; 183 goto error;
184 184
185 if (key->pkey != NULL) { 185 if (key->pkey != NULL)
186 CRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
187 return key->pkey; 186 return key->pkey;
188 }
189 187
190 if (key->public_key == NULL) 188 if (key->public_key == NULL)
191 goto error; 189 goto error;
@@ -220,7 +218,6 @@ X509_PUBKEY_get(X509_PUBKEY *key)
220 key->pkey = ret; 218 key->pkey = ret;
221 CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY); 219 CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY);
222 } 220 }
223 CRYPTO_add(&ret->references, 1, CRYPTO_LOCK_EVP_PKEY);
224 221
225 return ret; 222 return ret;
226 223
@@ -229,6 +226,19 @@ error:
229 return (NULL); 226 return (NULL);
230} 227}
231 228
229EVP_PKEY *
230X509_PUBKEY_get(X509_PUBKEY *key)
231{
232 EVP_PKEY *pkey;
233
234 if ((pkey = X509_PUBKEY_get0(key)) == NULL)
235 return (NULL);
236
237 CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
238
239 return pkey;
240}
241
232/* Now two pseudo ASN1 routines that take an EVP_PKEY structure 242/* Now two pseudo ASN1 routines that take an EVP_PKEY structure
233 * and encode or decode as X509_PUBKEY 243 * and encode or decode as X509_PUBKEY
234 */ 244 */