You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. /*
  2. * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (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. #ifndef OPENSSL_RSA_H
  10. #define OPENSSL_RSA_H
  11. #pragma once
  12. #include <openssl/macros.h>
  13. #ifndef OPENSSL_NO_DEPRECATED_3_0
  14. #define HEADER_RSA_H
  15. #endif
  16. #include <openssl/opensslconf.h>
  17. #include <openssl/asn1.h>
  18. #include <openssl/bio.h>
  19. #include <openssl/crypto.h>
  20. #include <openssl/types.h>
  21. #ifndef OPENSSL_NO_DEPRECATED_1_1_0
  22. #include <openssl/bn.h>
  23. #endif
  24. #include <openssl/rsaerr.h>
  25. #include <openssl/safestack.h>
  26. #ifdef __cplusplus
  27. extern "C"
  28. {
  29. #endif
  30. #ifndef OPENSSL_RSA_MAX_MODULUS_BITS
  31. #define OPENSSL_RSA_MAX_MODULUS_BITS 16384
  32. #endif
  33. #define RSA_3 0x3L
  34. #define RSA_F4 0x10001L
  35. #ifndef OPENSSL_NO_DEPRECATED_3_0
  36. /* The types RSA and RSA_METHOD are defined in ossl_typ.h */
  37. #define OPENSSL_RSA_FIPS_MIN_MODULUS_BITS 2048
  38. #ifndef OPENSSL_RSA_SMALL_MODULUS_BITS
  39. #define OPENSSL_RSA_SMALL_MODULUS_BITS 3072
  40. #endif
  41. /* exponent limit enforced for "large" modulus only */
  42. #ifndef OPENSSL_RSA_MAX_PUBEXP_BITS
  43. #define OPENSSL_RSA_MAX_PUBEXP_BITS 64
  44. #endif
  45. /* based on RFC 8017 appendix A.1.2 */
  46. #define RSA_ASN1_VERSION_DEFAULT 0
  47. #define RSA_ASN1_VERSION_MULTI 1
  48. #define RSA_DEFAULT_PRIME_NUM 2
  49. #define RSA_METHOD_FLAG_NO_CHECK 0x0001
  50. #define RSA_FLAG_CACHE_PUBLIC 0x0002
  51. #define RSA_FLAG_CACHE_PRIVATE 0x0004
  52. #define RSA_FLAG_BLINDING 0x0008
  53. #define RSA_FLAG_THREAD_SAFE 0x0010
  54. /*
  55. * This flag means the private key operations will be handled by rsa_mod_exp
  56. * and that they do not depend on the private key components being present:
  57. * for example a key stored in external hardware. Without this flag
  58. * bn_mod_exp gets called when private key components are absent.
  59. */
  60. #define RSA_FLAG_EXT_PKEY 0x0020
  61. /*
  62. * new with 0.9.6j and 0.9.7b; the built-in
  63. * RSA implementation now uses blinding by
  64. * default (ignoring RSA_FLAG_BLINDING),
  65. * but other engines might not need it
  66. */
  67. #define RSA_FLAG_NO_BLINDING 0x0080
  68. #endif /* OPENSSL_NO_DEPRECATED_3_0 */
  69. /*
  70. * Does nothing. Previously this switched off constant time behaviour.
  71. */
  72. #ifndef OPENSSL_NO_DEPRECATED_1_1_0
  73. #define RSA_FLAG_NO_CONSTTIME 0x0000
  74. #endif
  75. /* deprecated name for the flag*/
  76. /*
  77. * new with 0.9.7h; the built-in RSA
  78. * implementation now uses constant time
  79. * modular exponentiation for secret exponents
  80. * by default. This flag causes the
  81. * faster variable sliding window method to
  82. * be used for all exponents.
  83. */
  84. #ifndef OPENSSL_NO_DEPRECATED_0_9_8
  85. #define RSA_FLAG_NO_EXP_CONSTTIME RSA_FLAG_NO_CONSTTIME
  86. #endif
  87. /*-
  88. * New with 3.0: use part of the flags to denote exact type of RSA key,
  89. * some of which are limited to specific signature and encryption schemes.
  90. * These different types share the same RSA structure, but indicate the
  91. * use of certain fields in that structure.
  92. * Currently known are:
  93. * RSA - this is the "normal" unlimited RSA structure (typenum 0)
  94. * RSASSA-PSS - indicates that the PSS parameters are used.
  95. * RSAES-OAEP - no specific field used for the moment, but OAEP padding
  96. * is expected. (currently unused)
  97. *
  98. * 4 bits allow for 16 types
  99. */
  100. #define RSA_FLAG_TYPE_MASK 0xF000
  101. #define RSA_FLAG_TYPE_RSA 0x0000
  102. #define RSA_FLAG_TYPE_RSASSAPSS 0x1000
  103. #define RSA_FLAG_TYPE_RSAESOAEP 0x2000
  104. int EVP_PKEY_CTX_set_rsa_padding(EVP_PKEY_CTX* ctx, int pad_mode);
  105. int EVP_PKEY_CTX_get_rsa_padding(EVP_PKEY_CTX* ctx, int* pad_mode);
  106. int EVP_PKEY_CTX_set_rsa_pss_saltlen(EVP_PKEY_CTX* ctx, int saltlen);
  107. int EVP_PKEY_CTX_get_rsa_pss_saltlen(EVP_PKEY_CTX* ctx, int* saltlen);
  108. int EVP_PKEY_CTX_set_rsa_keygen_bits(EVP_PKEY_CTX* ctx, int bits);
  109. int EVP_PKEY_CTX_set1_rsa_keygen_pubexp(EVP_PKEY_CTX* ctx, BIGNUM* pubexp);
  110. int EVP_PKEY_CTX_set_rsa_keygen_primes(EVP_PKEY_CTX* ctx, int primes);
  111. int EVP_PKEY_CTX_set_rsa_pss_keygen_saltlen(EVP_PKEY_CTX* ctx, int saltlen);
  112. #ifndef OPENSSL_NO_DEPRECATED_3_0
  113. OSSL_DEPRECATEDIN_3_0
  114. int EVP_PKEY_CTX_set_rsa_keygen_pubexp(EVP_PKEY_CTX* ctx, BIGNUM* pubexp);
  115. #endif
  116. /* Salt length matches digest */
  117. #define RSA_PSS_SALTLEN_DIGEST -1
  118. /* Verify only: auto detect salt length */
  119. #define RSA_PSS_SALTLEN_AUTO -2
  120. /* Set salt length to maximum possible */
  121. #define RSA_PSS_SALTLEN_MAX -3
  122. /* Old compatible max salt length for sign only */
  123. #define RSA_PSS_SALTLEN_MAX_SIGN -2
  124. int EVP_PKEY_CTX_set_rsa_mgf1_md(EVP_PKEY_CTX* ctx, const EVP_MD* md);
  125. int EVP_PKEY_CTX_set_rsa_mgf1_md_name(EVP_PKEY_CTX* ctx, const char* mdname, const char* mdprops);
  126. int EVP_PKEY_CTX_get_rsa_mgf1_md(EVP_PKEY_CTX* ctx, const EVP_MD** md);
  127. int EVP_PKEY_CTX_get_rsa_mgf1_md_name(EVP_PKEY_CTX* ctx, char* name, size_t namelen);
  128. int EVP_PKEY_CTX_set_rsa_pss_keygen_mgf1_md(EVP_PKEY_CTX* ctx, const EVP_MD* md);
  129. int EVP_PKEY_CTX_set_rsa_pss_keygen_mgf1_md_name(EVP_PKEY_CTX* ctx, const char* mdname);
  130. int EVP_PKEY_CTX_set_rsa_pss_keygen_md(EVP_PKEY_CTX* ctx, const EVP_MD* md);
  131. int EVP_PKEY_CTX_set_rsa_pss_keygen_md_name(EVP_PKEY_CTX* ctx, const char* mdname, const char* mdprops);
  132. int EVP_PKEY_CTX_set_rsa_oaep_md(EVP_PKEY_CTX* ctx, const EVP_MD* md);
  133. int EVP_PKEY_CTX_set_rsa_oaep_md_name(EVP_PKEY_CTX* ctx, const char* mdname, const char* mdprops);
  134. int EVP_PKEY_CTX_get_rsa_oaep_md(EVP_PKEY_CTX* ctx, const EVP_MD** md);
  135. int EVP_PKEY_CTX_get_rsa_oaep_md_name(EVP_PKEY_CTX* ctx, char* name, size_t namelen);
  136. int EVP_PKEY_CTX_set0_rsa_oaep_label(EVP_PKEY_CTX* ctx, void* label, int llen);
  137. int EVP_PKEY_CTX_get0_rsa_oaep_label(EVP_PKEY_CTX* ctx, unsigned char** label);
  138. #define EVP_PKEY_CTRL_RSA_PADDING (EVP_PKEY_ALG_CTRL + 1)
  139. #define EVP_PKEY_CTRL_RSA_PSS_SALTLEN (EVP_PKEY_ALG_CTRL + 2)
  140. #define EVP_PKEY_CTRL_RSA_KEYGEN_BITS (EVP_PKEY_ALG_CTRL + 3)
  141. #define EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP (EVP_PKEY_ALG_CTRL + 4)
  142. #define EVP_PKEY_CTRL_RSA_MGF1_MD (EVP_PKEY_ALG_CTRL + 5)
  143. #define EVP_PKEY_CTRL_GET_RSA_PADDING (EVP_PKEY_ALG_CTRL + 6)
  144. #define EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN (EVP_PKEY_ALG_CTRL + 7)
  145. #define EVP_PKEY_CTRL_GET_RSA_MGF1_MD (EVP_PKEY_ALG_CTRL + 8)
  146. #define EVP_PKEY_CTRL_RSA_OAEP_MD (EVP_PKEY_ALG_CTRL + 9)
  147. #define EVP_PKEY_CTRL_RSA_OAEP_LABEL (EVP_PKEY_ALG_CTRL + 10)
  148. #define EVP_PKEY_CTRL_GET_RSA_OAEP_MD (EVP_PKEY_ALG_CTRL + 11)
  149. #define EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL (EVP_PKEY_ALG_CTRL + 12)
  150. #define EVP_PKEY_CTRL_RSA_KEYGEN_PRIMES (EVP_PKEY_ALG_CTRL + 13)
  151. #define RSA_PKCS1_PADDING 1
  152. #define RSA_NO_PADDING 3
  153. #define RSA_PKCS1_OAEP_PADDING 4
  154. #define RSA_X931_PADDING 5
  155. /* EVP_PKEY_ only */
  156. #define RSA_PKCS1_PSS_PADDING 6
  157. #define RSA_PKCS1_WITH_TLS_PADDING 7
  158. #define RSA_PKCS1_PADDING_SIZE 11
  159. #define RSA_set_app_data(s, arg) RSA_set_ex_data(s, 0, arg)
  160. #define RSA_get_app_data(s) RSA_get_ex_data(s, 0)
  161. #ifndef OPENSSL_NO_DEPRECATED_3_0
  162. OSSL_DEPRECATEDIN_3_0 RSA* RSA_new(void);
  163. OSSL_DEPRECATEDIN_3_0 RSA* RSA_new_method(ENGINE* engine);
  164. OSSL_DEPRECATEDIN_3_0 int RSA_bits(const RSA* rsa);
  165. OSSL_DEPRECATEDIN_3_0 int RSA_size(const RSA* rsa);
  166. OSSL_DEPRECATEDIN_3_0 int RSA_security_bits(const RSA* rsa);
  167. OSSL_DEPRECATEDIN_3_0 int RSA_set0_key(RSA* r, BIGNUM* n, BIGNUM* e, BIGNUM* d);
  168. OSSL_DEPRECATEDIN_3_0 int RSA_set0_factors(RSA* r, BIGNUM* p, BIGNUM* q);
  169. OSSL_DEPRECATEDIN_3_0 int RSA_set0_crt_params(RSA* r, BIGNUM* dmp1, BIGNUM* dmq1, BIGNUM* iqmp);
  170. OSSL_DEPRECATEDIN_3_0 int RSA_set0_multi_prime_params(RSA* r, BIGNUM* primes[], BIGNUM* exps[], BIGNUM* coeffs[], int pnum);
  171. OSSL_DEPRECATEDIN_3_0 void RSA_get0_key(const RSA* r, const BIGNUM** n, const BIGNUM** e, const BIGNUM** d);
  172. OSSL_DEPRECATEDIN_3_0 void RSA_get0_factors(const RSA* r, const BIGNUM** p, const BIGNUM** q);
  173. OSSL_DEPRECATEDIN_3_0 int RSA_get_multi_prime_extra_count(const RSA* r);
  174. OSSL_DEPRECATEDIN_3_0 int RSA_get0_multi_prime_factors(const RSA* r, const BIGNUM* primes[]);
  175. OSSL_DEPRECATEDIN_3_0 void RSA_get0_crt_params(const RSA* r, const BIGNUM** dmp1, const BIGNUM** dmq1, const BIGNUM** iqmp);
  176. OSSL_DEPRECATEDIN_3_0
  177. int RSA_get0_multi_prime_crt_params(const RSA* r, const BIGNUM* exps[], const BIGNUM* coeffs[]);
  178. OSSL_DEPRECATEDIN_3_0 const BIGNUM* RSA_get0_n(const RSA* d);
  179. OSSL_DEPRECATEDIN_3_0 const BIGNUM* RSA_get0_e(const RSA* d);
  180. OSSL_DEPRECATEDIN_3_0 const BIGNUM* RSA_get0_d(const RSA* d);
  181. OSSL_DEPRECATEDIN_3_0 const BIGNUM* RSA_get0_p(const RSA* d);
  182. OSSL_DEPRECATEDIN_3_0 const BIGNUM* RSA_get0_q(const RSA* d);
  183. OSSL_DEPRECATEDIN_3_0 const BIGNUM* RSA_get0_dmp1(const RSA* r);
  184. OSSL_DEPRECATEDIN_3_0 const BIGNUM* RSA_get0_dmq1(const RSA* r);
  185. OSSL_DEPRECATEDIN_3_0 const BIGNUM* RSA_get0_iqmp(const RSA* r);
  186. OSSL_DEPRECATEDIN_3_0 const RSA_PSS_PARAMS* RSA_get0_pss_params(const RSA* r);
  187. OSSL_DEPRECATEDIN_3_0 void RSA_clear_flags(RSA* r, int flags);
  188. OSSL_DEPRECATEDIN_3_0 int RSA_test_flags(const RSA* r, int flags);
  189. OSSL_DEPRECATEDIN_3_0 void RSA_set_flags(RSA* r, int flags);
  190. OSSL_DEPRECATEDIN_3_0 int RSA_get_version(RSA* r);
  191. OSSL_DEPRECATEDIN_3_0 ENGINE* RSA_get0_engine(const RSA* r);
  192. #endif /* !OPENSSL_NO_DEPRECATED_3_0 */
  193. #define EVP_RSA_gen(bits) \
  194. EVP_PKEY_Q_keygen(NULL, NULL, "RSA", (size_t)(0 + (bits)))
  195. /* Deprecated version */
  196. #ifndef OPENSSL_NO_DEPRECATED_0_9_8
  197. OSSL_DEPRECATEDIN_0_9_8 RSA* RSA_generate_key(int bits, unsigned long e, void (*callback)(int, int, void*), void* cb_arg);
  198. #endif
  199. /* New version */
  200. #ifndef OPENSSL_NO_DEPRECATED_3_0
  201. OSSL_DEPRECATEDIN_3_0 int RSA_generate_key_ex(RSA* rsa, int bits, BIGNUM* e, BN_GENCB* cb);
  202. /* Multi-prime version */
  203. OSSL_DEPRECATEDIN_3_0 int RSA_generate_multi_prime_key(RSA* rsa, int bits, int primes, BIGNUM* e, BN_GENCB* cb);
  204. OSSL_DEPRECATEDIN_3_0
  205. int RSA_X931_derive_ex(RSA* rsa, BIGNUM* p1, BIGNUM* p2, BIGNUM* q1, BIGNUM* q2, const BIGNUM* Xp1, const BIGNUM* Xp2, const BIGNUM* Xp, const BIGNUM* Xq1, const BIGNUM* Xq2, const BIGNUM* Xq, const BIGNUM* e, BN_GENCB* cb);
  206. OSSL_DEPRECATEDIN_3_0 int RSA_X931_generate_key_ex(RSA* rsa, int bits, const BIGNUM* e, BN_GENCB* cb);
  207. OSSL_DEPRECATEDIN_3_0 int RSA_check_key(const RSA*);
  208. OSSL_DEPRECATEDIN_3_0 int RSA_check_key_ex(const RSA*, BN_GENCB* cb);
  209. /* next 4 return -1 on error */
  210. OSSL_DEPRECATEDIN_3_0
  211. int RSA_public_encrypt(int flen, const unsigned char* from, unsigned char* to, RSA* rsa, int padding);
  212. OSSL_DEPRECATEDIN_3_0
  213. int RSA_private_encrypt(int flen, const unsigned char* from, unsigned char* to, RSA* rsa, int padding);
  214. OSSL_DEPRECATEDIN_3_0
  215. int RSA_public_decrypt(int flen, const unsigned char* from, unsigned char* to, RSA* rsa, int padding);
  216. OSSL_DEPRECATEDIN_3_0
  217. int RSA_private_decrypt(int flen, const unsigned char* from, unsigned char* to, RSA* rsa, int padding);
  218. OSSL_DEPRECATEDIN_3_0 void RSA_free(RSA* r);
  219. /* "up" the RSA object's reference count */
  220. OSSL_DEPRECATEDIN_3_0 int RSA_up_ref(RSA* r);
  221. OSSL_DEPRECATEDIN_3_0 int RSA_flags(const RSA* r);
  222. OSSL_DEPRECATEDIN_3_0 void RSA_set_default_method(const RSA_METHOD* meth);
  223. OSSL_DEPRECATEDIN_3_0 const RSA_METHOD* RSA_get_default_method(void);
  224. OSSL_DEPRECATEDIN_3_0 const RSA_METHOD* RSA_null_method(void);
  225. OSSL_DEPRECATEDIN_3_0 const RSA_METHOD* RSA_get_method(const RSA* rsa);
  226. OSSL_DEPRECATEDIN_3_0 int RSA_set_method(RSA* rsa, const RSA_METHOD* meth);
  227. /* these are the actual RSA functions */
  228. OSSL_DEPRECATEDIN_3_0 const RSA_METHOD* RSA_PKCS1_OpenSSL(void);
  229. DECLARE_ASN1_ENCODE_FUNCTIONS_name_attr(OSSL_DEPRECATEDIN_3_0, RSA, RSAPublicKey)
  230. DECLARE_ASN1_ENCODE_FUNCTIONS_name_attr(OSSL_DEPRECATEDIN_3_0, RSA, RSAPrivateKey)
  231. #endif /* !OPENSSL_NO_DEPRECATED_3_0 */
  232. int RSA_pkey_ctx_ctrl(EVP_PKEY_CTX* ctx, int optype, int cmd, int p1, void* p2);
  233. struct rsa_pss_params_st
  234. {
  235. X509_ALGOR* hashAlgorithm;
  236. X509_ALGOR* maskGenAlgorithm;
  237. ASN1_INTEGER* saltLength;
  238. ASN1_INTEGER* trailerField;
  239. /* Decoded hash algorithm from maskGenAlgorithm */
  240. X509_ALGOR* maskHash;
  241. };
  242. DECLARE_ASN1_FUNCTIONS(RSA_PSS_PARAMS)
  243. DECLARE_ASN1_DUP_FUNCTION(RSA_PSS_PARAMS)
  244. typedef struct rsa_oaep_params_st
  245. {
  246. X509_ALGOR* hashFunc;
  247. X509_ALGOR* maskGenFunc;
  248. X509_ALGOR* pSourceFunc;
  249. /* Decoded hash algorithm from maskGenFunc */
  250. X509_ALGOR* maskHash;
  251. } RSA_OAEP_PARAMS;
  252. DECLARE_ASN1_FUNCTIONS(RSA_OAEP_PARAMS)
  253. #ifndef OPENSSL_NO_DEPRECATED_3_0
  254. #ifndef OPENSSL_NO_STDIO
  255. OSSL_DEPRECATEDIN_3_0 int RSA_print_fp(FILE* fp, const RSA* r, int offset);
  256. #endif
  257. OSSL_DEPRECATEDIN_3_0 int RSA_print(BIO* bp, const RSA* r, int offset);
  258. /*
  259. * The following 2 functions sign and verify a X509_SIG ASN1 object inside
  260. * PKCS#1 padded RSA encryption
  261. */
  262. OSSL_DEPRECATEDIN_3_0 int RSA_sign(int type, const unsigned char* m, unsigned int m_length, unsigned char* sigret, unsigned int* siglen, RSA* rsa);
  263. OSSL_DEPRECATEDIN_3_0 int RSA_verify(int type, const unsigned char* m, unsigned int m_length, const unsigned char* sigbuf, unsigned int siglen, RSA* rsa);
  264. /*
  265. * The following 2 function sign and verify a ASN1_OCTET_STRING object inside
  266. * PKCS#1 padded RSA encryption
  267. */
  268. OSSL_DEPRECATEDIN_3_0
  269. int RSA_sign_ASN1_OCTET_STRING(int type, const unsigned char* m, unsigned int m_length, unsigned char* sigret, unsigned int* siglen, RSA* rsa);
  270. OSSL_DEPRECATEDIN_3_0
  271. int RSA_verify_ASN1_OCTET_STRING(int type, const unsigned char* m, unsigned int m_length, unsigned char* sigbuf, unsigned int siglen, RSA* rsa);
  272. OSSL_DEPRECATEDIN_3_0 int RSA_blinding_on(RSA* rsa, BN_CTX* ctx);
  273. OSSL_DEPRECATEDIN_3_0 void RSA_blinding_off(RSA* rsa);
  274. OSSL_DEPRECATEDIN_3_0 BN_BLINDING* RSA_setup_blinding(RSA* rsa, BN_CTX* ctx);
  275. OSSL_DEPRECATEDIN_3_0
  276. int RSA_padding_add_PKCS1_type_1(unsigned char* to, int tlen, const unsigned char* f, int fl);
  277. OSSL_DEPRECATEDIN_3_0
  278. int RSA_padding_check_PKCS1_type_1(unsigned char* to, int tlen, const unsigned char* f, int fl, int rsa_len);
  279. OSSL_DEPRECATEDIN_3_0
  280. int RSA_padding_add_PKCS1_type_2(unsigned char* to, int tlen, const unsigned char* f, int fl);
  281. OSSL_DEPRECATEDIN_3_0
  282. int RSA_padding_check_PKCS1_type_2(unsigned char* to, int tlen, const unsigned char* f, int fl, int rsa_len);
  283. OSSL_DEPRECATEDIN_3_0 int PKCS1_MGF1(unsigned char* mask, long len, const unsigned char* seed, long seedlen, const EVP_MD* dgst);
  284. OSSL_DEPRECATEDIN_3_0
  285. int RSA_padding_add_PKCS1_OAEP(unsigned char* to, int tlen, const unsigned char* f, int fl, const unsigned char* p, int pl);
  286. OSSL_DEPRECATEDIN_3_0
  287. int RSA_padding_check_PKCS1_OAEP(unsigned char* to, int tlen, const unsigned char* f, int fl, int rsa_len, const unsigned char* p, int pl);
  288. OSSL_DEPRECATEDIN_3_0
  289. int RSA_padding_add_PKCS1_OAEP_mgf1(unsigned char* to, int tlen, const unsigned char* from, int flen, const unsigned char* param, int plen, const EVP_MD* md, const EVP_MD* mgf1md);
  290. OSSL_DEPRECATEDIN_3_0
  291. int RSA_padding_check_PKCS1_OAEP_mgf1(unsigned char* to, int tlen, const unsigned char* from, int flen, int num, const unsigned char* param, int plen, const EVP_MD* md, const EVP_MD* mgf1md);
  292. OSSL_DEPRECATEDIN_3_0 int RSA_padding_add_none(unsigned char* to, int tlen, const unsigned char* f, int fl);
  293. OSSL_DEPRECATEDIN_3_0 int RSA_padding_check_none(unsigned char* to, int tlen, const unsigned char* f, int fl, int rsa_len);
  294. OSSL_DEPRECATEDIN_3_0 int RSA_padding_add_X931(unsigned char* to, int tlen, const unsigned char* f, int fl);
  295. OSSL_DEPRECATEDIN_3_0 int RSA_padding_check_X931(unsigned char* to, int tlen, const unsigned char* f, int fl, int rsa_len);
  296. OSSL_DEPRECATEDIN_3_0 int RSA_X931_hash_id(int nid);
  297. OSSL_DEPRECATEDIN_3_0
  298. int RSA_verify_PKCS1_PSS(RSA* rsa, const unsigned char* mHash, const EVP_MD* Hash, const unsigned char* EM, int sLen);
  299. OSSL_DEPRECATEDIN_3_0
  300. int RSA_padding_add_PKCS1_PSS(RSA* rsa, unsigned char* EM, const unsigned char* mHash, const EVP_MD* Hash, int sLen);
  301. OSSL_DEPRECATEDIN_3_0
  302. int RSA_verify_PKCS1_PSS_mgf1(RSA* rsa, const unsigned char* mHash, const EVP_MD* Hash, const EVP_MD* mgf1Hash, const unsigned char* EM, int sLen);
  303. OSSL_DEPRECATEDIN_3_0
  304. int RSA_padding_add_PKCS1_PSS_mgf1(RSA* rsa, unsigned char* EM, const unsigned char* mHash, const EVP_MD* Hash, const EVP_MD* mgf1Hash, int sLen);
  305. #define RSA_get_ex_new_index(l, p, newf, dupf, freef) \
  306. CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_RSA, l, p, newf, dupf, freef)
  307. OSSL_DEPRECATEDIN_3_0 int RSA_set_ex_data(RSA* r, int idx, void* arg);
  308. OSSL_DEPRECATEDIN_3_0 void* RSA_get_ex_data(const RSA* r, int idx);
  309. DECLARE_ASN1_DUP_FUNCTION_name_attr(OSSL_DEPRECATEDIN_3_0, RSA, RSAPublicKey)
  310. DECLARE_ASN1_DUP_FUNCTION_name_attr(OSSL_DEPRECATEDIN_3_0, RSA, RSAPrivateKey)
  311. /*
  312. * If this flag is set the RSA method is FIPS compliant and can be used in
  313. * FIPS mode. This is set in the validated module method. If an application
  314. * sets this flag in its own methods it is its responsibility to ensure the
  315. * result is compliant.
  316. */
  317. #define RSA_FLAG_FIPS_METHOD 0x0400
  318. /*
  319. * If this flag is set the operations normally disabled in FIPS mode are
  320. * permitted it is then the applications responsibility to ensure that the
  321. * usage is compliant.
  322. */
  323. #define RSA_FLAG_NON_FIPS_ALLOW 0x0400
  324. /*
  325. * Application has decided PRNG is good enough to generate a key: don't
  326. * check.
  327. */
  328. #define RSA_FLAG_CHECKED 0x0800
  329. OSSL_DEPRECATEDIN_3_0 RSA_METHOD* RSA_meth_new(const char* name, int flags);
  330. OSSL_DEPRECATEDIN_3_0 void RSA_meth_free(RSA_METHOD* meth);
  331. OSSL_DEPRECATEDIN_3_0 RSA_METHOD* RSA_meth_dup(const RSA_METHOD* meth);
  332. OSSL_DEPRECATEDIN_3_0 const char* RSA_meth_get0_name(const RSA_METHOD* meth);
  333. OSSL_DEPRECATEDIN_3_0 int RSA_meth_set1_name(RSA_METHOD* meth, const char* name);
  334. OSSL_DEPRECATEDIN_3_0 int RSA_meth_get_flags(const RSA_METHOD* meth);
  335. OSSL_DEPRECATEDIN_3_0 int RSA_meth_set_flags(RSA_METHOD* meth, int flags);
  336. OSSL_DEPRECATEDIN_3_0 void* RSA_meth_get0_app_data(const RSA_METHOD* meth);
  337. OSSL_DEPRECATEDIN_3_0 int RSA_meth_set0_app_data(RSA_METHOD* meth, void* app_data);
  338. OSSL_DEPRECATEDIN_3_0
  339. int (*RSA_meth_get_pub_enc(const RSA_METHOD* meth))(int flen, const unsigned char* from, unsigned char* to, RSA* rsa, int padding);
  340. OSSL_DEPRECATEDIN_3_0
  341. int RSA_meth_set_pub_enc(RSA_METHOD* rsa, int (*pub_enc)(int flen, const unsigned char* from, unsigned char* to, RSA* rsa, int padding));
  342. OSSL_DEPRECATEDIN_3_0
  343. int (*RSA_meth_get_pub_dec(const RSA_METHOD* meth))(int flen, const unsigned char* from, unsigned char* to, RSA* rsa, int padding);
  344. OSSL_DEPRECATEDIN_3_0
  345. int RSA_meth_set_pub_dec(RSA_METHOD* rsa, int (*pub_dec)(int flen, const unsigned char* from, unsigned char* to, RSA* rsa, int padding));
  346. OSSL_DEPRECATEDIN_3_0
  347. int (*RSA_meth_get_priv_enc(const RSA_METHOD* meth))(int flen, const unsigned char* from, unsigned char* to, RSA* rsa, int padding);
  348. OSSL_DEPRECATEDIN_3_0
  349. int RSA_meth_set_priv_enc(RSA_METHOD* rsa, int (*priv_enc)(int flen, const unsigned char* from, unsigned char* to, RSA* rsa, int padding));
  350. OSSL_DEPRECATEDIN_3_0
  351. int (*RSA_meth_get_priv_dec(const RSA_METHOD* meth))(int flen, const unsigned char* from, unsigned char* to, RSA* rsa, int padding);
  352. OSSL_DEPRECATEDIN_3_0
  353. int RSA_meth_set_priv_dec(RSA_METHOD* rsa, int (*priv_dec)(int flen, const unsigned char* from, unsigned char* to, RSA* rsa, int padding));
  354. OSSL_DEPRECATEDIN_3_0
  355. int (*RSA_meth_get_mod_exp(const RSA_METHOD* meth))(BIGNUM* r0, const BIGNUM* i, RSA* rsa, BN_CTX* ctx);
  356. OSSL_DEPRECATEDIN_3_0
  357. int RSA_meth_set_mod_exp(RSA_METHOD* rsa, int (*mod_exp)(BIGNUM* r0, const BIGNUM* i, RSA* rsa, BN_CTX* ctx));
  358. OSSL_DEPRECATEDIN_3_0
  359. int (*RSA_meth_get_bn_mod_exp(const RSA_METHOD* meth))(BIGNUM* r, const BIGNUM* a, const BIGNUM* p, const BIGNUM* m, BN_CTX* ctx, BN_MONT_CTX* m_ctx);
  360. OSSL_DEPRECATEDIN_3_0
  361. int RSA_meth_set_bn_mod_exp(RSA_METHOD* rsa, int (*bn_mod_exp)(BIGNUM* r, const BIGNUM* a, const BIGNUM* p, const BIGNUM* m, BN_CTX* ctx, BN_MONT_CTX* m_ctx));
  362. OSSL_DEPRECATEDIN_3_0
  363. int (*RSA_meth_get_init(const RSA_METHOD* meth))(RSA* rsa);
  364. OSSL_DEPRECATEDIN_3_0
  365. int RSA_meth_set_init(RSA_METHOD* rsa, int (*init)(RSA* rsa));
  366. OSSL_DEPRECATEDIN_3_0
  367. int (*RSA_meth_get_finish(const RSA_METHOD* meth))(RSA* rsa);
  368. OSSL_DEPRECATEDIN_3_0
  369. int RSA_meth_set_finish(RSA_METHOD* rsa, int (*finish)(RSA* rsa));
  370. OSSL_DEPRECATEDIN_3_0
  371. int (*RSA_meth_get_sign(const RSA_METHOD* meth))(int type, const unsigned char* m, unsigned int m_length, unsigned char* sigret, unsigned int* siglen, const RSA* rsa);
  372. OSSL_DEPRECATEDIN_3_0
  373. int RSA_meth_set_sign(RSA_METHOD* rsa, int (*sign)(int type, const unsigned char* m, unsigned int m_length, unsigned char* sigret, unsigned int* siglen, const RSA* rsa));
  374. OSSL_DEPRECATEDIN_3_0
  375. int (*RSA_meth_get_verify(const RSA_METHOD* meth))(int dtype, const unsigned char* m, unsigned int m_length, const unsigned char* sigbuf, unsigned int siglen, const RSA* rsa);
  376. OSSL_DEPRECATEDIN_3_0
  377. int RSA_meth_set_verify(RSA_METHOD* rsa, int (*verify)(int dtype, const unsigned char* m, unsigned int m_length, const unsigned char* sigbuf, unsigned int siglen, const RSA* rsa));
  378. OSSL_DEPRECATEDIN_3_0
  379. int (*RSA_meth_get_keygen(const RSA_METHOD* meth))(RSA* rsa, int bits, BIGNUM* e, BN_GENCB* cb);
  380. OSSL_DEPRECATEDIN_3_0
  381. int RSA_meth_set_keygen(RSA_METHOD* rsa, int (*keygen)(RSA* rsa, int bits, BIGNUM* e, BN_GENCB* cb));
  382. OSSL_DEPRECATEDIN_3_0
  383. int (*RSA_meth_get_multi_prime_keygen(const RSA_METHOD* meth))(RSA* rsa, int bits, int primes, BIGNUM* e, BN_GENCB* cb);
  384. OSSL_DEPRECATEDIN_3_0
  385. int RSA_meth_set_multi_prime_keygen(RSA_METHOD* meth, int (*keygen)(RSA* rsa, int bits, int primes, BIGNUM* e, BN_GENCB* cb));
  386. #endif /* !OPENSSL_NO_DEPRECATED_3_0 */
  387. #ifdef __cplusplus
  388. }
  389. #endif
  390. #endif