Richard Levitte | b879882 | 2016-04-02 16:43:21 +0200 | [diff] [blame] | 1 | =pod |
| 2 | |
| 3 | =head1 NAME |
| 4 | |
| 5 | RSA_set0_key, RSA_set0_factors, RSA_set0_crt_params, RSA_get0_key, |
Dr. Matthias St. Pierre | 6692ff7 | 2018-05-27 09:01:28 +0200 | [diff] [blame^] | 6 | RSA_get0_factors, RSA_get0_crt_params, |
| 7 | RSA_get0_n, RSA_get0_e, RSA_get0_d, RSA_get0_p, RSA_get0_q, |
| 8 | RSA_get0_dmp1, RSA_get0_dmq1, RSA_get0_iqmp, |
| 9 | RSA_clear_flags, |
Paul Yang | 665d899 | 2017-08-02 02:19:43 +0800 | [diff] [blame] | 10 | RSA_test_flags, RSA_set_flags, RSA_get0_engine, RSA_get_multi_prime_extra_count, |
| 11 | RSA_get0_multi_prime_factors, RSA_get0_multi_prime_crt_params, |
| 12 | RSA_set0_multi_prime_params, RSA_get_version |
| 13 | - Routines for getting and setting data in an RSA object |
Richard Levitte | b879882 | 2016-04-02 16:43:21 +0200 | [diff] [blame] | 14 | |
| 15 | =head1 SYNOPSIS |
| 16 | |
| 17 | #include <openssl/rsa.h> |
| 18 | |
| 19 | int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d); |
| 20 | int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q); |
Rich Salz | aebb9aa | 2016-07-19 09:27:53 -0400 | [diff] [blame] | 21 | int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp); |
Richard Levitte | fd809cf | 2016-06-14 15:48:16 +0200 | [diff] [blame] | 22 | void RSA_get0_key(const RSA *r, |
| 23 | const BIGNUM **n, const BIGNUM **e, const BIGNUM **d); |
| 24 | void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q); |
Richard Levitte | b879882 | 2016-04-02 16:43:21 +0200 | [diff] [blame] | 25 | void RSA_get0_crt_params(const RSA *r, |
Richard Levitte | fd809cf | 2016-06-14 15:48:16 +0200 | [diff] [blame] | 26 | const BIGNUM **dmp1, const BIGNUM **dmq1, |
| 27 | const BIGNUM **iqmp); |
Dr. Matthias St. Pierre | 6692ff7 | 2018-05-27 09:01:28 +0200 | [diff] [blame^] | 28 | const BIGNUM *RSA_get0_n(const RSA *d); |
| 29 | const BIGNUM *RSA_get0_e(const RSA *d); |
| 30 | const BIGNUM *RSA_get0_d(const RSA *d); |
| 31 | const BIGNUM *RSA_get0_p(const RSA *d); |
| 32 | const BIGNUM *RSA_get0_q(const RSA *d); |
| 33 | const BIGNUM *RSA_get0_dmp1(const RSA *r); |
| 34 | const BIGNUM *RSA_get0_dmq1(const RSA *r); |
| 35 | const BIGNUM *RSA_get0_iqmp(const RSA *r); |
Richard Levitte | b879882 | 2016-04-02 16:43:21 +0200 | [diff] [blame] | 36 | void RSA_clear_flags(RSA *r, int flags); |
| 37 | int RSA_test_flags(const RSA *r, int flags); |
| 38 | void RSA_set_flags(RSA *r, int flags); |
| 39 | ENGINE *RSA_get0_engine(RSA *r); |
Paul Yang | 665d899 | 2017-08-02 02:19:43 +0800 | [diff] [blame] | 40 | int RSA_get_multi_prime_extra_count(const RSA *r); |
| 41 | int RSA_get0_multi_prime_factors(const RSA *r, const BIGNUM *primes[]); |
| 42 | int RSA_get0_multi_prime_crt_params(const RSA *r, const BIGNUM *exps[], |
| 43 | const BIGNUM *coeffs[]); |
| 44 | int RSA_set0_multi_prime_params(RSA *r, BIGNUM *primes[], BIGNUM *exps[], |
| 45 | BIGNUM *coeffs[], int pnum); |
| 46 | int RSA_get_version(RSA *r); |
Richard Levitte | b879882 | 2016-04-02 16:43:21 +0200 | [diff] [blame] | 47 | |
| 48 | =head1 DESCRIPTION |
| 49 | |
| 50 | An RSA object contains the components for the public and private key, |
| 51 | B<n>, B<e>, B<d>, B<p>, B<q>, B<dmp1>, B<dmq1> and B<iqmp>. B<n> is |
| 52 | the modulus common to both public and private key, B<e> is the public |
| 53 | exponent and B<d> is the private exponent. B<p>, B<q>, B<dmp1>, |
| 54 | B<dmq1> and B<iqmp> are the factors for the second representation of a |
| 55 | private key (see PKCS#1 section 3 Key Types), where B<p> and B<q> are |
| 56 | the first and second factor of B<n> and B<dmp1>, B<dmq1> and B<iqmp> |
| 57 | are the exponents and coefficient for CRT calculations. |
| 58 | |
Paul Yang | 665d899 | 2017-08-02 02:19:43 +0800 | [diff] [blame] | 59 | For multi-prime RSA (defined in RFC 8017), there are also one or more |
| 60 | 'triplet' in an RSA object. A triplet contains three members, B<r>, B<d> |
| 61 | and B<t>. B<r> is the additional prime besides B<p> and B<q>. B<d> and |
| 62 | B<t> are the exponent and coefficient for CRT calculations. |
| 63 | |
Richard Levitte | b879882 | 2016-04-02 16:43:21 +0200 | [diff] [blame] | 64 | The B<n>, B<e> and B<d> parameters can be obtained by calling |
| 65 | RSA_get0_key(). If they have not been set yet, then B<*n>, B<*e> and |
| 66 | B<*d> will be set to NULL. Otherwise, they are set to pointers to |
| 67 | their respective values. These point directly to the internal |
| 68 | representations of the values and therefore should not be freed |
| 69 | by the caller. |
| 70 | |
| 71 | The B<n>, B<e> and B<d> parameter values can be set by calling |
| 72 | RSA_set0_key() and passing the new values for B<n>, B<e> and B<d> as |
Richard Levitte | 4c5e6b2 | 2016-04-26 13:40:53 +0200 | [diff] [blame] | 73 | parameters to the function. The values B<n> and B<e> must be non-NULL |
| 74 | the first time this function is called on a given RSA object. The |
| 75 | value B<d> may be NULL. On subsequent calls any of these values may be |
| 76 | NULL which means the corresponding RSA field is left untouched. |
| 77 | Calling this function transfers the memory management of the values to |
| 78 | the RSA object, and therefore the values that have been passed in |
| 79 | should not be freed by the caller after this function has been called. |
Richard Levitte | b879882 | 2016-04-02 16:43:21 +0200 | [diff] [blame] | 80 | |
| 81 | In a similar fashion, the B<p> and B<q> parameters can be obtained and |
| 82 | set with RSA_get0_factors() and RSA_set0_factors(), and the B<dmp1>, |
| 83 | B<dmq1> and B<iqmp> parameters can be obtained and set with |
| 84 | RSA_get0_crt_params() and RSA_set0_crt_params(). |
| 85 | |
Ken Goldman | 07c54e5 | 2017-07-31 16:44:47 -0400 | [diff] [blame] | 86 | For RSA_get0_key(), RSA_get0_factors(), and RSA_get0_crt_params(), |
Paul Yang | 665d899 | 2017-08-02 02:19:43 +0800 | [diff] [blame] | 87 | NULL value BIGNUM ** output parameters are permitted. The functions |
Ken Goldman | 07c54e5 | 2017-07-31 16:44:47 -0400 | [diff] [blame] | 88 | ignore NULL parameters but return values for other, non-NULL, parameters. |
| 89 | |
Paul Yang | 665d899 | 2017-08-02 02:19:43 +0800 | [diff] [blame] | 90 | For multi-prime RSA, RSA_get0_multi_prime_factors() and RSA_get0_multi_prime_params() |
| 91 | can be used to obtain other primes and related CRT parameters. The |
| 92 | return values are stored in an array of B<BIGNUM *>. RSA_set0_multi_prime_params() |
| 93 | sets a collect of multi-prime 'triplet' members (prime, exponent and coefficient) |
| 94 | into an RSA object. |
| 95 | |
Dr. Matthias St. Pierre | 6692ff7 | 2018-05-27 09:01:28 +0200 | [diff] [blame^] | 96 | Any of the values B<n>, B<e>, B<d>, B<p>, B<q>, B<dmp1>, B<dmq1>, and B<iqmp> can also be |
| 97 | retrieved separately by the corresponding function |
| 98 | RSA_get0_n(), RSA_get0_e(), RSA_get0_d(), RSA_get0_p(), RSA_get0_q(), |
| 99 | RSA_get0_dmp1(), RSA_get0_dmq1(), and RSA_get0_iqmp(), respectively. |
| 100 | |
Richard Levitte | b879882 | 2016-04-02 16:43:21 +0200 | [diff] [blame] | 101 | RSA_set_flags() sets the flags in the B<flags> parameter on the RSA |
| 102 | object. Multiple flags can be passed in one go (bitwise ORed together). |
| 103 | Any flags that are already set are left set. RSA_test_flags() tests to |
| 104 | see whether the flags passed in the B<flags> parameter are currently |
| 105 | set in the RSA object. Multiple flags can be tested in one go. All |
| 106 | flags that are currently set are returned, or zero if none of the |
| 107 | flags are set. RSA_clear_flags() clears the specified flags within the |
| 108 | RSA object. |
| 109 | |
| 110 | RSA_get0_engine() returns a handle to the ENGINE that has been set for |
| 111 | this RSA object, or NULL if no such ENGINE has been set. |
| 112 | |
Paul Yang | 665d899 | 2017-08-02 02:19:43 +0800 | [diff] [blame] | 113 | RSA_get_version() returns the version of an RSA object B<r>. |
| 114 | |
Richard Levitte | 4c5e6b2 | 2016-04-26 13:40:53 +0200 | [diff] [blame] | 115 | =head1 NOTES |
| 116 | |
| 117 | Values retrieved with RSA_get0_key() are owned by the RSA object used |
| 118 | in the call and may therefore I<not> be passed to RSA_set0_key(). If |
| 119 | needed, duplicate the received value using BN_dup() and pass the |
| 120 | duplicate. The same applies to RSA_get0_factors() and RSA_set0_factors() |
| 121 | as well as RSA_get0_crt_params() and RSA_set0_crt_params(). |
| 122 | |
Paul Yang | 665d899 | 2017-08-02 02:19:43 +0800 | [diff] [blame] | 123 | The caller should obtain the size by calling RSA_get_multi_prime_extra_count() |
| 124 | in advance and allocate sufficient buffer to store the return values before |
| 125 | calling RSA_get0_multi_prime_factors() and RSA_get0_multi_prime_params(). |
| 126 | |
| 127 | RSA_set0_multi_prime_params() always clears the original multi-prime |
| 128 | triplets in RSA object B<r> and assign the new set of triplets into it. |
| 129 | |
Richard Levitte | b879882 | 2016-04-02 16:43:21 +0200 | [diff] [blame] | 130 | =head1 RETURN VALUES |
| 131 | |
Paul Yang | 665d899 | 2017-08-02 02:19:43 +0800 | [diff] [blame] | 132 | RSA_set0_key(), RSA_set0_factors(), RSA_set0_crt_params() and |
| 133 | RSA_set0_multi_prime_params() return 1 on success or 0 on failure. |
| 134 | |
Dr. Matthias St. Pierre | 6692ff7 | 2018-05-27 09:01:28 +0200 | [diff] [blame^] | 135 | RSA_get0_n(), RSA_get0_e(), RSA_get0_d(), RSA_get0_p(), RSA_get0_q(), |
| 136 | RSA_get0_dmp1(), RSA_get0_dmq1(), and RSA_get0_iqmp() |
| 137 | return the respective value. |
| 138 | |
Paul Yang | 665d899 | 2017-08-02 02:19:43 +0800 | [diff] [blame] | 139 | RSA_get0_multi_prime_factors() and RSA_get0_multi_prime_crt_params() return |
| 140 | 1 on success or 0 on failure. |
| 141 | |
| 142 | RSA_get_multi_prime_extra_count() returns two less than the number of primes |
| 143 | in use, which is 0 for traditional RSA and the number of extra primes for |
| 144 | multi-prime RSA. |
| 145 | |
| 146 | RSA_get_version() returns B<RSA_ASN1_VERSION_MULTI> for multi-prime RSA and |
| 147 | B<RSA_ASN1_VERSION_DEFAULT> for normal two-prime RSA, as defined in RFC 8017. |
Richard Levitte | b879882 | 2016-04-02 16:43:21 +0200 | [diff] [blame] | 148 | |
| 149 | RSA_test_flags() returns the current state of the flags in the RSA object. |
| 150 | |
| 151 | RSA_get0_engine() returns the ENGINE set for the RSA object or NULL if no |
| 152 | ENGINE has been set. |
| 153 | |
| 154 | =head1 SEE ALSO |
| 155 | |
Richard Levitte | b97fdb5 | 2016-11-11 09:33:09 +0100 | [diff] [blame] | 156 | L<RSA_new(3)>, L<RSA_size(3)> |
Richard Levitte | b879882 | 2016-04-02 16:43:21 +0200 | [diff] [blame] | 157 | |
| 158 | =head1 HISTORY |
| 159 | |
Paul Yang | 665d899 | 2017-08-02 02:19:43 +0800 | [diff] [blame] | 160 | RSA_get_multi_prime_extra_count(), RSA_get0_multi_prime_factors(), |
| 161 | RSA_get0_multi_prime_crt_params(), RSA_set0_multi_prime_params(), |
| 162 | and RSA_get_version() functions were added in OpenSSL 1.1.1. |
| 163 | |
| 164 | Other functions described here were added in OpenSSL 1.1.0. |
Richard Levitte | b879882 | 2016-04-02 16:43:21 +0200 | [diff] [blame] | 165 | |
Rich Salz | e2f9261 | 2016-05-18 11:44:05 -0400 | [diff] [blame] | 166 | =head1 COPYRIGHT |
| 167 | |
Paul Yang | 665d899 | 2017-08-02 02:19:43 +0800 | [diff] [blame] | 168 | Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved. |
Rich Salz | e2f9261 | 2016-05-18 11:44:05 -0400 | [diff] [blame] | 169 | |
| 170 | Licensed under the OpenSSL license (the "License"). You may not use |
| 171 | this file except in compliance with the License. You can obtain a copy |
| 172 | in the file LICENSE in the source distribution or at |
| 173 | L<https://www.openssl.org/source/license.html>. |
| 174 | |
| 175 | =cut |