1 .\" $OpenBSD: RSA_set_method.3,v 1.5 2016/12/11 12:21:48 schwarze Exp $
2 .\" OpenSSL 99d63d46 Oct 26 13:56:48 2016 -0400
4 .\" This file was written by Ulf Moeller <ulf@openssl.org>
5 .\" and Geoff Thorpe <geoff@openssl.org>.
6 .\" Copyright (c) 2000, 2002, 2007, 2014 The OpenSSL Project.
7 .\" All rights reserved.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
13 .\" 1. Redistributions of source code must retain the above copyright
14 .\" notice, this list of conditions and the following disclaimer.
16 .\" 2. Redistributions in binary form must reproduce the above copyright
17 .\" notice, this list of conditions and the following disclaimer in
18 .\" the documentation and/or other materials provided with the
21 .\" 3. All advertising materials mentioning features or use of this
22 .\" software must display the following acknowledgment:
23 .\" "This product includes software developed by the OpenSSL Project
24 .\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
26 .\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 .\" endorse or promote products derived from this software without
28 .\" prior written permission. For written permission, please contact
29 .\" openssl-core@openssl.org.
31 .\" 5. Products derived from this software may not be called "OpenSSL"
32 .\" nor may "OpenSSL" appear in their names without prior written
33 .\" permission of the OpenSSL Project.
35 .\" 6. Redistributions of any form whatsoever must retain the following
37 .\" "This product includes software developed by the OpenSSL Project
38 .\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
40 .\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 .\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 .\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 .\" OF THE POSSIBILITY OF SUCH DAMAGE.
53 .Dd $Mdocdate: December 11 2016 $
57 .Nm RSA_set_default_method ,
58 .Nm RSA_get_default_method ,
61 .Nm RSA_PKCS1_SSLeay ,
65 .Nm RSA_get_default_openssl_method ,
66 .Nm RSA_set_default_openssl_method
71 .Fo RSA_set_default_method
72 .Fa "const RSA_METHOD *meth"
75 .Fn RSA_get_default_method void
79 .Fa "const RSA_METHOD *meth"
86 .Fn RSA_PKCS1_SSLeay void
88 .Fn RSA_null_method void
95 .Fa "RSA_METHOD *meth"
100 specifies the functions that OpenSSL uses for RSA operations.
101 By modifying the method, alternative implementations such as hardware
102 accelerators may be used.
105 section for how these RSA API functions are affected by the use of
109 Initially, the default
111 is the OpenSSL internal implementation, as returned by
112 .Fn RSA_PKCS1_SSLeay .
114 .Fn RSA_set_default_method
117 the default method for all
119 structures created later.
121 This is true only whilst no
123 has been set as a default for RSA, so this function is no longer
126 .Fn RSA_get_default_method
127 returns a pointer to the current default
129 However, the meaningfulness of this result is dependent on whether
132 API is being used, so this function is no longer recommended.
137 to perform all operations using the key
139 This will replace the
141 used by the RSA key, and if the previous method was supplied by an
145 will be released during the change.
146 It is possible to have RSA keys that only work with certain
148 implementations (e.g. from an
150 module that supports embedded hardware-protected keys),
151 and in such cases attempting to change the
153 for the key can have unexpected results.
156 returns a pointer to the
160 This method may or may not be supplied by an
162 implementation but if it is, the return value can only be guaranteed
163 to be valid as long as the RSA key itself is valid and does not
164 have its implementation changed by
168 returns the flags that are set for the current
177 allocates and initializes an
181 will be used for the RSA operations.
184 is NULL, the default ENGINE for RSA operations is used and, if no
185 default ENGINE is set, the RSA_METHOD controlled by
186 .Fn RSA_set_default_method
197 allocates and initializes an
201 will be used for the RSA operations.
206 the default method is used.
207 .Sh THE RSA_METHOD STRUCTURE
209 typedef struct rsa_meth_st
211 /* name of the implementation */
215 int (*rsa_pub_enc)(int flen, unsigned char *from,
216 unsigned char *to, RSA *rsa, int padding);
218 /* verify arbitrary data */
219 int (*rsa_pub_dec)(int flen, unsigned char *from,
220 unsigned char *to, RSA *rsa, int padding);
222 /* sign arbitrary data */
223 int (*rsa_priv_enc)(int flen, unsigned char *from,
224 unsigned char *to, RSA *rsa, int padding);
227 int (*rsa_priv_dec)(int flen, unsigned char *from,
228 unsigned char *to, RSA *rsa, int padding);
230 /* compute r0 = r0 ^ I mod rsa->n (May be NULL for some
232 int (*rsa_mod_exp)(BIGNUM *r0, BIGNUM *I, RSA *rsa);
234 /* compute r = a ^ p mod m (May be NULL for some implementations) */
235 int (*bn_mod_exp)(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
236 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
238 /* called at RSA_new */
239 int (*init)(RSA *rsa);
241 /* called at RSA_free */
242 int (*finish)(RSA *rsa);
244 /* RSA_FLAG_EXT_PKEY - rsa_mod_exp is called for private key
245 * operations, even if p,q,dmp1,dmq1,iqmp
247 * RSA_FLAG_SIGN_VER - enable rsa_sign and rsa_verify
248 * RSA_METHOD_FLAG_NO_CHECK - don't check pub/private match
252 char *app_data; /* ?? */
254 /* sign. For backward compatibility, this is used only
255 * if (flags & RSA_FLAG_SIGN_VER)
257 int (*rsa_sign)(int type, unsigned char *m, unsigned int m_len,
258 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
260 /* verify. For backward compatibility, this is used only
261 * if (flags & RSA_FLAG_SIGN_VER)
263 int (*rsa_verify)(int type, unsigned char *m, unsigned int m_len,
264 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
269 .Fn RSA_PKCS1_SSLeay ,
270 .Fn RSA_null_method ,
271 .Fn RSA_get_default_method
274 return pointers to the respective
278 returns a pointer to the old
280 implementation that was replaced.
281 However, this return value should probably be ignored because if it was
284 the pointer could be invalidated at any time if the
287 In fact, it could be unloaded as a result of the
289 function releasing its handle to the
291 For this reason, the return type may be replaced with a
293 declaration in a future release.
298 and sets an error code that can be obtained by
300 if the allocation fails.
301 Otherwise it returns a pointer to the newly allocated structure.
307 .Fn RSA_set_default_method
308 appeared in SSLeay 0.8.
309 .Fn RSA_get_default_method ,
319 were added in OpenSSL 0.9.4.
321 .Fn RSA_set_default_openssl_method
323 .Fn RSA_get_default_openssl_method
325 .Fn RSA_set_default_method
327 .Fn RSA_get_default_method
336 during development of the
338 version of OpenSSL 0.9.6.
339 For 0.9.7, the handling of defaults in the
341 API was restructured so that this change was reversed, and behaviour
342 of the other functions resembled more closely the previous behaviour.
343 The behaviour of defaults in the
345 API now transparently overrides the behaviour of defaults in the
346 RSA API without requiring changing these function prototypes.
350 implementations are grouped together with other algorithmic APIs (e.g.\&
359 is specified for RSA functionality using an
361 API function, that will override any RSA defaults set using the RSA
363 .Fn RSA_set_default_method .
366 API is the recommended way to control default implementations for
367 use in RSA and other cryptographic algorithms.
371 is a misfeature that is left as-is for now to avoid creating
372 compatibility problems.
373 RSA functionality, such as the encryption functions, are controlled by
378 key itself, not by the
382 attached to the RSA key (which is what this function returns).
383 If the flags element of an
385 key is changed, the changes will be honoured by RSA functionality
386 but will not be reflected in the return value of the
390 behaves more like a RSA_default_flags() function, which does not