Lines Matching refs:rsa
79 RSA *rsa = OPENSSL_malloc(sizeof(RSA)); in RSA_new_method() local
80 if (rsa == NULL) { in RSA_new_method()
85 OPENSSL_memset(rsa, 0, sizeof(RSA)); in RSA_new_method()
88 rsa->meth = ENGINE_get_RSA_method(engine); in RSA_new_method()
91 if (rsa->meth == NULL) { in RSA_new_method()
92 rsa->meth = (RSA_METHOD*) &RSA_default_method; in RSA_new_method()
94 METHOD_ref(rsa->meth); in RSA_new_method()
96 rsa->references = 1; in RSA_new_method()
97 rsa->flags = rsa->meth->flags; in RSA_new_method()
98 CRYPTO_MUTEX_init(&rsa->lock); in RSA_new_method()
99 CRYPTO_new_ex_data(&rsa->ex_data); in RSA_new_method()
101 if (rsa->meth->init && !rsa->meth->init(rsa)) { in RSA_new_method()
102 CRYPTO_free_ex_data(&g_ex_data_class, rsa, &rsa->ex_data); in RSA_new_method()
103 CRYPTO_MUTEX_cleanup(&rsa->lock); in RSA_new_method()
104 METHOD_unref(rsa->meth); in RSA_new_method()
105 OPENSSL_free(rsa); in RSA_new_method()
109 return rsa; in RSA_new_method()
125 void RSA_free(RSA *rsa) { in RSA_free() argument
128 if (rsa == NULL) { in RSA_free()
132 if (!CRYPTO_refcount_dec_and_test_zero(&rsa->references)) { in RSA_free()
136 if (rsa->meth->finish) { in RSA_free()
137 rsa->meth->finish(rsa); in RSA_free()
139 METHOD_unref(rsa->meth); in RSA_free()
141 CRYPTO_free_ex_data(&g_ex_data_class, rsa, &rsa->ex_data); in RSA_free()
143 BN_clear_free(rsa->n); in RSA_free()
144 BN_clear_free(rsa->e); in RSA_free()
145 BN_clear_free(rsa->d); in RSA_free()
146 BN_clear_free(rsa->p); in RSA_free()
147 BN_clear_free(rsa->q); in RSA_free()
148 BN_clear_free(rsa->dmp1); in RSA_free()
149 BN_clear_free(rsa->dmq1); in RSA_free()
150 BN_clear_free(rsa->iqmp); in RSA_free()
151 BN_MONT_CTX_free(rsa->mont_n); in RSA_free()
152 BN_MONT_CTX_free(rsa->mont_p); in RSA_free()
153 BN_MONT_CTX_free(rsa->mont_q); in RSA_free()
154 for (u = 0; u < rsa->num_blindings; u++) { in RSA_free()
155 BN_BLINDING_free(rsa->blindings[u]); in RSA_free()
157 OPENSSL_free(rsa->blindings); in RSA_free()
158 OPENSSL_free(rsa->blindings_inuse); in RSA_free()
159 if (rsa->additional_primes != NULL) { in RSA_free()
160 sk_RSA_additional_prime_pop_free(rsa->additional_primes, in RSA_free()
163 CRYPTO_MUTEX_cleanup(&rsa->lock); in RSA_free()
164 OPENSSL_free(rsa); in RSA_free()
167 int RSA_up_ref(RSA *rsa) { in RSA_up_ref() argument
168 CRYPTO_refcount_inc(&rsa->references); in RSA_up_ref()
172 void RSA_get0_key(const RSA *rsa, const BIGNUM **out_n, const BIGNUM **out_e, in RSA_get0_key() argument
175 *out_n = rsa->n; in RSA_get0_key()
178 *out_e = rsa->e; in RSA_get0_key()
181 *out_d = rsa->d; in RSA_get0_key()
185 void RSA_get0_factors(const RSA *rsa, const BIGNUM **out_p, in RSA_get0_factors() argument
188 *out_p = rsa->p; in RSA_get0_factors()
191 *out_q = rsa->q; in RSA_get0_factors()
195 void RSA_get0_crt_params(const RSA *rsa, const BIGNUM **out_dmp1, in RSA_get0_crt_params() argument
198 *out_dmp1 = rsa->dmp1; in RSA_get0_crt_params()
201 *out_dmq1 = rsa->dmq1; in RSA_get0_crt_params()
204 *out_iqmp = rsa->iqmp; in RSA_get0_crt_params()
208 int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb) { in RSA_generate_key_ex() argument
209 if (rsa->meth->keygen) { in RSA_generate_key_ex()
210 return rsa->meth->keygen(rsa, bits, e_value, cb); in RSA_generate_key_ex()
213 return rsa_default_keygen(rsa, bits, e_value, cb); in RSA_generate_key_ex()
216 int RSA_generate_multi_prime_key(RSA *rsa, int bits, int num_primes, in RSA_generate_multi_prime_key() argument
218 if (rsa->meth->multi_prime_keygen) { in RSA_generate_multi_prime_key()
219 return rsa->meth->multi_prime_keygen(rsa, bits, num_primes, e_value, cb); in RSA_generate_multi_prime_key()
222 return rsa_default_multi_prime_keygen(rsa, bits, num_primes, e_value, cb); in RSA_generate_multi_prime_key()
225 int RSA_encrypt(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out, in RSA_encrypt() argument
227 if (rsa->meth->encrypt) { in RSA_encrypt()
228 return rsa->meth->encrypt(rsa, out_len, out, max_out, in, in_len, padding); in RSA_encrypt()
231 return rsa_default_encrypt(rsa, out_len, out, max_out, in, in_len, padding); in RSA_encrypt()
234 int RSA_public_encrypt(size_t flen, const uint8_t *from, uint8_t *to, RSA *rsa, in RSA_public_encrypt() argument
238 if (!RSA_encrypt(rsa, &out_len, to, RSA_size(rsa), from, flen, padding)) { in RSA_public_encrypt()
249 int RSA_sign_raw(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out, in RSA_sign_raw() argument
251 if (rsa->meth->sign_raw) { in RSA_sign_raw()
252 return rsa->meth->sign_raw(rsa, out_len, out, max_out, in, in_len, padding); in RSA_sign_raw()
255 return rsa_default_sign_raw(rsa, out_len, out, max_out, in, in_len, padding); in RSA_sign_raw()
258 int RSA_private_encrypt(size_t flen, const uint8_t *from, uint8_t *to, RSA *rsa, in RSA_private_encrypt() argument
262 if (!RSA_sign_raw(rsa, &out_len, to, RSA_size(rsa), from, flen, padding)) { in RSA_private_encrypt()
273 int RSA_decrypt(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out, in RSA_decrypt() argument
275 if (rsa->meth->decrypt) { in RSA_decrypt()
276 return rsa->meth->decrypt(rsa, out_len, out, max_out, in, in_len, padding); in RSA_decrypt()
279 return rsa_default_decrypt(rsa, out_len, out, max_out, in, in_len, padding); in RSA_decrypt()
282 int RSA_private_decrypt(size_t flen, const uint8_t *from, uint8_t *to, RSA *rsa, in RSA_private_decrypt() argument
286 if (!RSA_decrypt(rsa, &out_len, to, RSA_size(rsa), from, flen, padding)) { in RSA_private_decrypt()
297 int RSA_public_decrypt(size_t flen, const uint8_t *from, uint8_t *to, RSA *rsa, in RSA_public_decrypt() argument
301 if (!RSA_verify_raw(rsa, &out_len, to, RSA_size(rsa), from, flen, padding)) { in RSA_public_decrypt()
312 unsigned RSA_size(const RSA *rsa) { in RSA_size() argument
313 if (rsa->meth->size) { in RSA_size()
314 return rsa->meth->size(rsa); in RSA_size()
317 return rsa_default_size(rsa); in RSA_size()
320 int RSA_is_opaque(const RSA *rsa) { in RSA_is_opaque() argument
321 return rsa->meth && (rsa->meth->flags & RSA_FLAG_OPAQUE); in RSA_is_opaque()
324 int RSA_supports_digest(const RSA *rsa, const EVP_MD *md) { in RSA_supports_digest() argument
325 if (rsa->meth && rsa->meth->supports_digest) { in RSA_supports_digest()
326 return rsa->meth->supports_digest(rsa, md); in RSA_supports_digest()
464 unsigned *out_len, RSA *rsa) { in RSA_sign() argument
465 const unsigned rsa_size = RSA_size(rsa); in RSA_sign()
472 if (rsa->meth->sign) { in RSA_sign()
473 return rsa->meth->sign(hash_nid, in, in_len, out, out_len, rsa); in RSA_sign()
487 if (RSA_sign_raw(rsa, &size_t_out_len, out, rsa_size, signed_msg, in RSA_sign()
501 const uint8_t *sig, size_t sig_len, RSA *rsa) { in RSA_verify() argument
502 if (rsa->n == NULL || rsa->e == NULL) { in RSA_verify()
507 const size_t rsa_size = RSA_size(rsa); in RSA_verify()
525 if (!RSA_verify_raw(rsa, &len, buf, rsa_size, sig, sig_len, in RSA_verify()
686 int RSA_recover_crt_params(RSA *rsa) { in RSA_recover_crt_params() argument
691 if (rsa->n == NULL || rsa->e == NULL || rsa->d == NULL) { in RSA_recover_crt_params()
696 if (rsa->p || rsa->q || rsa->dmp1 || rsa->dmq1 || rsa->iqmp) { in RSA_recover_crt_params()
701 if (rsa->additional_primes != NULL) { in RSA_recover_crt_params()
729 if (!BN_mul(totient, rsa->e, rsa->d, ctx) || in RSA_recover_crt_params()
749 !BN_div(multiple, NULL, totient, rsa->n, ctx) || in RSA_recover_crt_params()
761 rsa->p = BN_new(); in RSA_recover_crt_params()
762 rsa->q = BN_new(); in RSA_recover_crt_params()
763 rsa->dmp1 = BN_new(); in RSA_recover_crt_params()
764 rsa->dmq1 = BN_new(); in RSA_recover_crt_params()
765 rsa->iqmp = BN_new(); in RSA_recover_crt_params()
766 if (rsa->p == NULL || rsa->q == NULL || rsa->dmp1 == NULL || rsa->dmq1 == in RSA_recover_crt_params()
767 NULL || rsa->iqmp == NULL) { in RSA_recover_crt_params()
774 if (!BN_sub(p_plus_q, rsa->n, totient) || in RSA_recover_crt_params()
778 !BN_lshift(multiple, rsa->n, 2) || in RSA_recover_crt_params()
782 !BN_sub(rsa->q, p_plus_q, p_minus_q) || in RSA_recover_crt_params()
783 !BN_rshift1(rsa->q, rsa->q) || in RSA_recover_crt_params()
784 !BN_div(rsa->p, NULL, rsa->n, rsa->q, ctx) || in RSA_recover_crt_params()
785 !BN_mul(multiple, rsa->p, rsa->q, ctx)) { in RSA_recover_crt_params()
790 if (BN_cmp(multiple, rsa->n) != 0) { in RSA_recover_crt_params()
795 if (!BN_sub(rem, rsa->p, BN_value_one()) || in RSA_recover_crt_params()
796 !BN_mod(rsa->dmp1, rsa->d, rem, ctx) || in RSA_recover_crt_params()
797 !BN_sub(rem, rsa->q, BN_value_one()) || in RSA_recover_crt_params()
798 !BN_mod(rsa->dmq1, rsa->d, rem, ctx) || in RSA_recover_crt_params()
799 !BN_mod_inverse(rsa->iqmp, rsa->q, rsa->p, ctx)) { in RSA_recover_crt_params()
810 bn_free_and_null(&rsa->p); in RSA_recover_crt_params()
811 bn_free_and_null(&rsa->q); in RSA_recover_crt_params()
812 bn_free_and_null(&rsa->dmp1); in RSA_recover_crt_params()
813 bn_free_and_null(&rsa->dmq1); in RSA_recover_crt_params()
814 bn_free_and_null(&rsa->iqmp); in RSA_recover_crt_params()
819 int RSA_private_transform(RSA *rsa, uint8_t *out, const uint8_t *in, in RSA_private_transform() argument
821 if (rsa->meth->private_transform) { in RSA_private_transform()
822 return rsa->meth->private_transform(rsa, out, in, len); in RSA_private_transform()
825 return rsa_default_private_transform(rsa, out, in, len); in RSA_private_transform()
828 int RSA_blinding_on(RSA *rsa, BN_CTX *ctx) { in RSA_blinding_on() argument