diff options
author | djm@openbsd.org <djm@openbsd.org> | 2022-10-28 00:37:24 +0000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2022-10-28 12:46:57 +1100 |
commit | 591fed94e66a016acf87f4b7cd416ce812f2abe8 (patch) | |
tree | 03a5ee7575f669585607ae1502d7c05e8292f9f1 /ssh-rsa.c | |
parent | 1e78844ae2b2dc01ba735d5ae740904c57e13685 (diff) | |
download | openssh-git-591fed94e66a016acf87f4b7cd416ce812f2abe8.tar.gz |
upstream: factor out public key serialization
feedback/ok markus@
OpenBSD-Commit-ID: a3570c4b97290c5662890aea7328d87f55939033
Diffstat (limited to 'ssh-rsa.c')
-rw-r--r-- | ssh-rsa.c | 21 |
1 files changed, 20 insertions, 1 deletions
@@ -1,4 +1,4 @@ -/* $OpenBSD: ssh-rsa.c,v 1.70 2022/10/28 00:36:31 djm Exp $ */ +/* $OpenBSD: ssh-rsa.c,v 1.71 2022/10/28 00:37:24 djm Exp $ */ /* * Copyright (c) 2000, 2003 Markus Friedl <markus@openbsd.org> * @@ -86,6 +86,24 @@ ssh_rsa_equal(const struct sshkey *a, const struct sshkey *b) return 1; } +static int +ssh_rsa_serialize_public(const struct sshkey *key, struct sshbuf *b, + const char *typename, enum sshkey_serialize_rep opts) +{ + int r; + const BIGNUM *rsa_n, *rsa_e; + + if (key->rsa == NULL) + return SSH_ERR_INVALID_ARGUMENT; + RSA_get0_key(key->rsa, &rsa_n, &rsa_e, NULL); + if ((r = sshbuf_put_cstring(b, typename)) != 0 || + (r = sshbuf_put_bignum2(b, rsa_e)) != 0 || + (r = sshbuf_put_bignum2(b, rsa_n)) != 0) + return r; + + return 0; +} + static const char * rsa_hash_alg_ident(int hash_alg) { @@ -499,6 +517,7 @@ static const struct sshkey_impl_funcs sshkey_rsa_funcs = { /* .alloc = */ ssh_rsa_alloc, /* .cleanup = */ ssh_rsa_cleanup, /* .equal = */ ssh_rsa_equal, + /* .ssh_serialize_public = */ ssh_rsa_serialize_public, }; const struct sshkey_impl sshkey_rsa_impl = { |