summaryrefslogtreecommitdiff
path: root/ssh-rsa.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2022-10-28 00:41:17 +0000
committerDamien Miller <djm@mindrot.org>2022-10-28 12:46:59 +1100
commit7d00799c935271ce89300494c5677190779f6453 (patch)
tree14b674e5ef56ed3f05af8b38c446b8f1cf5c2f39 /ssh-rsa.c
parent262647c2e920492ca57f1b9320d74f4a0f6e482b (diff)
downloadopenssh-git-7d00799c935271ce89300494c5677190779f6453.tar.gz
upstream: refactor sshkey_from_private()
feedback/ok markus@ OpenBSD-Commit-ID: e5dbe7a3545930c50f70ee75c867a1e08b382b53
Diffstat (limited to 'ssh-rsa.c')
-rw-r--r--ssh-rsa.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/ssh-rsa.c b/ssh-rsa.c
index 87956a46..10585387 100644
--- a/ssh-rsa.c
+++ b/ssh-rsa.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-rsa.c,v 1.72 2022/10/28 00:39:29 djm Exp $ */
+/* $OpenBSD: ssh-rsa.c,v 1.73 2022/10/28 00:41:17 djm Exp $ */
/*
* Copyright (c) 2000, 2003 Markus Friedl <markus@openbsd.org>
*
@@ -132,6 +132,32 @@ ssh_rsa_generate(struct sshkey *k, int bits)
return ret;
}
+static int
+ssh_rsa_copy_public(const struct sshkey *from, struct sshkey *to)
+{
+ const BIGNUM *rsa_n, *rsa_e;
+ BIGNUM *rsa_n_dup = NULL, *rsa_e_dup = NULL;
+ int r = SSH_ERR_INTERNAL_ERROR;
+
+ RSA_get0_key(from->rsa, &rsa_n, &rsa_e, NULL);
+ if ((rsa_n_dup = BN_dup(rsa_n)) == NULL ||
+ (rsa_e_dup = BN_dup(rsa_e)) == NULL) {
+ r = SSH_ERR_ALLOC_FAIL;
+ goto out;
+ }
+ if (!RSA_set0_key(to->rsa, rsa_n_dup, rsa_e_dup, NULL)) {
+ r = SSH_ERR_LIBCRYPTO_ERROR;
+ goto out;
+ }
+ rsa_n_dup = rsa_e_dup = NULL; /* transferred */
+ /* success */
+ r = 0;
+ out:
+ BN_clear_free(rsa_n_dup);
+ BN_clear_free(rsa_e_dup);
+ return r;
+}
+
static const char *
rsa_hash_alg_ident(int hash_alg)
{
@@ -547,6 +573,7 @@ static const struct sshkey_impl_funcs sshkey_rsa_funcs = {
/* .equal = */ ssh_rsa_equal,
/* .ssh_serialize_public = */ ssh_rsa_serialize_public,
/* .generate = */ ssh_rsa_generate,
+ /* .copy_public = */ ssh_rsa_copy_public,
};
const struct sshkey_impl sshkey_rsa_impl = {