summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2021-12-24 12:59:18 +0000
committertb <>2021-12-24 12:59:18 +0000
commit424d5de6055515eb3315450fd86f752066a71c41 (patch)
treecd51fb6842fa5cc823cb316186608d14e1999b27 /src
parent6d0e78d09a83ec5890337baf10efbff2f48b6f9d (diff)
downloadopenbsd-424d5de6055515eb3315450fd86f752066a71c41.tar.gz
openbsd-424d5de6055515eb3315450fd86f752066a71c41.tar.bz2
openbsd-424d5de6055515eb3315450fd86f752066a71c41.zip
Prepare to provide PEM_write_bio_PrivateKey_traditional()
This will be needed in openssl-ruby after the bump. Part of OpenSSL commit 05dba815. ok inoguchi jsing
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/pem/pem.h7
-rw-r--r--src/lib/libcrypto/pem/pem_pkey.c17
2 files changed, 19 insertions, 5 deletions
diff --git a/src/lib/libcrypto/pem/pem.h b/src/lib/libcrypto/pem/pem.h
index 01c7174d39..b447dc4ac2 100644
--- a/src/lib/libcrypto/pem/pem.h
+++ b/src/lib/libcrypto/pem/pem.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: pem.h,v 1.20 2021/10/31 16:28:50 tb Exp $ */ 1/* $OpenBSD: pem.h,v 1.21 2021/12/24 12:59:17 tb Exp $ */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -482,6 +482,11 @@ DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY)
482 482
483DECLARE_PEM_rw(PUBKEY, EVP_PKEY) 483DECLARE_PEM_rw(PUBKEY, EVP_PKEY)
484 484
485#if defined(LIBRESSL_NEXT_API) || defined(LIBRESSL_CRYPTO_INTERNAL)
486int PEM_write_bio_PrivateKey_traditional(BIO *bp, EVP_PKEY *x,
487 const EVP_CIPHER *enc, unsigned char *kstr, int klen, pem_password_cb *cb,
488 void *u);
489#endif
485int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid, 490int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,
486 char *kstr, int klen, 491 char *kstr, int klen,
487 pem_password_cb *cb, void *u); 492 pem_password_cb *cb, void *u);
diff --git a/src/lib/libcrypto/pem/pem_pkey.c b/src/lib/libcrypto/pem/pem_pkey.c
index 8f4fba2f8e..2e5800394e 100644
--- a/src/lib/libcrypto/pem/pem_pkey.c
+++ b/src/lib/libcrypto/pem/pem_pkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pem_pkey.c,v 1.24 2021/12/12 21:30:14 tb Exp $ */ 1/* $OpenBSD: pem_pkey.c,v 1.25 2021/12/24 12:59:18 tb 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 *
@@ -152,12 +152,21 @@ int
152PEM_write_bio_PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, 152PEM_write_bio_PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
153 unsigned char *kstr, int klen, pem_password_cb *cb, void *u) 153 unsigned char *kstr, int klen, pem_password_cb *cb, void *u)
154{ 154{
155 char pem_str[80]; 155 if (x->ameth == NULL || x->ameth->priv_encode != NULL)
156
157 if (!x->ameth || x->ameth->priv_encode)
158 return PEM_write_bio_PKCS8PrivateKey(bp, x, enc, 156 return PEM_write_bio_PKCS8PrivateKey(bp, x, enc,
159 (char *)kstr, klen, cb, u); 157 (char *)kstr, klen, cb, u);
160 158
159 return PEM_write_bio_PrivateKey_traditional(bp, x, enc, kstr, klen, cb,
160 u);
161}
162
163int
164PEM_write_bio_PrivateKey_traditional(BIO *bp, EVP_PKEY *x,
165 const EVP_CIPHER *enc, unsigned char *kstr, int klen, pem_password_cb *cb,
166 void *u)
167{
168 char pem_str[80];
169
161 (void) snprintf(pem_str, sizeof(pem_str), "%s PRIVATE KEY", 170 (void) snprintf(pem_str, sizeof(pem_str), "%s PRIVATE KEY",
162 x->ameth->pem_str); 171 x->ameth->pem_str);
163 return PEM_ASN1_write_bio((i2d_of_void *)i2d_PrivateKey, 172 return PEM_ASN1_write_bio((i2d_of_void *)i2d_PrivateKey,