OpenCoverage

dh.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssh/src/dh.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10-
11static int-
12parse_prime(int linenum, char *line, struct dhgroup *dhg)-
13{-
14 char *cp, *arg;-
15 char *strsize, *gen, *prime;-
16 const char *errstr = -
17 ((void *)0)-
18 ;-
19 long long n;-
20-
21 dhg->p = dhg->g = -
22 ((void *)0)-
23 ;-
24 cp = line;-
25 if ((
(arg = strdeli...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
arg = strdelim(&cp)) ==
(arg = strdeli...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
26 ((void *)0)
(arg = strdeli...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
27 )-
28 return
never executed: return 0;
0;
never executed: return 0;
0
29-
30 if (*
*arg == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
arg == '\0'
*arg == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
)
0
31 arg = strdelim(&cp);
never executed: arg = strdelim(&cp);
0
32 if (!arg
!argDescription
TRUEnever evaluated
FALSEnever evaluated
|| !*arg
!*argDescription
TRUEnever evaluated
FALSEnever evaluated
|| *
*arg == '#'Description
TRUEnever evaluated
FALSEnever evaluated
arg == '#'
*arg == '#'Description
TRUEnever evaluated
FALSEnever evaluated
)
0
33 return
never executed: return 0;
0;
never executed: return 0;
0
34-
35-
36 if (cp ==
cp == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
37 ((void *)0)
cp == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
38 || *
*arg == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
arg == '\0'
*arg == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
)
0
39 goto
never executed: goto truncated;
truncated;
never executed: goto truncated;
0
40 arg = -
41 __extension__ ({ char __r0, __r1, __r2; (__builtin_constant_p (-
42 " "-
43 ) && ((size_t)(const void *)((-
44 " "-
45 ) + 1) - (size_t)(const void *)(-
46 " "-
47 ) == 1) && (__r0 = ((const char *) (-
48 " "-
49 ))[0], ((const char *) (-
50 " "-
51 ))[0] != '\0') ? ((__r1 = ((const char *) (-
52 " "-
53 ))[1], ((const char *) (-
54 " "-
55 ))[1] == '\0') ? __strsep_1c (-
56 &cp-
57 , __r0) : ((__r2 = ((const char *) (-
58 " "-
59 ))[2], __r2 == '\0') ? __strsep_2c (-
60 &cp-
61 , __r0, __r1) : (((const char *) (-
62 " "-
63 ))[3] == '\0' ? __strsep_3c (-
64 &cp-
65 , __r0, __r1, __r2) : __strsep_g (-
66 &cp-
67 , -
68 " "-
69 )))) : __strsep_g (-
70 &cp-
71 , -
72 " "-
73 )); })-
74 ;-
75 if (cp ==
cp == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
76 ((void *)0)
cp == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
77 || *
*arg == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
arg == '\0'
*arg == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
)
0
78 goto
never executed: goto truncated;
truncated;
never executed: goto truncated;
0
79-
80 n = strtonum(arg, 0, 5, &errstr);-
81 if (errstr !=
errstr != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
82 ((void *)0)
errstr != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
83 || n != (2)
n != (2)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
84 error("moduli:%d: type is not %d", linenum, (2));-
85 goto
never executed: goto fail;
fail;
never executed: goto fail;
0
86 }-
87 arg = -
88 __extension__ ({ char __r0, __r1, __r2; (__builtin_constant_p (-
89 " "-
90 ) && ((size_t)(const void *)((-
91 " "-
92 ) + 1) - (size_t)(const void *)(-
93 " "-
94 ) == 1) && (__r0 = ((const char *) (-
95 " "-
96 ))[0], ((const char *) (-
97 " "-
98 ))[0] != '\0') ? ((__r1 = ((const char *) (-
99 " "-
100 ))[1], ((const char *) (-
101 " "-
102 ))[1] == '\0') ? __strsep_1c (-
103 &cp-
104 , __r0) : ((__r2 = ((const char *) (-
105 " "-
106 ))[2], __r2 == '\0') ? __strsep_2c (-
107 &cp-
108 , __r0, __r1) : (((const char *) (-
109 " "-
110 ))[3] == '\0' ? __strsep_3c (-
111 &cp-
112 , __r0, __r1, __r2) : __strsep_g (-
113 &cp-
114 , -
115 " "-
116 )))) : __strsep_g (-
117 &cp-
118 , -
119 " "-
120 )); })-
121 ;-
122 if (cp ==
cp == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
123 ((void *)0)
cp == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
124 || *
*arg == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
arg == '\0'
*arg == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
)
0
125 goto
never executed: goto truncated;
truncated;
never executed: goto truncated;
0
126-
127 n = strtonum(arg, 0, 0x1f, &errstr);-
128 if (errstr !=
errstr != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
129 ((void *)0)
errstr != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
130 ||-
131 (
(n & (0x01))Description
TRUEnever evaluated
FALSEnever evaluated
n & (0x01))
(n & (0x01))Description
TRUEnever evaluated
FALSEnever evaluated
|| !(n & ~(0x01))
!(n & ~(0x01))Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
132 error("moduli:%d: invalid moduli tests flag", linenum);-
133 goto
never executed: goto fail;
fail;
never executed: goto fail;
0
134 }-
135 arg = -
136 __extension__ ({ char __r0, __r1, __r2; (__builtin_constant_p (-
137 " "-
138 ) && ((size_t)(const void *)((-
139 " "-
140 ) + 1) - (size_t)(const void *)(-
141 " "-
142 ) == 1) && (__r0 = ((const char *) (-
143 " "-
144 ))[0], ((const char *) (-
145 " "-
146 ))[0] != '\0') ? ((__r1 = ((const char *) (-
147 " "-
148 ))[1], ((const char *) (-
149 " "-
150 ))[1] == '\0') ? __strsep_1c (-
151 &cp-
152 , __r0) : ((__r2 = ((const char *) (-
153 " "-
154 ))[2], __r2 == '\0') ? __strsep_2c (-
155 &cp-
156 , __r0, __r1) : (((const char *) (-
157 " "-
158 ))[3] == '\0' ? __strsep_3c (-
159 &cp-
160 , __r0, __r1, __r2) : __strsep_g (-
161 &cp-
162 , -
163 " "-
164 )))) : __strsep_g (-
165 &cp-
166 , -
167 " "-
168 )); })-
169 ;-
170 if (cp ==
cp == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
171 ((void *)0)
cp == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
172 || *
*arg == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
arg == '\0'
*arg == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
)
0
173 goto
never executed: goto truncated;
truncated;
never executed: goto truncated;
0
174 n = strtonum(arg, 0, 1<<30, &errstr);-
175 if (errstr !=
errstr != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
176 ((void *)0)
errstr != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
177 || n == 0
n == 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
178 error("moduli:%d: invalid primality trial count", linenum);-
179 goto
never executed: goto fail;
fail;
never executed: goto fail;
0
180 }-
181 strsize = -
182 __extension__ ({ char __r0, __r1, __r2; (__builtin_constant_p (-
183 " "-
184 ) && ((size_t)(const void *)((-
185 " "-
186 ) + 1) - (size_t)(const void *)(-
187 " "-
188 ) == 1) && (__r0 = ((const char *) (-
189 " "-
190 ))[0], ((const char *) (-
191 " "-
192 ))[0] != '\0') ? ((__r1 = ((const char *) (-
193 " "-
194 ))[1], ((const char *) (-
195 " "-
196 ))[1] == '\0') ? __strsep_1c (-
197 &cp-
198 , __r0) : ((__r2 = ((const char *) (-
199 " "-
200 ))[2], __r2 == '\0') ? __strsep_2c (-
201 &cp-
202 , __r0, __r1) : (((const char *) (-
203 " "-
204 ))[3] == '\0' ? __strsep_3c (-
205 &cp-
206 , __r0, __r1, __r2) : __strsep_g (-
207 &cp-
208 , -
209 " "-
210 )))) : __strsep_g (-
211 &cp-
212 , -
213 " "-
214 )); })-
215 ;-
216 if (cp ==
cp == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
217 ((void *)0)
cp == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
218 || *
*strsize == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
strsize == '\0'
*strsize == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
||
0
219 (
(dhg->size = (...&errstr)) == 0Description
TRUEnever evaluated
FALSEnever evaluated
dhg->size = (int)strtonum(strsize, 0, 64*1024, &errstr)) == 0
(dhg->size = (...&errstr)) == 0Description
TRUEnever evaluated
FALSEnever evaluated
||
0
220 errstr
errstrDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
221 error("moduli:%d: invalid prime length", linenum);-
222 goto
never executed: goto fail;
fail;
never executed: goto fail;
0
223 }-
224-
225 dhg->size++;-
226 gen = -
227 __extension__ ({ char __r0, __r1, __r2; (__builtin_constant_p (-
228 " "-
229 ) && ((size_t)(const void *)((-
230 " "-
231 ) + 1) - (size_t)(const void *)(-
232 " "-
233 ) == 1) && (__r0 = ((const char *) (-
234 " "-
235 ))[0], ((const char *) (-
236 " "-
237 ))[0] != '\0') ? ((__r1 = ((const char *) (-
238 " "-
239 ))[1], ((const char *) (-
240 " "-
241 ))[1] == '\0') ? __strsep_1c (-
242 &cp-
243 , __r0) : ((__r2 = ((const char *) (-
244 " "-
245 ))[2], __r2 == '\0') ? __strsep_2c (-
246 &cp-
247 , __r0, __r1) : (((const char *) (-
248 " "-
249 ))[3] == '\0' ? __strsep_3c (-
250 &cp-
251 , __r0, __r1, __r2) : __strsep_g (-
252 &cp-
253 , -
254 " "-
255 )))) : __strsep_g (-
256 &cp-
257 , -
258 " "-
259 )); })-
260 ;-
261 if (cp ==
cp == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
262 ((void *)0)
cp == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
263 || *
*gen == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
gen == '\0'
*gen == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
)
0
264 goto
never executed: goto truncated;
truncated;
never executed: goto truncated;
0
265 prime = -
266 __extension__ ({ char __r0, __r1, __r2; (__builtin_constant_p (-
267 " "-
268 ) && ((size_t)(const void *)((-
269 " "-
270 ) + 1) - (size_t)(const void *)(-
271 " "-
272 ) == 1) && (__r0 = ((const char *) (-
273 " "-
274 ))[0], ((const char *) (-
275 " "-
276 ))[0] != '\0') ? ((__r1 = ((const char *) (-
277 " "-
278 ))[1], ((const char *) (-
279 " "-
280 ))[1] == '\0') ? __strsep_1c (-
281 &cp-
282 , __r0) : ((__r2 = ((const char *) (-
283 " "-
284 ))[2], __r2 == '\0') ? __strsep_2c (-
285 &cp-
286 , __r0, __r1) : (((const char *) (-
287 " "-
288 ))[3] == '\0' ? __strsep_3c (-
289 &cp-
290 , __r0, __r1, __r2) : __strsep_g (-
291 &cp-
292 , -
293 " "-
294 )))) : __strsep_g (-
295 &cp-
296 , -
297 " "-
298 )); })-
299 ;-
300 if (cp !=
cp != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
301 ((void *)0)
cp != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
302 || *
*prime == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
prime == '\0'
*prime == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
303 truncated:-
304 error("moduli:%d: truncated", linenum);-
305 goto
never executed: goto fail;
fail;
never executed: goto fail;
0
306 }-
307-
308 if ((
(dhg->g = BN_n...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
dhg->g = BN_new()) ==
(dhg->g = BN_n...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
309 ((void *)0)
(dhg->g = BN_n...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
310 ||-
311 (
(dhg->p = BN_n...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
dhg->p = BN_new()) ==
(dhg->p = BN_n...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
312 ((void *)0)
(dhg->p = BN_n...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
313 ) {-
314 error("parse_prime: BN_new failed");-
315 goto
never executed: goto fail;
fail;
never executed: goto fail;
0
316 }-
317 if (BN_hex2bn(&dhg->g, gen) == 0
BN_hex2bn(&dhg->g, gen) == 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
318 error("moduli:%d: could not parse generator value", linenum);-
319 goto
never executed: goto fail;
fail;
never executed: goto fail;
0
320 }-
321 if (BN_hex2bn(&dhg->p, prime) == 0
BN_hex2bn(&dhg->p, prime) == 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
322 error("moduli:%d: could not parse prime value", linenum);-
323 goto
never executed: goto fail;
fail;
never executed: goto fail;
0
324 }-
325 if (BN_num_bits(dhg->p) != dhg->size
BN_num_bits(dh...) != dhg->sizeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
326 error("moduli:%d: prime has wrong size: actual %d listed %d",-
327 linenum, BN_num_bits(dhg->p), dhg->size - 1);-
328 goto
never executed: goto fail;
fail;
never executed: goto fail;
0
329 }-
330 if (BN_cmp(dhg->g, BN_value_one()) <= 0
BN_cmp(dhg->g,...ue_one()) <= 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
331 error("moduli:%d: generator is invalid", linenum);-
332 goto
never executed: goto fail;
fail;
never executed: goto fail;
0
333 }-
334 return
never executed: return 1;
1;
never executed: return 1;
0
335-
336 fail:-
337 BN_clear_free(dhg->g);-
338 BN_clear_free(dhg->p);-
339 dhg->g = dhg->p = -
340 ((void *)0)-
341 ;-
342 return
never executed: return 0;
0;
never executed: return 0;
0
343}-
344-
345DH *-
346choose_dh(int min, int wantbits, int max)-
347{-
348 FILE *f;-
349 char *line = -
350 ((void *)0)-
351 ;-
352 size_t linesize = 0;-
353 int best, bestcount, which, linenum;-
354 struct dhgroup dhg;-
355-
356 if ((
(f = fopen("/v...== ((void *)0)Description
TRUEevaluated 40 times by 1 test
Evaluated by:
  • test_kex
FALSEnever evaluated
f = fopen("/var/tmp/openssh-test/etc" "/moduli", "r")) ==
(f = fopen("/v...== ((void *)0)Description
TRUEevaluated 40 times by 1 test
Evaluated by:
  • test_kex
FALSEnever evaluated
0-40
357 ((void *)0)
(f = fopen("/v...== ((void *)0)Description
TRUEevaluated 40 times by 1 test
Evaluated by:
  • test_kex
FALSEnever evaluated
0-40
358 ) {-
359 logit("WARNING: could not open %s (%s), using fixed modulus",-
360 "/var/tmp/openssh-test/etc" "/moduli", strerror(-
361 (*__errno_location ())-
362 ));-
363 return
executed 40 times by 1 test: return (dh_new_group_fallback(max));
Executed by:
  • test_kex
(dh_new_group_fallback(max));
executed 40 times by 1 test: return (dh_new_group_fallback(max));
Executed by:
  • test_kex
40
364 }-
365-
366 linenum = 0;-
367 best = bestcount = 0;-
368 while (getline(&line, &linesize, f) != -1
getline(&line,...size, f) != -1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
369 linenum++;-
370 if (!parse_prime(linenum, line, &dhg)
!parse_prime(l...m, line, &dhg)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
371 continue;
never executed: continue;
0
372 BN_clear_free(dhg.g);-
373 BN_clear_free(dhg.p);-
374-
375 if (dhg.size > max
dhg.size > maxDescription
TRUEnever evaluated
FALSEnever evaluated
|| dhg.size < min
dhg.size < minDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
376 continue;
never executed: continue;
0
377-
378 if ((dhg.size > wantbits
dhg.size > wantbitsDescription
TRUEnever evaluated
FALSEnever evaluated
&& dhg.size < best
dhg.size < bestDescription
TRUEnever evaluated
FALSEnever evaluated
) ||
0
379 (dhg.size > best
dhg.size > bestDescription
TRUEnever evaluated
FALSEnever evaluated
&& best < wantbits
best < wantbitsDescription
TRUEnever evaluated
FALSEnever evaluated
)) {
0
380 best = dhg.size;-
381 bestcount = 0;-
382 }
never executed: end of block
0
383 if (dhg.size == best
dhg.size == bestDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
384 bestcount++;
never executed: bestcount++;
0
385 }
never executed: end of block
0
386 free(line);-
387 line = -
388 ((void *)0)-
389 ;-
390 linesize = 0;-
391 rewind(f);-
392-
393 if (bestcount == 0
bestcount == 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
394 fclose(f);-
395 logit("WARNING: no suitable primes in %s", "/var/tmp/openssh-test/etc" "/moduli");-
396 return
never executed: return (dh_new_group_fallback(max));
(dh_new_group_fallback(max));
never executed: return (dh_new_group_fallback(max));
0
397 }-
398 which = arc4random_uniform(bestcount);-
399-
400 linenum = 0;-
401 bestcount = 0;-
402 while (getline(&line, &linesize, f) != -1
getline(&line,...size, f) != -1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
403 linenum++;-
404 if (!parse_prime(linenum, line, &dhg)
!parse_prime(l...m, line, &dhg)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
405 continue;
never executed: continue;
0
406 if ((dhg.size > max
dhg.size > maxDescription
TRUEnever evaluated
FALSEnever evaluated
|| dhg.size < min
dhg.size < minDescription
TRUEnever evaluated
FALSEnever evaluated
) ||
0
407 dhg.size != best
dhg.size != bestDescription
TRUEnever evaluated
FALSEnever evaluated
||
0
408 bestcount++ != which
bestcount++ != whichDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
409 BN_clear_free(dhg.g);-
410 BN_clear_free(dhg.p);-
411 continue;
never executed: continue;
0
412 }-
413 break;
never executed: break;
0
414 }-
415 free(line);-
416 line = -
417 ((void *)0)-
418 ;-
419 fclose(f);-
420 if (bestcount != which + 1
bestcount != which + 1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
421 logit("WARNING: selected prime disappeared in %s, giving up",-
422 "/var/tmp/openssh-test/etc" "/moduli");-
423 return
never executed: return (dh_new_group_fallback(max));
(dh_new_group_fallback(max));
never executed: return (dh_new_group_fallback(max));
0
424 }-
425-
426 return
never executed: return (dh_new_group(dhg.g, dhg.p));
(dh_new_group(dhg.g, dhg.p));
never executed: return (dh_new_group(dhg.g, dhg.p));
0
427}-
428-
429-
430-
431int-
432dh_pub_is_valid(const DH *dh, const BIGNUM *dh_pub)-
433{-
434 int i;-
435 int n = BN_num_bits(dh_pub);-
436 int bits_set = 0;-
437 BIGNUM *tmp;-
438 const BIGNUM *dh_p;-
439-
440 DH_get0_pqg(dh, &dh_p, -
441 ((void *)0)-
442 , -
443 ((void *)0)-
444 );-
445-
446 if (-
447 ((
(( dh_pub )->neg != 0)Description
TRUEnever evaluated
FALSEevaluated 320 times by 1 test
Evaluated by:
  • test_kex
0-320
448 dh_pub
(( dh_pub )->neg != 0)Description
TRUEnever evaluated
FALSEevaluated 320 times by 1 test
Evaluated by:
  • test_kex
0-320
449 )->neg != 0)
(( dh_pub )->neg != 0)Description
TRUEnever evaluated
FALSEevaluated 320 times by 1 test
Evaluated by:
  • test_kex
0-320
450 ) {-
451 logit("invalid public DH value: negative");-
452 return
never executed: return 0;
0;
never executed: return 0;
0
453 }-
454 if (BN_cmp(dh_pub, BN_value_one()) != 1
BN_cmp(dh_pub,...ue_one()) != 1Description
TRUEnever evaluated
FALSEevaluated 320 times by 1 test
Evaluated by:
  • test_kex
) {
0-320
455 logit("invalid public DH value: <= 1");-
456 return
never executed: return 0;
0;
never executed: return 0;
0
457 }-
458-
459 if ((
(tmp = BN_new(...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 320 times by 1 test
Evaluated by:
  • test_kex
tmp = BN_new()) ==
(tmp = BN_new(...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 320 times by 1 test
Evaluated by:
  • test_kex
0-320
460 ((void *)0)
(tmp = BN_new(...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 320 times by 1 test
Evaluated by:
  • test_kex
0-320
461 ) {-
462 error("%s: BN_new failed", __func__);-
463 return
never executed: return 0;
0;
never executed: return 0;
0
464 }-
465 if (!BN_sub(tmp, dh_p, BN_value_one())
!BN_sub(tmp, d...N_value_one())Description
TRUEnever evaluated
FALSEevaluated 320 times by 1 test
Evaluated by:
  • test_kex
||
0-320
466 BN_cmp(dh_pub, tmp) != -1
BN_cmp(dh_pub, tmp) != -1Description
TRUEnever evaluated
FALSEevaluated 320 times by 1 test
Evaluated by:
  • test_kex
) {
0-320
467 BN_clear_free(tmp);-
468 logit("invalid public DH value: >= p-1");-
469 return
never executed: return 0;
0;
never executed: return 0;
0
470 }-
471 BN_clear_free(tmp);-
472-
473 for (i = 0; i <= n
i <= nDescription
TRUEevaluated 1556474 times by 1 test
Evaluated by:
  • test_kex
FALSEevaluated 320 times by 1 test
Evaluated by:
  • test_kex
; i++)
320-1556474
474 if (BN_is_bit_set(dh_pub, i)
BN_is_bit_set(dh_pub, i)Description
TRUEevaluated 776620 times by 1 test
Evaluated by:
  • test_kex
FALSEevaluated 779854 times by 1 test
Evaluated by:
  • test_kex
)
776620-779854
475 bits_set++;
executed 776620 times by 1 test: bits_set++;
Executed by:
  • test_kex
776620
476 debug2("bits set: %d/%d", bits_set, BN_num_bits(dh_p));-
477-
478-
479-
480-
481 if (bits_set < 4
bits_set < 4Description
TRUEnever evaluated
FALSEevaluated 320 times by 1 test
Evaluated by:
  • test_kex
) {
0-320
482 logit("invalid public DH value (%d/%d)",-
483 bits_set, BN_num_bits(dh_p));-
484 return
never executed: return 0;
0;
never executed: return 0;
0
485 }-
486 return
executed 320 times by 1 test: return 1;
Executed by:
  • test_kex
1;
executed 320 times by 1 test: return 1;
Executed by:
  • test_kex
320
487}-
488-
489int-
490dh_gen_key(DH *dh, int need)-
491{-
492 int pbits;-
493 const BIGNUM *dh_p, *pub_key;-
494-
495 DH_get0_pqg(dh, &dh_p, -
496 ((void *)0)-
497 , -
498 ((void *)0)-
499 );-
500-
501 if (need < 0
need < 0Description
TRUEnever evaluated
FALSEevaluated 160 times by 1 test
Evaluated by:
  • test_kex
|| dh_p ==
dh_p == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 160 times by 1 test
Evaluated by:
  • test_kex
0-160
502 ((void *)0)
dh_p == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 160 times by 1 test
Evaluated by:
  • test_kex
0-160
503 ||-
504 (
(pbits = BN_nu...ts(dh_p)) <= 0Description
TRUEnever evaluated
FALSEevaluated 160 times by 1 test
Evaluated by:
  • test_kex
pbits = BN_num_bits(dh_p)) <= 0
(pbits = BN_nu...ts(dh_p)) <= 0Description
TRUEnever evaluated
FALSEevaluated 160 times by 1 test
Evaluated by:
  • test_kex
||
0-160
505 need > 0x7fffffff / 2
need > 0x7fffffff / 2Description
TRUEnever evaluated
FALSEevaluated 160 times by 1 test
Evaluated by:
  • test_kex
|| 2 * need > pbits
2 * need > pbitsDescription
TRUEnever evaluated
FALSEevaluated 160 times by 1 test
Evaluated by:
  • test_kex
)
0-160
506 return
never executed: return -10;
-10;
never executed: return -10;
0
507 if (need < 256
need < 256Description
TRUEnever evaluated
FALSEevaluated 160 times by 1 test
Evaluated by:
  • test_kex
)
0-160
508 need = 256;
never executed: need = 256;
0
509-
510-
511-
512-
513 if (!DH_set_length(dh, (((need * 2) < (pbits - 1)) ? (need * 2) : (pbits - 1)))
!DH_set_length... (pbits - 1)))Description
TRUEnever evaluated
FALSEevaluated 160 times by 1 test
Evaluated by:
  • test_kex
)
0-160
514 return
never executed: return -22;
-22;
never executed: return -22;
0
515-
516 if (DH_generate_key(dh) == 0
DH_generate_key(dh) == 0Description
TRUEnever evaluated
FALSEevaluated 160 times by 1 test
Evaluated by:
  • test_kex
)
0-160
517 return
never executed: return -22;
-22;
never executed: return -22;
0
518 DH_get0_key(dh, &pub_key, -
519 ((void *)0)-
520 );-
521 if (!dh_pub_is_valid(dh, pub_key)
!dh_pub_is_valid(dh, pub_key)Description
TRUEnever evaluated
FALSEevaluated 160 times by 1 test
Evaluated by:
  • test_kex
)
0-160
522 return
never executed: return -4;
-4;
never executed: return -4;
0
523 return
executed 160 times by 1 test: return 0;
Executed by:
  • test_kex
0;
executed 160 times by 1 test: return 0;
Executed by:
  • test_kex
160
524}-
525-
526DH *-
527dh_new_group_asc(const char *gen, const char *modulus)-
528{-
529 DH *dh;-
530 BIGNUM *dh_p = -
531 ((void *)0)-
532 , *dh_g = -
533 ((void *)0)-
534 ;-
535-
536 if ((
(dh = DH_new()) == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 120 times by 1 test
Evaluated by:
  • test_kex
dh = DH_new()) ==
(dh = DH_new()) == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 120 times by 1 test
Evaluated by:
  • test_kex
0-120
537 ((void *)0)
(dh = DH_new()) == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 120 times by 1 test
Evaluated by:
  • test_kex
0-120
538 )-
539 return
never executed: return ((void *)0) ;
never executed: return ((void *)0) ;
0
540 ((void *)0)
never executed: return ((void *)0) ;
0
541 ;
never executed: return ((void *)0) ;
0
542 if (BN_hex2bn(&dh_p, modulus) == 0
BN_hex2bn(&dh_p, modulus) == 0Description
TRUEnever evaluated
FALSEevaluated 120 times by 1 test
Evaluated by:
  • test_kex
||
0-120
543 BN_hex2bn(&dh_g, gen) == 0
BN_hex2bn(&dh_g, gen) == 0Description
TRUEnever evaluated
FALSEevaluated 120 times by 1 test
Evaluated by:
  • test_kex
)
0-120
544 goto
never executed: goto fail;
fail;
never executed: goto fail;
0
545 if (!DH_set0_pqg(dh, dh_p,
!DH_set0_pqg(d...d *)0) , dh_g)Description
TRUEnever evaluated
FALSEevaluated 120 times by 1 test
Evaluated by:
  • test_kex
0-120
546 ((void *)0)
!DH_set0_pqg(d...d *)0) , dh_g)Description
TRUEnever evaluated
FALSEevaluated 120 times by 1 test
Evaluated by:
  • test_kex
0-120
547 , dh_g)
!DH_set0_pqg(d...d *)0) , dh_g)Description
TRUEnever evaluated
FALSEevaluated 120 times by 1 test
Evaluated by:
  • test_kex
)
0-120
548 goto
never executed: goto fail;
fail;
never executed: goto fail;
0
549 return
executed 120 times by 1 test: return dh;
Executed by:
  • test_kex
dh;
executed 120 times by 1 test: return dh;
Executed by:
  • test_kex
120
550 fail:-
551 DH_free(dh);-
552 BN_clear_free(dh_p);-
553 BN_clear_free(dh_g);-
554 return
never executed: return ((void *)0) ;
never executed: return ((void *)0) ;
0
555 ((void *)0)
never executed: return ((void *)0) ;
0
556 ;
never executed: return ((void *)0) ;
0
557}-
558-
559-
560-
561-
562-
563DH *-
564dh_new_group(BIGNUM *gen, BIGNUM *modulus)-
565{-
566 DH *dh;-
567-
568 if ((
(dh = DH_new()) == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 40 times by 1 test
Evaluated by:
  • test_kex
dh = DH_new()) ==
(dh = DH_new()) == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 40 times by 1 test
Evaluated by:
  • test_kex
0-40
569 ((void *)0)
(dh = DH_new()) == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 40 times by 1 test
Evaluated by:
  • test_kex
0-40
570 )-
571 return
never executed: return ((void *)0) ;
never executed: return ((void *)0) ;
0
572 ((void *)0)
never executed: return ((void *)0) ;
0
573 ;
never executed: return ((void *)0) ;
0
574 if (!DH_set0_pqg(dh, modulus,
!DH_set0_pqg(d...id *)0) , gen)Description
TRUEnever evaluated
FALSEevaluated 40 times by 1 test
Evaluated by:
  • test_kex
0-40
575 ((void *)0)
!DH_set0_pqg(d...id *)0) , gen)Description
TRUEnever evaluated
FALSEevaluated 40 times by 1 test
Evaluated by:
  • test_kex
0-40
576 , gen)
!DH_set0_pqg(d...id *)0) , gen)Description
TRUEnever evaluated
FALSEevaluated 40 times by 1 test
Evaluated by:
  • test_kex
) {
0-40
577 DH_free(dh);-
578 return
never executed: return ((void *)0) ;
never executed: return ((void *)0) ;
0
579 ((void *)0)
never executed: return ((void *)0) ;
0
580 ;
never executed: return ((void *)0) ;
0
581 }-
582-
583 return
executed 40 times by 1 test: return dh;
Executed by:
  • test_kex
dh;
executed 40 times by 1 test: return dh;
Executed by:
  • test_kex
40
584}-
585-
586-
587DH *-
588dh_new_group1(void)-
589{-
590 static char *gen = "2", *group1 =-
591 "FFFFFFFF" "FFFFFFFF" "C90FDAA2" "2168C234" "C4C6628B" "80DC1CD1"-
592 "29024E08" "8A67CC74" "020BBEA6" "3B139B22" "514A0879" "8E3404DD"-
593 "EF9519B3" "CD3A431B" "302B0A6D" "F25F1437" "4FE1356D" "6D51C245"-
594 "E485B576" "625E7EC6" "F44C42E9" "A637ED6B" "0BFF5CB6" "F406B7ED"-
595 "EE386BFB" "5A899FA5" "AE9F2411" "7C4B1FE6" "49286651" "ECE65381"-
596 "FFFFFFFF" "FFFFFFFF";-
597-
598 return
executed 40 times by 1 test: return (dh_new_group_asc(gen, group1));
Executed by:
  • test_kex
(dh_new_group_asc(gen, group1));
executed 40 times by 1 test: return (dh_new_group_asc(gen, group1));
Executed by:
  • test_kex
40
599}-
600-
601-
602DH *-
603dh_new_group14(void)-
604{-
605 static char *gen = "2", *group14 =-
606 "FFFFFFFF" "FFFFFFFF" "C90FDAA2" "2168C234" "C4C6628B" "80DC1CD1"-
607 "29024E08" "8A67CC74" "020BBEA6" "3B139B22" "514A0879" "8E3404DD"-
608 "EF9519B3" "CD3A431B" "302B0A6D" "F25F1437" "4FE1356D" "6D51C245"-
609 "E485B576" "625E7EC6" "F44C42E9" "A637ED6B" "0BFF5CB6" "F406B7ED"-
610 "EE386BFB" "5A899FA5" "AE9F2411" "7C4B1FE6" "49286651" "ECE45B3D"-
611 "C2007CB8" "A163BF05" "98DA4836" "1C55D39A" "69163FA8" "FD24CF5F"-
612 "83655D23" "DCA3AD96" "1C62F356" "208552BB" "9ED52907" "7096966D"-
613 "670C354E" "4ABC9804" "F1746C08" "CA18217C" "32905E46" "2E36CE3B"-
614 "E39E772C" "180E8603" "9B2783A2" "EC07A28F" "B5C55DF0" "6F4C52C9"-
615 "DE2BCBF6" "95581718" "3995497C" "EA956AE5" "15D22618" "98FA0510"-
616 "15728E5A" "8AACAA68" "FFFFFFFF" "FFFFFFFF";-
617-
618 return
executed 40 times by 1 test: return (dh_new_group_asc(gen, group14));
Executed by:
  • test_kex
(dh_new_group_asc(gen, group14));
executed 40 times by 1 test: return (dh_new_group_asc(gen, group14));
Executed by:
  • test_kex
40
619}-
620-
621-
622DH *-
623dh_new_group16(void)-
624{-
625 static char *gen = "2", *group16 =-
626 "FFFFFFFF" "FFFFFFFF" "C90FDAA2" "2168C234" "C4C6628B" "80DC1CD1"-
627 "29024E08" "8A67CC74" "020BBEA6" "3B139B22" "514A0879" "8E3404DD"-
628 "EF9519B3" "CD3A431B" "302B0A6D" "F25F1437" "4FE1356D" "6D51C245"-
629 "E485B576" "625E7EC6" "F44C42E9" "A637ED6B" "0BFF5CB6" "F406B7ED"-
630 "EE386BFB" "5A899FA5" "AE9F2411" "7C4B1FE6" "49286651" "ECE45B3D"-
631 "C2007CB8" "A163BF05" "98DA4836" "1C55D39A" "69163FA8" "FD24CF5F"-
632 "83655D23" "DCA3AD96" "1C62F356" "208552BB" "9ED52907" "7096966D"-
633 "670C354E" "4ABC9804" "F1746C08" "CA18217C" "32905E46" "2E36CE3B"-
634 "E39E772C" "180E8603" "9B2783A2" "EC07A28F" "B5C55DF0" "6F4C52C9"-
635 "DE2BCBF6" "95581718" "3995497C" "EA956AE5" "15D22618" "98FA0510"-
636 "15728E5A" "8AAAC42D" "AD33170D" "04507A33" "A85521AB" "DF1CBA64"-
637 "ECFB8504" "58DBEF0A" "8AEA7157" "5D060C7D" "B3970F85" "A6E1E4C7"-
638 "ABF5AE8C" "DB0933D7" "1E8C94E0" "4A25619D" "CEE3D226" "1AD2EE6B"-
639 "F12FFA06" "D98A0864" "D8760273" "3EC86A64" "521F2B18" "177B200C"-
640 "BBE11757" "7A615D6C" "770988C0" "BAD946E2" "08E24FA0" "74E5AB31"-
641 "43DB5BFC" "E0FD108E" "4B82D120" "A9210801" "1A723C12" "A787E6D7"-
642 "88719A10" "BDBA5B26" "99C32718" "6AF4E23C" "1A946834" "B6150BDA"-
643 "2583E9CA" "2AD44CE8" "DBBBC2DB" "04DE8EF9" "2E8EFC14" "1FBECAA6"-
644 "287C5947" "4E6BC05D" "99B2964F" "A090C3A2" "233BA186" "515BE7ED"-
645 "1F612970" "CEE2D7AF" "B81BDD76" "2170481C" "D0069127" "D5B05AA9"-
646 "93B4EA98" "8D8FDDC1" "86FFB7DC" "90A6C08F" "4DF435C9" "34063199"-
647 "FFFFFFFF" "FFFFFFFF";-
648-
649 return
never executed: return (dh_new_group_asc(gen, group16));
(dh_new_group_asc(gen, group16));
never executed: return (dh_new_group_asc(gen, group16));
0
650}-
651-
652-
653DH *-
654dh_new_group18(void)-
655{-
656 static char *gen = "2", *group16 =-
657 "FFFFFFFF" "FFFFFFFF" "C90FDAA2" "2168C234" "C4C6628B" "80DC1CD1"-
658 "29024E08" "8A67CC74" "020BBEA6" "3B139B22" "514A0879" "8E3404DD"-
659 "EF9519B3" "CD3A431B" "302B0A6D" "F25F1437" "4FE1356D" "6D51C245"-
660 "E485B576" "625E7EC6" "F44C42E9" "A637ED6B" "0BFF5CB6" "F406B7ED"-
661 "EE386BFB" "5A899FA5" "AE9F2411" "7C4B1FE6" "49286651" "ECE45B3D"-
662 "C2007CB8" "A163BF05" "98DA4836" "1C55D39A" "69163FA8" "FD24CF5F"-
663 "83655D23" "DCA3AD96" "1C62F356" "208552BB" "9ED52907" "7096966D"-
664 "670C354E" "4ABC9804" "F1746C08" "CA18217C" "32905E46" "2E36CE3B"-
665 "E39E772C" "180E8603" "9B2783A2" "EC07A28F" "B5C55DF0" "6F4C52C9"-
666 "DE2BCBF6" "95581718" "3995497C" "EA956AE5" "15D22618" "98FA0510"-
667 "15728E5A" "8AAAC42D" "AD33170D" "04507A33" "A85521AB" "DF1CBA64"-
668 "ECFB8504" "58DBEF0A" "8AEA7157" "5D060C7D" "B3970F85" "A6E1E4C7"-
669 "ABF5AE8C" "DB0933D7" "1E8C94E0" "4A25619D" "CEE3D226" "1AD2EE6B"-
670 "F12FFA06" "D98A0864" "D8760273" "3EC86A64" "521F2B18" "177B200C"-
671 "BBE11757" "7A615D6C" "770988C0" "BAD946E2" "08E24FA0" "74E5AB31"-
672 "43DB5BFC" "E0FD108E" "4B82D120" "A9210801" "1A723C12" "A787E6D7"-
673 "88719A10" "BDBA5B26" "99C32718" "6AF4E23C" "1A946834" "B6150BDA"-
674 "2583E9CA" "2AD44CE8" "DBBBC2DB" "04DE8EF9" "2E8EFC14" "1FBECAA6"-
675 "287C5947" "4E6BC05D" "99B2964F" "A090C3A2" "233BA186" "515BE7ED"-
676 "1F612970" "CEE2D7AF" "B81BDD76" "2170481C" "D0069127" "D5B05AA9"-
677 "93B4EA98" "8D8FDDC1" "86FFB7DC" "90A6C08F" "4DF435C9" "34028492"-
678 "36C3FAB4" "D27C7026" "C1D4DCB2" "602646DE" "C9751E76" "3DBA37BD"-
679 "F8FF9406" "AD9E530E" "E5DB382F" "413001AE" "B06A53ED" "9027D831"-
680 "179727B0" "865A8918" "DA3EDBEB" "CF9B14ED" "44CE6CBA" "CED4BB1B"-
681 "DB7F1447" "E6CC254B" "33205151" "2BD7AF42" "6FB8F401" "378CD2BF"-
682 "5983CA01" "C64B92EC" "F032EA15" "D1721D03" "F482D7CE" "6E74FEF6"-
683 "D55E702F" "46980C82" "B5A84031" "900B1C9E" "59E7C97F" "BEC7E8F3"-
684 "23A97A7E" "36CC88BE" "0F1D45B7" "FF585AC5" "4BD407B2" "2B4154AA"-
685 "CC8F6D7E" "BF48E1D8" "14CC5ED2" "0F8037E0" "A79715EE" "F29BE328"-
686 "06A1D58B" "B7C5DA76" "F550AA3D" "8A1FBFF0" "EB19CCB1" "A313D55C"-
687 "DA56C9EC" "2EF29632" "387FE8D7" "6E3C0468" "043E8F66" "3F4860EE"-
688 "12BF2D5B" "0B7474D6" "E694F91E" "6DBE1159" "74A3926F" "12FEE5E4"-
689 "38777CB6" "A932DF8C" "D8BEC4D0" "73B931BA" "3BC832B6" "8D9DD300"-
690 "741FA7BF" "8AFC47ED" "2576F693" "6BA42466" "3AAB639C" "5AE4F568"-
691 "3423B474" "2BF1C978" "238F16CB" "E39D652D" "E3FDB8BE" "FC848AD9"-
692 "22222E04" "A4037C07" "13EB57A8" "1A23F0C7" "3473FC64" "6CEA306B"-
693 "4BCBC886" "2F8385DD" "FA9D4B7F" "A2C087E8" "79683303" "ED5BDD3A"-
694 "062B3CF5" "B3A278A6" "6D2A13F8" "3F44F82D" "DF310EE0" "74AB6A36"-
695 "4597E899" "A0255DC1" "64F31CC5" "0846851D" "F9AB4819" "5DED7EA1"-
696 "B1D510BD" "7EE74D73" "FAF36BC3" "1ECFA268" "359046F4" "EB879F92"-
697 "4009438B" "481C6CD7" "889A002E" "D5EE382B" "C9190DA6" "FC026E47"-
698 "9558E447" "5677E9AA" "9E3050E2" "765694DF" "C81F56E8" "80B96E71"-
699 "60C980DD" "98EDD3DF" "FFFFFFFF" "FFFFFFFF";-
700-
701 return
executed 40 times by 1 test: return (dh_new_group_asc(gen, group16));
Executed by:
  • test_kex
(dh_new_group_asc(gen, group16));
executed 40 times by 1 test: return (dh_new_group_asc(gen, group16));
Executed by:
  • test_kex
40
702}-
703-
704-
705DH *-
706dh_new_group_fallback(int max)-
707{-
708 debug3("%s: requested max size %d", __func__, max);-
709 if (max < 3072
max < 3072Description
TRUEnever evaluated
FALSEevaluated 40 times by 1 test
Evaluated by:
  • test_kex
) {
0-40
710 debug3("using 2k bit group 14");-
711 return
never executed: return dh_new_group14();
dh_new_group14();
never executed: return dh_new_group14();
0
712 } else if (max < 6144
max < 6144Description
TRUEnever evaluated
FALSEevaluated 40 times by 1 test
Evaluated by:
  • test_kex
) {
0-40
713 debug3("using 4k bit group 16");-
714 return
never executed: return dh_new_group16();
dh_new_group16();
never executed: return dh_new_group16();
0
715 }-
716 debug3("using 8k bit group 18");-
717 return
executed 40 times by 1 test: return dh_new_group18();
Executed by:
  • test_kex
dh_new_group18();
executed 40 times by 1 test: return dh_new_group18();
Executed by:
  • test_kex
40
718}-
719u_int-
720dh_estimate(int bits)-
721{-
722 if (bits <= 112
bits <= 112Description
TRUEnever evaluated
FALSEevaluated 40 times by 1 test
Evaluated by:
  • test_kex
)
0-40
723 return
never executed: return 2048;
2048;
never executed: return 2048;
0
724 if (bits <= 128
bits <= 128Description
TRUEnever evaluated
FALSEevaluated 40 times by 1 test
Evaluated by:
  • test_kex
)
0-40
725 return
never executed: return 3072;
3072;
never executed: return 3072;
0
726 if (bits <= 192
bits <= 192Description
TRUEnever evaluated
FALSEevaluated 40 times by 1 test
Evaluated by:
  • test_kex
)
0-40
727 return
never executed: return 7680;
7680;
never executed: return 7680;
0
728 return
executed 40 times by 1 test: return 8192;
Executed by:
  • test_kex
8192;
executed 40 times by 1 test: return 8192;
Executed by:
  • test_kex
40
729}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.2