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