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