summaryrefslogtreecommitdiffstats
path: root/ssh-xmss.c
diff options
context:
space:
mode:
Diffstat (limited to 'ssh-xmss.c')
-rw-r--r--ssh-xmss.c40
1 files changed, 36 insertions, 4 deletions
diff --git a/ssh-xmss.c b/ssh-xmss.c
index ef0fed167..039436b43 100644
--- a/ssh-xmss.c
+++ b/ssh-xmss.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-xmss.c,v 1.10 2022/10/28 00:41:17 djm Exp $*/
+/* $OpenBSD: ssh-xmss.c,v 1.11 2022/10/28 00:41:52 djm Exp $*/
/*
* Copyright (c) 2017 Stefan-Lukas Gazdag.
* Copyright (c) 2017 Markus Friedl.
@@ -65,15 +65,14 @@ ssh_xmss_equal(const struct sshkey *a, const struct sshkey *b)
static int
ssh_xmss_serialize_public(const struct sshkey *key, struct sshbuf *b,
- const char *typename, enum sshkey_serialize_rep opts)
+ enum sshkey_serialize_rep opts)
{
int r;
if (key->xmss_name == NULL || key->xmss_pk == NULL ||
sshkey_xmss_pklen(key) == 0)
return SSH_ERR_INVALID_ARGUMENT;
- if ((r = sshbuf_put_cstring(b, typename)) != 0 ||
- (r = sshbuf_put_cstring(b, key->xmss_name)) != 0 ||
+ if ((r = sshbuf_put_cstring(b, key->xmss_name)) != 0 ||
(r = sshbuf_put_string(b, key->xmss_pk,
sshkey_xmss_pklen(key))) != 0 ||
(r = sshkey_xmss_serialize_pk_info(key, b, opts)) != 0)
@@ -107,6 +106,38 @@ ssh_xmss_copy_public(const struct sshkey *from, struct sshkey *to)
return 0;
}
+static int
+ssh_xmss_deserialize_public(const char *ktype, struct sshbuf *b,
+ struct sshkey *key)
+{
+ size_t len = 0;
+ char *xmss_name = NULL;
+ u_char *pk = NULL;
+ int ret = SSH_ERR_INTERNAL_ERROR;
+
+ if ((ret = sshbuf_get_cstring(b, &xmss_name, NULL)) != 0)
+ goto out;
+ if ((ret = sshkey_xmss_init(key, xmss_name)) != 0)
+ goto out;
+ if ((ret = sshbuf_get_string(b, &pk, &len)) != 0)
+ goto out;
+ if (len == 0 || len != sshkey_xmss_pklen(key)) {
+ ret = SSH_ERR_INVALID_FORMAT;
+ goto out;
+ }
+ key->xmss_pk = pk;
+ pk = NULL;
+ if (!sshkey_is_cert(key) &&
+ (ret = sshkey_xmss_deserialize_pk_info(key, b)) != 0)
+ goto out;
+ /* success */
+ ret = 0;
+ out:
+ free(xmss_name);
+ freezero(pk, len);
+ return ret;
+}
+
int
ssh_xmss_sign(const struct sshkey *key, u_char **sigp, size_t *lenp,
const u_char *data, size_t datalen, u_int compat)
@@ -261,6 +292,7 @@ static const struct sshkey_impl_funcs sshkey_xmss_funcs = {
/* .cleanup = */ ssh_xmss_cleanup,
/* .equal = */ ssh_xmss_equal,
/* .ssh_serialize_public = */ ssh_xmss_serialize_public,
+ /* .ssh_deserialize_public = */ ssh_xmss_deserialize_public,
/* .generate = */ sshkey_xmss_generate_private_key,
/* .copy_public = */ ssh_xmss_copy_public,
};