RSA_set_method.pod 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. =pod
  2. =head1 NAME
  3. RSA_set_default_method, RSA_get_default_method, RSA_set_method,
  4. RSA_get_method, RSA_PKCS1_SSLeay, RSA_null_method, RSA_flags,
  5. RSA_new_method - select RSA method
  6. =head1 SYNOPSIS
  7. #include <openssl/rsa.h>
  8. void RSA_set_default_method(const RSA_METHOD *meth);
  9. RSA_METHOD *RSA_get_default_method(void);
  10. int RSA_set_method(RSA *rsa, const RSA_METHOD *meth);
  11. RSA_METHOD *RSA_get_method(const RSA *rsa);
  12. RSA_METHOD *RSA_PKCS1_SSLeay(void);
  13. RSA_METHOD *RSA_null_method(void);
  14. int RSA_flags(const RSA *rsa);
  15. RSA *RSA_new_method(RSA_METHOD *method);
  16. =head1 DESCRIPTION
  17. An B<RSA_METHOD> specifies the functions that OpenSSL uses for RSA
  18. operations. By modifying the method, alternative implementations such as
  19. hardware accelerators may be used. IMPORTANT: See the NOTES section for
  20. important information about how these RSA API functions are affected by the
  21. use of B<ENGINE> API calls.
  22. Initially, the default RSA_METHOD is the OpenSSL internal implementation,
  23. as returned by RSA_PKCS1_SSLeay().
  24. RSA_set_default_method() makes B<meth> the default method for all RSA
  25. structures created later. B<NB>: This is true only whilst no ENGINE has
  26. been set as a default for RSA, so this function is no longer recommended.
  27. RSA_get_default_method() returns a pointer to the current default
  28. RSA_METHOD. However, the meaningfulness of this result is dependent on
  29. whether the ENGINE API is being used, so this function is no longer
  30. recommended.
  31. RSA_set_method() selects B<meth> to perform all operations using the key
  32. B<rsa>. This will replace the RSA_METHOD used by the RSA key and if the
  33. previous method was supplied by an ENGINE, the handle to that ENGINE will
  34. be released during the change. It is possible to have RSA keys that only
  35. work with certain RSA_METHOD implementations (eg. from an ENGINE module
  36. that supports embedded hardware-protected keys), and in such cases
  37. attempting to change the RSA_METHOD for the key can have unexpected
  38. results.
  39. RSA_get_method() returns a pointer to the RSA_METHOD being used by B<rsa>.
  40. This method may or may not be supplied by an ENGINE implementation, but if
  41. it is, the return value can only be guaranteed to be valid as long as the
  42. RSA key itself is valid and does not have its implementation changed by
  43. RSA_set_method().
  44. RSA_flags() returns the B<flags> that are set for B<rsa>'s current
  45. RSA_METHOD. See the BUGS section.
  46. RSA_new_method() allocates and initializes an RSA structure so that
  47. B<engine> will be used for the RSA operations. If B<engine> is NULL, the
  48. default ENGINE for RSA operations is used, and if no default ENGINE is set,
  49. the RSA_METHOD controlled by RSA_set_default_method() is used.
  50. RSA_flags() returns the B<flags> that are set for B<rsa>'s current method.
  51. RSA_new_method() allocates and initializes an B<RSA> structure so that
  52. B<method> will be used for the RSA operations. If B<method> is B<NULL>,
  53. the default method is used.
  54. =head1 THE RSA_METHOD STRUCTURE
  55. typedef struct rsa_meth_st
  56. {
  57. /* name of the implementation */
  58. const char *name;
  59. /* encrypt */
  60. int (*rsa_pub_enc)(int flen, unsigned char *from,
  61. unsigned char *to, RSA *rsa, int padding);
  62. /* verify arbitrary data */
  63. int (*rsa_pub_dec)(int flen, unsigned char *from,
  64. unsigned char *to, RSA *rsa, int padding);
  65. /* sign arbitrary data */
  66. int (*rsa_priv_enc)(int flen, unsigned char *from,
  67. unsigned char *to, RSA *rsa, int padding);
  68. /* decrypt */
  69. int (*rsa_priv_dec)(int flen, unsigned char *from,
  70. unsigned char *to, RSA *rsa, int padding);
  71. /* compute r0 = r0 ^ I mod rsa->n (May be NULL for some
  72. implementations) */
  73. int (*rsa_mod_exp)(BIGNUM *r0, BIGNUM *I, RSA *rsa);
  74. /* compute r = a ^ p mod m (May be NULL for some implementations) */
  75. int (*bn_mod_exp)(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
  76. const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
  77. /* called at RSA_new */
  78. int (*init)(RSA *rsa);
  79. /* called at RSA_free */
  80. int (*finish)(RSA *rsa);
  81. /* RSA_FLAG_EXT_PKEY - rsa_mod_exp is called for private key
  82. * operations, even if p,q,dmp1,dmq1,iqmp
  83. * are NULL
  84. * RSA_FLAG_SIGN_VER - enable rsa_sign and rsa_verify
  85. * RSA_METHOD_FLAG_NO_CHECK - don't check pub/private match
  86. */
  87. int flags;
  88. char *app_data; /* ?? */
  89. /* sign. For backward compatibility, this is used only
  90. * if (flags & RSA_FLAG_SIGN_VER)
  91. */
  92. int (*rsa_sign)(int type,
  93. const unsigned char *m, unsigned int m_length,
  94. unsigned char *sigret, unsigned int *siglen, const RSA *rsa);
  95. /* verify. For backward compatibility, this is used only
  96. * if (flags & RSA_FLAG_SIGN_VER)
  97. */
  98. int (*rsa_verify)(int dtype,
  99. const unsigned char *m, unsigned int m_length,
  100. const unsigned char *sigbuf, unsigned int siglen,
  101. const RSA *rsa);
  102. /* keygen. If NULL builtin RSA key generation will be used */
  103. int (*rsa_keygen)(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
  104. } RSA_METHOD;
  105. =head1 RETURN VALUES
  106. RSA_PKCS1_SSLeay(), RSA_PKCS1_null_method(), RSA_get_default_method()
  107. and RSA_get_method() return pointers to the respective RSA_METHODs.
  108. RSA_set_default_method() returns no value.
  109. RSA_set_method() returns a pointer to the old RSA_METHOD implementation
  110. that was replaced. However, this return value should probably be ignored
  111. because if it was supplied by an ENGINE, the pointer could be invalidated
  112. at any time if the ENGINE is unloaded (in fact it could be unloaded as a
  113. result of the RSA_set_method() function releasing its handle to the
  114. ENGINE). For this reason, the return type may be replaced with a B<void>
  115. declaration in a future release.
  116. RSA_new_method() returns NULL and sets an error code that can be obtained
  117. by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation fails. Otherwise
  118. it returns a pointer to the newly allocated structure.
  119. =head1 NOTES
  120. As of version 0.9.7, RSA_METHOD implementations are grouped together with
  121. other algorithmic APIs (eg. DSA_METHOD, EVP_CIPHER, etc) into B<ENGINE>
  122. modules. If a default ENGINE is specified for RSA functionality using an
  123. ENGINE API function, that will override any RSA defaults set using the RSA
  124. API (ie. RSA_set_default_method()). For this reason, the ENGINE API is the
  125. recommended way to control default implementations for use in RSA and other
  126. cryptographic algorithms.
  127. =head1 BUGS
  128. The behaviour of RSA_flags() is a mis-feature that is left as-is for now
  129. to avoid creating compatibility problems. RSA functionality, such as the
  130. encryption functions, are controlled by the B<flags> value in the RSA key
  131. itself, not by the B<flags> value in the RSA_METHOD attached to the RSA key
  132. (which is what this function returns). If the flags element of an RSA key
  133. is changed, the changes will be honoured by RSA functionality but will not
  134. be reflected in the return value of the RSA_flags() function - in effect
  135. RSA_flags() behaves more like an RSA_default_flags() function (which does
  136. not currently exist).
  137. =head1 SEE ALSO
  138. L<rsa(3)|rsa(3)>, L<RSA_new(3)|RSA_new(3)>
  139. =head1 HISTORY
  140. RSA_new_method() and RSA_set_default_method() appeared in SSLeay 0.8.
  141. RSA_get_default_method(), RSA_set_method() and RSA_get_method() as
  142. well as the rsa_sign and rsa_verify components of RSA_METHOD were
  143. added in OpenSSL 0.9.4.
  144. RSA_set_default_openssl_method() and RSA_get_default_openssl_method()
  145. replaced RSA_set_default_method() and RSA_get_default_method()
  146. respectively, and RSA_set_method() and RSA_new_method() were altered to use
  147. B<ENGINE>s rather than B<RSA_METHOD>s during development of the engine
  148. version of OpenSSL 0.9.6. For 0.9.7, the handling of defaults in the ENGINE
  149. API was restructured so that this change was reversed, and behaviour of the
  150. other functions resembled more closely the previous behaviour. The
  151. behaviour of defaults in the ENGINE API now transparently overrides the
  152. behaviour of defaults in the RSA API without requiring changing these
  153. function prototypes.
  154. =cut