Jakub Jelen 5d6a14
From eb0d8e708a1f958aecd2d6e2ff2450af488d4c2a Mon Sep 17 00:00:00 2001
Jakub Jelen 5d6a14
From: "djm@openbsd.org" <djm@openbsd.org>
Jakub Jelen 5d6a14
Date: Mon, 15 Jul 2019 13:16:29 +0000
Jakub Jelen 5d6a14
Subject: [PATCH] upstream: support PKCS8 as an optional format for storage of
Jakub Jelen 56fdfa
Jakub Jelen 5d6a14
private keys, enabled via "ssh-keygen -m PKCS8" on operations that save
Jakub Jelen 5d6a14
private keys to disk.
Jakub Jelen 56fdfa
Jakub Jelen 5d6a14
The OpenSSH native key format remains the default, but PKCS8 is a
Jakub Jelen 5d6a14
superior format to PEM if interoperability with non-OpenSSH software
Jakub Jelen 5d6a14
is required, as it may use a less terrible KDF (IIRC PEM uses a single
Jakub Jelen 5d6a14
round of MD5 as a KDF).
Jakub Jelen 5d6a14
Jakub Jelen 5d6a14
adapted from patch by Jakub Jelen via bz3013; ok markus
Jakub Jelen 5d6a14
Jakub Jelen 5d6a14
OpenBSD-Commit-ID: 027824e3bc0b1c243dc5188504526d73a55accb1
Jakub Jelen 5d6a14
---
Jakub Jelen 5d6a14
 authfile.c   |  6 ++--
Jakub Jelen 5d6a14
 ssh-keygen.1 |  9 +++---
Jakub Jelen 5d6a14
 ssh-keygen.c | 25 +++++++++--------
Jakub Jelen 5d6a14
 sshkey.c     | 78 +++++++++++++++++++++++++++++++++++++---------------
Jakub Jelen 5d6a14
 sshkey.h     | 11 ++++++--
Jakub Jelen 5d6a14
 5 files changed, 87 insertions(+), 42 deletions(-)
Jakub Jelen 5d6a14
Jakub Jelen 5d6a14
diff --git a/authfile.c b/authfile.c
Jakub Jelen 5d6a14
index 2166c1689..851c1a8a1 100644
Jakub Jelen 5d6a14
--- a/authfile.c
Jakub Jelen 5d6a14
+++ b/authfile.c
Jakub Jelen 5d6a14
@@ -74,7 +74,7 @@ sshkey_save_private_blob(struct sshbuf *keybuf, const char *filename)
Jakub Jelen 5d6a14
 int
Jakub Jelen 5d6a14
 sshkey_save_private(struct sshkey *key, const char *filename,
Jakub Jelen 5d6a14
     const char *passphrase, const char *comment,
Jakub Jelen 5d6a14
-    int force_new_format, const char *new_format_cipher, int new_format_rounds)
Jakub Jelen 5d6a14
+    int format, const char *openssh_format_cipher, int openssh_format_rounds)
Jakub Jelen 5d6a14
 {
Jakub Jelen 5d6a14
 	struct sshbuf *keyblob = NULL;
Jakub Jelen 5d6a14
 	int r;
Jakub Jelen 5d6a14
@@ -82,7 +82,7 @@ sshkey_save_private(struct sshkey *key, const char *filename,
Jakub Jelen 5d6a14
 	if ((keyblob = sshbuf_new()) == NULL)
Jakub Jelen 5d6a14
 		return SSH_ERR_ALLOC_FAIL;
Jakub Jelen 5d6a14
 	if ((r = sshkey_private_to_fileblob(key, keyblob, passphrase, comment,
Jakub Jelen 5d6a14
-	    force_new_format, new_format_cipher, new_format_rounds)) != 0)
Jakub Jelen 5d6a14
+	    format, openssh_format_cipher, openssh_format_rounds)) != 0)
Jakub Jelen 5d6a14
 		goto out;
Jakub Jelen 5d6a14
 	if ((r = sshkey_save_private_blob(keyblob, filename)) != 0)
Jakub Jelen 5d6a14
 		goto out;
Jakub Jelen 5d6a14
diff --git a/ssh-keygen.1 b/ssh-keygen.1
Jakub Jelen 5d6a14
index f42127c60..8184a1797 100644
Jakub Jelen 5d6a14
--- a/ssh-keygen.1
Jakub Jelen 5d6a14
+++ b/ssh-keygen.1
Jakub Jelen 5d6a14
@@ -419,11 +419,12 @@ The supported key formats are:
Jakub Jelen 5d6a14
 .Dq RFC4716
Jakub Jelen 5d6a14
 (RFC 4716/SSH2 public or private key),
Jakub Jelen 5d6a14
 .Dq PKCS8
Jakub Jelen 5d6a14
-(PEM PKCS8 public key)
Jakub Jelen 5d6a14
+(PKCS8 public or private key)
Jakub Jelen 5d6a14
 or
Jakub Jelen 5d6a14
 .Dq PEM
Jakub Jelen 5d6a14
 (PEM public key).
Jakub Jelen 5d6a14
-The default conversion format is
Jakub Jelen 5d6a14
+By default OpenSSH will write newly-generated private keys in its own
Jakub Jelen 5d6a14
+format, but when converting public keys for export the default format is
Jakub Jelen 5d6a14
 .Dq RFC4716 .
Jakub Jelen 5d6a14
 Setting a format of
Jakub Jelen 5d6a14
 .Dq PEM
Jakub Jelen 5d6a14
diff --git a/ssh-keygen.c b/ssh-keygen.c
Jakub Jelen 5d6a14
index b019a02ff..5dcad1f61 100644
Jakub Jelen 5d6a14
--- a/ssh-keygen.c
Jakub Jelen 5d6a14
+++ b/ssh-keygen.c
Jakub Jelen 5d6a14
@@ -147,11 +147,11 @@ static char *key_type_name = NULL;
Jakub Jelen 5d6a14
 /* Load key from this PKCS#11 provider */
Jakub Jelen 5d6a14
 static char *pkcs11provider = NULL;
Jakub Jelen 5d6a14
 
Jakub Jelen 5d6a14
-/* Use new OpenSSH private key format when writing SSH2 keys instead of PEM */
Jakub Jelen 5d6a14
-static int use_new_format = 1;
Jakub Jelen 5d6a14
+/* Format for writing private keys */
Jakub Jelen 5d6a14
+static int private_key_format = SSHKEY_PRIVATE_OPENSSH;
Jakub Jelen 5d6a14
 
Jakub Jelen 5d6a14
 /* Cipher for new-format private keys */
Jakub Jelen 5d6a14
-static char *new_format_cipher = NULL;
Jakub Jelen 5d6a14
+static char *openssh_format_cipher = NULL;
Jakub Jelen 5d6a14
 
Jakub Jelen 5d6a14
 /*
Jakub Jelen 5d6a14
  * Number of KDF rounds to derive new format keys /
Jakub Jelen 5d6a14
@@ -1048,7 +1048,8 @@ do_gen_all_hostkeys(struct passwd *pw)
Jakub Jelen 5d6a14
 		snprintf(comment, sizeof comment, "%s@%s", pw->pw_name,
Jakub Jelen 5d6a14
 		    hostname);
Jakub Jelen 5d6a14
 		if ((r = sshkey_save_private(private, prv_tmp, "",
Jakub Jelen 5d6a14
-		    comment, use_new_format, new_format_cipher, rounds)) != 0) {
Jakub Jelen 5d6a14
+		    comment, private_key_format, openssh_format_cipher,
Jakub Jelen 5d6a14
+		    rounds)) != 0) {
Jakub Jelen 5d6a14
 			error("Saving key \"%s\" failed: %s",
Jakub Jelen 5d6a14
 			    prv_tmp, ssh_err(r));
Jakub Jelen 5d6a14
 			goto failnext;
Jakub Jelen 5d6a14
@@ -1391,7 +1392,7 @@ do_change_passphrase(struct passwd *pw)
Jakub Jelen 5d6a14
 
Jakub Jelen 5d6a14
 	/* Save the file using the new passphrase. */
Jakub Jelen 5d6a14
 	if ((r = sshkey_save_private(private, identity_file, passphrase1,
Jakub Jelen 5d6a14
-	    comment, use_new_format, new_format_cipher, rounds)) != 0) {
Jakub Jelen 5d6a14
+	    comment, private_key_format, openssh_format_cipher, rounds)) != 0) {
Jakub Jelen 5d6a14
 		error("Saving key \"%s\" failed: %s.",
Jakub Jelen 5d6a14
 		    identity_file, ssh_err(r));
Jakub Jelen 5d6a14
 		explicit_bzero(passphrase1, strlen(passphrase1));
Jakub Jelen 5d6a14
@@ -1480,7 +1481,7 @@ do_change_comment(struct passwd *pw, const char *identity_comment)
Jakub Jelen 5d6a14
 	}
Jakub Jelen 5d6a14
 
Jakub Jelen 5d6a14
 	if (private->type != KEY_ED25519 && private->type != KEY_XMSS &&
Jakub Jelen 5d6a14
-	    !use_new_format) {
Jakub Jelen 5d6a14
+	    private_key_format != SSHKEY_PRIVATE_OPENSSH) {
Jakub Jelen 5d6a14
 		error("Comments are only supported for keys stored in "
Jakub Jelen 5d6a14
 		    "the new format (-o).");
Jakub Jelen 5d6a14
 		explicit_bzero(passphrase, strlen(passphrase));
Jakub Jelen 5d6a14
@@ -1514,7 +1515,8 @@ do_change_comment(struct passwd *pw, const char *identity_comment)
Jakub Jelen 5d6a14
 
Jakub Jelen 5d6a14
 	/* Save the file using the new passphrase. */
Jakub Jelen 5d6a14
 	if ((r = sshkey_save_private(private, identity_file, passphrase,
Jakub Jelen 5d6a14
-	    new_comment, use_new_format, new_format_cipher, rounds)) != 0) {
Jakub Jelen 5d6a14
+	    new_comment, private_key_format, openssh_format_cipher,
Jakub Jelen 5d6a14
+	    rounds)) != 0) {
Jakub Jelen 5d6a14
 		error("Saving key \"%s\" failed: %s",
Jakub Jelen 5d6a14
 		    identity_file, ssh_err(r));
Jakub Jelen 5d6a14
 		explicit_bzero(passphrase, strlen(passphrase));
Jakub Jelen 5d6a14
@@ -2525,11 +2527,12 @@ main(int argc, char **argv)
Jakub Jelen 5d6a14
 			}
Jakub Jelen 5d6a14
 			if (strcasecmp(optarg, "PKCS8") == 0) {
Jakub Jelen 5d6a14
 				convert_format = FMT_PKCS8;
Jakub Jelen 5d6a14
+				private_key_format = SSHKEY_PRIVATE_PKCS8;
Jakub Jelen 5d6a14
 				break;
Jakub Jelen 5d6a14
 			}
Jakub Jelen 5d6a14
 			if (strcasecmp(optarg, "PEM") == 0) {
Jakub Jelen 5d6a14
 				convert_format = FMT_PEM;
Jakub Jelen 5d6a14
-				use_new_format = 0;
Jakub Jelen 5d6a14
+				private_key_format = SSHKEY_PRIVATE_PEM;
Jakub Jelen 5d6a14
 				break;
Jakub Jelen 5d6a14
 			}
Jakub Jelen 5d6a14
 			fatal("Unsupported conversion format \"%s\"", optarg);
Jakub Jelen 5d6a14
@@ -2567,7 +2570,7 @@ main(int argc, char **argv)
Jakub Jelen 5d6a14
 			add_cert_option(optarg);
Jakub Jelen 5d6a14
 			break;
Jakub Jelen 5d6a14
 		case 'Z':
Jakub Jelen 5d6a14
-			new_format_cipher = optarg;
Jakub Jelen 5d6a14
+			openssh_format_cipher = optarg;
Jakub Jelen 5d6a14
 			break;
Jakub Jelen 5d6a14
 		case 'C':
Jakub Jelen 5d6a14
 			identity_comment = optarg;
Jakub Jelen 5d6a14
@@ -2912,7 +2915,7 @@ main(int argc, char **argv)
Jakub Jelen 5d6a14
 
Jakub Jelen 5d6a14
 	/* Save the key with the given passphrase and comment. */
Jakub Jelen 5d6a14
 	if ((r = sshkey_save_private(private, identity_file, passphrase1,
Jakub Jelen 5d6a14
-	    comment, use_new_format, new_format_cipher, rounds)) != 0) {
Jakub Jelen 5d6a14
+	    comment, private_key_format, openssh_format_cipher, rounds)) != 0) {
Jakub Jelen 5d6a14
 		error("Saving key \"%s\" failed: %s",
Jakub Jelen 5d6a14
 		    identity_file, ssh_err(r));
Jakub Jelen 5d6a14
 		explicit_bzero(passphrase1, strlen(passphrase1));
Jakub Jelen 56fdfa
diff --git a/sshkey.c b/sshkey.c
Jakub Jelen 5d6a14
index 6b5ff0485..a0cea9257 100644
Jakub Jelen 56fdfa
--- a/sshkey.c
Jakub Jelen 56fdfa
+++ b/sshkey.c
Jakub Jelen 5d6a14
@@ -3975,10 +3975,10 @@ sshkey_parse_private2(struct sshbuf *blob, int type, const char *passphrase,
Jakub Jelen 5d6a14
 
Jakub Jelen 5d6a14
 
Jakub Jelen 5d6a14
 #ifdef WITH_OPENSSL
Jakub Jelen 5d6a14
-/* convert SSH v2 key in OpenSSL PEM format */
Jakub Jelen 5d6a14
+/* convert SSH v2 key to PEM or PKCS#8 format */
Jakub Jelen 5d6a14
 static int
Jakub Jelen 5d6a14
-sshkey_private_pem_to_blob(struct sshkey *key, struct sshbuf *blob,
Jakub Jelen 5d6a14
-    const char *_passphrase, const char *comment)
Jakub Jelen 5d6a14
+sshkey_private_to_blob_pem_pkcs8(struct sshkey *key, struct sshbuf *blob,
Jakub Jelen 5d6a14
+    int format, const char *_passphrase, const char *comment)
Jakub Jelen 5d6a14
 {
Jakub Jelen 5d6a14
 	int success, r;
Jakub Jelen 5d6a14
 	int blen, len = strlen(_passphrase);
Jakub Jelen 5d6a14
@@ -3988,26 +3988,46 @@ sshkey_private_pem_to_blob(struct sshkey *key, struct sshbuf *buf,
Jakub Jelen 56fdfa
 	const EVP_CIPHER *cipher = (len > 0) ? EVP_aes_128_cbc() : NULL;
Jakub Jelen 56fdfa
 	char *bptr;
Jakub Jelen 56fdfa
 	BIO *bio = NULL;
Jakub Jelen 56fdfa
+	EVP_PKEY *pkey = NULL;
Jakub Jelen 56fdfa
 
Jakub Jelen 56fdfa
 	if (len > 0 && len <= 4)
Jakub Jelen 56fdfa
 		return SSH_ERR_PASSPHRASE_TOO_SHORT;
Jakub Jelen 5d6a14
-	if ((bio = BIO_new(BIO_s_mem())) == NULL)
Jakub Jelen 5d6a14
-		return SSH_ERR_ALLOC_FAIL;
Jakub Jelen 5d6a14
+ 	if ((bio = BIO_new(BIO_s_mem())) == NULL) {
Jakub Jelen 5d6a14
+		r = SSH_ERR_ALLOC_FAIL;
Jakub Jelen 5d6a14
+		goto out;
Jakub Jelen 5d6a14
+ 	}
Jakub Jelen 5d6a14
+
Jakub Jelen 5d6a14
+	if (format == SSHKEY_PRIVATE_PKCS8 && (pkey = EVP_PKEY_new()) == NULL) {
Jakub Jelen 5d6a14
+		r = SSH_ERR_ALLOC_FAIL;
Jakub Jelen 5d6a14
+		goto out;
Jakub Jelen 5d6a14
+ 	}
Jakub Jelen 56fdfa
 
Jakub Jelen 56fdfa
 	switch (key->type) {
Jakub Jelen 56fdfa
 	case KEY_DSA:
Jakub Jelen 56fdfa
-		success = PEM_write_bio_DSAPrivateKey(bio, key->dsa,
Jakub Jelen 56fdfa
-		    cipher, passphrase, len, NULL, NULL);
Jakub Jelen 5d6a14
+		if (format == SSHKEY_PRIVATE_PEM) {
Jakub Jelen 5d6a14
+			success = PEM_write_bio_DSAPrivateKey(bio, key->dsa,
Jakub Jelen 5d6a14
+			    cipher, passphrase, len, NULL, NULL);
Jakub Jelen 5d6a14
+		} else {
Jakub Jelen 5d6a14
+			success = EVP_PKEY_set1_DSA(pkey, key->dsa);
Jakub Jelen 5d6a14
+		}
Jakub Jelen 56fdfa
 		break;
Jakub Jelen 56fdfa
 #ifdef OPENSSL_HAS_ECC
Jakub Jelen 56fdfa
 	case KEY_ECDSA:
Jakub Jelen 56fdfa
-		success = PEM_write_bio_ECPrivateKey(bio, key->ecdsa,
Jakub Jelen 56fdfa
-		    cipher, passphrase, len, NULL, NULL);
Jakub Jelen 5d6a14
+		if (format == SSHKEY_PRIVATE_PEM) {
Jakub Jelen 5d6a14
+			success = PEM_write_bio_ECPrivateKey(bio, key->ecdsa,
Jakub Jelen 5d6a14
+			    cipher, passphrase, len, NULL, NULL);
Jakub Jelen 5d6a14
+		} else {
Jakub Jelen 5d6a14
+			success = EVP_PKEY_set1_EC_KEY(pkey, key->ecdsa);
Jakub Jelen 5d6a14
+		}
Jakub Jelen 56fdfa
 		break;
Jakub Jelen 56fdfa
 #endif
Jakub Jelen 56fdfa
 	case KEY_RSA:
Jakub Jelen 56fdfa
-		success = PEM_write_bio_RSAPrivateKey(bio, key->rsa,
Jakub Jelen 56fdfa
-		    cipher, passphrase, len, NULL, NULL);
Jakub Jelen 5d6a14
+		if (format == SSHKEY_PRIVATE_PEM) {
Jakub Jelen 5d6a14
+			success = PEM_write_bio_RSAPrivateKey(bio, key->rsa,
Jakub Jelen 5d6a14
+			    cipher, passphrase, len, NULL, NULL);
Jakub Jelen 5d6a14
+		} else {
Jakub Jelen 5d6a14
+			success = EVP_PKEY_set1_RSA(pkey, key->rsa);
Jakub Jelen 5d6a14
+		}
Jakub Jelen 56fdfa
 		break;
Jakub Jelen 56fdfa
 	default:
Jakub Jelen 56fdfa
 		success = 0;
Jakub Jelen 5d6a14
@@ -4023,6 +4040,13 @@ sshkey_private_pem_to_blob(struct sshkey *key, struct sshbuf *buf,
Jakub Jelen 56fdfa
 		r = SSH_ERR_LIBCRYPTO_ERROR;
Jakub Jelen 56fdfa
 		goto out;
Jakub Jelen 56fdfa
 	}
Jakub Jelen 5d6a14
+	if (format == SSHKEY_PRIVATE_PKCS8) {
Jakub Jelen 5d6a14
+		if ((success = PEM_write_bio_PrivateKey(bio, pkey, cipher,
Jakub Jelen 5d6a14
+		    passphrase, len, NULL, NULL)) == 0) {
Jakub Jelen 5d6a14
+			r = SSH_ERR_LIBCRYPTO_ERROR;
Jakub Jelen 5d6a14
+			goto out;
Jakub Jelen 5d6a14
+		}
Jakub Jelen 56fdfa
+	}
Jakub Jelen 56fdfa
 	if ((blen = BIO_get_mem_data(bio, &bptr)) <= 0) {
Jakub Jelen 56fdfa
 		r = SSH_ERR_INTERNAL_ERROR;
Jakub Jelen 56fdfa
 		goto out;
Jakub Jelen 5d6a14
@@ -4035,6 +4059,7 @@ sshkey_private_pem_to_blob(struct sshkey *key, struct sshbuf *buf,
Jakub Jelen 56fdfa
 		goto out;
Jakub Jelen 56fdfa
 	r = 0;
Jakub Jelen 56fdfa
  out:
Jakub Jelen 56fdfa
+	EVP_PKEY_free(pkey);
Jakub Jelen 56fdfa
 	BIO_free(bio);
Jakub Jelen 56fdfa
 	return r;
Jakub Jelen 56fdfa
 }
Jakub Jelen 5d6a14
@@ -4046,29 +4071,38 @@ sshkey_private_pem_to_blob(struct sshkey *key, struct sshbuf *buf,
Jakub Jelen 5d6a14
 int
Jakub Jelen 5d6a14
 sshkey_private_to_fileblob(struct sshkey *key, struct sshbuf *blob,
Jakub Jelen 5d6a14
     const char *passphrase, const char *comment,
Jakub Jelen 5d6a14
-    int force_new_format, const char *new_format_cipher, int new_format_rounds)
Jakub Jelen 5d6a14
+    int format, const char *openssh_format_cipher, int openssh_format_rounds)
Jakub Jelen 5d6a14
 {
Jakub Jelen 5d6a14
 	switch (key->type) {
Jakub Jelen 5d6a14
 #ifdef WITH_OPENSSL
Jakub Jelen 5d6a14
 	case KEY_DSA:
Jakub Jelen 5d6a14
 	case KEY_ECDSA:
Jakub Jelen 5d6a14
 	case KEY_RSA:
Jakub Jelen 5d6a14
-		if (force_new_format) {
Jakub Jelen 5d6a14
-			return sshkey_private_to_blob2(key, blob, passphrase,
Jakub Jelen 5d6a14
-			    comment, new_format_cipher, new_format_rounds);
Jakub Jelen 5d6a14
-		}
Jakub Jelen 5d6a14
-		return sshkey_private_pem_to_blob(key, blob,
Jakub Jelen 5d6a14
-		    passphrase, comment);
Jakub Jelen 5d6a14
+		break; /* see below */
Jakub Jelen 5d6a14
 #endif /* WITH_OPENSSL */
Jakub Jelen 5d6a14
 	case KEY_ED25519:
Jakub Jelen 5d6a14
 #ifdef WITH_XMSS
Jakub Jelen 5d6a14
 	case KEY_XMSS:
Jakub Jelen 5d6a14
 #endif /* WITH_XMSS */
Jakub Jelen 5d6a14
 		return sshkey_private_to_blob2(key, blob, passphrase,
Jakub Jelen 5d6a14
-		    comment, new_format_cipher, new_format_rounds);
Jakub Jelen 5d6a14
+		    comment, openssh_format_cipher, openssh_format_rounds);
Jakub Jelen 5d6a14
 	default:
Jakub Jelen 5d6a14
 		return SSH_ERR_KEY_TYPE_UNKNOWN;
Jakub Jelen 5d6a14
 	}
Jakub Jelen 5d6a14
+
Jakub Jelen 5d6a14
+#ifdef WITH_OPENSSL
Jakub Jelen 5d6a14
+	switch (format) {
Jakub Jelen 5d6a14
+	case SSHKEY_PRIVATE_OPENSSH:
Jakub Jelen 5d6a14
+		return sshkey_private_to_blob2(key, blob, passphrase,
Jakub Jelen 5d6a14
+		    comment, openssh_format_cipher, openssh_format_rounds);
Jakub Jelen 5d6a14
+	case SSHKEY_PRIVATE_PEM:
Jakub Jelen 5d6a14
+	case SSHKEY_PRIVATE_PKCS8:
Jakub Jelen 5d6a14
+		return sshkey_private_to_blob_pem_pkcs8(key, blob,
Jakub Jelen 5d6a14
+		    format, passphrase, comment);
Jakub Jelen 5d6a14
+	default:
Jakub Jelen 5d6a14
+		return SSH_ERR_INVALID_ARGUMENT;
Jakub Jelen 5d6a14
+	}
Jakub Jelen 5d6a14
+#endif /* WITH_OPENSSL */
Jakub Jelen 5d6a14
 }
Jakub Jelen 5d6a14
 
Jakub Jelen 5d6a14
 
Jakub Jelen 5d6a14
diff --git a/sshkey.h b/sshkey.h
Jakub Jelen 5d6a14
index 41d159a1b..d30a69cc9 100644
Jakub Jelen 5d6a14
--- a/sshkey.h
Jakub Jelen 5d6a14
+++ b/sshkey.h
Jakub Jelen 5d6a14
@@ -88,6 +88,13 @@ enum sshkey_serialize_rep {
Jakub Jelen 5d6a14
 	SSHKEY_SERIALIZE_INFO = 254,
Jakub Jelen 5d6a14
 };
Jakub Jelen 5d6a14
 
Jakub Jelen 5d6a14
+/* Private key disk formats */
Jakub Jelen 5d6a14
+enum sshkey_private_format {
Jakub Jelen 5d6a14
+	SSHKEY_PRIVATE_OPENSSH = 0,
Jakub Jelen 5d6a14
+	SSHKEY_PRIVATE_PEM = 1,
Jakub Jelen 5d6a14
+	SSHKEY_PRIVATE_PKCS8 = 2,
Jakub Jelen 5d6a14
+};
Jakub Jelen 5d6a14
+
Jakub Jelen 5d6a14
 /* key is stored in external hardware */
Jakub Jelen 5d6a14
 #define SSHKEY_FLAG_EXT		0x0001
Jakub Jelen 5d6a14
 
Jakub Jelen 5d6a14
@@ -221,7 +228,7 @@ int	sshkey_private_deserialize(struct sshbuf *buf,  struct sshkey **keyp);
Jakub Jelen 5d6a14
 /* private key file format parsing and serialisation */
Jakub Jelen 5d6a14
 int	sshkey_private_to_fileblob(struct sshkey *key, struct sshbuf *blob,
Jakub Jelen 5d6a14
     const char *passphrase, const char *comment,
Jakub Jelen 5d6a14
-    int force_new_format, const char *new_format_cipher, int new_format_rounds);
Jakub Jelen 5d6a14
+    int format, const char *openssh_format_cipher, int openssh_format_rounds);
Jakub Jelen 5d6a14
 int	sshkey_parse_private_fileblob(struct sshbuf *buffer,
Jakub Jelen 5d6a14
     const char *passphrase, struct sshkey **keyp, char **commentp);
Jakub Jelen 5d6a14
 int	sshkey_parse_private_fileblob_type(struct sshbuf *blob, int type,
Jakub Jelen 56fdfa