summaryrefslogtreecommitdiff
path: root/ssh-rsa.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2022-10-28 00:36:31 +0000
committerDamien Miller <djm@mindrot.org>2022-10-28 12:46:56 +1100
commit1e78844ae2b2dc01ba735d5ae740904c57e13685 (patch)
tree9aaea84e13b641b1cc04dd9446d4af46c0a0919b /ssh-rsa.c
parent25de1c01a8b9a2c8ab9b1da22444a03e89c982de (diff)
downloadopenssh-git-1e78844ae2b2dc01ba735d5ae740904c57e13685.tar.gz
upstream: factor out sshkey_equal_public()
feedback/ok markus@ OpenBSD-Commit-ID: 1368ba114cb37732fe6ec3d89c7e6d27ea6fdc94
Diffstat (limited to 'ssh-rsa.c')
-rw-r--r--ssh-rsa.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/ssh-rsa.c b/ssh-rsa.c
index e7225e82..345d9a8d 100644
--- a/ssh-rsa.c
+++ b/ssh-rsa.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-rsa.c,v 1.69 2022/10/28 00:35:40 djm Exp $ */
+/* $OpenBSD: ssh-rsa.c,v 1.70 2022/10/28 00:36:31 djm Exp $ */
/*
* Copyright (c) 2000, 2003 Markus Friedl <markus@openbsd.org>
*
@@ -65,6 +65,27 @@ ssh_rsa_cleanup(struct sshkey *k)
k->rsa = NULL;
}
+static int
+ssh_rsa_equal(const struct sshkey *a, const struct sshkey *b)
+{
+ const BIGNUM *rsa_e_a, *rsa_n_a;
+ const BIGNUM *rsa_e_b, *rsa_n_b;
+
+ if (a->rsa == NULL || b->rsa == NULL)
+ return 0;
+ RSA_get0_key(a->rsa, &rsa_n_a, &rsa_e_a, NULL);
+ RSA_get0_key(b->rsa, &rsa_n_b, &rsa_e_b, NULL);
+ if (rsa_e_a == NULL || rsa_e_b == NULL)
+ return 0;
+ if (rsa_n_a == NULL || rsa_n_b == NULL)
+ return 0;
+ if (BN_cmp(rsa_e_a, rsa_e_b) != 0)
+ return 0;
+ if (BN_cmp(rsa_n_a, rsa_n_b) != 0)
+ return 0;
+ return 1;
+}
+
static const char *
rsa_hash_alg_ident(int hash_alg)
{
@@ -477,6 +498,7 @@ static const struct sshkey_impl_funcs sshkey_rsa_funcs = {
/* .size = */ ssh_rsa_size,
/* .alloc = */ ssh_rsa_alloc,
/* .cleanup = */ ssh_rsa_cleanup,
+ /* .equal = */ ssh_rsa_equal,
};
const struct sshkey_impl sshkey_rsa_impl = {