RSA_meth_new.pod 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. =pod
  2. =head1 NAME
  3. RSA_meth_get0_app_data, RSA_meth_set0_app_data,
  4. RSA_meth_new, RSA_meth_free, RSA_meth_dup, RSA_meth_get0_name,
  5. RSA_meth_set1_name, RSA_meth_get_flags, RSA_meth_set_flags,
  6. RSA_meth_get_pub_enc,
  7. RSA_meth_set_pub_enc, RSA_meth_get_pub_dec, RSA_meth_set_pub_dec,
  8. RSA_meth_get_priv_enc, RSA_meth_set_priv_enc, RSA_meth_get_priv_dec,
  9. RSA_meth_set_priv_dec, RSA_meth_get_mod_exp, RSA_meth_set_mod_exp,
  10. RSA_meth_get_bn_mod_exp, RSA_meth_set_bn_mod_exp, RSA_meth_get_init,
  11. RSA_meth_set_init, RSA_meth_get_finish, RSA_meth_set_finish,
  12. RSA_meth_get_sign, RSA_meth_set_sign, RSA_meth_get_verify,
  13. RSA_meth_set_verify, RSA_meth_get_keygen, RSA_meth_set_keygen,
  14. RSA_meth_get_multi_prime_keygen, RSA_meth_set_multi_prime_keygen
  15. - Routines to build up RSA methods
  16. =head1 SYNOPSIS
  17. #include <openssl/rsa.h>
  18. RSA_METHOD *RSA_meth_new(const char *name, int flags);
  19. void RSA_meth_free(RSA_METHOD *meth);
  20. RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth);
  21. const char *RSA_meth_get0_name(const RSA_METHOD *meth);
  22. int RSA_meth_set1_name(RSA_METHOD *meth, const char *name);
  23. int RSA_meth_get_flags(const RSA_METHOD *meth);
  24. int RSA_meth_set_flags(RSA_METHOD *meth, int flags);
  25. void *RSA_meth_get0_app_data(const RSA_METHOD *meth);
  26. int RSA_meth_set0_app_data(RSA_METHOD *meth, void *app_data);
  27. int (*RSA_meth_get_pub_enc(const RSA_METHOD *meth))(int flen, const unsigned char *from,
  28. unsigned char *to, RSA *rsa, int padding);
  29. int RSA_meth_set_pub_enc(RSA_METHOD *rsa,
  30. int (*pub_enc)(int flen, const unsigned char *from,
  31. unsigned char *to, RSA *rsa,
  32. int padding));
  33. int (*RSA_meth_get_pub_dec(const RSA_METHOD *meth))
  34. (int flen, const unsigned char *from,
  35. unsigned char *to, RSA *rsa, int padding);
  36. int RSA_meth_set_pub_dec(RSA_METHOD *rsa,
  37. int (*pub_dec)(int flen, const unsigned char *from,
  38. unsigned char *to, RSA *rsa,
  39. int padding));
  40. int (*RSA_meth_get_priv_enc(const RSA_METHOD *meth))(int flen, const unsigned char *from,
  41. unsigned char *to, RSA *rsa,
  42. int padding);
  43. int RSA_meth_set_priv_enc(RSA_METHOD *rsa,
  44. int (*priv_enc)(int flen, const unsigned char *from,
  45. unsigned char *to, RSA *rsa, int padding));
  46. int (*RSA_meth_get_priv_dec(const RSA_METHOD *meth))(int flen, const unsigned char *from,
  47. unsigned char *to, RSA *rsa,
  48. int padding);
  49. int RSA_meth_set_priv_dec(RSA_METHOD *rsa,
  50. int (*priv_dec)(int flen, const unsigned char *from,
  51. unsigned char *to, RSA *rsa, int padding));
  52. /* Can be null */
  53. int (*RSA_meth_get_mod_exp(const RSA_METHOD *meth))(BIGNUM *r0, const BIGNUM *I,
  54. RSA *rsa, BN_CTX *ctx);
  55. int RSA_meth_set_mod_exp(RSA_METHOD *rsa,
  56. int (*mod_exp)(BIGNUM *r0, const BIGNUM *I, RSA *rsa,
  57. BN_CTX *ctx));
  58. /* Can be null */
  59. int (*RSA_meth_get_bn_mod_exp(const RSA_METHOD *meth))(BIGNUM *r, const BIGNUM *a,
  60. const BIGNUM *p, const BIGNUM *m,
  61. BN_CTX *ctx, BN_MONT_CTX *m_ctx);
  62. int RSA_meth_set_bn_mod_exp(RSA_METHOD *rsa,
  63. int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a,
  64. const BIGNUM *p, const BIGNUM *m,
  65. BN_CTX *ctx, BN_MONT_CTX *m_ctx));
  66. /* called at new */
  67. int (*RSA_meth_get_init(const RSA_METHOD *meth) (RSA *rsa);
  68. int RSA_meth_set_init(RSA_METHOD *rsa, int (*init (RSA *rsa));
  69. /* called at free */
  70. int (*RSA_meth_get_finish(const RSA_METHOD *meth))(RSA *rsa);
  71. int RSA_meth_set_finish(RSA_METHOD *rsa, int (*finish)(RSA *rsa));
  72. int (*RSA_meth_get_sign(const RSA_METHOD *meth))(int type, const unsigned char *m,
  73. unsigned int m_length,
  74. unsigned char *sigret,
  75. unsigned int *siglen, const RSA *rsa);
  76. int RSA_meth_set_sign(RSA_METHOD *rsa,
  77. int (*sign)(int type, const unsigned char *m,
  78. unsigned int m_length, unsigned char *sigret,
  79. unsigned int *siglen, const RSA *rsa));
  80. int (*RSA_meth_get_verify(const RSA_METHOD *meth))(int dtype, const unsigned char *m,
  81. unsigned int m_length,
  82. const unsigned char *sigbuf,
  83. unsigned int siglen, const RSA *rsa);
  84. int RSA_meth_set_verify(RSA_METHOD *rsa,
  85. int (*verify)(int dtype, const unsigned char *m,
  86. unsigned int m_length,
  87. const unsigned char *sigbuf,
  88. unsigned int siglen, const RSA *rsa));
  89. int (*RSA_meth_get_keygen(const RSA_METHOD *meth))(RSA *rsa, int bits, BIGNUM *e,
  90. BN_GENCB *cb);
  91. int RSA_meth_set_keygen(RSA_METHOD *rsa,
  92. int (*keygen)(RSA *rsa, int bits, BIGNUM *e,
  93. BN_GENCB *cb));
  94. int (*RSA_meth_get_multi_prime_keygen(const RSA_METHOD *meth))(RSA *rsa, int bits,
  95. int primes, BIGNUM *e,
  96. BN_GENCB *cb);
  97. int RSA_meth_set_multi_prime_keygen(RSA_METHOD *meth,
  98. int (*keygen) (RSA *rsa, int bits,
  99. int primes, BIGNUM *e,
  100. BN_GENCB *cb));
  101. =head1 DESCRIPTION
  102. The B<RSA_METHOD> type is a structure used for the provision of custom
  103. RSA implementations. It provides a set of functions used by OpenSSL
  104. for the implementation of the various RSA capabilities. See the L<rsa>
  105. page for more information.
  106. RSA_meth_new() creates a new B<RSA_METHOD> structure. It should be
  107. given a unique B<name> and a set of B<flags>. The B<name> should be a
  108. NULL terminated string, which will be duplicated and stored in the
  109. B<RSA_METHOD> object. It is the callers responsibility to free the
  110. original string. The flags will be used during the construction of a
  111. new B<RSA> object based on this B<RSA_METHOD>. Any new B<RSA> object
  112. will have those flags set by default.
  113. RSA_meth_dup() creates a duplicate copy of the B<RSA_METHOD> object
  114. passed as a parameter. This might be useful for creating a new
  115. B<RSA_METHOD> based on an existing one, but with some differences.
  116. RSA_meth_free() destroys an B<RSA_METHOD> structure and frees up any
  117. memory associated with it.
  118. RSA_meth_get0_name() will return a pointer to the name of this
  119. RSA_METHOD. This is a pointer to the internal name string and so
  120. should not be freed by the caller. RSA_meth_set1_name() sets the name
  121. of the RSA_METHOD to B<name>. The string is duplicated and the copy is
  122. stored in the RSA_METHOD structure, so the caller remains responsible
  123. for freeing the memory associated with the name.
  124. RSA_meth_get_flags() returns the current value of the flags associated
  125. with this RSA_METHOD. RSA_meth_set_flags() provides the ability to set
  126. these flags.
  127. The functions RSA_meth_get0_app_data() and RSA_meth_set0_app_data()
  128. provide the ability to associate implementation specific data with the
  129. RSA_METHOD. It is the application's responsibility to free this data
  130. before the RSA_METHOD is freed via a call to RSA_meth_free().
  131. RSA_meth_get_sign() and RSA_meth_set_sign() get and set the function
  132. used for creating an RSA signature respectively. This function will be
  133. called in response to the application calling RSA_sign(). The
  134. parameters for the function have the same meaning as for RSA_sign().
  135. RSA_meth_get_verify() and RSA_meth_set_verify() get and set the
  136. function used for verifying an RSA signature respectively. This
  137. function will be called in response to the application calling
  138. RSA_verify(). The parameters for the function have the same meaning as
  139. for RSA_verify().
  140. RSA_meth_get_mod_exp() and RSA_meth_set_mod_exp() get and set the
  141. function used for CRT computations.
  142. RSA_meth_get_bn_mod_exp() and RSA_meth_set_bn_mod_exp() get and set
  143. the function used for CRT computations, specifically the following
  144. value:
  145. r = a ^ p mod m
  146. Both the mod_exp() and bn_mod_exp() functions are called by the
  147. default OpenSSL method during encryption, decryption, signing and
  148. verification.
  149. RSA_meth_get_init() and RSA_meth_set_init() get and set the function
  150. used for creating a new RSA instance respectively. This function will
  151. be called in response to the application calling RSA_new() (if the
  152. current default RSA_METHOD is this one) or RSA_new_method(). The
  153. RSA_new() and RSA_new_method() functions will allocate the memory for
  154. the new RSA object, and a pointer to this newly allocated structure
  155. will be passed as a parameter to the function. This function may be
  156. NULL.
  157. RSA_meth_get_finish() and RSA_meth_set_finish() get and set the
  158. function used for destroying an instance of an RSA object respectively.
  159. This function will be called in response to the application calling
  160. RSA_free(). A pointer to the RSA to be destroyed is passed as a
  161. parameter. The destroy function should be used for RSA implementation
  162. specific clean up. The memory for the RSA itself should not be freed
  163. by this function. This function may be NULL.
  164. RSA_meth_get_keygen() and RSA_meth_set_keygen() get and set the
  165. function used for generating a new RSA key pair respectively. This
  166. function will be called in response to the application calling
  167. RSA_generate_key_ex(). The parameter for the function has the same
  168. meaning as for RSA_generate_key_ex().
  169. RSA_meth_get_multi_prime_keygen() and RSA_meth_set_multi_prime_keygen() get
  170. and set the function used for generating a new multi-prime RSA key pair
  171. respectively. This function will be called in response to the application calling
  172. RSA_generate_multi_prime_key(). The parameter for the function has the same
  173. meaning as for RSA_generate_multi_prime_key().
  174. RSA_meth_get_pub_enc(), RSA_meth_set_pub_enc(),
  175. RSA_meth_get_pub_dec(), RSA_meth_set_pub_dec(),
  176. RSA_meth_get_priv_enc(), RSA_meth_set_priv_enc(),
  177. RSA_meth_get_priv_dec(), RSA_meth_set_priv_dec() get and set the
  178. functions used for public and private key encryption and decryption.
  179. These functions will be called in response to the application calling
  180. RSA_public_encrypt(), RSA_private_decrypt(), RSA_private_encrypt() and
  181. RSA_public_decrypt() and take the same parameters as those.
  182. =head1 RETURN VALUES
  183. RSA_meth_new() and RSA_meth_dup() return the newly allocated
  184. RSA_METHOD object or NULL on failure.
  185. RSA_meth_get0_name() and RSA_meth_get_flags() return the name and
  186. flags associated with the RSA_METHOD respectively.
  187. All other RSA_meth_get_*() functions return the appropriate function
  188. pointer that has been set in the RSA_METHOD, or NULL if no such
  189. pointer has yet been set.
  190. RSA_meth_set1_name and all RSA_meth_set_*() functions return 1 on
  191. success or 0 on failure.
  192. =head1 SEE ALSO
  193. L<RSA_new(3)>, L<RSA_generate_key_ex(3)>, L<RSA_sign(3)>,
  194. L<RSA_set_method(3)>, L<RSA_size(3)>, L<RSA_get0_key(3)>,
  195. L<RSA_generate_multi_prime_key(3)>
  196. =head1 HISTORY
  197. RSA_meth_get_multi_prime_keygen() and RSA_meth_set_multi_prime_keygen() were
  198. added in OpenSSL 1.1.1.
  199. Other functions described here were added in OpenSSL 1.1.0.
  200. =head1 COPYRIGHT
  201. Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
  202. Licensed under the OpenSSL license (the "License"). You may not use
  203. this file except in compliance with the License. You can obtain a copy
  204. in the file LICENSE in the source distribution or at
  205. L<https://www.openssl.org/source/license.html>.
  206. =cut