RSA_set_method.pod 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. =pod
  2. =head1 NAME
  3. RSA_set_default_method, RSA_get_default_method, RSA_set_method,
  4. RSA_get_method, RSA_PKCS1_OpenSSL, RSA_flags,
  5. RSA_new_method - select RSA method
  6. =head1 SYNOPSIS
  7. #include <openssl/rsa.h>
  8. The following functions have been deprecated since OpenSSL 3.0, and can be
  9. hidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value,
  10. see L<openssl_user_macros(7)>:
  11. void RSA_set_default_method(const RSA_METHOD *meth);
  12. const RSA_METHOD *RSA_get_default_method(void);
  13. int RSA_set_method(RSA *rsa, const RSA_METHOD *meth);
  14. const RSA_METHOD *RSA_get_method(const RSA *rsa);
  15. const RSA_METHOD *RSA_PKCS1_OpenSSL(void);
  16. int RSA_flags(const RSA *rsa);
  17. RSA *RSA_new_method(ENGINE *engine);
  18. =head1 DESCRIPTION
  19. All of the functions described on this page are deprecated.
  20. Applications should instead use the OSSL_PROVIDER APIs.
  21. An B<RSA_METHOD> specifies the functions that OpenSSL uses for RSA
  22. operations. By modifying the method, alternative implementations such as
  23. hardware accelerators may be used. IMPORTANT: See the NOTES section for
  24. important information about how these RSA API functions are affected by the
  25. use of B<ENGINE> API calls.
  26. Initially, the default RSA_METHOD is the OpenSSL internal implementation,
  27. as returned by RSA_PKCS1_OpenSSL().
  28. RSA_set_default_method() makes B<meth> the default method for all RSA
  29. structures created later.
  30. B<NB>: This is true only whilst no ENGINE has
  31. been set as a default for RSA, so this function is no longer recommended.
  32. This function is not thread-safe and should not be called at the same time
  33. as other OpenSSL functions.
  34. RSA_get_default_method() returns a pointer to the current default
  35. RSA_METHOD. However, the meaningfulness of this result is dependent on
  36. whether the ENGINE API is being used, so this function is no longer
  37. recommended.
  38. RSA_set_method() selects B<meth> to perform all operations using the key
  39. B<rsa>. This will replace the RSA_METHOD used by the RSA key and if the
  40. previous method was supplied by an ENGINE, the handle to that ENGINE will
  41. be released during the change. It is possible to have RSA keys that only
  42. work with certain RSA_METHOD implementations (e.g. from an ENGINE module
  43. that supports embedded hardware-protected keys), and in such cases
  44. attempting to change the RSA_METHOD for the key can have unexpected
  45. results.
  46. RSA_get_method() returns a pointer to the RSA_METHOD being used by B<rsa>.
  47. This method may or may not be supplied by an ENGINE implementation, but if
  48. it is, the return value can only be guaranteed to be valid as long as the
  49. RSA key itself is valid and does not have its implementation changed by
  50. RSA_set_method().
  51. RSA_flags() returns the B<flags> that are set for B<rsa>'s current
  52. RSA_METHOD. See the BUGS section.
  53. RSA_new_method() allocates and initializes an RSA structure so that
  54. B<engine> will be used for the RSA operations. If B<engine> is NULL, the
  55. default ENGINE for RSA operations is used, and if no default ENGINE is set,
  56. the RSA_METHOD controlled by RSA_set_default_method() is used.
  57. RSA_flags() returns the B<flags> that are set for B<rsa>'s current method.
  58. RSA_new_method() allocates and initializes an B<RSA> structure so that
  59. B<method> will be used for the RSA operations. If B<method> is B<NULL>,
  60. the default method is used.
  61. =head1 THE RSA_METHOD STRUCTURE
  62. typedef struct rsa_meth_st
  63. {
  64. /* name of the implementation */
  65. const char *name;
  66. /* encrypt */
  67. int (*rsa_pub_enc)(int flen, unsigned char *from,
  68. unsigned char *to, RSA *rsa, int padding);
  69. /* verify arbitrary data */
  70. int (*rsa_pub_dec)(int flen, unsigned char *from,
  71. unsigned char *to, RSA *rsa, int padding);
  72. /* sign arbitrary data */
  73. int (*rsa_priv_enc)(int flen, unsigned char *from,
  74. unsigned char *to, RSA *rsa, int padding);
  75. /* decrypt */
  76. int (*rsa_priv_dec)(int flen, unsigned char *from,
  77. unsigned char *to, RSA *rsa, int padding);
  78. /* compute r0 = r0 ^ I mod rsa->n (May be NULL for some implementations) */
  79. int (*rsa_mod_exp)(BIGNUM *r0, BIGNUM *I, RSA *rsa);
  80. /* compute r = a ^ p mod m (May be NULL for some implementations) */
  81. int (*bn_mod_exp)(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
  82. const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
  83. /* called at RSA_new */
  84. int (*init)(RSA *rsa);
  85. /* called at RSA_free */
  86. int (*finish)(RSA *rsa);
  87. /*
  88. * RSA_FLAG_EXT_PKEY - rsa_mod_exp is called for private key
  89. * operations, even if p,q,dmp1,dmq1,iqmp
  90. * are NULL
  91. * RSA_METHOD_FLAG_NO_CHECK - don't check pub/private match
  92. */
  93. int flags;
  94. char *app_data; /* ?? */
  95. int (*rsa_sign)(int type,
  96. const unsigned char *m, unsigned int m_length,
  97. unsigned char *sigret, unsigned int *siglen, const RSA *rsa);
  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 built-in 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_OpenSSL(), 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)> if the allocation fails. Otherwise
  118. it returns a pointer to the newly allocated structure.
  119. =head1 BUGS
  120. The behaviour of RSA_flags() is a mis-feature that is left as-is for now
  121. to avoid creating compatibility problems. RSA functionality, such as the
  122. encryption functions, are controlled by the B<flags> value in the RSA key
  123. itself, not by the B<flags> value in the RSA_METHOD attached to the RSA key
  124. (which is what this function returns). If the flags element of an RSA key
  125. is changed, the changes will be honoured by RSA functionality but will not
  126. be reflected in the return value of the RSA_flags() function - in effect
  127. RSA_flags() behaves more like an RSA_default_flags() function (which does
  128. not currently exist).
  129. =head1 SEE ALSO
  130. L<RSA_new(3)>
  131. =head1 HISTORY
  132. All of these functions were deprecated in OpenSSL 3.0.
  133. The RSA_null_method(), which was a partial attempt to avoid patent issues,
  134. was replaced to always return NULL in OpenSSL 1.1.1.
  135. =head1 COPYRIGHT
  136. Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
  137. Licensed under the Apache License 2.0 (the "License"). You may not use
  138. this file except in compliance with the License. You can obtain a copy
  139. in the file LICENSE in the source distribution or at
  140. L<https://www.openssl.org/source/license.html>.
  141. =cut