From 6901e25085f8924f9d83e12107c05f935bd24287 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 30 Aug 2011 09:36:06 +0200 Subject: pki_crypto: Add ecdsa support for key duplication. --- src/pki_crypto.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/pki_crypto.c b/src/pki_crypto.c index 7291dc2..29e589f 100644 --- a/src/pki_crypto.c +++ b/src/pki_crypto.c @@ -30,6 +30,14 @@ #include #include +#ifdef HAVE_OPENSSL_EC_H +#include +#endif +#ifdef HAVE_OPENSSL_ECDSA_H +#include +#endif + + #include "libssh/priv.h" #include "libssh/libssh.h" #include "libssh/buffer.h" @@ -200,6 +208,29 @@ ssh_key pki_key_dup(const ssh_key key, int demote) break; case SSH_KEYTYPE_ECDSA: + /* privkey -> pubkey */ + if (demote && ssh_key_is_private(key)) { + const EC_POINT *p; + int ok; + + new->ecdsa = EC_KEY_new_by_curve_name(key->ecdsa_nid); + if (new->ecdsa == NULL) { + goto fail; + } + + p = EC_KEY_get0_public_key(key->ecdsa); + if (p == NULL) { + goto fail; + } + + ok = EC_KEY_set_public_key(new->ecdsa, p); + if (!ok) { + goto fail; + } + } else { + new->ecdsa = EC_KEY_dup(key->ecdsa); + } + break; case SSH_KEYTYPE_UNKNOWN: ssh_key_free(new); return NULL; -- cgit