RSA_set_method.pod 6.9 KB

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