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