summaryrefslogtreecommitdiff
path: root/ssh-dss.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2022-10-28 00:37:24 +0000
committerDamien Miller <djm@mindrot.org>2022-10-28 12:46:57 +1100
commit591fed94e66a016acf87f4b7cd416ce812f2abe8 (patch)
tree03a5ee7575f669585607ae1502d7c05e8292f9f1 /ssh-dss.c
parent1e78844ae2b2dc01ba735d5ae740904c57e13685 (diff)
downloadopenssh-git-591fed94e66a016acf87f4b7cd416ce812f2abe8.tar.gz
upstream: factor out public key serialization
feedback/ok markus@ OpenBSD-Commit-ID: a3570c4b97290c5662890aea7328d87f55939033
Diffstat (limited to 'ssh-dss.c')
-rw-r--r--ssh-dss.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/ssh-dss.c b/ssh-dss.c
index 15d6cea3..e955fdd5 100644
--- a/ssh-dss.c
+++ b/ssh-dss.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-dss.c,v 1.41 2022/10/28 00:36:31 djm Exp $ */
+/* $OpenBSD: ssh-dss.c,v 1.42 2022/10/28 00:37:24 djm Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
*
@@ -102,6 +102,30 @@ ssh_dss_equal(const struct sshkey *a, const struct sshkey *b)
return 1;
}
+static int
+ssh_dss_serialize_public(const struct sshkey *key, struct sshbuf *b,
+ const char *typename, enum sshkey_serialize_rep opts)
+{
+ int r;
+ const BIGNUM *dsa_p, *dsa_q, *dsa_g, *dsa_pub_key;
+
+ if (key->dsa == NULL)
+ return SSH_ERR_INVALID_ARGUMENT;
+ DSA_get0_pqg(key->dsa, &dsa_p, &dsa_q, &dsa_g);
+ DSA_get0_key(key->dsa, &dsa_pub_key, NULL);
+ if (dsa_p == NULL || dsa_q == NULL ||
+ dsa_g == NULL || dsa_pub_key == NULL)
+ return SSH_ERR_INTERNAL_ERROR;
+ if ((r = sshbuf_put_cstring(b, typename)) != 0 ||
+ (r = sshbuf_put_bignum2(b, dsa_p)) != 0 ||
+ (r = sshbuf_put_bignum2(b, dsa_q)) != 0 ||
+ (r = sshbuf_put_bignum2(b, dsa_g)) != 0 ||
+ (r = sshbuf_put_bignum2(b, dsa_pub_key)) != 0)
+ return r;
+
+ return 0;
+}
+
int
ssh_dss_sign(const struct sshkey *key, u_char **sigp, size_t *lenp,
const u_char *data, size_t datalen, u_int compat)
@@ -264,6 +288,7 @@ static const struct sshkey_impl_funcs sshkey_dss_funcs = {
/* .alloc = */ ssh_dss_alloc,
/* .cleanup = */ ssh_dss_cleanup,
/* .equal = */ ssh_dss_equal,
+ /* .ssh_serialize_public = */ ssh_dss_serialize_public,
};
const struct sshkey_impl sshkey_dss_impl = {