RSA_set_method.pod 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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, unsigned char *m, unsigned int m_len,
  93. unsigned char *sigret, unsigned int *siglen, RSA *rsa);
  94. /* verify. For backward compatibility, this is used only
  95. * if (flags & RSA_FLAG_SIGN_VER)
  96. */
  97. int (*rsa_verify)(int type, unsigned char *m, unsigned int m_len,
  98. unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
  99. } RSA_METHOD;
  100. =head1 RETURN VALUES
  101. RSA_PKCS1_SSLeay(), RSA_PKCS1_null_method(), RSA_get_default_method()
  102. and RSA_get_method() return pointers to the respective RSA_METHODs.
  103. RSA_set_default_method() returns no value.
  104. RSA_set_method() returns a pointer to the old RSA_METHOD implementation
  105. that was replaced. However, this return value should probably be ignored
  106. because if it was supplied by an ENGINE, the pointer could be invalidated
  107. at any time if the ENGINE is unloaded (in fact it could be unloaded as a
  108. result of the RSA_set_method() function releasing its handle to the
  109. ENGINE). For this reason, the return type may be replaced with a B<void>
  110. declaration in a future release.
  111. RSA_new_method() returns NULL and sets an error code that can be obtained
  112. by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation fails. Otherwise
  113. it returns a pointer to the newly allocated structure.
  114. =head1 NOTES
  115. As of version 0.9.7, RSA_METHOD implementations are grouped together with
  116. other algorithmic APIs (eg. DSA_METHOD, EVP_CIPHER, etc) into B<ENGINE>
  117. modules. If a default ENGINE is specified for RSA functionality using an
  118. ENGINE API function, that will override any RSA defaults set using the RSA
  119. API (ie. RSA_set_default_method()). For this reason, the ENGINE API is the
  120. recommended way to control default implementations for use in RSA and other
  121. cryptographic algorithms.
  122. =head1 BUGS
  123. The behaviour of RSA_flags() is a mis-feature that is left as-is for now
  124. to avoid creating compatibility problems. RSA functionality, such as the
  125. encryption functions, are controlled by the B<flags> value in the RSA key
  126. itself, not by the B<flags> value in the RSA_METHOD attached to the RSA key
  127. (which is what this function returns). If the flags element of an RSA key
  128. is changed, the changes will be honoured by RSA functionality but will not
  129. be reflected in the return value of the RSA_flags() function - in effect
  130. RSA_flags() behaves more like an RSA_default_flags() function (which does
  131. not currently exist).
  132. =head1 SEE ALSO
  133. L<rsa(3)|rsa(3)>, L<RSA_new(3)|RSA_new(3)>
  134. =head1 HISTORY
  135. RSA_new_method() and RSA_set_default_method() appeared in SSLeay 0.8.
  136. RSA_get_default_method(), RSA_set_method() and RSA_get_method() as
  137. well as the rsa_sign and rsa_verify components of RSA_METHOD were
  138. added in OpenSSL 0.9.4.
  139. RSA_set_default_openssl_method() and RSA_get_default_openssl_method()
  140. replaced RSA_set_default_method() and RSA_get_default_method()
  141. respectively, and RSA_set_method() and RSA_new_method() were altered to use
  142. B<ENGINE>s rather than B<RSA_METHOD>s during development of the engine
  143. version of OpenSSL 0.9.6. For 0.9.7, the handling of defaults in the ENGINE
  144. API was restructured so that this change was reversed, and behaviour of the
  145. other functions resembled more closely the previous behaviour. The
  146. behaviour of defaults in the ENGINE API now transparently overrides the
  147. behaviour of defaults in the RSA API without requiring changing these
  148. function prototypes.
  149. =cut