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