summaryrefslogtreecommitdiffstats
path: root/ssh-ecdsa.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2022-10-28 02:36:31 +0200
committerDamien Miller <djm@mindrot.org>2022-10-28 03:46:56 +0200
commit1e78844ae2b2dc01ba735d5ae740904c57e13685 (patch)
tree9aaea84e13b641b1cc04dd9446d4af46c0a0919b /ssh-ecdsa.c
parentupstream: begin big refactor of sshkey (diff)
downloadopenssh-1e78844ae2b2dc01ba735d5ae740904c57e13685.tar.xz
openssh-1e78844ae2b2dc01ba735d5ae740904c57e13685.zip
upstream: factor out sshkey_equal_public()
feedback/ok markus@ OpenBSD-Commit-ID: 1368ba114cb37732fe6ec3d89c7e6d27ea6fdc94
Diffstat (limited to 'ssh-ecdsa.c')
-rw-r--r--ssh-ecdsa.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/ssh-ecdsa.c b/ssh-ecdsa.c
index e207e43fd..85fa15c49 100644
--- a/ssh-ecdsa.c
+++ b/ssh-ecdsa.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-ecdsa.c,v 1.17 2022/10/28 00:35:40 djm Exp $ */
+/* $OpenBSD: ssh-ecdsa.c,v 1.18 2022/10/28 00:36:31 djm Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
* Copyright (c) 2010 Damien Miller. All rights reserved.
@@ -69,6 +69,27 @@ ssh_ecdsa_cleanup(struct sshkey *k)
k->ecdsa = NULL;
}
+static int
+ssh_ecdsa_equal(const struct sshkey *a, const struct sshkey *b)
+{
+ const EC_GROUP *grp_a, *grp_b;
+ const EC_POINT *pub_a, *pub_b;
+
+ if (a->ecdsa == NULL || b->ecdsa == NULL)
+ return 0;
+ if ((grp_a = EC_KEY_get0_group(a->ecdsa)) == NULL ||
+ (grp_b = EC_KEY_get0_group(b->ecdsa)) == NULL)
+ return 0;
+ if ((pub_a = EC_KEY_get0_public_key(a->ecdsa)) == NULL ||
+ (pub_b = EC_KEY_get0_public_key(b->ecdsa)) == NULL)
+ return 0;
+ if (EC_GROUP_cmp(grp_a, grp_b, NULL) != 0)
+ return 0;
+ if (EC_POINT_cmp(grp_a, pub_a, pub_b, NULL) != 0)
+ return 0;
+ return 1;
+}
+
/* ARGSUSED */
int
ssh_ecdsa_sign(const struct sshkey *key, u_char **sigp, size_t *lenp,
@@ -221,10 +242,12 @@ ssh_ecdsa_verify(const struct sshkey *key,
return ret;
}
-static const struct sshkey_impl_funcs sshkey_ecdsa_funcs = {
+/* NB. not static; used by ECDSA-SK */
+const struct sshkey_impl_funcs sshkey_ecdsa_funcs = {
/* .size = */ ssh_ecdsa_size,
/* .alloc = */ NULL,
/* .cleanup = */ ssh_ecdsa_cleanup,
+ /* .equal = */ ssh_ecdsa_equal,
};
const struct sshkey_impl sshkey_ecdsa_nistp256_impl = {