Go to the documentation of this file.
70 #include "../bn/internal.h"
71 #include "../../internal.h"
72 #include "../delocate.h"
73 #include "../rand/fork_detect.h"
77 if (rsa->
n == NULL || rsa->
e == NULL) {
83 if (n_bits > 16 * 1024) {
97 static const unsigned kMaxExponentBits = 33;
99 if (e_bits > kMaxExponentBits ||
112 if (n_bits <= kMaxExponentBits) {
162 if (rsa->
mont_n == NULL) {
164 if (rsa->
mont_n == NULL) {
174 if (rsa->
d != NULL &&
179 if (rsa->
p != NULL && rsa->
q != NULL) {
185 if (rsa->
mont_p == NULL) {
187 if (rsa->
mont_p == NULL) {
193 if (rsa->
mont_q == NULL) {
195 if (rsa->
mont_q == NULL) {
201 if (rsa->
dmp1 != NULL && rsa->
dmq1 != NULL) {
203 if (rsa->
iqmp == NULL) {
228 ok = inv_small_mod_large_mont != NULL &&
232 inv_small_mod_large_mont, rsa->
mont_q,
ctx);
234 ok = inv_small_mod_large_mont != NULL &&
239 BN_free(inv_small_mod_large_mont);
263 const uint8_t *
in,
size_t in_len,
int padding) {
268 const unsigned rsa_size =
RSA_size(rsa);
274 if (max_out < rsa_size) {
300 NULL, 0, NULL, NULL);
352 #if defined(OPENSSL_TSAN)
354 #define MAX_BLINDINGS_PER_RSA 2
356 #define MAX_BLINDINGS_PER_RSA 1024
369 assert(rsa->
mont_n != NULL);
387 uint8_t *
const free_inuse_flag =
389 if (free_inuse_flag != NULL) {
390 *free_inuse_flag = 1;
407 "MAX_BLINDINGS_PER_RSA too large");
409 if (new_num_blindings == 0) {
410 new_num_blindings = 1;
419 "MAX_BLINDINGS_PER_RSA too large");
423 if (new_blindings == NULL || new_blindings_inuse == NULL) {
433 if (new_blindings[
i] == NULL) {
468 unsigned blinding_index) {
482 size_t max_out,
const uint8_t *
in,
size_t in_len,
484 const unsigned rsa_size =
RSA_size(rsa);
488 if (max_out < rsa_size) {
530 const uint8_t *
in,
size_t in_len,
int padding) {
531 const unsigned rsa_size =
RSA_size(rsa);
535 if (max_out < rsa_size) {
551 if (in_len != rsa_size) {
568 rsa_size, NULL, 0, NULL, NULL);
597 const uint8_t *
in,
size_t in_len,
int padding) {
602 const unsigned rsa_size =
RSA_size(rsa);
605 if (max_out < rsa_size) {
610 if (in_len != rsa_size) {
626 if (
f == NULL ||
result == NULL) {
691 if (rsa->
n == NULL || rsa->
d == NULL) {
698 unsigned blinding_index = 0;
710 if (
f == NULL ||
result == NULL) {
732 if (rsa->
e == NULL && do_blinding) {
743 if (blinding == NULL) {
752 if (rsa->
p != NULL && rsa->
q != NULL && rsa->
e != NULL && rsa->
dmp1 != NULL &&
753 rsa->
dmq1 != NULL && rsa->
iqmp != NULL &&
777 if (rsa->
e != NULL) {
811 if (blinding != NULL) {
852 assert(rsa->
n != NULL);
853 assert(rsa->
e != NULL);
854 assert(rsa->
d != NULL);
855 assert(rsa->
p != NULL);
856 assert(rsa->
q != NULL);
857 assert(rsa->
dmp1 != NULL);
858 assert(rsa->
dmq1 != NULL);
859 assert(rsa->
iqmp != NULL);
892 const BIGNUM *q = &mont_q->N;
986 TOBN(0x4d7c60a5, 0xe633e3e1), TOBN(0x5fcf8f7b, 0xca3ea33b),
987 TOBN(0xc246785e, 0x92957023), TOBN(0xf9acce41, 0x797f2805),
988 TOBN(0xfdfe170f, 0xd3b1f780), TOBN(0xd24f4a76, 0x3facb882),
989 TOBN(0x18838a2e, 0xaff5f3b2), TOBN(0xc1fcbdde, 0xa2f7dc33),
990 TOBN(0xdea06241, 0xf7aa81c2), TOBN(0xf6a1be3f, 0xca221307),
991 TOBN(0x332a5e9f, 0x7bda1ebf), TOBN(0x0104dc01, 0xfe32352f),
992 TOBN(0xb8cf341b, 0x6f8236c7), TOBN(0x4264dabc, 0xd528b651),
993 TOBN(0xf4d3a02c, 0xebc93e0c), TOBN(0x81394ab6, 0xd8fd0efd),
994 TOBN(0xeaa4a089, 0x9040ca4a), TOBN(0xf52f120f, 0x836e582e),
995 TOBN(0xcb2a6343, 0x31f3c84d), TOBN(0xc6d5a8a3, 0x8bb7e9dc),
996 TOBN(0x460abc72, 0x2f7c4e33), TOBN(0xcab1bc91, 0x1688458a),
997 TOBN(0x53059c60, 0x11bc337b), TOBN(0xd2202e87, 0x42af1f4e),
998 TOBN(0x78048736, 0x3dfa2768), TOBN(0x0f74a85e, 0x439c7b4a),
999 TOBN(0xa8b1fe6f, 0xdc83db39), TOBN(0x4afc8304, 0x3ab8a2c3),
1000 TOBN(0xed17ac85, 0x83339915), TOBN(0x1d6f60ba, 0x893ba84c),
1001 TOBN(0x597d89b3, 0x754abe9f), TOBN(0xb504f333, 0xf9de6484),
1015 if (
bits < 128 || (
bits % BN_BITS2) != 0) {
1052 if (
bits >= INT_MAX/32) {
1058 int ret = 0, tries = 0, rand_tries = 0;
1099 int relatively_prime;
1104 if (relatively_prime) {
1106 int is_probable_prime;
1111 if (is_probable_prime) {
1121 if (tries >= limit) {
1169 int prime_bits =
bits / 2;
1181 if (totient == NULL || pm1 == NULL || qm1 == NULL || sqrt2 == NULL ||
1182 pow2_prime_bits_100 == NULL || pow2_prime_bits == NULL ||
1183 !
BN_set_bit(pow2_prime_bits_100, prime_bits - 100) ||
1209 if (sqrt2_bits > prime_bits) {
1212 if (!
BN_rshift(sqrt2, sqrt2, sqrt2_bits - prime_bits)) {
1215 }
else if (prime_bits > sqrt2_bits) {
1219 !
BN_lshift(sqrt2, sqrt2, prime_bits - sqrt2_bits)) {
1232 pow2_prime_bits_100,
ctx,
cb) ||
1235 pow2_prime_bits_100,
ctx,
cb) ||
1263 }
while (
BN_cmp(rsa->
d, pow2_prime_bits) <= 0);
1377 &
tmp->inv_small_mod_large_mont);
1403 int ret = e != NULL &&
1415 out->common.is_static = 1;
#define BN_MONT_CTX_new_consttime
#define RSA_R_VALUE_MISSING
const RSA_METHOD * RSA_default_method(void)
#define bn_set_minimal_width
int RSA_encrypt(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out, const uint8_t *in, size_t in_len, int padding)
#define CRYPTO_get_fork_generation
return memset(p, 0, total)
static void rsa_blinding_release(RSA *rsa, BN_BLINDING *blinding, unsigned blinding_index)
#define BN_primality_test
#define bn_mod_sub_consttime
#define OPENSSL_PUT_ERROR(library, reason)
static int copy(grpc_slice_buffer *input, grpc_slice_buffer *output)
#define OPENSSL_ARRAY_SIZE(array)
static void replace_bn_mont_ctx(BN_MONT_CTX **out, BN_MONT_CTX **in)
static BN_BLINDING * rsa_blinding_get(RSA *rsa, unsigned *index_used, BN_CTX *ctx)
#define CRYPTO_MUTEX_unlock_read
int rsa_default_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)
static void * OPENSSL_memchr(const void *s, int c, size_t n)
#define RSA_padding_add_PKCS1_type_1
#define CONSTTIME_DECLASSIFY(x, y)
#define BN_GENCB_GENERATED
#define RSA_R_NO_PUBLIC_EXPONENT
int rsa_default_decrypt(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out, const uint8_t *in, size_t in_len, int padding)
#define RSA_R_BAD_E_VALUE
size_t rsa_default_size(const RSA *rsa)
#define RSA_R_INTERNAL_ERROR
static void * OPENSSL_memset(void *dst, int c, size_t n)
#define RSA_R_DATA_LEN_NOT_EQUAL_TO_MOD_LEN
std::atomic< uint64_t > failures
const OPENSSL_EXPORT BIGNUM * BN_value_one(void)
#define RSA_R_OUTPUT_BUFFER_TOO_SMALL
#define RSA_PKCS1_PADDING
static int rsa_generate_key_impl(RSA *rsa, int bits, const BIGNUM *e_value, BN_GENCB *cb)
int rsa_default_private_transform(RSA *rsa, uint8_t *out, const uint8_t *in, size_t len)
#define MAX_BLINDINGS_PER_RSA
#define bn_uadd_consttime
#define ERR_GET_REASON(packed_error)
int rsa_check_public_key(const RSA *rsa)
BIGNUM * inv_small_mod_large_mont
#define RSA_R_KEY_SIZE_TOO_SMALL
#define bn_usub_consttime
DEFINE_METHOD_FUNCTION(RSA_METHOD, RSA_default_method)
#define RSA_R_UNKNOWN_PADDING_TYPE
unsigned __int64 uint64_t
static void * OPENSSL_memcpy(void *dst, const void *src, size_t n)
#define ERR_GET_LIB(packed_error)
OPENSSL_EXPORT ASN1_BIT_STRING * bits
#define RSA_padding_check_PKCS1_OAEP_mgf1
static int ensure_bignum(BIGNUM **out)
#define ERR_R_INTERNAL_ERROR
static int mod_montgomery(BIGNUM *r, const BIGNUM *I, const BIGNUM *p, const BN_MONT_CTX *mont_p, const BIGNUM *q, BN_CTX *ctx)
#define RSA_R_PADDING_CHECK_FAILED
#define RSA_R_DATA_TOO_LARGE_FOR_MODULUS
#define bn_mod_inverse_consttime
#define BN_RAND_BOTTOM_ODD
#define RSA_R_BAD_RSA_PARAMETERS
#define RSA_padding_check_PKCS1_type_1
#define bn_mod_inverse_secret_prime
#define RSA_padding_check_PKCS1_type_2
const size_t kBoringSSLRSASqrtTwoLen
#define RSA_R_TOO_MANY_ITERATIONS
#define bn_odd_number_is_obviously_composite
#define BN_MONT_CTX_set_locked
#define BN_MONT_CTX_new_for_modulus
unsigned char * blindings_inuse
int RSA_generate_key_fips(RSA *rsa, int bits, BN_GENCB *cb)
#define RSA_FLAG_NO_BLINDING
#define CRYPTO_MUTEX_lock_read
#define BN_BLINDING_convert
static int RSA_generate_key_ex_maybe_fips(RSA *rsa, int bits, const BIGNUM *e_value, BN_GENCB *cb, int check_fips)
#define RSA_padding_add_PKCS1_type_2
static int freeze_private_key(RSA *rsa, BN_CTX *ctx)
static int ensure_fixed_copy(BIGNUM **out, const BIGNUM *in, int width)
#define RSA_R_MODULUS_TOO_LARGE
static int generate_prime(BIGNUM *out, int bits, const BIGNUM *e, const BIGNUM *p, const BIGNUM *sqrt2, const BIGNUM *pow2_bits_100, BN_CTX *ctx, BN_GENCB *cb)
uint64_t blinding_fork_generation
#define RSA_PKCS1_OAEP_PADDING
UniquePtr< SSL_SESSION > ret
#define RSA_private_transform
#define CRYPTO_MUTEX_lock_write
static void replace_bignum(BIGNUM **out, BIGNUM **in)
#define BN_mod_exp_mont_consttime
unsigned private_key_frozen
#define BN_equal_consttime
#define bn_abs_sub_consttime
#define CONSTTIME_SECRET(x, y)
int RSA_verify_raw(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out, const uint8_t *in, size_t in_len, int padding)
int RSA_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e_value, BN_GENCB *cb)
#define BN_mod_mul_montgomery
#define BN_BLINDING_invalidate
#define CRYPTO_MUTEX_unlock_write
#define BN_from_montgomery
#define RSA_padding_add_PKCS1_OAEP_mgf1
OPENSSL_EXPORT pem_password_cb * cb
#define BN_BLINDING_invert
const BN_ULONG kBoringSSLRSASqrtTwo[]
#define OPENSSL_STATIC_ASSERT(cond, msg)
#define bn_is_relatively_prime
#define ERR_R_MALLOC_FAILURE
#define RSA_padding_add_none
static int mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
#define BN_prime_checks_for_generation
#define bn_less_than_montgomery_R
grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:13