summaryrefslogtreecommitdiff
path: root/usr.bin/ssh/dh.c
diff options
context:
space:
mode:
authorNiels Provos <provos@cvs.openbsd.org>2001-03-27 17:46:51 +0000
committerNiels Provos <provos@cvs.openbsd.org>2001-03-27 17:46:51 +0000
commit6184a97d2bbb6c2b11ce9a90994b814cf4bb85b4 (patch)
tree40585dac26ba6cf1d1d311328dc6e401f5995b71 /usr.bin/ssh/dh.c
parentacb804f2fba02b2a7159852bcd5b347b3416ab32 (diff)
make dh group exchange more flexible, allow min and max group size,
okay markus@, deraadt@
Diffstat (limited to 'usr.bin/ssh/dh.c')
-rw-r--r--usr.bin/ssh/dh.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/usr.bin/ssh/dh.c b/usr.bin/ssh/dh.c
index ac73f8400d5..5f441ee1c81 100644
--- a/usr.bin/ssh/dh.c
+++ b/usr.bin/ssh/dh.c
@@ -23,7 +23,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: dh.c,v 1.8 2001/03/05 17:58:22 stevesk Exp $");
+RCSID("$OpenBSD: dh.c,v 1.9 2001/03/27 17:46:49 provos Exp $");
#include "xmalloc.h"
@@ -69,6 +69,8 @@ parse_prime(int linenum, char *line, struct dhgroup *dhg)
if (cp == NULL || *strsize == '\0' ||
(dhg->size = atoi(strsize)) == 0)
goto fail;
+ /* The whole group is one bit larger */
+ dhg->size++;
gen = strsep(&cp, " "); /* gen */
if (cp == NULL || *gen == '\0')
goto fail;
@@ -95,7 +97,7 @@ parse_prime(int linenum, char *line, struct dhgroup *dhg)
}
DH *
-choose_dh(int minbits)
+choose_dh(int min, int wantbits, int max)
{
FILE *f;
char line[1024];
@@ -118,8 +120,11 @@ choose_dh(int minbits)
BN_free(dhg.g);
BN_free(dhg.p);
- if ((dhg.size > minbits && dhg.size < best) ||
- (dhg.size > best && best < minbits)) {
+ if (dhg.size > max || dhg.size < min)
+ continue;
+
+ if ((dhg.size > wantbits && dhg.size < best) ||
+ (dhg.size > best && best < wantbits)) {
best = dhg.size;
bestcount = 0;
}
@@ -129,8 +134,8 @@ choose_dh(int minbits)
fclose (f);
if (bestcount == 0) {
- log("WARNING: no primes in %s, using old prime", _PATH_DH_PRIMES);
- return (dh_new_group1());
+ log("WARNING: no suitable primes in %s", _PATH_DH_PRIMES);
+ return (NULL);
}
f = fopen(_PATH_DH_PRIMES, "r");
@@ -143,6 +148,8 @@ choose_dh(int minbits)
while (fgets(line, sizeof(line), f)) {
if (!parse_prime(linenum, line, &dhg))
continue;
+ if (dhg.size > max || dhg.size < min)
+ continue;
if (dhg.size != best)
continue;
if (linenum++ != which) {