rsa.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. /*
  2. * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (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 HEADER_RSA_H
  10. # define HEADER_RSA_H
  11. # include <openssl/opensslconf.h>
  12. # ifndef OPENSSL_NO_RSA
  13. # include <openssl/asn1.h>
  14. # include <openssl/bio.h>
  15. # include <openssl/crypto.h>
  16. # include <openssl/ossl_typ.h>
  17. # if OPENSSL_API_COMPAT < 0x10100000L
  18. # include <openssl/bn.h>
  19. # endif
  20. # ifdef __cplusplus
  21. extern "C" {
  22. # endif
  23. /* The types RSA and RSA_METHOD are defined in ossl_typ.h */
  24. # ifndef OPENSSL_RSA_MAX_MODULUS_BITS
  25. # define OPENSSL_RSA_MAX_MODULUS_BITS 16384
  26. # endif
  27. # define OPENSSL_RSA_FIPS_MIN_MODULUS_BITS 1024
  28. # ifndef OPENSSL_RSA_SMALL_MODULUS_BITS
  29. # define OPENSSL_RSA_SMALL_MODULUS_BITS 3072
  30. # endif
  31. # ifndef OPENSSL_RSA_MAX_PUBEXP_BITS
  32. /* exponent limit enforced for "large" modulus only */
  33. # define OPENSSL_RSA_MAX_PUBEXP_BITS 64
  34. # endif
  35. # define RSA_3 0x3L
  36. # define RSA_F4 0x10001L
  37. # define RSA_METHOD_FLAG_NO_CHECK 0x0001/* don't check pub/private
  38. * match */
  39. # define RSA_FLAG_CACHE_PUBLIC 0x0002
  40. # define RSA_FLAG_CACHE_PRIVATE 0x0004
  41. # define RSA_FLAG_BLINDING 0x0008
  42. # define RSA_FLAG_THREAD_SAFE 0x0010
  43. /*
  44. * This flag means the private key operations will be handled by rsa_mod_exp
  45. * and that they do not depend on the private key components being present:
  46. * for example a key stored in external hardware. Without this flag
  47. * bn_mod_exp gets called when private key components are absent.
  48. */
  49. # define RSA_FLAG_EXT_PKEY 0x0020
  50. /*
  51. * new with 0.9.6j and 0.9.7b; the built-in
  52. * RSA implementation now uses blinding by
  53. * default (ignoring RSA_FLAG_BLINDING),
  54. * but other engines might not need it
  55. */
  56. # define RSA_FLAG_NO_BLINDING 0x0080
  57. # if OPENSSL_API_COMPAT < 0x10100000L
  58. /*
  59. * Does nothing. Previously this switched off constant time behaviour.
  60. */
  61. # define RSA_FLAG_NO_CONSTTIME 0x0000
  62. # endif
  63. # if OPENSSL_API_COMPAT < 0x00908000L
  64. /* deprecated name for the flag*/
  65. /*
  66. * new with 0.9.7h; the built-in RSA
  67. * implementation now uses constant time
  68. * modular exponentiation for secret exponents
  69. * by default. This flag causes the
  70. * faster variable sliding window method to
  71. * be used for all exponents.
  72. */
  73. # define RSA_FLAG_NO_EXP_CONSTTIME RSA_FLAG_NO_CONSTTIME
  74. # endif
  75. # define EVP_PKEY_CTX_set_rsa_padding(ctx, pad) \
  76. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, -1, EVP_PKEY_CTRL_RSA_PADDING, \
  77. pad, NULL)
  78. # define EVP_PKEY_CTX_get_rsa_padding(ctx, ppad) \
  79. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, -1, \
  80. EVP_PKEY_CTRL_GET_RSA_PADDING, 0, ppad)
  81. # define EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, len) \
  82. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, \
  83. (EVP_PKEY_OP_SIGN|EVP_PKEY_OP_VERIFY), \
  84. EVP_PKEY_CTRL_RSA_PSS_SALTLEN, \
  85. len, NULL)
  86. # define EVP_PKEY_CTX_get_rsa_pss_saltlen(ctx, plen) \
  87. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, \
  88. (EVP_PKEY_OP_SIGN|EVP_PKEY_OP_VERIFY), \
  89. EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN, \
  90. 0, plen)
  91. # define EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, bits) \
  92. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_KEYGEN, \
  93. EVP_PKEY_CTRL_RSA_KEYGEN_BITS, bits, NULL)
  94. # define EVP_PKEY_CTX_set_rsa_keygen_pubexp(ctx, pubexp) \
  95. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_KEYGEN, \
  96. EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP, 0, pubexp)
  97. # define EVP_PKEY_CTX_set_rsa_mgf1_md(ctx, md) \
  98. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, \
  99. EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT, \
  100. EVP_PKEY_CTRL_RSA_MGF1_MD, 0, (void *)md)
  101. # define EVP_PKEY_CTX_set_rsa_oaep_md(ctx, md) \
  102. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, \
  103. EVP_PKEY_CTRL_RSA_OAEP_MD, 0, (void *)md)
  104. # define EVP_PKEY_CTX_get_rsa_mgf1_md(ctx, pmd) \
  105. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, \
  106. EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT, \
  107. EVP_PKEY_CTRL_GET_RSA_MGF1_MD, 0, (void *)pmd)
  108. # define EVP_PKEY_CTX_get_rsa_oaep_md(ctx, pmd) \
  109. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, \
  110. EVP_PKEY_CTRL_GET_RSA_OAEP_MD, 0, (void *)pmd)
  111. # define EVP_PKEY_CTX_set0_rsa_oaep_label(ctx, l, llen) \
  112. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, \
  113. EVP_PKEY_CTRL_RSA_OAEP_LABEL, llen, (void *)l)
  114. # define EVP_PKEY_CTX_get0_rsa_oaep_label(ctx, l) \
  115. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, \
  116. EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL, 0, (void *)l)
  117. # define EVP_PKEY_CTRL_RSA_PADDING (EVP_PKEY_ALG_CTRL + 1)
  118. # define EVP_PKEY_CTRL_RSA_PSS_SALTLEN (EVP_PKEY_ALG_CTRL + 2)
  119. # define EVP_PKEY_CTRL_RSA_KEYGEN_BITS (EVP_PKEY_ALG_CTRL + 3)
  120. # define EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP (EVP_PKEY_ALG_CTRL + 4)
  121. # define EVP_PKEY_CTRL_RSA_MGF1_MD (EVP_PKEY_ALG_CTRL + 5)
  122. # define EVP_PKEY_CTRL_GET_RSA_PADDING (EVP_PKEY_ALG_CTRL + 6)
  123. # define EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN (EVP_PKEY_ALG_CTRL + 7)
  124. # define EVP_PKEY_CTRL_GET_RSA_MGF1_MD (EVP_PKEY_ALG_CTRL + 8)
  125. # define EVP_PKEY_CTRL_RSA_OAEP_MD (EVP_PKEY_ALG_CTRL + 9)
  126. # define EVP_PKEY_CTRL_RSA_OAEP_LABEL (EVP_PKEY_ALG_CTRL + 10)
  127. # define EVP_PKEY_CTRL_GET_RSA_OAEP_MD (EVP_PKEY_ALG_CTRL + 11)
  128. # define EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL (EVP_PKEY_ALG_CTRL + 12)
  129. # define RSA_PKCS1_PADDING 1
  130. # define RSA_SSLV23_PADDING 2
  131. # define RSA_NO_PADDING 3
  132. # define RSA_PKCS1_OAEP_PADDING 4
  133. # define RSA_X931_PADDING 5
  134. /* EVP_PKEY_ only */
  135. # define RSA_PKCS1_PSS_PADDING 6
  136. # define RSA_PKCS1_PADDING_SIZE 11
  137. # define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,arg)
  138. # define RSA_get_app_data(s) RSA_get_ex_data(s,0)
  139. RSA *RSA_new(void);
  140. RSA *RSA_new_method(ENGINE *engine);
  141. int RSA_bits(const RSA *rsa);
  142. int RSA_size(const RSA *rsa);
  143. int RSA_security_bits(const RSA *rsa);
  144. int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
  145. int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q);
  146. int RSA_set0_crt_params(RSA *r,BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp);
  147. void RSA_get0_key(const RSA *r,
  148. const BIGNUM **n, const BIGNUM **e, const BIGNUM **d);
  149. void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q);
  150. void RSA_get0_crt_params(const RSA *r,
  151. const BIGNUM **dmp1, const BIGNUM **dmq1,
  152. const BIGNUM **iqmp);
  153. void RSA_clear_flags(RSA *r, int flags);
  154. int RSA_test_flags(const RSA *r, int flags);
  155. void RSA_set_flags(RSA *r, int flags);
  156. ENGINE *RSA_get0_engine(const RSA *r);
  157. /* Deprecated version */
  158. DEPRECATEDIN_0_9_8(RSA *RSA_generate_key(int bits, unsigned long e, void
  159. (*callback) (int, int, void *),
  160. void *cb_arg))
  161. /* New version */
  162. int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
  163. int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1,
  164. BIGNUM *q2, const BIGNUM *Xp1, const BIGNUM *Xp2,
  165. const BIGNUM *Xp, const BIGNUM *Xq1, const BIGNUM *Xq2,
  166. const BIGNUM *Xq, const BIGNUM *e, BN_GENCB *cb);
  167. int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e,
  168. BN_GENCB *cb);
  169. int RSA_check_key(const RSA *);
  170. int RSA_check_key_ex(const RSA *, BN_GENCB *cb);
  171. /* next 4 return -1 on error */
  172. int RSA_public_encrypt(int flen, const unsigned char *from,
  173. unsigned char *to, RSA *rsa, int padding);
  174. int RSA_private_encrypt(int flen, const unsigned char *from,
  175. unsigned char *to, RSA *rsa, int padding);
  176. int RSA_public_decrypt(int flen, const unsigned char *from,
  177. unsigned char *to, RSA *rsa, int padding);
  178. int RSA_private_decrypt(int flen, const unsigned char *from,
  179. unsigned char *to, RSA *rsa, int padding);
  180. void RSA_free(RSA *r);
  181. /* "up" the RSA object's reference count */
  182. int RSA_up_ref(RSA *r);
  183. int RSA_flags(const RSA *r);
  184. void RSA_set_default_method(const RSA_METHOD *meth);
  185. const RSA_METHOD *RSA_get_default_method(void);
  186. const RSA_METHOD *RSA_get_method(const RSA *rsa);
  187. int RSA_set_method(RSA *rsa, const RSA_METHOD *meth);
  188. /* these are the actual RSA functions */
  189. const RSA_METHOD *RSA_PKCS1_OpenSSL(void);
  190. const RSA_METHOD *RSA_null_method(void);
  191. DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPublicKey)
  192. DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPrivateKey)
  193. typedef struct rsa_pss_params_st {
  194. X509_ALGOR *hashAlgorithm;
  195. X509_ALGOR *maskGenAlgorithm;
  196. ASN1_INTEGER *saltLength;
  197. ASN1_INTEGER *trailerField;
  198. } RSA_PSS_PARAMS;
  199. DECLARE_ASN1_FUNCTIONS(RSA_PSS_PARAMS)
  200. typedef struct rsa_oaep_params_st {
  201. X509_ALGOR *hashFunc;
  202. X509_ALGOR *maskGenFunc;
  203. X509_ALGOR *pSourceFunc;
  204. } RSA_OAEP_PARAMS;
  205. DECLARE_ASN1_FUNCTIONS(RSA_OAEP_PARAMS)
  206. # ifndef OPENSSL_NO_STDIO
  207. int RSA_print_fp(FILE *fp, const RSA *r, int offset);
  208. # endif
  209. int RSA_print(BIO *bp, const RSA *r, int offset);
  210. /*
  211. * The following 2 functions sign and verify a X509_SIG ASN1 object inside
  212. * PKCS#1 padded RSA encryption
  213. */
  214. int RSA_sign(int type, const unsigned char *m, unsigned int m_length,
  215. unsigned char *sigret, unsigned int *siglen, RSA *rsa);
  216. int RSA_verify(int type, const unsigned char *m, unsigned int m_length,
  217. const unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
  218. /*
  219. * The following 2 function sign and verify a ASN1_OCTET_STRING object inside
  220. * PKCS#1 padded RSA encryption
  221. */
  222. int RSA_sign_ASN1_OCTET_STRING(int type,
  223. const unsigned char *m, unsigned int m_length,
  224. unsigned char *sigret, unsigned int *siglen,
  225. RSA *rsa);
  226. int RSA_verify_ASN1_OCTET_STRING(int type, const unsigned char *m,
  227. unsigned int m_length, unsigned char *sigbuf,
  228. unsigned int siglen, RSA *rsa);
  229. int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
  230. void RSA_blinding_off(RSA *rsa);
  231. BN_BLINDING *RSA_setup_blinding(RSA *rsa, BN_CTX *ctx);
  232. int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen,
  233. const unsigned char *f, int fl);
  234. int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
  235. const unsigned char *f, int fl,
  236. int rsa_len);
  237. int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
  238. const unsigned char *f, int fl);
  239. int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
  240. const unsigned char *f, int fl,
  241. int rsa_len);
  242. int PKCS1_MGF1(unsigned char *mask, long len, const unsigned char *seed,
  243. long seedlen, const EVP_MD *dgst);
  244. int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
  245. const unsigned char *f, int fl,
  246. const unsigned char *p, int pl);
  247. int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
  248. const unsigned char *f, int fl, int rsa_len,
  249. const unsigned char *p, int pl);
  250. int RSA_padding_add_PKCS1_OAEP_mgf1(unsigned char *to, int tlen,
  251. const unsigned char *from, int flen,
  252. const unsigned char *param, int plen,
  253. const EVP_MD *md, const EVP_MD *mgf1md);
  254. int RSA_padding_check_PKCS1_OAEP_mgf1(unsigned char *to, int tlen,
  255. const unsigned char *from, int flen,
  256. int num, const unsigned char *param,
  257. int plen, const EVP_MD *md,
  258. const EVP_MD *mgf1md);
  259. int RSA_padding_add_SSLv23(unsigned char *to, int tlen,
  260. const unsigned char *f, int fl);
  261. int RSA_padding_check_SSLv23(unsigned char *to, int tlen,
  262. const unsigned char *f, int fl, int rsa_len);
  263. int RSA_padding_add_none(unsigned char *to, int tlen, const unsigned char *f,
  264. int fl);
  265. int RSA_padding_check_none(unsigned char *to, int tlen,
  266. const unsigned char *f, int fl, int rsa_len);
  267. int RSA_padding_add_X931(unsigned char *to, int tlen, const unsigned char *f,
  268. int fl);
  269. int RSA_padding_check_X931(unsigned char *to, int tlen,
  270. const unsigned char *f, int fl, int rsa_len);
  271. int RSA_X931_hash_id(int nid);
  272. int RSA_verify_PKCS1_PSS(RSA *rsa, const unsigned char *mHash,
  273. const EVP_MD *Hash, const unsigned char *EM,
  274. int sLen);
  275. int RSA_padding_add_PKCS1_PSS(RSA *rsa, unsigned char *EM,
  276. const unsigned char *mHash, const EVP_MD *Hash,
  277. int sLen);
  278. int RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const unsigned char *mHash,
  279. const EVP_MD *Hash, const EVP_MD *mgf1Hash,
  280. const unsigned char *EM, int sLen);
  281. int RSA_padding_add_PKCS1_PSS_mgf1(RSA *rsa, unsigned char *EM,
  282. const unsigned char *mHash,
  283. const EVP_MD *Hash, const EVP_MD *mgf1Hash,
  284. int sLen);
  285. #define RSA_get_ex_new_index(l, p, newf, dupf, freef) \
  286. CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_RSA, l, p, newf, dupf, freef)
  287. int RSA_set_ex_data(RSA *r, int idx, void *arg);
  288. void *RSA_get_ex_data(const RSA *r, int idx);
  289. RSA *RSAPublicKey_dup(RSA *rsa);
  290. RSA *RSAPrivateKey_dup(RSA *rsa);
  291. /*
  292. * If this flag is set the RSA method is FIPS compliant and can be used in
  293. * FIPS mode. This is set in the validated module method. If an application
  294. * sets this flag in its own methods it is its responsibility to ensure the
  295. * result is compliant.
  296. */
  297. # define RSA_FLAG_FIPS_METHOD 0x0400
  298. /*
  299. * If this flag is set the operations normally disabled in FIPS mode are
  300. * permitted it is then the applications responsibility to ensure that the
  301. * usage is compliant.
  302. */
  303. # define RSA_FLAG_NON_FIPS_ALLOW 0x0400
  304. /*
  305. * Application has decided PRNG is good enough to generate a key: don't
  306. * check.
  307. */
  308. # define RSA_FLAG_CHECKED 0x0800
  309. RSA_METHOD *RSA_meth_new(const char *name, int flags);
  310. void RSA_meth_free(RSA_METHOD *meth);
  311. RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth);
  312. const char *RSA_meth_get0_name(const RSA_METHOD *meth);
  313. int RSA_meth_set1_name(RSA_METHOD *meth, const char *name);
  314. int RSA_meth_get_flags(RSA_METHOD *meth);
  315. int RSA_meth_set_flags(RSA_METHOD *meth, int flags);
  316. void *RSA_meth_get0_app_data(const RSA_METHOD *meth);
  317. int RSA_meth_set0_app_data(RSA_METHOD *meth, void *app_data);
  318. int (*RSA_meth_get_pub_enc(const RSA_METHOD *meth))
  319. (int flen, const unsigned char *from,
  320. unsigned char *to, RSA *rsa, int padding);
  321. int RSA_meth_set_pub_enc(RSA_METHOD *rsa,
  322. int (*pub_enc) (int flen, const unsigned char *from,
  323. unsigned char *to, RSA *rsa,
  324. int padding));
  325. int (*RSA_meth_get_pub_dec(const RSA_METHOD *meth))
  326. (int flen, const unsigned char *from,
  327. unsigned char *to, RSA *rsa, int padding);
  328. int RSA_meth_set_pub_dec(RSA_METHOD *rsa,
  329. int (*pub_dec) (int flen, const unsigned char *from,
  330. unsigned char *to, RSA *rsa,
  331. int padding));
  332. int (*RSA_meth_get_priv_enc(const RSA_METHOD *meth))
  333. (int flen, const unsigned char *from,
  334. unsigned char *to, RSA *rsa, int padding);
  335. int RSA_meth_set_priv_enc(RSA_METHOD *rsa,
  336. int (*priv_enc) (int flen, const unsigned char *from,
  337. unsigned char *to, RSA *rsa,
  338. int padding));
  339. int (*RSA_meth_get_priv_dec(const RSA_METHOD *meth))
  340. (int flen, const unsigned char *from,
  341. unsigned char *to, RSA *rsa, int padding);
  342. int RSA_meth_set_priv_dec(RSA_METHOD *rsa,
  343. int (*priv_dec) (int flen, const unsigned char *from,
  344. unsigned char *to, RSA *rsa,
  345. int padding));
  346. int (*RSA_meth_get_mod_exp(const RSA_METHOD *meth))
  347. (BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx);
  348. int RSA_meth_set_mod_exp(RSA_METHOD *rsa,
  349. int (*mod_exp) (BIGNUM *r0, const BIGNUM *I, RSA *rsa,
  350. BN_CTX *ctx));
  351. int (*RSA_meth_get_bn_mod_exp(const RSA_METHOD *meth))
  352. (BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
  353. const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
  354. int RSA_meth_set_bn_mod_exp(RSA_METHOD *rsa,
  355. int (*bn_mod_exp) (BIGNUM *r,
  356. const BIGNUM *a,
  357. const BIGNUM *p,
  358. const BIGNUM *m,
  359. BN_CTX *ctx,
  360. BN_MONT_CTX *m_ctx));
  361. int (*RSA_meth_get_init(const RSA_METHOD *meth)) (RSA *rsa);
  362. int RSA_meth_set_init(RSA_METHOD *rsa, int (*init) (RSA *rsa));
  363. int (*RSA_meth_get_finish(const RSA_METHOD *meth)) (RSA *rsa);
  364. int RSA_meth_set_finish(RSA_METHOD *rsa, int (*finish) (RSA *rsa));
  365. int (*RSA_meth_get_sign(const RSA_METHOD *meth))
  366. (int type,
  367. const unsigned char *m, unsigned int m_length,
  368. unsigned char *sigret, unsigned int *siglen,
  369. const RSA *rsa);
  370. int RSA_meth_set_sign(RSA_METHOD *rsa,
  371. int (*sign) (int type, const unsigned char *m,
  372. unsigned int m_length,
  373. unsigned char *sigret, unsigned int *siglen,
  374. const RSA *rsa));
  375. int (*RSA_meth_get_verify(const RSA_METHOD *meth))
  376. (int dtype, const unsigned char *m,
  377. unsigned int m_length, const unsigned char *sigbuf,
  378. unsigned int siglen, const RSA *rsa);
  379. int RSA_meth_set_verify(RSA_METHOD *rsa,
  380. int (*verify) (int dtype, const unsigned char *m,
  381. unsigned int m_length,
  382. const unsigned char *sigbuf,
  383. unsigned int siglen, const RSA *rsa));
  384. int (*RSA_meth_get_keygen(const RSA_METHOD *meth))
  385. (RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
  386. int RSA_meth_set_keygen(RSA_METHOD *rsa,
  387. int (*keygen) (RSA *rsa, int bits, BIGNUM *e,
  388. BN_GENCB *cb));
  389. /* BEGIN ERROR CODES */
  390. /*
  391. * The following lines are auto generated by the script mkerr.pl. Any changes
  392. * made after this point may be overwritten when the script is next run.
  393. */
  394. int ERR_load_RSA_strings(void);
  395. /* Error codes for the RSA functions. */
  396. /* Function codes. */
  397. # define RSA_F_CHECK_PADDING_MD 140
  398. # define RSA_F_ENCODE_PKCS1 146
  399. # define RSA_F_INT_RSA_VERIFY 145
  400. # define RSA_F_OLD_RSA_PRIV_DECODE 147
  401. # define RSA_F_PKEY_RSA_CTRL 143
  402. # define RSA_F_PKEY_RSA_CTRL_STR 144
  403. # define RSA_F_PKEY_RSA_SIGN 142
  404. # define RSA_F_PKEY_RSA_VERIFY 149
  405. # define RSA_F_PKEY_RSA_VERIFYRECOVER 141
  406. # define RSA_F_RSA_ALGOR_TO_MD 156
  407. # define RSA_F_RSA_BUILTIN_KEYGEN 129
  408. # define RSA_F_RSA_CHECK_KEY 123
  409. # define RSA_F_RSA_CHECK_KEY_EX 160
  410. # define RSA_F_RSA_CMS_DECRYPT 159
  411. # define RSA_F_RSA_ITEM_VERIFY 148
  412. # define RSA_F_RSA_METH_DUP 161
  413. # define RSA_F_RSA_METH_NEW 162
  414. # define RSA_F_RSA_METH_SET1_NAME 163
  415. # define RSA_F_RSA_MGF1_TO_MD 157
  416. # define RSA_F_RSA_NEW_METHOD 106
  417. # define RSA_F_RSA_NULL 124
  418. # define RSA_F_RSA_NULL_PRIVATE_DECRYPT 132
  419. # define RSA_F_RSA_NULL_PRIVATE_ENCRYPT 133
  420. # define RSA_F_RSA_NULL_PUBLIC_DECRYPT 134
  421. # define RSA_F_RSA_NULL_PUBLIC_ENCRYPT 135
  422. # define RSA_F_RSA_OSSL_PRIVATE_DECRYPT 101
  423. # define RSA_F_RSA_OSSL_PRIVATE_ENCRYPT 102
  424. # define RSA_F_RSA_OSSL_PUBLIC_DECRYPT 103
  425. # define RSA_F_RSA_OSSL_PUBLIC_ENCRYPT 104
  426. # define RSA_F_RSA_PADDING_ADD_NONE 107
  427. # define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP 121
  428. # define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP_MGF1 154
  429. # define RSA_F_RSA_PADDING_ADD_PKCS1_PSS 125
  430. # define RSA_F_RSA_PADDING_ADD_PKCS1_PSS_MGF1 152
  431. # define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 108
  432. # define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2 109
  433. # define RSA_F_RSA_PADDING_ADD_SSLV23 110
  434. # define RSA_F_RSA_PADDING_ADD_X931 127
  435. # define RSA_F_RSA_PADDING_CHECK_NONE 111
  436. # define RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP 122
  437. # define RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP_MGF1 153
  438. # define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1 112
  439. # define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2 113
  440. # define RSA_F_RSA_PADDING_CHECK_SSLV23 114
  441. # define RSA_F_RSA_PADDING_CHECK_X931 128
  442. # define RSA_F_RSA_PRINT 115
  443. # define RSA_F_RSA_PRINT_FP 116
  444. # define RSA_F_RSA_PRIV_ENCODE 138
  445. # define RSA_F_RSA_PSS_TO_CTX 155
  446. # define RSA_F_RSA_PUB_DECODE 139
  447. # define RSA_F_RSA_SETUP_BLINDING 136
  448. # define RSA_F_RSA_SIGN 117
  449. # define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 118
  450. # define RSA_F_RSA_VERIFY 119
  451. # define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING 120
  452. # define RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1 126
  453. /* Reason codes. */
  454. # define RSA_R_ALGORITHM_MISMATCH 100
  455. # define RSA_R_BAD_E_VALUE 101
  456. # define RSA_R_BAD_FIXED_HEADER_DECRYPT 102
  457. # define RSA_R_BAD_PAD_BYTE_COUNT 103
  458. # define RSA_R_BAD_SIGNATURE 104
  459. # define RSA_R_BLOCK_TYPE_IS_NOT_01 106
  460. # define RSA_R_BLOCK_TYPE_IS_NOT_02 107
  461. # define RSA_R_DATA_GREATER_THAN_MOD_LEN 108
  462. # define RSA_R_DATA_TOO_LARGE 109
  463. # define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 110
  464. # define RSA_R_DATA_TOO_LARGE_FOR_MODULUS 132
  465. # define RSA_R_DATA_TOO_SMALL 111
  466. # define RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE 122
  467. # define RSA_R_DIGEST_DOES_NOT_MATCH 158
  468. # define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY 112
  469. # define RSA_R_DMP1_NOT_CONGRUENT_TO_D 124
  470. # define RSA_R_DMQ1_NOT_CONGRUENT_TO_D 125
  471. # define RSA_R_D_E_NOT_CONGRUENT_TO_1 123
  472. # define RSA_R_FIRST_OCTET_INVALID 133
  473. # define RSA_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE 144
  474. # define RSA_R_INVALID_DIGEST 157
  475. # define RSA_R_INVALID_DIGEST_LENGTH 143
  476. # define RSA_R_INVALID_HEADER 137
  477. # define RSA_R_INVALID_LABEL 160
  478. # define RSA_R_INVALID_MESSAGE_LENGTH 131
  479. # define RSA_R_INVALID_MGF1_MD 156
  480. # define RSA_R_INVALID_OAEP_PARAMETERS 161
  481. # define RSA_R_INVALID_PADDING 138
  482. # define RSA_R_INVALID_PADDING_MODE 141
  483. # define RSA_R_INVALID_PSS_PARAMETERS 149
  484. # define RSA_R_INVALID_PSS_SALTLEN 146
  485. # define RSA_R_INVALID_SALT_LENGTH 150
  486. # define RSA_R_INVALID_TRAILER 139
  487. # define RSA_R_INVALID_X931_DIGEST 142
  488. # define RSA_R_IQMP_NOT_INVERSE_OF_Q 126
  489. # define RSA_R_KEY_SIZE_TOO_SMALL 120
  490. # define RSA_R_LAST_OCTET_INVALID 134
  491. # define RSA_R_MODULUS_TOO_LARGE 105
  492. # define RSA_R_NO_PUBLIC_EXPONENT 140
  493. # define RSA_R_NULL_BEFORE_BLOCK_MISSING 113
  494. # define RSA_R_N_DOES_NOT_EQUAL_P_Q 127
  495. # define RSA_R_OAEP_DECODING_ERROR 121
  496. # define RSA_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE 148
  497. # define RSA_R_PADDING_CHECK_FAILED 114
  498. # define RSA_R_PKCS_DECODING_ERROR 159
  499. # define RSA_R_P_NOT_PRIME 128
  500. # define RSA_R_Q_NOT_PRIME 129
  501. # define RSA_R_RSA_OPERATIONS_NOT_SUPPORTED 130
  502. # define RSA_R_SLEN_CHECK_FAILED 136
  503. # define RSA_R_SLEN_RECOVERY_FAILED 135
  504. # define RSA_R_SSLV3_ROLLBACK_ATTACK 115
  505. # define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116
  506. # define RSA_R_UNKNOWN_ALGORITHM_TYPE 117
  507. # define RSA_R_UNKNOWN_DIGEST 166
  508. # define RSA_R_UNKNOWN_MASK_DIGEST 151
  509. # define RSA_R_UNKNOWN_PADDING_TYPE 118
  510. # define RSA_R_UNSUPPORTED_ENCRYPTION_TYPE 162
  511. # define RSA_R_UNSUPPORTED_LABEL_SOURCE 163
  512. # define RSA_R_UNSUPPORTED_MASK_ALGORITHM 153
  513. # define RSA_R_UNSUPPORTED_MASK_PARAMETER 154
  514. # define RSA_R_UNSUPPORTED_SIGNATURE_TYPE 155
  515. # define RSA_R_VALUE_MISSING 147
  516. # define RSA_R_WRONG_SIGNATURE_LENGTH 119
  517. # ifdef __cplusplus
  518. }
  519. # endif
  520. # endif
  521. #endif