summaryrefslogtreecommitdiffstats
path: root/ssh-ecdsa.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2022-10-28 02:41:17 +0200
committerDamien Miller <djm@mindrot.org>2022-10-28 03:46:59 +0200
commit7d00799c935271ce89300494c5677190779f6453 (patch)
tree14b674e5ef56ed3f05af8b38c446b8f1cf5c2f39 /ssh-ecdsa.c
parentupstream: factor out key generation (diff)
downloadopenssh-7d00799c935271ce89300494c5677190779f6453.tar.xz
openssh-7d00799c935271ce89300494c5677190779f6453.zip
upstream: refactor sshkey_from_private()
feedback/ok markus@ OpenBSD-Commit-ID: e5dbe7a3545930c50f70ee75c867a1e08b382b53
Diffstat (limited to 'ssh-ecdsa.c')
-rw-r--r--ssh-ecdsa.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/ssh-ecdsa.c b/ssh-ecdsa.c
index 16a8ea877..271285c9f 100644
--- a/ssh-ecdsa.c
+++ b/ssh-ecdsa.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-ecdsa.c,v 1.20 2022/10/28 00:39:29 djm Exp $ */
+/* $OpenBSD: ssh-ecdsa.c,v 1.21 2022/10/28 00:41:17 djm Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
* Copyright (c) 2010 Damien Miller. All rights reserved.
@@ -126,6 +126,18 @@ ssh_ecdsa_generate(struct sshkey *k, int bits)
return 0;
}
+static int
+ssh_ecdsa_copy_public(const struct sshkey *from, struct sshkey *to)
+{
+ to->ecdsa_nid = from->ecdsa_nid;
+ if ((to->ecdsa = EC_KEY_new_by_curve_name(from->ecdsa_nid)) == NULL)
+ return SSH_ERR_ALLOC_FAIL;
+ if (EC_KEY_set_public_key(to->ecdsa,
+ EC_KEY_get0_public_key(from->ecdsa)) != 1)
+ return SSH_ERR_LIBCRYPTO_ERROR; /* caller will free k->ecdsa */
+ return 0;
+}
+
/* ARGSUSED */
int
ssh_ecdsa_sign(const struct sshkey *key, u_char **sigp, size_t *lenp,
@@ -286,6 +298,7 @@ const struct sshkey_impl_funcs sshkey_ecdsa_funcs = {
/* .equal = */ ssh_ecdsa_equal,
/* .ssh_serialize_public = */ ssh_ecdsa_serialize_public,
/* .generate = */ ssh_ecdsa_generate,
+ /* .copy_public = */ ssh_ecdsa_copy_public,
};
const struct sshkey_impl sshkey_ecdsa_nistp256_impl = {