aboutsummaryrefslogtreecommitdiff
path: root/src/pki_gcrypt.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_gcrypt.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_gcrypt.c')
-rw-r--r--src/pki_gcrypt.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/pki_gcrypt.c b/src/pki_gcrypt.c
index 6f3cd957..2bb99d24 100644
--- a/src/pki_gcrypt.c
+++ b/src/pki_gcrypt.c
@@ -966,6 +966,33 @@ fail:
return NULL;
}
+static int pki_key_generate(ssh_key key, int parameter, const char *type_s, int type){
+ gcry_sexp_t parms;
+ int rc;
+ rc = gcry_sexp_build(&parms,
+ NULL,
+ "(genkey(%s(nbits %d)(transient-key)))",
+ type_s,
+ parameter);
+ if (rc != 0)
+ return SSH_ERROR;
+ if(type == SSH_KEYTYPE_RSA)
+ rc = gcry_pk_genkey(&key->rsa, parms);
+ else
+ rc = gcry_pk_genkey(&key->dsa, parms);
+ gcry_sexp_release(parms);
+ if (rc != 0)
+ return SSH_ERROR;
+ return SSH_OK;
+}
+
+int pki_key_generate_rsa(ssh_key key, int parameter){
+ return pki_key_generate(key, parameter, "rsa", SSH_KEYTYPE_RSA);
+}
+int pki_key_generate_dss(ssh_key key, int parameter){
+ return pki_key_generate(key, parameter, "dsa", SSH_KEYTYPE_DSS);
+}
+
ssh_string pki_publickey_to_blob(const ssh_key key)
{
ssh_buffer buffer;