Prepare to provide PEM_write_bio_PrivateKey_traditional()
authortb <tb@openbsd.org>
Fri, 24 Dec 2021 12:59:17 +0000 (12:59 +0000)
committertb <tb@openbsd.org>
Fri, 24 Dec 2021 12:59:17 +0000 (12:59 +0000)
This will be needed in openssl-ruby after the bump.
Part of OpenSSL commit 05dba815.

ok inoguchi jsing

lib/libcrypto/pem/pem.h
lib/libcrypto/pem/pem_pkey.c

index 01c7174..b447dc4 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: pem.h,v 1.20 2021/10/31 16:28:50 tb Exp $ */
+/* $OpenBSD: pem.h,v 1.21 2021/12/24 12:59:17 tb Exp $ */
 /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
@@ -482,6 +482,11 @@ DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY)
 
 DECLARE_PEM_rw(PUBKEY, EVP_PKEY)
 
+#if defined(LIBRESSL_NEXT_API) || defined(LIBRESSL_CRYPTO_INTERNAL)
+int PEM_write_bio_PrivateKey_traditional(BIO *bp, EVP_PKEY *x,
+    const EVP_CIPHER *enc, unsigned char *kstr, int klen, pem_password_cb *cb,
+    void *u);
+#endif
 int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,
     char *kstr, int klen,
     pem_password_cb *cb, void *u);
index 8f4fba2..2e58003 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: pem_pkey.c,v 1.24 2021/12/12 21:30:14 tb Exp $ */
+/* $OpenBSD: pem_pkey.c,v 1.25 2021/12/24 12:59:18 tb Exp $ */
 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
@@ -152,12 +152,21 @@ int
 PEM_write_bio_PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
     unsigned char *kstr, int klen, pem_password_cb *cb, void *u)
 {
-       char pem_str[80];
-
-       if (!x->ameth || x->ameth->priv_encode)
+       if (x->ameth == NULL || x->ameth->priv_encode != NULL)
                return PEM_write_bio_PKCS8PrivateKey(bp, x, enc,
                    (char *)kstr, klen, cb, u);
 
+       return PEM_write_bio_PrivateKey_traditional(bp, x, enc, kstr, klen, cb,
+           u);
+}
+
+int
+PEM_write_bio_PrivateKey_traditional(BIO *bp, EVP_PKEY *x,
+    const EVP_CIPHER *enc, unsigned char *kstr, int klen, pem_password_cb *cb,
+    void *u)
+{
+       char pem_str[80];
+
        (void) snprintf(pem_str, sizeof(pem_str), "%s PRIVATE KEY",
            x->ameth->pem_str);
        return PEM_ASN1_write_bio((i2d_of_void *)i2d_PrivateKey,