diff options
Diffstat (limited to 'dh.c')
-rw-r--r-- | dh.c | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -23,7 +23,7 @@ | |||
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include "includes.h" | 25 | #include "includes.h" |
26 | RCSID("$OpenBSD: dh.c,v 1.8 2001/03/05 17:58:22 stevesk Exp $"); | 26 | RCSID("$OpenBSD: dh.c,v 1.9 2001/03/27 17:46:49 provos Exp $"); |
27 | 27 | ||
28 | #include "xmalloc.h" | 28 | #include "xmalloc.h" |
29 | 29 | ||
@@ -69,6 +69,8 @@ parse_prime(int linenum, char *line, struct dhgroup *dhg) | |||
69 | if (cp == NULL || *strsize == '\0' || | 69 | if (cp == NULL || *strsize == '\0' || |
70 | (dhg->size = atoi(strsize)) == 0) | 70 | (dhg->size = atoi(strsize)) == 0) |
71 | goto fail; | 71 | goto fail; |
72 | /* The whole group is one bit larger */ | ||
73 | dhg->size++; | ||
72 | gen = strsep(&cp, " "); /* gen */ | 74 | gen = strsep(&cp, " "); /* gen */ |
73 | if (cp == NULL || *gen == '\0') | 75 | if (cp == NULL || *gen == '\0') |
74 | goto fail; | 76 | goto fail; |
@@ -95,7 +97,7 @@ parse_prime(int linenum, char *line, struct dhgroup *dhg) | |||
95 | } | 97 | } |
96 | 98 | ||
97 | DH * | 99 | DH * |
98 | choose_dh(int minbits) | 100 | choose_dh(int min, int wantbits, int max) |
99 | { | 101 | { |
100 | FILE *f; | 102 | FILE *f; |
101 | char line[1024]; | 103 | char line[1024]; |
@@ -118,8 +120,11 @@ choose_dh(int minbits) | |||
118 | BN_free(dhg.g); | 120 | BN_free(dhg.g); |
119 | BN_free(dhg.p); | 121 | BN_free(dhg.p); |
120 | 122 | ||
121 | if ((dhg.size > minbits && dhg.size < best) || | 123 | if (dhg.size > max || dhg.size < min) |
122 | (dhg.size > best && best < minbits)) { | 124 | continue; |
125 | |||
126 | if ((dhg.size > wantbits && dhg.size < best) || | ||
127 | (dhg.size > best && best < wantbits)) { | ||
123 | best = dhg.size; | 128 | best = dhg.size; |
124 | bestcount = 0; | 129 | bestcount = 0; |
125 | } | 130 | } |
@@ -129,8 +134,8 @@ choose_dh(int minbits) | |||
129 | fclose (f); | 134 | fclose (f); |
130 | 135 | ||
131 | if (bestcount == 0) { | 136 | if (bestcount == 0) { |
132 | log("WARNING: no primes in %s, using old prime", _PATH_DH_PRIMES); | 137 | log("WARNING: no suitable primes in %s", _PATH_DH_PRIMES); |
133 | return (dh_new_group1()); | 138 | return (NULL); |
134 | } | 139 | } |
135 | 140 | ||
136 | f = fopen(_PATH_DH_PRIMES, "r"); | 141 | f = fopen(_PATH_DH_PRIMES, "r"); |
@@ -143,6 +148,8 @@ choose_dh(int minbits) | |||
143 | while (fgets(line, sizeof(line), f)) { | 148 | while (fgets(line, sizeof(line), f)) { |
144 | if (!parse_prime(linenum, line, &dhg)) | 149 | if (!parse_prime(linenum, line, &dhg)) |
145 | continue; | 150 | continue; |
151 | if (dhg.size > max || dhg.size < min) | ||
152 | continue; | ||
146 | if (dhg.size != best) | 153 | if (dhg.size != best) |
147 | continue; | 154 | continue; |
148 | if (linenum++ != which) { | 155 | if (linenum++ != which) { |