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_OpenSSL, RSA_flags, RSA_new_method - select
8 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_OpenSSL(void);
22
23 int RSA_flags(const RSA *rsa);
24
25 RSA *RSA_new_method(ENGINE *engine);
26
28 An RSA_METHOD specifies the functions that OpenSSL uses for RSA
29 operations. By modifying the method, alternative implementations such
30 as hardware accelerators may be used. IMPORTANT: See the NOTES section
31 for important information about how these RSA API functions are
32 affected by the use of ENGINE API calls.
33
34 Initially, the default RSA_METHOD is the OpenSSL internal
35 implementation, as returned by RSA_PKCS1_OpenSSL().
36
37 RSA_set_default_method() makes meth the default method for all RSA
38 structures created later. NB: This is true only whilst no ENGINE has
39 been set as a default for RSA, so this function is no longer
40 recommended. This function is not thread-safe and should not be called
41 at the same time as other OpenSSL functions.
42
43 RSA_get_default_method() returns a pointer to the current default
44 RSA_METHOD. However, the meaningfulness of this result is dependent on
45 whether the ENGINE API is being used, so this function is no longer
46 recommended.
47
48 RSA_set_method() selects meth to perform all operations using the key
49 rsa. This will replace the RSA_METHOD used by the RSA key and if the
50 previous method was supplied by an ENGINE, the handle to that ENGINE
51 will be released during the change. It is possible to have RSA keys
52 that only work with certain RSA_METHOD implementations (e.g. from an
53 ENGINE module that supports embedded hardware-protected keys), and in
54 such cases attempting to change the RSA_METHOD for the key can have
55 unexpected results.
56
57 RSA_get_method() returns a pointer to the RSA_METHOD being used by rsa.
58 This method may or may not be supplied by an ENGINE implementation, but
59 if it is, the return value can only be guaranteed to be valid as long
60 as the RSA key itself is valid and does not have its implementation
61 changed by RSA_set_method().
62
63 RSA_flags() returns the flags that are set for rsa's current
64 RSA_METHOD. See the BUGS section.
65
66 RSA_new_method() allocates and initializes an RSA structure so that
67 engine will be used for the RSA operations. If engine is NULL, the
68 default ENGINE for RSA operations is used, and if no default ENGINE is
69 set, the RSA_METHOD controlled by RSA_set_default_method() is used.
70
71 RSA_flags() returns the flags that are set for rsa's current method.
72
73 RSA_new_method() allocates and initializes an RSA structure so that
74 method will be used for the RSA operations. If method is NULL, the
75 default method is used.
76
78 typedef struct rsa_meth_st
79 {
80 /* name of the implementation */
81 const char *name;
82
83 /* encrypt */
84 int (*rsa_pub_enc)(int flen, unsigned char *from,
85 unsigned char *to, RSA *rsa, int padding);
86
87 /* verify arbitrary data */
88 int (*rsa_pub_dec)(int flen, unsigned char *from,
89 unsigned char *to, RSA *rsa, int padding);
90
91 /* sign arbitrary data */
92 int (*rsa_priv_enc)(int flen, unsigned char *from,
93 unsigned char *to, RSA *rsa, int padding);
94
95 /* decrypt */
96 int (*rsa_priv_dec)(int flen, unsigned char *from,
97 unsigned char *to, RSA *rsa, int padding);
98
99 /* compute r0 = r0 ^ I mod rsa->n (May be NULL for some implementations) */
100 int (*rsa_mod_exp)(BIGNUM *r0, BIGNUM *I, RSA *rsa);
101
102 /* compute r = a ^ p mod m (May be NULL for some implementations) */
103 int (*bn_mod_exp)(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
104 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
105
106 /* called at RSA_new */
107 int (*init)(RSA *rsa);
108
109 /* called at RSA_free */
110 int (*finish)(RSA *rsa);
111
112 /*
113 * RSA_FLAG_EXT_PKEY - rsa_mod_exp is called for private key
114 * operations, even if p,q,dmp1,dmq1,iqmp
115 * are NULL
116 * RSA_METHOD_FLAG_NO_CHECK - don't check pub/private match
117 */
118 int flags;
119
120 char *app_data; /* ?? */
121
122 int (*rsa_sign)(int type,
123 const unsigned char *m, unsigned int m_length,
124 unsigned char *sigret, unsigned int *siglen, const RSA *rsa);
125 int (*rsa_verify)(int dtype,
126 const unsigned char *m, unsigned int m_length,
127 const unsigned char *sigbuf, unsigned int siglen,
128 const RSA *rsa);
129 /* keygen. If NULL builtin RSA key generation will be used */
130 int (*rsa_keygen)(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
131
132 } RSA_METHOD;
133
135 RSA_PKCS1_OpenSSL(), RSA_PKCS1_null_method(), RSA_get_default_method()
136 and RSA_get_method() return pointers to the respective RSA_METHODs.
137
138 RSA_set_default_method() returns no value.
139
140 RSA_set_method() returns a pointer to the old RSA_METHOD implementation
141 that was replaced. However, this return value should probably be
142 ignored because if it was supplied by an ENGINE, the pointer could be
143 invalidated at any time if the ENGINE is unloaded (in fact it could be
144 unloaded as a result of the RSA_set_method() function releasing its
145 handle to the ENGINE). For this reason, the return type may be replaced
146 with a void declaration in a future release.
147
148 RSA_new_method() returns NULL and sets an error code that can be
149 obtained by ERR_get_error(3) if the allocation fails. Otherwise it
150 returns a pointer to the newly allocated structure.
151
153 The behaviour of RSA_flags() is a mis-feature that is left as-is for
154 now to avoid creating compatibility problems. RSA functionality, such
155 as the encryption functions, are controlled by the flags value in the
156 RSA key itself, not by the flags value in the RSA_METHOD attached to
157 the RSA key (which is what this function returns). If the flags element
158 of an RSA key is changed, the changes will be honoured by RSA
159 functionality but will not be reflected in the return value of the
160 RSA_flags() function - in effect RSA_flags() behaves more like an
161 RSA_default_flags() function (which does not currently exist).
162
164 RSA_new(3)
165
167 The RSA_null_method(), which was a partial attempt to avoid patent
168 issues, was replaced to always return NULL in OpenSSL 1.1.1.
169
171 Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
172
173 Licensed under the OpenSSL license (the "License"). You may not use
174 this file except in compliance with the License. You can obtain a copy
175 in the file LICENSE in the source distribution or at
176 <https://www.openssl.org/source/license.html>.
177
178
179
1801.1.1i 2021-07-22 RSA_SET_METHOD(3)