RSA_get0_key.pod 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. =pod
  2. =head1 NAME
  3. RSA_set0_key, RSA_set0_factors, RSA_set0_crt_params, RSA_get0_key,
  4. RSA_get0_factors, RSA_get0_crt_params, RSA_clear_flags,
  5. RSA_test_flags, RSA_set_flags, RSA_get0_engine, RSA_get_multi_prime_extra_count,
  6. RSA_get0_multi_prime_factors, RSA_get0_multi_prime_crt_params,
  7. RSA_set0_multi_prime_params, RSA_get_version
  8. - Routines for getting and setting data in an RSA object
  9. =head1 SYNOPSIS
  10. #include <openssl/rsa.h>
  11. int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
  12. int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q);
  13. int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp);
  14. void RSA_get0_key(const RSA *r,
  15. const BIGNUM **n, const BIGNUM **e, const BIGNUM **d);
  16. void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q);
  17. void RSA_get0_crt_params(const RSA *r,
  18. const BIGNUM **dmp1, const BIGNUM **dmq1,
  19. const BIGNUM **iqmp);
  20. void RSA_clear_flags(RSA *r, int flags);
  21. int RSA_test_flags(const RSA *r, int flags);
  22. void RSA_set_flags(RSA *r, int flags);
  23. ENGINE *RSA_get0_engine(RSA *r);
  24. int RSA_get_multi_prime_extra_count(const RSA *r);
  25. int RSA_get0_multi_prime_factors(const RSA *r, const BIGNUM *primes[]);
  26. int RSA_get0_multi_prime_crt_params(const RSA *r, const BIGNUM *exps[],
  27. const BIGNUM *coeffs[]);
  28. int RSA_set0_multi_prime_params(RSA *r, BIGNUM *primes[], BIGNUM *exps[],
  29. BIGNUM *coeffs[], int pnum);
  30. int RSA_get_version(RSA *r);
  31. =head1 DESCRIPTION
  32. An RSA object contains the components for the public and private key,
  33. B<n>, B<e>, B<d>, B<p>, B<q>, B<dmp1>, B<dmq1> and B<iqmp>. B<n> is
  34. the modulus common to both public and private key, B<e> is the public
  35. exponent and B<d> is the private exponent. B<p>, B<q>, B<dmp1>,
  36. B<dmq1> and B<iqmp> are the factors for the second representation of a
  37. private key (see PKCS#1 section 3 Key Types), where B<p> and B<q> are
  38. the first and second factor of B<n> and B<dmp1>, B<dmq1> and B<iqmp>
  39. are the exponents and coefficient for CRT calculations.
  40. For multi-prime RSA (defined in RFC 8017), there are also one or more
  41. 'triplet' in an RSA object. A triplet contains three members, B<r>, B<d>
  42. and B<t>. B<r> is the additional prime besides B<p> and B<q>. B<d> and
  43. B<t> are the exponent and coefficient for CRT calculations.
  44. The B<n>, B<e> and B<d> parameters can be obtained by calling
  45. RSA_get0_key(). If they have not been set yet, then B<*n>, B<*e> and
  46. B<*d> will be set to NULL. Otherwise, they are set to pointers to
  47. their respective values. These point directly to the internal
  48. representations of the values and therefore should not be freed
  49. by the caller.
  50. The B<n>, B<e> and B<d> parameter values can be set by calling
  51. RSA_set0_key() and passing the new values for B<n>, B<e> and B<d> as
  52. parameters to the function. The values B<n> and B<e> must be non-NULL
  53. the first time this function is called on a given RSA object. The
  54. value B<d> may be NULL. On subsequent calls any of these values may be
  55. NULL which means the corresponding RSA field is left untouched.
  56. Calling this function transfers the memory management of the values to
  57. the RSA object, and therefore the values that have been passed in
  58. should not be freed by the caller after this function has been called.
  59. In a similar fashion, the B<p> and B<q> parameters can be obtained and
  60. set with RSA_get0_factors() and RSA_set0_factors(), and the B<dmp1>,
  61. B<dmq1> and B<iqmp> parameters can be obtained and set with
  62. RSA_get0_crt_params() and RSA_set0_crt_params().
  63. For RSA_get0_key(), RSA_get0_factors(), and RSA_get0_crt_params(),
  64. NULL value BIGNUM ** output parameters are permitted. The functions
  65. ignore NULL parameters but return values for other, non-NULL, parameters.
  66. For multi-prime RSA, RSA_get0_multi_prime_factors() and RSA_get0_multi_prime_params()
  67. can be used to obtain other primes and related CRT parameters. The
  68. return values are stored in an array of B<BIGNUM *>. RSA_set0_multi_prime_params()
  69. sets a collect of multi-prime 'triplet' members (prime, exponent and coefficient)
  70. into an RSA object.
  71. RSA_set_flags() sets the flags in the B<flags> parameter on the RSA
  72. object. Multiple flags can be passed in one go (bitwise ORed together).
  73. Any flags that are already set are left set. RSA_test_flags() tests to
  74. see whether the flags passed in the B<flags> parameter are currently
  75. set in the RSA object. Multiple flags can be tested in one go. All
  76. flags that are currently set are returned, or zero if none of the
  77. flags are set. RSA_clear_flags() clears the specified flags within the
  78. RSA object.
  79. RSA_get0_engine() returns a handle to the ENGINE that has been set for
  80. this RSA object, or NULL if no such ENGINE has been set.
  81. RSA_get_version() returns the version of an RSA object B<r>.
  82. =head1 NOTES
  83. Values retrieved with RSA_get0_key() are owned by the RSA object used
  84. in the call and may therefore I<not> be passed to RSA_set0_key(). If
  85. needed, duplicate the received value using BN_dup() and pass the
  86. duplicate. The same applies to RSA_get0_factors() and RSA_set0_factors()
  87. as well as RSA_get0_crt_params() and RSA_set0_crt_params().
  88. The caller should obtain the size by calling RSA_get_multi_prime_extra_count()
  89. in advance and allocate sufficient buffer to store the return values before
  90. calling RSA_get0_multi_prime_factors() and RSA_get0_multi_prime_params().
  91. RSA_set0_multi_prime_params() always clears the original multi-prime
  92. triplets in RSA object B<r> and assign the new set of triplets into it.
  93. =head1 RETURN VALUES
  94. RSA_set0_key(), RSA_set0_factors(), RSA_set0_crt_params() and
  95. RSA_set0_multi_prime_params() return 1 on success or 0 on failure.
  96. RSA_get0_multi_prime_factors() and RSA_get0_multi_prime_crt_params() return
  97. 1 on success or 0 on failure.
  98. RSA_get_multi_prime_extra_count() returns two less than the number of primes
  99. in use, which is 0 for traditional RSA and the number of extra primes for
  100. multi-prime RSA.
  101. RSA_get_version() returns B<RSA_ASN1_VERSION_MULTI> for multi-prime RSA and
  102. B<RSA_ASN1_VERSION_DEFAULT> for normal two-prime RSA, as defined in RFC 8017.
  103. RSA_test_flags() returns the current state of the flags in the RSA object.
  104. RSA_get0_engine() returns the ENGINE set for the RSA object or NULL if no
  105. ENGINE has been set.
  106. =head1 SEE ALSO
  107. L<RSA_new(3)>, L<RSA_size(3)>
  108. =head1 HISTORY
  109. RSA_get_multi_prime_extra_count(), RSA_get0_multi_prime_factors(),
  110. RSA_get0_multi_prime_crt_params(), RSA_set0_multi_prime_params(),
  111. and RSA_get_version() functions were added in OpenSSL 1.1.1.
  112. Other functions described here were added in OpenSSL 1.1.0.
  113. =head1 COPYRIGHT
  114. Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved.
  115. Licensed under the OpenSSL license (the "License"). You may not use
  116. this file except in compliance with the License. You can obtain a copy
  117. in the file LICENSE in the source distribution or at
  118. L<https://www.openssl.org/source/license.html>.
  119. =cut