xref: /freebsd/crypto/openssl/doc/man3/RSA_meth_new.pod (revision 02e9120893770924227138ba49df1edb3896112a)
1=pod
2
3=head1 NAME
4
5RSA_meth_get0_app_data, RSA_meth_set0_app_data,
6RSA_meth_new, RSA_meth_free, RSA_meth_dup, RSA_meth_get0_name,
7RSA_meth_set1_name, RSA_meth_get_flags, RSA_meth_set_flags,
8RSA_meth_get_pub_enc,
9RSA_meth_set_pub_enc, RSA_meth_get_pub_dec, RSA_meth_set_pub_dec,
10RSA_meth_get_priv_enc, RSA_meth_set_priv_enc, RSA_meth_get_priv_dec,
11RSA_meth_set_priv_dec, RSA_meth_get_mod_exp, RSA_meth_set_mod_exp,
12RSA_meth_get_bn_mod_exp, RSA_meth_set_bn_mod_exp, RSA_meth_get_init,
13RSA_meth_set_init, RSA_meth_get_finish, RSA_meth_set_finish,
14RSA_meth_get_sign, RSA_meth_set_sign, RSA_meth_get_verify,
15RSA_meth_set_verify, RSA_meth_get_keygen, RSA_meth_set_keygen,
16RSA_meth_get_multi_prime_keygen, RSA_meth_set_multi_prime_keygen
17- Routines to build up RSA methods
18
19=head1 SYNOPSIS
20
21 #include <openssl/rsa.h>
22
23The following functions have been deprecated since OpenSSL 3.0, and can be
24hidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value,
25see L<openssl_user_macros(7)>:
26
27 RSA_METHOD *RSA_meth_new(const char *name, int flags);
28 void RSA_meth_free(RSA_METHOD *meth);
29
30 RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth);
31
32 const char *RSA_meth_get0_name(const RSA_METHOD *meth);
33 int RSA_meth_set1_name(RSA_METHOD *meth, const char *name);
34
35 int RSA_meth_get_flags(const RSA_METHOD *meth);
36 int RSA_meth_set_flags(RSA_METHOD *meth, int flags);
37
38 void *RSA_meth_get0_app_data(const RSA_METHOD *meth);
39 int RSA_meth_set0_app_data(RSA_METHOD *meth, void *app_data);
40
41 int (*RSA_meth_get_pub_enc(const RSA_METHOD *meth))(int flen, const unsigned char *from,
42                                                     unsigned char *to, RSA *rsa, int padding);
43 int RSA_meth_set_pub_enc(RSA_METHOD *rsa,
44                          int (*pub_enc)(int flen, const unsigned char *from,
45                                         unsigned char *to, RSA *rsa,
46                                         int padding));
47
48 int (*RSA_meth_get_pub_dec(const RSA_METHOD *meth))
49     (int flen, const unsigned char *from,
50      unsigned char *to, RSA *rsa, int padding);
51 int RSA_meth_set_pub_dec(RSA_METHOD *rsa,
52                          int (*pub_dec)(int flen, const unsigned char *from,
53                                         unsigned char *to, RSA *rsa,
54                                         int padding));
55
56 int (*RSA_meth_get_priv_enc(const RSA_METHOD *meth))(int flen, const unsigned char *from,
57                                                      unsigned char *to, RSA *rsa,
58                                                      int padding);
59 int RSA_meth_set_priv_enc(RSA_METHOD *rsa,
60                           int (*priv_enc)(int flen, const unsigned char *from,
61                                           unsigned char *to, RSA *rsa, int padding));
62
63 int (*RSA_meth_get_priv_dec(const RSA_METHOD *meth))(int flen, const unsigned char *from,
64                                                      unsigned char *to, RSA *rsa,
65                                                      int padding);
66 int RSA_meth_set_priv_dec(RSA_METHOD *rsa,
67                           int (*priv_dec)(int flen, const unsigned char *from,
68                                           unsigned char *to, RSA *rsa, int padding));
69
70 /* Can be null */
71 int (*RSA_meth_get_mod_exp(const RSA_METHOD *meth))(BIGNUM *r0, const BIGNUM *i,
72                                                     RSA *rsa, BN_CTX *ctx);
73 int RSA_meth_set_mod_exp(RSA_METHOD *rsa,
74                          int (*mod_exp)(BIGNUM *r0, const BIGNUM *i, RSA *rsa,
75                                         BN_CTX *ctx));
76
77 /* Can be null */
78 int (*RSA_meth_get_bn_mod_exp(const RSA_METHOD *meth))(BIGNUM *r, const BIGNUM *a,
79                                                        const BIGNUM *p, const BIGNUM *m,
80                                                        BN_CTX *ctx, BN_MONT_CTX *m_ctx);
81 int RSA_meth_set_bn_mod_exp(RSA_METHOD *rsa,
82                             int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a,
83                                               const BIGNUM *p, const BIGNUM *m,
84                                               BN_CTX *ctx, BN_MONT_CTX *m_ctx));
85
86 /* called at new */
87 int (*RSA_meth_get_init(const RSA_METHOD *meth) (RSA *rsa);
88 int RSA_meth_set_init(RSA_METHOD *rsa, int (*init (RSA *rsa));
89
90 /* called at free */
91 int (*RSA_meth_get_finish(const RSA_METHOD *meth))(RSA *rsa);
92 int RSA_meth_set_finish(RSA_METHOD *rsa, int (*finish)(RSA *rsa));
93
94 int (*RSA_meth_get_sign(const RSA_METHOD *meth))(int type, const unsigned char *m,
95                                                  unsigned int m_length,
96                                                  unsigned char *sigret,
97                                                  unsigned int *siglen, const RSA *rsa);
98 int RSA_meth_set_sign(RSA_METHOD *rsa,
99                       int (*sign)(int type, const unsigned char *m,
100                                   unsigned int m_length, unsigned char *sigret,
101                                   unsigned int *siglen, const RSA *rsa));
102
103 int (*RSA_meth_get_verify(const RSA_METHOD *meth))(int dtype, const unsigned char *m,
104                                                    unsigned int m_length,
105                                                    const unsigned char *sigbuf,
106                                                    unsigned int siglen, const RSA *rsa);
107 int RSA_meth_set_verify(RSA_METHOD *rsa,
108                         int (*verify)(int dtype, const unsigned char *m,
109                                       unsigned int m_length,
110                                       const unsigned char *sigbuf,
111                                       unsigned int siglen, const RSA *rsa));
112
113 int (*RSA_meth_get_keygen(const RSA_METHOD *meth))(RSA *rsa, int bits, BIGNUM *e,
114                                                    BN_GENCB *cb);
115 int RSA_meth_set_keygen(RSA_METHOD *rsa,
116                         int (*keygen)(RSA *rsa, int bits, BIGNUM *e,
117                                       BN_GENCB *cb));
118
119 int (*RSA_meth_get_multi_prime_keygen(const RSA_METHOD *meth))(RSA *rsa, int bits,
120                                                                int primes, BIGNUM *e,
121                                                                BN_GENCB *cb);
122
123 int RSA_meth_set_multi_prime_keygen(RSA_METHOD *meth,
124                                     int (*keygen) (RSA *rsa, int bits,
125                                                    int primes, BIGNUM *e,
126                                                    BN_GENCB *cb));
127
128=head1 DESCRIPTION
129
130All of the functions described on this page are deprecated.
131Applications should instead use the OSSL_PROVIDER APIs.
132
133The B<RSA_METHOD> type is a structure used for the provision of custom
134RSA implementations. It provides a set of functions used by OpenSSL
135for the implementation of the various RSA capabilities.
136
137RSA_meth_new() creates a new B<RSA_METHOD> structure. It should be
138given a unique B<name> and a set of B<flags>. The B<name> should be a
139NULL terminated string, which will be duplicated and stored in the
140B<RSA_METHOD> object. It is the callers responsibility to free the
141original string. The flags will be used during the construction of a
142new B<RSA> object based on this B<RSA_METHOD>. Any new B<RSA> object
143will have those flags set by default.
144
145RSA_meth_dup() creates a duplicate copy of the B<RSA_METHOD> object
146passed as a parameter. This might be useful for creating a new
147B<RSA_METHOD> based on an existing one, but with some differences.
148
149RSA_meth_free() destroys an B<RSA_METHOD> structure and frees up any
150memory associated with it.
151
152RSA_meth_get0_name() will return a pointer to the name of this
153RSA_METHOD. This is a pointer to the internal name string and so
154should not be freed by the caller. RSA_meth_set1_name() sets the name
155of the RSA_METHOD to B<name>. The string is duplicated and the copy is
156stored in the RSA_METHOD structure, so the caller remains responsible
157for freeing the memory associated with the name.
158
159RSA_meth_get_flags() returns the current value of the flags associated
160with this RSA_METHOD. RSA_meth_set_flags() provides the ability to set
161these flags.
162
163The functions RSA_meth_get0_app_data() and RSA_meth_set0_app_data()
164provide the ability to associate implementation specific data with the
165RSA_METHOD. It is the application's responsibility to free this data
166before the RSA_METHOD is freed via a call to RSA_meth_free().
167
168RSA_meth_get_sign() and RSA_meth_set_sign() get and set the function
169used for creating an RSA signature respectively. This function will be
170called in response to the application calling RSA_sign(). The
171parameters for the function have the same meaning as for RSA_sign().
172
173RSA_meth_get_verify() and RSA_meth_set_verify() get and set the
174function used for verifying an RSA signature respectively. This
175function will be called in response to the application calling
176RSA_verify(). The parameters for the function have the same meaning as
177for RSA_verify().
178
179RSA_meth_get_mod_exp() and RSA_meth_set_mod_exp() get and set the
180function used for CRT computations.
181
182RSA_meth_get_bn_mod_exp() and RSA_meth_set_bn_mod_exp() get and set
183the function used for CRT computations, specifically the following
184value:
185
186 r = a ^ p mod m
187
188Both the mod_exp() and bn_mod_exp() functions are called by the
189default OpenSSL method during encryption, decryption, signing and
190verification.
191
192RSA_meth_get_init() and RSA_meth_set_init() get and set the function
193used for creating a new RSA instance respectively. This function will
194be called in response to the application calling RSA_new() (if the
195current default RSA_METHOD is this one) or RSA_new_method(). The
196RSA_new() and RSA_new_method() functions will allocate the memory for
197the new RSA object, and a pointer to this newly allocated structure
198will be passed as a parameter to the function. This function may be
199NULL.
200
201RSA_meth_get_finish() and RSA_meth_set_finish() get and set the
202function used for destroying an instance of an RSA object respectively.
203This function will be called in response to the application calling
204RSA_free(). A pointer to the RSA to be destroyed is passed as a
205parameter. The destroy function should be used for RSA implementation
206specific clean up. The memory for the RSA itself should not be freed
207by this function. This function may be NULL.
208
209RSA_meth_get_keygen() and RSA_meth_set_keygen() get and set the
210function used for generating a new RSA key pair respectively. This
211function will be called in response to the application calling
212RSA_generate_key_ex(). The parameter for the function has the same
213meaning as for RSA_generate_key_ex().
214
215RSA_meth_get_multi_prime_keygen() and RSA_meth_set_multi_prime_keygen() get
216and set the function used for generating a new multi-prime RSA key pair
217respectively. This function will be called in response to the application calling
218RSA_generate_multi_prime_key(). The parameter for the function has the same
219meaning as for RSA_generate_multi_prime_key().
220
221RSA_meth_get_pub_enc(), RSA_meth_set_pub_enc(),
222RSA_meth_get_pub_dec(), RSA_meth_set_pub_dec(),
223RSA_meth_get_priv_enc(), RSA_meth_set_priv_enc(),
224RSA_meth_get_priv_dec(), RSA_meth_set_priv_dec() get and set the
225functions used for public and private key encryption and decryption.
226These functions will be called in response to the application calling
227RSA_public_encrypt(), RSA_private_decrypt(), RSA_private_encrypt() and
228RSA_public_decrypt() and take the same parameters as those.
229
230
231=head1 RETURN VALUES
232
233RSA_meth_new() and RSA_meth_dup() return the newly allocated
234RSA_METHOD object or NULL on failure.
235
236RSA_meth_get0_name() and RSA_meth_get_flags() return the name and
237flags associated with the RSA_METHOD respectively.
238
239All other RSA_meth_get_*() functions return the appropriate function
240pointer that has been set in the RSA_METHOD, or NULL if no such
241pointer has yet been set.
242
243RSA_meth_set1_name and all RSA_meth_set_*() functions return 1 on
244success or 0 on failure.
245
246=head1 SEE ALSO
247
248L<RSA_new(3)>, L<RSA_generate_key_ex(3)>, L<RSA_sign(3)>,
249L<RSA_set_method(3)>, L<RSA_size(3)>, L<RSA_get0_key(3)>,
250L<RSA_generate_multi_prime_key(3)>
251
252=head1 HISTORY
253
254All of these functions were deprecated in OpenSSL 3.0.
255
256RSA_meth_get_multi_prime_keygen() and RSA_meth_set_multi_prime_keygen() were
257added in OpenSSL 1.1.1.
258
259Other functions described here were added in OpenSSL 1.1.0.
260
261=head1 COPYRIGHT
262
263Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
264
265Licensed under the Apache License 2.0 (the "License").  You may not use
266this file except in compliance with the License.  You can obtain a copy
267in the file LICENSE in the source distribution or at
268L<https://www.openssl.org/source/license.html>.
269
270=cut
271