Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/rsa/rsa_lib.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* | - | ||||||||||||||||||||||||
2 | * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. | - | ||||||||||||||||||||||||
3 | * | - | ||||||||||||||||||||||||
4 | * Licensed under the OpenSSL license (the "License"). You may not use | - | ||||||||||||||||||||||||
5 | * this file except in compliance with the License. You can obtain a copy | - | ||||||||||||||||||||||||
6 | * in the file LICENSE in the source distribution or at | - | ||||||||||||||||||||||||
7 | * https://www.openssl.org/source/license.html | - | ||||||||||||||||||||||||
8 | */ | - | ||||||||||||||||||||||||
9 | - | |||||||||||||||||||||||||
10 | #include <stdio.h> | - | ||||||||||||||||||||||||
11 | #include <openssl/crypto.h> | - | ||||||||||||||||||||||||
12 | #include "internal/cryptlib.h" | - | ||||||||||||||||||||||||
13 | #include "internal/refcount.h" | - | ||||||||||||||||||||||||
14 | #include "internal/bn_int.h" | - | ||||||||||||||||||||||||
15 | #include <openssl/engine.h> | - | ||||||||||||||||||||||||
16 | #include <openssl/evp.h> | - | ||||||||||||||||||||||||
17 | #include "internal/evp_int.h" | - | ||||||||||||||||||||||||
18 | #include "rsa_locl.h" | - | ||||||||||||||||||||||||
19 | - | |||||||||||||||||||||||||
20 | RSA *RSA_new(void) | - | ||||||||||||||||||||||||
21 | { | - | ||||||||||||||||||||||||
22 | return RSA_new_method(NULL); executed 25970 times by 1 test: return RSA_new_method( ((void *)0) ); Executed by:
| 25970 | ||||||||||||||||||||||||
23 | } | - | ||||||||||||||||||||||||
24 | - | |||||||||||||||||||||||||
25 | const RSA_METHOD *RSA_get_method(const RSA *rsa) | - | ||||||||||||||||||||||||
26 | { | - | ||||||||||||||||||||||||
27 | return rsa->meth; never executed: return rsa->meth; | 0 | ||||||||||||||||||||||||
28 | } | - | ||||||||||||||||||||||||
29 | - | |||||||||||||||||||||||||
30 | int RSA_set_method(RSA *rsa, const RSA_METHOD *meth) | - | ||||||||||||||||||||||||
31 | { | - | ||||||||||||||||||||||||
32 | /* | - | ||||||||||||||||||||||||
33 | * NB: The caller is specifically setting a method, so it's not up to us | - | ||||||||||||||||||||||||
34 | * to deal with which ENGINE it comes from. | - | ||||||||||||||||||||||||
35 | */ | - | ||||||||||||||||||||||||
36 | const RSA_METHOD *mtmp; | - | ||||||||||||||||||||||||
37 | mtmp = rsa->meth; | - | ||||||||||||||||||||||||
38 | if (mtmp->finish)
| 0 | ||||||||||||||||||||||||
39 | mtmp->finish(rsa); never executed: mtmp->finish(rsa); | 0 | ||||||||||||||||||||||||
40 | #ifndef OPENSSL_NO_ENGINE | - | ||||||||||||||||||||||||
41 | ENGINE_finish(rsa->engine); | - | ||||||||||||||||||||||||
42 | rsa->engine = NULL; | - | ||||||||||||||||||||||||
43 | #endif | - | ||||||||||||||||||||||||
44 | rsa->meth = meth; | - | ||||||||||||||||||||||||
45 | if (meth->init)
| 0 | ||||||||||||||||||||||||
46 | meth->init(rsa); never executed: meth->init(rsa); | 0 | ||||||||||||||||||||||||
47 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||
48 | } | - | ||||||||||||||||||||||||
49 | - | |||||||||||||||||||||||||
50 | RSA *RSA_new_method(ENGINE *engine) | - | ||||||||||||||||||||||||
51 | { | - | ||||||||||||||||||||||||
52 | RSA *ret = OPENSSL_zalloc(sizeof(*ret)); | - | ||||||||||||||||||||||||
53 | - | |||||||||||||||||||||||||
54 | if (ret == NULL) {
| 0-25970 | ||||||||||||||||||||||||
55 | RSAerr(RSA_F_RSA_NEW_METHOD, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
56 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
57 | } | - | ||||||||||||||||||||||||
58 | - | |||||||||||||||||||||||||
59 | ret->references = 1; | - | ||||||||||||||||||||||||
60 | ret->lock = CRYPTO_THREAD_lock_new(); | - | ||||||||||||||||||||||||
61 | if (ret->lock == NULL) {
| 0-25970 | ||||||||||||||||||||||||
62 | RSAerr(RSA_F_RSA_NEW_METHOD, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
63 | OPENSSL_free(ret); | - | ||||||||||||||||||||||||
64 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
65 | } | - | ||||||||||||||||||||||||
66 | - | |||||||||||||||||||||||||
67 | ret->meth = RSA_get_default_method(); | - | ||||||||||||||||||||||||
68 | #ifndef OPENSSL_NO_ENGINE | - | ||||||||||||||||||||||||
69 | ret->flags = ret->meth->flags & ~RSA_FLAG_NON_FIPS_ALLOW; | - | ||||||||||||||||||||||||
70 | if (engine) {
| 0-25970 | ||||||||||||||||||||||||
71 | if (!ENGINE_init(engine)) {
| 0 | ||||||||||||||||||||||||
72 | RSAerr(RSA_F_RSA_NEW_METHOD, ERR_R_ENGINE_LIB); | - | ||||||||||||||||||||||||
73 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
74 | } | - | ||||||||||||||||||||||||
75 | ret->engine = engine; | - | ||||||||||||||||||||||||
76 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
77 | ret->engine = ENGINE_get_default_RSA(); | - | ||||||||||||||||||||||||
78 | } executed 25970 times by 1 test: end of block Executed by:
| 25970 | ||||||||||||||||||||||||
79 | if (ret->engine) {
| 0-25970 | ||||||||||||||||||||||||
80 | ret->meth = ENGINE_get_RSA(ret->engine); | - | ||||||||||||||||||||||||
81 | if (ret->meth == NULL) {
| 0 | ||||||||||||||||||||||||
82 | RSAerr(RSA_F_RSA_NEW_METHOD, ERR_R_ENGINE_LIB); | - | ||||||||||||||||||||||||
83 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
84 | } | - | ||||||||||||||||||||||||
85 | } never executed: end of block | 0 | ||||||||||||||||||||||||
86 | #endif | - | ||||||||||||||||||||||||
87 | - | |||||||||||||||||||||||||
88 | ret->flags = ret->meth->flags & ~RSA_FLAG_NON_FIPS_ALLOW; | - | ||||||||||||||||||||||||
89 | if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data)) {
| 0-25970 | ||||||||||||||||||||||||
90 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
91 | } | - | ||||||||||||||||||||||||
92 | - | |||||||||||||||||||||||||
93 | if ((ret->meth->init != NULL) && !ret->meth->init(ret)) {
| 0-25970 | ||||||||||||||||||||||||
94 | RSAerr(RSA_F_RSA_NEW_METHOD, ERR_R_INIT_FAIL); | - | ||||||||||||||||||||||||
95 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
96 | } | - | ||||||||||||||||||||||||
97 | - | |||||||||||||||||||||||||
98 | return ret; executed 25970 times by 1 test: return ret; Executed by:
| 25970 | ||||||||||||||||||||||||
99 | - | |||||||||||||||||||||||||
100 | err: | - | ||||||||||||||||||||||||
101 | RSA_free(ret); | - | ||||||||||||||||||||||||
102 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
103 | } | - | ||||||||||||||||||||||||
104 | - | |||||||||||||||||||||||||
105 | void RSA_free(RSA *r) | - | ||||||||||||||||||||||||
106 | { | - | ||||||||||||||||||||||||
107 | int i; | - | ||||||||||||||||||||||||
108 | - | |||||||||||||||||||||||||
109 | if (r == NULL)
| 2741-26039 | ||||||||||||||||||||||||
110 | return; executed 2741 times by 1 test: return; Executed by:
| 2741 | ||||||||||||||||||||||||
111 | - | |||||||||||||||||||||||||
112 | CRYPTO_DOWN_REF(&r->references, &i, r->lock); | - | ||||||||||||||||||||||||
113 | REF_PRINT_COUNT("RSA", r); | - | ||||||||||||||||||||||||
114 | if (i > 0)
| 69-25970 | ||||||||||||||||||||||||
115 | return; executed 69 times by 1 test: return; Executed by:
| 69 | ||||||||||||||||||||||||
116 | REF_ASSERT_ISNT(i < 0); | - | ||||||||||||||||||||||||
117 | - | |||||||||||||||||||||||||
118 | if (r->meth != NULL && r->meth->finish != NULL)
| 0-25970 | ||||||||||||||||||||||||
119 | r->meth->finish(r); executed 25970 times by 1 test: r->meth->finish(r); Executed by:
| 25970 | ||||||||||||||||||||||||
120 | #ifndef OPENSSL_NO_ENGINE | - | ||||||||||||||||||||||||
121 | ENGINE_finish(r->engine); | - | ||||||||||||||||||||||||
122 | #endif | - | ||||||||||||||||||||||||
123 | - | |||||||||||||||||||||||||
124 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, r, &r->ex_data); | - | ||||||||||||||||||||||||
125 | - | |||||||||||||||||||||||||
126 | CRYPTO_THREAD_lock_free(r->lock); | - | ||||||||||||||||||||||||
127 | - | |||||||||||||||||||||||||
128 | BN_clear_free(r->n); | - | ||||||||||||||||||||||||
129 | BN_clear_free(r->e); | - | ||||||||||||||||||||||||
130 | BN_clear_free(r->d); | - | ||||||||||||||||||||||||
131 | BN_clear_free(r->p); | - | ||||||||||||||||||||||||
132 | BN_clear_free(r->q); | - | ||||||||||||||||||||||||
133 | BN_clear_free(r->dmp1); | - | ||||||||||||||||||||||||
134 | BN_clear_free(r->dmq1); | - | ||||||||||||||||||||||||
135 | BN_clear_free(r->iqmp); | - | ||||||||||||||||||||||||
136 | RSA_PSS_PARAMS_free(r->pss); | - | ||||||||||||||||||||||||
137 | sk_RSA_PRIME_INFO_pop_free(r->prime_infos, rsa_multip_info_free); | - | ||||||||||||||||||||||||
138 | BN_BLINDING_free(r->blinding); | - | ||||||||||||||||||||||||
139 | BN_BLINDING_free(r->mt_blinding); | - | ||||||||||||||||||||||||
140 | OPENSSL_free(r->bignum_data); | - | ||||||||||||||||||||||||
141 | OPENSSL_free(r); | - | ||||||||||||||||||||||||
142 | } executed 25970 times by 1 test: end of block Executed by:
| 25970 | ||||||||||||||||||||||||
143 | - | |||||||||||||||||||||||||
144 | int RSA_up_ref(RSA *r) | - | ||||||||||||||||||||||||
145 | { | - | ||||||||||||||||||||||||
146 | int i; | - | ||||||||||||||||||||||||
147 | - | |||||||||||||||||||||||||
148 | if (CRYPTO_UP_REF(&r->references, &i, r->lock) <= 0)
| 0-69 | ||||||||||||||||||||||||
149 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
150 | - | |||||||||||||||||||||||||
151 | REF_PRINT_COUNT("RSA", r); | - | ||||||||||||||||||||||||
152 | REF_ASSERT_ISNT(i < 2); | - | ||||||||||||||||||||||||
153 | return i > 1 ? 1 : 0; executed 69 times by 1 test: return i > 1 ? 1 : 0; Executed by:
| 0-69 | ||||||||||||||||||||||||
154 | } | - | ||||||||||||||||||||||||
155 | - | |||||||||||||||||||||||||
156 | int RSA_set_ex_data(RSA *r, int idx, void *arg) | - | ||||||||||||||||||||||||
157 | { | - | ||||||||||||||||||||||||
158 | return CRYPTO_set_ex_data(&r->ex_data, idx, arg); never executed: return CRYPTO_set_ex_data(&r->ex_data, idx, arg); | 0 | ||||||||||||||||||||||||
159 | } | - | ||||||||||||||||||||||||
160 | - | |||||||||||||||||||||||||
161 | void *RSA_get_ex_data(const RSA *r, int idx) | - | ||||||||||||||||||||||||
162 | { | - | ||||||||||||||||||||||||
163 | return CRYPTO_get_ex_data(&r->ex_data, idx); never executed: return CRYPTO_get_ex_data(&r->ex_data, idx); | 0 | ||||||||||||||||||||||||
164 | } | - | ||||||||||||||||||||||||
165 | - | |||||||||||||||||||||||||
166 | int RSA_security_bits(const RSA *rsa) | - | ||||||||||||||||||||||||
167 | { | - | ||||||||||||||||||||||||
168 | int bits = BN_num_bits(rsa->n); | - | ||||||||||||||||||||||||
169 | - | |||||||||||||||||||||||||
170 | if (rsa->version == RSA_ASN1_VERSION_MULTI) {
| 0-8547 | ||||||||||||||||||||||||
171 | /* This ought to mean that we have private key at hand. */ | - | ||||||||||||||||||||||||
172 | int ex_primes = sk_RSA_PRIME_INFO_num(rsa->prime_infos); | - | ||||||||||||||||||||||||
173 | - | |||||||||||||||||||||||||
174 | if (ex_primes <= 0 || (ex_primes + 2) > rsa_multip_cap(bits))
| 0 | ||||||||||||||||||||||||
175 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
176 | } never executed: end of block | 0 | ||||||||||||||||||||||||
177 | return BN_security_bits(bits, -1); executed 8547 times by 1 test: return BN_security_bits(bits, -1); Executed by:
| 8547 | ||||||||||||||||||||||||
178 | } | - | ||||||||||||||||||||||||
179 | - | |||||||||||||||||||||||||
180 | int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d) | - | ||||||||||||||||||||||||
181 | { | - | ||||||||||||||||||||||||
182 | /* If the fields n and e in r are NULL, the corresponding input | - | ||||||||||||||||||||||||
183 | * parameters MUST be non-NULL for n and e. d may be | - | ||||||||||||||||||||||||
184 | * left NULL (in case only the public key is used). | - | ||||||||||||||||||||||||
185 | */ | - | ||||||||||||||||||||||||
186 | if ((r->n == NULL && n == NULL)
| 0-11 | ||||||||||||||||||||||||
187 | || (r->e == NULL && e == NULL))
| 0-11 | ||||||||||||||||||||||||
188 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
189 | - | |||||||||||||||||||||||||
190 | if (n != NULL) {
| 0-11 | ||||||||||||||||||||||||
191 | BN_free(r->n); | - | ||||||||||||||||||||||||
192 | r->n = n; | - | ||||||||||||||||||||||||
193 | } executed 11 times by 1 test: end of block Executed by:
| 11 | ||||||||||||||||||||||||
194 | if (e != NULL) {
| 0-11 | ||||||||||||||||||||||||
195 | BN_free(r->e); | - | ||||||||||||||||||||||||
196 | r->e = e; | - | ||||||||||||||||||||||||
197 | } executed 11 times by 1 test: end of block Executed by:
| 11 | ||||||||||||||||||||||||
198 | if (d != NULL) {
| 4-7 | ||||||||||||||||||||||||
199 | BN_free(r->d); | - | ||||||||||||||||||||||||
200 | r->d = d; | - | ||||||||||||||||||||||||
201 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||||||||||||||
202 | - | |||||||||||||||||||||||||
203 | return 1; executed 11 times by 1 test: return 1; Executed by:
| 11 | ||||||||||||||||||||||||
204 | } | - | ||||||||||||||||||||||||
205 | - | |||||||||||||||||||||||||
206 | int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q) | - | ||||||||||||||||||||||||
207 | { | - | ||||||||||||||||||||||||
208 | /* If the fields p and q in r are NULL, the corresponding input | - | ||||||||||||||||||||||||
209 | * parameters MUST be non-NULL. | - | ||||||||||||||||||||||||
210 | */ | - | ||||||||||||||||||||||||
211 | if ((r->p == NULL && p == NULL)
| 0-7 | ||||||||||||||||||||||||
212 | || (r->q == NULL && q == NULL))
| 0-7 | ||||||||||||||||||||||||
213 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
214 | - | |||||||||||||||||||||||||
215 | if (p != NULL) {
| 0-7 | ||||||||||||||||||||||||
216 | BN_free(r->p); | - | ||||||||||||||||||||||||
217 | r->p = p; | - | ||||||||||||||||||||||||
218 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||||||||||||||
219 | if (q != NULL) {
| 0-7 | ||||||||||||||||||||||||
220 | BN_free(r->q); | - | ||||||||||||||||||||||||
221 | r->q = q; | - | ||||||||||||||||||||||||
222 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||||||||||||||
223 | - | |||||||||||||||||||||||||
224 | return 1; executed 7 times by 1 test: return 1; Executed by:
| 7 | ||||||||||||||||||||||||
225 | } | - | ||||||||||||||||||||||||
226 | - | |||||||||||||||||||||||||
227 | int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp) | - | ||||||||||||||||||||||||
228 | { | - | ||||||||||||||||||||||||
229 | /* If the fields dmp1, dmq1 and iqmp in r are NULL, the corresponding input | - | ||||||||||||||||||||||||
230 | * parameters MUST be non-NULL. | - | ||||||||||||||||||||||||
231 | */ | - | ||||||||||||||||||||||||
232 | if ((r->dmp1 == NULL && dmp1 == NULL)
| 0-7 | ||||||||||||||||||||||||
233 | || (r->dmq1 == NULL && dmq1 == NULL)
| 0-7 | ||||||||||||||||||||||||
234 | || (r->iqmp == NULL && iqmp == NULL))
| 0-7 | ||||||||||||||||||||||||
235 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
236 | - | |||||||||||||||||||||||||
237 | if (dmp1 != NULL) {
| 0-7 | ||||||||||||||||||||||||
238 | BN_free(r->dmp1); | - | ||||||||||||||||||||||||
239 | r->dmp1 = dmp1; | - | ||||||||||||||||||||||||
240 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||||||||||||||
241 | if (dmq1 != NULL) {
| 0-7 | ||||||||||||||||||||||||
242 | BN_free(r->dmq1); | - | ||||||||||||||||||||||||
243 | r->dmq1 = dmq1; | - | ||||||||||||||||||||||||
244 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||||||||||||||
245 | if (iqmp != NULL) {
| 0-7 | ||||||||||||||||||||||||
246 | BN_free(r->iqmp); | - | ||||||||||||||||||||||||
247 | r->iqmp = iqmp; | - | ||||||||||||||||||||||||
248 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||||||||||||||
249 | - | |||||||||||||||||||||||||
250 | return 1; executed 7 times by 1 test: return 1; Executed by:
| 7 | ||||||||||||||||||||||||
251 | } | - | ||||||||||||||||||||||||
252 | - | |||||||||||||||||||||||||
253 | /* | - | ||||||||||||||||||||||||
254 | * Is it better to export RSA_PRIME_INFO structure | - | ||||||||||||||||||||||||
255 | * and related functions to let user pass a triplet? | - | ||||||||||||||||||||||||
256 | */ | - | ||||||||||||||||||||||||
257 | int RSA_set0_multi_prime_params(RSA *r, BIGNUM *primes[], BIGNUM *exps[], | - | ||||||||||||||||||||||||
258 | BIGNUM *coeffs[], int pnum) | - | ||||||||||||||||||||||||
259 | { | - | ||||||||||||||||||||||||
260 | STACK_OF(RSA_PRIME_INFO) *prime_infos, *old = NULL; | - | ||||||||||||||||||||||||
261 | RSA_PRIME_INFO *pinfo; | - | ||||||||||||||||||||||||
262 | int i; | - | ||||||||||||||||||||||||
263 | - | |||||||||||||||||||||||||
264 | if (primes == NULL || exps == NULL || coeffs == NULL || pnum == 0)
| 0-1 | ||||||||||||||||||||||||
265 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
266 | - | |||||||||||||||||||||||||
267 | prime_infos = sk_RSA_PRIME_INFO_new_reserve(NULL, pnum); | - | ||||||||||||||||||||||||
268 | if (prime_infos == NULL)
| 0-1 | ||||||||||||||||||||||||
269 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
270 | - | |||||||||||||||||||||||||
271 | if (r->prime_infos != NULL)
| 0-1 | ||||||||||||||||||||||||
272 | old = r->prime_infos; never executed: old = r->prime_infos; | 0 | ||||||||||||||||||||||||
273 | - | |||||||||||||||||||||||||
274 | for (i = 0; i < pnum; i++) {
| 1 | ||||||||||||||||||||||||
275 | pinfo = rsa_multip_info_new(); | - | ||||||||||||||||||||||||
276 | if (pinfo == NULL)
| 0-1 | ||||||||||||||||||||||||
277 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
278 | if (primes[i] != NULL && exps[i] != NULL && coeffs[i] != NULL) {
| 0-1 | ||||||||||||||||||||||||
279 | BN_free(pinfo->r); | - | ||||||||||||||||||||||||
280 | BN_free(pinfo->d); | - | ||||||||||||||||||||||||
281 | BN_free(pinfo->t); | - | ||||||||||||||||||||||||
282 | pinfo->r = primes[i]; | - | ||||||||||||||||||||||||
283 | pinfo->d = exps[i]; | - | ||||||||||||||||||||||||
284 | pinfo->t = coeffs[i]; | - | ||||||||||||||||||||||||
285 | } else { executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||||||||
286 | rsa_multip_info_free(pinfo); | - | ||||||||||||||||||||||||
287 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
288 | } | - | ||||||||||||||||||||||||
289 | (void)sk_RSA_PRIME_INFO_push(prime_infos, pinfo); | - | ||||||||||||||||||||||||
290 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||||||||
291 | - | |||||||||||||||||||||||||
292 | r->prime_infos = prime_infos; | - | ||||||||||||||||||||||||
293 | - | |||||||||||||||||||||||||
294 | if (!rsa_multip_calc_product(r)) {
| 0-1 | ||||||||||||||||||||||||
295 | r->prime_infos = old; | - | ||||||||||||||||||||||||
296 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
297 | } | - | ||||||||||||||||||||||||
298 | - | |||||||||||||||||||||||||
299 | if (old != NULL) {
| 0-1 | ||||||||||||||||||||||||
300 | /* | - | ||||||||||||||||||||||||
301 | * This is hard to deal with, since the old infos could | - | ||||||||||||||||||||||||
302 | * also be set by this function and r, d, t should not | - | ||||||||||||||||||||||||
303 | * be freed in that case. So currently, stay consistent | - | ||||||||||||||||||||||||
304 | * with other *set0* functions: just free it... | - | ||||||||||||||||||||||||
305 | */ | - | ||||||||||||||||||||||||
306 | sk_RSA_PRIME_INFO_pop_free(old, rsa_multip_info_free); | - | ||||||||||||||||||||||||
307 | } never executed: end of block | 0 | ||||||||||||||||||||||||
308 | - | |||||||||||||||||||||||||
309 | r->version = RSA_ASN1_VERSION_MULTI; | - | ||||||||||||||||||||||||
310 | - | |||||||||||||||||||||||||
311 | return 1; executed 1 time by 1 test: return 1; Executed by:
| 1 | ||||||||||||||||||||||||
312 | err: | - | ||||||||||||||||||||||||
313 | /* r, d, t should not be freed */ | - | ||||||||||||||||||||||||
314 | sk_RSA_PRIME_INFO_pop_free(prime_infos, rsa_multip_info_free_ex); | - | ||||||||||||||||||||||||
315 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
316 | } | - | ||||||||||||||||||||||||
317 | - | |||||||||||||||||||||||||
318 | void RSA_get0_key(const RSA *r, | - | ||||||||||||||||||||||||
319 | const BIGNUM **n, const BIGNUM **e, const BIGNUM **d) | - | ||||||||||||||||||||||||
320 | { | - | ||||||||||||||||||||||||
321 | if (n != NULL)
| 4-10 | ||||||||||||||||||||||||
322 | *n = r->n; executed 4 times by 1 test: *n = r->n; Executed by:
| 4 | ||||||||||||||||||||||||
323 | if (e != NULL)
| 0-14 | ||||||||||||||||||||||||
324 | *e = r->e; executed 14 times by 1 test: *e = r->e; Executed by:
| 14 | ||||||||||||||||||||||||
325 | if (d != NULL)
| 4-10 | ||||||||||||||||||||||||
326 | *d = r->d; executed 4 times by 1 test: *d = r->d; Executed by:
| 4 | ||||||||||||||||||||||||
327 | } executed 14 times by 1 test: end of block Executed by:
| 14 | ||||||||||||||||||||||||
328 | - | |||||||||||||||||||||||||
329 | void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q) | - | ||||||||||||||||||||||||
330 | { | - | ||||||||||||||||||||||||
331 | if (p != NULL)
| 0 | ||||||||||||||||||||||||
332 | *p = r->p; never executed: *p = r->p; | 0 | ||||||||||||||||||||||||
333 | if (q != NULL)
| 0 | ||||||||||||||||||||||||
334 | *q = r->q; never executed: *q = r->q; | 0 | ||||||||||||||||||||||||
335 | } never executed: end of block | 0 | ||||||||||||||||||||||||
336 | - | |||||||||||||||||||||||||
337 | int RSA_get_multi_prime_extra_count(const RSA *r) | - | ||||||||||||||||||||||||
338 | { | - | ||||||||||||||||||||||||
339 | int pnum; | - | ||||||||||||||||||||||||
340 | - | |||||||||||||||||||||||||
341 | pnum = sk_RSA_PRIME_INFO_num(r->prime_infos); | - | ||||||||||||||||||||||||
342 | if (pnum <= 0)
| 0 | ||||||||||||||||||||||||
343 | pnum = 0; never executed: pnum = 0; | 0 | ||||||||||||||||||||||||
344 | return pnum; never executed: return pnum; | 0 | ||||||||||||||||||||||||
345 | } | - | ||||||||||||||||||||||||
346 | - | |||||||||||||||||||||||||
347 | int RSA_get0_multi_prime_factors(const RSA *r, const BIGNUM *primes[]) | - | ||||||||||||||||||||||||
348 | { | - | ||||||||||||||||||||||||
349 | int pnum, i; | - | ||||||||||||||||||||||||
350 | RSA_PRIME_INFO *pinfo; | - | ||||||||||||||||||||||||
351 | - | |||||||||||||||||||||||||
352 | if ((pnum = RSA_get_multi_prime_extra_count(r)) == 0)
| 0 | ||||||||||||||||||||||||
353 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
354 | - | |||||||||||||||||||||||||
355 | /* | - | ||||||||||||||||||||||||
356 | * return other primes | - | ||||||||||||||||||||||||
357 | * it's caller's responsibility to allocate oth_primes[pnum] | - | ||||||||||||||||||||||||
358 | */ | - | ||||||||||||||||||||||||
359 | for (i = 0; i < pnum; i++) {
| 0 | ||||||||||||||||||||||||
360 | pinfo = sk_RSA_PRIME_INFO_value(r->prime_infos, i); | - | ||||||||||||||||||||||||
361 | primes[i] = pinfo->r; | - | ||||||||||||||||||||||||
362 | } never executed: end of block | 0 | ||||||||||||||||||||||||
363 | - | |||||||||||||||||||||||||
364 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||
365 | } | - | ||||||||||||||||||||||||
366 | - | |||||||||||||||||||||||||
367 | void RSA_get0_crt_params(const RSA *r, | - | ||||||||||||||||||||||||
368 | const BIGNUM **dmp1, const BIGNUM **dmq1, | - | ||||||||||||||||||||||||
369 | const BIGNUM **iqmp) | - | ||||||||||||||||||||||||
370 | { | - | ||||||||||||||||||||||||
371 | if (dmp1 != NULL)
| 0 | ||||||||||||||||||||||||
372 | *dmp1 = r->dmp1; never executed: *dmp1 = r->dmp1; | 0 | ||||||||||||||||||||||||
373 | if (dmq1 != NULL)
| 0 | ||||||||||||||||||||||||
374 | *dmq1 = r->dmq1; never executed: *dmq1 = r->dmq1; | 0 | ||||||||||||||||||||||||
375 | if (iqmp != NULL)
| 0 | ||||||||||||||||||||||||
376 | *iqmp = r->iqmp; never executed: *iqmp = r->iqmp; | 0 | ||||||||||||||||||||||||
377 | } never executed: end of block | 0 | ||||||||||||||||||||||||
378 | - | |||||||||||||||||||||||||
379 | int RSA_get0_multi_prime_crt_params(const RSA *r, const BIGNUM *exps[], | - | ||||||||||||||||||||||||
380 | const BIGNUM *coeffs[]) | - | ||||||||||||||||||||||||
381 | { | - | ||||||||||||||||||||||||
382 | int pnum; | - | ||||||||||||||||||||||||
383 | - | |||||||||||||||||||||||||
384 | if ((pnum = RSA_get_multi_prime_extra_count(r)) == 0)
| 0 | ||||||||||||||||||||||||
385 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
386 | - | |||||||||||||||||||||||||
387 | /* return other primes */ | - | ||||||||||||||||||||||||
388 | if (exps != NULL || coeffs != NULL) {
| 0 | ||||||||||||||||||||||||
389 | RSA_PRIME_INFO *pinfo; | - | ||||||||||||||||||||||||
390 | int i; | - | ||||||||||||||||||||||||
391 | - | |||||||||||||||||||||||||
392 | /* it's the user's job to guarantee the buffer length */ | - | ||||||||||||||||||||||||
393 | for (i = 0; i < pnum; i++) {
| 0 | ||||||||||||||||||||||||
394 | pinfo = sk_RSA_PRIME_INFO_value(r->prime_infos, i); | - | ||||||||||||||||||||||||
395 | if (exps != NULL)
| 0 | ||||||||||||||||||||||||
396 | exps[i] = pinfo->d; never executed: exps[i] = pinfo->d; | 0 | ||||||||||||||||||||||||
397 | if (coeffs != NULL)
| 0 | ||||||||||||||||||||||||
398 | coeffs[i] = pinfo->t; never executed: coeffs[i] = pinfo->t; | 0 | ||||||||||||||||||||||||
399 | } never executed: end of block | 0 | ||||||||||||||||||||||||
400 | } never executed: end of block | 0 | ||||||||||||||||||||||||
401 | - | |||||||||||||||||||||||||
402 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||
403 | } | - | ||||||||||||||||||||||||
404 | - | |||||||||||||||||||||||||
405 | const BIGNUM *RSA_get0_n(const RSA *r) | - | ||||||||||||||||||||||||
406 | { | - | ||||||||||||||||||||||||
407 | return r->n; never executed: return r->n; | 0 | ||||||||||||||||||||||||
408 | } | - | ||||||||||||||||||||||||
409 | - | |||||||||||||||||||||||||
410 | const BIGNUM *RSA_get0_e(const RSA *r) | - | ||||||||||||||||||||||||
411 | { | - | ||||||||||||||||||||||||
412 | return r->e; never executed: return r->e; | 0 | ||||||||||||||||||||||||
413 | } | - | ||||||||||||||||||||||||
414 | - | |||||||||||||||||||||||||
415 | const BIGNUM *RSA_get0_d(const RSA *r) | - | ||||||||||||||||||||||||
416 | { | - | ||||||||||||||||||||||||
417 | return r->d; never executed: return r->d; | 0 | ||||||||||||||||||||||||
418 | } | - | ||||||||||||||||||||||||
419 | - | |||||||||||||||||||||||||
420 | const BIGNUM *RSA_get0_p(const RSA *r) | - | ||||||||||||||||||||||||
421 | { | - | ||||||||||||||||||||||||
422 | return r->p; never executed: return r->p; | 0 | ||||||||||||||||||||||||
423 | } | - | ||||||||||||||||||||||||
424 | - | |||||||||||||||||||||||||
425 | const BIGNUM *RSA_get0_q(const RSA *r) | - | ||||||||||||||||||||||||
426 | { | - | ||||||||||||||||||||||||
427 | return r->q; never executed: return r->q; | 0 | ||||||||||||||||||||||||
428 | } | - | ||||||||||||||||||||||||
429 | - | |||||||||||||||||||||||||
430 | const BIGNUM *RSA_get0_dmp1(const RSA *r) | - | ||||||||||||||||||||||||
431 | { | - | ||||||||||||||||||||||||
432 | return r->dmp1; never executed: return r->dmp1; | 0 | ||||||||||||||||||||||||
433 | } | - | ||||||||||||||||||||||||
434 | - | |||||||||||||||||||||||||
435 | const BIGNUM *RSA_get0_dmq1(const RSA *r) | - | ||||||||||||||||||||||||
436 | { | - | ||||||||||||||||||||||||
437 | return r->dmq1; never executed: return r->dmq1; | 0 | ||||||||||||||||||||||||
438 | } | - | ||||||||||||||||||||||||
439 | - | |||||||||||||||||||||||||
440 | const BIGNUM *RSA_get0_iqmp(const RSA *r) | - | ||||||||||||||||||||||||
441 | { | - | ||||||||||||||||||||||||
442 | return r->iqmp; never executed: return r->iqmp; | 0 | ||||||||||||||||||||||||
443 | } | - | ||||||||||||||||||||||||
444 | - | |||||||||||||||||||||||||
445 | void RSA_clear_flags(RSA *r, int flags) | - | ||||||||||||||||||||||||
446 | { | - | ||||||||||||||||||||||||
447 | r->flags &= ~flags; | - | ||||||||||||||||||||||||
448 | } never executed: end of block | 0 | ||||||||||||||||||||||||
449 | - | |||||||||||||||||||||||||
450 | int RSA_test_flags(const RSA *r, int flags) | - | ||||||||||||||||||||||||
451 | { | - | ||||||||||||||||||||||||
452 | return r->flags & flags; never executed: return r->flags & flags; | 0 | ||||||||||||||||||||||||
453 | } | - | ||||||||||||||||||||||||
454 | - | |||||||||||||||||||||||||
455 | void RSA_set_flags(RSA *r, int flags) | - | ||||||||||||||||||||||||
456 | { | - | ||||||||||||||||||||||||
457 | r->flags |= flags; | - | ||||||||||||||||||||||||
458 | } never executed: end of block | 0 | ||||||||||||||||||||||||
459 | - | |||||||||||||||||||||||||
460 | int RSA_get_version(RSA *r) | - | ||||||||||||||||||||||||
461 | { | - | ||||||||||||||||||||||||
462 | /* { two-prime(0), multi(1) } */ | - | ||||||||||||||||||||||||
463 | return r->version; never executed: return r->version; | 0 | ||||||||||||||||||||||||
464 | } | - | ||||||||||||||||||||||||
465 | - | |||||||||||||||||||||||||
466 | ENGINE *RSA_get0_engine(const RSA *r) | - | ||||||||||||||||||||||||
467 | { | - | ||||||||||||||||||||||||
468 | return r->engine; never executed: return r->engine; | 0 | ||||||||||||||||||||||||
469 | } | - | ||||||||||||||||||||||||
470 | - | |||||||||||||||||||||||||
471 | int RSA_pkey_ctx_ctrl(EVP_PKEY_CTX *ctx, int optype, int cmd, int p1, void *p2) | - | ||||||||||||||||||||||||
472 | { | - | ||||||||||||||||||||||||
473 | /* If key type not RSA or RSA-PSS return error */ | - | ||||||||||||||||||||||||
474 | if (ctx != NULL && ctx->pmeth != NULL
| 0-4268 | ||||||||||||||||||||||||
475 | && ctx->pmeth->pkey_id != EVP_PKEY_RSA
| 20-4248 | ||||||||||||||||||||||||
476 | && ctx->pmeth->pkey_id != EVP_PKEY_RSA_PSS)
| 0-20 | ||||||||||||||||||||||||
477 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
478 | return EVP_PKEY_CTX_ctrl(ctx, -1, optype, cmd, p1, p2); executed 4268 times by 1 test: return EVP_PKEY_CTX_ctrl(ctx, -1, optype, cmd, p1, p2); Executed by:
| 4268 | ||||||||||||||||||||||||
479 | } | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |