diff options
author | djm@openbsd.org <djm@openbsd.org> | 2022-10-28 02:41:52 +0200 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2022-10-28 03:46:59 +0200 |
commit | a1deb6cdbbe6afaab74ecb08fcb62db5739267be (patch) | |
tree | c5fcd10bde2ab9bdc6cc00da41f5e495bf865021 /ssh-xmss.c | |
parent | upstream: refactor sshkey_from_private() (diff) | |
download | openssh-a1deb6cdbbe6afaab74ecb08fcb62db5739267be.tar.xz openssh-a1deb6cdbbe6afaab74ecb08fcb62db5739267be.zip |
upstream: refactor sshkey_from_blob_internal()
feedback/ok markus@
OpenBSD-Commit-ID: 1f46c0cbb8060ee9666a02749594ad6658c8e283
Diffstat (limited to 'ssh-xmss.c')
-rw-r--r-- | ssh-xmss.c | 40 |
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, }; |