diff options
author | djm@openbsd.org <djm@openbsd.org> | 2022-10-28 02:44:44 +0200 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2022-10-28 03:47:01 +0200 |
commit | 27267642699342412964aa785b98afd69d952c88 (patch) | |
tree | b2aa59e6b542da8a1ece82e337cf38e4c253067b /ssh-ed25519.c | |
parent | upstream: refactor sshkey_private_serialize_opt() (diff) | |
download | openssh-27267642699342412964aa785b98afd69d952c88.tar.xz openssh-27267642699342412964aa785b98afd69d952c88.zip |
upstream: refactor sshkey_private_deserialize
feedback/ok markus@
OpenBSD-Commit-ID: f5ca6932fdaf840a5e8250becb38315a29b5fc9f
Diffstat (limited to 'ssh-ed25519.c')
-rw-r--r-- | ssh-ed25519.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/ssh-ed25519.c b/ssh-ed25519.c index 2707361b1..22d8db026 100644 --- a/ssh-ed25519.c +++ b/ssh-ed25519.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssh-ed25519.c,v 1.18 2022/10/28 00:44:17 djm Exp $ */ +/* $OpenBSD: ssh-ed25519.c,v 1.19 2022/10/28 00:44:44 djm Exp $ */ /* * Copyright (c) 2013 Markus Friedl <markus@openbsd.org> * @@ -118,6 +118,31 @@ ssh_ed25519_deserialize_public(const char *ktype, struct sshbuf *b, } static int +ssh_ed25519_deserialize_private(const char *ktype, struct sshbuf *b, + struct sshkey *key) +{ + int r; + size_t sklen = 0; + u_char *ed25519_sk = NULL; + + if ((r = ssh_ed25519_deserialize_public(NULL, b, key)) != 0) + goto out; + if ((r = sshbuf_get_string(b, &ed25519_sk, &sklen)) != 0) + goto out; + if (sklen != ED25519_SK_SZ) { + r = SSH_ERR_INVALID_FORMAT; + goto out; + } + key->ed25519_sk = ed25519_sk; + ed25519_sk = NULL; /* transferred */ + /* success */ + r = 0; + out: + freezero(ed25519_sk, sklen); + return r; +} + +static int ssh_ed25519_sign(struct sshkey *key, u_char **sigp, size_t *lenp, const u_char *data, size_t datalen, @@ -256,6 +281,7 @@ const struct sshkey_impl_funcs sshkey_ed25519_funcs = { /* .ssh_serialize_public = */ ssh_ed25519_serialize_public, /* .ssh_deserialize_public = */ ssh_ed25519_deserialize_public, /* .ssh_serialize_private = */ ssh_ed25519_serialize_private, + /* .ssh_deserialize_private = */ ssh_ed25519_deserialize_private, /* .generate = */ ssh_ed25519_generate, /* .copy_public = */ ssh_ed25519_copy_public, /* .sign = */ ssh_ed25519_sign, |