rsa.h 22 KB

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