summaryrefslogtreecommitdiff
path: root/ssh-dss.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2022-10-28 00:39:29 +0000
committerDamien Miller <djm@mindrot.org>2022-10-28 12:46:58 +1100
commit262647c2e920492ca57f1b9320d74f4a0f6e482b (patch)
tree1ce89f627b8230d5ce9611ebe698e5b3f4338fa1 /ssh-dss.c
parent401c74e7dc15eab60540653d2f94d9306a927bab (diff)
downloadopenssh-git-262647c2e920492ca57f1b9320d74f4a0f6e482b.tar.gz
upstream: factor out key generation
feedback/ok markus@ OpenBSD-Commit-ID: 5b4211bff4de8d9adb84bc72857a8c42c44e7ceb
Diffstat (limited to 'ssh-dss.c')
-rw-r--r--ssh-dss.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/ssh-dss.c b/ssh-dss.c
index e955fdd5..bc8fb4e1 100644
--- a/ssh-dss.c
+++ b/ssh-dss.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-dss.c,v 1.42 2022/10/28 00:37:24 djm Exp $ */
+/* $OpenBSD: ssh-dss.c,v 1.43 2022/10/28 00:39:29 djm Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
*
@@ -126,6 +126,24 @@ ssh_dss_serialize_public(const struct sshkey *key, struct sshbuf *b,
return 0;
}
+static int
+ssh_dss_generate(struct sshkey *k, int bits)
+{
+ DSA *private;
+
+ if (bits != 1024)
+ return SSH_ERR_KEY_LENGTH;
+ if ((private = DSA_new()) == NULL)
+ return SSH_ERR_ALLOC_FAIL;
+ if (!DSA_generate_parameters_ex(private, bits, NULL, 0, NULL,
+ NULL, NULL) || !DSA_generate_key(private)) {
+ DSA_free(private);
+ return SSH_ERR_LIBCRYPTO_ERROR;
+ }
+ k->dsa = private;
+ 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)
@@ -289,6 +307,7 @@ static const struct sshkey_impl_funcs sshkey_dss_funcs = {
/* .cleanup = */ ssh_dss_cleanup,
/* .equal = */ ssh_dss_equal,
/* .ssh_serialize_public = */ ssh_dss_serialize_public,
+ /* .generate = */ ssh_dss_generate,
};
const struct sshkey_impl sshkey_dss_impl = {