]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
upstream: use KEM API for vanilla c25519 KEX
authordjm@openbsd.org <djm@openbsd.org>
Mon, 21 Jan 2019 10:24:09 +0000 (10:24 +0000)
committerDamien Miller <djm@mindrot.org>
Mon, 21 Jan 2019 11:08:04 +0000 (22:08 +1100)
OpenBSD-Commit-ID: 38d937b85ff770886379dd66a8f32ab0c1c35c1f

12 files changed:
Makefile.in
kex.h
kexc25519.c
kexc25519c.c [deleted file]
kexc25519s.c [deleted file]
kexkemc.c
kexkems.c
monitor.c
ssh-keyscan.c
ssh_api.c
sshconnect2.c
sshd.c

index 2b22e9f47a577ca50d434eb1d65985675e9614b3..89f930367c259fd289499eba64e8ea62813d2ac4 100644 (file)
@@ -98,8 +98,6 @@ LIBSSH_OBJS=${LIBOPENSSH_OBJS} \
        ssh-ed25519.o digest-openssl.o digest-libc.o hmac.o \
        sc25519.o ge25519.o fe25519.o ed25519.o verify.o hash.o \
        kex.o kexdh.o kexgex.o kexecdh.o kexc25519.o \
-       kexdhc.o kexgexc.o kexecdhc.o kexc25519c.o \
-       kexdhs.o kexgexs.o kexecdhs.o kexc25519s.o \
        sntrup4591761.o kexsntrup4591761x25519.o kexkemc.o kexkems.o \
        platform-pledge.o platform-tracing.o platform-misc.o
 
diff --git a/kex.h b/kex.h
index 258a6471251cf59afd3c73d5e95c6e8b4dd50992..2eec2e04f6f03c3eddf41125e86ca1c3eb6064eb 100644 (file)
--- a/kex.h
+++ b/kex.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: kex.h,v 1.99 2019/01/21 10:20:12 djm Exp $ */
+/* $OpenBSD: kex.h,v 1.100 2019/01/21 10:24:09 djm Exp $ */
 
 /*
  * Copyright (c) 2000, 2001 Markus Friedl.  All rights reserved.
@@ -211,6 +211,11 @@ int         kexc25519_server(struct ssh *);
 int     kex_kem_client(struct ssh *);
 int     kex_kem_server(struct ssh *);
 
+int     kex_c25519_keypair(struct kex *);
+int     kex_c25519_enc(struct kex *, const u_char *, size_t, struct sshbuf **,
+    struct sshbuf **);
+int     kex_c25519_dec(struct kex *, const u_char *, size_t, struct sshbuf **);
+
 int     kex_kem_sntrup4591761x25519_keypair(struct kex *);
 int     kex_kem_sntrup4591761x25519_enc(struct kex *, const u_char *, size_t,
     struct sshbuf **, struct sshbuf **);
index 3911baf14757b4a0dacaa9144cc382222f27b344..a06c6e44ba751d8100e0c4ae57c29aa37f60676f 100644 (file)
@@ -1,6 +1,6 @@
-/* $OpenBSD: kexc25519.c,v 1.13 2019/01/21 10:20:12 djm Exp $ */
+/* $OpenBSD: kexc25519.c,v 1.14 2019/01/21 10:24:09 djm Exp $ */
 /*
- * Copyright (c) 2001, 2013 Markus Friedl.  All rights reserved.
+ * Copyright (c) 2019 Markus Friedl.  All rights reserved.
  * Copyright (c) 2010 Damien Miller.  All rights reserved.
  * Copyright (c) 2013 Aris Adamantiadis.  All rights reserved.
  *
 
 #include <sys/types.h>
 
-#include <signal.h>
+#include <stdio.h>
 #include <string.h>
+#include <signal.h>
 
-#include <openssl/bn.h>
-#include <openssl/evp.h>
-
-#include "sshbuf.h"
-#include "ssh2.h"
 #include "sshkey.h"
-#include "cipher.h"
 #include "kex.h"
-#include "log.h"
+#include "sshbuf.h"
 #include "digest.h"
 #include "ssherr.h"
+#include "ssh2.h"
 
 extern int crypto_scalarmult_curve25519(u_char a[CURVE25519_SIZE],
     const u_char b[CURVE25519_SIZE], const u_char c[CURVE25519_SIZE])
@@ -142,3 +138,109 @@ kex_c25519_hash(
 #endif
        return 0;
 }
+
+int
+kex_c25519_keypair(struct kex *kex)
+{
+       struct sshbuf *buf = NULL;
+       u_char *cp = NULL;
+       int r;
+
+       if ((buf = sshbuf_new()) == NULL)
+               return SSH_ERR_ALLOC_FAIL;
+       if ((r = sshbuf_reserve(buf, CURVE25519_SIZE, &cp)) != 0)
+               goto out;
+       kexc25519_keygen(kex->c25519_client_key, cp);
+#ifdef DEBUG_KEXECDH
+       dump_digest("client public key c25519:", cp, CURVE25519_SIZE);
+#endif
+       kex->kem_client_pub = buf;
+       buf = NULL;
+ out:
+       sshbuf_free(buf);
+       return r;
+}
+
+int
+kex_c25519_enc(struct kex *kex, const u_char *pkblob,
+   size_t pklen, struct sshbuf **server_blobp, struct sshbuf **shared_secretp)
+{
+       struct sshbuf *server_blob = NULL;
+       struct sshbuf *buf = NULL;
+       u_char *server_pub;
+       u_char server_key[CURVE25519_SIZE];
+       int r;
+
+       *server_blobp = NULL;
+       *shared_secretp = NULL;
+
+       if (pklen != CURVE25519_SIZE) {
+               r = SSH_ERR_SIGNATURE_INVALID;
+               goto out;
+       }
+#ifdef DEBUG_KEXECDH
+       dump_digest("client public key 25519:", pkblob, CURVE25519_SIZE);
+#endif
+       /* allocate space for encrypted KEM key and ECDH pub key */
+       if ((server_blob = sshbuf_new()) == NULL) {
+               r = SSH_ERR_ALLOC_FAIL;
+               goto out;
+       }
+       if ((r = sshbuf_reserve(server_blob, CURVE25519_SIZE, &server_pub)) != 0)
+               goto out;
+       kexc25519_keygen(server_key, server_pub);
+       /* allocate shared secret */
+       if ((buf = sshbuf_new()) == NULL) {
+               r = SSH_ERR_ALLOC_FAIL;
+               goto out;
+       }
+       if ((r = kexc25519_shared_key_ext(server_key, pkblob, buf, 0)) < 0)
+               goto out;
+#ifdef DEBUG_KEXECDH
+       dump_digest("server public key 25519:", server_pub, CURVE25519_SIZE);
+       dump_digest("encoded shared secret:", sshbuf_ptr(buf), sshbuf_len(buf));
+#endif
+       *server_blobp = server_blob;
+       *shared_secretp = buf;
+       server_blob = NULL;
+       buf = NULL;
+ out:
+       explicit_bzero(server_key, sizeof(server_key));
+       sshbuf_free(server_blob);
+       sshbuf_free(buf);
+       return r;
+}
+
+int
+kex_c25519_dec(struct kex *kex, const u_char *pkblob,
+    size_t pklen, struct sshbuf **shared_secretp)
+{
+       struct sshbuf *buf = NULL;
+       int r;
+
+       *shared_secretp = NULL;
+
+       if (pklen != CURVE25519_SIZE) {
+               r = SSH_ERR_SIGNATURE_INVALID;
+               goto out;
+       }
+#ifdef DEBUG_KEXECDH
+       dump_digest("server public key c25519:", pkblob, CURVE25519_SIZE);
+#endif
+       /* shared secret */
+       if ((buf = sshbuf_new()) == NULL) {
+               r = SSH_ERR_ALLOC_FAIL;
+               goto out;
+       }
+       if ((r = kexc25519_shared_key_ext(kex->c25519_client_key, pkblob,
+           buf, 0)) < 0)
+               goto out;
+#ifdef DEBUG_KEXECDH
+       dump_digest("encoded shared secret:", sshbuf_ptr(buf), sshbuf_len(buf));
+#endif
+       *shared_secretp = buf;
+       buf = NULL;
+ out:
+       sshbuf_free(buf);
+       return r;
+}
diff --git a/kexc25519c.c b/kexc25519c.c
deleted file mode 100644 (file)
index cc6e54c..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-/* $OpenBSD: kexc25519c.c,v 1.13 2019/01/21 10:20:12 djm Exp $ */
-/*
- * Copyright (c) 2001 Markus Friedl.  All rights reserved.
- * Copyright (c) 2010 Damien Miller.  All rights reserved.
- * Copyright (c) 2013 Aris Adamantiadis.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "includes.h"
-
-#include <sys/types.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <signal.h>
-
-#include "sshkey.h"
-#include "cipher.h"
-#include "kex.h"
-#include "log.h"
-#include "packet.h"
-#include "ssh2.h"
-#include "sshbuf.h"
-#include "digest.h"
-#include "ssherr.h"
-
-static int
-input_kex_c25519_reply(int type, u_int32_t seq, struct ssh *ssh);
-
-int
-kexc25519_client(struct ssh *ssh)
-{
-       struct kex *kex = ssh->kex;
-       int r;
-
-       kexc25519_keygen(kex->c25519_client_key, kex->c25519_client_pubkey);
-#ifdef DEBUG_KEXECDH
-       dump_digest("client private key:", kex->c25519_client_key,
-           sizeof(kex->c25519_client_key));
-#endif
-       if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_ECDH_INIT)) != 0 ||
-           (r = sshpkt_put_string(ssh, kex->c25519_client_pubkey,
-           sizeof(kex->c25519_client_pubkey))) != 0 ||
-           (r = sshpkt_send(ssh)) != 0)
-               return r;
-
-       debug("expecting SSH2_MSG_KEX_ECDH_REPLY");
-       ssh_dispatch_set(ssh, SSH2_MSG_KEX_ECDH_REPLY, &input_kex_c25519_reply);
-       return 0;
-}
-
-static int
-input_kex_c25519_reply(int type, u_int32_t seq, struct ssh *ssh)
-{
-       struct kex *kex = ssh->kex;
-       struct sshkey *server_host_key = NULL;
-       struct sshbuf *shared_secret = NULL;
-       u_char *server_pubkey = NULL;
-       u_char *server_host_key_blob = NULL, *signature = NULL;
-       u_char hash[SSH_DIGEST_MAX_LENGTH];
-       size_t slen, pklen, sbloblen, hashlen;
-       int r;
-
-       /* hostkey */
-       if ((r = sshpkt_get_string(ssh, &server_host_key_blob,
-           &sbloblen)) != 0 ||
-           (r = sshkey_from_blob(server_host_key_blob, sbloblen,
-           &server_host_key)) != 0)
-               goto out;
-       if ((r = kex_verify_host_key(ssh, server_host_key)) != 0)
-               goto out;
-
-       /* Q_S, server public key */
-       /* signed H */
-       if ((r = sshpkt_get_string(ssh, &server_pubkey, &pklen)) != 0 ||
-           (r = sshpkt_get_string(ssh, &signature, &slen)) != 0 ||
-           (r = sshpkt_get_end(ssh)) != 0)
-               goto out;
-       if (pklen != CURVE25519_SIZE) {
-               r = SSH_ERR_SIGNATURE_INVALID;
-               goto out;
-       }
-
-#ifdef DEBUG_KEXECDH
-       dump_digest("server public key:", server_pubkey, CURVE25519_SIZE);
-#endif
-
-       if ((shared_secret = sshbuf_new()) == NULL) {
-               r = SSH_ERR_ALLOC_FAIL;
-               goto out;
-       }
-       if ((r = kexc25519_shared_key(kex->c25519_client_key, server_pubkey,
-           shared_secret)) != 0)
-               goto out;
-
-       /* calc and verify H */
-       hashlen = sizeof(hash);
-       if ((r = kex_c25519_hash(
-           kex->hash_alg,
-           kex->client_version,
-           kex->server_version,
-           sshbuf_ptr(kex->my), sshbuf_len(kex->my),
-           sshbuf_ptr(kex->peer), sshbuf_len(kex->peer),
-           server_host_key_blob, sbloblen,
-           kex->c25519_client_pubkey, sizeof(kex->c25519_client_pubkey),
-           server_pubkey, pklen,
-           sshbuf_ptr(shared_secret), sshbuf_len(shared_secret),
-           hash, &hashlen)) != 0)
-               goto out;
-
-       if ((r = sshkey_verify(server_host_key, signature, slen, hash, hashlen,
-           kex->hostkey_alg, ssh->compat)) != 0)
-               goto out;
-
-       if ((r = kex_derive_keys(ssh, hash, hashlen, shared_secret)) == 0)
-               r = kex_send_newkeys(ssh);
-out:
-       explicit_bzero(hash, sizeof(hash));
-       explicit_bzero(kex->c25519_client_key, sizeof(kex->c25519_client_key));
-       free(server_host_key_blob);
-       free(server_pubkey);
-       free(signature);
-       sshkey_free(server_host_key);
-       sshbuf_free(shared_secret);
-       return r;
-}
diff --git a/kexc25519s.c b/kexc25519s.c
deleted file mode 100644 (file)
index ace4d5c..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-/* $OpenBSD: kexc25519s.c,v 1.16 2019/01/21 10:20:12 djm Exp $ */
-/*
- * Copyright (c) 2001 Markus Friedl.  All rights reserved.
- * Copyright (c) 2010 Damien Miller.  All rights reserved.
- * Copyright (c) 2013 Aris Adamantiadis.  All rights reserved.
- *
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "includes.h"
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <string.h>
-#include <signal.h>
-
-#include "sshkey.h"
-#include "cipher.h"
-#include "digest.h"
-#include "kex.h"
-#include "log.h"
-#include "packet.h"
-#include "ssh2.h"
-#include "sshbuf.h"
-#include "ssherr.h"
-
-static int input_kex_c25519_init(int, u_int32_t, struct ssh *);
-
-int
-kexc25519_server(struct ssh *ssh)
-{
-       debug("expecting SSH2_MSG_KEX_ECDH_INIT");
-       ssh_dispatch_set(ssh, SSH2_MSG_KEX_ECDH_INIT, &input_kex_c25519_init);
-       return 0;
-}
-
-static int
-input_kex_c25519_init(int type, u_int32_t seq, struct ssh *ssh)
-{
-       struct kex *kex = ssh->kex;
-       struct sshkey *server_host_private, *server_host_public;
-       struct sshbuf *shared_secret = NULL;
-       u_char *server_host_key_blob = NULL, *signature = NULL;
-       u_char server_key[CURVE25519_SIZE];
-       u_char *client_pubkey = NULL;
-       u_char server_pubkey[CURVE25519_SIZE];
-       u_char hash[SSH_DIGEST_MAX_LENGTH];
-       size_t slen, pklen, sbloblen, hashlen;
-       int r;
-
-       /* generate private key */
-       kexc25519_keygen(server_key, server_pubkey);
-#ifdef DEBUG_KEXECDH
-       dump_digest("server private key:", server_key, sizeof(server_key));
-#endif
-       if ((r = kex_load_hostkey(ssh, &server_host_private,
-           &server_host_public)) != 0)
-               goto out;
-       if ((r = sshpkt_get_string(ssh, &client_pubkey, &pklen)) != 0 ||
-           (r = sshpkt_get_end(ssh)) != 0)
-               goto out;
-       if (pklen != CURVE25519_SIZE) {
-               r = SSH_ERR_SIGNATURE_INVALID;
-               goto out;
-       }
-#ifdef DEBUG_KEXECDH
-       dump_digest("client public key:", client_pubkey, CURVE25519_SIZE);
-#endif
-
-       if ((shared_secret = sshbuf_new()) == NULL) {
-               r = SSH_ERR_ALLOC_FAIL;
-               goto out;
-       }
-       if ((r = kexc25519_shared_key(server_key, client_pubkey,
-           shared_secret)) < 0)
-               goto out;
-
-       /* calc H */
-       if ((r = sshkey_to_blob(server_host_public, &server_host_key_blob,
-           &sbloblen)) != 0)
-               goto out;
-       hashlen = sizeof(hash);
-       if ((r = kex_c25519_hash(
-           kex->hash_alg,
-           kex->client_version,
-           kex->server_version,
-           sshbuf_ptr(kex->peer), sshbuf_len(kex->peer),
-           sshbuf_ptr(kex->my), sshbuf_len(kex->my),
-           server_host_key_blob, sbloblen,
-           client_pubkey, pklen,
-           server_pubkey, sizeof(server_pubkey),
-           sshbuf_ptr(shared_secret), sshbuf_len(shared_secret),
-           hash, &hashlen)) != 0)
-               goto out;
-
-       /* sign H */
-       if ((r = kex->sign(ssh, server_host_private, server_host_public,
-           &signature, &slen, hash, hashlen, kex->hostkey_alg)) < 0)
-               goto out;
-
-       /* send server hostkey, ECDH pubkey 'Q_S' and signed H */
-       if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_ECDH_REPLY)) != 0 ||
-           (r = sshpkt_put_string(ssh, server_host_key_blob, sbloblen)) != 0 ||
-           (r = sshpkt_put_string(ssh, server_pubkey, sizeof(server_pubkey))) != 0 ||
-           (r = sshpkt_put_string(ssh, signature, slen)) != 0 ||
-           (r = sshpkt_send(ssh)) != 0)
-               goto out;
-
-       if ((r = kex_derive_keys(ssh, hash, hashlen, shared_secret)) == 0)
-               r = kex_send_newkeys(ssh);
-out:
-       explicit_bzero(hash, sizeof(hash));
-       explicit_bzero(server_key, sizeof(server_key));
-       free(server_host_key_blob);
-       free(signature);
-       free(client_pubkey);
-       sshbuf_free(shared_secret);
-       return r;
-}
index 47f15c30c756c04dde097ce4cd9011988955a535..13f36a1160a579cc9e766a505b25fc3949cd03f6 100644 (file)
--- a/kexkemc.c
+++ b/kexkemc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kexkemc.c,v 1.1 2019/01/21 10:20:12 djm Exp $ */
+/* $OpenBSD: kexkemc.c,v 1.2 2019/01/21 10:24:09 djm Exp $ */
 /*
  * Copyright (c) 2019 Markus Friedl.  All rights reserved.
  *
@@ -47,7 +47,18 @@ kex_kem_client(struct ssh *ssh)
        struct kex *kex = ssh->kex;
        int r;
 
-       if ((r = kex_kem_sntrup4591761x25519_keypair(kex)) != 0)
+       switch (kex->kex_type) {
+       case KEX_C25519_SHA256:
+               r = kex_c25519_keypair(kex);
+               break;
+       case KEX_KEM_SNTRUP4591761X25519_SHA512:
+               r = kex_kem_sntrup4591761x25519_keypair(kex);
+               break;
+       default:
+               r = SSH_ERR_INVALID_ARGUMENT;
+               break;
+       }
+       if (r != 0)
                return r;
        if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_ECDH_INIT)) != 0 ||
            (r = sshpkt_put_stringb(ssh, kex->kem_client_pub)) != 0 ||
@@ -87,8 +98,19 @@ input_kex_kem_reply(int type, u_int32_t seq, struct ssh *ssh)
                goto out;
 
        /* compute shared secret */
-       if ((r = kex_kem_sntrup4591761x25519_dec(kex, server_pubkey, pklen,
-           &shared_secret)) != 0)
+       switch (kex->kex_type) {
+       case KEX_C25519_SHA256:
+               r = kex_c25519_dec(kex, server_pubkey, pklen, &shared_secret);
+               break;
+       case KEX_KEM_SNTRUP4591761X25519_SHA512:
+               r = kex_kem_sntrup4591761x25519_dec(kex, server_pubkey, pklen,
+                   &shared_secret);
+               break;
+       default:
+               r = SSH_ERR_INVALID_ARGUMENT;
+               break;
+       }
+       if (r !=0 )
                goto out;
 
        /* calc and verify H */
index 43cf82018d5cd656a2d4bbf366d288cb197c9971..89237902bf4b0b793d59e447db894e6a2c21730a 100644 (file)
--- a/kexkems.c
+++ b/kexkems.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kexkems.c,v 1.1 2019/01/21 10:20:12 djm Exp $ */
+/* $OpenBSD: kexkems.c,v 1.2 2019/01/21 10:24:09 djm Exp $ */
 /*
  * Copyright (c) 2019 Markus Friedl.  All rights reserved.
  *
@@ -68,8 +68,20 @@ input_kex_kem_init(int type, u_int32_t seq, struct ssh *ssh)
                goto out;
 
        /* compute shared secret */
-       if ((r = kex_kem_sntrup4591761x25519_enc(kex, client_pubkey, pklen,
-           &server_pubkey, &shared_secret)) != 0)
+       switch (kex->kex_type) {
+       case KEX_C25519_SHA256:
+               r = kex_c25519_enc(kex, client_pubkey, pklen, &server_pubkey,
+                   &shared_secret);
+               break;
+       case KEX_KEM_SNTRUP4591761X25519_SHA512:
+               r = kex_kem_sntrup4591761x25519_enc(kex, client_pubkey, pklen,
+                   &server_pubkey, &shared_secret);
+               break;
+       default:
+               r = SSH_ERR_INVALID_ARGUMENT;
+               break;
+       }
+       if (r !=0 )
                goto out;
 
        /* calc H */
index b10fdebf2c92b6363ca65cb7ab4fa7b8f0fee9bc..9f86d5b752d6bb2d8ad24590578f6999e7a84962 100644 (file)
--- a/monitor.c
+++ b/monitor.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: monitor.c,v 1.193 2019/01/21 10:20:12 djm Exp $ */
+/* $OpenBSD: monitor.c,v 1.194 2019/01/21 10:24:09 djm Exp $ */
 /*
  * Copyright 2002 Niels Provos <provos@citi.umich.edu>
  * Copyright 2002 Markus Friedl <markus@openbsd.org>
@@ -1688,7 +1688,7 @@ monitor_apply_keystate(struct ssh *ssh, struct monitor *pmonitor)
                kex->kex[KEX_ECDH_SHA2] = kexecdh_server;
 # endif
 #endif /* WITH_OPENSSL */
-               kex->kex[KEX_C25519_SHA256] = kexc25519_server;
+               kex->kex[KEX_C25519_SHA256] = kex_kem_server;
                kex->kex[KEX_KEM_SNTRUP4591761X25519_SHA512] = kex_kem_server;
                kex->load_host_public_key=&get_hostkey_public_by_type;
                kex->load_host_private_key=&get_hostkey_private_by_type;
index 83a7687003a1d8f25d096e408d449696a095c124..9eebc1445c02e09c0328512f9f3a5a70deee036d 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-keyscan.c,v 1.121 2019/01/21 10:20:12 djm Exp $ */
+/* $OpenBSD: ssh-keyscan.c,v 1.122 2019/01/21 10:24:09 djm Exp $ */
 /*
  * Copyright 1995, 1996 by David Mazieres <dm@lcs.mit.edu>.
  *
@@ -271,7 +271,7 @@ keygrab_ssh2(con *c)
        c->c_ssh->kex->kex[KEX_ECDH_SHA2] = kexecdh_client;
 # endif
 #endif
-       c->c_ssh->kex->kex[KEX_C25519_SHA256] = kexc25519_client;
+       c->c_ssh->kex->kex[KEX_C25519_SHA256] = kex_kem_client;
        c->c_ssh->kex->kex[KEX_KEM_SNTRUP4591761X25519_SHA512] = kex_kem_client;
        ssh_set_verify_host_key_callback(c->c_ssh, key_print_wrapper);
        /*
index 73981aa37cb5c412e34cbe8d590296803ba2f865..fe9fbf5a7d3c02b4c209f82aecb48545d88ad23b 100644 (file)
--- a/ssh_api.c
+++ b/ssh_api.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh_api.c,v 1.11 2019/01/21 10:20:12 djm Exp $ */
+/* $OpenBSD: ssh_api.c,v 1.12 2019/01/21 10:24:09 djm Exp $ */
 /*
  * Copyright (c) 2012 Markus Friedl.  All rights reserved.
  *
@@ -110,7 +110,7 @@ ssh_init(struct ssh **sshp, int is_server, struct kex_params *kex_params)
                ssh->kex->kex[KEX_ECDH_SHA2] = kexecdh_server;
 # endif
 #endif /* WITH_OPENSSL */
-               ssh->kex->kex[KEX_C25519_SHA256] = kexc25519_server;
+               ssh->kex->kex[KEX_C25519_SHA256] = kex_kem_server;
                ssh->kex->kex[KEX_KEM_SNTRUP4591761X25519_SHA512] = kex_kem_server;
                ssh->kex->load_host_public_key=&_ssh_host_public_key;
                ssh->kex->load_host_private_key=&_ssh_host_private_key;
@@ -128,7 +128,7 @@ ssh_init(struct ssh **sshp, int is_server, struct kex_params *kex_params)
                ssh->kex->kex[KEX_ECDH_SHA2] = kexecdh_client;
 # endif
 #endif /* WITH_OPENSSL */
-               ssh->kex->kex[KEX_C25519_SHA256] = kexc25519_client;
+               ssh->kex->kex[KEX_C25519_SHA256] = kex_kem_client;
                ssh->kex->kex[KEX_KEM_SNTRUP4591761X25519_SHA512] = kex_kem_client;
                ssh->kex->verify_host_key =&_ssh_verify_host_key;
        }
index 05657fd73eaef09a308197fd4c2d3b7f1e94a5e1..be19722bb2e944526ff626cebb6bb3457a4d9a95 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: sshconnect2.c,v 1.297 2019/01/21 10:20:12 djm Exp $ */
+/* $OpenBSD: sshconnect2.c,v 1.298 2019/01/21 10:24:09 djm Exp $ */
 /*
  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
  * Copyright (c) 2008 Damien Miller.  All rights reserved.
@@ -212,7 +212,7 @@ ssh_kex2(struct ssh *ssh, char *host, struct sockaddr *hostaddr, u_short port)
        ssh->kex->kex[KEX_ECDH_SHA2] = kexecdh_client;
 # endif
 #endif
-       ssh->kex->kex[KEX_C25519_SHA256] = kexc25519_client;
+       ssh->kex->kex[KEX_C25519_SHA256] = kex_kem_client;
        ssh->kex->kex[KEX_KEM_SNTRUP4591761X25519_SHA512] = kex_kem_client;
        ssh->kex->verify_host_key=&verify_host_key_callback;
 
diff --git a/sshd.c b/sshd.c
index 330b8052da1ec1c593835688b3760c12af6c9f66..665b22b1e737bcabd57d6a201d72cefcbd83080b 100644 (file)
--- a/sshd.c
+++ b/sshd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sshd.c,v 1.528 2019/01/21 10:20:12 djm Exp $ */
+/* $OpenBSD: sshd.c,v 1.529 2019/01/21 10:24:09 djm Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -2218,7 +2218,7 @@ do_ssh2_kex(struct ssh *ssh)
        kex->kex[KEX_ECDH_SHA2] = kexecdh_server;
 # endif
 #endif
-       kex->kex[KEX_C25519_SHA256] = kexc25519_server;
+       kex->kex[KEX_C25519_SHA256] = kex_kem_server;
        kex->kex[KEX_KEM_SNTRUP4591761X25519_SHA512] = kex_kem_server;
        kex->load_host_public_key=&get_hostkey_public_by_type;
        kex->load_host_private_key=&get_hostkey_private_by_type;