Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/rsa/rsa_ossl.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||||||||
2 | static int rsa_ossl_public_encrypt(int flen, const unsigned char *from, | - | ||||||||||||||||||||||||
3 | unsigned char *to, RSA *rsa, int padding); | - | ||||||||||||||||||||||||
4 | static int rsa_ossl_private_encrypt(int flen, const unsigned char *from, | - | ||||||||||||||||||||||||
5 | unsigned char *to, RSA *rsa, int padding); | - | ||||||||||||||||||||||||
6 | static int rsa_ossl_public_decrypt(int flen, const unsigned char *from, | - | ||||||||||||||||||||||||
7 | unsigned char *to, RSA *rsa, int padding); | - | ||||||||||||||||||||||||
8 | static int rsa_ossl_private_decrypt(int flen, const unsigned char *from, | - | ||||||||||||||||||||||||
9 | unsigned char *to, RSA *rsa, int padding); | - | ||||||||||||||||||||||||
10 | static int rsa_ossl_mod_exp(BIGNUM *r0, const BIGNUM *i, RSA *rsa, | - | ||||||||||||||||||||||||
11 | BN_CTX *ctx); | - | ||||||||||||||||||||||||
12 | static int rsa_ossl_init(RSA *rsa); | - | ||||||||||||||||||||||||
13 | static int rsa_ossl_finish(RSA *rsa); | - | ||||||||||||||||||||||||
14 | static RSA_METHOD rsa_pkcs1_ossl_meth = { | - | ||||||||||||||||||||||||
15 | "OpenSSL PKCS#1 RSA", | - | ||||||||||||||||||||||||
16 | rsa_ossl_public_encrypt, | - | ||||||||||||||||||||||||
17 | rsa_ossl_public_decrypt, | - | ||||||||||||||||||||||||
18 | rsa_ossl_private_encrypt, | - | ||||||||||||||||||||||||
19 | rsa_ossl_private_decrypt, | - | ||||||||||||||||||||||||
20 | rsa_ossl_mod_exp, | - | ||||||||||||||||||||||||
21 | BN_mod_exp_mont, | - | ||||||||||||||||||||||||
22 | - | |||||||||||||||||||||||||
23 | rsa_ossl_init, | - | ||||||||||||||||||||||||
24 | rsa_ossl_finish, | - | ||||||||||||||||||||||||
25 | 0x0400, | - | ||||||||||||||||||||||||
26 | - | |||||||||||||||||||||||||
27 | ((void *)0) | - | ||||||||||||||||||||||||
28 | , | - | ||||||||||||||||||||||||
29 | 0, | - | ||||||||||||||||||||||||
30 | 0, | - | ||||||||||||||||||||||||
31 | - | |||||||||||||||||||||||||
32 | ((void *)0) | - | ||||||||||||||||||||||||
33 | , | - | ||||||||||||||||||||||||
34 | - | |||||||||||||||||||||||||
35 | ((void *)0) | - | ||||||||||||||||||||||||
36 | - | |||||||||||||||||||||||||
37 | }; | - | ||||||||||||||||||||||||
38 | - | |||||||||||||||||||||||||
39 | static const RSA_METHOD *default_RSA_meth = &rsa_pkcs1_ossl_meth; | - | ||||||||||||||||||||||||
40 | - | |||||||||||||||||||||||||
41 | void RSA_set_default_method(const RSA_METHOD *meth) | - | ||||||||||||||||||||||||
42 | { | - | ||||||||||||||||||||||||
43 | default_RSA_meth = meth; | - | ||||||||||||||||||||||||
44 | } never executed: end of block | 0 | ||||||||||||||||||||||||
45 | - | |||||||||||||||||||||||||
46 | const RSA_METHOD *RSA_get_default_method(void) | - | ||||||||||||||||||||||||
47 | { | - | ||||||||||||||||||||||||
48 | return executed 25970 times by 1 test: default_RSA_meth;return default_RSA_meth; Executed by:
executed 25970 times by 1 test: return default_RSA_meth; Executed by:
| 25970 | ||||||||||||||||||||||||
49 | } | - | ||||||||||||||||||||||||
50 | - | |||||||||||||||||||||||||
51 | const RSA_METHOD *RSA_PKCS1_OpenSSL(void) | - | ||||||||||||||||||||||||
52 | { | - | ||||||||||||||||||||||||
53 | return never executed: &rsa_pkcs1_ossl_meth;return &rsa_pkcs1_ossl_meth; never executed: return &rsa_pkcs1_ossl_meth; | 0 | ||||||||||||||||||||||||
54 | } | - | ||||||||||||||||||||||||
55 | - | |||||||||||||||||||||||||
56 | const RSA_METHOD *RSA_null_method(void) | - | ||||||||||||||||||||||||
57 | { | - | ||||||||||||||||||||||||
58 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
59 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
60 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
61 | } | - | ||||||||||||||||||||||||
62 | - | |||||||||||||||||||||||||
63 | static int rsa_ossl_public_encrypt(int flen, const unsigned char *from, | - | ||||||||||||||||||||||||
64 | unsigned char *to, RSA *rsa, int padding) | - | ||||||||||||||||||||||||
65 | { | - | ||||||||||||||||||||||||
66 | BIGNUM *f, *ret; | - | ||||||||||||||||||||||||
67 | int i, num = 0, r = -1; | - | ||||||||||||||||||||||||
68 | unsigned char *buf = | - | ||||||||||||||||||||||||
69 | ((void *)0) | - | ||||||||||||||||||||||||
70 | ; | - | ||||||||||||||||||||||||
71 | BN_CTX *ctx = | - | ||||||||||||||||||||||||
72 | ((void *)0) | - | ||||||||||||||||||||||||
73 | ; | - | ||||||||||||||||||||||||
74 | - | |||||||||||||||||||||||||
75 | if (BN_num_bits(rsa->n) > 16384
| 0-499 | ||||||||||||||||||||||||
76 | ERR_put_error(4,(104),(105),__FILE__,76); | - | ||||||||||||||||||||||||
77 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
78 | } | - | ||||||||||||||||||||||||
79 | - | |||||||||||||||||||||||||
80 | if (BN_ucmp(rsa->n, rsa->e) <= 0
| 1-498 | ||||||||||||||||||||||||
81 | ERR_put_error(4,(104),(101),__FILE__,81); | - | ||||||||||||||||||||||||
82 | return executed 1 time by 1 test: -1;return -1; Executed by:
executed 1 time by 1 test: return -1; Executed by:
| 1 | ||||||||||||||||||||||||
83 | } | - | ||||||||||||||||||||||||
84 | - | |||||||||||||||||||||||||
85 | - | |||||||||||||||||||||||||
86 | if (BN_num_bits(rsa->n) > 3072
| 4-494 | ||||||||||||||||||||||||
87 | if (BN_num_bits(rsa->e) > 64
| 0-4 | ||||||||||||||||||||||||
88 | ERR_put_error(4,(104),(101),__FILE__,88); | - | ||||||||||||||||||||||||
89 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
90 | } | - | ||||||||||||||||||||||||
91 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
92 | - | |||||||||||||||||||||||||
93 | if ((
| 0-498 | ||||||||||||||||||||||||
94 | ((void *)0)
| 0-498 | ||||||||||||||||||||||||
95 | ) | - | ||||||||||||||||||||||||
96 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
97 | BN_CTX_start(ctx); | - | ||||||||||||||||||||||||
98 | f = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||
99 | ret = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||
100 | num = ((BN_num_bits(rsa->n)+7)/8); | - | ||||||||||||||||||||||||
101 | buf = CRYPTO_malloc(num, __FILE__, 99); | - | ||||||||||||||||||||||||
102 | if (ret ==
| 0-498 | ||||||||||||||||||||||||
103 | ((void *)0)
| 0-498 | ||||||||||||||||||||||||
104 | || buf ==
| 0-498 | ||||||||||||||||||||||||
105 | ((void *)0)
| 0-498 | ||||||||||||||||||||||||
106 | ) { | - | ||||||||||||||||||||||||
107 | ERR_put_error(4,(104),((1|64)),__FILE__,101); | - | ||||||||||||||||||||||||
108 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
109 | } | - | ||||||||||||||||||||||||
110 | - | |||||||||||||||||||||||||
111 | switch (padding) { | - | ||||||||||||||||||||||||
112 | case executed 493 times by 1 test: 1:case 1: Executed by:
executed 493 times by 1 test: case 1: Executed by:
| 493 | ||||||||||||||||||||||||
113 | i = RSA_padding_add_PKCS1_type_2(buf, num, from, flen); | - | ||||||||||||||||||||||||
114 | break; executed 493 times by 1 test: break; Executed by:
| 493 | ||||||||||||||||||||||||
115 | case executed 3 times by 1 test: 4:case 4: Executed by:
executed 3 times by 1 test: case 4: Executed by:
| 3 | ||||||||||||||||||||||||
116 | i = RSA_padding_add_PKCS1_OAEP(buf, num, from, flen, | - | ||||||||||||||||||||||||
117 | ((void *)0) | - | ||||||||||||||||||||||||
118 | , 0); | - | ||||||||||||||||||||||||
119 | break; executed 3 times by 1 test: break; Executed by:
| 3 | ||||||||||||||||||||||||
120 | case never executed: 2:case 2: never executed: case 2: | 0 | ||||||||||||||||||||||||
121 | i = RSA_padding_add_SSLv23(buf, num, from, flen); | - | ||||||||||||||||||||||||
122 | break; never executed: break; | 0 | ||||||||||||||||||||||||
123 | case executed 2 times by 1 test: 3:case 3: Executed by:
executed 2 times by 1 test: case 3: Executed by:
| 2 | ||||||||||||||||||||||||
124 | i = RSA_padding_add_none(buf, num, from, flen); | - | ||||||||||||||||||||||||
125 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||||||||||||||
126 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||||||||
127 | ERR_put_error(4,(104),(118),__FILE__,119); | - | ||||||||||||||||||||||||
128 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
129 | } | - | ||||||||||||||||||||||||
130 | if (i <= 0
| 1-497 | ||||||||||||||||||||||||
131 | goto executed 1 time by 1 test: err;goto err; Executed by:
executed 1 time by 1 test: goto err; Executed by:
| 1 | ||||||||||||||||||||||||
132 | - | |||||||||||||||||||||||||
133 | if (BN_bin2bn(buf, num, f) ==
| 0-497 | ||||||||||||||||||||||||
134 | ((void *)0)
| 0-497 | ||||||||||||||||||||||||
135 | ) | - | ||||||||||||||||||||||||
136 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
137 | - | |||||||||||||||||||||||||
138 | if (BN_ucmp(f, rsa->n) >= 0
| 0-497 | ||||||||||||||||||||||||
139 | - | |||||||||||||||||||||||||
140 | ERR_put_error(4,(104),(132),__FILE__,131) | - | ||||||||||||||||||||||||
141 | ; | - | ||||||||||||||||||||||||
142 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
143 | } | - | ||||||||||||||||||||||||
144 | - | |||||||||||||||||||||||||
145 | if (rsa->flags & 0x0002
| 0-497 | ||||||||||||||||||||||||
146 | if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, rsa->lock,
| 15-482 | ||||||||||||||||||||||||
147 | rsa->n, ctx)
| 15-482 | ||||||||||||||||||||||||
148 | goto executed 15 times by 1 test: err;goto err; Executed by:
executed 15 times by 1 test: goto err; Executed by:
| 15 | ||||||||||||||||||||||||
149 | - | |||||||||||||||||||||||||
150 | if (!rsa->meth->bn_mod_exp(ret, f, rsa->e, rsa->n, ctx,
| 0-482 | ||||||||||||||||||||||||
151 | rsa->_method_mod_n)
| 0-482 | ||||||||||||||||||||||||
152 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
153 | - | |||||||||||||||||||||||||
154 | - | |||||||||||||||||||||||||
155 | - | |||||||||||||||||||||||||
156 | - | |||||||||||||||||||||||||
157 | - | |||||||||||||||||||||||||
158 | r = BN_bn2binpad(ret, to, num); | - | ||||||||||||||||||||||||
159 | err: code before this statement executed 482 times by 1 test: err: Executed by:
| 482 | ||||||||||||||||||||||||
160 | if (ctx !=
| 0-498 | ||||||||||||||||||||||||
161 | ((void *)0)
| 0-498 | ||||||||||||||||||||||||
162 | ) | - | ||||||||||||||||||||||||
163 | BN_CTX_end(ctx); executed 498 times by 1 test: BN_CTX_end(ctx); Executed by:
| 498 | ||||||||||||||||||||||||
164 | BN_CTX_free(ctx); | - | ||||||||||||||||||||||||
165 | CRYPTO_clear_free(buf, num, __FILE__, 153); | - | ||||||||||||||||||||||||
166 | return executed 498 times by 1 test: r;return r; Executed by:
executed 498 times by 1 test: return r; Executed by:
| 498 | ||||||||||||||||||||||||
167 | } | - | ||||||||||||||||||||||||
168 | - | |||||||||||||||||||||||||
169 | static BN_BLINDING *rsa_get_blinding(RSA *rsa, int *local, BN_CTX *ctx) | - | ||||||||||||||||||||||||
170 | { | - | ||||||||||||||||||||||||
171 | BN_BLINDING *ret; | - | ||||||||||||||||||||||||
172 | - | |||||||||||||||||||||||||
173 | CRYPTO_THREAD_write_lock(rsa->lock); | - | ||||||||||||||||||||||||
174 | - | |||||||||||||||||||||||||
175 | if (rsa->blinding ==
| 648-1733 | ||||||||||||||||||||||||
176 | ((void *)0)
| 648-1733 | ||||||||||||||||||||||||
177 | ) { | - | ||||||||||||||||||||||||
178 | rsa->blinding = RSA_setup_blinding(rsa, ctx); | - | ||||||||||||||||||||||||
179 | } executed 1733 times by 1 test: end of block Executed by:
| 1733 | ||||||||||||||||||||||||
180 | - | |||||||||||||||||||||||||
181 | ret = rsa->blinding; | - | ||||||||||||||||||||||||
182 | if (ret ==
| 0-2381 | ||||||||||||||||||||||||
183 | ((void *)0)
| 0-2381 | ||||||||||||||||||||||||
184 | ) | - | ||||||||||||||||||||||||
185 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
186 | - | |||||||||||||||||||||||||
187 | if (BN_BLINDING_is_current_thread(ret)
| 0-2381 | ||||||||||||||||||||||||
188 | - | |||||||||||||||||||||||||
189 | - | |||||||||||||||||||||||||
190 | *local = 1; | - | ||||||||||||||||||||||||
191 | } executed 2381 times by 1 test: else {end of block Executed by:
| 2381 | ||||||||||||||||||||||||
192 | - | |||||||||||||||||||||||||
193 | - | |||||||||||||||||||||||||
194 | - | |||||||||||||||||||||||||
195 | - | |||||||||||||||||||||||||
196 | - | |||||||||||||||||||||||||
197 | - | |||||||||||||||||||||||||
198 | - | |||||||||||||||||||||||||
199 | *local = 0; | - | ||||||||||||||||||||||||
200 | - | |||||||||||||||||||||||||
201 | if (rsa->mt_blinding ==
| 0 | ||||||||||||||||||||||||
202 | ((void *)0)
| 0 | ||||||||||||||||||||||||
203 | ) { | - | ||||||||||||||||||||||||
204 | rsa->mt_blinding = RSA_setup_blinding(rsa, ctx); | - | ||||||||||||||||||||||||
205 | } never executed: end of block | 0 | ||||||||||||||||||||||||
206 | ret = rsa->mt_blinding; | - | ||||||||||||||||||||||||
207 | } never executed: end of block | 0 | ||||||||||||||||||||||||
208 | - | |||||||||||||||||||||||||
209 | err: code before this statement executed 2381 times by 1 test: err: Executed by:
| 2381 | ||||||||||||||||||||||||
210 | CRYPTO_THREAD_unlock(rsa->lock); | - | ||||||||||||||||||||||||
211 | return executed 2381 times by 1 test: ret;return ret; Executed by:
executed 2381 times by 1 test: return ret; Executed by:
| 2381 | ||||||||||||||||||||||||
212 | } | - | ||||||||||||||||||||||||
213 | - | |||||||||||||||||||||||||
214 | static int rsa_blinding_convert(BN_BLINDING *b, BIGNUM *f, BIGNUM *unblind, | - | ||||||||||||||||||||||||
215 | BN_CTX *ctx) | - | ||||||||||||||||||||||||
216 | { | - | ||||||||||||||||||||||||
217 | if (unblind ==
| 0-2381 | ||||||||||||||||||||||||
218 | ((void *)0)
| 0-2381 | ||||||||||||||||||||||||
219 | ) { | - | ||||||||||||||||||||||||
220 | - | |||||||||||||||||||||||||
221 | - | |||||||||||||||||||||||||
222 | - | |||||||||||||||||||||||||
223 | return executed 2381 times by 1 test: BN_BLINDING_convert_ex(f, return BN_BLINDING_convert_ex(f, ((void *)0) , b, ctx); Executed by:
executed 2381 times by 1 test: return BN_BLINDING_convert_ex(f, ((void *)0) , b, ctx); Executed by:
| 2381 | ||||||||||||||||||||||||
224 | ((void *)0) executed 2381 times by 1 test: return BN_BLINDING_convert_ex(f, ((void *)0) , b, ctx); Executed by:
| 2381 | ||||||||||||||||||||||||
225 | , b, ctx); executed 2381 times by 1 test: return BN_BLINDING_convert_ex(f, ((void *)0) , b, ctx); Executed by:
| 2381 | ||||||||||||||||||||||||
226 | } else { | - | ||||||||||||||||||||||||
227 | - | |||||||||||||||||||||||||
228 | - | |||||||||||||||||||||||||
229 | - | |||||||||||||||||||||||||
230 | int ret; | - | ||||||||||||||||||||||||
231 | - | |||||||||||||||||||||||||
232 | BN_BLINDING_lock(b); | - | ||||||||||||||||||||||||
233 | ret = BN_BLINDING_convert_ex(f, unblind, b, ctx); | - | ||||||||||||||||||||||||
234 | BN_BLINDING_unlock(b); | - | ||||||||||||||||||||||||
235 | - | |||||||||||||||||||||||||
236 | return never executed: ret;return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||
237 | } | - | ||||||||||||||||||||||||
238 | } | - | ||||||||||||||||||||||||
239 | - | |||||||||||||||||||||||||
240 | static int rsa_blinding_invert(BN_BLINDING *b, BIGNUM *f, BIGNUM *unblind, | - | ||||||||||||||||||||||||
241 | BN_CTX *ctx) | - | ||||||||||||||||||||||||
242 | { | - | ||||||||||||||||||||||||
243 | return executed 2381 times by 1 test: BN_BLINDING_invert_ex(f, unblind, b, ctx);return BN_BLINDING_invert_ex(f, unblind, b, ctx); Executed by:
executed 2381 times by 1 test: return BN_BLINDING_invert_ex(f, unblind, b, ctx); Executed by:
| 2381 | ||||||||||||||||||||||||
244 | } | - | ||||||||||||||||||||||||
245 | - | |||||||||||||||||||||||||
246 | - | |||||||||||||||||||||||||
247 | static int rsa_ossl_private_encrypt(int flen, const unsigned char *from, | - | ||||||||||||||||||||||||
248 | unsigned char *to, RSA *rsa, int padding) | - | ||||||||||||||||||||||||
249 | { | - | ||||||||||||||||||||||||
250 | BIGNUM *f, *ret, *res; | - | ||||||||||||||||||||||||
251 | int i, num = 0, r = -1; | - | ||||||||||||||||||||||||
252 | unsigned char *buf = | - | ||||||||||||||||||||||||
253 | ((void *)0) | - | ||||||||||||||||||||||||
254 | ; | - | ||||||||||||||||||||||||
255 | BN_CTX *ctx = | - | ||||||||||||||||||||||||
256 | ((void *)0) | - | ||||||||||||||||||||||||
257 | ; | - | ||||||||||||||||||||||||
258 | int local_blinding = 0; | - | ||||||||||||||||||||||||
259 | - | |||||||||||||||||||||||||
260 | - | |||||||||||||||||||||||||
261 | - | |||||||||||||||||||||||||
262 | - | |||||||||||||||||||||||||
263 | - | |||||||||||||||||||||||||
264 | BIGNUM *unblind = | - | ||||||||||||||||||||||||
265 | ((void *)0) | - | ||||||||||||||||||||||||
266 | ; | - | ||||||||||||||||||||||||
267 | BN_BLINDING *blinding = | - | ||||||||||||||||||||||||
268 | ((void *)0) | - | ||||||||||||||||||||||||
269 | ; | - | ||||||||||||||||||||||||
270 | - | |||||||||||||||||||||||||
271 | if ((
| 0-1651 | ||||||||||||||||||||||||
272 | ((void *)0)
| 0-1651 | ||||||||||||||||||||||||
273 | ) | - | ||||||||||||||||||||||||
274 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
275 | BN_CTX_start(ctx); | - | ||||||||||||||||||||||||
276 | f = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||
277 | ret = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||
278 | num = ((BN_num_bits(rsa->n)+7)/8); | - | ||||||||||||||||||||||||
279 | buf = CRYPTO_malloc(num, __FILE__, 255); | - | ||||||||||||||||||||||||
280 | if (ret ==
| 0-1651 | ||||||||||||||||||||||||
281 | ((void *)0)
| 0-1651 | ||||||||||||||||||||||||
282 | || buf ==
| 0-1651 | ||||||||||||||||||||||||
283 | ((void *)0)
| 0-1651 | ||||||||||||||||||||||||
284 | ) { | - | ||||||||||||||||||||||||
285 | ERR_put_error(4,(102),((1|64)),__FILE__,257); | - | ||||||||||||||||||||||||
286 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
287 | } | - | ||||||||||||||||||||||||
288 | - | |||||||||||||||||||||||||
289 | switch (padding) { | - | ||||||||||||||||||||||||
290 | case executed 559 times by 1 test: 1:case 1: Executed by:
executed 559 times by 1 test: case 1: Executed by:
| 559 | ||||||||||||||||||||||||
291 | i = RSA_padding_add_PKCS1_type_1(buf, num, from, flen); | - | ||||||||||||||||||||||||
292 | break; executed 559 times by 1 test: break; Executed by:
| 559 | ||||||||||||||||||||||||
293 | case never executed: 5:case 5: never executed: case 5: | 0 | ||||||||||||||||||||||||
294 | i = RSA_padding_add_X931(buf, num, from, flen); | - | ||||||||||||||||||||||||
295 | break; never executed: break; | 0 | ||||||||||||||||||||||||
296 | case executed 1092 times by 1 test: 3:case 3: Executed by:
executed 1092 times by 1 test: case 3: Executed by:
| 1092 | ||||||||||||||||||||||||
297 | i = RSA_padding_add_none(buf, num, from, flen); | - | ||||||||||||||||||||||||
298 | break; executed 1092 times by 1 test: break; Executed by:
| 1092 | ||||||||||||||||||||||||
299 | case never executed: 2:case 2: never executed: case 2: | 0 | ||||||||||||||||||||||||
300 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||||||||
301 | ERR_put_error(4,(102),(118),__FILE__,273); | - | ||||||||||||||||||||||||
302 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
303 | } | - | ||||||||||||||||||||||||
304 | if (i <= 0
| 0-1651 | ||||||||||||||||||||||||
305 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
306 | - | |||||||||||||||||||||||||
307 | if (BN_bin2bn(buf, num, f) ==
| 0-1651 | ||||||||||||||||||||||||
308 | ((void *)0)
| 0-1651 | ||||||||||||||||||||||||
309 | ) | - | ||||||||||||||||||||||||
310 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
311 | - | |||||||||||||||||||||||||
312 | if (BN_ucmp(f, rsa->n) >= 0
| 0-1651 | ||||||||||||||||||||||||
313 | - | |||||||||||||||||||||||||
314 | ERR_put_error(4,(102),(132),__FILE__,285) | - | ||||||||||||||||||||||||
315 | ; | - | ||||||||||||||||||||||||
316 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
317 | } | - | ||||||||||||||||||||||||
318 | - | |||||||||||||||||||||||||
319 | if (!(rsa->flags & 0x0080)
| 0-1651 | ||||||||||||||||||||||||
320 | blinding = rsa_get_blinding(rsa, &local_blinding, ctx); | - | ||||||||||||||||||||||||
321 | if (blinding ==
| 0-1651 | ||||||||||||||||||||||||
322 | ((void *)0)
| 0-1651 | ||||||||||||||||||||||||
323 | ) { | - | ||||||||||||||||||||||||
324 | ERR_put_error(4,(102),((4|64)),__FILE__,292); | - | ||||||||||||||||||||||||
325 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
326 | } | - | ||||||||||||||||||||||||
327 | } executed 1651 times by 1 test: end of block Executed by:
| 1651 | ||||||||||||||||||||||||
328 | - | |||||||||||||||||||||||||
329 | if (blinding !=
| 0-1651 | ||||||||||||||||||||||||
330 | ((void *)0)
| 0-1651 | ||||||||||||||||||||||||
331 | ) { | - | ||||||||||||||||||||||||
332 | if (!local_blinding
| 0-1651 | ||||||||||||||||||||||||
333 | ((void *)0)
| 0 | ||||||||||||||||||||||||
334 | )
| 0 | ||||||||||||||||||||||||
335 | ERR_put_error(4,(102),((1|64)),__FILE__,299); | - | ||||||||||||||||||||||||
336 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
337 | } | - | ||||||||||||||||||||||||
338 | if (!rsa_blinding_convert(blinding, f, unblind, ctx)
| 0-1651 | ||||||||||||||||||||||||
339 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
340 | } executed 1651 times by 1 test: end of block Executed by:
| 1651 | ||||||||||||||||||||||||
341 | - | |||||||||||||||||||||||||
342 | if ((
| 0-1651 | ||||||||||||||||||||||||
343 | (
| 0-1651 | ||||||||||||||||||||||||
344 | ((
| 0-1651 | ||||||||||||||||||||||||
345 | ((void *)0)
| 0-1651 | ||||||||||||||||||||||||
346 | )
| 0-1651 | ||||||||||||||||||||||||
347 | (
| 0-1651 | ||||||||||||||||||||||||
348 | ((void *)0)
| 0-1651 | ||||||||||||||||||||||||
349 | )
| 0-1651 | ||||||||||||||||||||||||
350 | (
| 0-1651 | ||||||||||||||||||||||||
351 | ((void *)0)
| 0-1651 | ||||||||||||||||||||||||
352 | )
| 0-1651 | ||||||||||||||||||||||||
353 | ((void *)0)
| 0-1651 | ||||||||||||||||||||||||
354 | )
| 0-1651 | ||||||||||||||||||||||||
355 | ((void *)0)
| 0-1651 | ||||||||||||||||||||||||
356 | )
| 0-1651 | ||||||||||||||||||||||||
357 | if (!rsa->meth->rsa_mod_exp(ret, f, rsa, ctx)
| 0-1651 | ||||||||||||||||||||||||
358 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
359 | } executed 1651 times by 1 test: else {end of block Executed by:
| 1651 | ||||||||||||||||||||||||
360 | BIGNUM *d = BN_new(); | - | ||||||||||||||||||||||||
361 | if (d ==
| 0 | ||||||||||||||||||||||||
362 | ((void *)0)
| 0 | ||||||||||||||||||||||||
363 | ) { | - | ||||||||||||||||||||||||
364 | ERR_put_error(4,(102),((1|64)),__FILE__,316); | - | ||||||||||||||||||||||||
365 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
366 | } | - | ||||||||||||||||||||||||
367 | BN_with_flags(d, rsa->d, 0x04); | - | ||||||||||||||||||||||||
368 | - | |||||||||||||||||||||||||
369 | if (rsa->flags & 0x0002
| 0 | ||||||||||||||||||||||||
370 | if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, rsa->lock,
| 0 | ||||||||||||||||||||||||
371 | rsa->n, ctx)
| 0 | ||||||||||||||||||||||||
372 | BN_free(d); | - | ||||||||||||||||||||||||
373 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
374 | } | - | ||||||||||||||||||||||||
375 | - | |||||||||||||||||||||||||
376 | if (!rsa->meth->bn_mod_exp(ret, f, d, rsa->n, ctx,
| 0 | ||||||||||||||||||||||||
377 | rsa->_method_mod_n)
| 0 | ||||||||||||||||||||||||
378 | BN_free(d); | - | ||||||||||||||||||||||||
379 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
380 | } | - | ||||||||||||||||||||||||
381 | - | |||||||||||||||||||||||||
382 | BN_free(d); | - | ||||||||||||||||||||||||
383 | } never executed: end of block | 0 | ||||||||||||||||||||||||
384 | - | |||||||||||||||||||||||||
385 | if (blinding
| 0-1651 | ||||||||||||||||||||||||
386 | if (!rsa_blinding_invert(blinding, ret, unblind, ctx)
| 0-1651 | ||||||||||||||||||||||||
387 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
388 | - | |||||||||||||||||||||||||
389 | if (padding == 5
| 0-1651 | ||||||||||||||||||||||||
390 | if (!BN_sub(f, rsa->n, ret)
| 0 | ||||||||||||||||||||||||
391 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
392 | if (BN_cmp(ret, f) > 0
| 0 | ||||||||||||||||||||||||
393 | res = f; never executed: res = f; | 0 | ||||||||||||||||||||||||
394 | else | - | ||||||||||||||||||||||||
395 | res = ret; never executed: res = ret; | 0 | ||||||||||||||||||||||||
396 | } else { | - | ||||||||||||||||||||||||
397 | res = ret; | - | ||||||||||||||||||||||||
398 | } executed 1651 times by 1 test: end of block Executed by:
| 1651 | ||||||||||||||||||||||||
399 | - | |||||||||||||||||||||||||
400 | - | |||||||||||||||||||||||||
401 | - | |||||||||||||||||||||||||
402 | - | |||||||||||||||||||||||||
403 | - | |||||||||||||||||||||||||
404 | r = BN_bn2binpad(res, to, num); | - | ||||||||||||||||||||||||
405 | err: code before this statement executed 1651 times by 1 test: err: Executed by:
| 1651 | ||||||||||||||||||||||||
406 | if (ctx !=
| 0-1651 | ||||||||||||||||||||||||
407 | ((void *)0)
| 0-1651 | ||||||||||||||||||||||||
408 | ) | - | ||||||||||||||||||||||||
409 | BN_CTX_end(ctx); executed 1651 times by 1 test: BN_CTX_end(ctx); Executed by:
| 1651 | ||||||||||||||||||||||||
410 | BN_CTX_free(ctx); | - | ||||||||||||||||||||||||
411 | CRYPTO_clear_free(buf, num, __FILE__, 361); | - | ||||||||||||||||||||||||
412 | return executed 1651 times by 1 test: r;return r; Executed by:
executed 1651 times by 1 test: return r; Executed by:
| 1651 | ||||||||||||||||||||||||
413 | } | - | ||||||||||||||||||||||||
414 | - | |||||||||||||||||||||||||
415 | static int rsa_ossl_private_decrypt(int flen, const unsigned char *from, | - | ||||||||||||||||||||||||
416 | unsigned char *to, RSA *rsa, int padding) | - | ||||||||||||||||||||||||
417 | { | - | ||||||||||||||||||||||||
418 | BIGNUM *f, *ret; | - | ||||||||||||||||||||||||
419 | int j, num = 0, r = -1; | - | ||||||||||||||||||||||||
420 | unsigned char *buf = | - | ||||||||||||||||||||||||
421 | ((void *)0) | - | ||||||||||||||||||||||||
422 | ; | - | ||||||||||||||||||||||||
423 | BN_CTX *ctx = | - | ||||||||||||||||||||||||
424 | ((void *)0) | - | ||||||||||||||||||||||||
425 | ; | - | ||||||||||||||||||||||||
426 | int local_blinding = 0; | - | ||||||||||||||||||||||||
427 | - | |||||||||||||||||||||||||
428 | - | |||||||||||||||||||||||||
429 | - | |||||||||||||||||||||||||
430 | - | |||||||||||||||||||||||||
431 | - | |||||||||||||||||||||||||
432 | BIGNUM *unblind = | - | ||||||||||||||||||||||||
433 | ((void *)0) | - | ||||||||||||||||||||||||
434 | ; | - | ||||||||||||||||||||||||
435 | BN_BLINDING *blinding = | - | ||||||||||||||||||||||||
436 | ((void *)0) | - | ||||||||||||||||||||||||
437 | ; | - | ||||||||||||||||||||||||
438 | - | |||||||||||||||||||||||||
439 | if ((
| 0-735 | ||||||||||||||||||||||||
440 | ((void *)0)
| 0-735 | ||||||||||||||||||||||||
441 | ) | - | ||||||||||||||||||||||||
442 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
443 | BN_CTX_start(ctx); | - | ||||||||||||||||||||||||
444 | f = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||
445 | ret = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||
446 | num = ((BN_num_bits(rsa->n)+7)/8); | - | ||||||||||||||||||||||||
447 | buf = CRYPTO_malloc(num, __FILE__, 387); | - | ||||||||||||||||||||||||
448 | if (ret ==
| 0-735 | ||||||||||||||||||||||||
449 | ((void *)0)
| 0-735 | ||||||||||||||||||||||||
450 | || buf ==
| 0-735 | ||||||||||||||||||||||||
451 | ((void *)0)
| 0-735 | ||||||||||||||||||||||||
452 | ) { | - | ||||||||||||||||||||||||
453 | ERR_put_error(4,(101),((1|64)),__FILE__,389); | - | ||||||||||||||||||||||||
454 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
455 | } | - | ||||||||||||||||||||||||
456 | - | |||||||||||||||||||||||||
457 | - | |||||||||||||||||||||||||
458 | - | |||||||||||||||||||||||||
459 | - | |||||||||||||||||||||||||
460 | - | |||||||||||||||||||||||||
461 | if (flen > num
| 0-735 | ||||||||||||||||||||||||
462 | ERR_put_error(4,(101),(108),__FILE__,399) | - | ||||||||||||||||||||||||
463 | ; | - | ||||||||||||||||||||||||
464 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
465 | } | - | ||||||||||||||||||||||||
466 | - | |||||||||||||||||||||||||
467 | - | |||||||||||||||||||||||||
468 | if (BN_bin2bn(from, (int)flen, f) ==
| 3-732 | ||||||||||||||||||||||||
469 | ((void *)0)
| 3-732 | ||||||||||||||||||||||||
470 | ) | - | ||||||||||||||||||||||||
471 | goto executed 3 times by 1 test: err;goto err; Executed by:
executed 3 times by 1 test: goto err; Executed by:
| 3 | ||||||||||||||||||||||||
472 | - | |||||||||||||||||||||||||
473 | if (BN_ucmp(f, rsa->n) >= 0
| 2-730 | ||||||||||||||||||||||||
474 | ERR_put_error(4,(101),(132),__FILE__,409) | - | ||||||||||||||||||||||||
475 | ; | - | ||||||||||||||||||||||||
476 | goto executed 2 times by 1 test: err;goto err; Executed by:
executed 2 times by 1 test: goto err; Executed by:
| 2 | ||||||||||||||||||||||||
477 | } | - | ||||||||||||||||||||||||
478 | - | |||||||||||||||||||||||||
479 | if (!(rsa->flags & 0x0080)
| 0-730 | ||||||||||||||||||||||||
480 | blinding = rsa_get_blinding(rsa, &local_blinding, ctx); | - | ||||||||||||||||||||||||
481 | if (blinding ==
| 0-730 | ||||||||||||||||||||||||
482 | ((void *)0)
| 0-730 | ||||||||||||||||||||||||
483 | ) { | - | ||||||||||||||||||||||||
484 | ERR_put_error(4,(101),((4|64)),__FILE__,416); | - | ||||||||||||||||||||||||
485 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
486 | } | - | ||||||||||||||||||||||||
487 | } executed 730 times by 1 test: end of block Executed by:
| 730 | ||||||||||||||||||||||||
488 | - | |||||||||||||||||||||||||
489 | if (blinding !=
| 0-730 | ||||||||||||||||||||||||
490 | ((void *)0)
| 0-730 | ||||||||||||||||||||||||
491 | ) { | - | ||||||||||||||||||||||||
492 | if (!local_blinding
| 0-730 | ||||||||||||||||||||||||
493 | ((void *)0)
| 0 | ||||||||||||||||||||||||
494 | )
| 0 | ||||||||||||||||||||||||
495 | ERR_put_error(4,(101),((1|64)),__FILE__,423); | - | ||||||||||||||||||||||||
496 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
497 | } | - | ||||||||||||||||||||||||
498 | if (!rsa_blinding_convert(blinding, f, unblind, ctx)
| 0-730 | ||||||||||||||||||||||||
499 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
500 | } executed 730 times by 1 test: end of block Executed by:
| 730 | ||||||||||||||||||||||||
501 | - | |||||||||||||||||||||||||
502 | - | |||||||||||||||||||||||||
503 | if ((
| 0-730 | ||||||||||||||||||||||||
504 | (
| 7-723 | ||||||||||||||||||||||||
505 | ((
| 0-723 | ||||||||||||||||||||||||
506 | ((void *)0)
| 0-723 | ||||||||||||||||||||||||
507 | )
| 0-723 | ||||||||||||||||||||||||
508 | (
| 0-723 | ||||||||||||||||||||||||
509 | ((void *)0)
| 0-723 | ||||||||||||||||||||||||
510 | )
| 0-723 | ||||||||||||||||||||||||
511 | (
| 0-723 | ||||||||||||||||||||||||
512 | ((void *)0)
| 0-723 | ||||||||||||||||||||||||
513 | )
| 0-723 | ||||||||||||||||||||||||
514 | ((void *)0)
| 0-723 | ||||||||||||||||||||||||
515 | )
| 0-723 | ||||||||||||||||||||||||
516 | ((void *)0)
| 0-723 | ||||||||||||||||||||||||
517 | )
| 0-723 | ||||||||||||||||||||||||
518 | if (!rsa->meth->rsa_mod_exp(ret, f, rsa, ctx)
| 0-730 | ||||||||||||||||||||||||
519 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
520 | } executed 730 times by 1 test: else {end of block Executed by:
| 730 | ||||||||||||||||||||||||
521 | BIGNUM *d = BN_new(); | - | ||||||||||||||||||||||||
522 | if (d ==
| 0 | ||||||||||||||||||||||||
523 | ((void *)0)
| 0 | ||||||||||||||||||||||||
524 | ) { | - | ||||||||||||||||||||||||
525 | ERR_put_error(4,(101),((1|64)),__FILE__,441); | - | ||||||||||||||||||||||||
526 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
527 | } | - | ||||||||||||||||||||||||
528 | BN_with_flags(d, rsa->d, 0x04); | - | ||||||||||||||||||||||||
529 | - | |||||||||||||||||||||||||
530 | if (rsa->flags & 0x0002
| 0 | ||||||||||||||||||||||||
531 | if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, rsa->lock,
| 0 | ||||||||||||||||||||||||
532 | rsa->n, ctx)
| 0 | ||||||||||||||||||||||||
533 | BN_free(d); | - | ||||||||||||||||||||||||
534 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
535 | } | - | ||||||||||||||||||||||||
536 | if (!rsa->meth->bn_mod_exp(ret, f, d, rsa->n, ctx,
| 0 | ||||||||||||||||||||||||
537 | rsa->_method_mod_n)
| 0 | ||||||||||||||||||||||||
538 | BN_free(d); | - | ||||||||||||||||||||||||
539 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
540 | } | - | ||||||||||||||||||||||||
541 | - | |||||||||||||||||||||||||
542 | BN_free(d); | - | ||||||||||||||||||||||||
543 | } never executed: end of block | 0 | ||||||||||||||||||||||||
544 | - | |||||||||||||||||||||||||
545 | if (blinding
| 0-730 | ||||||||||||||||||||||||
546 | if (!rsa_blinding_invert(blinding, ret, unblind, ctx)
| 0-730 | ||||||||||||||||||||||||
547 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
548 | - | |||||||||||||||||||||||||
549 | j = BN_bn2binpad(ret, buf, num); | - | ||||||||||||||||||||||||
550 | - | |||||||||||||||||||||||||
551 | switch (padding) { | - | ||||||||||||||||||||||||
552 | case executed 31 times by 1 test: 1:case 1: Executed by:
executed 31 times by 1 test: case 1: Executed by:
| 31 | ||||||||||||||||||||||||
553 | r = RSA_padding_check_PKCS1_type_2(to, num, buf, j, num); | - | ||||||||||||||||||||||||
554 | break; executed 31 times by 1 test: break; Executed by:
| 31 | ||||||||||||||||||||||||
555 | case executed 490 times by 1 test: 4:case 4: Executed by:
executed 490 times by 1 test: case 4: Executed by:
| 490 | ||||||||||||||||||||||||
556 | r = RSA_padding_check_PKCS1_OAEP(to, num, buf, j, num, | - | ||||||||||||||||||||||||
557 | ((void *)0) | - | ||||||||||||||||||||||||
558 | , 0); | - | ||||||||||||||||||||||||
559 | break; executed 490 times by 1 test: break; Executed by:
| 490 | ||||||||||||||||||||||||
560 | case never executed: 2:case 2: never executed: case 2: | 0 | ||||||||||||||||||||||||
561 | r = RSA_padding_check_SSLv23(to, num, buf, j, num); | - | ||||||||||||||||||||||||
562 | break; never executed: break; | 0 | ||||||||||||||||||||||||
563 | case executed 209 times by 1 test: 3:case 3: Executed by:
executed 209 times by 1 test: case 3: Executed by:
| 209 | ||||||||||||||||||||||||
564 | memcpy(to, buf, (r = j)); | - | ||||||||||||||||||||||||
565 | break; executed 209 times by 1 test: break; Executed by:
| 209 | ||||||||||||||||||||||||
566 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||||||||
567 | ERR_put_error(4,(101),(118),__FILE__,481); | - | ||||||||||||||||||||||||
568 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
569 | } | - | ||||||||||||||||||||||||
570 | if (r < 0
| 241-489 | ||||||||||||||||||||||||
571 | ERR_put_error(4,(101),(114),__FILE__,485); executed 489 times by 1 test: ERR_put_error(4,(101),(114),__FILE__,485); Executed by:
| 489 | ||||||||||||||||||||||||
572 | - | |||||||||||||||||||||||||
573 | err: code before this statement executed 730 times by 1 test: err: Executed by:
| 730 | ||||||||||||||||||||||||
574 | if (ctx !=
| 0-735 | ||||||||||||||||||||||||
575 | ((void *)0)
| 0-735 | ||||||||||||||||||||||||
576 | ) | - | ||||||||||||||||||||||||
577 | BN_CTX_end(ctx); executed 735 times by 1 test: BN_CTX_end(ctx); Executed by:
| 735 | ||||||||||||||||||||||||
578 | BN_CTX_free(ctx); | - | ||||||||||||||||||||||||
579 | CRYPTO_clear_free(buf, num, __FILE__, 491); | - | ||||||||||||||||||||||||
580 | return executed 735 times by 1 test: r;return r; Executed by:
executed 735 times by 1 test: return r; Executed by:
| 735 | ||||||||||||||||||||||||
581 | } | - | ||||||||||||||||||||||||
582 | - | |||||||||||||||||||||||||
583 | - | |||||||||||||||||||||||||
584 | static int rsa_ossl_public_decrypt(int flen, const unsigned char *from, | - | ||||||||||||||||||||||||
585 | unsigned char *to, RSA *rsa, int padding) | - | ||||||||||||||||||||||||
586 | { | - | ||||||||||||||||||||||||
587 | BIGNUM *f, *ret; | - | ||||||||||||||||||||||||
588 | int i, num = 0, r = -1; | - | ||||||||||||||||||||||||
589 | unsigned char *buf = | - | ||||||||||||||||||||||||
590 | ((void *)0) | - | ||||||||||||||||||||||||
591 | ; | - | ||||||||||||||||||||||||
592 | BN_CTX *ctx = | - | ||||||||||||||||||||||||
593 | ((void *)0) | - | ||||||||||||||||||||||||
594 | ; | - | ||||||||||||||||||||||||
595 | - | |||||||||||||||||||||||||
596 | if (BN_num_bits(rsa->n) > 16384
| 0-2776 | ||||||||||||||||||||||||
597 | ERR_put_error(4,(103),(105),__FILE__,505); | - | ||||||||||||||||||||||||
598 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
599 | } | - | ||||||||||||||||||||||||
600 | - | |||||||||||||||||||||||||
601 | if (BN_ucmp(rsa->n, rsa->e) <= 0
| 0-2776 | ||||||||||||||||||||||||
602 | ERR_put_error(4,(103),(101),__FILE__,510); | - | ||||||||||||||||||||||||
603 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
604 | } | - | ||||||||||||||||||||||||
605 | - | |||||||||||||||||||||||||
606 | - | |||||||||||||||||||||||||
607 | if (BN_num_bits(rsa->n) > 3072
| 4-2772 | ||||||||||||||||||||||||
608 | if (BN_num_bits(rsa->e) > 64
| 0-4 | ||||||||||||||||||||||||
609 | ERR_put_error(4,(103),(101),__FILE__,517); | - | ||||||||||||||||||||||||
610 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
611 | } | - | ||||||||||||||||||||||||
612 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
613 | - | |||||||||||||||||||||||||
614 | if ((
| 0-2776 | ||||||||||||||||||||||||
615 | ((void *)0)
| 0-2776 | ||||||||||||||||||||||||
616 | ) | - | ||||||||||||||||||||||||
617 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
618 | BN_CTX_start(ctx); | - | ||||||||||||||||||||||||
619 | f = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||
620 | ret = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||
621 | num = ((BN_num_bits(rsa->n)+7)/8); | - | ||||||||||||||||||||||||
622 | buf = CRYPTO_malloc(num, __FILE__, 528); | - | ||||||||||||||||||||||||
623 | if (ret ==
| 0-2776 | ||||||||||||||||||||||||
624 | ((void *)0)
| 0-2776 | ||||||||||||||||||||||||
625 | || buf ==
| 0-2776 | ||||||||||||||||||||||||
626 | ((void *)0)
| 0-2776 | ||||||||||||||||||||||||
627 | ) { | - | ||||||||||||||||||||||||
628 | ERR_put_error(4,(103),((1|64)),__FILE__,530); | - | ||||||||||||||||||||||||
629 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
630 | } | - | ||||||||||||||||||||||||
631 | - | |||||||||||||||||||||||||
632 | - | |||||||||||||||||||||||||
633 | - | |||||||||||||||||||||||||
634 | - | |||||||||||||||||||||||||
635 | - | |||||||||||||||||||||||||
636 | if (flen > num
| 0-2776 | ||||||||||||||||||||||||
637 | ERR_put_error(4,(103),(108),__FILE__,539); | - | ||||||||||||||||||||||||
638 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
639 | } | - | ||||||||||||||||||||||||
640 | - | |||||||||||||||||||||||||
641 | if (BN_bin2bn(from, flen, f) ==
| 0-2776 | ||||||||||||||||||||||||
642 | ((void *)0)
| 0-2776 | ||||||||||||||||||||||||
643 | ) | - | ||||||||||||||||||||||||
644 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
645 | - | |||||||||||||||||||||||||
646 | if (BN_ucmp(f, rsa->n) >= 0
| 2-2774 | ||||||||||||||||||||||||
647 | ERR_put_error(4,(103),(132),__FILE__,548) | - | ||||||||||||||||||||||||
648 | ; | - | ||||||||||||||||||||||||
649 | goto executed 2 times by 1 test: err;goto err; Executed by:
executed 2 times by 1 test: goto err; Executed by:
| 2 | ||||||||||||||||||||||||
650 | } | - | ||||||||||||||||||||||||
651 | - | |||||||||||||||||||||||||
652 | if (rsa->flags & 0x0002
| 0-2774 | ||||||||||||||||||||||||
653 | if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, rsa->lock,
| 2-2772 | ||||||||||||||||||||||||
654 | rsa->n, ctx)
| 2-2772 | ||||||||||||||||||||||||
655 | goto executed 2 times by 1 test: err;goto err; Executed by:
executed 2 times by 1 test: goto err; Executed by:
| 2 | ||||||||||||||||||||||||
656 | - | |||||||||||||||||||||||||
657 | if (!rsa->meth->bn_mod_exp(ret, f, rsa->e, rsa->n, ctx,
| 0-2772 | ||||||||||||||||||||||||
658 | rsa->_method_mod_n)
| 0-2772 | ||||||||||||||||||||||||
659 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
660 | - | |||||||||||||||||||||||||
661 | if ((
| 0-2772 | ||||||||||||||||||||||||
662 | if (!BN_sub(ret, rsa->n, ret)
| 0 | ||||||||||||||||||||||||
663 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
664 | - | |||||||||||||||||||||||||
665 | i = BN_bn2binpad(ret, buf, num); | - | ||||||||||||||||||||||||
666 | - | |||||||||||||||||||||||||
667 | switch (padding) { | - | ||||||||||||||||||||||||
668 | case executed 1763 times by 1 test: 1:case 1: Executed by:
executed 1763 times by 1 test: case 1: Executed by:
| 1763 | ||||||||||||||||||||||||
669 | r = RSA_padding_check_PKCS1_type_1(to, num, buf, i, num); | - | ||||||||||||||||||||||||
670 | break; executed 1763 times by 1 test: break; Executed by:
| 1763 | ||||||||||||||||||||||||
671 | case never executed: 5:case 5: never executed: case 5: | 0 | ||||||||||||||||||||||||
672 | r = RSA_padding_check_X931(to, num, buf, i, num); | - | ||||||||||||||||||||||||
673 | break; never executed: break; | 0 | ||||||||||||||||||||||||
674 | case executed 1009 times by 1 test: 3:case 3: Executed by:
executed 1009 times by 1 test: case 3: Executed by:
| 1009 | ||||||||||||||||||||||||
675 | memcpy(to, buf, (r = i)); | - | ||||||||||||||||||||||||
676 | break; executed 1009 times by 1 test: break; Executed by:
| 1009 | ||||||||||||||||||||||||
677 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||||||||
678 | ERR_put_error(4,(103),(118),__FILE__,578); | - | ||||||||||||||||||||||||
679 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
680 | } | - | ||||||||||||||||||||||||
681 | if (r < 0
| 20-2752 | ||||||||||||||||||||||||
682 | ERR_put_error(4,(103),(114),__FILE__,582); executed 20 times by 1 test: ERR_put_error(4,(103),(114),__FILE__,582); Executed by:
| 20 | ||||||||||||||||||||||||
683 | - | |||||||||||||||||||||||||
684 | err: code before this statement executed 2772 times by 1 test: err: Executed by:
| 2772 | ||||||||||||||||||||||||
685 | if (ctx !=
| 0-2776 | ||||||||||||||||||||||||
686 | ((void *)0)
| 0-2776 | ||||||||||||||||||||||||
687 | ) | - | ||||||||||||||||||||||||
688 | BN_CTX_end(ctx); executed 2776 times by 1 test: BN_CTX_end(ctx); Executed by:
| 2776 | ||||||||||||||||||||||||
689 | BN_CTX_free(ctx); | - | ||||||||||||||||||||||||
690 | CRYPTO_clear_free(buf, num, __FILE__, 588); | - | ||||||||||||||||||||||||
691 | return executed 2776 times by 1 test: r;return r; Executed by:
executed 2776 times by 1 test: return r; Executed by:
| 2776 | ||||||||||||||||||||||||
692 | } | - | ||||||||||||||||||||||||
693 | - | |||||||||||||||||||||||||
694 | static int rsa_ossl_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) | - | ||||||||||||||||||||||||
695 | { | - | ||||||||||||||||||||||||
696 | BIGNUM *r1, *m1, *vrfy, *r2, *m[5 - 2]; | - | ||||||||||||||||||||||||
697 | int ret = 0, i, ex_primes = 0, smooth = 0; | - | ||||||||||||||||||||||||
698 | RSA_PRIME_INFO *pinfo; | - | ||||||||||||||||||||||||
699 | - | |||||||||||||||||||||||||
700 | BN_CTX_start(ctx); | - | ||||||||||||||||||||||||
701 | - | |||||||||||||||||||||||||
702 | r1 = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||
703 | r2 = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||
704 | m1 = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||
705 | vrfy = BN_CTX_get(ctx); | - | ||||||||||||||||||||||||
706 | if (vrfy ==
| 0-2381 | ||||||||||||||||||||||||
707 | ((void *)0)
| 0-2381 | ||||||||||||||||||||||||
708 | ) | - | ||||||||||||||||||||||||
709 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
710 | - | |||||||||||||||||||||||||
711 | if (rsa->version == 1
| 7-2374 | ||||||||||||||||||||||||
712 | && ((
| 0-7 | ||||||||||||||||||||||||
713 | || ex_primes > 5 - 2
| 0-7 | ||||||||||||||||||||||||
714 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
715 | - | |||||||||||||||||||||||||
716 | if (rsa->flags & 0x0004
| 0-2381 | ||||||||||||||||||||||||
717 | BIGNUM *factor = BN_new(); | - | ||||||||||||||||||||||||
718 | - | |||||||||||||||||||||||||
719 | if (factor ==
| 0-2381 | ||||||||||||||||||||||||
720 | ((void *)0)
| 0-2381 | ||||||||||||||||||||||||
721 | ) | - | ||||||||||||||||||||||||
722 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
723 | - | |||||||||||||||||||||||||
724 | - | |||||||||||||||||||||||||
725 | - | |||||||||||||||||||||||||
726 | - | |||||||||||||||||||||||||
727 | - | |||||||||||||||||||||||||
728 | if (!(BN_with_flags(factor, rsa->p, 0x04),
| 0-2381 | ||||||||||||||||||||||||
729 | BN_MONT_CTX_set_locked(&rsa->_method_mod_p, rsa->lock,
| 0-2381 | ||||||||||||||||||||||||
730 | factor, ctx))
| 0-2381 | ||||||||||||||||||||||||
731 | || !(BN_with_flags(factor, rsa->q, 0x04),
| 0-2381 | ||||||||||||||||||||||||
732 | BN_MONT_CTX_set_locked(&rsa->_method_mod_q, rsa->lock,
| 0-2381 | ||||||||||||||||||||||||
733 | factor, ctx))
| 0-2381 | ||||||||||||||||||||||||
734 | BN_free(factor); | - | ||||||||||||||||||||||||
735 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
736 | } | - | ||||||||||||||||||||||||
737 | for (i = 0; i < ex_primes
| 13-2381 | ||||||||||||||||||||||||
738 | pinfo = sk_RSA_PRIME_INFO_value(rsa->prime_infos, i); | - | ||||||||||||||||||||||||
739 | BN_with_flags(factor, pinfo->r, 0x04); | - | ||||||||||||||||||||||||
740 | if (!BN_MONT_CTX_set_locked(&pinfo->m, rsa->lock, factor, ctx)
| 0-13 | ||||||||||||||||||||||||
741 | BN_free(factor); | - | ||||||||||||||||||||||||
742 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
743 | } | - | ||||||||||||||||||||||||
744 | } executed 13 times by 1 test: end of block Executed by:
| 13 | ||||||||||||||||||||||||
745 | - | |||||||||||||||||||||||||
746 | - | |||||||||||||||||||||||||
747 | - | |||||||||||||||||||||||||
748 | BN_free(factor); | - | ||||||||||||||||||||||||
749 | - | |||||||||||||||||||||||||
750 | smooth = (
| 7-2374 | ||||||||||||||||||||||||
751 | && (
| 0-2374 | ||||||||||||||||||||||||
752 | && (
| 0-2374 | ||||||||||||||||||||||||
753 | } executed 2381 times by 1 test: end of block Executed by:
| 2381 | ||||||||||||||||||||||||
754 | - | |||||||||||||||||||||||||
755 | if (rsa->flags & 0x0002
| 0-2381 | ||||||||||||||||||||||||
756 | if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, rsa->lock,
| 0-2381 | ||||||||||||||||||||||||
757 | rsa->n, ctx)
| 0-2381 | ||||||||||||||||||||||||
758 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
759 | - | |||||||||||||||||||||||||
760 | if (smooth
| 7-2374 | ||||||||||||||||||||||||
761 | - | |||||||||||||||||||||||||
762 | - | |||||||||||||||||||||||||
763 | - | |||||||||||||||||||||||||
764 | - | |||||||||||||||||||||||||
765 | - | |||||||||||||||||||||||||
766 | - | |||||||||||||||||||||||||
767 | - | |||||||||||||||||||||||||
768 | if ( | - | ||||||||||||||||||||||||
769 | !bn_from_mont_fixed_top(m1, I, rsa->_method_mod_q, ctx)
| 0-2374 | ||||||||||||||||||||||||
770 | || !bn_to_mont_fixed_top(m1, m1, rsa->_method_mod_q, ctx)
| 0-2374 | ||||||||||||||||||||||||
771 | - | |||||||||||||||||||||||||
772 | || !BN_mod_exp_mont_consttime(m1, m1, rsa->dmq1, rsa->q, ctx,
| 0-2374 | ||||||||||||||||||||||||
773 | rsa->_method_mod_q)
| 0-2374 | ||||||||||||||||||||||||
774 | - | |||||||||||||||||||||||||
775 | || !bn_from_mont_fixed_top(r1, I, rsa->_method_mod_p, ctx)
| 0-2374 | ||||||||||||||||||||||||
776 | || !bn_to_mont_fixed_top(r1, r1, rsa->_method_mod_p, ctx)
| 0-2374 | ||||||||||||||||||||||||
777 | - | |||||||||||||||||||||||||
778 | || !BN_mod_exp_mont_consttime(r1, r1, rsa->dmp1, rsa->p, ctx,
| 0-2374 | ||||||||||||||||||||||||
779 | rsa->_method_mod_p)
| 0-2374 | ||||||||||||||||||||||||
780 | - | |||||||||||||||||||||||||
781 | - | |||||||||||||||||||||||||
782 | - | |||||||||||||||||||||||||
783 | - | |||||||||||||||||||||||||
784 | - | |||||||||||||||||||||||||
785 | - | |||||||||||||||||||||||||
786 | - | |||||||||||||||||||||||||
787 | || !bn_mod_sub_fixed_top(r1, r1, m1, rsa->p)
| 0-2374 | ||||||||||||||||||||||||
788 | - | |||||||||||||||||||||||||
789 | - | |||||||||||||||||||||||||
790 | || !bn_to_mont_fixed_top(r1, r1, rsa->_method_mod_p, ctx)
| 0-2374 | ||||||||||||||||||||||||
791 | || !bn_mul_mont_fixed_top(r1, r1, rsa->iqmp, rsa->_method_mod_p,
| 0-2374 | ||||||||||||||||||||||||
792 | ctx)
| 0-2374 | ||||||||||||||||||||||||
793 | || !bn_mul_fixed_top(r0, r1, rsa->q, ctx)
| 0-2374 | ||||||||||||||||||||||||
794 | || !bn_mod_add_fixed_top(r0, r0, m1, rsa->n)
| 0-2374 | ||||||||||||||||||||||||
795 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
796 | - | |||||||||||||||||||||||||
797 | goto executed 2374 times by 1 test: tail;goto tail; Executed by:
executed 2374 times by 1 test: goto tail; Executed by:
| 2374 | ||||||||||||||||||||||||
798 | } | - | ||||||||||||||||||||||||
799 | - | |||||||||||||||||||||||||
800 | - | |||||||||||||||||||||||||
801 | { | - | ||||||||||||||||||||||||
802 | BIGNUM *c = BN_new(); | - | ||||||||||||||||||||||||
803 | if (c ==
| 0-7 | ||||||||||||||||||||||||
804 | ((void *)0)
| 0-7 | ||||||||||||||||||||||||
805 | ) | - | ||||||||||||||||||||||||
806 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
807 | BN_with_flags(c, I, 0x04); | - | ||||||||||||||||||||||||
808 | - | |||||||||||||||||||||||||
809 | if (!BN_div(
| 0-7 | ||||||||||||||||||||||||
810 | ((void *)0)
| 0-7 | ||||||||||||||||||||||||
811 | ,(r1),(c),(rsa->q),(ctx))
| 0-7 | ||||||||||||||||||||||||
812 | BN_free(c); | - | ||||||||||||||||||||||||
813 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
814 | } | - | ||||||||||||||||||||||||
815 | - | |||||||||||||||||||||||||
816 | { | - | ||||||||||||||||||||||||
817 | BIGNUM *dmq1 = BN_new(); | - | ||||||||||||||||||||||||
818 | if (dmq1 ==
| 0-7 | ||||||||||||||||||||||||
819 | ((void *)0)
| 0-7 | ||||||||||||||||||||||||
820 | ) { | - | ||||||||||||||||||||||||
821 | BN_free(c); | - | ||||||||||||||||||||||||
822 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
823 | } | - | ||||||||||||||||||||||||
824 | BN_with_flags(dmq1, rsa->dmq1, 0x04); | - | ||||||||||||||||||||||||
825 | - | |||||||||||||||||||||||||
826 | - | |||||||||||||||||||||||||
827 | if (!rsa->meth->bn_mod_exp(m1, r1, dmq1, rsa->q, ctx,
| 0-7 | ||||||||||||||||||||||||
828 | rsa->_method_mod_q)
| 0-7 | ||||||||||||||||||||||||
829 | BN_free(c); | - | ||||||||||||||||||||||||
830 | BN_free(dmq1); | - | ||||||||||||||||||||||||
831 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
832 | } | - | ||||||||||||||||||||||||
833 | - | |||||||||||||||||||||||||
834 | BN_free(dmq1); | - | ||||||||||||||||||||||||
835 | } | - | ||||||||||||||||||||||||
836 | - | |||||||||||||||||||||||||
837 | - | |||||||||||||||||||||||||
838 | if (!BN_div(
| 0-7 | ||||||||||||||||||||||||
839 | ((void *)0)
| 0-7 | ||||||||||||||||||||||||
840 | ,(r1),(c),(rsa->p),(ctx))
| 0-7 | ||||||||||||||||||||||||
841 | BN_free(c); | - | ||||||||||||||||||||||||
842 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
843 | } | - | ||||||||||||||||||||||||
844 | - | |||||||||||||||||||||||||
845 | BN_free(c); | - | ||||||||||||||||||||||||
846 | } | - | ||||||||||||||||||||||||
847 | - | |||||||||||||||||||||||||
848 | { | - | ||||||||||||||||||||||||
849 | BIGNUM *dmp1 = BN_new(); | - | ||||||||||||||||||||||||
850 | if (dmp1 ==
| 0-7 | ||||||||||||||||||||||||
851 | ((void *)0)
| 0-7 | ||||||||||||||||||||||||
852 | ) | - | ||||||||||||||||||||||||
853 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
854 | BN_with_flags(dmp1, rsa->dmp1, 0x04); | - | ||||||||||||||||||||||||
855 | - | |||||||||||||||||||||||||
856 | - | |||||||||||||||||||||||||
857 | if (!rsa->meth->bn_mod_exp(r0, r1, dmp1, rsa->p, ctx,
| 0-7 | ||||||||||||||||||||||||
858 | rsa->_method_mod_p)
| 0-7 | ||||||||||||||||||||||||
859 | BN_free(dmp1); | - | ||||||||||||||||||||||||
860 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
861 | } | - | ||||||||||||||||||||||||
862 | - | |||||||||||||||||||||||||
863 | BN_free(dmp1); | - | ||||||||||||||||||||||||
864 | } | - | ||||||||||||||||||||||||
865 | if (ex_primes > 0
| 0-7 | ||||||||||||||||||||||||
866 | BIGNUM *di = BN_new(), *cc = BN_new(); | - | ||||||||||||||||||||||||
867 | - | |||||||||||||||||||||||||
868 | if (cc ==
| 0-7 | ||||||||||||||||||||||||
869 | ((void *)0)
| 0-7 | ||||||||||||||||||||||||
870 | || di ==
| 0-7 | ||||||||||||||||||||||||
871 | ((void *)0)
| 0-7 | ||||||||||||||||||||||||
872 | ) { | - | ||||||||||||||||||||||||
873 | BN_free(cc); | - | ||||||||||||||||||||||||
874 | BN_free(di); | - | ||||||||||||||||||||||||
875 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
876 | } | - | ||||||||||||||||||||||||
877 | - | |||||||||||||||||||||||||
878 | for (i = 0; i < ex_primes
| 7-13 | ||||||||||||||||||||||||
879 | - | |||||||||||||||||||||||||
880 | if ((
| 0-13 | ||||||||||||||||||||||||
881 | ((void *)0)
| 0-13 | ||||||||||||||||||||||||
882 | ) { | - | ||||||||||||||||||||||||
883 | BN_free(cc); | - | ||||||||||||||||||||||||
884 | BN_free(di); | - | ||||||||||||||||||||||||
885 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
886 | } | - | ||||||||||||||||||||||||
887 | - | |||||||||||||||||||||||||
888 | pinfo = sk_RSA_PRIME_INFO_value(rsa->prime_infos, i); | - | ||||||||||||||||||||||||
889 | - | |||||||||||||||||||||||||
890 | - | |||||||||||||||||||||||||
891 | BN_with_flags(cc, I, 0x04); | - | ||||||||||||||||||||||||
892 | BN_with_flags(di, pinfo->d, 0x04); | - | ||||||||||||||||||||||||
893 | - | |||||||||||||||||||||||||
894 | if (!BN_div(
| 0-13 | ||||||||||||||||||||||||
895 | ((void *)0)
| 0-13 | ||||||||||||||||||||||||
896 | ,(r1),(cc),(pinfo->r),(ctx))
| 0-13 | ||||||||||||||||||||||||
897 | BN_free(cc); | - | ||||||||||||||||||||||||
898 | BN_free(di); | - | ||||||||||||||||||||||||
899 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
900 | } | - | ||||||||||||||||||||||||
901 | - | |||||||||||||||||||||||||
902 | if (!rsa->meth->bn_mod_exp(m[i], r1, di, pinfo->r, ctx, pinfo->m)
| 0-13 | ||||||||||||||||||||||||
903 | BN_free(cc); | - | ||||||||||||||||||||||||
904 | BN_free(di); | - | ||||||||||||||||||||||||
905 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
906 | } | - | ||||||||||||||||||||||||
907 | } executed 13 times by 1 test: end of block Executed by:
| 13 | ||||||||||||||||||||||||
908 | - | |||||||||||||||||||||||||
909 | BN_free(cc); | - | ||||||||||||||||||||||||
910 | BN_free(di); | - | ||||||||||||||||||||||||
911 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||||||||||||||
912 | - | |||||||||||||||||||||||||
913 | if (!BN_sub(r0, r0, m1)
| 0-7 | ||||||||||||||||||||||||
914 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
915 | - | |||||||||||||||||||||||||
916 | - | |||||||||||||||||||||||||
917 | - | |||||||||||||||||||||||||
918 | - | |||||||||||||||||||||||||
919 | if (BN_is_negative(r0)
| 2-5 | ||||||||||||||||||||||||
920 | if (!BN_add(r0, r0, rsa->p)
| 0-2 | ||||||||||||||||||||||||
921 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
922 | - | |||||||||||||||||||||||||
923 | if (!BN_mul(r1, r0, rsa->iqmp, ctx)
| 0-7 | ||||||||||||||||||||||||
924 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
925 | - | |||||||||||||||||||||||||
926 | { | - | ||||||||||||||||||||||||
927 | BIGNUM *pr1 = BN_new(); | - | ||||||||||||||||||||||||
928 | if (pr1 ==
| 0-7 | ||||||||||||||||||||||||
929 | ((void *)0)
| 0-7 | ||||||||||||||||||||||||
930 | ) | - | ||||||||||||||||||||||||
931 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
932 | BN_with_flags(pr1, r1, 0x04); | - | ||||||||||||||||||||||||
933 | - | |||||||||||||||||||||||||
934 | if (!BN_div(
| 0-7 | ||||||||||||||||||||||||
935 | ((void *)0)
| 0-7 | ||||||||||||||||||||||||
936 | ,(r0),(pr1),(rsa->p),(ctx))
| 0-7 | ||||||||||||||||||||||||
937 | BN_free(pr1); | - | ||||||||||||||||||||||||
938 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
939 | } | - | ||||||||||||||||||||||||
940 | - | |||||||||||||||||||||||||
941 | BN_free(pr1); | - | ||||||||||||||||||||||||
942 | } | - | ||||||||||||||||||||||||
943 | if (BN_is_negative(r0)
| 0-7 | ||||||||||||||||||||||||
944 | if (!BN_add(r0, r0, rsa->p)
| 0 | ||||||||||||||||||||||||
945 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
946 | if (!BN_mul(r1, r0, rsa->q, ctx)
| 0-7 | ||||||||||||||||||||||||
947 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
948 | if (!BN_add(r0, r1, m1)
| 0-7 | ||||||||||||||||||||||||
949 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
950 | - | |||||||||||||||||||||||||
951 | - | |||||||||||||||||||||||||
952 | if (ex_primes > 0
| 0-7 | ||||||||||||||||||||||||
953 | BIGNUM *pr2 = BN_new(); | - | ||||||||||||||||||||||||
954 | - | |||||||||||||||||||||||||
955 | if (pr2 ==
| 0-7 | ||||||||||||||||||||||||
956 | ((void *)0)
| 0-7 | ||||||||||||||||||||||||
957 | ) | - | ||||||||||||||||||||||||
958 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
959 | - | |||||||||||||||||||||||||
960 | for (i = 0; i < ex_primes
| 7-13 | ||||||||||||||||||||||||
961 | pinfo = sk_RSA_PRIME_INFO_value(rsa->prime_infos, i); | - | ||||||||||||||||||||||||
962 | if (!BN_sub(r1, m[i], r0)
| 0-13 | ||||||||||||||||||||||||
963 | BN_free(pr2); | - | ||||||||||||||||||||||||
964 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
965 | } | - | ||||||||||||||||||||||||
966 | - | |||||||||||||||||||||||||
967 | if (!BN_mul(r2, r1, pinfo->t, ctx)
| 0-13 | ||||||||||||||||||||||||
968 | BN_free(pr2); | - | ||||||||||||||||||||||||
969 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
970 | } | - | ||||||||||||||||||||||||
971 | - | |||||||||||||||||||||||||
972 | BN_with_flags(pr2, r2, 0x04); | - | ||||||||||||||||||||||||
973 | - | |||||||||||||||||||||||||
974 | if (!BN_div(
| 0-13 | ||||||||||||||||||||||||
975 | ((void *)0)
| 0-13 | ||||||||||||||||||||||||
976 | ,(r1),(pr2),(pinfo->r),(ctx))
| 0-13 | ||||||||||||||||||||||||
977 | BN_free(pr2); | - | ||||||||||||||||||||||||
978 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
979 | } | - | ||||||||||||||||||||||||
980 | - | |||||||||||||||||||||||||
981 | if (BN_is_negative(r1)
| 0-13 | ||||||||||||||||||||||||
982 | if (!BN_add(r1, r1, pinfo->r)
| 0-13 | ||||||||||||||||||||||||
983 | BN_free(pr2); | - | ||||||||||||||||||||||||
984 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
985 | } | - | ||||||||||||||||||||||||
986 | if (!BN_mul(r1, r1, pinfo->pp, ctx)
| 0-13 | ||||||||||||||||||||||||
987 | BN_free(pr2); | - | ||||||||||||||||||||||||
988 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
989 | } | - | ||||||||||||||||||||||||
990 | if (!BN_add(r0, r0, r1)
| 0-13 | ||||||||||||||||||||||||
991 | BN_free(pr2); | - | ||||||||||||||||||||||||
992 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
993 | } | - | ||||||||||||||||||||||||
994 | } executed 13 times by 1 test: end of block Executed by:
| 13 | ||||||||||||||||||||||||
995 | BN_free(pr2); | - | ||||||||||||||||||||||||
996 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||||||||||||||
997 | - | |||||||||||||||||||||||||
998 | tail: code before this statement executed 7 times by 1 test: tail: Executed by:
| 7 | ||||||||||||||||||||||||
999 | if (rsa->e
| 0-2381 | ||||||||||||||||||||||||
1000 | if (rsa->meth->bn_mod_exp == BN_mod_exp_mont
| 0-2381 | ||||||||||||||||||||||||
1001 | if (!BN_mod_exp_mont(vrfy, r0, rsa->e, rsa->n, ctx,
| 0-2381 | ||||||||||||||||||||||||
1002 | rsa->_method_mod_n)
| 0-2381 | ||||||||||||||||||||||||
1003 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
1004 | } executed 2381 times by 1 test: else {end of block Executed by:
| 2381 | ||||||||||||||||||||||||
1005 | bn_correct_top(r0); | - | ||||||||||||||||||||||||
1006 | if (!rsa->meth->bn_mod_exp(vrfy, r0, rsa->e, rsa->n, ctx,
| 0 | ||||||||||||||||||||||||
1007 | rsa->_method_mod_n)
| 0 | ||||||||||||||||||||||||
1008 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
1009 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1010 | - | |||||||||||||||||||||||||
1011 | - | |||||||||||||||||||||||||
1012 | - | |||||||||||||||||||||||||
1013 | - | |||||||||||||||||||||||||
1014 | - | |||||||||||||||||||||||||
1015 | - | |||||||||||||||||||||||||
1016 | if (!BN_sub(vrfy, vrfy, I)
| 0-2381 | ||||||||||||||||||||||||
1017 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
1018 | if (BN_is_zero(vrfy)
| 0-2381 | ||||||||||||||||||||||||
1019 | bn_correct_top(r0); | - | ||||||||||||||||||||||||
1020 | ret = 1; | - | ||||||||||||||||||||||||
1021 | goto executed 2381 times by 1 test: err;goto err; Executed by:
executed 2381 times by 1 test: goto err; Executed by:
| 2381 | ||||||||||||||||||||||||
1022 | } | - | ||||||||||||||||||||||||
1023 | if (!BN_div(
| 0 | ||||||||||||||||||||||||
1024 | ((void *)0)
| 0 | ||||||||||||||||||||||||
1025 | ,(vrfy),(vrfy),(rsa->n),(ctx))
| 0 | ||||||||||||||||||||||||
1026 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
1027 | if (BN_is_negative(vrfy)
| 0 | ||||||||||||||||||||||||
1028 | if (!BN_add(vrfy, vrfy, rsa->n)
| 0 | ||||||||||||||||||||||||
1029 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
1030 | if (!BN_is_zero(vrfy)
| 0 | ||||||||||||||||||||||||
1031 | - | |||||||||||||||||||||||||
1032 | - | |||||||||||||||||||||||||
1033 | - | |||||||||||||||||||||||||
1034 | - | |||||||||||||||||||||||||
1035 | - | |||||||||||||||||||||||||
1036 | - | |||||||||||||||||||||||||
1037 | BIGNUM *d = BN_new(); | - | ||||||||||||||||||||||||
1038 | if (d ==
| 0 | ||||||||||||||||||||||||
1039 | ((void *)0)
| 0 | ||||||||||||||||||||||||
1040 | ) | - | ||||||||||||||||||||||||
1041 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
1042 | BN_with_flags(d, rsa->d, 0x04); | - | ||||||||||||||||||||||||
1043 | - | |||||||||||||||||||||||||
1044 | if (!rsa->meth->bn_mod_exp(r0, I, d, rsa->n, ctx,
| 0 | ||||||||||||||||||||||||
1045 | rsa->_method_mod_n)
| 0 | ||||||||||||||||||||||||
1046 | BN_free(d); | - | ||||||||||||||||||||||||
1047 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
1048 | } | - | ||||||||||||||||||||||||
1049 | - | |||||||||||||||||||||||||
1050 | BN_free(d); | - | ||||||||||||||||||||||||
1051 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1052 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1053 | bn_correct_top(r0); | - | ||||||||||||||||||||||||
1054 | ret = 1; | - | ||||||||||||||||||||||||
1055 | err: code before this statement never executed: err: | 0 | ||||||||||||||||||||||||
1056 | BN_CTX_end(ctx); | - | ||||||||||||||||||||||||
1057 | return executed 2381 times by 1 test: ret;return ret; Executed by:
executed 2381 times by 1 test: return ret; Executed by:
| 2381 | ||||||||||||||||||||||||
1058 | } | - | ||||||||||||||||||||||||
1059 | - | |||||||||||||||||||||||||
1060 | static int rsa_ossl_init(RSA *rsa) | - | ||||||||||||||||||||||||
1061 | { | - | ||||||||||||||||||||||||
1062 | rsa->flags |= 0x0002 | 0x0004; | - | ||||||||||||||||||||||||
1063 | return executed 25970 times by 1 test: 1;return 1; Executed by:
executed 25970 times by 1 test: return 1; Executed by:
| 25970 | ||||||||||||||||||||||||
1064 | } | - | ||||||||||||||||||||||||
1065 | - | |||||||||||||||||||||||||
1066 | static int rsa_ossl_finish(RSA *rsa) | - | ||||||||||||||||||||||||
1067 | { | - | ||||||||||||||||||||||||
1068 | int i; | - | ||||||||||||||||||||||||
1069 | RSA_PRIME_INFO *pinfo; | - | ||||||||||||||||||||||||
1070 | - | |||||||||||||||||||||||||
1071 | BN_MONT_CTX_free(rsa->_method_mod_n); | - | ||||||||||||||||||||||||
1072 | BN_MONT_CTX_free(rsa->_method_mod_p); | - | ||||||||||||||||||||||||
1073 | BN_MONT_CTX_free(rsa->_method_mod_q); | - | ||||||||||||||||||||||||
1074 | for (i = 0; i < sk_RSA_PRIME_INFO_num(rsa->prime_infos)
| 8639-25970 | ||||||||||||||||||||||||
1075 | pinfo = sk_RSA_PRIME_INFO_value(rsa->prime_infos, i); | - | ||||||||||||||||||||||||
1076 | BN_MONT_CTX_free(pinfo->m); | - | ||||||||||||||||||||||||
1077 | } executed 8639 times by 1 test: end of block Executed by:
| 8639 | ||||||||||||||||||||||||
1078 | return executed 25970 times by 1 test: 1;return 1; Executed by:
executed 25970 times by 1 test: return 1; Executed by:
| 25970 | ||||||||||||||||||||||||
1079 | } | - | ||||||||||||||||||||||||
Switch to Source code | Preprocessed file |