rsa.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  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. /* Deprecated version */
  214. # ifndef OPENSSL_NO_DEPRECATED_0_9_8
  215. OSSL_DEPRECATEDIN_0_9_8 RSA *RSA_generate_key(int bits, unsigned long e, void
  216. (*callback) (int, int, void *),
  217. void *cb_arg);
  218. # endif
  219. /* New version */
  220. # ifndef OPENSSL_NO_DEPRECATED_3_0
  221. OSSL_DEPRECATEDIN_3_0 int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e,
  222. BN_GENCB *cb);
  223. /* Multi-prime version */
  224. OSSL_DEPRECATEDIN_3_0 int RSA_generate_multi_prime_key(RSA *rsa, int bits,
  225. int primes, BIGNUM *e,
  226. BN_GENCB *cb);
  227. OSSL_DEPRECATEDIN_3_0
  228. int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2,
  229. BIGNUM *q1, BIGNUM *q2,
  230. const BIGNUM *Xp1, const BIGNUM *Xp2,
  231. const BIGNUM *Xp, const BIGNUM *Xq1,
  232. const BIGNUM *Xq2, const BIGNUM *Xq,
  233. const BIGNUM *e, BN_GENCB *cb);
  234. OSSL_DEPRECATEDIN_3_0 int RSA_X931_generate_key_ex(RSA *rsa, int bits,
  235. const BIGNUM *e,
  236. BN_GENCB *cb);
  237. OSSL_DEPRECATEDIN_3_0 int RSA_check_key(const RSA *);
  238. OSSL_DEPRECATEDIN_3_0 int RSA_check_key_ex(const RSA *, BN_GENCB *cb);
  239. /* next 4 return -1 on error */
  240. OSSL_DEPRECATEDIN_3_0
  241. int RSA_public_encrypt(int flen, const unsigned char *from, unsigned char *to,
  242. RSA *rsa, int padding);
  243. OSSL_DEPRECATEDIN_3_0
  244. int RSA_private_encrypt(int flen, const unsigned char *from, unsigned char *to,
  245. RSA *rsa, int padding);
  246. OSSL_DEPRECATEDIN_3_0
  247. int RSA_public_decrypt(int flen, const unsigned char *from, unsigned char *to,
  248. RSA *rsa, int padding);
  249. OSSL_DEPRECATEDIN_3_0
  250. int RSA_private_decrypt(int flen, const unsigned char *from, unsigned char *to,
  251. RSA *rsa, int padding);
  252. OSSL_DEPRECATEDIN_3_0 void RSA_free(RSA *r);
  253. /* "up" the RSA object's reference count */
  254. OSSL_DEPRECATEDIN_3_0 int RSA_up_ref(RSA *r);
  255. OSSL_DEPRECATEDIN_3_0 int RSA_flags(const RSA *r);
  256. OSSL_DEPRECATEDIN_3_0 void RSA_set_default_method(const RSA_METHOD *meth);
  257. OSSL_DEPRECATEDIN_3_0 const RSA_METHOD *RSA_get_default_method(void);
  258. OSSL_DEPRECATEDIN_3_0 const RSA_METHOD *RSA_null_method(void);
  259. OSSL_DEPRECATEDIN_3_0 const RSA_METHOD *RSA_get_method(const RSA *rsa);
  260. OSSL_DEPRECATEDIN_3_0 int RSA_set_method(RSA *rsa, const RSA_METHOD *meth);
  261. /* these are the actual RSA functions */
  262. OSSL_DEPRECATEDIN_3_0 const RSA_METHOD *RSA_PKCS1_OpenSSL(void);
  263. DECLARE_ASN1_ENCODE_FUNCTIONS_name_attr(OSSL_DEPRECATEDIN_3_0,
  264. RSA, RSAPublicKey)
  265. DECLARE_ASN1_ENCODE_FUNCTIONS_name_attr(OSSL_DEPRECATEDIN_3_0,
  266. RSA, RSAPrivateKey)
  267. # endif /* !OPENSSL_NO_DEPRECATED_3_0 */
  268. int RSA_pkey_ctx_ctrl(EVP_PKEY_CTX *ctx, int optype, int cmd, int p1, void *p2);
  269. struct rsa_pss_params_st {
  270. X509_ALGOR *hashAlgorithm;
  271. X509_ALGOR *maskGenAlgorithm;
  272. ASN1_INTEGER *saltLength;
  273. ASN1_INTEGER *trailerField;
  274. /* Decoded hash algorithm from maskGenAlgorithm */
  275. X509_ALGOR *maskHash;
  276. };
  277. DECLARE_ASN1_FUNCTIONS(RSA_PSS_PARAMS)
  278. DECLARE_ASN1_DUP_FUNCTION(RSA_PSS_PARAMS)
  279. typedef struct rsa_oaep_params_st {
  280. X509_ALGOR *hashFunc;
  281. X509_ALGOR *maskGenFunc;
  282. X509_ALGOR *pSourceFunc;
  283. /* Decoded hash algorithm from maskGenFunc */
  284. X509_ALGOR *maskHash;
  285. } RSA_OAEP_PARAMS;
  286. DECLARE_ASN1_FUNCTIONS(RSA_OAEP_PARAMS)
  287. # ifndef OPENSSL_NO_DEPRECATED_3_0
  288. # ifndef OPENSSL_NO_STDIO
  289. OSSL_DEPRECATEDIN_3_0 int RSA_print_fp(FILE *fp, const RSA *r, int offset);
  290. # endif
  291. OSSL_DEPRECATEDIN_3_0 int RSA_print(BIO *bp, const RSA *r, int offset);
  292. /*
  293. * The following 2 functions sign and verify a X509_SIG ASN1 object inside
  294. * PKCS#1 padded RSA encryption
  295. */
  296. OSSL_DEPRECATEDIN_3_0 int RSA_sign(int type, const unsigned char *m,
  297. unsigned int m_length, unsigned char *sigret,
  298. unsigned int *siglen, RSA *rsa);
  299. OSSL_DEPRECATEDIN_3_0 int RSA_verify(int type, const unsigned char *m,
  300. unsigned int m_length,
  301. const unsigned char *sigbuf,
  302. unsigned int siglen, RSA *rsa);
  303. /*
  304. * The following 2 function sign and verify a ASN1_OCTET_STRING object inside
  305. * PKCS#1 padded RSA encryption
  306. */
  307. OSSL_DEPRECATEDIN_3_0
  308. int RSA_sign_ASN1_OCTET_STRING(int type,
  309. const unsigned char *m, unsigned int m_length,
  310. unsigned char *sigret, unsigned int *siglen,
  311. RSA *rsa);
  312. OSSL_DEPRECATEDIN_3_0
  313. int RSA_verify_ASN1_OCTET_STRING(int type,
  314. const unsigned char *m, unsigned int m_length,
  315. unsigned char *sigbuf, unsigned int siglen,
  316. RSA *rsa);
  317. OSSL_DEPRECATEDIN_3_0 int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
  318. OSSL_DEPRECATEDIN_3_0 void RSA_blinding_off(RSA *rsa);
  319. OSSL_DEPRECATEDIN_3_0 BN_BLINDING *RSA_setup_blinding(RSA *rsa, BN_CTX *ctx);
  320. OSSL_DEPRECATEDIN_3_0
  321. int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen,
  322. const unsigned char *f, int fl);
  323. OSSL_DEPRECATEDIN_3_0
  324. int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
  325. const unsigned char *f, int fl,
  326. int rsa_len);
  327. OSSL_DEPRECATEDIN_3_0
  328. int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
  329. const unsigned char *f, int fl);
  330. OSSL_DEPRECATEDIN_3_0
  331. int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
  332. const unsigned char *f, int fl,
  333. int rsa_len);
  334. OSSL_DEPRECATEDIN_3_0 int PKCS1_MGF1(unsigned char *mask, long len,
  335. const unsigned char *seed, long seedlen,
  336. const EVP_MD *dgst);
  337. OSSL_DEPRECATEDIN_3_0
  338. int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
  339. const unsigned char *f, int fl,
  340. const unsigned char *p, int pl);
  341. OSSL_DEPRECATEDIN_3_0
  342. int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
  343. const unsigned char *f, int fl, int rsa_len,
  344. const unsigned char *p, int pl);
  345. OSSL_DEPRECATEDIN_3_0
  346. int RSA_padding_add_PKCS1_OAEP_mgf1(unsigned char *to, int tlen,
  347. const unsigned char *from, int flen,
  348. const unsigned char *param, int plen,
  349. const EVP_MD *md, const EVP_MD *mgf1md);
  350. OSSL_DEPRECATEDIN_3_0
  351. int RSA_padding_check_PKCS1_OAEP_mgf1(unsigned char *to, int tlen,
  352. const unsigned char *from, int flen,
  353. int num,
  354. const unsigned char *param, int plen,
  355. const EVP_MD *md, const EVP_MD *mgf1md);
  356. OSSL_DEPRECATEDIN_3_0 int RSA_padding_add_none(unsigned char *to, int tlen,
  357. const unsigned char *f, int fl);
  358. OSSL_DEPRECATEDIN_3_0 int RSA_padding_check_none(unsigned char *to, int tlen,
  359. const unsigned char *f, int fl,
  360. int rsa_len);
  361. OSSL_DEPRECATEDIN_3_0 int RSA_padding_add_X931(unsigned char *to, int tlen,
  362. const unsigned char *f, int fl);
  363. OSSL_DEPRECATEDIN_3_0 int RSA_padding_check_X931(unsigned char *to, int tlen,
  364. const unsigned char *f, int fl,
  365. int rsa_len);
  366. OSSL_DEPRECATEDIN_3_0 int RSA_X931_hash_id(int nid);
  367. OSSL_DEPRECATEDIN_3_0
  368. int RSA_verify_PKCS1_PSS(RSA *rsa, const unsigned char *mHash,
  369. const EVP_MD *Hash, const unsigned char *EM,
  370. int sLen);
  371. OSSL_DEPRECATEDIN_3_0
  372. int RSA_padding_add_PKCS1_PSS(RSA *rsa, unsigned char *EM,
  373. const unsigned char *mHash, const EVP_MD *Hash,
  374. int sLen);
  375. OSSL_DEPRECATEDIN_3_0
  376. int RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const unsigned char *mHash,
  377. const EVP_MD *Hash, const EVP_MD *mgf1Hash,
  378. const unsigned char *EM, int sLen);
  379. OSSL_DEPRECATEDIN_3_0
  380. int RSA_padding_add_PKCS1_PSS_mgf1(RSA *rsa, unsigned char *EM,
  381. const unsigned char *mHash,
  382. const EVP_MD *Hash, const EVP_MD *mgf1Hash,
  383. int sLen);
  384. # define RSA_get_ex_new_index(l, p, newf, dupf, freef) \
  385. CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_RSA, l, p, newf, dupf, freef)
  386. OSSL_DEPRECATEDIN_3_0 int RSA_set_ex_data(RSA *r, int idx, void *arg);
  387. OSSL_DEPRECATEDIN_3_0 void *RSA_get_ex_data(const RSA *r, int idx);
  388. DECLARE_ASN1_DUP_FUNCTION_name_attr(OSSL_DEPRECATEDIN_3_0, RSA, RSAPublicKey)
  389. DECLARE_ASN1_DUP_FUNCTION_name_attr(OSSL_DEPRECATEDIN_3_0, RSA, RSAPrivateKey)
  390. /*
  391. * If this flag is set the RSA method is FIPS compliant and can be used in
  392. * FIPS mode. This is set in the validated module method. If an application
  393. * sets this flag in its own methods it is its responsibility to ensure the
  394. * result is compliant.
  395. */
  396. # define RSA_FLAG_FIPS_METHOD 0x0400
  397. /*
  398. * If this flag is set the operations normally disabled in FIPS mode are
  399. * permitted it is then the applications responsibility to ensure that the
  400. * usage is compliant.
  401. */
  402. # define RSA_FLAG_NON_FIPS_ALLOW 0x0400
  403. /*
  404. * Application has decided PRNG is good enough to generate a key: don't
  405. * check.
  406. */
  407. # define RSA_FLAG_CHECKED 0x0800
  408. OSSL_DEPRECATEDIN_3_0 RSA_METHOD *RSA_meth_new(const char *name, int flags);
  409. OSSL_DEPRECATEDIN_3_0 void RSA_meth_free(RSA_METHOD *meth);
  410. OSSL_DEPRECATEDIN_3_0 RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth);
  411. OSSL_DEPRECATEDIN_3_0 const char *RSA_meth_get0_name(const RSA_METHOD *meth);
  412. OSSL_DEPRECATEDIN_3_0 int RSA_meth_set1_name(RSA_METHOD *meth,
  413. const char *name);
  414. OSSL_DEPRECATEDIN_3_0 int RSA_meth_get_flags(const RSA_METHOD *meth);
  415. OSSL_DEPRECATEDIN_3_0 int RSA_meth_set_flags(RSA_METHOD *meth, int flags);
  416. OSSL_DEPRECATEDIN_3_0 void *RSA_meth_get0_app_data(const RSA_METHOD *meth);
  417. OSSL_DEPRECATEDIN_3_0 int RSA_meth_set0_app_data(RSA_METHOD *meth,
  418. void *app_data);
  419. OSSL_DEPRECATEDIN_3_0
  420. int (*RSA_meth_get_pub_enc(const RSA_METHOD *meth)) (int flen,
  421. const unsigned char *from,
  422. unsigned char *to,
  423. RSA *rsa, int padding);
  424. OSSL_DEPRECATEDIN_3_0
  425. int RSA_meth_set_pub_enc(RSA_METHOD *rsa,
  426. int (*pub_enc) (int flen, const unsigned char *from,
  427. unsigned char *to, RSA *rsa,
  428. int padding));
  429. OSSL_DEPRECATEDIN_3_0
  430. int (*RSA_meth_get_pub_dec(const RSA_METHOD *meth)) (int flen,
  431. const unsigned char *from,
  432. unsigned char *to,
  433. RSA *rsa, int padding);
  434. OSSL_DEPRECATEDIN_3_0
  435. int RSA_meth_set_pub_dec(RSA_METHOD *rsa,
  436. int (*pub_dec) (int flen, const unsigned char *from,
  437. unsigned char *to, RSA *rsa,
  438. int padding));
  439. OSSL_DEPRECATEDIN_3_0
  440. int (*RSA_meth_get_priv_enc(const RSA_METHOD *meth)) (int flen,
  441. const unsigned char *from,
  442. unsigned char *to,
  443. RSA *rsa, int padding);
  444. OSSL_DEPRECATEDIN_3_0
  445. int RSA_meth_set_priv_enc(RSA_METHOD *rsa,
  446. int (*priv_enc) (int flen, const unsigned char *from,
  447. unsigned char *to, RSA *rsa,
  448. int padding));
  449. OSSL_DEPRECATEDIN_3_0
  450. int (*RSA_meth_get_priv_dec(const RSA_METHOD *meth)) (int flen,
  451. const unsigned char *from,
  452. unsigned char *to,
  453. RSA *rsa, int padding);
  454. OSSL_DEPRECATEDIN_3_0
  455. int RSA_meth_set_priv_dec(RSA_METHOD *rsa,
  456. int (*priv_dec) (int flen, const unsigned char *from,
  457. unsigned char *to, RSA *rsa,
  458. int padding));
  459. OSSL_DEPRECATEDIN_3_0
  460. int (*RSA_meth_get_mod_exp(const RSA_METHOD *meth)) (BIGNUM *r0,
  461. const BIGNUM *i,
  462. RSA *rsa, BN_CTX *ctx);
  463. OSSL_DEPRECATEDIN_3_0
  464. int RSA_meth_set_mod_exp(RSA_METHOD *rsa,
  465. int (*mod_exp) (BIGNUM *r0, const BIGNUM *i, RSA *rsa,
  466. BN_CTX *ctx));
  467. OSSL_DEPRECATEDIN_3_0
  468. int (*RSA_meth_get_bn_mod_exp(const RSA_METHOD *meth)) (BIGNUM *r,
  469. const BIGNUM *a,
  470. const BIGNUM *p,
  471. const BIGNUM *m,
  472. BN_CTX *ctx,
  473. BN_MONT_CTX *m_ctx);
  474. OSSL_DEPRECATEDIN_3_0
  475. int RSA_meth_set_bn_mod_exp(RSA_METHOD *rsa,
  476. int (*bn_mod_exp) (BIGNUM *r,
  477. const BIGNUM *a,
  478. const BIGNUM *p,
  479. const BIGNUM *m,
  480. BN_CTX *ctx,
  481. BN_MONT_CTX *m_ctx));
  482. OSSL_DEPRECATEDIN_3_0
  483. int (*RSA_meth_get_init(const RSA_METHOD *meth)) (RSA *rsa);
  484. OSSL_DEPRECATEDIN_3_0
  485. int RSA_meth_set_init(RSA_METHOD *rsa, int (*init) (RSA *rsa));
  486. OSSL_DEPRECATEDIN_3_0
  487. int (*RSA_meth_get_finish(const RSA_METHOD *meth)) (RSA *rsa);
  488. OSSL_DEPRECATEDIN_3_0
  489. int RSA_meth_set_finish(RSA_METHOD *rsa, int (*finish) (RSA *rsa));
  490. OSSL_DEPRECATEDIN_3_0
  491. int (*RSA_meth_get_sign(const RSA_METHOD *meth)) (int type,
  492. const unsigned char *m,
  493. unsigned int m_length,
  494. unsigned char *sigret,
  495. unsigned int *siglen,
  496. const RSA *rsa);
  497. OSSL_DEPRECATEDIN_3_0
  498. int RSA_meth_set_sign(RSA_METHOD *rsa,
  499. int (*sign) (int type, const unsigned char *m,
  500. unsigned int m_length,
  501. unsigned char *sigret, unsigned int *siglen,
  502. const RSA *rsa));
  503. OSSL_DEPRECATEDIN_3_0
  504. int (*RSA_meth_get_verify(const RSA_METHOD *meth)) (int dtype,
  505. const unsigned char *m,
  506. unsigned int m_length,
  507. const unsigned char *sigbuf,
  508. unsigned int siglen,
  509. const RSA *rsa);
  510. OSSL_DEPRECATEDIN_3_0
  511. int RSA_meth_set_verify(RSA_METHOD *rsa,
  512. int (*verify) (int dtype, const unsigned char *m,
  513. unsigned int m_length,
  514. const unsigned char *sigbuf,
  515. unsigned int siglen, const RSA *rsa));
  516. OSSL_DEPRECATEDIN_3_0
  517. int (*RSA_meth_get_keygen(const RSA_METHOD *meth)) (RSA *rsa, int bits,
  518. BIGNUM *e, BN_GENCB *cb);
  519. OSSL_DEPRECATEDIN_3_0
  520. int RSA_meth_set_keygen(RSA_METHOD *rsa,
  521. int (*keygen) (RSA *rsa, int bits, BIGNUM *e,
  522. BN_GENCB *cb));
  523. OSSL_DEPRECATEDIN_3_0
  524. int (*RSA_meth_get_multi_prime_keygen(const RSA_METHOD *meth)) (RSA *rsa,
  525. int bits,
  526. int primes,
  527. BIGNUM *e,
  528. BN_GENCB *cb);
  529. OSSL_DEPRECATEDIN_3_0
  530. int RSA_meth_set_multi_prime_keygen(RSA_METHOD *meth,
  531. int (*keygen) (RSA *rsa, int bits,
  532. int primes, BIGNUM *e,
  533. BN_GENCB *cb));
  534. #endif /* !OPENSSL_NO_DEPRECATED_3_0 */
  535. # ifdef __cplusplus
  536. }
  537. # endif
  538. #endif