summaryrefslogtreecommitdiff
path: root/kexc25519s.c
diff options
context:
space:
mode:
Diffstat (limited to 'kexc25519s.c')
-rw-r--r--kexc25519s.c136
1 files changed, 0 insertions, 136 deletions
diff --git a/kexc25519s.c b/kexc25519s.c
deleted file mode 100644
index ace4d5c79..000000000
--- a/kexc25519s.c
+++ /dev/null
@@ -1,136 +0,0 @@
1/* $OpenBSD: kexc25519s.c,v 1.16 2019/01/21 10:20:12 djm Exp $ */
2/*
3 * Copyright (c) 2001 Markus Friedl. All rights reserved.
4 * Copyright (c) 2010 Damien Miller. All rights reserved.
5 * Copyright (c) 2013 Aris Adamantiadis. All rights reserved.
6 *
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include "includes.h"
28
29#include <sys/types.h>
30#include <stdio.h>
31#include <string.h>
32#include <signal.h>
33
34#include "sshkey.h"
35#include "cipher.h"
36#include "digest.h"
37#include "kex.h"
38#include "log.h"
39#include "packet.h"
40#include "ssh2.h"
41#include "sshbuf.h"
42#include "ssherr.h"
43
44static int input_kex_c25519_init(int, u_int32_t, struct ssh *);
45
46int
47kexc25519_server(struct ssh *ssh)
48{
49 debug("expecting SSH2_MSG_KEX_ECDH_INIT");
50 ssh_dispatch_set(ssh, SSH2_MSG_KEX_ECDH_INIT, &input_kex_c25519_init);
51 return 0;
52}
53
54static int
55input_kex_c25519_init(int type, u_int32_t seq, struct ssh *ssh)
56{
57 struct kex *kex = ssh->kex;
58 struct sshkey *server_host_private, *server_host_public;
59 struct sshbuf *shared_secret = NULL;
60 u_char *server_host_key_blob = NULL, *signature = NULL;
61 u_char server_key[CURVE25519_SIZE];
62 u_char *client_pubkey = NULL;
63 u_char server_pubkey[CURVE25519_SIZE];
64 u_char hash[SSH_DIGEST_MAX_LENGTH];
65 size_t slen, pklen, sbloblen, hashlen;
66 int r;
67
68 /* generate private key */
69 kexc25519_keygen(server_key, server_pubkey);
70#ifdef DEBUG_KEXECDH
71 dump_digest("server private key:", server_key, sizeof(server_key));
72#endif
73 if ((r = kex_load_hostkey(ssh, &server_host_private,
74 &server_host_public)) != 0)
75 goto out;
76 if ((r = sshpkt_get_string(ssh, &client_pubkey, &pklen)) != 0 ||
77 (r = sshpkt_get_end(ssh)) != 0)
78 goto out;
79 if (pklen != CURVE25519_SIZE) {
80 r = SSH_ERR_SIGNATURE_INVALID;
81 goto out;
82 }
83#ifdef DEBUG_KEXECDH
84 dump_digest("client public key:", client_pubkey, CURVE25519_SIZE);
85#endif
86
87 if ((shared_secret = sshbuf_new()) == NULL) {
88 r = SSH_ERR_ALLOC_FAIL;
89 goto out;
90 }
91 if ((r = kexc25519_shared_key(server_key, client_pubkey,
92 shared_secret)) < 0)
93 goto out;
94
95 /* calc H */
96 if ((r = sshkey_to_blob(server_host_public, &server_host_key_blob,
97 &sbloblen)) != 0)
98 goto out;
99 hashlen = sizeof(hash);
100 if ((r = kex_c25519_hash(
101 kex->hash_alg,
102 kex->client_version,
103 kex->server_version,
104 sshbuf_ptr(kex->peer), sshbuf_len(kex->peer),
105 sshbuf_ptr(kex->my), sshbuf_len(kex->my),
106 server_host_key_blob, sbloblen,
107 client_pubkey, pklen,
108 server_pubkey, sizeof(server_pubkey),
109 sshbuf_ptr(shared_secret), sshbuf_len(shared_secret),
110 hash, &hashlen)) != 0)
111 goto out;
112
113 /* sign H */
114 if ((r = kex->sign(ssh, server_host_private, server_host_public,
115 &signature, &slen, hash, hashlen, kex->hostkey_alg)) < 0)
116 goto out;
117
118 /* send server hostkey, ECDH pubkey 'Q_S' and signed H */
119 if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_ECDH_REPLY)) != 0 ||
120 (r = sshpkt_put_string(ssh, server_host_key_blob, sbloblen)) != 0 ||
121 (r = sshpkt_put_string(ssh, server_pubkey, sizeof(server_pubkey))) != 0 ||
122 (r = sshpkt_put_string(ssh, signature, slen)) != 0 ||
123 (r = sshpkt_send(ssh)) != 0)
124 goto out;
125
126 if ((r = kex_derive_keys(ssh, hash, hashlen, shared_secret)) == 0)
127 r = kex_send_newkeys(ssh);
128out:
129 explicit_bzero(hash, sizeof(hash));
130 explicit_bzero(server_key, sizeof(server_key));
131 free(server_host_key_blob);
132 free(signature);
133 free(client_pubkey);
134 sshbuf_free(shared_secret);
135 return r;
136}