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