summaryrefslogtreecommitdiffstats
path: root/ssh-xmss.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-xmss.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-xmss.c')
-rw-r--r--ssh-xmss.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/ssh-xmss.c b/ssh-xmss.c
index da8b4cc30..ef0fed167 100644
--- a/ssh-xmss.c
+++ b/ssh-xmss.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-xmss.c,v 1.9 2022/10/28 00:39:29 djm Exp $*/
+/* $OpenBSD: ssh-xmss.c,v 1.10 2022/10/28 00:41:17 djm Exp $*/
/*
* Copyright (c) 2017 Stefan-Lukas Gazdag.
* Copyright (c) 2017 Markus Friedl.
@@ -82,6 +82,31 @@ ssh_xmss_serialize_public(const struct sshkey *key, struct sshbuf *b,
return 0;
}
+static int
+ssh_xmss_copy_public(const struct sshkey *from, struct sshkey *to)
+{
+ int r = SSH_ERR_INTERNAL_ERROR;
+ u_int32_t left;
+ size_t pklen;
+
+ if ((r = sshkey_xmss_init(to, from->xmss_name)) != 0)
+ return r;
+ if (from->xmss_pk == NULL)
+ return 0; /* XXX SSH_ERR_INTERNAL_ERROR ? */
+
+ if ((pklen = sshkey_xmss_pklen(from)) == 0 ||
+ sshkey_xmss_pklen(to) != pklen)
+ return SSH_ERR_INTERNAL_ERROR;
+ if ((to->xmss_pk = malloc(pklen)) == NULL)
+ return SSH_ERR_ALLOC_FAIL;
+ memcpy(to->xmss_pk, from->xmss_pk, pklen);
+ /* simulate number of signatures left on pubkey */
+ left = sshkey_xmss_signatures_left(from);
+ if (left)
+ sshkey_xmss_enable_maxsign(to, left);
+ return 0;
+}
+
int
ssh_xmss_sign(const struct sshkey *key, u_char **sigp, size_t *lenp,
const u_char *data, size_t datalen, u_int compat)
@@ -237,6 +262,7 @@ static const struct sshkey_impl_funcs sshkey_xmss_funcs = {
/* .equal = */ ssh_xmss_equal,
/* .ssh_serialize_public = */ ssh_xmss_serialize_public,
/* .generate = */ sshkey_xmss_generate_private_key,
+ /* .copy_public = */ ssh_xmss_copy_public,
};
const struct sshkey_impl sshkey_xmss_impl = {