rsa.h 27 KB

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