aboutsummaryrefslogtreecommitdiff
path: root/src/pki.c
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2011-09-24 01:36:58 +0200
committerAris Adamantiadis <aris@0xbadc0de.be>2011-09-24 01:36:58 +0200
commite38f2f933b3f091fa4d9beed917e31f82bcf6a1c (patch)
tree528ed58a85c5c31ec6d257559af6164d223a06b8 /src/pki.c
parent21d68112b869697a54536086956545543cbe9ec6 (diff)
downloadlibssh-e38f2f933b3f091fa4d9beed917e31f82bcf6a1c.tar.gz
libssh-e38f2f933b3f091fa4d9beed917e31f82bcf6a1c.tar.xz
libssh-e38f2f933b3f091fa4d9beed917e31f82bcf6a1c.zip
pki: ssh_pki_generate
for both gcrypt and openssl
Diffstat (limited to 'src/pki.c')
-rw-r--r--src/pki.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/pki.c b/src/pki.c
index d0e52c44..c6f0e5f8 100644
--- a/src/pki.c
+++ b/src/pki.c
@@ -790,6 +790,49 @@ int ssh_pki_import_pubkey_file(const char *filename, ssh_key *pkey)
}
/**
+ * @brief Generates a keypair.
+ * @param[in] type Type of key to create
+ * @param[in] parameter Parameter to the creation of key:
+ * rsa : length of the key in bits (e.g. 1024, 2048, 4096)
+ * dsa : length of the key in bits (e.g. 1024, 2048, 3072)
+ * ecdsa : not implemented
+ * @param[out] pkey A pointer to store the private key. You need to free the
+ * memory.
+ * @return SSH_OK on success, SSH_ERROR on error.
+ * @warning Generating a key pair may take some time.
+ */
+
+int ssh_pki_generate(enum ssh_keytypes_e type, int parameter,
+ ssh_key *pkey){
+ int rc;
+ ssh_key key = ssh_key_new();
+ switch(type){
+ case SSH_KEYTYPE_RSA:
+ case SSH_KEYTYPE_RSA1:
+ rc = pki_key_generate_rsa(key, parameter);
+ if(rc == SSH_ERROR)
+ goto error;
+ break;
+ case SSH_KEYTYPE_DSS:
+ rc = pki_key_generate_dss(key, parameter);
+ if(rc == SSH_ERROR)
+ goto error;
+ break;
+ case SSH_KEYTYPE_ECDSA:
+ case SSH_KEYTYPE_UNKNOWN:
+ goto error;
+ }
+ key->type = type;
+ key->type_c = ssh_key_type_to_char(type);
+ key->flags = SSH_KEY_FLAG_PRIVATE | SSH_KEY_FLAG_PUBLIC;
+ *pkey = key;
+ return SSH_OK;
+error:
+ ssh_key_free(key);
+ return SSH_ERROR;
+}
+
+/**
* @brief Create a public key from a private key.
*
* @param[in] privkey The private key to get the public key from.