xref: /freebsd/crypto/openssl/doc/man3/RSA_get0_key.pod (revision aa7957345732816fb0ba8308798d2f79f45597f9)
1e71b7053SJung-uk Kim=pod
2e71b7053SJung-uk Kim
3e71b7053SJung-uk Kim=head1 NAME
4e71b7053SJung-uk Kim
5e71b7053SJung-uk KimRSA_set0_key, RSA_set0_factors, RSA_set0_crt_params, RSA_get0_key,
6e71b7053SJung-uk KimRSA_get0_factors, RSA_get0_crt_params,
7e71b7053SJung-uk KimRSA_get0_n, RSA_get0_e, RSA_get0_d, RSA_get0_p, RSA_get0_q,
817f01e99SJung-uk KimRSA_get0_dmp1, RSA_get0_dmq1, RSA_get0_iqmp, RSA_get0_pss_params,
9e71b7053SJung-uk KimRSA_clear_flags,
10e71b7053SJung-uk KimRSA_test_flags, RSA_set_flags, RSA_get0_engine, RSA_get_multi_prime_extra_count,
11e71b7053SJung-uk KimRSA_get0_multi_prime_factors, RSA_get0_multi_prime_crt_params,
12e71b7053SJung-uk KimRSA_set0_multi_prime_params, RSA_get_version
13e71b7053SJung-uk Kim- Routines for getting and setting data in an RSA object
14e71b7053SJung-uk Kim
15e71b7053SJung-uk Kim=head1 SYNOPSIS
16e71b7053SJung-uk Kim
17e71b7053SJung-uk Kim #include <openssl/rsa.h>
18e71b7053SJung-uk Kim
19b077aed3SPierre ProncheryThe following functions have been deprecated since OpenSSL 3.0, and can be
20b077aed3SPierre Proncheryhidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value,
21b077aed3SPierre Proncherysee L<openssl_user_macros(7)>:
22b077aed3SPierre Pronchery
23e71b7053SJung-uk Kim int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
24e71b7053SJung-uk Kim int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q);
25e71b7053SJung-uk Kim int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp);
26e71b7053SJung-uk Kim void RSA_get0_key(const RSA *r,
27e71b7053SJung-uk Kim                   const BIGNUM **n, const BIGNUM **e, const BIGNUM **d);
28e71b7053SJung-uk Kim void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q);
29e71b7053SJung-uk Kim void RSA_get0_crt_params(const RSA *r,
30e71b7053SJung-uk Kim                          const BIGNUM **dmp1, const BIGNUM **dmq1,
31e71b7053SJung-uk Kim                          const BIGNUM **iqmp);
32e71b7053SJung-uk Kim const BIGNUM *RSA_get0_n(const RSA *d);
33e71b7053SJung-uk Kim const BIGNUM *RSA_get0_e(const RSA *d);
34e71b7053SJung-uk Kim const BIGNUM *RSA_get0_d(const RSA *d);
35e71b7053SJung-uk Kim const BIGNUM *RSA_get0_p(const RSA *d);
36e71b7053SJung-uk Kim const BIGNUM *RSA_get0_q(const RSA *d);
37e71b7053SJung-uk Kim const BIGNUM *RSA_get0_dmp1(const RSA *r);
38e71b7053SJung-uk Kim const BIGNUM *RSA_get0_dmq1(const RSA *r);
39e71b7053SJung-uk Kim const BIGNUM *RSA_get0_iqmp(const RSA *r);
4017f01e99SJung-uk Kim const RSA_PSS_PARAMS *RSA_get0_pss_params(const RSA *r);
41e71b7053SJung-uk Kim void RSA_clear_flags(RSA *r, int flags);
42e71b7053SJung-uk Kim int RSA_test_flags(const RSA *r, int flags);
43e71b7053SJung-uk Kim void RSA_set_flags(RSA *r, int flags);
44e71b7053SJung-uk Kim ENGINE *RSA_get0_engine(RSA *r);
45e71b7053SJung-uk Kim int RSA_get_multi_prime_extra_count(const RSA *r);
46e71b7053SJung-uk Kim int RSA_get0_multi_prime_factors(const RSA *r, const BIGNUM *primes[]);
47e71b7053SJung-uk Kim int RSA_get0_multi_prime_crt_params(const RSA *r, const BIGNUM *exps[],
48e71b7053SJung-uk Kim                                     const BIGNUM *coeffs[]);
49e71b7053SJung-uk Kim int RSA_set0_multi_prime_params(RSA *r, BIGNUM *primes[], BIGNUM *exps[],
50e71b7053SJung-uk Kim                                BIGNUM *coeffs[], int pnum);
51e71b7053SJung-uk Kim int RSA_get_version(RSA *r);
52e71b7053SJung-uk Kim
53e71b7053SJung-uk Kim=head1 DESCRIPTION
54e71b7053SJung-uk Kim
55b077aed3SPierre ProncheryAll of the functions described on this page are deprecated.
56b077aed3SPierre ProncheryApplications should instead use L<EVP_PKEY_get_bn_param(3)> for any methods that
57*aa795734SPierre Proncheryreturn a B<BIGNUM>. Refer to L<EVP_PKEY-DH(7)> for more information.
58b077aed3SPierre Pronchery
59e71b7053SJung-uk KimAn RSA object contains the components for the public and private key,
60e71b7053SJung-uk KimB<n>, B<e>, B<d>, B<p>, B<q>, B<dmp1>, B<dmq1> and B<iqmp>.  B<n> is
61e71b7053SJung-uk Kimthe modulus common to both public and private key, B<e> is the public
62e71b7053SJung-uk Kimexponent and B<d> is the private exponent.  B<p>, B<q>, B<dmp1>,
63e71b7053SJung-uk KimB<dmq1> and B<iqmp> are the factors for the second representation of a
64e71b7053SJung-uk Kimprivate key (see PKCS#1 section 3 Key Types), where B<p> and B<q> are
65e71b7053SJung-uk Kimthe first and second factor of B<n> and B<dmp1>, B<dmq1> and B<iqmp>
66e71b7053SJung-uk Kimare the exponents and coefficient for CRT calculations.
67e71b7053SJung-uk Kim
68e71b7053SJung-uk KimFor multi-prime RSA (defined in RFC 8017), there are also one or more
69e71b7053SJung-uk Kim'triplet' in an RSA object. A triplet contains three members, B<r>, B<d>
70e71b7053SJung-uk Kimand B<t>. B<r> is the additional prime besides B<p> and B<q>. B<d> and
71e71b7053SJung-uk KimB<t> are the exponent and coefficient for CRT calculations.
72e71b7053SJung-uk Kim
73e71b7053SJung-uk KimThe B<n>, B<e> and B<d> parameters can be obtained by calling
74e71b7053SJung-uk KimRSA_get0_key().  If they have not been set yet, then B<*n>, B<*e> and
75e71b7053SJung-uk KimB<*d> will be set to NULL.  Otherwise, they are set to pointers to
76e71b7053SJung-uk Kimtheir respective values. These point directly to the internal
77e71b7053SJung-uk Kimrepresentations of the values and therefore should not be freed
78e71b7053SJung-uk Kimby the caller.
79e71b7053SJung-uk Kim
80e71b7053SJung-uk KimThe B<n>, B<e> and B<d> parameter values can be set by calling
81e71b7053SJung-uk KimRSA_set0_key() and passing the new values for B<n>, B<e> and B<d> as
82e71b7053SJung-uk Kimparameters to the function.  The values B<n> and B<e> must be non-NULL
83e71b7053SJung-uk Kimthe first time this function is called on a given RSA object. The
84e71b7053SJung-uk Kimvalue B<d> may be NULL. On subsequent calls any of these values may be
85e71b7053SJung-uk KimNULL which means the corresponding RSA field is left untouched.
86e71b7053SJung-uk KimCalling this function transfers the memory management of the values to
87e71b7053SJung-uk Kimthe RSA object, and therefore the values that have been passed in
88e71b7053SJung-uk Kimshould not be freed by the caller after this function has been called.
89e71b7053SJung-uk Kim
90e71b7053SJung-uk KimIn a similar fashion, the B<p> and B<q> parameters can be obtained and
91e71b7053SJung-uk Kimset with RSA_get0_factors() and RSA_set0_factors(), and the B<dmp1>,
92e71b7053SJung-uk KimB<dmq1> and B<iqmp> parameters can be obtained and set with
93e71b7053SJung-uk KimRSA_get0_crt_params() and RSA_set0_crt_params().
94e71b7053SJung-uk Kim
95e71b7053SJung-uk KimFor RSA_get0_key(), RSA_get0_factors(), and RSA_get0_crt_params(),
96e71b7053SJung-uk KimNULL value BIGNUM ** output parameters are permitted. The functions
97e71b7053SJung-uk Kimignore NULL parameters but return values for other, non-NULL, parameters.
98e71b7053SJung-uk Kim
99e71b7053SJung-uk KimFor multi-prime RSA, RSA_get0_multi_prime_factors() and RSA_get0_multi_prime_params()
100e71b7053SJung-uk Kimcan be used to obtain other primes and related CRT parameters. The
101e71b7053SJung-uk Kimreturn values are stored in an array of B<BIGNUM *>. RSA_set0_multi_prime_params()
102e71b7053SJung-uk Kimsets a collect of multi-prime 'triplet' members (prime, exponent and coefficient)
103e71b7053SJung-uk Kiminto an RSA object.
104e71b7053SJung-uk Kim
105e71b7053SJung-uk KimAny of the values B<n>, B<e>, B<d>, B<p>, B<q>, B<dmp1>, B<dmq1>, and B<iqmp> can also be
106e71b7053SJung-uk Kimretrieved separately by the corresponding function
107e71b7053SJung-uk KimRSA_get0_n(), RSA_get0_e(), RSA_get0_d(), RSA_get0_p(), RSA_get0_q(),
108e71b7053SJung-uk KimRSA_get0_dmp1(), RSA_get0_dmq1(), and RSA_get0_iqmp(), respectively.
109e71b7053SJung-uk Kim
11017f01e99SJung-uk KimRSA_get0_pss_params() is used to retrieve the RSA-PSS parameters.
11117f01e99SJung-uk Kim
112e71b7053SJung-uk KimRSA_set_flags() sets the flags in the B<flags> parameter on the RSA
113e71b7053SJung-uk Kimobject. Multiple flags can be passed in one go (bitwise ORed together).
114e71b7053SJung-uk KimAny flags that are already set are left set. RSA_test_flags() tests to
115e71b7053SJung-uk Kimsee whether the flags passed in the B<flags> parameter are currently
116e71b7053SJung-uk Kimset in the RSA object. Multiple flags can be tested in one go. All
117e71b7053SJung-uk Kimflags that are currently set are returned, or zero if none of the
118e71b7053SJung-uk Kimflags are set. RSA_clear_flags() clears the specified flags within the
119e71b7053SJung-uk KimRSA object.
120e71b7053SJung-uk Kim
121e71b7053SJung-uk KimRSA_get0_engine() returns a handle to the ENGINE that has been set for
122e71b7053SJung-uk Kimthis RSA object, or NULL if no such ENGINE has been set.
123e71b7053SJung-uk Kim
124e71b7053SJung-uk KimRSA_get_version() returns the version of an RSA object B<r>.
125e71b7053SJung-uk Kim
126e71b7053SJung-uk Kim=head1 NOTES
127e71b7053SJung-uk Kim
128e71b7053SJung-uk KimValues retrieved with RSA_get0_key() are owned by the RSA object used
129e71b7053SJung-uk Kimin the call and may therefore I<not> be passed to RSA_set0_key().  If
130e71b7053SJung-uk Kimneeded, duplicate the received value using BN_dup() and pass the
131e71b7053SJung-uk Kimduplicate.  The same applies to RSA_get0_factors() and RSA_set0_factors()
132e71b7053SJung-uk Kimas well as RSA_get0_crt_params() and RSA_set0_crt_params().
133e71b7053SJung-uk Kim
134e71b7053SJung-uk KimThe caller should obtain the size by calling RSA_get_multi_prime_extra_count()
135e71b7053SJung-uk Kimin advance and allocate sufficient buffer to store the return values before
136e71b7053SJung-uk Kimcalling RSA_get0_multi_prime_factors() and RSA_get0_multi_prime_params().
137e71b7053SJung-uk Kim
138e71b7053SJung-uk KimRSA_set0_multi_prime_params() always clears the original multi-prime
139e71b7053SJung-uk Kimtriplets in RSA object B<r> and assign the new set of triplets into it.
140e71b7053SJung-uk Kim
141e71b7053SJung-uk Kim=head1 RETURN VALUES
142e71b7053SJung-uk Kim
143e71b7053SJung-uk KimRSA_set0_key(), RSA_set0_factors(), RSA_set0_crt_params() and
144e71b7053SJung-uk KimRSA_set0_multi_prime_params() return 1 on success or 0 on failure.
145e71b7053SJung-uk Kim
146e71b7053SJung-uk KimRSA_get0_n(), RSA_get0_e(), RSA_get0_d(), RSA_get0_p(), RSA_get0_q(),
147e71b7053SJung-uk KimRSA_get0_dmp1(), RSA_get0_dmq1(), and RSA_get0_iqmp()
148e71b7053SJung-uk Kimreturn the respective value.
149e71b7053SJung-uk Kim
150b077aed3SPierre ProncheryRSA_get0_pss_params() returns a B<RSA_PSS_PARAMS> pointer, or NULL if
151b077aed3SPierre Proncherythere is none.
152b077aed3SPierre Pronchery
153e71b7053SJung-uk KimRSA_get0_multi_prime_factors() and RSA_get0_multi_prime_crt_params() return
154e71b7053SJung-uk Kim1 on success or 0 on failure.
155e71b7053SJung-uk Kim
156e71b7053SJung-uk KimRSA_get_multi_prime_extra_count() returns two less than the number of primes
157e71b7053SJung-uk Kimin use, which is 0 for traditional RSA and the number of extra primes for
158e71b7053SJung-uk Kimmulti-prime RSA.
159e71b7053SJung-uk Kim
160e71b7053SJung-uk KimRSA_get_version() returns B<RSA_ASN1_VERSION_MULTI> for multi-prime RSA and
161e71b7053SJung-uk KimB<RSA_ASN1_VERSION_DEFAULT> for normal two-prime RSA, as defined in RFC 8017.
162e71b7053SJung-uk Kim
163e71b7053SJung-uk KimRSA_test_flags() returns the current state of the flags in the RSA object.
164e71b7053SJung-uk Kim
165e71b7053SJung-uk KimRSA_get0_engine() returns the ENGINE set for the RSA object or NULL if no
166e71b7053SJung-uk KimENGINE has been set.
167e71b7053SJung-uk Kim
168e71b7053SJung-uk Kim=head1 SEE ALSO
169e71b7053SJung-uk Kim
170e71b7053SJung-uk KimL<RSA_new(3)>, L<RSA_size(3)>
171e71b7053SJung-uk Kim
172e71b7053SJung-uk Kim=head1 HISTORY
173e71b7053SJung-uk Kim
17417f01e99SJung-uk KimThe RSA_get0_pss_params() function was added in OpenSSL 1.1.1e.
17517f01e99SJung-uk Kim
1766935a639SJung-uk KimThe
177e71b7053SJung-uk KimRSA_get_multi_prime_extra_count(), RSA_get0_multi_prime_factors(),
178e71b7053SJung-uk KimRSA_get0_multi_prime_crt_params(), RSA_set0_multi_prime_params(),
179e71b7053SJung-uk Kimand RSA_get_version() functions were added in OpenSSL 1.1.1.
180e71b7053SJung-uk Kim
181e71b7053SJung-uk KimOther functions described here were added in OpenSSL 1.1.0.
182e71b7053SJung-uk Kim
183b077aed3SPierre ProncheryAll of these functions were deprecated in OpenSSL 3.0.
184b077aed3SPierre Pronchery
185e71b7053SJung-uk Kim=head1 COPYRIGHT
186e71b7053SJung-uk Kim
187*aa795734SPierre ProncheryCopyright 2016-2023 The OpenSSL Project Authors. All Rights Reserved.
188e71b7053SJung-uk Kim
189b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
190e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
191e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
192e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
193e71b7053SJung-uk Kim
194e71b7053SJung-uk Kim=cut
195