summaryrefslogtreecommitdiffstats
path: root/ssh-xmss.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2022-10-28 02:44:44 +0200
committerDamien Miller <djm@mindrot.org>2022-10-28 03:47:01 +0200
commit27267642699342412964aa785b98afd69d952c88 (patch)
treeb2aa59e6b542da8a1ece82e337cf38e4c253067b /ssh-xmss.c
parentupstream: refactor sshkey_private_serialize_opt() (diff)
downloadopenssh-27267642699342412964aa785b98afd69d952c88.tar.xz
openssh-27267642699342412964aa785b98afd69d952c88.zip
upstream: refactor sshkey_private_deserialize
feedback/ok markus@ OpenBSD-Commit-ID: f5ca6932fdaf840a5e8250becb38315a29b5fc9f
Diffstat (limited to 'ssh-xmss.c')
-rw-r--r--ssh-xmss.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/ssh-xmss.c b/ssh-xmss.c
index 2b57b2d79..b3aec0f72 100644
--- a/ssh-xmss.c
+++ b/ssh-xmss.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-xmss.c,v 1.13 2022/10/28 00:44:17 djm Exp $*/
+/* $OpenBSD: ssh-xmss.c,v 1.14 2022/10/28 00:44:44 djm Exp $*/
/*
* Copyright (c) 2017 Stefan-Lukas Gazdag.
* Copyright (c) 2017 Markus Friedl.
@@ -159,6 +159,43 @@ ssh_xmss_deserialize_public(const char *ktype, struct sshbuf *b,
}
static int
+ssh_xmss_deserialize_private(const char *ktype, struct sshbuf *b,
+ struct sshkey *key)
+{
+ int r;
+ char *xmss_name = NULL;
+ size_t pklen = 0, sklen = 0;
+ u_char *xmss_pk = NULL, *xmss_sk = NULL;
+
+ /* Note: can't reuse ssh_xmss_deserialize_public because of sk order */
+ if ((r = sshbuf_get_cstring(b, &xmss_name, NULL)) != 0 ||
+ (r = sshbuf_get_string(b, &xmss_pk, &pklen)) != 0 ||
+ (r = sshbuf_get_string(b, &xmss_sk, &sklen)) != 0)
+ goto out;
+ if (!sshkey_is_cert(key) &&
+ (r = sshkey_xmss_init(key, xmss_name)) != 0)
+ goto out;
+ if (pklen != sshkey_xmss_pklen(key) ||
+ sklen != sshkey_xmss_sklen(key)) {
+ r = SSH_ERR_INVALID_FORMAT;
+ goto out;
+ }
+ key->xmss_pk = xmss_pk;
+ key->xmss_sk = xmss_sk;
+ xmss_pk = xmss_sk = NULL;
+ /* optional internal state */
+ if ((r = sshkey_xmss_deserialize_state_opt(key, b)) != 0)
+ goto out;
+ /* success */
+ r = 0;
+ out:
+ free(xmss_name);
+ freezero(xmss_pk, pklen);
+ freezero(xmss_sk, sklen);
+ return r;
+}
+
+static int
ssh_xmss_sign(struct sshkey *key,
u_char **sigp, size_t *lenp,
const u_char *data, size_t datalen,
@@ -317,6 +354,7 @@ static const struct sshkey_impl_funcs sshkey_xmss_funcs = {
/* .ssh_serialize_public = */ ssh_xmss_serialize_public,
/* .ssh_deserialize_public = */ ssh_xmss_deserialize_public,
/* .ssh_serialize_private = */ ssh_xmss_serialize_private,
+ /* .ssh_deserialize_private = */ ssh_xmss_deserialize_private,
/* .generate = */ sshkey_xmss_generate_private_key,
/* .copy_public = */ ssh_xmss_copy_public,
/* .sign = */ ssh_xmss_sign,