summaryrefslogtreecommitdiffstats
path: root/ssh-ecdsa.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2022-10-28 02:37:24 +0200
committerDamien Miller <djm@mindrot.org>2022-10-28 03:46:57 +0200
commit591fed94e66a016acf87f4b7cd416ce812f2abe8 (patch)
tree03a5ee7575f669585607ae1502d7c05e8292f9f1 /ssh-ecdsa.c
parentupstream: factor out sshkey_equal_public() (diff)
downloadopenssh-591fed94e66a016acf87f4b7cd416ce812f2abe8.tar.xz
openssh-591fed94e66a016acf87f4b7cd416ce812f2abe8.zip
upstream: factor out public key serialization
feedback/ok markus@ OpenBSD-Commit-ID: a3570c4b97290c5662890aea7328d87f55939033
Diffstat (limited to 'ssh-ecdsa.c')
-rw-r--r--ssh-ecdsa.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/ssh-ecdsa.c b/ssh-ecdsa.c
index 85fa15c49..24f66bdc0 100644
--- a/ssh-ecdsa.c
+++ b/ssh-ecdsa.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-ecdsa.c,v 1.18 2022/10/28 00:36:31 djm Exp $ */
+/* $OpenBSD: ssh-ecdsa.c,v 1.19 2022/10/28 00:37:24 djm Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
* Copyright (c) 2010 Damien Miller. All rights reserved.
@@ -87,9 +87,27 @@ ssh_ecdsa_equal(const struct sshkey *a, const struct sshkey *b)
return 0;
if (EC_POINT_cmp(grp_a, pub_a, pub_b, NULL) != 0)
return 0;
+
return 1;
}
+static int
+ssh_ecdsa_serialize_public(const struct sshkey *key, struct sshbuf *b,
+ const char *typename, enum sshkey_serialize_rep opts)
+{
+ int r;
+
+ if (key->ecdsa == NULL)
+ return SSH_ERR_INVALID_ARGUMENT;
+ if ((r = sshbuf_put_cstring(b, typename)) != 0 ||
+ (r = sshbuf_put_cstring(b,
+ sshkey_curve_nid_to_name(key->ecdsa_nid))) != 0 ||
+ (r = sshbuf_put_eckey(b, key->ecdsa)) != 0)
+ return r;
+
+ return 0;
+}
+
/* ARGSUSED */
int
ssh_ecdsa_sign(const struct sshkey *key, u_char **sigp, size_t *lenp,
@@ -248,6 +266,7 @@ const struct sshkey_impl_funcs sshkey_ecdsa_funcs = {
/* .alloc = */ NULL,
/* .cleanup = */ ssh_ecdsa_cleanup,
/* .equal = */ ssh_ecdsa_equal,
+ /* .ssh_serialize_public = */ ssh_ecdsa_serialize_public,
};
const struct sshkey_impl sshkey_ecdsa_nistp256_impl = {