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