Remove reference to RSA_PKCS1_RSAref, since it doesn't exist any more.
[openssl.git] / doc / crypto / RSA_set_method.pod
1 =pod
2
3 =head1 NAME
4
5 RSA_set_default_method, RSA_get_default_method, RSA_set_method,
6 RSA_get_method, RSA_PKCS1_SSLeay, RSA_null_method, RSA_flags,
7 RSA_new_method - select RSA method
8
9 =head1 SYNOPSIS
10
11  #include <openssl/rsa.h>
12
13  void RSA_set_default_method(const RSA_METHOD *meth);
14
15  RSA_METHOD *RSA_get_default_method(void);
16
17  int RSA_set_method(RSA *rsa, const RSA_METHOD *meth);
18
19  RSA_METHOD *RSA_get_method(const RSA *rsa);
20
21  RSA_METHOD *RSA_PKCS1_SSLeay(void);
22
23  RSA_METHOD *RSA_PKCS1_RSAref(void);
24
25  RSA_METHOD *RSA_null_method(void);
26
27  int RSA_flags(const RSA *rsa);
28
29  RSA *RSA_new_method(RSA_METHOD *method);
30
31 =head1 DESCRIPTION
32
33 An B<RSA_METHOD> specifies the functions that OpenSSL uses for RSA
34 operations. By modifying the method, alternative implementations such as
35 hardware accelerators may be used. IMPORTANT: See the NOTES section for
36 important information about how these RSA API functions are affected by the
37 use of B<ENGINE> API calls.
38
39 Initially, the default RSA_METHOD is the OpenSSL internal implementation,
40 as returned by RSA_PKCS1_SSLeay().
41
42 RSA_set_default_method() makes B<meth> the default method for all RSA
43 structures created later. B<NB>: This is true only whilst no ENGINE has
44 been set as a default for RSA, so this function is no longer recommended.
45
46 RSA_get_default_method() returns a pointer to the current default
47 RSA_METHOD. However, the meaningfulness of this result is dependant on
48 whether the ENGINE API is being used, so this function is no longer 
49 recommended.
50
51 RSA_set_method() selects B<meth> to perform all operations using the key
52 B<rsa>. This will replace the RSA_METHOD used by the RSA key and if the
53 previous method was supplied by an ENGINE, the handle to that ENGINE will
54 be released during the change. It is possible to have RSA keys that only
55 work with certain RSA_METHOD implementations (eg. from an ENGINE module
56 that supports embedded hardware-protected keys), and in such cases
57 attempting to change the RSA_METHOD for the key can have unexpected
58 results.
59
60 RSA_get_method() returns a pointer to the RSA_METHOD being used by B<rsa>.
61 This method may or may not be supplied by an ENGINE implementation, but if
62 it is, the return value can only be guaranteed to be valid as long as the
63 RSA key itself is valid and does not have its implementation changed by
64 RSA_set_method().
65
66 RSA_flags() returns the B<flags> that are set for B<rsa>'s current
67 RSA_METHOD. See the BUGS section.
68
69 RSA_new_method() allocates and initializes an RSA structure so that
70 B<engine> will be used for the RSA operations. If B<engine> is NULL, the
71 default ENGINE for RSA operations is used, and if no default ENGINE is set,
72 the RSA_METHOD controlled by RSA_set_default_method() is used.
73
74 RSA_flags() returns the B<flags> that are set for B<rsa>'s current method.
75
76 RSA_new_method() allocates and initializes an B<RSA> structure so that
77 B<method> will be used for the RSA operations. If B<method> is B<NULL>,
78 the default method is used.
79
80 =head1 THE RSA_METHOD STRUCTURE
81
82  typedef struct rsa_meth_st
83  {
84      /* name of the implementation */
85         const char *name;
86
87      /* encrypt */
88         int (*rsa_pub_enc)(int flen, unsigned char *from,
89           unsigned char *to, RSA *rsa, int padding);
90
91      /* verify arbitrary data */
92         int (*rsa_pub_dec)(int flen, unsigned char *from,
93           unsigned char *to, RSA *rsa, int padding);
94
95      /* sign arbitrary data */
96         int (*rsa_priv_enc)(int flen, unsigned char *from,
97           unsigned char *to, RSA *rsa, int padding);
98
99      /* decrypt */
100         int (*rsa_priv_dec)(int flen, unsigned char *from,
101           unsigned char *to, RSA *rsa, int padding);
102
103      /* compute r0 = r0 ^ I mod rsa->n (May be NULL for some
104                                         implementations) */
105         int (*rsa_mod_exp)(BIGNUM *r0, BIGNUM *I, RSA *rsa);
106
107      /* compute r = a ^ p mod m (May be NULL for some implementations) */
108         int (*bn_mod_exp)(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
109           const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
110
111      /* called at RSA_new */
112         int (*init)(RSA *rsa);
113
114      /* called at RSA_free */
115         int (*finish)(RSA *rsa);
116
117      /* RSA_FLAG_EXT_PKEY        - rsa_mod_exp is called for private key
118       *                            operations, even if p,q,dmp1,dmq1,iqmp
119       *                            are NULL
120       * RSA_FLAG_SIGN_VER        - enable rsa_sign and rsa_verify
121       * RSA_METHOD_FLAG_NO_CHECK - don't check pub/private match
122       */
123         int flags;
124
125         char *app_data; /* ?? */
126
127      /* sign. For backward compatibility, this is used only
128       * if (flags & RSA_FLAG_SIGN_VER)
129       */
130         int (*rsa_sign)(int type, unsigned char *m, unsigned int m_len,
131            unsigned char *sigret, unsigned int *siglen, RSA *rsa);
132
133      /* verify. For backward compatibility, this is used only
134       * if (flags & RSA_FLAG_SIGN_VER)
135       */
136         int (*rsa_verify)(int type, unsigned char *m, unsigned int m_len,
137            unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
138
139  } RSA_METHOD;
140
141 =head1 RETURN VALUES
142
143 RSA_PKCS1_SSLeay(), RSA_PKCS1_null_method(), RSA_get_default_method()
144 and RSA_get_method() return pointers to the respective RSA_METHODs.
145
146 RSA_set_default_method() returns no value.
147
148 RSA_set_method() returns a pointer to the old RSA_METHOD implementation
149 that was replaced. However, this return value should probably be ignored
150 because if it was supplied by an ENGINE, the pointer could be invalidated
151 at any time if the ENGINE is unloaded (in fact it could be unloaded as a
152 result of the RSA_set_method() function releasing its handle to the
153 ENGINE). For this reason, the return type may be replaced with a B<void>
154 declaration in a future release.
155
156 RSA_new_method() returns NULL and sets an error code that can be obtained
157 by L<ERR_get_error(3)|ERR_get_error(3)> if the allocation fails. Otherwise
158 it returns a pointer to the newly allocated structure.
159
160 =head1 NOTES
161
162 As of version 0.9.7, RSA_METHOD implementations are grouped together with
163 other algorithmic APIs (eg. DSA_METHOD, EVP_CIPHER, etc) into B<ENGINE>
164 modules. If a default ENGINE is specified for RSA functionality using an
165 ENGINE API function, that will override any RSA defaults set using the RSA
166 API (ie.  RSA_set_default_method()). For this reason, the ENGINE API is the
167 recommended way to control default implementations for use in RSA and other
168 cryptographic algorithms.
169
170 =head1 BUGS
171
172 The behaviour of RSA_flags() is a mis-feature that is left as-is for now
173 to avoid creating compatibility problems. RSA functionality, such as the
174 encryption functions, are controlled by the B<flags> value in the RSA key
175 itself, not by the B<flags> value in the RSA_METHOD attached to the RSA key
176 (which is what this function returns). If the flags element of an RSA key
177 is changed, the changes will be honoured by RSA functionality but will not
178 be reflected in the return value of the RSA_flags() function - in effect
179 RSA_flags() behaves more like an RSA_default_flags() function (which does
180 not currently exist).
181
182 =head1 SEE ALSO
183
184 L<rsa(3)|rsa(3)>, L<RSA_new(3)|RSA_new(3)>
185
186 =head1 HISTORY
187
188 RSA_new_method() and RSA_set_default_method() appeared in SSLeay 0.8.
189 RSA_get_default_method(), RSA_set_method() and RSA_get_method() as
190 well as the rsa_sign and rsa_verify components of RSA_METHOD were
191 added in OpenSSL 0.9.4.
192
193 RSA_set_default_openssl_method() and RSA_get_default_openssl_method()
194 replaced RSA_set_default_method() and RSA_get_default_method()
195 respectively, and RSA_set_method() and RSA_new_method() were altered to use
196 B<ENGINE>s rather than B<RSA_METHOD>s during development of the engine
197 version of OpenSSL 0.9.6. For 0.9.7, the handling of defaults in the ENGINE
198 API was restructured so that this change was reversed, and behaviour of the
199 other functions resembled more closely the previous behaviour. The
200 behaviour of defaults in the ENGINE API now transparently overrides the
201 behaviour of defaults in the RSA API without requiring changing these
202 function prototypes.
203
204 =cut