A local copy of OpenSSL from GitHub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

607 lines
28 KiB

This is a first-cut at improving the callback mechanisms used in key-generation and prime-checking functions. Rather than explicitly passing callback functions and caller-defined context data for the callbacks, a new structure BN_GENCB is defined that encapsulates this; a pointer to the structure is passed to all such functions instead. This wrapper structure allows the encapsulation of "old" and "new" style callbacks - "new" callbacks return a boolean result on the understanding that returning FALSE should terminate keygen/primality processing. The BN_GENCB abstraction will allow future callback modifications without needing to break binary compatibility nor change the API function prototypes. The new API functions have been given names ending in "_ex" and the old functions are implemented as wrappers to the new ones. The OPENSSL_NO_DEPRECATED symbol has been introduced so that, if defined, declaration of the older functions will be skipped. NB: Some openssl-internal code will stick with the older callbacks for now, so appropriate "#undef" logic will be put in place - this is in case the user is *building* openssl (rather than *including* its headers) with this symbol defined. There is another change in the new _ex functions; the key-generation functions do not return key structures but operate on structures passed by the caller, the return value is a boolean. This will allow for a smoother transition to having key-generation as "virtual function" in the various ***_METHOD tables.
20 years ago
This is a first-cut at improving the callback mechanisms used in key-generation and prime-checking functions. Rather than explicitly passing callback functions and caller-defined context data for the callbacks, a new structure BN_GENCB is defined that encapsulates this; a pointer to the structure is passed to all such functions instead. This wrapper structure allows the encapsulation of "old" and "new" style callbacks - "new" callbacks return a boolean result on the understanding that returning FALSE should terminate keygen/primality processing. The BN_GENCB abstraction will allow future callback modifications without needing to break binary compatibility nor change the API function prototypes. The new API functions have been given names ending in "_ex" and the old functions are implemented as wrappers to the new ones. The OPENSSL_NO_DEPRECATED symbol has been introduced so that, if defined, declaration of the older functions will be skipped. NB: Some openssl-internal code will stick with the older callbacks for now, so appropriate "#undef" logic will be put in place - this is in case the user is *building* openssl (rather than *including* its headers) with this symbol defined. There is another change in the new _ex functions; the key-generation functions do not return key structures but operate on structures passed by the caller, the return value is a boolean. This will allow for a smoother transition to having key-generation as "virtual function" in the various ***_METHOD tables.
20 years ago
This is a first-cut at improving the callback mechanisms used in key-generation and prime-checking functions. Rather than explicitly passing callback functions and caller-defined context data for the callbacks, a new structure BN_GENCB is defined that encapsulates this; a pointer to the structure is passed to all such functions instead. This wrapper structure allows the encapsulation of "old" and "new" style callbacks - "new" callbacks return a boolean result on the understanding that returning FALSE should terminate keygen/primality processing. The BN_GENCB abstraction will allow future callback modifications without needing to break binary compatibility nor change the API function prototypes. The new API functions have been given names ending in "_ex" and the old functions are implemented as wrappers to the new ones. The OPENSSL_NO_DEPRECATED symbol has been introduced so that, if defined, declaration of the older functions will be skipped. NB: Some openssl-internal code will stick with the older callbacks for now, so appropriate "#undef" logic will be put in place - this is in case the user is *building* openssl (rather than *including* its headers) with this symbol defined. There is another change in the new _ex functions; the key-generation functions do not return key structures but operate on structures passed by the caller, the return value is a boolean. This will allow for a smoother transition to having key-generation as "virtual function" in the various ***_METHOD tables.
20 years ago
  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. /*
  58. * new with 0.9.8f; the built-in RSA
  59. * implementation now uses constant time
  60. * operations by default in private key operations,
  61. * e.g., constant time modular exponentiation,
  62. * modular inverse without leaking branches,
  63. * division without leaking branches. This
  64. * flag disables these constant time
  65. * operations and results in faster RSA
  66. * private key operations.
  67. */
  68. # define RSA_FLAG_NO_CONSTTIME 0x0100
  69. # if OPENSSL_API_COMPAT < 0x00908000L
  70. /* deprecated name for the flag*/
  71. /*
  72. * new with 0.9.7h; the built-in RSA
  73. * implementation now uses constant time
  74. * modular exponentiation for secret exponents
  75. * by default. This flag causes the
  76. * faster variable sliding window method to
  77. * be used for all exponents.
  78. */
  79. # define RSA_FLAG_NO_EXP_CONSTTIME RSA_FLAG_NO_CONSTTIME
  80. # endif
  81. # define EVP_PKEY_CTX_set_rsa_padding(ctx, pad) \
  82. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, -1, EVP_PKEY_CTRL_RSA_PADDING, \
  83. pad, NULL)
  84. # define EVP_PKEY_CTX_get_rsa_padding(ctx, ppad) \
  85. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, -1, \
  86. EVP_PKEY_CTRL_GET_RSA_PADDING, 0, ppad)
  87. # define EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, len) \
  88. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, \
  89. (EVP_PKEY_OP_SIGN|EVP_PKEY_OP_VERIFY), \
  90. EVP_PKEY_CTRL_RSA_PSS_SALTLEN, \
  91. len, NULL)
  92. # define EVP_PKEY_CTX_get_rsa_pss_saltlen(ctx, plen) \
  93. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, \
  94. (EVP_PKEY_OP_SIGN|EVP_PKEY_OP_VERIFY), \
  95. EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN, \
  96. 0, plen)
  97. # define EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, bits) \
  98. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_KEYGEN, \
  99. EVP_PKEY_CTRL_RSA_KEYGEN_BITS, bits, NULL)
  100. # define EVP_PKEY_CTX_set_rsa_keygen_pubexp(ctx, pubexp) \
  101. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_KEYGEN, \
  102. EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP, 0, pubexp)
  103. # define EVP_PKEY_CTX_set_rsa_mgf1_md(ctx, md) \
  104. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, \
  105. EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT, \
  106. EVP_PKEY_CTRL_RSA_MGF1_MD, 0, (void *)md)
  107. # define EVP_PKEY_CTX_set_rsa_oaep_md(ctx, md) \
  108. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, \
  109. EVP_PKEY_CTRL_RSA_OAEP_MD, 0, (void *)md)
  110. # define EVP_PKEY_CTX_get_rsa_mgf1_md(ctx, pmd) \
  111. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, \
  112. EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT, \
  113. EVP_PKEY_CTRL_GET_RSA_MGF1_MD, 0, (void *)pmd)
  114. # define EVP_PKEY_CTX_get_rsa_oaep_md(ctx, pmd) \
  115. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, \
  116. EVP_PKEY_CTRL_GET_RSA_OAEP_MD, 0, (void *)pmd)
  117. # define EVP_PKEY_CTX_set0_rsa_oaep_label(ctx, l, llen) \
  118. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, \
  119. EVP_PKEY_CTRL_RSA_OAEP_LABEL, llen, (void *)l)
  120. # define EVP_PKEY_CTX_get0_rsa_oaep_label(ctx, l) \
  121. EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, \
  122. EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL, 0, (void *)l)
  123. # define EVP_PKEY_CTRL_RSA_PADDING (EVP_PKEY_ALG_CTRL + 1)
  124. # define EVP_PKEY_CTRL_RSA_PSS_SALTLEN (EVP_PKEY_ALG_CTRL + 2)
  125. # define EVP_PKEY_CTRL_RSA_KEYGEN_BITS (EVP_PKEY_ALG_CTRL + 3)
  126. # define EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP (EVP_PKEY_ALG_CTRL + 4)
  127. # define EVP_PKEY_CTRL_RSA_MGF1_MD (EVP_PKEY_ALG_CTRL + 5)
  128. # define EVP_PKEY_CTRL_GET_RSA_PADDING (EVP_PKEY_ALG_CTRL + 6)
  129. # define EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN (EVP_PKEY_ALG_CTRL + 7)
  130. # define EVP_PKEY_CTRL_GET_RSA_MGF1_MD (EVP_PKEY_ALG_CTRL + 8)
  131. # define EVP_PKEY_CTRL_RSA_OAEP_MD (EVP_PKEY_ALG_CTRL + 9)
  132. # define EVP_PKEY_CTRL_RSA_OAEP_LABEL (EVP_PKEY_ALG_CTRL + 10)
  133. # define EVP_PKEY_CTRL_GET_RSA_OAEP_MD (EVP_PKEY_ALG_CTRL + 11)
  134. # define EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL (EVP_PKEY_ALG_CTRL + 12)
  135. # define RSA_PKCS1_PADDING 1
  136. # define RSA_SSLV23_PADDING 2
  137. # define RSA_NO_PADDING 3
  138. # define RSA_PKCS1_OAEP_PADDING 4
  139. # define RSA_X931_PADDING 5
  140. /* EVP_PKEY_ only */
  141. # define RSA_PKCS1_PSS_PADDING 6
  142. # define RSA_PKCS1_PADDING_SIZE 11
  143. # define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,arg)
  144. # define RSA_get_app_data(s) RSA_get_ex_data(s,0)
  145. RSA *RSA_new(void);
  146. RSA *RSA_new_method(ENGINE *engine);
  147. int RSA_bits(const RSA *rsa);
  148. int RSA_size(const RSA *rsa);
  149. int RSA_security_bits(const RSA *rsa);
  150. int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
  151. int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q);
  152. int RSA_set0_crt_params(RSA *r,BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp);
  153. void RSA_get0_key(const RSA *r, BIGNUM **n, BIGNUM **e, BIGNUM **d);
  154. void RSA_get0_factors(const RSA *r, BIGNUM **p, BIGNUM **q);
  155. void RSA_get0_crt_params(const RSA *r,
  156. BIGNUM **dmp1, BIGNUM **dmq1, BIGNUM **iqmp);
  157. void RSA_clear_flags(RSA *r, int flags);
  158. int RSA_test_flags(const RSA *r, int flags);
  159. void RSA_set_flags(RSA *r, int flags);
  160. ENGINE *RSA_get0_engine(RSA *r);
  161. /* Deprecated version */
  162. DEPRECATEDIN_0_9_8(RSA *RSA_generate_key(int bits, unsigned long e, void
  163. (*callback) (int, int, void *),
  164. void *cb_arg))
  165. /* New version */
  166. int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
  167. int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1,
  168. BIGNUM *q2, const BIGNUM *Xp1, const BIGNUM *Xp2,
  169. const BIGNUM *Xp, const BIGNUM *Xq1, const BIGNUM *Xq2,
  170. const BIGNUM *Xq, const BIGNUM *e, BN_GENCB *cb);
  171. int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e,
  172. BN_GENCB *cb);
  173. int RSA_check_key(const RSA *);
  174. int RSA_check_key_ex(const RSA *, BN_GENCB *cb);
  175. /* next 4 return -1 on error */
  176. int RSA_public_encrypt(int flen, const unsigned char *from,
  177. unsigned char *to, RSA *rsa, int padding);
  178. int RSA_private_encrypt(int flen, const unsigned char *from,
  179. unsigned char *to, RSA *rsa, int padding);
  180. int RSA_public_decrypt(int flen, const unsigned char *from,
  181. unsigned char *to, RSA *rsa, int padding);
  182. int RSA_private_decrypt(int flen, const unsigned char *from,
  183. unsigned char *to, RSA *rsa, int padding);
  184. void RSA_free(RSA *r);
  185. /* "up" the RSA object's reference count */
  186. int RSA_up_ref(RSA *r);
  187. int RSA_flags(const RSA *r);
  188. void RSA_set_default_method(const RSA_METHOD *meth);
  189. const RSA_METHOD *RSA_get_default_method(void);
  190. const RSA_METHOD *RSA_get_method(const RSA *rsa);
  191. int RSA_set_method(RSA *rsa, const RSA_METHOD *meth);
  192. /* This function needs the memory locking malloc callbacks to be installed */
  193. int RSA_memory_lock(RSA *r);
  194. /* these are the actual RSA functions */
  195. const RSA_METHOD *RSA_PKCS1_OpenSSL(void);
  196. const RSA_METHOD *RSA_null_method(void);
  197. DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPublicKey)
  198. DECLARE_ASN1_ENCODE_FUNCTIONS_const(RSA, RSAPrivateKey)
  199. typedef struct rsa_pss_params_st {
  200. X509_ALGOR *hashAlgorithm;
  201. X509_ALGOR *maskGenAlgorithm;
  202. ASN1_INTEGER *saltLength;
  203. ASN1_INTEGER *trailerField;
  204. } RSA_PSS_PARAMS;
  205. DECLARE_ASN1_FUNCTIONS(RSA_PSS_PARAMS)
  206. typedef struct rsa_oaep_params_st {
  207. X509_ALGOR *hashFunc;
  208. X509_ALGOR *maskGenFunc;
  209. X509_ALGOR *pSourceFunc;
  210. } RSA_OAEP_PARAMS;
  211. DECLARE_ASN1_FUNCTIONS(RSA_OAEP_PARAMS)
  212. # ifndef OPENSSL_NO_STDIO
  213. int RSA_print_fp(FILE *fp, const RSA *r, int offset);
  214. # endif
  215. int RSA_print(BIO *bp, const RSA *r, int offset);
  216. /*
  217. * The following 2 functions sign and verify a X509_SIG ASN1 object inside
  218. * PKCS#1 padded RSA encryption
  219. */
  220. int RSA_sign(int type, const unsigned char *m, unsigned int m_length,
  221. unsigned char *sigret, unsigned int *siglen, RSA *rsa);
  222. int RSA_verify(int type, const unsigned char *m, unsigned int m_length,
  223. const unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
  224. /*
  225. * The following 2 function sign and verify a ASN1_OCTET_STRING object inside
  226. * PKCS#1 padded RSA encryption
  227. */
  228. int RSA_sign_ASN1_OCTET_STRING(int type,
  229. const unsigned char *m, unsigned int m_length,
  230. unsigned char *sigret, unsigned int *siglen,
  231. RSA *rsa);
  232. int RSA_verify_ASN1_OCTET_STRING(int type, const unsigned char *m,
  233. unsigned int m_length, unsigned char *sigbuf,
  234. unsigned int siglen, RSA *rsa);
  235. int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
  236. void RSA_blinding_off(RSA *rsa);
  237. BN_BLINDING *RSA_setup_blinding(RSA *rsa, BN_CTX *ctx);
  238. int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen,
  239. const unsigned char *f, int fl);
  240. int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
  241. const unsigned char *f, int fl,
  242. int rsa_len);
  243. int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
  244. const unsigned char *f, int fl);
  245. int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
  246. const unsigned char *f, int fl,
  247. int rsa_len);
  248. int PKCS1_MGF1(unsigned char *mask, long len, const unsigned char *seed,
  249. long seedlen, const EVP_MD *dgst);
  250. int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
  251. const unsigned char *f, int fl,
  252. const unsigned char *p, int pl);
  253. int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
  254. const unsigned char *f, int fl, int rsa_len,
  255. const unsigned char *p, int pl);
  256. int RSA_padding_add_PKCS1_OAEP_mgf1(unsigned char *to, int tlen,
  257. const unsigned char *from, int flen,
  258. const unsigned char *param, int plen,
  259. const EVP_MD *md, const EVP_MD *mgf1md);
  260. int RSA_padding_check_PKCS1_OAEP_mgf1(unsigned char *to, int tlen,
  261. const unsigned char *from, int flen,
  262. int num, const unsigned char *param,
  263. int plen, const EVP_MD *md,
  264. const EVP_MD *mgf1md);
  265. int RSA_padding_add_SSLv23(unsigned char *to, int tlen,
  266. const unsigned char *f, int fl);
  267. int RSA_padding_check_SSLv23(unsigned char *to, int tlen,
  268. const unsigned char *f, int fl, int rsa_len);
  269. int RSA_padding_add_none(unsigned char *to, int tlen, const unsigned char *f,
  270. int fl);
  271. int RSA_padding_check_none(unsigned char *to, int tlen,
  272. const unsigned char *f, int fl, int rsa_len);
  273. int RSA_padding_add_X931(unsigned char *to, int tlen, const unsigned char *f,
  274. int fl);
  275. int RSA_padding_check_X931(unsigned char *to, int tlen,
  276. const unsigned char *f, int fl, int rsa_len);
  277. int RSA_X931_hash_id(int nid);
  278. int RSA_verify_PKCS1_PSS(RSA *rsa, const unsigned char *mHash,
  279. const EVP_MD *Hash, const unsigned char *EM,
  280. int sLen);
  281. int RSA_padding_add_PKCS1_PSS(RSA *rsa, unsigned char *EM,
  282. const unsigned char *mHash, const EVP_MD *Hash,
  283. int sLen);
  284. int RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const unsigned char *mHash,
  285. const EVP_MD *Hash, const EVP_MD *mgf1Hash,
  286. const unsigned char *EM, int sLen);
  287. int RSA_padding_add_PKCS1_PSS_mgf1(RSA *rsa, unsigned char *EM,
  288. const unsigned char *mHash,
  289. const EVP_MD *Hash, const EVP_MD *mgf1Hash,
  290. int sLen);
  291. #define RSA_get_ex_new_index(l, p, newf, dupf, freef) \
  292. CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_RSA, l, p, newf, dupf, freef)
  293. int RSA_set_ex_data(RSA *r, int idx, void *arg);
  294. void *RSA_get_ex_data(const RSA *r, int idx);
  295. RSA *RSAPublicKey_dup(RSA *rsa);
  296. RSA *RSAPrivateKey_dup(RSA *rsa);
  297. /*
  298. * If this flag is set the RSA method is FIPS compliant and can be used in
  299. * FIPS mode. This is set in the validated module method. If an application
  300. * sets this flag in its own methods it is its responsibility to ensure the
  301. * result is compliant.
  302. */
  303. # define RSA_FLAG_FIPS_METHOD 0x0400
  304. /*
  305. * If this flag is set the operations normally disabled in FIPS mode are
  306. * permitted it is then the applications responsibility to ensure that the
  307. * usage is compliant.
  308. */
  309. # define RSA_FLAG_NON_FIPS_ALLOW 0x0400
  310. /*
  311. * Application has decided PRNG is good enough to generate a key: don't
  312. * check.
  313. */
  314. # define RSA_FLAG_CHECKED 0x0800
  315. RSA_METHOD *RSA_meth_new(const char *name, int flags);
  316. void RSA_meth_free(RSA_METHOD *meth);
  317. RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth);
  318. const char *RSA_meth_get0_name(const RSA_METHOD *meth);
  319. int RSA_meth_set1_name(RSA_METHOD *meth, const char *name);
  320. int RSA_meth_get_flags(RSA_METHOD *meth);
  321. int RSA_meth_set_flags(RSA_METHOD *meth, int flags);
  322. void *RSA_meth_get0_app_data(const RSA_METHOD *meth);
  323. int RSA_meth_set0_app_data(RSA_METHOD *meth, void *app_data);
  324. int (*RSA_meth_get_pub_enc(const RSA_METHOD *meth))
  325. (int flen, const unsigned char *from,
  326. unsigned char *to, RSA *rsa, int padding);
  327. int RSA_meth_set_pub_enc(RSA_METHOD *rsa,
  328. int (*pub_enc) (int flen, const unsigned char *from,
  329. unsigned char *to, RSA *rsa,
  330. int padding));
  331. int (*RSA_meth_get_pub_dec(const RSA_METHOD *meth))
  332. (int flen, const unsigned char *from,
  333. unsigned char *to, RSA *rsa, int padding);
  334. int RSA_meth_set_pub_dec(RSA_METHOD *rsa,
  335. int (*pub_dec) (int flen, const unsigned char *from,
  336. unsigned char *to, RSA *rsa,
  337. int padding));
  338. int (*RSA_meth_get_priv_enc(const RSA_METHOD *meth))
  339. (int flen, const unsigned char *from,
  340. unsigned char *to, RSA *rsa, int padding);
  341. int RSA_meth_set_priv_enc(RSA_METHOD *rsa,
  342. int (*priv_enc) (int flen, const unsigned char *from,
  343. unsigned char *to, RSA *rsa,
  344. int padding));
  345. int (*RSA_meth_get_priv_dec(const RSA_METHOD *meth))
  346. (int flen, const unsigned char *from,
  347. unsigned char *to, RSA *rsa, int padding);
  348. int RSA_meth_set_priv_dec(RSA_METHOD *rsa,
  349. int (*priv_dec) (int flen, const unsigned char *from,
  350. unsigned char *to, RSA *rsa,
  351. int padding));
  352. int (*RSA_meth_get_mod_exp(const RSA_METHOD *meth))
  353. (BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx);
  354. int RSA_meth_set_mod_exp(RSA_METHOD *rsa,
  355. int (*mod_exp) (BIGNUM *r0, const BIGNUM *I, RSA *rsa,
  356. BN_CTX *ctx));
  357. int (*RSA_meth_get_bn_mod_exp(const RSA_METHOD *meth))
  358. (BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
  359. const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
  360. int RSA_meth_set_bn_mod_exp(RSA_METHOD *rsa,
  361. int (*bn_mod_exp) (BIGNUM *r,
  362. const BIGNUM *a,
  363. const BIGNUM *p,
  364. const BIGNUM *m,
  365. BN_CTX *ctx,
  366. BN_MONT_CTX *m_ctx));
  367. int (*RSA_meth_get_init(const RSA_METHOD *meth)) (RSA *rsa);
  368. int RSA_meth_set_init(RSA_METHOD *rsa, int (*init) (RSA *rsa));
  369. int (*RSA_meth_get_finish(const RSA_METHOD *meth)) (RSA *rsa);
  370. int RSA_meth_set_finish(RSA_METHOD *rsa, int (*finish) (RSA *rsa));
  371. int (*RSA_meth_get_sign(const RSA_METHOD *meth))
  372. (int type,
  373. const unsigned char *m, unsigned int m_length,
  374. unsigned char *sigret, unsigned int *siglen,
  375. const RSA *rsa);
  376. int RSA_meth_set_sign(RSA_METHOD *rsa,
  377. int (*sign) (int type, const unsigned char *m,
  378. unsigned int m_length,
  379. unsigned char *sigret, unsigned int *siglen,
  380. const RSA *rsa));
  381. int (*RSA_meth_get_verify(const RSA_METHOD *meth))
  382. (int dtype, const unsigned char *m,
  383. unsigned int m_length, const unsigned char *sigbuf,
  384. unsigned int siglen, const RSA *rsa);
  385. int RSA_meth_set_verify(RSA_METHOD *rsa,
  386. int (*verify) (int dtype, const unsigned char *m,
  387. unsigned int m_length,
  388. const unsigned char *sigbuf,
  389. unsigned int siglen, const RSA *rsa));
  390. int (*RSA_meth_get_keygen(const RSA_METHOD *meth))
  391. (RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
  392. int RSA_meth_set_keygen(RSA_METHOD *rsa,
  393. int (*keygen) (RSA *rsa, int bits, BIGNUM *e,
  394. BN_GENCB *cb));
  395. /* BEGIN ERROR CODES */
  396. /*
  397. * The following lines are auto generated by the script mkerr.pl. Any changes
  398. * made after this point may be overwritten when the script is next run.
  399. */
  400. void ERR_load_RSA_strings(void);
  401. /* Error codes for the RSA functions. */
  402. /* Function codes. */
  403. # define RSA_F_CHECK_PADDING_MD 140
  404. # define RSA_F_DO_RSA_PRINT 146
  405. # define RSA_F_FIPS_RSA_SIGN_DIGEST 149
  406. # define RSA_F_FIPS_RSA_VERIFY 150
  407. # define RSA_F_FIPS_RSA_VERIFY_DIGEST 151
  408. # define RSA_F_INT_RSA_VERIFY 145
  409. # define RSA_F_MEMORY_LOCK 100
  410. # define RSA_F_OLD_RSA_PRIV_DECODE 147
  411. # define RSA_F_PKEY_RSA_CTRL 143
  412. # define RSA_F_PKEY_RSA_CTRL_STR 144
  413. # define RSA_F_PKEY_RSA_SIGN 142
  414. # define RSA_F_PKEY_RSA_VERIFYRECOVER 141
  415. # define RSA_F_RSA_ALGOR_TO_MD 156
  416. # define RSA_F_RSA_BUILTIN_KEYGEN 129
  417. # define RSA_F_RSA_CHECK_KEY 123
  418. # define RSA_F_RSA_CHECK_KEY_EX 160
  419. # define RSA_F_RSA_CMS_DECRYPT 159
  420. # define RSA_F_RSA_GENERATE_KEY 105
  421. # define RSA_F_RSA_ITEM_VERIFY 148
  422. # define RSA_F_RSA_MEMORY_LOCK 130
  423. # define RSA_F_RSA_METH_DUP 161
  424. # define RSA_F_RSA_METH_NEW 162
  425. # define RSA_F_RSA_METH_SET1_NAME 163
  426. # define RSA_F_RSA_MGF1_TO_MD 157
  427. # define RSA_F_RSA_NEW_METHOD 106
  428. # define RSA_F_RSA_NULL 124
  429. # define RSA_F_RSA_NULL_MOD_EXP 131
  430. # define RSA_F_RSA_NULL_PRIVATE_DECRYPT 132
  431. # define RSA_F_RSA_NULL_PRIVATE_ENCRYPT 133
  432. # define RSA_F_RSA_NULL_PUBLIC_DECRYPT 134
  433. # define RSA_F_RSA_NULL_PUBLIC_ENCRYPT 135
  434. # define RSA_F_RSA_OAEP_TO_CTX 158
  435. # define RSA_F_RSA_OSSL_PRIVATE_DECRYPT 101
  436. # define RSA_F_RSA_OSSL_PRIVATE_ENCRYPT 102
  437. # define RSA_F_RSA_OSSL_PUBLIC_DECRYPT 103
  438. # define RSA_F_RSA_OSSL_PUBLIC_ENCRYPT 104
  439. # define RSA_F_RSA_PADDING_ADD_NONE 107
  440. # define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP 121
  441. # define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP_MGF1 154
  442. # define RSA_F_RSA_PADDING_ADD_PKCS1_PSS 125
  443. # define RSA_F_RSA_PADDING_ADD_PKCS1_PSS_MGF1 152
  444. # define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 108
  445. # define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2 109
  446. # define RSA_F_RSA_PADDING_ADD_SSLV23 110
  447. # define RSA_F_RSA_PADDING_ADD_X931 127
  448. # define RSA_F_RSA_PADDING_CHECK_NONE 111
  449. # define RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP 122
  450. # define RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP_MGF1 153
  451. # define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1 112
  452. # define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2 113
  453. # define RSA_F_RSA_PADDING_CHECK_SSLV23 114
  454. # define RSA_F_RSA_PADDING_CHECK_X931 128
  455. # define RSA_F_RSA_PRINT 115
  456. # define RSA_F_RSA_PRINT_FP 116
  457. # define RSA_F_RSA_PRIV_DECODE 137
  458. # define RSA_F_RSA_PRIV_ENCODE 138
  459. # define RSA_F_RSA_PSS_TO_CTX 155
  460. # define RSA_F_RSA_PUB_DECODE 139
  461. # define RSA_F_RSA_SETUP_BLINDING 136
  462. # define RSA_F_RSA_SIGN 117
  463. # define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 118
  464. # define RSA_F_RSA_VERIFY 119
  465. # define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING 120
  466. # define RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1 126
  467. /* Reason codes. */
  468. # define RSA_R_ALGORITHM_MISMATCH 100
  469. # define RSA_R_BAD_E_VALUE 101
  470. # define RSA_R_BAD_FIXED_HEADER_DECRYPT 102
  471. # define RSA_R_BAD_PAD_BYTE_COUNT 103
  472. # define RSA_R_BAD_SIGNATURE 104
  473. # define RSA_R_BLOCK_TYPE_IS_NOT_01 106
  474. # define RSA_R_BLOCK_TYPE_IS_NOT_02 107
  475. # define RSA_R_DATA_GREATER_THAN_MOD_LEN 108
  476. # define RSA_R_DATA_TOO_LARGE 109
  477. # define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 110
  478. # define RSA_R_DATA_TOO_LARGE_FOR_MODULUS 132
  479. # define RSA_R_DATA_TOO_SMALL 111
  480. # define RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE 122
  481. # define RSA_R_DIGEST_DOES_NOT_MATCH 158
  482. # define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY 112
  483. # define RSA_R_DMP1_NOT_CONGRUENT_TO_D 124
  484. # define RSA_R_DMQ1_NOT_CONGRUENT_TO_D 125
  485. # define RSA_R_D_E_NOT_CONGRUENT_TO_1 123
  486. # define RSA_R_FIRST_OCTET_INVALID 133
  487. # define RSA_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE 144
  488. # define RSA_R_INVALID_DIGEST 157
  489. # define RSA_R_INVALID_DIGEST_LENGTH 143
  490. # define RSA_R_INVALID_HEADER 137
  491. # define RSA_R_INVALID_KEYBITS 145
  492. # define RSA_R_INVALID_LABEL 160
  493. # define RSA_R_INVALID_MESSAGE_LENGTH 131
  494. # define RSA_R_INVALID_MGF1_MD 156
  495. # define RSA_R_INVALID_OAEP_PARAMETERS 161
  496. # define RSA_R_INVALID_PADDING 138
  497. # define RSA_R_INVALID_PADDING_MODE 141
  498. # define RSA_R_INVALID_PSS_PARAMETERS 149
  499. # define RSA_R_INVALID_PSS_SALTLEN 146
  500. # define RSA_R_INVALID_SALT_LENGTH 150
  501. # define RSA_R_INVALID_TRAILER 139
  502. # define RSA_R_INVALID_X931_DIGEST 142
  503. # define RSA_R_IQMP_NOT_INVERSE_OF_Q 126
  504. # define RSA_R_KEY_SIZE_TOO_SMALL 120
  505. # define RSA_R_LAST_OCTET_INVALID 134
  506. # define RSA_R_MODULUS_TOO_LARGE 105
  507. # define RSA_R_NO_PUBLIC_EXPONENT 140
  508. # define RSA_R_NULL_BEFORE_BLOCK_MISSING 113
  509. # define RSA_R_N_DOES_NOT_EQUAL_P_Q 127
  510. # define RSA_R_OAEP_DECODING_ERROR 121
  511. # define RSA_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE 148
  512. # define RSA_R_PADDING_CHECK_FAILED 114
  513. # define RSA_R_PKCS_DECODING_ERROR 159
  514. # define RSA_R_P_NOT_PRIME 128
  515. # define RSA_R_Q_NOT_PRIME 129
  516. # define RSA_R_RSA_OPERATIONS_NOT_SUPPORTED 130
  517. # define RSA_R_SLEN_CHECK_FAILED 136
  518. # define RSA_R_SLEN_RECOVERY_FAILED 135
  519. # define RSA_R_SSLV3_ROLLBACK_ATTACK 115
  520. # define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116
  521. # define RSA_R_UNKNOWN_ALGORITHM_TYPE 117
  522. # define RSA_R_UNKNOWN_DIGEST 166
  523. # define RSA_R_UNKNOWN_MASK_DIGEST 151
  524. # define RSA_R_UNKNOWN_PADDING_TYPE 118
  525. # define RSA_R_UNKNOWN_PSS_DIGEST 152
  526. # define RSA_R_UNSUPPORTED_ENCRYPTION_TYPE 162
  527. # define RSA_R_UNSUPPORTED_LABEL_SOURCE 163
  528. # define RSA_R_UNSUPPORTED_MASK_ALGORITHM 153
  529. # define RSA_R_UNSUPPORTED_MASK_PARAMETER 154
  530. # define RSA_R_UNSUPPORTED_SIGNATURE_TYPE 155
  531. # define RSA_R_VALUE_MISSING 147
  532. # define RSA_R_WRONG_SIGNATURE_LENGTH 119
  533. # ifdef __cplusplus
  534. }
  535. # endif
  536. # endif
  537. #endif