rsa.c
Go to the documentation of this file.
1 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
2  * All rights reserved.
3  *
4  * This package is an SSL implementation written
5  * by Eric Young (eay@cryptsoft.com).
6  * The implementation was written so as to conform with Netscapes SSL.
7  *
8  * This library is free for commercial and non-commercial use as long as
9  * the following conditions are aheared to. The following conditions
10  * apply to all code found in this distribution, be it the RC4, RSA,
11  * lhash, DES, etc., code; not just the SSL code. The SSL documentation
12  * included with this distribution is covered by the same copyright terms
13  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
14  *
15  * Copyright remains Eric Young's, and as such any Copyright notices in
16  * the code are not to be removed.
17  * If this package is used in a product, Eric Young should be given attribution
18  * as the author of the parts of the library used.
19  * This can be in the form of a textual message at program startup or
20  * in documentation (online or textual) provided with the package.
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions
24  * are met:
25  * 1. Redistributions of source code must retain the copyright
26  * notice, this list of conditions and the following disclaimer.
27  * 2. Redistributions in binary form must reproduce the above copyright
28  * notice, this list of conditions and the following disclaimer in the
29  * documentation and/or other materials provided with the distribution.
30  * 3. All advertising materials mentioning features or use of this software
31  * must display the following acknowledgement:
32  * "This product includes cryptographic software written by
33  * Eric Young (eay@cryptsoft.com)"
34  * The word 'cryptographic' can be left out if the rouines from the library
35  * being used are not cryptographic related :-).
36  * 4. If you include any Windows specific code (or a derivative thereof) from
37  * the apps directory (application code) you must include an acknowledgement:
38  * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
39  *
40  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
41  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50  * SUCH DAMAGE.
51  *
52  * The licence and distribution terms for any publically available version or
53  * derivative of this code cannot be changed. i.e. this code cannot simply be
54  * copied and put under another distribution licence
55  * [including the GNU Public Licence.] */
56 
57 #include <openssl/rsa.h>
58 
59 #include <limits.h>
60 #include <string.h>
61 
62 #include <openssl/bn.h>
63 #include <openssl/digest.h>
64 #include <openssl/engine.h>
65 #include <openssl/err.h>
66 #include <openssl/ex_data.h>
67 #include <openssl/md5.h>
68 #include <openssl/mem.h>
69 #include <openssl/nid.h>
70 #include <openssl/sha.h>
71 #include <openssl/thread.h>
72 
73 #include "../bn/internal.h"
74 #include "../delocate.h"
75 #include "../../internal.h"
76 #include "internal.h"
77 
78 
79 // RSA_R_BLOCK_TYPE_IS_NOT_02 is part of the legacy SSLv23 padding scheme.
80 // Cryptography.io depends on this error code.
81 OPENSSL_DECLARE_ERROR_REASON(RSA, BLOCK_TYPE_IS_NOT_02)
82 
83 DEFINE_STATIC_EX_DATA_CLASS(g_rsa_ex_data_class)
84 
85 RSA *RSA_new(void) { return RSA_new_method(NULL); }
86 
87 RSA *RSA_new_method(const ENGINE *engine) {
88  RSA *rsa = OPENSSL_malloc(sizeof(RSA));
89  if (rsa == NULL) {
91  return NULL;
92  }
93 
94  OPENSSL_memset(rsa, 0, sizeof(RSA));
95 
96  if (engine) {
97  rsa->meth = ENGINE_get_RSA_method(engine);
98  }
99 
100  if (rsa->meth == NULL) {
101  rsa->meth = (RSA_METHOD *) RSA_default_method();
102  }
103  METHOD_ref(rsa->meth);
104 
105  rsa->references = 1;
106  rsa->flags = rsa->meth->flags;
107  CRYPTO_MUTEX_init(&rsa->lock);
109 
110  if (rsa->meth->init && !rsa->meth->init(rsa)) {
111  CRYPTO_free_ex_data(g_rsa_ex_data_class_bss_get(), rsa, &rsa->ex_data);
112  CRYPTO_MUTEX_cleanup(&rsa->lock);
113  METHOD_unref(rsa->meth);
114  OPENSSL_free(rsa);
115  return NULL;
116  }
117 
118  return rsa;
119 }
120 
121 void RSA_free(RSA *rsa) {
122  unsigned u;
123 
124  if (rsa == NULL) {
125  return;
126  }
127 
129  return;
130  }
131 
132  if (rsa->meth->finish) {
133  rsa->meth->finish(rsa);
134  }
135  METHOD_unref(rsa->meth);
136 
137  CRYPTO_free_ex_data(g_rsa_ex_data_class_bss_get(), rsa, &rsa->ex_data);
138 
139  BN_free(rsa->n);
140  BN_free(rsa->e);
141  BN_free(rsa->d);
142  BN_free(rsa->p);
143  BN_free(rsa->q);
144  BN_free(rsa->dmp1);
145  BN_free(rsa->dmq1);
146  BN_free(rsa->iqmp);
147  BN_MONT_CTX_free(rsa->mont_n);
148  BN_MONT_CTX_free(rsa->mont_p);
149  BN_MONT_CTX_free(rsa->mont_q);
150  BN_free(rsa->d_fixed);
151  BN_free(rsa->dmp1_fixed);
152  BN_free(rsa->dmq1_fixed);
154  for (u = 0; u < rsa->num_blindings; u++) {
156  }
157  OPENSSL_free(rsa->blindings);
159  CRYPTO_MUTEX_cleanup(&rsa->lock);
160  OPENSSL_free(rsa);
161 }
162 
163 int RSA_up_ref(RSA *rsa) {
165  return 1;
166 }
167 
168 unsigned RSA_bits(const RSA *rsa) { return BN_num_bits(rsa->n); }
169 
170 const BIGNUM *RSA_get0_n(const RSA *rsa) { return rsa->n; }
171 
172 const BIGNUM *RSA_get0_e(const RSA *rsa) { return rsa->e; }
173 
174 const BIGNUM *RSA_get0_d(const RSA *rsa) { return rsa->d; }
175 
176 const BIGNUM *RSA_get0_p(const RSA *rsa) { return rsa->p; }
177 
178 const BIGNUM *RSA_get0_q(const RSA *rsa) { return rsa->q; }
179 
180 const BIGNUM *RSA_get0_dmp1(const RSA *rsa) { return rsa->dmp1; }
181 
182 const BIGNUM *RSA_get0_dmq1(const RSA *rsa) { return rsa->dmq1; }
183 
184 const BIGNUM *RSA_get0_iqmp(const RSA *rsa) { return rsa->iqmp; }
185 
186 void RSA_get0_key(const RSA *rsa, const BIGNUM **out_n, const BIGNUM **out_e,
187  const BIGNUM **out_d) {
188  if (out_n != NULL) {
189  *out_n = rsa->n;
190  }
191  if (out_e != NULL) {
192  *out_e = rsa->e;
193  }
194  if (out_d != NULL) {
195  *out_d = rsa->d;
196  }
197 }
198 
199 void RSA_get0_factors(const RSA *rsa, const BIGNUM **out_p,
200  const BIGNUM **out_q) {
201  if (out_p != NULL) {
202  *out_p = rsa->p;
203  }
204  if (out_q != NULL) {
205  *out_q = rsa->q;
206  }
207 }
208 
210  // We do not support the id-RSASSA-PSS key encoding. If we add support later,
211  // the |maskHash| field should be filled in for OpenSSL compatibility.
212  return NULL;
213 }
214 
215 void RSA_get0_crt_params(const RSA *rsa, const BIGNUM **out_dmp1,
216  const BIGNUM **out_dmq1, const BIGNUM **out_iqmp) {
217  if (out_dmp1 != NULL) {
218  *out_dmp1 = rsa->dmp1;
219  }
220  if (out_dmq1 != NULL) {
221  *out_dmq1 = rsa->dmq1;
222  }
223  if (out_iqmp != NULL) {
224  *out_iqmp = rsa->iqmp;
225  }
226 }
227 
228 int RSA_set0_key(RSA *rsa, BIGNUM *n, BIGNUM *e, BIGNUM *d) {
229  if ((rsa->n == NULL && n == NULL) ||
230  (rsa->e == NULL && e == NULL)) {
231  return 0;
232  }
233 
234  if (n != NULL) {
235  BN_free(rsa->n);
236  rsa->n = n;
237  }
238  if (e != NULL) {
239  BN_free(rsa->e);
240  rsa->e = e;
241  }
242  if (d != NULL) {
243  BN_free(rsa->d);
244  rsa->d = d;
245  }
246 
247  return 1;
248 }
249 
250 int RSA_set0_factors(RSA *rsa, BIGNUM *p, BIGNUM *q) {
251  if ((rsa->p == NULL && p == NULL) ||
252  (rsa->q == NULL && q == NULL)) {
253  return 0;
254  }
255 
256  if (p != NULL) {
257  BN_free(rsa->p);
258  rsa->p = p;
259  }
260  if (q != NULL) {
261  BN_free(rsa->q);
262  rsa->q = q;
263  }
264 
265  return 1;
266 }
267 
268 int RSA_set0_crt_params(RSA *rsa, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp) {
269  if ((rsa->dmp1 == NULL && dmp1 == NULL) ||
270  (rsa->dmq1 == NULL && dmq1 == NULL) ||
271  (rsa->iqmp == NULL && iqmp == NULL)) {
272  return 0;
273  }
274 
275  if (dmp1 != NULL) {
276  BN_free(rsa->dmp1);
277  rsa->dmp1 = dmp1;
278  }
279  if (dmq1 != NULL) {
280  BN_free(rsa->dmq1);
281  rsa->dmq1 = dmq1;
282  }
283  if (iqmp != NULL) {
284  BN_free(rsa->iqmp);
285  rsa->iqmp = iqmp;
286  }
287 
288  return 1;
289 }
290 
291 int RSA_public_encrypt(size_t flen, const uint8_t *from, uint8_t *to, RSA *rsa,
292  int padding) {
293  size_t out_len;
294 
295  if (!RSA_encrypt(rsa, &out_len, to, RSA_size(rsa), from, flen, padding)) {
296  return -1;
297  }
298 
299  if (out_len > INT_MAX) {
301  return -1;
302  }
303  return out_len;
304 }
305 
306 int RSA_sign_raw(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out,
307  const uint8_t *in, size_t in_len, int padding) {
308  if (rsa->meth->sign_raw) {
309  return rsa->meth->sign_raw(rsa, out_len, out, max_out, in, in_len, padding);
310  }
311 
312  return rsa_default_sign_raw(rsa, out_len, out, max_out, in, in_len, padding);
313 }
314 
315 int RSA_private_encrypt(size_t flen, const uint8_t *from, uint8_t *to, RSA *rsa,
316  int padding) {
317  size_t out_len;
318 
319  if (!RSA_sign_raw(rsa, &out_len, to, RSA_size(rsa), from, flen, padding)) {
320  return -1;
321  }
322 
323  if (out_len > INT_MAX) {
325  return -1;
326  }
327  return out_len;
328 }
329 
330 int RSA_decrypt(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out,
331  const uint8_t *in, size_t in_len, int padding) {
332  if (rsa->meth->decrypt) {
333  return rsa->meth->decrypt(rsa, out_len, out, max_out, in, in_len, padding);
334  }
335 
336  return rsa_default_decrypt(rsa, out_len, out, max_out, in, in_len, padding);
337 }
338 
339 int RSA_private_decrypt(size_t flen, const uint8_t *from, uint8_t *to, RSA *rsa,
340  int padding) {
341  size_t out_len;
342 
343  if (!RSA_decrypt(rsa, &out_len, to, RSA_size(rsa), from, flen, padding)) {
344  return -1;
345  }
346 
347  if (out_len > INT_MAX) {
349  return -1;
350  }
351  return out_len;
352 }
353 
354 int RSA_public_decrypt(size_t flen, const uint8_t *from, uint8_t *to, RSA *rsa,
355  int padding) {
356  size_t out_len;
357 
358  if (!RSA_verify_raw(rsa, &out_len, to, RSA_size(rsa), from, flen, padding)) {
359  return -1;
360  }
361 
362  if (out_len > INT_MAX) {
364  return -1;
365  }
366  return out_len;
367 }
368 
369 unsigned RSA_size(const RSA *rsa) {
370  if (rsa->meth->size) {
371  return rsa->meth->size(rsa);
372  }
373 
374  return rsa_default_size(rsa);
375 }
376 
377 int RSA_is_opaque(const RSA *rsa) {
378  return rsa->meth && (rsa->meth->flags & RSA_FLAG_OPAQUE);
379 }
380 
381 int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_unused *unused,
382  CRYPTO_EX_dup *dup_unused, CRYPTO_EX_free *free_func) {
383  int index;
384  if (!CRYPTO_get_ex_new_index(g_rsa_ex_data_class_bss_get(), &index, argl,
385  argp, free_func)) {
386  return -1;
387  }
388  return index;
389 }
390 
391 int RSA_set_ex_data(RSA *rsa, int idx, void *arg) {
392  return CRYPTO_set_ex_data(&rsa->ex_data, idx, arg);
393 }
394 
395 void *RSA_get_ex_data(const RSA *rsa, int idx) {
396  return CRYPTO_get_ex_data(&rsa->ex_data, idx);
397 }
398 
399 // SSL_SIG_LENGTH is the size of an SSL/TLS (prior to TLS 1.2) signature: it's
400 // the length of an MD5 and SHA1 hash.
401 static const unsigned SSL_SIG_LENGTH = 36;
402 
403 // pkcs1_sig_prefix contains the ASN.1, DER encoded prefix for a hash that is
404 // to be signed with PKCS#1.
406  // nid identifies the hash function.
407  int nid;
408  // hash_len is the expected length of the hash function.
410  // len is the number of bytes of |bytes| which are valid.
412  // bytes contains the DER bytes.
414 };
415 
416 // kPKCS1SigPrefixes contains the ASN.1 prefixes for PKCS#1 signatures with
417 // different hash functions.
418 static const struct pkcs1_sig_prefix kPKCS1SigPrefixes[] = {
419  {
420  NID_md5,
422  18,
423  {0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
424  0x02, 0x05, 0x05, 0x00, 0x04, 0x10},
425  },
426  {
427  NID_sha1,
429  15,
430  {0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05,
431  0x00, 0x04, 0x14},
432  },
433  {
434  NID_sha224,
436  19,
437  {0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03,
438  0x04, 0x02, 0x04, 0x05, 0x00, 0x04, 0x1c},
439  },
440  {
441  NID_sha256,
443  19,
444  {0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03,
445  0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20},
446  },
447  {
448  NID_sha384,
450  19,
451  {0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03,
452  0x04, 0x02, 0x02, 0x05, 0x00, 0x04, 0x30},
453  },
454  {
455  NID_sha512,
457  19,
458  {0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03,
459  0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40},
460  },
461  {
462  NID_undef, 0, 0, {0},
463  },
464 };
465 
466 int RSA_add_pkcs1_prefix(uint8_t **out_msg, size_t *out_msg_len,
467  int *is_alloced, int hash_nid, const uint8_t *digest,
468  size_t digest_len) {
469  unsigned i;
470 
471  if (hash_nid == NID_md5_sha1) {
472  // Special case: SSL signature, just check the length.
473  if (digest_len != SSL_SIG_LENGTH) {
475  return 0;
476  }
477 
478  *out_msg = (uint8_t *)digest;
479  *out_msg_len = SSL_SIG_LENGTH;
480  *is_alloced = 0;
481  return 1;
482  }
483 
484  for (i = 0; kPKCS1SigPrefixes[i].nid != NID_undef; i++) {
485  const struct pkcs1_sig_prefix *sig_prefix = &kPKCS1SigPrefixes[i];
486  if (sig_prefix->nid != hash_nid) {
487  continue;
488  }
489 
490  if (digest_len != sig_prefix->hash_len) {
492  return 0;
493  }
494 
495  const uint8_t* prefix = sig_prefix->bytes;
496  unsigned prefix_len = sig_prefix->len;
497  unsigned signed_msg_len;
498  uint8_t *signed_msg;
499 
500  signed_msg_len = prefix_len + digest_len;
501  if (signed_msg_len < prefix_len) {
503  return 0;
504  }
505 
506  signed_msg = OPENSSL_malloc(signed_msg_len);
507  if (!signed_msg) {
509  return 0;
510  }
511 
512  OPENSSL_memcpy(signed_msg, prefix, prefix_len);
513  OPENSSL_memcpy(signed_msg + prefix_len, digest, digest_len);
514 
515  *out_msg = signed_msg;
516  *out_msg_len = signed_msg_len;
517  *is_alloced = 1;
518 
519  return 1;
520  }
521 
523  return 0;
524 }
525 
526 int RSA_sign(int hash_nid, const uint8_t *digest, unsigned digest_len,
527  uint8_t *out, unsigned *out_len, RSA *rsa) {
528  const unsigned rsa_size = RSA_size(rsa);
529  int ret = 0;
530  uint8_t *signed_msg = NULL;
531  size_t signed_msg_len = 0;
532  int signed_msg_is_alloced = 0;
533  size_t size_t_out_len;
534 
535  if (rsa->meth->sign) {
536  return rsa->meth->sign(hash_nid, digest, digest_len, out, out_len, rsa);
537  }
538 
539  if (!RSA_add_pkcs1_prefix(&signed_msg, &signed_msg_len,
540  &signed_msg_is_alloced, hash_nid, digest,
541  digest_len) ||
542  !RSA_sign_raw(rsa, &size_t_out_len, out, rsa_size, signed_msg,
543  signed_msg_len, RSA_PKCS1_PADDING)) {
544  goto err;
545  }
546 
547  *out_len = size_t_out_len;
548  ret = 1;
549 
550 err:
551  if (signed_msg_is_alloced) {
552  OPENSSL_free(signed_msg);
553  }
554  return ret;
555 }
556 
557 int RSA_sign_pss_mgf1(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out,
558  const uint8_t *digest, size_t digest_len,
559  const EVP_MD *md, const EVP_MD *mgf1_md, int salt_len) {
560  if (digest_len != EVP_MD_size(md)) {
562  return 0;
563  }
564 
565  size_t padded_len = RSA_size(rsa);
566  uint8_t *padded = OPENSSL_malloc(padded_len);
567  if (padded == NULL) {
569  return 0;
570  }
571 
572  int ret = RSA_padding_add_PKCS1_PSS_mgf1(rsa, padded, digest, md, mgf1_md,
573  salt_len) &&
574  RSA_sign_raw(rsa, out_len, out, max_out, padded, padded_len,
576  OPENSSL_free(padded);
577  return ret;
578 }
579 
580 int RSA_verify(int hash_nid, const uint8_t *digest, size_t digest_len,
581  const uint8_t *sig, size_t sig_len, RSA *rsa) {
582  if (rsa->n == NULL || rsa->e == NULL) {
584  return 0;
585  }
586 
587  const size_t rsa_size = RSA_size(rsa);
588  uint8_t *buf = NULL;
589  int ret = 0;
590  uint8_t *signed_msg = NULL;
591  size_t signed_msg_len = 0, len;
592  int signed_msg_is_alloced = 0;
593 
594  if (hash_nid == NID_md5_sha1 && digest_len != SSL_SIG_LENGTH) {
596  return 0;
597  }
598 
599  buf = OPENSSL_malloc(rsa_size);
600  if (!buf) {
602  return 0;
603  }
604 
605  if (!RSA_verify_raw(rsa, &len, buf, rsa_size, sig, sig_len,
607  goto out;
608  }
609 
610  if (!RSA_add_pkcs1_prefix(&signed_msg, &signed_msg_len,
611  &signed_msg_is_alloced, hash_nid, digest,
612  digest_len)) {
613  goto out;
614  }
615 
616  // Check that no other information follows the hash value (FIPS 186-4 Section
617  // 5.5) and it matches the expected hash.
618  if (len != signed_msg_len || OPENSSL_memcmp(buf, signed_msg, len) != 0) {
620  goto out;
621  }
622 
623  ret = 1;
624 
625 out:
626  OPENSSL_free(buf);
627  if (signed_msg_is_alloced) {
628  OPENSSL_free(signed_msg);
629  }
630  return ret;
631 }
632 
633 int RSA_verify_pss_mgf1(RSA *rsa, const uint8_t *digest, size_t digest_len,
634  const EVP_MD *md, const EVP_MD *mgf1_md, int salt_len,
635  const uint8_t *sig, size_t sig_len) {
636  if (digest_len != EVP_MD_size(md)) {
638  return 0;
639  }
640 
641  size_t em_len = RSA_size(rsa);
642  uint8_t *em = OPENSSL_malloc(em_len);
643  if (em == NULL) {
645  return 0;
646  }
647 
648  int ret = 0;
649  if (!RSA_verify_raw(rsa, &em_len, em, em_len, sig, sig_len, RSA_NO_PADDING)) {
650  goto err;
651  }
652 
653  if (em_len != RSA_size(rsa)) {
655  goto err;
656  }
657 
658  ret = RSA_verify_PKCS1_PSS_mgf1(rsa, digest, md, mgf1_md, em, salt_len);
659 
660 err:
661  OPENSSL_free(em);
662  return ret;
663 }
664 
665 static int check_mod_inverse(int *out_ok, const BIGNUM *a, const BIGNUM *ainv,
666  const BIGNUM *m, unsigned m_min_bits,
667  BN_CTX *ctx) {
668  if (BN_is_negative(ainv) || BN_cmp(ainv, m) >= 0) {
669  *out_ok = 0;
670  return 1;
671  }
672 
673  // Note |bn_mul_consttime| and |bn_div_consttime| do not scale linearly, but
674  // checking |ainv| is in range bounds the running time, assuming |m|'s bounds
675  // were checked by the caller.
676  BN_CTX_start(ctx);
677  BIGNUM *tmp = BN_CTX_get(ctx);
678  int ret = tmp != NULL &&
679  bn_mul_consttime(tmp, a, ainv, ctx) &&
680  bn_div_consttime(NULL, tmp, tmp, m, m_min_bits, ctx);
681  if (ret) {
682  *out_ok = BN_is_one(tmp);
683  }
684  BN_CTX_end(ctx);
685  return ret;
686 }
687 
688 int RSA_check_key(const RSA *key) {
689  // TODO(davidben): RSA key initialization is spread across
690  // |rsa_check_public_key|, |RSA_check_key|, |freeze_private_key|, and
691  // |BN_MONT_CTX_set_locked| as a result of API issues. See
692  // https://crbug.com/boringssl/316. As a result, we inconsistently check RSA
693  // invariants. We should fix this and integrate that logic.
694 
695  if (RSA_is_opaque(key)) {
696  // Opaque keys can't be checked.
697  return 1;
698  }
699 
700  if (!rsa_check_public_key(key)) {
701  return 0;
702  }
703 
704  if ((key->p != NULL) != (key->q != NULL)) {
706  return 0;
707  }
708 
709  // |key->d| must be bounded by |key->n|. This ensures bounds on |RSA_bits|
710  // translate to bounds on the running time of private key operations.
711  if (key->d != NULL &&
712  (BN_is_negative(key->d) || BN_cmp(key->d, key->n) >= 0)) {
714  return 0;
715  }
716 
717  if (key->d == NULL || key->p == NULL) {
718  // For a public key, or without p and q, there's nothing that can be
719  // checked.
720  return 1;
721  }
722 
723  BN_CTX *ctx = BN_CTX_new();
724  if (ctx == NULL) {
726  return 0;
727  }
728 
729  BIGNUM tmp, de, pm1, qm1, dmp1, dmq1;
730  int ok = 0;
731  BN_init(&tmp);
732  BN_init(&de);
733  BN_init(&pm1);
734  BN_init(&qm1);
735  BN_init(&dmp1);
736  BN_init(&dmq1);
737 
738  // Check that p * q == n. Before we multiply, we check that p and q are in
739  // bounds, to avoid a DoS vector in |bn_mul_consttime| below. Note that
740  // n was bound by |rsa_check_public_key|.
741  if (BN_is_negative(key->p) || BN_cmp(key->p, key->n) >= 0 ||
742  BN_is_negative(key->q) || BN_cmp(key->q, key->n) >= 0) {
744  goto out;
745  }
746  if (!bn_mul_consttime(&tmp, key->p, key->q, ctx)) {
748  goto out;
749  }
750  if (BN_cmp(&tmp, key->n) != 0) {
752  goto out;
753  }
754 
755  // d must be an inverse of e mod the Carmichael totient, lcm(p-1, q-1), but it
756  // may be unreduced because other implementations use the Euler totient. We
757  // simply check that d * e is one mod p-1 and mod q-1. Note d and e were bound
758  // by earlier checks in this function.
759  if (!bn_usub_consttime(&pm1, key->p, BN_value_one()) ||
760  !bn_usub_consttime(&qm1, key->q, BN_value_one())) {
762  goto out;
763  }
764  const unsigned pm1_bits = BN_num_bits(&pm1);
765  const unsigned qm1_bits = BN_num_bits(&qm1);
766  if (!bn_mul_consttime(&de, key->d, key->e, ctx) ||
767  !bn_div_consttime(NULL, &tmp, &de, &pm1, pm1_bits, ctx) ||
768  !bn_div_consttime(NULL, &de, &de, &qm1, qm1_bits, ctx)) {
770  goto out;
771  }
772 
773  if (!BN_is_one(&tmp) || !BN_is_one(&de)) {
775  goto out;
776  }
777 
778  int has_crt_values = key->dmp1 != NULL;
779  if (has_crt_values != (key->dmq1 != NULL) ||
780  has_crt_values != (key->iqmp != NULL)) {
782  goto out;
783  }
784 
785  if (has_crt_values) {
786  int dmp1_ok, dmq1_ok, iqmp_ok;
787  if (!check_mod_inverse(&dmp1_ok, key->e, key->dmp1, &pm1, pm1_bits, ctx) ||
788  !check_mod_inverse(&dmq1_ok, key->e, key->dmq1, &qm1, qm1_bits, ctx) ||
789  // |p| is odd, so |pm1| and |p| have the same bit width. If they didn't,
790  // we only need a lower bound anyway.
791  !check_mod_inverse(&iqmp_ok, key->q, key->iqmp, key->p, pm1_bits,
792  ctx)) {
794  goto out;
795  }
796 
797  if (!dmp1_ok || !dmq1_ok || !iqmp_ok) {
799  goto out;
800  }
801  }
802 
803  ok = 1;
804 
805 out:
806  BN_free(&tmp);
807  BN_free(&de);
808  BN_free(&pm1);
809  BN_free(&qm1);
810  BN_free(&dmp1);
811  BN_free(&dmq1);
812  BN_CTX_free(ctx);
813 
814  return ok;
815 }
816 
817 
818 // This is the product of the 132 smallest odd primes, from 3 to 751.
819 static const BN_ULONG kSmallFactorsLimbs[] = {
820  TOBN(0xc4309333, 0x3ef4e3e1), TOBN(0x71161eb6, 0xcd2d655f),
821  TOBN(0x95e2238c, 0x0bf94862), TOBN(0x3eb233d3, 0x24f7912b),
822  TOBN(0x6b55514b, 0xbf26c483), TOBN(0x0a84d817, 0x5a144871),
823  TOBN(0x77d12fee, 0x9b82210a), TOBN(0xdb5b93c2, 0x97f050b3),
824  TOBN(0x4acad6b9, 0x4d6c026b), TOBN(0xeb7751f3, 0x54aec893),
825  TOBN(0xdba53368, 0x36bc85c4), TOBN(0xd85a1b28, 0x7f5ec78e),
826  TOBN(0x2eb072d8, 0x6b322244), TOBN(0xbba51112, 0x5e2b3aea),
827  TOBN(0x36ed1a6c, 0x0e2486bf), TOBN(0x5f270460, 0xec0c5727),
828  0x000017b1
829 };
830 
831 DEFINE_LOCAL_DATA(BIGNUM, g_small_factors) {
832  out->d = (BN_ULONG *) kSmallFactorsLimbs;
834  out->dmax = out->width;
835  out->neg = 0;
836  out->flags = BN_FLG_STATIC_DATA;
837 }
838 
840  if (RSA_is_opaque(key)) {
841  // Opaque keys can't be checked.
843  return 0;
844  }
845 
846  if (!RSA_check_key(key)) {
847  return 0;
848  }
849 
850  BN_CTX *ctx = BN_CTX_new();
851  if (ctx == NULL) {
853  return 0;
854  }
855 
856  BIGNUM small_gcd;
857  BN_init(&small_gcd);
858 
859  int ret = 1;
860 
861  // Perform partial public key validation of RSA keys (SP 800-89 5.3.3).
862  // Although this is not for primality testing, SP 800-89 cites an RSA
863  // primality testing algorithm, so we use |BN_prime_checks_for_generation| to
864  // match. This is only a plausibility test and we expect the value to be
865  // composite, so too few iterations will cause us to reject the key, not use
866  // an implausible one.
867  enum bn_primality_result_t primality_result;
868  if (BN_num_bits(key->e) <= 16 ||
869  BN_num_bits(key->e) > 256 ||
870  !BN_is_odd(key->n) ||
871  !BN_is_odd(key->e) ||
872  !BN_gcd(&small_gcd, key->n, g_small_factors(), ctx) ||
873  !BN_is_one(&small_gcd) ||
874  !BN_enhanced_miller_rabin_primality_test(&primality_result, key->n,
876  ctx, NULL) ||
877  primality_result != bn_non_prime_power_composite) {
879  ret = 0;
880  }
881 
882  BN_free(&small_gcd);
883  BN_CTX_free(ctx);
884 
885  if (!ret || key->d == NULL || key->p == NULL) {
886  // On a failure or on only a public key, there's nothing else can be
887  // checked.
888  return ret;
889  }
890 
891  // FIPS pairwise consistency test (FIPS 140-2 4.9.2). Per FIPS 140-2 IG,
892  // section 9.9, it is not known whether |rsa| will be used for signing or
893  // encryption, so either pair-wise consistency self-test is acceptable. We
894  // perform a signing test.
895  uint8_t data[32] = {0};
896  unsigned sig_len = RSA_size(key);
897  uint8_t *sig = OPENSSL_malloc(sig_len);
898  if (sig == NULL) {
900  return 0;
901  }
902 
903  if (!RSA_sign(NID_sha256, data, sizeof(data), sig, &sig_len, key)) {
905  ret = 0;
906  goto cleanup;
907  }
908 #if defined(BORINGSSL_FIPS_BREAK_RSA_PWCT)
909  data[0] = ~data[0];
910 #endif
911  if (!RSA_verify(NID_sha256, data, sizeof(data), sig, sig_len, key)) {
913  ret = 0;
914  }
915 
916 cleanup:
917  OPENSSL_free(sig);
918 
919  return ret;
920 }
921 
923  size_t len) {
924  if (rsa->meth->private_transform) {
925  return rsa->meth->private_transform(rsa, out, in, len);
926  }
927 
928  return rsa_default_private_transform(rsa, out, in, len);
929 }
930 
931 int RSA_flags(const RSA *rsa) { return rsa->flags; }
932 
934  return 1;
935 }
RSA_R_VALUE_MISSING
#define RSA_R_VALUE_MISSING
Definition: rsa.h:849
rsa_st::dmp1_fixed
BIGNUM * dmp1_fixed
Definition: rsa.h:765
bn.h
RSA_R_N_NOT_EQUAL_P_Q
#define RSA_R_N_NOT_EQUAL_P_Q
Definition: rsa.h:837
NID_md5_sha1
#define NID_md5_sha1
Definition: nid.h:603
RSA_R_INCONSISTENT_SET_OF_CRT_VALUES
#define RSA_R_INCONSISTENT_SET_OF_CRT_VALUES
Definition: rsa.h:828
RSA_R_D_OUT_OF_RANGE
#define RSA_R_D_OUT_OF_RANGE
Definition: rsa.h:852
RSA_default_method
const RSA_METHOD * RSA_default_method(void)
RSA_private_encrypt
int RSA_private_encrypt(size_t flen, const uint8_t *from, uint8_t *to, RSA *rsa, int padding)
Definition: rsa.c:315
RSA_set_ex_data
int RSA_set_ex_data(RSA *rsa, int idx, void *arg)
Definition: rsa.c:391
test_server.argp
argp
Definition: test_server.py:33
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
rsa_meth_st::sign
int(* sign)(int type, const uint8_t *m, unsigned int m_length, uint8_t *sigret, unsigned int *siglen, const RSA *rsa)
Definition: rsa.h:700
kSmallFactorsLimbs
static const BN_ULONG kSmallFactorsLimbs[]
Definition: rsa.c:819
OPENSSL_memcmp
static int OPENSSL_memcmp(const void *s1, const void *s2, size_t n)
Definition: third_party/boringssl-with-bazel/src/crypto/internal.h:811
ctx
Definition: benchmark-async.c:30
BN_FLG_STATIC_DATA
#define BN_FLG_STATIC_DATA
Definition: bn.h:997
RSA_get0_dmq1
const BIGNUM * RSA_get0_dmq1(const RSA *rsa)
Definition: rsa.c:182
cleanup
void cleanup(void)
Definition: bloaty/third_party/zlib/examples/enough.c:182
rsa_st::d
BIGNUM * d
Definition: rsa.h:740
CRYPTO_EX_dup
int CRYPTO_EX_dup(CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from, void **from_d, int index, long argl, void *argp)
Definition: ex_data.h:184
env_md_st
Definition: third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/internal.h:67
DEFINE_STATIC_EX_DATA_CLASS
#define DEFINE_STATIC_EX_DATA_CLASS(name)
Definition: delocate.h:46
RSA_verify_PKCS1_PSS_mgf1
#define RSA_verify_PKCS1_PSS_mgf1
Definition: boringssl_prefix_symbols.h:2142
RSA_up_ref
int RSA_up_ref(RSA *rsa)
Definition: rsa.c:163
METHOD_ref
#define METHOD_ref
Definition: boringssl_prefix_symbols.h:1816
RSA_add_pkcs1_prefix
int RSA_add_pkcs1_prefix(uint8_t **out_msg, size_t *out_msg_len, int *is_alloced, int hash_nid, const uint8_t *digest, size_t digest_len)
Definition: rsa.c:466
OPENSSL_PUT_ERROR
#define OPENSSL_PUT_ERROR(library, reason)
Definition: err.h:423
string.h
OPENSSL_ARRAY_SIZE
#define OPENSSL_ARRAY_SIZE(array)
Definition: third_party/boringssl-with-bazel/src/crypto/internal.h:179
rsa_st::num_blindings
unsigned num_blindings
Definition: rsa.h:775
buf
voidpf void * buf
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
check_mod_inverse
static int check_mod_inverse(int *out_ok, const BIGNUM *a, const BIGNUM *ainv, const BIGNUM *m, unsigned m_min_bits, BN_CTX *ctx)
Definition: rsa.c:665
pkcs1_sig_prefix::nid
int nid
Definition: rsa.c:407
RSA_get0_n
const BIGNUM * RSA_get0_n(const RSA *rsa)
Definition: rsa.c:170
RSA_public_decrypt
int RSA_public_decrypt(size_t flen, const uint8_t *from, uint8_t *to, RSA *rsa, int padding)
Definition: rsa.c:354
RSA_sign_raw
int RSA_sign_raw(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out, const uint8_t *in, size_t in_len, int padding)
Definition: rsa.c:306
error_ref_leak.err
err
Definition: error_ref_leak.py:35
rsa_meth_st::flags
int flags
Definition: rsa.h:724
rsa_st::dmq1
BIGNUM * dmq1
Definition: rsa.h:744
RSA_set0_crt_params
int RSA_set0_crt_params(RSA *rsa, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp)
Definition: rsa.c:268
u
OPENSSL_EXPORT pem_password_cb void * u
Definition: pem.h:351
SSL_SIG_LENGTH
static const unsigned SSL_SIG_LENGTH
Definition: rsa.c:401
ENGINE_get_RSA_method
#define ENGINE_get_RSA_method
Definition: boringssl_prefix_symbols.h:1404
bn_non_prime_power_composite
@ bn_non_prime_power_composite
Definition: bn.h:708
BN_free
#define BN_free
Definition: boringssl_prefix_symbols.h:923
a
int a
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:88
RSA_set0_key
int RSA_set0_key(RSA *rsa, BIGNUM *n, BIGNUM *e, BIGNUM *d)
Definition: rsa.c:228
to
size_t to
Definition: abseil-cpp/absl/container/internal/layout_test.cc:1385
bignum_ctx
Definition: ctx.c:91
BN_CTX_get
#define BN_CTX_get
Definition: boringssl_prefix_symbols.h:884
xds_manager.p
p
Definition: xds_manager.py:60
CRYPTO_MUTEX_init
#define CRYPTO_MUTEX_init
Definition: boringssl_prefix_symbols.h:1124
rsa_st::ex_data
CRYPTO_EX_DATA ex_data
Definition: rsa.h:748
NID_sha384
#define NID_sha384
Definition: nid.h:2998
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
rsa_default_private_transform
#define rsa_default_private_transform
Definition: boringssl_prefix_symbols.h:3359
OPENSSL_memset
static void * OPENSSL_memset(void *dst, int c, size_t n)
Definition: third_party/boringssl-with-bazel/src/crypto/internal.h:835
RSA_check_key
int RSA_check_key(const RSA *key)
Definition: rsa.c:688
RSA_get0_d
const BIGNUM * RSA_get0_d(const RSA *rsa)
Definition: rsa.c:174
BN_value_one
const OPENSSL_EXPORT BIGNUM * BN_value_one(void)
RSA_new
RSA * RSA_new(void)
Definition: rsa.c:85
RSA_R_INVALID_MESSAGE_LENGTH
#define RSA_R_INVALID_MESSAGE_LENGTH
Definition: rsa.h:830
CRYPTO_free_ex_data
#define CRYPTO_free_ex_data
Definition: boringssl_prefix_symbols.h:1151
rsa_meth_st::size
size_t(* size)(const RSA *rsa)
Definition: rsa.h:698
RSA_padding_add_PKCS1_PSS_mgf1
#define RSA_padding_add_PKCS1_PSS_mgf1
Definition: boringssl_prefix_symbols.h:2113
SHA384_DIGEST_LENGTH
#define SHA384_DIGEST_LENGTH
Definition: sha.h:203
RSA_PKCS1_PADDING
#define RSA_PKCS1_PADDING
Definition: rsa.h:210
OPENSSL_malloc
#define OPENSSL_malloc
Definition: boringssl_prefix_symbols.h:1885
from
size_t from
Definition: abseil-cpp/absl/container/internal/layout_test.cc:1384
RSA_is_opaque
int RSA_is_opaque(const RSA *rsa)
Definition: rsa.c:377
RSA_R_ONLY_ONE_OF_P_Q_GIVEN
#define RSA_R_ONLY_ONE_OF_P_Q_GIVEN
Definition: rsa.h:839
BN_enhanced_miller_rabin_primality_test
#define BN_enhanced_miller_rabin_primality_test
Definition: boringssl_prefix_symbols.h:920
RSA_verify
int RSA_verify(int hash_nid, const uint8_t *digest, size_t digest_len, const uint8_t *sig, size_t sig_len, RSA *rsa)
Definition: rsa.c:580
in
const char * in
Definition: third_party/abseil-cpp/absl/strings/internal/str_format/parser_test.cc:391
RSA_new_method
RSA * RSA_new_method(const ENGINE *engine)
Definition: rsa.c:87
RSA_get0_factors
void RSA_get0_factors(const RSA *rsa, const BIGNUM **out_p, const BIGNUM **out_q)
Definition: rsa.c:199
RSA_size
unsigned RSA_size(const RSA *rsa)
Definition: rsa.c:369
rsa_meth_st::finish
int(* finish)(RSA *rsa)
Definition: rsa.h:695
rsa_st::mont_p
BN_MONT_CTX * mont_p
Definition: rsa.h:757
RSA_R_UNKNOWN_ALGORITHM_TYPE
#define RSA_R_UNKNOWN_ALGORITHM_TYPE
Definition: rsa.h:847
RSA_private_decrypt
int RSA_private_decrypt(size_t flen, const uint8_t *from, uint8_t *to, RSA *rsa, int padding)
Definition: rsa.c:339
rsa_st::inv_small_mod_large_mont
BIGNUM * inv_small_mod_large_mont
Definition: rsa.h:770
rsa_st::p
BIGNUM * p
Definition: rsa.h:741
NID_sha256
#define NID_sha256
Definition: nid.h:2993
bn_usub_consttime
#define bn_usub_consttime
Definition: boringssl_prefix_symbols.h:2918
rsa_st::e
BIGNUM * e
Definition: rsa.h:739
bn_div_consttime
#define bn_div_consttime
Definition: boringssl_prefix_symbols.h:2853
EVP_MD_size
#define EVP_MD_size
Definition: boringssl_prefix_symbols.h:1579
sha.h
rsa_st::dmp1
BIGNUM * dmp1
Definition: rsa.h:743
kPKCS1SigPrefixes
static const struct pkcs1_sig_prefix kPKCS1SigPrefixes[]
Definition: rsa.c:418
BN_BLINDING_free
#define BN_BLINDING_free
Definition: boringssl_prefix_symbols.h:878
BN_gcd
#define BN_gcd
Definition: boringssl_prefix_symbols.h:925
OPENSSL_memcpy
static void * OPENSSL_memcpy(void *dst, const void *src, size_t n)
Definition: third_party/boringssl-with-bazel/src/crypto/internal.h:819
RSA_R_TOO_LONG
#define RSA_R_TOO_LONG
Definition: rsa.h:845
rsa_default_sign_raw
#define rsa_default_sign_raw
Definition: boringssl_prefix_symbols.h:3360
ERR_LIB_BN
@ ERR_LIB_BN
Definition: err.h:294
RSA_blinding_on
int RSA_blinding_on(RSA *rsa, BN_CTX *ctx)
Definition: rsa.c:933
err.h
ERR_R_INTERNAL_ERROR
#define ERR_R_INTERNAL_ERROR
Definition: err.h:374
rsa_meth_st::sign_raw
int(* sign_raw)(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out, const uint8_t *in, size_t in_len, int padding)
Definition: rsa.h:704
rsa.h
rsa_st::dmq1_fixed
BIGNUM * dmq1_fixed
Definition: rsa.h:765
arg
Definition: cmdline.cc:40
CRYPTO_EX_unused
int CRYPTO_EX_unused
Definition: ex_data.h:192
CRYPTO_new_ex_data
#define CRYPTO_new_ex_data
Definition: boringssl_prefix_symbols.h:1179
RSA_R_D_E_NOT_CONGRUENT_TO_1
#define RSA_R_D_E_NOT_CONGRUENT_TO_1
Definition: rsa.h:824
BN_is_odd
#define BN_is_odd
Definition: boringssl_prefix_symbols.h:934
RSA_get0_crt_params
void RSA_get0_crt_params(const RSA *rsa, const BIGNUM **out_dmp1, const BIGNUM **out_dmq1, const BIGNUM **out_iqmp)
Definition: rsa.c:215
NID_undef
#define NID_undef
Definition: nid.h:85
SHA512_DIGEST_LENGTH
#define SHA512_DIGEST_LENGTH
Definition: sha.h:230
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
pkcs1_sig_prefix::bytes
uint8_t bytes[19]
Definition: rsa.c:413
OPENSSL_DECLARE_ERROR_REASON
#define OPENSSL_DECLARE_ERROR_REASON(lib, reason)
Definition: err.h:459
BN_CTX_new
#define BN_CTX_new
Definition: boringssl_prefix_symbols.h:885
rsa_st::meth
RSA_METHOD * meth
Definition: rsa.h:733
NID_md5
#define NID_md5
Definition: nid.h:105
RSA_get0_pss_params
const RSA_PSS_PARAMS * RSA_get0_pss_params(const RSA *rsa)
Definition: rsa.c:209
NID_sha1
#define NID_sha1
Definition: nid.h:372
d
static const fe d
Definition: curve25519_tables.h:19
CRYPTO_EX_free
void CRYPTO_EX_free(void *parent, void *ptr, CRYPTO_EX_DATA *ad, int index, long argl, void *argp)
Definition: ex_data.h:174
n
int n
Definition: abseil-cpp/absl/container/btree_test.cc:1080
RSA_NO_PADDING
#define RSA_NO_PADDING
Definition: rsa.h:213
NID_sha512
#define NID_sha512
Definition: nid.h:3003
setup.idx
idx
Definition: third_party/bloaty/third_party/capstone/bindings/python/setup.py:197
ERR_R_OVERFLOW
#define ERR_R_OVERFLOW
Definition: err.h:375
bn_mul_consttime
#define bn_mul_consttime
Definition: boringssl_prefix_symbols.h:2887
RSA_get0_iqmp
const BIGNUM * RSA_get0_iqmp(const RSA *rsa)
Definition: rsa.c:184
rsa_st::q
BIGNUM * q
Definition: rsa.h:742
rsa_st::blindings_inuse
unsigned char * blindings_inuse
Definition: rsa.h:780
BN_num_bits
#define BN_num_bits
Definition: boringssl_prefix_symbols.h:974
CRYPTO_get_ex_data
#define CRYPTO_get_ex_data
Definition: boringssl_prefix_symbols.h:1164
RSA_verify_pss_mgf1
int RSA_verify_pss_mgf1(RSA *rsa, const uint8_t *digest, size_t digest_len, const EVP_MD *md, const EVP_MD *mgf1_md, int salt_len, const uint8_t *sig, size_t sig_len)
Definition: rsa.c:633
NID_sha224
#define NID_sha224
Definition: nid.h:3008
RSA_private_transform
int RSA_private_transform(RSA *rsa, uint8_t *out, const uint8_t *in, size_t len)
Definition: rsa.c:922
CRYPTO_MUTEX_cleanup
#define CRYPTO_MUTEX_cleanup
Definition: boringssl_prefix_symbols.h:1123
rsa_st::iqmp
BIGNUM * iqmp
Definition: rsa.h:745
benchmark.md
md
Definition: benchmark.py:86
RSA_get0_e
const BIGNUM * RSA_get0_e(const RSA *rsa)
Definition: rsa.c:172
nid.h
digest.h
CRYPTO_get_ex_new_index
#define CRYPTO_get_ex_new_index
Definition: boringssl_prefix_symbols.h:1165
key
const char * key
Definition: hpack_parser_table.cc:164
SHA224_DIGEST_LENGTH
#define SHA224_DIGEST_LENGTH
Definition: sha.h:128
RSA_sign
int RSA_sign(int hash_nid, const uint8_t *digest, unsigned digest_len, uint8_t *out, unsigned *out_len, RSA *rsa)
Definition: rsa.c:526
rsa_pss_params_st
Definition: x509.h:1844
rsa_meth_st::init
int(* init)(RSA *rsa)
Definition: rsa.h:694
RSA_R_BAD_SIGNATURE
#define RSA_R_BAD_SIGNATURE
Definition: rsa.h:810
BN_CTX_start
#define BN_CTX_start
Definition: boringssl_prefix_symbols.h:886
md5.h
RSA_get0_key
void RSA_get0_key(const RSA *rsa, const BIGNUM **out_n, const BIGNUM **out_e, const BIGNUM **out_d)
Definition: rsa.c:186
bignum_st
Definition: bn.h:957
rsa_default_size
#define rsa_default_size
Definition: boringssl_prefix_symbols.h:3361
BN_is_one
#define BN_is_one
Definition: boringssl_prefix_symbols.h:935
RSA_flags
int RSA_flags(const RSA *rsa)
Definition: rsa.c:931
index
int index
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1184
internal.h
BN_CTX_free
#define BN_CTX_free
Definition: boringssl_prefix_symbols.h:883
ret
UniquePtr< SSL_SESSION > ret
Definition: ssl_x509.cc:1029
RSA_public_encrypt
int RSA_public_encrypt(size_t flen, const uint8_t *from, uint8_t *to, RSA *rsa, int padding)
Definition: rsa.c:291
RSA_get0_p
const BIGNUM * RSA_get0_p(const RSA *rsa)
Definition: rsa.c:176
SHA256_DIGEST_LENGTH
#define SHA256_DIGEST_LENGTH
Definition: sha.h:155
MD5_DIGEST_LENGTH
#define MD5_DIGEST_LENGTH
Definition: md5.h:74
RSA_free
void RSA_free(RSA *rsa)
Definition: rsa.c:121
RSA_bits
unsigned RSA_bits(const RSA *rsa)
Definition: rsa.c:168
BN_cmp
#define BN_cmp
Definition: boringssl_prefix_symbols.h:912
pkcs1_sig_prefix::len
uint8_t len
Definition: rsa.c:411
rsa_st::d_fixed
BIGNUM * d_fixed
Definition: rsa.h:765
prefix
static const char prefix[]
Definition: head_of_line_blocking.cc:28
RSA_FLAG_OPAQUE
#define RSA_FLAG_OPAQUE
Definition: rsa.h:590
rsa_st::references
CRYPTO_refcount_t references
Definition: rsa.h:749
ok
bool ok
Definition: async_end2end_test.cc:197
RSA_R_PUBLIC_KEY_VALIDATION_FAILED
#define RSA_R_PUBLIC_KEY_VALIDATION_FAILED
Definition: rsa.h:851
DEFINE_LOCAL_DATA
DEFINE_LOCAL_DATA(BIGNUM, g_small_factors)
Definition: rsa.c:831
pkcs1_sig_prefix
Definition: rsa.c:405
BN_init
#define BN_init
Definition: boringssl_prefix_symbols.h:931
BN_is_negative
#define BN_is_negative
Definition: boringssl_prefix_symbols.h:933
SHA_DIGEST_LENGTH
#define SHA_DIGEST_LENGTH
Definition: sha.h:74
RSA_get_ex_new_index
int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_unused *unused, CRYPTO_EX_dup *dup_unused, CRYPTO_EX_free *free_func)
Definition: rsa.c:381
BN_MONT_CTX_free
#define BN_MONT_CTX_free
Definition: boringssl_prefix_symbols.h:890
rsa_meth_st
Definition: rsa.h:689
rsa_meth_st::private_transform
int(* private_transform)(RSA *rsa, uint8_t *out, const uint8_t *in, size_t len)
Definition: rsa.h:721
RSA_get_ex_data
void * RSA_get_ex_data(const RSA *rsa, int idx)
Definition: rsa.c:395
engine.h
engine_st
Definition: engine.c:29
RSA_decrypt
int RSA_decrypt(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out, const uint8_t *in, size_t in_len, int padding)
Definition: rsa.c:330
CRYPTO_refcount_inc
#define CRYPTO_refcount_inc
Definition: boringssl_prefix_symbols.h:1191
BN_CTX_end
#define BN_CTX_end
Definition: boringssl_prefix_symbols.h:882
RSA_sign_pss_mgf1
int RSA_sign_pss_mgf1(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out, const uint8_t *digest, size_t digest_len, const EVP_MD *md, const EVP_MD *mgf1_md, int salt_len)
Definition: rsa.c:557
mem.h
RSA_verify_raw
#define RSA_verify_raw
Definition: boringssl_prefix_symbols.h:2144
rsa_st
Definition: rsa.h:732
ex_data.h
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
autogen_x86imm.tmp
tmp
Definition: autogen_x86imm.py:12
RSA_check_fips
int RSA_check_fips(RSA *key)
Definition: rsa.c:839
rsa_st::mont_n
BN_MONT_CTX * mont_n
Definition: rsa.h:756
rsa_check_public_key
#define rsa_check_public_key
Definition: boringssl_prefix_symbols.h:3357
CRYPTO_set_ex_data
#define CRYPTO_set_ex_data
Definition: boringssl_prefix_symbols.h:1196
regress.m
m
Definition: regress/regress.py:25
pkcs1_sig_prefix::hash_len
uint8_t hash_len
Definition: rsa.c:409
RSA_get0_q
const BIGNUM * RSA_get0_q(const RSA *rsa)
Definition: rsa.c:178
thread.h
rsa_st::blindings
BN_BLINDING ** blindings
Definition: rsa.h:779
hash_nid
int hash_nid
Definition: ssl_privkey.cc:512
rsa_st::lock
CRYPTO_MUTEX lock
Definition: rsa.h:752
OPENSSL_free
#define OPENSSL_free
Definition: boringssl_prefix_symbols.h:1869
rsa_st::flags
int flags
Definition: rsa.h:750
rsa_meth_st::decrypt
int(* decrypt)(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out, const uint8_t *in, size_t in_len, int padding)
Definition: rsa.h:706
METHOD_unref
#define METHOD_unref
Definition: boringssl_prefix_symbols.h:1817
rsa_st::n
BIGNUM * n
Definition: rsa.h:738
RSA_set0_factors
int RSA_set0_factors(RSA *rsa, BIGNUM *p, BIGNUM *q)
Definition: rsa.c:250
rsa_st::mont_q
BN_MONT_CTX * mont_q
Definition: rsa.h:758
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
rsa_default_decrypt
#define rsa_default_decrypt
Definition: boringssl_prefix_symbols.h:3358
bn_primality_result_t
bn_primality_result_t
Definition: bn.h:705
ERR_R_MALLOC_FAILURE
#define ERR_R_MALLOC_FAILURE
Definition: err.h:371
RSA_encrypt
#define RSA_encrypt
Definition: boringssl_prefix_symbols.h:2088
RSA_R_CRT_VALUES_INCORRECT
#define RSA_R_CRT_VALUES_INCORRECT
Definition: rsa.h:816
CRYPTO_refcount_dec_and_test_zero
#define CRYPTO_refcount_dec_and_test_zero
Definition: boringssl_prefix_symbols.h:1190
BN_prime_checks_for_generation
#define BN_prime_checks_for_generation
Definition: bn.h:702
RSA_get0_dmp1
const BIGNUM * RSA_get0_dmp1(const RSA *rsa)
Definition: rsa.c:180


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:13