+ return PEM_read_PUBKEY_ex(fp, x, cb, u, NULL, NULL);
+}
+#endif
+
+EVP_PKEY *PEM_read_bio_PrivateKey_ex(BIO *bp, EVP_PKEY **x,
+ pem_password_cb *cb, void *u,
+ OSSL_LIB_CTX *libctx, const char *propq)
+{
+ return pem_read_bio_key(bp, x, cb, u, libctx, propq,
+ /* we also want the public key, if available */
+ EVP_PKEY_KEYPAIR);
+}
+
+EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb,
+ void *u)
+{
+ return PEM_read_bio_PrivateKey_ex(bp, x, cb, u, NULL, NULL);
+}
+
+PEM_write_cb_ex_fnsig(PrivateKey, EVP_PKEY, BIO, write_bio)
+{
+ IMPLEMENT_PEM_provided_write_body_vars(pkey, PrivateKey, propq);
+
+ IMPLEMENT_PEM_provided_write_body_pass();
+ IMPLEMENT_PEM_provided_write_body_main(pkey, bio);
+
+ legacy:
+ if (x != NULL && (x->ameth == NULL || x->ameth->priv_encode != NULL))
+ return PEM_write_bio_PKCS8PrivateKey(out, x, enc,
+ (const char *)kstr, klen, cb, u);
+ return PEM_write_bio_PrivateKey_traditional(out, x, enc, kstr, klen, cb, u);
+}
+
+PEM_write_cb_fnsig(PrivateKey, EVP_PKEY, BIO, write_bio)
+{
+ return PEM_write_bio_PrivateKey_ex(out, x, enc, kstr, klen, cb, u,
+ NULL, NULL);
+}
+
+/*
+ * Note: there is no way to tell a provided pkey encoder to use "traditional"
+ * encoding. Therefore, if the pkey is provided, we try to take a copy
+ */
+int PEM_write_bio_PrivateKey_traditional(BIO *bp, const EVP_PKEY *x,
+ const EVP_CIPHER *enc,
+ const unsigned char *kstr, int klen,
+ pem_password_cb *cb, void *u)
+{
+ char pem_str[80];
+ EVP_PKEY *copy = NULL;