Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/rsa/rsa_eay.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | - | |||||||||||||||||||
4 | - | |||||||||||||||||||
5 | static int RSA_eay_public_encrypt(int flen, const unsigned char *from, | - | ||||||||||||||||||
6 | unsigned char *to, RSA *rsa, int padding); | - | ||||||||||||||||||
7 | static int RSA_eay_private_encrypt(int flen, const unsigned char *from, | - | ||||||||||||||||||
8 | unsigned char *to, RSA *rsa, int padding); | - | ||||||||||||||||||
9 | static int RSA_eay_public_decrypt(int flen, const unsigned char *from, | - | ||||||||||||||||||
10 | unsigned char *to, RSA *rsa, int padding); | - | ||||||||||||||||||
11 | static int RSA_eay_private_decrypt(int flen, const unsigned char *from, | - | ||||||||||||||||||
12 | unsigned char *to, RSA *rsa, int padding); | - | ||||||||||||||||||
13 | static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *i, RSA *rsa, BN_CTX *ctx); | - | ||||||||||||||||||
14 | static int RSA_eay_init(RSA *rsa); | - | ||||||||||||||||||
15 | static int RSA_eay_finish(RSA *rsa); | - | ||||||||||||||||||
16 | - | |||||||||||||||||||
17 | static RSA_METHOD rsa_pkcs1_eay_meth = { | - | ||||||||||||||||||
18 | .name = "Eric Young's PKCS#1 RSA", | - | ||||||||||||||||||
19 | .rsa_pub_enc = RSA_eay_public_encrypt, | - | ||||||||||||||||||
20 | .rsa_pub_dec = RSA_eay_public_decrypt, | - | ||||||||||||||||||
21 | .rsa_priv_enc = RSA_eay_private_encrypt, | - | ||||||||||||||||||
22 | .rsa_priv_dec = RSA_eay_private_decrypt, | - | ||||||||||||||||||
23 | .rsa_mod_exp = RSA_eay_mod_exp, | - | ||||||||||||||||||
24 | .bn_mod_exp = BN_mod_exp_mont_ct, | - | ||||||||||||||||||
25 | .init = RSA_eay_init, | - | ||||||||||||||||||
26 | .finish = RSA_eay_finish, | - | ||||||||||||||||||
27 | }; | - | ||||||||||||||||||
28 | - | |||||||||||||||||||
29 | const RSA_METHOD * | - | ||||||||||||||||||
30 | RSA_PKCS1_SSLeay(void) | - | ||||||||||||||||||
31 | { | - | ||||||||||||||||||
32 | return executed 58 times by 6 tests: &rsa_pkcs1_eay_meth;return &rsa_pkcs1_eay_meth; Executed by:
executed 58 times by 6 tests: return &rsa_pkcs1_eay_meth; Executed by:
| 58 | ||||||||||||||||||
33 | } | - | ||||||||||||||||||
34 | - | |||||||||||||||||||
35 | static int | - | ||||||||||||||||||
36 | RSA_eay_public_encrypt(int flen, const unsigned char *from, unsigned char *to, | - | ||||||||||||||||||
37 | RSA *rsa, int padding) | - | ||||||||||||||||||
38 | { | - | ||||||||||||||||||
39 | BIGNUM *f, *ret; | - | ||||||||||||||||||
40 | int i, j, k, num = 0, r = -1; | - | ||||||||||||||||||
41 | unsigned char *buf = | - | ||||||||||||||||||
42 | ((void *)0) | - | ||||||||||||||||||
43 | ; | - | ||||||||||||||||||
44 | BN_CTX *ctx = | - | ||||||||||||||||||
45 | ((void *)0) | - | ||||||||||||||||||
46 | ; | - | ||||||||||||||||||
47 | - | |||||||||||||||||||
48 | if (BN_num_bits(rsa->n) > 16384
| 0-21 | ||||||||||||||||||
49 | ERR_put_error(4,(0xfff),(105),__FILE__,163); | - | ||||||||||||||||||
50 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||
51 | } | - | ||||||||||||||||||
52 | - | |||||||||||||||||||
53 | if (BN_ucmp(rsa->n, rsa->e) <= 0
| 0-21 | ||||||||||||||||||
54 | ERR_put_error(4,(0xfff),(101),__FILE__,168); | - | ||||||||||||||||||
55 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||
56 | } | - | ||||||||||||||||||
57 | - | |||||||||||||||||||
58 | - | |||||||||||||||||||
59 | if (BN_num_bits(rsa->n) > 3072
| 0-21 | ||||||||||||||||||
60 | if (BN_num_bits(rsa->e) > 64
| 0 | ||||||||||||||||||
61 | ERR_put_error(4,(0xfff),(101),__FILE__,175); | - | ||||||||||||||||||
62 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||
63 | } | - | ||||||||||||||||||
64 | } never executed: end of block | 0 | ||||||||||||||||||
65 | - | |||||||||||||||||||
66 | if ((
| 0-21 | ||||||||||||||||||
67 | ((void *)0)
| 0-21 | ||||||||||||||||||
68 | ) | - | ||||||||||||||||||
69 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
70 | - | |||||||||||||||||||
71 | BN_CTX_start(ctx); | - | ||||||||||||||||||
72 | f = BN_CTX_get(ctx); | - | ||||||||||||||||||
73 | ret = BN_CTX_get(ctx); | - | ||||||||||||||||||
74 | num = ((BN_num_bits(rsa->n)+7)/8); | - | ||||||||||||||||||
75 | buf = malloc(num); | - | ||||||||||||||||||
76 | - | |||||||||||||||||||
77 | if (f ==
| 0-21 | ||||||||||||||||||
78 | ((void *)0)
| 0-21 | ||||||||||||||||||
79 | || ret ==
| 0-21 | ||||||||||||||||||
80 | ((void *)0)
| 0-21 | ||||||||||||||||||
81 | || buf ==
| 0-21 | ||||||||||||||||||
82 | ((void *)0)
| 0-21 | ||||||||||||||||||
83 | ) { | - | ||||||||||||||||||
84 | ERR_put_error(4,(0xfff),((1|64)),__FILE__,190); | - | ||||||||||||||||||
85 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
86 | } | - | ||||||||||||||||||
87 | - | |||||||||||||||||||
88 | switch (padding) { | - | ||||||||||||||||||
89 | case executed 18 times by 3 tests: 1:case 1: Executed by:
executed 18 times by 3 tests: case 1: Executed by:
| 18 | ||||||||||||||||||
90 | i = RSA_padding_add_PKCS1_type_2(buf, num, from, flen); | - | ||||||||||||||||||
91 | break; executed 18 times by 3 tests: break; Executed by:
| 18 | ||||||||||||||||||
92 | - | |||||||||||||||||||
93 | case executed 3 times by 1 test: 4:case 4: Executed by:
executed 3 times by 1 test: case 4: Executed by:
| 3 | ||||||||||||||||||
94 | i = RSA_padding_add_PKCS1_OAEP(buf, num, from, flen, | - | ||||||||||||||||||
95 | ((void *)0) | - | ||||||||||||||||||
96 | , 0); | - | ||||||||||||||||||
97 | break; executed 3 times by 1 test: break; Executed by:
| 3 | ||||||||||||||||||
98 | - | |||||||||||||||||||
99 | case never executed: 3:case 3: never executed: case 3: | 0 | ||||||||||||||||||
100 | i = RSA_padding_add_none(buf, num, from, flen); | - | ||||||||||||||||||
101 | break; never executed: break; | 0 | ||||||||||||||||||
102 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||
103 | ERR_put_error(4,(0xfff),(118),__FILE__,207); | - | ||||||||||||||||||
104 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
105 | } | - | ||||||||||||||||||
106 | if (i <= 0
| 0-21 | ||||||||||||||||||
107 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
108 | - | |||||||||||||||||||
109 | if (BN_bin2bn(buf, num, f) ==
| 0-21 | ||||||||||||||||||
110 | ((void *)0)
| 0-21 | ||||||||||||||||||
111 | ) | - | ||||||||||||||||||
112 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
113 | - | |||||||||||||||||||
114 | if (BN_ucmp(f, rsa->n) >= 0
| 0-21 | ||||||||||||||||||
115 | - | |||||||||||||||||||
116 | ERR_put_error(4,(0xfff),(132),__FILE__,218); | - | ||||||||||||||||||
117 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
118 | } | - | ||||||||||||||||||
119 | - | |||||||||||||||||||
120 | if (rsa->flags & 0x0002
| 0-21 | ||||||||||||||||||
121 | if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n,
| 0-21 | ||||||||||||||||||
122 | 9, rsa->n, ctx)
| 0-21 | ||||||||||||||||||
123 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
124 | - | |||||||||||||||||||
125 | if (!rsa->meth->bn_mod_exp(ret, f, rsa->e, rsa->n, ctx,
| 0-21 | ||||||||||||||||||
126 | rsa->_method_mod_n)
| 0-21 | ||||||||||||||||||
127 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
128 | - | |||||||||||||||||||
129 | - | |||||||||||||||||||
130 | - | |||||||||||||||||||
131 | j = ((BN_num_bits(ret)+7)/8); | - | ||||||||||||||||||
132 | i = BN_bn2bin(ret, &(to[num - j])); | - | ||||||||||||||||||
133 | for (k = 0; k < num - i
| 0-21 | ||||||||||||||||||
134 | to[k] = 0; never executed: to[k] = 0; | 0 | ||||||||||||||||||
135 | - | |||||||||||||||||||
136 | r = num; | - | ||||||||||||||||||
137 | err: code before this statement executed 21 times by 3 tests: err: Executed by:
| 21 | ||||||||||||||||||
138 | if (ctx !=
| 0-21 | ||||||||||||||||||
139 | ((void *)0)
| 0-21 | ||||||||||||||||||
140 | ) { | - | ||||||||||||||||||
141 | BN_CTX_end(ctx); | - | ||||||||||||||||||
142 | BN_CTX_free(ctx); | - | ||||||||||||||||||
143 | } executed 21 times by 3 tests: end of block Executed by:
| 21 | ||||||||||||||||||
144 | freezero(buf, num); | - | ||||||||||||||||||
145 | return executed 21 times by 3 tests: r;return r; Executed by:
executed 21 times by 3 tests: return r; Executed by:
| 21 | ||||||||||||||||||
146 | } | - | ||||||||||||||||||
147 | - | |||||||||||||||||||
148 | static BN_BLINDING * | - | ||||||||||||||||||
149 | rsa_get_blinding(RSA *rsa, int *local, BN_CTX *ctx) | - | ||||||||||||||||||
150 | { | - | ||||||||||||||||||
151 | BN_BLINDING *ret; | - | ||||||||||||||||||
152 | int got_write_lock = 0; | - | ||||||||||||||||||
153 | CRYPTO_THREADID cur; | - | ||||||||||||||||||
154 | - | |||||||||||||||||||
155 | CRYPTO_lock(1|4,9,__FILE__,255); | - | ||||||||||||||||||
156 | - | |||||||||||||||||||
157 | if (rsa->blinding ==
| 67-492 | ||||||||||||||||||
158 | ((void *)0)
| 67-492 | ||||||||||||||||||
159 | ) { | - | ||||||||||||||||||
160 | CRYPTO_lock(2|4,9,__FILE__,258); | - | ||||||||||||||||||
161 | CRYPTO_lock(1|8,9,__FILE__,259); | - | ||||||||||||||||||
162 | got_write_lock = 1; | - | ||||||||||||||||||
163 | - | |||||||||||||||||||
164 | if (rsa->blinding ==
| 0-67 | ||||||||||||||||||
165 | ((void *)0)
| 0-67 | ||||||||||||||||||
166 | ) | - | ||||||||||||||||||
167 | rsa->blinding = RSA_setup_blinding(rsa, ctx); executed 67 times by 6 tests: rsa->blinding = RSA_setup_blinding(rsa, ctx); Executed by:
| 67 | ||||||||||||||||||
168 | } executed 67 times by 6 tests: end of block Executed by:
| 67 | ||||||||||||||||||
169 | - | |||||||||||||||||||
170 | ret = rsa->blinding; | - | ||||||||||||||||||
171 | if (ret ==
| 0-559 | ||||||||||||||||||
172 | ((void *)0)
| 0-559 | ||||||||||||||||||
173 | ) | - | ||||||||||||||||||
174 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
175 | - | |||||||||||||||||||
176 | CRYPTO_THREADID_current(&cur); | - | ||||||||||||||||||
177 | if (!CRYPTO_THREADID_cmp(&cur, BN_BLINDING_thread_id(ret))
| 0-559 | ||||||||||||||||||
178 | - | |||||||||||||||||||
179 | *local = 1; | - | ||||||||||||||||||
180 | } executed 559 times by 6 tests: else {end of block Executed by:
| 559 | ||||||||||||||||||
181 | - | |||||||||||||||||||
182 | - | |||||||||||||||||||
183 | - | |||||||||||||||||||
184 | - | |||||||||||||||||||
185 | - | |||||||||||||||||||
186 | - | |||||||||||||||||||
187 | - | |||||||||||||||||||
188 | *local = 0; | - | ||||||||||||||||||
189 | - | |||||||||||||||||||
190 | if (rsa->mt_blinding ==
| 0 | ||||||||||||||||||
191 | ((void *)0)
| 0 | ||||||||||||||||||
192 | ) { | - | ||||||||||||||||||
193 | if (!got_write_lock
| 0 | ||||||||||||||||||
194 | CRYPTO_lock(2|4,9,__FILE__,286); | - | ||||||||||||||||||
195 | CRYPTO_lock(1|8,9,__FILE__,287); | - | ||||||||||||||||||
196 | got_write_lock = 1; | - | ||||||||||||||||||
197 | } never executed: end of block | 0 | ||||||||||||||||||
198 | - | |||||||||||||||||||
199 | if (rsa->mt_blinding ==
| 0 | ||||||||||||||||||
200 | ((void *)0)
| 0 | ||||||||||||||||||
201 | ) | - | ||||||||||||||||||
202 | rsa->mt_blinding = RSA_setup_blinding(rsa, ctx); never executed: rsa->mt_blinding = RSA_setup_blinding(rsa, ctx); | 0 | ||||||||||||||||||
203 | } never executed: end of block | 0 | ||||||||||||||||||
204 | ret = rsa->mt_blinding; | - | ||||||||||||||||||
205 | } never executed: end of block | 0 | ||||||||||||||||||
206 | - | |||||||||||||||||||
207 | err: code before this statement executed 559 times by 6 tests: err: Executed by:
| 559 | ||||||||||||||||||
208 | if (got_write_lock
| 67-492 | ||||||||||||||||||
209 | CRYPTO_lock(2|8,9,__FILE__,299); executed 67 times by 6 tests: CRYPTO_lock(2|8,9,__FILE__,299); Executed by:
| 67 | ||||||||||||||||||
210 | else | - | ||||||||||||||||||
211 | CRYPTO_lock(2|4,9,__FILE__,301); executed 492 times by 2 tests: CRYPTO_lock(2|4,9,__FILE__,301); Executed by:
| 492 | ||||||||||||||||||
212 | return executed 559 times by 6 tests: ret;return ret; Executed by:
executed 559 times by 6 tests: return ret; Executed by:
| 559 | ||||||||||||||||||
213 | } | - | ||||||||||||||||||
214 | - | |||||||||||||||||||
215 | static int | - | ||||||||||||||||||
216 | rsa_blinding_convert(BN_BLINDING *b, BIGNUM *f, BIGNUM *unblind, BN_CTX *ctx) | - | ||||||||||||||||||
217 | { | - | ||||||||||||||||||
218 | if (unblind ==
| 0-559 | ||||||||||||||||||
219 | ((void *)0)
| 0-559 | ||||||||||||||||||
220 | ) | - | ||||||||||||||||||
221 | - | |||||||||||||||||||
222 | - | |||||||||||||||||||
223 | - | |||||||||||||||||||
224 | - | |||||||||||||||||||
225 | return executed 559 times by 6 tests: BN_BLINDING_convert_ex(f, return BN_BLINDING_convert_ex(f, ((void *)0) , b, ctx); Executed by:
executed 559 times by 6 tests: return BN_BLINDING_convert_ex(f, ((void *)0) , b, ctx); Executed by:
| 559 | ||||||||||||||||||
226 | ((void *)0) executed 559 times by 6 tests: return BN_BLINDING_convert_ex(f, ((void *)0) , b, ctx); Executed by:
| 559 | ||||||||||||||||||
227 | , b, ctx); executed 559 times by 6 tests: return BN_BLINDING_convert_ex(f, ((void *)0) , b, ctx); Executed by:
| 559 | ||||||||||||||||||
228 | else { | - | ||||||||||||||||||
229 | - | |||||||||||||||||||
230 | - | |||||||||||||||||||
231 | - | |||||||||||||||||||
232 | - | |||||||||||||||||||
233 | int ret; | - | ||||||||||||||||||
234 | CRYPTO_lock(1|8,25,__FILE__,320); | - | ||||||||||||||||||
235 | ret = BN_BLINDING_convert_ex(f, unblind, b, ctx); | - | ||||||||||||||||||
236 | CRYPTO_lock(2|8,25,__FILE__,322); | - | ||||||||||||||||||
237 | return never executed: ret;return ret; never executed: return ret; | 0 | ||||||||||||||||||
238 | } | - | ||||||||||||||||||
239 | } | - | ||||||||||||||||||
240 | - | |||||||||||||||||||
241 | static int | - | ||||||||||||||||||
242 | rsa_blinding_invert(BN_BLINDING *b, BIGNUM *f, BIGNUM *unblind, BN_CTX *ctx) | - | ||||||||||||||||||
243 | { | - | ||||||||||||||||||
244 | return executed 559 times by 6 tests: BN_BLINDING_invert_ex(f, unblind, b, ctx);return BN_BLINDING_invert_ex(f, unblind, b, ctx); Executed by:
executed 559 times by 6 tests: return BN_BLINDING_invert_ex(f, unblind, b, ctx); Executed by:
| 559 | ||||||||||||||||||
245 | } | - | ||||||||||||||||||
246 | - | |||||||||||||||||||
247 | - | |||||||||||||||||||
248 | static int | - | ||||||||||||||||||
249 | RSA_eay_private_encrypt(int flen, const unsigned char *from, unsigned char *to, | - | ||||||||||||||||||
250 | RSA *rsa, int padding) | - | ||||||||||||||||||
251 | { | - | ||||||||||||||||||
252 | BIGNUM *f, *ret, *res; | - | ||||||||||||||||||
253 | int i, j, k, num = 0, r = -1; | - | ||||||||||||||||||
254 | unsigned char *buf = | - | ||||||||||||||||||
255 | ((void *)0) | - | ||||||||||||||||||
256 | ; | - | ||||||||||||||||||
257 | BN_CTX *ctx = | - | ||||||||||||||||||
258 | ((void *)0) | - | ||||||||||||||||||
259 | ; | - | ||||||||||||||||||
260 | int local_blinding = 0; | - | ||||||||||||||||||
261 | - | |||||||||||||||||||
262 | - | |||||||||||||||||||
263 | - | |||||||||||||||||||
264 | - | |||||||||||||||||||
265 | - | |||||||||||||||||||
266 | BIGNUM *unblind = | - | ||||||||||||||||||
267 | ((void *)0) | - | ||||||||||||||||||
268 | ; | - | ||||||||||||||||||
269 | BN_BLINDING *blinding = | - | ||||||||||||||||||
270 | ((void *)0) | - | ||||||||||||||||||
271 | ; | - | ||||||||||||||||||
272 | - | |||||||||||||||||||
273 | if ((
| 0-51 | ||||||||||||||||||
274 | ((void *)0)
| 0-51 | ||||||||||||||||||
275 | ) | - | ||||||||||||||||||
276 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
277 | - | |||||||||||||||||||
278 | BN_CTX_start(ctx); | - | ||||||||||||||||||
279 | f = BN_CTX_get(ctx); | - | ||||||||||||||||||
280 | ret = BN_CTX_get(ctx); | - | ||||||||||||||||||
281 | num = ((BN_num_bits(rsa->n)+7)/8); | - | ||||||||||||||||||
282 | buf = malloc(num); | - | ||||||||||||||||||
283 | - | |||||||||||||||||||
284 | if (f ==
| 0-51 | ||||||||||||||||||
285 | ((void *)0)
| 0-51 | ||||||||||||||||||
286 | || ret ==
| 0-51 | ||||||||||||||||||
287 | ((void *)0)
| 0-51 | ||||||||||||||||||
288 | || buf ==
| 0-51 | ||||||||||||||||||
289 | ((void *)0)
| 0-51 | ||||||||||||||||||
290 | ) { | - | ||||||||||||||||||
291 | ERR_put_error(4,(0xfff),((1|64)),__FILE__,369); | - | ||||||||||||||||||
292 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
293 | } | - | ||||||||||||||||||
294 | - | |||||||||||||||||||
295 | switch (padding) { | - | ||||||||||||||||||
296 | case executed 51 times by 5 tests: 1:case 1: Executed by:
executed 51 times by 5 tests: case 1: Executed by:
| 51 | ||||||||||||||||||
297 | i = RSA_padding_add_PKCS1_type_1(buf, num, from, flen); | - | ||||||||||||||||||
298 | break; executed 51 times by 5 tests: break; Executed by:
| 51 | ||||||||||||||||||
299 | case never executed: 5:case 5: never executed: case 5: | 0 | ||||||||||||||||||
300 | i = RSA_padding_add_X931(buf, num, from, flen); | - | ||||||||||||||||||
301 | break; never executed: break; | 0 | ||||||||||||||||||
302 | case never executed: 3:case 3: never executed: case 3: | 0 | ||||||||||||||||||
303 | i = RSA_padding_add_none(buf, num, from, flen); | - | ||||||||||||||||||
304 | break; never executed: break; | 0 | ||||||||||||||||||
305 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||
306 | ERR_put_error(4,(0xfff),(118),__FILE__,384); | - | ||||||||||||||||||
307 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
308 | } | - | ||||||||||||||||||
309 | if (i <= 0
| 0-51 | ||||||||||||||||||
310 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
311 | - | |||||||||||||||||||
312 | if (BN_bin2bn(buf, num, f) ==
| 0-51 | ||||||||||||||||||
313 | ((void *)0)
| 0-51 | ||||||||||||||||||
314 | ) | - | ||||||||||||||||||
315 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
316 | - | |||||||||||||||||||
317 | if (BN_ucmp(f, rsa->n) >= 0
| 0-51 | ||||||||||||||||||
318 | - | |||||||||||||||||||
319 | ERR_put_error(4,(0xfff),(132),__FILE__,395); | - | ||||||||||||||||||
320 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
321 | } | - | ||||||||||||||||||
322 | - | |||||||||||||||||||
323 | if (!(rsa->flags & 0x0080)
| 0-51 | ||||||||||||||||||
324 | blinding = rsa_get_blinding(rsa, &local_blinding, ctx); | - | ||||||||||||||||||
325 | if (blinding ==
| 0-51 | ||||||||||||||||||
326 | ((void *)0)
| 0-51 | ||||||||||||||||||
327 | ) { | - | ||||||||||||||||||
328 | ERR_put_error(4,(0xfff),((4|64)),__FILE__,402); | - | ||||||||||||||||||
329 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
330 | } | - | ||||||||||||||||||
331 | } executed 51 times by 5 tests: end of block Executed by:
| 51 | ||||||||||||||||||
332 | - | |||||||||||||||||||
333 | if (blinding !=
| 0-51 | ||||||||||||||||||
334 | ((void *)0)
| 0-51 | ||||||||||||||||||
335 | ) { | - | ||||||||||||||||||
336 | if (!local_blinding
| 0-51 | ||||||||||||||||||
337 | ((void *)0)
| 0 | ||||||||||||||||||
338 | )
| 0 | ||||||||||||||||||
339 | ERR_put_error(4,(0xfff),((1|64)),__FILE__,409); | - | ||||||||||||||||||
340 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
341 | } | - | ||||||||||||||||||
342 | if (!rsa_blinding_convert(blinding, f, unblind, ctx)
| 0-51 | ||||||||||||||||||
343 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
344 | } executed 51 times by 5 tests: end of block Executed by:
| 51 | ||||||||||||||||||
345 | - | |||||||||||||||||||
346 | if ((
| 0-51 | ||||||||||||||||||
347 | (rsa->p !=
| 0-51 | ||||||||||||||||||
348 | ((void *)0)
| 0-51 | ||||||||||||||||||
349 | && rsa->q !=
| 0-51 | ||||||||||||||||||
350 | ((void *)0)
| 0-51 | ||||||||||||||||||
351 | && rsa->dmp1 !=
| 0-51 | ||||||||||||||||||
352 | ((void *)0)
| 0-51 | ||||||||||||||||||
353 | && | - | ||||||||||||||||||
354 | rsa->dmq1 !=
| 0-51 | ||||||||||||||||||
355 | ((void *)0)
| 0-51 | ||||||||||||||||||
356 | && rsa->iqmp !=
| 0-51 | ||||||||||||||||||
357 | ((void *)0)
| 0-51 | ||||||||||||||||||
358 | )) { | - | ||||||||||||||||||
359 | if (!rsa->meth->rsa_mod_exp(ret, f, rsa, ctx)
| 0-51 | ||||||||||||||||||
360 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
361 | } executed 51 times by 5 tests: else {end of block Executed by:
| 51 | ||||||||||||||||||
362 | BIGNUM d; | - | ||||||||||||||||||
363 | - | |||||||||||||||||||
364 | BN_init(&d); | - | ||||||||||||||||||
365 | ((&d)->d=(rsa->d)->d, (&d)->top=(rsa->d)->top, (&d)->dmax=(rsa->d)->dmax, (&d)->neg=(rsa->d)->neg, (&d)->flags=(((&d)->flags & 0x01) | ((rsa->d)->flags & ~0x01) | 0x02 | (0x04))); | - | ||||||||||||||||||
366 | - | |||||||||||||||||||
367 | if (rsa->flags & 0x0002
| 0 | ||||||||||||||||||
368 | if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n,
| 0 | ||||||||||||||||||
369 | 9, rsa->n, ctx)
| 0 | ||||||||||||||||||
370 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
371 | - | |||||||||||||||||||
372 | if (!rsa->meth->bn_mod_exp(ret, f, &d, rsa->n, ctx,
| 0 | ||||||||||||||||||
373 | rsa->_method_mod_n)
| 0 | ||||||||||||||||||
374 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
375 | } | - | ||||||||||||||||||
376 | } never executed: end of block | 0 | ||||||||||||||||||
377 | - | |||||||||||||||||||
378 | if (blinding
| 0-51 | ||||||||||||||||||
379 | if (!rsa_blinding_invert(blinding, ret, unblind, ctx)
| 0-51 | ||||||||||||||||||
380 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
381 | - | |||||||||||||||||||
382 | if (padding == 5
| 0-51 | ||||||||||||||||||
383 | BN_sub(f, rsa->n, ret); | - | ||||||||||||||||||
384 | if (BN_cmp(ret, f) > 0
| 0 | ||||||||||||||||||
385 | res = f; never executed: res = f; | 0 | ||||||||||||||||||
386 | else | - | ||||||||||||||||||
387 | res = ret; never executed: res = ret; | 0 | ||||||||||||||||||
388 | } else | - | ||||||||||||||||||
389 | res = ret; executed 51 times by 5 tests: res = ret; Executed by:
| 51 | ||||||||||||||||||
390 | - | |||||||||||||||||||
391 | - | |||||||||||||||||||
392 | - | |||||||||||||||||||
393 | j = ((BN_num_bits(res)+7)/8); | - | ||||||||||||||||||
394 | i = BN_bn2bin(res, &(to[num - j])); | - | ||||||||||||||||||
395 | for (k = 0; k < num - i
| 0-51 | ||||||||||||||||||
396 | to[k] = 0; never executed: to[k] = 0; | 0 | ||||||||||||||||||
397 | - | |||||||||||||||||||
398 | r = num; | - | ||||||||||||||||||
399 | err: code before this statement executed 51 times by 5 tests: err: Executed by:
| 51 | ||||||||||||||||||
400 | if (ctx !=
| 0-51 | ||||||||||||||||||
401 | ((void *)0)
| 0-51 | ||||||||||||||||||
402 | ) { | - | ||||||||||||||||||
403 | BN_CTX_end(ctx); | - | ||||||||||||||||||
404 | BN_CTX_free(ctx); | - | ||||||||||||||||||
405 | } executed 51 times by 5 tests: end of block Executed by:
| 51 | ||||||||||||||||||
406 | freezero(buf, num); | - | ||||||||||||||||||
407 | return executed 51 times by 5 tests: r;return r; Executed by:
executed 51 times by 5 tests: return r; Executed by:
| 51 | ||||||||||||||||||
408 | } | - | ||||||||||||||||||
409 | - | |||||||||||||||||||
410 | static int | - | ||||||||||||||||||
411 | RSA_eay_private_decrypt(int flen, const unsigned char *from, unsigned char *to, | - | ||||||||||||||||||
412 | RSA *rsa, int padding) | - | ||||||||||||||||||
413 | { | - | ||||||||||||||||||
414 | BIGNUM *f, *ret; | - | ||||||||||||||||||
415 | int j, num = 0, r = -1; | - | ||||||||||||||||||
416 | unsigned char *p; | - | ||||||||||||||||||
417 | unsigned char *buf = | - | ||||||||||||||||||
418 | ((void *)0) | - | ||||||||||||||||||
419 | ; | - | ||||||||||||||||||
420 | BN_CTX *ctx = | - | ||||||||||||||||||
421 | ((void *)0) | - | ||||||||||||||||||
422 | ; | - | ||||||||||||||||||
423 | int local_blinding = 0; | - | ||||||||||||||||||
424 | - | |||||||||||||||||||
425 | - | |||||||||||||||||||
426 | - | |||||||||||||||||||
427 | - | |||||||||||||||||||
428 | - | |||||||||||||||||||
429 | BIGNUM *unblind = | - | ||||||||||||||||||
430 | ((void *)0) | - | ||||||||||||||||||
431 | ; | - | ||||||||||||||||||
432 | BN_BLINDING *blinding = | - | ||||||||||||||||||
433 | ((void *)0) | - | ||||||||||||||||||
434 | ; | - | ||||||||||||||||||
435 | - | |||||||||||||||||||
436 | if ((
| 0-511 | ||||||||||||||||||
437 | ((void *)0)
| 0-511 | ||||||||||||||||||
438 | ) | - | ||||||||||||||||||
439 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
440 | - | |||||||||||||||||||
441 | BN_CTX_start(ctx); | - | ||||||||||||||||||
442 | f = BN_CTX_get(ctx); | - | ||||||||||||||||||
443 | ret = BN_CTX_get(ctx); | - | ||||||||||||||||||
444 | num = ((BN_num_bits(rsa->n)+7)/8); | - | ||||||||||||||||||
445 | buf = malloc(num); | - | ||||||||||||||||||
446 | - | |||||||||||||||||||
447 | if (!f
| 0-511 | ||||||||||||||||||
448 | ERR_put_error(4,(0xfff),((1|64)),__FILE__,496); | - | ||||||||||||||||||
449 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
450 | } | - | ||||||||||||||||||
451 | - | |||||||||||||||||||
452 | - | |||||||||||||||||||
453 | - | |||||||||||||||||||
454 | if (flen > num
| 0-511 | ||||||||||||||||||
455 | ERR_put_error(4,(0xfff),(108),__FILE__,503); | - | ||||||||||||||||||
456 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
457 | } | - | ||||||||||||||||||
458 | - | |||||||||||||||||||
459 | - | |||||||||||||||||||
460 | if (BN_bin2bn(from, (int)flen, f) ==
| 3-508 | ||||||||||||||||||
461 | ((void *)0)
| 3-508 | ||||||||||||||||||
462 | ) | - | ||||||||||||||||||
463 | goto executed 3 times by 1 test: err;goto err; Executed by:
executed 3 times by 1 test: goto err; Executed by:
| 3 | ||||||||||||||||||
464 | - | |||||||||||||||||||
465 | if (BN_ucmp(f, rsa->n) >= 0
| 0-508 | ||||||||||||||||||
466 | ERR_put_error(4,(0xfff),(132),__FILE__,512); | - | ||||||||||||||||||
467 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
468 | } | - | ||||||||||||||||||
469 | - | |||||||||||||||||||
470 | if (!(rsa->flags & 0x0080)
| 0-508 | ||||||||||||||||||
471 | blinding = rsa_get_blinding(rsa, &local_blinding, ctx); | - | ||||||||||||||||||
472 | if (blinding ==
| 0-508 | ||||||||||||||||||
473 | ((void *)0)
| 0-508 | ||||||||||||||||||
474 | ) { | - | ||||||||||||||||||
475 | ERR_put_error(4,(0xfff),((4|64)),__FILE__,519); | - | ||||||||||||||||||
476 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
477 | } | - | ||||||||||||||||||
478 | } executed 508 times by 3 tests: end of block Executed by:
| 508 | ||||||||||||||||||
479 | - | |||||||||||||||||||
480 | if (blinding !=
| 0-508 | ||||||||||||||||||
481 | ((void *)0)
| 0-508 | ||||||||||||||||||
482 | ) { | - | ||||||||||||||||||
483 | if (!local_blinding
| 0-508 | ||||||||||||||||||
484 | ((void *)0)
| 0 | ||||||||||||||||||
485 | )
| 0 | ||||||||||||||||||
486 | ERR_put_error(4,(0xfff),((1|64)),__FILE__,526); | - | ||||||||||||||||||
487 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
488 | } | - | ||||||||||||||||||
489 | if (!rsa_blinding_convert(blinding, f, unblind, ctx)
| 0-508 | ||||||||||||||||||
490 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
491 | } executed 508 times by 3 tests: end of block Executed by:
| 508 | ||||||||||||||||||
492 | - | |||||||||||||||||||
493 | - | |||||||||||||||||||
494 | if ((
| 0-508 | ||||||||||||||||||
495 | (rsa->p !=
| 0-508 | ||||||||||||||||||
496 | ((void *)0)
| 0-508 | ||||||||||||||||||
497 | && rsa->q !=
| 0-508 | ||||||||||||||||||
498 | ((void *)0)
| 0-508 | ||||||||||||||||||
499 | && rsa->dmp1 !=
| 0-508 | ||||||||||||||||||
500 | ((void *)0)
| 0-508 | ||||||||||||||||||
501 | && | - | ||||||||||||||||||
502 | rsa->dmq1 !=
| 0-508 | ||||||||||||||||||
503 | ((void *)0)
| 0-508 | ||||||||||||||||||
504 | && rsa->iqmp !=
| 0-508 | ||||||||||||||||||
505 | ((void *)0)
| 0-508 | ||||||||||||||||||
506 | )) { | - | ||||||||||||||||||
507 | if (!rsa->meth->rsa_mod_exp(ret, f, rsa, ctx)
| 0-508 | ||||||||||||||||||
508 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
509 | } executed 508 times by 3 tests: else {end of block Executed by:
| 508 | ||||||||||||||||||
510 | BIGNUM d; | - | ||||||||||||||||||
511 | - | |||||||||||||||||||
512 | BN_init(&d); | - | ||||||||||||||||||
513 | ((&d)->d=(rsa->d)->d, (&d)->top=(rsa->d)->top, (&d)->dmax=(rsa->d)->dmax, (&d)->neg=(rsa->d)->neg, (&d)->flags=(((&d)->flags & 0x01) | ((rsa->d)->flags & ~0x01) | 0x02 | (0x04))); | - | ||||||||||||||||||
514 | - | |||||||||||||||||||
515 | if (rsa->flags & 0x0002
| 0 | ||||||||||||||||||
516 | if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n,
| 0 | ||||||||||||||||||
517 | 9, rsa->n, ctx)
| 0 | ||||||||||||||||||
518 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
519 | - | |||||||||||||||||||
520 | if (!rsa->meth->bn_mod_exp(ret, f, &d, rsa->n, ctx,
| 0 | ||||||||||||||||||
521 | rsa->_method_mod_n)
| 0 | ||||||||||||||||||
522 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
523 | } | - | ||||||||||||||||||
524 | } never executed: end of block | 0 | ||||||||||||||||||
525 | - | |||||||||||||||||||
526 | if (blinding
| 0-508 | ||||||||||||||||||
527 | if (!rsa_blinding_invert(blinding, ret, unblind, ctx)
| 0-508 | ||||||||||||||||||
528 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
529 | - | |||||||||||||||||||
530 | p = buf; | - | ||||||||||||||||||
531 | j = BN_bn2bin(ret, p); | - | ||||||||||||||||||
532 | - | |||||||||||||||||||
533 | switch (padding) { | - | ||||||||||||||||||
534 | case executed 18 times by 3 tests: 1:case 1: Executed by:
executed 18 times by 3 tests: case 1: Executed by:
| 18 | ||||||||||||||||||
535 | r = RSA_padding_check_PKCS1_type_2(to, num, buf, j, num); | - | ||||||||||||||||||
536 | break; executed 18 times by 3 tests: break; Executed by:
| 18 | ||||||||||||||||||
537 | - | |||||||||||||||||||
538 | case executed 490 times by 1 test: 4:case 4: Executed by:
executed 490 times by 1 test: case 4: Executed by:
| 490 | ||||||||||||||||||
539 | r = RSA_padding_check_PKCS1_OAEP(to, num, buf, j, num, | - | ||||||||||||||||||
540 | ((void *)0) | - | ||||||||||||||||||
541 | , 0); | - | ||||||||||||||||||
542 | break; executed 490 times by 1 test: break; Executed by:
| 490 | ||||||||||||||||||
543 | - | |||||||||||||||||||
544 | case never executed: 3:case 3: never executed: case 3: | 0 | ||||||||||||||||||
545 | r = RSA_padding_check_none(to, num, buf, j, num); | - | ||||||||||||||||||
546 | break; never executed: break; | 0 | ||||||||||||||||||
547 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||
548 | ERR_put_error(4,(0xfff),(118),__FILE__,576); | - | ||||||||||||||||||
549 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
550 | } | - | ||||||||||||||||||
551 | if (r < 0
| 24-484 | ||||||||||||||||||
552 | ERR_put_error(4,(0xfff),(114),__FILE__,580); executed 484 times by 1 test: ERR_put_error(4,(0xfff),(114),__FILE__,580); Executed by:
| 484 | ||||||||||||||||||
553 | - | |||||||||||||||||||
554 | err: code before this statement executed 508 times by 3 tests: err: Executed by:
| 508 | ||||||||||||||||||
555 | if (ctx !=
| 0-511 | ||||||||||||||||||
556 | ((void *)0)
| 0-511 | ||||||||||||||||||
557 | ) { | - | ||||||||||||||||||
558 | BN_CTX_end(ctx); | - | ||||||||||||||||||
559 | BN_CTX_free(ctx); | - | ||||||||||||||||||
560 | } executed 511 times by 3 tests: end of block Executed by:
| 511 | ||||||||||||||||||
561 | freezero(buf, num); | - | ||||||||||||||||||
562 | return executed 511 times by 3 tests: r;return r; Executed by:
executed 511 times by 3 tests: return r; Executed by:
| 511 | ||||||||||||||||||
563 | } | - | ||||||||||||||||||
564 | - | |||||||||||||||||||
565 | - | |||||||||||||||||||
566 | static int | - | ||||||||||||||||||
567 | RSA_eay_public_decrypt(int flen, const unsigned char *from, unsigned char *to, | - | ||||||||||||||||||
568 | RSA *rsa, int padding) | - | ||||||||||||||||||
569 | { | - | ||||||||||||||||||
570 | BIGNUM *f, *ret; | - | ||||||||||||||||||
571 | int i, num = 0, r = -1; | - | ||||||||||||||||||
572 | unsigned char *p; | - | ||||||||||||||||||
573 | unsigned char *buf = | - | ||||||||||||||||||
574 | ((void *)0) | - | ||||||||||||||||||
575 | ; | - | ||||||||||||||||||
576 | BN_CTX *ctx = | - | ||||||||||||||||||
577 | ((void *)0) | - | ||||||||||||||||||
578 | ; | - | ||||||||||||||||||
579 | - | |||||||||||||||||||
580 | if (BN_num_bits(rsa->n) > 16384
| 0-120 | ||||||||||||||||||
581 | ERR_put_error(4,(0xfff),(105),__FILE__,603); | - | ||||||||||||||||||
582 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||
583 | } | - | ||||||||||||||||||
584 | - | |||||||||||||||||||
585 | if (BN_ucmp(rsa->n, rsa->e) <= 0
| 0-120 | ||||||||||||||||||
586 | ERR_put_error(4,(0xfff),(101),__FILE__,608); | - | ||||||||||||||||||
587 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||
588 | } | - | ||||||||||||||||||
589 | - | |||||||||||||||||||
590 | - | |||||||||||||||||||
591 | if (BN_num_bits(rsa->n) > 3072
| 0-120 | ||||||||||||||||||
592 | if (BN_num_bits(rsa->e) > 64
| 0 | ||||||||||||||||||
593 | ERR_put_error(4,(0xfff),(101),__FILE__,615); | - | ||||||||||||||||||
594 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||
595 | } | - | ||||||||||||||||||
596 | } never executed: end of block | 0 | ||||||||||||||||||
597 | - | |||||||||||||||||||
598 | if ((
| 0-120 | ||||||||||||||||||
599 | ((void *)0)
| 0-120 | ||||||||||||||||||
600 | ) | - | ||||||||||||||||||
601 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
602 | - | |||||||||||||||||||
603 | BN_CTX_start(ctx); | - | ||||||||||||||||||
604 | f = BN_CTX_get(ctx); | - | ||||||||||||||||||
605 | ret = BN_CTX_get(ctx); | - | ||||||||||||||||||
606 | num = ((BN_num_bits(rsa->n)+7)/8); | - | ||||||||||||||||||
607 | buf = malloc(num); | - | ||||||||||||||||||
608 | - | |||||||||||||||||||
609 | if (!f
| 0-120 | ||||||||||||||||||
610 | ERR_put_error(4,(0xfff),((1|64)),__FILE__,630); | - | ||||||||||||||||||
611 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
612 | } | - | ||||||||||||||||||
613 | - | |||||||||||||||||||
614 | - | |||||||||||||||||||
615 | - | |||||||||||||||||||
616 | if (flen > num
| 0-120 | ||||||||||||||||||
617 | ERR_put_error(4,(0xfff),(108),__FILE__,637); | - | ||||||||||||||||||
618 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
619 | } | - | ||||||||||||||||||
620 | - | |||||||||||||||||||
621 | if (BN_bin2bn(from, flen, f) ==
| 0-120 | ||||||||||||||||||
622 | ((void *)0)
| 0-120 | ||||||||||||||||||
623 | ) | - | ||||||||||||||||||
624 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
625 | - | |||||||||||||||||||
626 | if (BN_ucmp(f, rsa->n) >= 0
| 0-120 | ||||||||||||||||||
627 | ERR_put_error(4,(0xfff),(132),__FILE__,645); | - | ||||||||||||||||||
628 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
629 | } | - | ||||||||||||||||||
630 | - | |||||||||||||||||||
631 | if (rsa->flags & 0x0002
| 0-120 | ||||||||||||||||||
632 | if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n,
| 0-120 | ||||||||||||||||||
633 | 9, rsa->n, ctx)
| 0-120 | ||||||||||||||||||
634 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
635 | - | |||||||||||||||||||
636 | if (!rsa->meth->bn_mod_exp(ret, f, rsa->e, rsa->n, ctx,
| 0-120 | ||||||||||||||||||
637 | rsa->_method_mod_n)
| 0-120 | ||||||||||||||||||
638 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
639 | - | |||||||||||||||||||
640 | if (padding == 5
| 0-120 | ||||||||||||||||||
641 | if (!BN_sub(ret, rsa->n, ret)
| 0 | ||||||||||||||||||
642 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
643 | - | |||||||||||||||||||
644 | p = buf; | - | ||||||||||||||||||
645 | i = BN_bn2bin(ret, p); | - | ||||||||||||||||||
646 | - | |||||||||||||||||||
647 | switch (padding) { | - | ||||||||||||||||||
648 | case executed 120 times by 3 tests: 1:case 1: Executed by:
executed 120 times by 3 tests: case 1: Executed by:
| 120 | ||||||||||||||||||
649 | r = RSA_padding_check_PKCS1_type_1(to, num, buf, i, num); | - | ||||||||||||||||||
650 | break; executed 120 times by 3 tests: break; Executed by:
| 120 | ||||||||||||||||||
651 | case never executed: 5:case 5: never executed: case 5: | 0 | ||||||||||||||||||
652 | r = RSA_padding_check_X931(to, num, buf, i, num); | - | ||||||||||||||||||
653 | break; never executed: break; | 0 | ||||||||||||||||||
654 | case never executed: 3:case 3: never executed: case 3: | 0 | ||||||||||||||||||
655 | r = RSA_padding_check_none(to, num, buf, i, num); | - | ||||||||||||||||||
656 | break; never executed: break; | 0 | ||||||||||||||||||
657 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||
658 | ERR_put_error(4,(0xfff),(118),__FILE__,676); | - | ||||||||||||||||||
659 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
660 | } | - | ||||||||||||||||||
661 | if (r < 0
| 0-120 | ||||||||||||||||||
662 | ERR_put_error(4,(0xfff),(114),__FILE__,680); never executed: ERR_put_error(4,(0xfff),(114),__FILE__,680); | 0 | ||||||||||||||||||
663 | - | |||||||||||||||||||
664 | err: code before this statement executed 120 times by 3 tests: err: Executed by:
| 120 | ||||||||||||||||||
665 | if (ctx !=
| 0-120 | ||||||||||||||||||
666 | ((void *)0)
| 0-120 | ||||||||||||||||||
667 | ) { | - | ||||||||||||||||||
668 | BN_CTX_end(ctx); | - | ||||||||||||||||||
669 | BN_CTX_free(ctx); | - | ||||||||||||||||||
670 | } executed 120 times by 3 tests: end of block Executed by:
| 120 | ||||||||||||||||||
671 | freezero(buf, num); | - | ||||||||||||||||||
672 | return executed 120 times by 3 tests: r;return r; Executed by:
executed 120 times by 3 tests: return r; Executed by:
| 120 | ||||||||||||||||||
673 | } | - | ||||||||||||||||||
674 | - | |||||||||||||||||||
675 | static int | - | ||||||||||||||||||
676 | RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) | - | ||||||||||||||||||
677 | { | - | ||||||||||||||||||
678 | BIGNUM *r1, *m1, *vrfy; | - | ||||||||||||||||||
679 | BIGNUM dmp1, dmq1, c, pr1; | - | ||||||||||||||||||
680 | int ret = 0; | - | ||||||||||||||||||
681 | - | |||||||||||||||||||
682 | BN_CTX_start(ctx); | - | ||||||||||||||||||
683 | r1 = BN_CTX_get(ctx); | - | ||||||||||||||||||
684 | m1 = BN_CTX_get(ctx); | - | ||||||||||||||||||
685 | vrfy = BN_CTX_get(ctx); | - | ||||||||||||||||||
686 | if (r1 ==
| 0-559 | ||||||||||||||||||
687 | ((void *)0)
| 0-559 | ||||||||||||||||||
688 | || m1 ==
| 0-559 | ||||||||||||||||||
689 | ((void *)0)
| 0-559 | ||||||||||||||||||
690 | || vrfy ==
| 0-559 | ||||||||||||||||||
691 | ((void *)0)
| 0-559 | ||||||||||||||||||
692 | ) { | - | ||||||||||||||||||
693 | ERR_put_error(4,(0xfff),((1|64)),__FILE__,703); | - | ||||||||||||||||||
694 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
695 | } | - | ||||||||||||||||||
696 | - | |||||||||||||||||||
697 | { | - | ||||||||||||||||||
698 | BIGNUM p, q; | - | ||||||||||||||||||
699 | - | |||||||||||||||||||
700 | - | |||||||||||||||||||
701 | - | |||||||||||||||||||
702 | - | |||||||||||||||||||
703 | - | |||||||||||||||||||
704 | BN_init(&p); | - | ||||||||||||||||||
705 | BN_init(&q); | - | ||||||||||||||||||
706 | ((&p)->d=(rsa->p)->d, (&p)->top=(rsa->p)->top, (&p)->dmax=(rsa->p)->dmax, (&p)->neg=(rsa->p)->neg, (&p)->flags=(((&p)->flags & 0x01) | ((rsa->p)->flags & ~0x01) | 0x02 | (0x04))); | - | ||||||||||||||||||
707 | ((&q)->d=(rsa->q)->d, (&q)->top=(rsa->q)->top, (&q)->dmax=(rsa->q)->dmax, (&q)->neg=(rsa->q)->neg, (&q)->flags=(((&q)->flags & 0x01) | ((rsa->q)->flags & ~0x01) | 0x02 | (0x04))); | - | ||||||||||||||||||
708 | - | |||||||||||||||||||
709 | if (rsa->flags & 0x0004
| 0-559 | ||||||||||||||||||
710 | if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_p,
| 0-559 | ||||||||||||||||||
711 | 9, &p, ctx)
| 0-559 | ||||||||||||||||||
712 | !BN_MONT_CTX_set_locked(&rsa->_method_mod_q,
| 0-559 | ||||||||||||||||||
713 | 9, &q, ctx)
| 0-559 | ||||||||||||||||||
714 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
715 | } | - | ||||||||||||||||||
716 | } executed 559 times by 6 tests: end of block Executed by:
| 559 | ||||||||||||||||||
717 | } | - | ||||||||||||||||||
718 | - | |||||||||||||||||||
719 | if (rsa->flags & 0x0002
| 0-559 | ||||||||||||||||||
720 | if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n,
| 0-559 | ||||||||||||||||||
721 | 9, rsa->n, ctx)
| 0-559 | ||||||||||||||||||
722 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
723 | - | |||||||||||||||||||
724 | - | |||||||||||||||||||
725 | BN_init(&c); | - | ||||||||||||||||||
726 | ((&c)->d=(I)->d, (&c)->top=(I)->top, (&c)->dmax=(I)->dmax, (&c)->neg=(I)->neg, (&c)->flags=(((&c)->flags & 0x01) | ((I)->flags & ~0x01) | 0x02 | (0x04))); | - | ||||||||||||||||||
727 | - | |||||||||||||||||||
728 | if (!BN_div_ct(
| 0-559 | ||||||||||||||||||
729 | ((void *)0)
| 0-559 | ||||||||||||||||||
730 | ,(r1),(&c),(rsa->q),(ctx))
| 0-559 | ||||||||||||||||||
731 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
732 | - | |||||||||||||||||||
733 | - | |||||||||||||||||||
734 | BN_init(&dmq1); | - | ||||||||||||||||||
735 | ((&dmq1)->d=(rsa->dmq1)->d, (&dmq1)->top=(rsa->dmq1)->top, (&dmq1)->dmax=(rsa->dmq1)->dmax, (&dmq1)->neg=(rsa->dmq1)->neg, (&dmq1)->flags=(((&dmq1)->flags & 0x01) | ((rsa->dmq1)->flags & ~0x01) | 0x02 | (0x04))); | - | ||||||||||||||||||
736 | - | |||||||||||||||||||
737 | if (!rsa->meth->bn_mod_exp(m1, r1, &dmq1, rsa->q, ctx,
| 0-559 | ||||||||||||||||||
738 | rsa->_method_mod_q)
| 0-559 | ||||||||||||||||||
739 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
740 | - | |||||||||||||||||||
741 | - | |||||||||||||||||||
742 | ((&c)->d=(I)->d, (&c)->top=(I)->top, (&c)->dmax=(I)->dmax, (&c)->neg=(I)->neg, (&c)->flags=(((&c)->flags & 0x01) | ((I)->flags & ~0x01) | 0x02 | (0x04))); | - | ||||||||||||||||||
743 | - | |||||||||||||||||||
744 | if (!BN_div_ct(
| 0-559 | ||||||||||||||||||
745 | ((void *)0)
| 0-559 | ||||||||||||||||||
746 | ,(r1),(&c),(rsa->p),(ctx))
| 0-559 | ||||||||||||||||||
747 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
748 | - | |||||||||||||||||||
749 | - | |||||||||||||||||||
750 | BN_init(&dmp1); | - | ||||||||||||||||||
751 | ((&dmp1)->d=(rsa->dmp1)->d, (&dmp1)->top=(rsa->dmp1)->top, (&dmp1)->dmax=(rsa->dmp1)->dmax, (&dmp1)->neg=(rsa->dmp1)->neg, (&dmp1)->flags=(((&dmp1)->flags & 0x01) | ((rsa->dmp1)->flags & ~0x01) | 0x02 | (0x04))); | - | ||||||||||||||||||
752 | - | |||||||||||||||||||
753 | if (!rsa->meth->bn_mod_exp(r0, r1, &dmp1, rsa->p, ctx,
| 0-559 | ||||||||||||||||||
754 | rsa->_method_mod_p)
| 0-559 | ||||||||||||||||||
755 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
756 | - | |||||||||||||||||||
757 | if (!BN_sub(r0, r0, m1)
| 0-559 | ||||||||||||||||||
758 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
759 | - | |||||||||||||||||||
760 | - | |||||||||||||||||||
761 | - | |||||||||||||||||||
762 | - | |||||||||||||||||||
763 | - | |||||||||||||||||||
764 | if (((
| 253-306 | ||||||||||||||||||
765 | if (!BN_add(r0, r0, rsa->p)
| 0-253 | ||||||||||||||||||
766 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
767 | - | |||||||||||||||||||
768 | if (!BN_mul(r1, r0, rsa->iqmp, ctx)
| 0-559 | ||||||||||||||||||
769 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
770 | - | |||||||||||||||||||
771 | - | |||||||||||||||||||
772 | BN_init(&pr1); | - | ||||||||||||||||||
773 | ((&pr1)->d=(r1)->d, (&pr1)->top=(r1)->top, (&pr1)->dmax=(r1)->dmax, (&pr1)->neg=(r1)->neg, (&pr1)->flags=(((&pr1)->flags & 0x01) | ((r1)->flags & ~0x01) | 0x02 | (0x04))); | - | ||||||||||||||||||
774 | - | |||||||||||||||||||
775 | if (!BN_div_ct(
| 0-559 | ||||||||||||||||||
776 | ((void *)0)
| 0-559 | ||||||||||||||||||
777 | ,(r0),(&pr1),(rsa->p),(ctx))
| 0-559 | ||||||||||||||||||
778 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
779 | if (((
| 0-559 | ||||||||||||||||||
780 | if (!BN_add(r0, r0, rsa->p)
| 0 | ||||||||||||||||||
781 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
782 | if (!BN_mul(r1, r0, rsa->q, ctx)
| 0-559 | ||||||||||||||||||
783 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
784 | if (!BN_add(r0, r1, m1)
| 0-559 | ||||||||||||||||||
785 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
786 | - | |||||||||||||||||||
787 | if (rsa->e
| 0-559 | ||||||||||||||||||
788 | if (!rsa->meth->bn_mod_exp(vrfy, r0, rsa->e, rsa->n, ctx,
| 0-559 | ||||||||||||||||||
789 | rsa->_method_mod_n)
| 0-559 | ||||||||||||||||||
790 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
791 | - | |||||||||||||||||||
792 | - | |||||||||||||||||||
793 | - | |||||||||||||||||||
794 | - | |||||||||||||||||||
795 | - | |||||||||||||||||||
796 | - | |||||||||||||||||||
797 | if (!BN_sub(vrfy, vrfy, I)
| 0-559 | ||||||||||||||||||
798 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
799 | if (!BN_div_ct(
| 0-559 | ||||||||||||||||||
800 | ((void *)0)
| 0-559 | ||||||||||||||||||
801 | ,(vrfy),(vrfy),(rsa->n),(ctx))
| 0-559 | ||||||||||||||||||
802 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
803 | if (((
| 0-559 | ||||||||||||||||||
804 | if (!BN_add(vrfy, vrfy, rsa->n)
| 0 | ||||||||||||||||||
805 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
806 | if (!((vrfy)->top == 0)
| 0-559 | ||||||||||||||||||
807 | - | |||||||||||||||||||
808 | - | |||||||||||||||||||
809 | - | |||||||||||||||||||
810 | - | |||||||||||||||||||
811 | - | |||||||||||||||||||
812 | BIGNUM d; | - | ||||||||||||||||||
813 | - | |||||||||||||||||||
814 | BN_init(&d); | - | ||||||||||||||||||
815 | ((&d)->d=(rsa->d)->d, (&d)->top=(rsa->d)->top, (&d)->dmax=(rsa->d)->dmax, (&d)->neg=(rsa->d)->neg, (&d)->flags=(((&d)->flags & 0x01) | ((rsa->d)->flags & ~0x01) | 0x02 | (0x04))); | - | ||||||||||||||||||
816 | - | |||||||||||||||||||
817 | if (!rsa->meth->bn_mod_exp(r0, I, &d, rsa->n, ctx,
| 0 | ||||||||||||||||||
818 | rsa->_method_mod_n)
| 0 | ||||||||||||||||||
819 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
820 | } | - | ||||||||||||||||||
821 | } never executed: end of block | 0 | ||||||||||||||||||
822 | } executed 559 times by 6 tests: end of block Executed by:
| 559 | ||||||||||||||||||
823 | ret = 1; | - | ||||||||||||||||||
824 | err: code before this statement executed 559 times by 6 tests: err: Executed by:
| 559 | ||||||||||||||||||
825 | BN_CTX_end(ctx); | - | ||||||||||||||||||
826 | return executed 559 times by 6 tests: ret;return ret; Executed by:
executed 559 times by 6 tests: return ret; Executed by:
| 559 | ||||||||||||||||||
827 | } | - | ||||||||||||||||||
828 | - | |||||||||||||||||||
829 | static int | - | ||||||||||||||||||
830 | RSA_eay_init(RSA *rsa) | - | ||||||||||||||||||
831 | { | - | ||||||||||||||||||
832 | rsa->flags |= 0x0002 | 0x0004; | - | ||||||||||||||||||
833 | return executed 256 times by 6 tests: 1;return 1; Executed by:
executed 256 times by 6 tests: return 1; Executed by:
| 256 | ||||||||||||||||||
834 | } | - | ||||||||||||||||||
835 | - | |||||||||||||||||||
836 | static int | - | ||||||||||||||||||
837 | RSA_eay_finish(RSA *rsa) | - | ||||||||||||||||||
838 | { | - | ||||||||||||||||||
839 | BN_MONT_CTX_free(rsa->_method_mod_n); | - | ||||||||||||||||||
840 | BN_MONT_CTX_free(rsa->_method_mod_p); | - | ||||||||||||||||||
841 | BN_MONT_CTX_free(rsa->_method_mod_q); | - | ||||||||||||||||||
842 | - | |||||||||||||||||||
843 | return executed 254 times by 5 tests: 1;return 1; Executed by:
executed 254 times by 5 tests: return 1; Executed by:
| 254 | ||||||||||||||||||
844 | } | - | ||||||||||||||||||
Switch to Source code | Preprocessed file |