132f8f8
diff -up openssh-6.8p1/compat.c.cisco-dh openssh-6.8p1/compat.c
132f8f8
--- openssh-6.8p1/compat.c.cisco-dh	2015-03-17 06:49:20.000000000 +0100
132f8f8
+++ openssh-6.8p1/compat.c	2015-03-19 12:57:58.862606969 +0100
08fe9e8
@@ -167,6 +167,7 @@ compat_datafellows(const char *version)
08fe9e8
 					SSH_BUG_SCANNER },
08fe9e8
 		{ "Probe-*",
08fe9e8
 					SSH_BUG_PROBE },
08fe9e8
+		{ "Cisco-*",		SSH_BUG_MAX4096DH },
08fe9e8
 		{ NULL,			0 }
08fe9e8
 	};
08fe9e8
 
132f8f8
diff -up openssh-6.8p1/compat.h.cisco-dh openssh-6.8p1/compat.h
132f8f8
--- openssh-6.8p1/compat.h.cisco-dh	2015-03-17 06:49:20.000000000 +0100
132f8f8
+++ openssh-6.8p1/compat.h	2015-03-19 12:57:58.862606969 +0100
08fe9e8
@@ -60,6 +60,7 @@
08fe9e8
 #define SSH_NEW_OPENSSH		0x04000000
08fe9e8
 #define SSH_BUG_DYNAMIC_RPORT	0x08000000
08fe9e8
 #define SSH_BUG_CURVE25519PAD	0x10000000
08fe9e8
+#define SSH_BUG_MAX4096DH       0x20000000
08fe9e8
 
08fe9e8
 void     enable_compat13(void);
08fe9e8
 void     enable_compat20(void);
132f8f8
diff -up openssh-6.8p1/kexgexc.c.cisco-dh openssh-6.8p1/kexgexc.c
132f8f8
--- openssh-6.8p1/kexgexc.c.cisco-dh	2015-03-19 12:57:58.862606969 +0100
132f8f8
+++ openssh-6.8p1/kexgexc.c	2015-03-19 13:11:52.320519969 +0100
132f8f8
@@ -64,8 +64,27 @@ kexgex_client(struct ssh *ssh)
08fe9e8
 
132f8f8
 	kex->min = DH_GRP_MIN;
132f8f8
 	kex->max = DH_GRP_MAX;
08fe9e8
+
08fe9e8
+	/* Servers with MAX4096DH need a preferred size (nbits) <= 4096.
08fe9e8
+ 	 * We need to also ensure that min < nbits < max */
08fe9e8
+
08fe9e8
+	if (datafellows & SSH_BUG_MAX4096DH) {
08fe9e8
+		/* The largest min for these servers is 4096 */
132f8f8
+		kex->min = MIN(kex->min, 4096);
08fe9e8
+	}
08fe9e8
+
132f8f8
 	kex->nbits = nbits;
132f8f8
-	if (ssh->compat & SSH_OLD_DHGEX) {
132f8f8
+	kex->nbits = MIN(nbits, kex->max);
132f8f8
+	kex->nbits = MAX(nbits, kex->min);
08fe9e8
+
132f8f8
+	if (ssh->compat & SSH_BUG_MAX4096DH) {
08fe9e8
+		/* Cannot have a nbits > 4096 for these servers */
132f8f8
+		kex->nbits = MIN(kex->nbits, 4096);
08fe9e8
+		/* nbits has to be powers of two */
132f8f8
+		if (kex->nbits == 3072)
132f8f8
+			kex->nbits = 4096;
08fe9e8
+	}
132f8f8
+	if (ssh->compat & SSH_OLD_DHGEX) {	/* Old GEX request */
08fe9e8
 		/* Old GEX request */
132f8f8
 		if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_DH_GEX_REQUEST_OLD))
132f8f8
 		    != 0 ||