5 RSA_set_default_method, RSA_get_default_method, RSA_set_method,
6 RSA_get_method, RSA_PKCS1_OpenSSL, RSA_flags,
7 RSA_new_method - select RSA method
11 #include <openssl/rsa.h>
13 void RSA_set_default_method(const RSA_METHOD *meth);
15 RSA_METHOD *RSA_get_default_method(void);
17 int RSA_set_method(RSA *rsa, const RSA_METHOD *meth);
19 RSA_METHOD *RSA_get_method(const RSA *rsa);
21 RSA_METHOD *RSA_PKCS1_OpenSSL(void);
23 int RSA_flags(const RSA *rsa);
25 RSA *RSA_new_method(ENGINE *engine);
29 An B<RSA_METHOD> specifies the functions that OpenSSL uses for RSA
30 operations. By modifying the method, alternative implementations such as
31 hardware accelerators may be used. IMPORTANT: See the NOTES section for
32 important information about how these RSA API functions are affected by the
33 use of B<ENGINE> API calls.
35 Initially, the default RSA_METHOD is the OpenSSL internal implementation,
36 as returned by RSA_PKCS1_OpenSSL().
38 RSA_set_default_method() makes B<meth> the default method for all RSA
39 structures created later.
40 B<NB>: This is true only whilst no ENGINE has
41 been set as a default for RSA, so this function is no longer recommended.
42 This function is not thread-safe and should not be called at the same time
43 as other OpenSSL functions.
45 RSA_get_default_method() returns a pointer to the current default
46 RSA_METHOD. However, the meaningfulness of this result is dependent on
47 whether the ENGINE API is being used, so this function is no longer
50 RSA_set_method() selects B<meth> to perform all operations using the key
51 B<rsa>. This will replace the RSA_METHOD used by the RSA key and if the
52 previous method was supplied by an ENGINE, the handle to that ENGINE will
53 be released during the change. It is possible to have RSA keys that only
54 work with certain RSA_METHOD implementations (eg. from an ENGINE module
55 that supports embedded hardware-protected keys), and in such cases
56 attempting to change the RSA_METHOD for the key can have unexpected
59 RSA_get_method() returns a pointer to the RSA_METHOD being used by B<rsa>.
60 This method may or may not be supplied by an ENGINE implementation, but if
61 it is, the return value can only be guaranteed to be valid as long as the
62 RSA key itself is valid and does not have its implementation changed by
65 RSA_flags() returns the B<flags> that are set for B<rsa>'s current
66 RSA_METHOD. See the BUGS section.
68 RSA_new_method() allocates and initializes an RSA structure so that
69 B<engine> will be used for the RSA operations. If B<engine> is NULL, the
70 default ENGINE for RSA operations is used, and if no default ENGINE is set,
71 the RSA_METHOD controlled by RSA_set_default_method() is used.
73 RSA_flags() returns the B<flags> that are set for B<rsa>'s current method.
75 RSA_new_method() allocates and initializes an B<RSA> structure so that
76 B<method> will be used for the RSA operations. If B<method> is B<NULL>,
77 the default method is used.
79 =head1 THE RSA_METHOD STRUCTURE
81 typedef struct rsa_meth_st
83 /* name of the implementation */
87 int (*rsa_pub_enc)(int flen, unsigned char *from,
88 unsigned char *to, RSA *rsa, int padding);
90 /* verify arbitrary data */
91 int (*rsa_pub_dec)(int flen, unsigned char *from,
92 unsigned char *to, RSA *rsa, int padding);
94 /* sign arbitrary data */
95 int (*rsa_priv_enc)(int flen, unsigned char *from,
96 unsigned char *to, RSA *rsa, int padding);
99 int (*rsa_priv_dec)(int flen, unsigned char *from,
100 unsigned char *to, RSA *rsa, int padding);
102 /* compute r0 = r0 ^ I mod rsa->n (May be NULL for some implementations) */
103 int (*rsa_mod_exp)(BIGNUM *r0, BIGNUM *I, RSA *rsa);
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);
109 /* called at RSA_new */
110 int (*init)(RSA *rsa);
112 /* called at RSA_free */
113 int (*finish)(RSA *rsa);
116 * RSA_FLAG_EXT_PKEY - rsa_mod_exp is called for private key
117 * operations, even if p,q,dmp1,dmq1,iqmp
119 * RSA_METHOD_FLAG_NO_CHECK - don't check pub/private match
123 char *app_data; /* ?? */
125 int (*rsa_sign)(int type,
126 const unsigned char *m, unsigned int m_length,
127 unsigned char *sigret, unsigned int *siglen, const RSA *rsa);
128 int (*rsa_verify)(int dtype,
129 const unsigned char *m, unsigned int m_length,
130 const unsigned char *sigbuf, unsigned int siglen,
132 /* keygen. If NULL builtin RSA key generation will be used */
133 int (*rsa_keygen)(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
139 RSA_PKCS1_OpenSSL(), RSA_PKCS1_null_method(), RSA_get_default_method()
140 and RSA_get_method() return pointers to the respective RSA_METHODs.
142 RSA_set_default_method() returns no value.
144 RSA_set_method() returns a pointer to the old RSA_METHOD implementation
145 that was replaced. However, this return value should probably be ignored
146 because if it was supplied by an ENGINE, the pointer could be invalidated
147 at any time if the ENGINE is unloaded (in fact it could be unloaded as a
148 result of the RSA_set_method() function releasing its handle to the
149 ENGINE). For this reason, the return type may be replaced with a B<void>
150 declaration in a future release.
152 RSA_new_method() returns NULL and sets an error code that can be obtained
153 by L<ERR_get_error(3)> if the allocation fails. Otherwise
154 it returns a pointer to the newly allocated structure.
158 The behaviour of RSA_flags() is a mis-feature that is left as-is for now
159 to avoid creating compatibility problems. RSA functionality, such as the
160 encryption functions, are controlled by the B<flags> value in the RSA key
161 itself, not by the B<flags> value in the RSA_METHOD attached to the RSA key
162 (which is what this function returns). If the flags element of an RSA key
163 is changed, the changes will be honoured by RSA functionality but will not
164 be reflected in the return value of the RSA_flags() function - in effect
165 RSA_flags() behaves more like an RSA_default_flags() function (which does
166 not currently exist).
174 The RSA_null_method(), which was a partial attempt to avoid patent issues,
175 was replaced to always return NULL in OpenSSL 1.1.1.
179 Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
181 Licensed under the OpenSSL license (the "License"). You may not use
182 this file except in compliance with the License. You can obtain a copy
183 in the file LICENSE in the source distribution or at
184 L<https://www.openssl.org/source/license.html>.