Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/dh/dh_check.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||||||||
2 | - | |||||||||||||||||||||||||
3 | - | |||||||||||||||||||||||||
4 | - | |||||||||||||||||||||||||
5 | - | |||||||||||||||||||||||||
6 | - | |||||||||||||||||||||||||
7 | - | |||||||||||||||||||||||||
8 | int DH_check_params_ex(const DH *dh) | - | ||||||||||||||||||||||||
9 | { | - | ||||||||||||||||||||||||
10 | int errflags = 0; | - | ||||||||||||||||||||||||
11 | - | |||||||||||||||||||||||||
12 | (void)DH_check_params(dh, &errflags); | - | ||||||||||||||||||||||||
13 | - | |||||||||||||||||||||||||
14 | if ((
| 0 | ||||||||||||||||||||||||
15 | ERR_put_error(5,(122),(117),__FILE__,28); never executed: ERR_put_error(5,(122),(117),__FILE__,28); | 0 | ||||||||||||||||||||||||
16 | if ((
| 0 | ||||||||||||||||||||||||
17 | ERR_put_error(5,(122),(120),__FILE__,30); never executed: ERR_put_error(5,(122),(120),__FILE__,30); | 0 | ||||||||||||||||||||||||
18 | - | |||||||||||||||||||||||||
19 | return never executed: errflags == 0;return errflags == 0; never executed: return errflags == 0; | 0 | ||||||||||||||||||||||||
20 | } | - | ||||||||||||||||||||||||
21 | - | |||||||||||||||||||||||||
22 | int DH_check_params(const DH *dh, int *ret) | - | ||||||||||||||||||||||||
23 | { | - | ||||||||||||||||||||||||
24 | int ok = 0; | - | ||||||||||||||||||||||||
25 | BIGNUM *tmp = | - | ||||||||||||||||||||||||
26 | ((void *)0) | - | ||||||||||||||||||||||||
27 | ; | - | ||||||||||||||||||||||||
28 | BN_CTX *ctx = | - | ||||||||||||||||||||||||
29 | ((void *)0) | - | ||||||||||||||||||||||||
30 | ; | - | ||||||||||||||||||||||||
31 | - | |||||||||||||||||||||||||
32 | *ret = 0; | - | ||||||||||||||||||||||||
33 | ctx = BN_CTX_new(); | - | ||||||||||||||||||||||||
34 | if (ctx ==
| 0-385 | ||||||||||||||||||||||||
35 | ((void *)0)
| 0-385 | ||||||||||||||||||||||||
36 | ) | - | ||||||||||||||||||||||||
37 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
38 | BN_CTX_start(ctx); | - | ||||||||||||||||||||||||
39 | tmp = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||
40 | if (tmp ==
| 0-385 | ||||||||||||||||||||||||
41 | ((void *)0)
| 0-385 | ||||||||||||||||||||||||
42 | ) | - | ||||||||||||||||||||||||
43 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
44 | - | |||||||||||||||||||||||||
45 | if (!BN_is_odd(dh->p)
| 8-377 | ||||||||||||||||||||||||
46 | * executed 8 times by 1 test: ret |= 0x01;*ret |= 0x01; Executed by:
executed 8 times by 1 test: *ret |= 0x01; Executed by:
| 8 | ||||||||||||||||||||||||
47 | if (BN_is_negative(dh->g)
| 0-385 | ||||||||||||||||||||||||
48 | * executed 8 times by 1 test: ret |= 0x08;*ret |= 0x08; Executed by:
executed 8 times by 1 test: *ret |= 0x08; Executed by:
| 8 | ||||||||||||||||||||||||
49 | if (BN_copy(tmp, dh->p) ==
| 0-385 | ||||||||||||||||||||||||
50 | ((void *)0)
| 0-385 | ||||||||||||||||||||||||
51 | || !BN_sub_word(tmp, 1)
| 0-385 | ||||||||||||||||||||||||
52 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
53 | if (BN_cmp(dh->g, tmp) >= 0
| 3-382 | ||||||||||||||||||||||||
54 | * executed 3 times by 1 test: ret |= 0x08;*ret |= 0x08; Executed by:
executed 3 times by 1 test: *ret |= 0x08; Executed by:
| 3 | ||||||||||||||||||||||||
55 | - | |||||||||||||||||||||||||
56 | ok = 1; | - | ||||||||||||||||||||||||
57 | err: code before this statement executed 385 times by 1 test: err: Executed by:
| 385 | ||||||||||||||||||||||||
58 | if (ctx !=
| 0-385 | ||||||||||||||||||||||||
59 | ((void *)0)
| 0-385 | ||||||||||||||||||||||||
60 | ) { | - | ||||||||||||||||||||||||
61 | BN_CTX_end(ctx); | - | ||||||||||||||||||||||||
62 | BN_CTX_free(ctx); | - | ||||||||||||||||||||||||
63 | } executed 385 times by 1 test: end of block Executed by:
| 385 | ||||||||||||||||||||||||
64 | return executed 385 times by 1 test: ok;return ok; Executed by:
executed 385 times by 1 test: return ok; Executed by:
| 385 | ||||||||||||||||||||||||
65 | } | - | ||||||||||||||||||||||||
66 | int DH_check_ex(const DH *dh) | - | ||||||||||||||||||||||||
67 | { | - | ||||||||||||||||||||||||
68 | int errflags = 0; | - | ||||||||||||||||||||||||
69 | - | |||||||||||||||||||||||||
70 | (void)DH_check(dh, &errflags); | - | ||||||||||||||||||||||||
71 | - | |||||||||||||||||||||||||
72 | if ((
| 0 | ||||||||||||||||||||||||
73 | ERR_put_error(5,(121),(120),__FILE__,84); never executed: ERR_put_error(5,(121),(120),__FILE__,84); | 0 | ||||||||||||||||||||||||
74 | if ((
| 0 | ||||||||||||||||||||||||
75 | ERR_put_error(5,(121),(119),__FILE__,86); never executed: ERR_put_error(5,(121),(119),__FILE__,86); | 0 | ||||||||||||||||||||||||
76 | if ((
| 0 | ||||||||||||||||||||||||
77 | ERR_put_error(5,(121),(116),__FILE__,88); never executed: ERR_put_error(5,(121),(116),__FILE__,88); | 0 | ||||||||||||||||||||||||
78 | if ((
| 0 | ||||||||||||||||||||||||
79 | ERR_put_error(5,(121),(115),__FILE__,90); never executed: ERR_put_error(5,(121),(115),__FILE__,90); | 0 | ||||||||||||||||||||||||
80 | if ((
| 0 | ||||||||||||||||||||||||
81 | ERR_put_error(5,(121),(121),__FILE__,92); never executed: ERR_put_error(5,(121),(121),__FILE__,92); | 0 | ||||||||||||||||||||||||
82 | if ((
| 0 | ||||||||||||||||||||||||
83 | ERR_put_error(5,(121),(117),__FILE__,94); never executed: ERR_put_error(5,(121),(117),__FILE__,94); | 0 | ||||||||||||||||||||||||
84 | if ((
| 0 | ||||||||||||||||||||||||
85 | ERR_put_error(5,(121),(118),__FILE__,96); never executed: ERR_put_error(5,(121),(118),__FILE__,96); | 0 | ||||||||||||||||||||||||
86 | - | |||||||||||||||||||||||||
87 | return never executed: errflags == 0;return errflags == 0; never executed: return errflags == 0; | 0 | ||||||||||||||||||||||||
88 | } | - | ||||||||||||||||||||||||
89 | - | |||||||||||||||||||||||||
90 | int DH_check(const DH *dh, int *ret) | - | ||||||||||||||||||||||||
91 | { | - | ||||||||||||||||||||||||
92 | int ok = 0, r; | - | ||||||||||||||||||||||||
93 | BN_CTX *ctx = | - | ||||||||||||||||||||||||
94 | ((void *)0) | - | ||||||||||||||||||||||||
95 | ; | - | ||||||||||||||||||||||||
96 | unsigned long l; | - | ||||||||||||||||||||||||
97 | BIGNUM *t1 = | - | ||||||||||||||||||||||||
98 | ((void *)0) | - | ||||||||||||||||||||||||
99 | , *t2 = | - | ||||||||||||||||||||||||
100 | ((void *)0) | - | ||||||||||||||||||||||||
101 | ; | - | ||||||||||||||||||||||||
102 | - | |||||||||||||||||||||||||
103 | *ret = 0; | - | ||||||||||||||||||||||||
104 | ctx = BN_CTX_new(); | - | ||||||||||||||||||||||||
105 | if (ctx ==
| 0-1 | ||||||||||||||||||||||||
106 | ((void *)0)
| 0-1 | ||||||||||||||||||||||||
107 | ) | - | ||||||||||||||||||||||||
108 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
109 | BN_CTX_start(ctx); | - | ||||||||||||||||||||||||
110 | t1 = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||
111 | t2 = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||
112 | if (t2 ==
| 0-1 | ||||||||||||||||||||||||
113 | ((void *)0)
| 0-1 | ||||||||||||||||||||||||
114 | ) | - | ||||||||||||||||||||||||
115 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
116 | - | |||||||||||||||||||||||||
117 | if (dh->q
| 0-1 | ||||||||||||||||||||||||
118 | if (BN_cmp(dh->g, BN_value_one()) <= 0
| 0 | ||||||||||||||||||||||||
119 | * never executed: ret |= 0x08;*ret |= 0x08; never executed: *ret |= 0x08; | 0 | ||||||||||||||||||||||||
120 | else if (BN_cmp(dh->g, dh->p) >= 0
| 0 | ||||||||||||||||||||||||
121 | * never executed: ret |= 0x08;*ret |= 0x08; never executed: *ret |= 0x08; | 0 | ||||||||||||||||||||||||
122 | else { | - | ||||||||||||||||||||||||
123 | - | |||||||||||||||||||||||||
124 | if (!BN_mod_exp(t1, dh->g, dh->q, dh->p, ctx)
| 0 | ||||||||||||||||||||||||
125 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
126 | if (!BN_is_one(t1)
| 0 | ||||||||||||||||||||||||
127 | * never executed: ret |= 0x08;*ret |= 0x08; never executed: *ret |= 0x08; | 0 | ||||||||||||||||||||||||
128 | } never executed: end of block | 0 | ||||||||||||||||||||||||
129 | r = BN_is_prime_ex(dh->q, 0, ctx, | - | ||||||||||||||||||||||||
130 | ((void *)0) | - | ||||||||||||||||||||||||
131 | ); | - | ||||||||||||||||||||||||
132 | if (r < 0
| 0 | ||||||||||||||||||||||||
133 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
134 | if (!r
| 0 | ||||||||||||||||||||||||
135 | * never executed: ret |= 0x10;*ret |= 0x10; never executed: *ret |= 0x10; | 0 | ||||||||||||||||||||||||
136 | - | |||||||||||||||||||||||||
137 | if (!BN_div(t1, t2, dh->p, dh->q, ctx)
| 0 | ||||||||||||||||||||||||
138 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
139 | if (!BN_is_one(t2)
| 0 | ||||||||||||||||||||||||
140 | * never executed: ret |= 0x20;*ret |= 0x20; never executed: *ret |= 0x20; | 0 | ||||||||||||||||||||||||
141 | if (dh->j
| 0 | ||||||||||||||||||||||||
142 | * never executed: ret |= 0x40;*ret |= 0x40; never executed: *ret |= 0x40; | 0 | ||||||||||||||||||||||||
143 | - | |||||||||||||||||||||||||
144 | } never executed: else if (BN_is_word(dh->g, 2)end of block
| 0-1 | ||||||||||||||||||||||||
145 | l = BN_mod_word(dh->p, 24); | - | ||||||||||||||||||||||||
146 | if (l == (unsigned long)-1
| 0 | ||||||||||||||||||||||||
147 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
148 | if (l != 11
| 0 | ||||||||||||||||||||||||
149 | * never executed: ret |= 0x08;*ret |= 0x08; never executed: *ret |= 0x08; | 0 | ||||||||||||||||||||||||
150 | } never executed: else if (BN_is_word(dh->g, 5)end of block
| 0-1 | ||||||||||||||||||||||||
151 | l = BN_mod_word(dh->p, 10); | - | ||||||||||||||||||||||||
152 | if (l == (unsigned long)-1
| 0-1 | ||||||||||||||||||||||||
153 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
154 | if ((
| 0-1 | ||||||||||||||||||||||||
155 | * never executed: ret |= 0x08;*ret |= 0x08; never executed: *ret |= 0x08; | 0 | ||||||||||||||||||||||||
156 | } executed 1 time by 1 test: elseend of block Executed by:
| 1 | ||||||||||||||||||||||||
157 | * never executed: ret |= 0x04;*ret |= 0x04; never executed: *ret |= 0x04; | 0 | ||||||||||||||||||||||||
158 | - | |||||||||||||||||||||||||
159 | r = BN_is_prime_ex(dh->p, 0, ctx, | - | ||||||||||||||||||||||||
160 | ((void *)0) | - | ||||||||||||||||||||||||
161 | ); | - | ||||||||||||||||||||||||
162 | if (r < 0
| 0-1 | ||||||||||||||||||||||||
163 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
164 | if (!r
| 0-1 | ||||||||||||||||||||||||
165 | * never executed: ret |= 0x01;*ret |= 0x01; never executed: *ret |= 0x01; | 0 | ||||||||||||||||||||||||
166 | else if (!dh->q
| 0-1 | ||||||||||||||||||||||||
167 | if (!BN_rshift1(t1, dh->p)
| 0-1 | ||||||||||||||||||||||||
168 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
169 | r = BN_is_prime_ex(t1, 0, ctx, | - | ||||||||||||||||||||||||
170 | ((void *)0) | - | ||||||||||||||||||||||||
171 | ); | - | ||||||||||||||||||||||||
172 | if (r < 0
| 0-1 | ||||||||||||||||||||||||
173 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
174 | if (!r
| 0-1 | ||||||||||||||||||||||||
175 | * never executed: ret |= 0x02;*ret |= 0x02; never executed: *ret |= 0x02; | 0 | ||||||||||||||||||||||||
176 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||||||||
177 | ok = 1; | - | ||||||||||||||||||||||||
178 | err: code before this statement executed 1 time by 1 test: err: Executed by:
| 1 | ||||||||||||||||||||||||
179 | if (ctx !=
| 0-1 | ||||||||||||||||||||||||
180 | ((void *)0)
| 0-1 | ||||||||||||||||||||||||
181 | ) { | - | ||||||||||||||||||||||||
182 | BN_CTX_end(ctx); | - | ||||||||||||||||||||||||
183 | BN_CTX_free(ctx); | - | ||||||||||||||||||||||||
184 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||||||||
185 | return executed 1 time by 1 test: ok;return ok; Executed by:
executed 1 time by 1 test: return ok; Executed by:
| 1 | ||||||||||||||||||||||||
186 | } | - | ||||||||||||||||||||||||
187 | - | |||||||||||||||||||||||||
188 | int DH_check_pub_key_ex(const DH *dh, const BIGNUM *pub_key) | - | ||||||||||||||||||||||||
189 | { | - | ||||||||||||||||||||||||
190 | int errflags = 0; | - | ||||||||||||||||||||||||
191 | - | |||||||||||||||||||||||||
192 | (void)DH_check(dh, &errflags); | - | ||||||||||||||||||||||||
193 | - | |||||||||||||||||||||||||
194 | if ((
| 0 | ||||||||||||||||||||||||
195 | ERR_put_error(5,(123),(124),__FILE__,188); never executed: ERR_put_error(5,(123),(124),__FILE__,188); | 0 | ||||||||||||||||||||||||
196 | if ((
| 0 | ||||||||||||||||||||||||
197 | ERR_put_error(5,(123),(123),__FILE__,190); never executed: ERR_put_error(5,(123),(123),__FILE__,190); | 0 | ||||||||||||||||||||||||
198 | if ((
| 0 | ||||||||||||||||||||||||
199 | ERR_put_error(5,(123),(122),__FILE__,192); never executed: ERR_put_error(5,(123),(122),__FILE__,192); | 0 | ||||||||||||||||||||||||
200 | - | |||||||||||||||||||||||||
201 | return never executed: errflags == 0;return errflags == 0; never executed: return errflags == 0; | 0 | ||||||||||||||||||||||||
202 | } | - | ||||||||||||||||||||||||
203 | - | |||||||||||||||||||||||||
204 | int DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *ret) | - | ||||||||||||||||||||||||
205 | { | - | ||||||||||||||||||||||||
206 | int ok = 0; | - | ||||||||||||||||||||||||
207 | BIGNUM *tmp = | - | ||||||||||||||||||||||||
208 | ((void *)0) | - | ||||||||||||||||||||||||
209 | ; | - | ||||||||||||||||||||||||
210 | BN_CTX *ctx = | - | ||||||||||||||||||||||||
211 | ((void *)0) | - | ||||||||||||||||||||||||
212 | ; | - | ||||||||||||||||||||||||
213 | - | |||||||||||||||||||||||||
214 | *ret = 0; | - | ||||||||||||||||||||||||
215 | ctx = BN_CTX_new(); | - | ||||||||||||||||||||||||
216 | if (ctx ==
| 0-236 | ||||||||||||||||||||||||
217 | ((void *)0)
| 0-236 | ||||||||||||||||||||||||
218 | ) | - | ||||||||||||||||||||||||
219 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
220 | BN_CTX_start(ctx); | - | ||||||||||||||||||||||||
221 | tmp = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||
222 | if (tmp ==
| 0-236 | ||||||||||||||||||||||||
223 | ((void *)0)
| 0-236 | ||||||||||||||||||||||||
224 | || !BN_set_word(tmp, 1)
| 0-236 | ||||||||||||||||||||||||
225 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
226 | if (BN_cmp(pub_key, tmp) <= 0
| 1-235 | ||||||||||||||||||||||||
227 | * executed 1 time by 1 test: ret |= 0x01;*ret |= 0x01; Executed by:
executed 1 time by 1 test: *ret |= 0x01; Executed by:
| 1 | ||||||||||||||||||||||||
228 | if (BN_copy(tmp, dh->p) ==
| 0-236 | ||||||||||||||||||||||||
229 | ((void *)0)
| 0-236 | ||||||||||||||||||||||||
230 | || !BN_sub_word(tmp, 1)
| 0-236 | ||||||||||||||||||||||||
231 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
232 | if (BN_cmp(pub_key, tmp) >= 0
| 14-222 | ||||||||||||||||||||||||
233 | * executed 14 times by 1 test: ret |= 0x02;*ret |= 0x02; Executed by:
executed 14 times by 1 test: *ret |= 0x02; Executed by:
| 14 | ||||||||||||||||||||||||
234 | - | |||||||||||||||||||||||||
235 | if (dh->q !=
| 9-227 | ||||||||||||||||||||||||
236 | ((void *)0)
| 9-227 | ||||||||||||||||||||||||
237 | ) { | - | ||||||||||||||||||||||||
238 | - | |||||||||||||||||||||||||
239 | if (!BN_mod_exp(tmp, pub_key, dh->q, dh->p, ctx)
| 0-9 | ||||||||||||||||||||||||
240 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
241 | if (!BN_is_one(tmp)
| 1-8 | ||||||||||||||||||||||||
242 | * executed 1 time by 1 test: ret |= 0x04;*ret |= 0x04; Executed by:
executed 1 time by 1 test: *ret |= 0x04; Executed by:
| 1 | ||||||||||||||||||||||||
243 | } executed 9 times by 1 test: end of block Executed by:
| 9 | ||||||||||||||||||||||||
244 | - | |||||||||||||||||||||||||
245 | ok = 1; | - | ||||||||||||||||||||||||
246 | err: code before this statement executed 236 times by 1 test: err: Executed by:
| 236 | ||||||||||||||||||||||||
247 | if (ctx !=
| 0-236 | ||||||||||||||||||||||||
248 | ((void *)0)
| 0-236 | ||||||||||||||||||||||||
249 | ) { | - | ||||||||||||||||||||||||
250 | BN_CTX_end(ctx); | - | ||||||||||||||||||||||||
251 | BN_CTX_free(ctx); | - | ||||||||||||||||||||||||
252 | } executed 236 times by 1 test: end of block Executed by:
| 236 | ||||||||||||||||||||||||
253 | return executed 236 times by 1 test: ok;return ok; Executed by:
executed 236 times by 1 test: return ok; Executed by:
| 236 | ||||||||||||||||||||||||
254 | } | - | ||||||||||||||||||||||||
Switch to Source code | Preprocessed file |