rsa.h 28 KB

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