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