summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/man/RSA_set_method.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/man/RSA_set_method.3')
-rw-r--r--src/lib/libcrypto/man/RSA_set_method.3339
1 files changed, 339 insertions, 0 deletions
diff --git a/src/lib/libcrypto/man/RSA_set_method.3 b/src/lib/libcrypto/man/RSA_set_method.3
new file mode 100644
index 0000000000..d7a2756b70
--- /dev/null
+++ b/src/lib/libcrypto/man/RSA_set_method.3
@@ -0,0 +1,339 @@
1.Dd $Mdocdate: November 4 2016 $
2.Dt RSA_SET_METHOD 3
3.Os
4.Sh NAME
5.Nm RSA_set_default_method ,
6.Nm RSA_get_default_method ,
7.Nm RSA_set_method ,
8.Nm RSA_get_method ,
9.Nm RSA_PKCS1_SSLeay ,
10.Nm RSA_null_method ,
11.Nm RSA_flags ,
12.Nm RSA_new_method ,
13.Nm RSA_get_default_openssl_method ,
14.Nm RSA_set_default_openssl_method
15.Nd select RSA method
16.Sh SYNOPSIS
17.In openssl/rsa.h
18.Ft void
19.Fo RSA_set_default_method
20.Fa "const RSA_METHOD *meth"
21.Fc
22.Ft RSA_METHOD *
23.Fn RSA_get_default_method void
24.Ft int
25.Fo RSA_set_method
26.Fa "RSA *rsa"
27.Fa "const RSA_METHOD *meth"
28.Fc
29.Ft RSA_METHOD *
30.Fo RSA_get_method
31.Fa "const RSA *rsa"
32.Fc
33.Ft RSA_METHOD *
34.Fn RSA_PKCS1_SSLeay void
35.Ft RSA_METHOD *
36.Fn RSA_null_method void
37.Ft int
38.Fo RSA_flags
39.Fa "const RSA *rsa"
40.Fc
41.Ft RSA *
42.Fo RSA_new_method
43.Fa "RSA_METHOD *meth"
44.Fc
45.Sh DESCRIPTION
46An
47.Vt RSA_METHOD
48specifies the functions that OpenSSL uses for RSA operations.
49By modifying the method, alternative implementations such as hardware
50accelerators may be used.
51See the
52.Sx CAVEATS
53section for how these RSA API functions are affected by the use of
54.Xr engine 3
55API calls.
56.Pp
57Initially, the default
58.Vt RSA_METHOD
59is the OpenSSL internal implementation, as returned by
60.Fn RSA_PKCS1_SSLeay .
61.Pp
62.Fn RSA_set_default_method
63makes
64.Fa meth
65the default method for all
66.Vt RSA
67structures created later.
68.Sy NB :
69This is true only whilst no
70.Vt ENGINE
71has been set as a default for RSA, so this function is no longer
72recommended.
73.Pp
74.Fn RSA_get_default_method
75returns a pointer to the current default
76.Vt RSA_METHOD .
77However, the meaningfulness of this result is dependent on whether
78the
79.Xr engine 3
80API is being used, so this function is no longer recommended.
81.Pp
82.Fn RSA_set_method
83selects
84.Fa meth
85to perform all operations using the key
86.Fa rsa .
87This will replace the
88.Vt RSA_METHOD
89used by the RSA key, and if the previous method was supplied by an
90.Vt ENGINE ,
91the handle to that
92.Vt ENGINE
93will be released during the change.
94It is possible to have RSA keys that only work with certain
95.Vt RSA_METHOD
96implementations (eg. from an
97.Vt ENGINE
98module that supports embedded hardware-protected keys),
99and in such cases attempting to change the
100.Vt RSA_METHOD
101for the key can have unexpected results.
102.Pp
103.Fn RSA_get_method
104returns a pointer to the
105.Vt RSA_METHOD
106being used by
107.Fa rsa .
108This method may or may not be supplied by an
109.Vt ENGINE
110implementation, but if it is, the return value can only be guaranteed
111to be valid as long as the RSA key itself is valid and does not
112have its implementation changed by
113.Fn RSA_set_method .
114.Pp
115.Fn RSA_flags
116returns the flags that are set for the current
117.Vt RSA_METHOD
118of
119.Fa rsa .
120See the
121.Sx BUGS
122section.
123.Pp
124.Fn RSA_new_method
125allocates and initializes an
126.Vt RSA
127structure so that
128.Fa meth
129will be used for the RSA operations.
130If
131.Sy engine
132is NULL, the default ENGINE for RSA operations is used, and if no
133default ENGINE is set, the RSA_METHOD controlled by
134.Fn RSA_set_default_method
135is used.
136.Pp
137.Fn RSA_flags
138returns the
139.Sy flags
140that are set for
141.Fa rsa Ns 's
142current method.
143.Pp
144.Fn RSA_new_method
145allocates and initializes an
146.Vt RSA
147structure so that
148.Fa meth
149will be used for the RSA operations.
150If
151.Fa meth
152is
153.Dv NULL ,
154the default method is used.
155.Sh THE RSA_METHOD STRUCTURE
156.Bd -literal
157typedef struct rsa_meth_st
158{
159 /* name of the implementation */
160 const char *name;
161
162 /* encrypt */
163 int (*rsa_pub_enc)(int flen, unsigned char *from,
164 unsigned char *to, RSA *rsa, int padding);
165
166 /* verify arbitrary data */
167 int (*rsa_pub_dec)(int flen, unsigned char *from,
168 unsigned char *to, RSA *rsa, int padding);
169
170 /* sign arbitrary data */
171 int (*rsa_priv_enc)(int flen, unsigned char *from,
172 unsigned char *to, RSA *rsa, int padding);
173
174 /* decrypt */
175 int (*rsa_priv_dec)(int flen, unsigned char *from,
176 unsigned char *to, RSA *rsa, int padding);
177
178 /* compute r0 = r0 ^ I mod rsa->n (May be NULL for some
179 implementations) */
180 int (*rsa_mod_exp)(BIGNUM *r0, BIGNUM *I, RSA *rsa);
181
182 /* compute r = a ^ p mod m (May be NULL for some implementations) */
183 int (*bn_mod_exp)(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
184 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
185
186 /* called at RSA_new */
187 int (*init)(RSA *rsa);
188
189 /* called at RSA_free */
190 int (*finish)(RSA *rsa);
191
192 /* RSA_FLAG_EXT_PKEY - rsa_mod_exp is called for private key
193 * operations, even if p,q,dmp1,dmq1,iqmp
194 * are NULL
195 * RSA_FLAG_SIGN_VER - enable rsa_sign and rsa_verify
196 * RSA_METHOD_FLAG_NO_CHECK - don't check pub/private match
197 */
198 int flags;
199
200 char *app_data; /* ?? */
201
202 /* sign. For backward compatibility, this is used only
203 * if (flags & RSA_FLAG_SIGN_VER)
204 */
205 int (*rsa_sign)(int type, unsigned char *m, unsigned int m_len,
206 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
207
208 /* verify. For backward compatibility, this is used only
209 * if (flags & RSA_FLAG_SIGN_VER)
210 */
211 int (*rsa_verify)(int type, unsigned char *m, unsigned int m_len,
212 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
213
214} RSA_METHOD;
215.Ed
216.Sh RETURN VALUES
217.Fn RSA_PKCS1_SSLeay ,
218.Fn RSA_null_method ,
219.Fn RSA_get_default_method
220and
221.Fn RSA_get_method
222return pointers to the respective
223.Vt RSA_METHOD .
224.Pp
225.Fn RSA_set_method
226returns a pointer to the old
227.Vt RSA_METHOD
228implementation that was replaced.
229However, this return value should probably be ignored because if it was
230supplied by an
231.Vt ENGINE ,
232the pointer could be invalidated at any time if the
233.Vt ENGINE
234is unloaded.
235In fact, it could be unloaded as a result of the
236.Fn RSA_set_method
237function releasing its handle to the
238.Vt ENGINE .
239For this reason, the return type may be replaced with a
240.Vt void
241declaration in a future release.
242.Pp
243.Fn RSA_new_method
244returns
245.Dv NULL
246and sets an error code that can be obtained by
247.Xr ERR_get_error 3
248if the allocation fails.
249Otherwise it returns a pointer to the newly allocated structure.
250.Sh SEE ALSO
251.Xr rsa 3 ,
252.Xr RSA_new 3
253.Sh HISTORY
254.Fn RSA_new_method
255and
256.Fn RSA_set_default_method
257appeared in SSLeay 0.8.
258.Fn RSA_get_default_method ,
259.Fn RSA_set_method ,
260and
261.Fn RSA_get_method
262as well as the
263.Fa rsa_sign
264and
265.Fa rsa_verify
266components of
267.Vt RSA_METHOD
268were added in OpenSSL 0.9.4.
269.Pp
270.Fn RSA_set_default_openssl_method
271and
272.Fn RSA_get_default_openssl_method
273replaced
274.Fn RSA_set_default_method
275and
276.Fn RSA_get_default_method
277respectively, and
278.Fn RSA_set_method
279and
280.Fn RSA_new_method
281were altered to use
282.Vt ENGINE Ns s
283rather than
284.Vt RSA_METHOD Ns s
285during development of the
286.Xr engine 3
287version of OpenSSL 0.9.6.
288For 0.9.7, the handling of defaults in the
289.Xr engine 3
290API was restructured so that this change was reversed, and behaviour
291of the other functions resembled more closely the previous behaviour.
292The behaviour of defaults in the
293.Xr engine 3
294API now transparently overrides the behaviour of defaults in the
295RSA API without requiring changing these function prototypes.
296.Sh CAVEATS
297As of version 0.9.7,
298.Vt RSA_METHOD
299implementations are grouped together with other algorithmic APIs (eg.\&
300.Vt DSA_METHOD ,
301.Vt EVP_CIPHER ,
302etc.) into
303.Vt ENGINE
304modules.
305If a default
306.Vt ENGINE
307is specified for RSA functionality using an
308.Xr engine 3
309API function, that will override any RSA defaults set using the RSA
310API, ie.\&
311.Fn RSA_set_default_method .
312For this reason, the
313.Xr engine 3
314API is the recommended way to control default implementations for
315use in RSA and other cryptographic algorithms.
316.Sh BUGS
317The behaviour of
318.Fn RSA_flags
319is a mis-feature that is left as-is for now to avoid creating
320compatibility problems.
321RSA functionality, such as the encryption functions, are controlled by
322the
323.Fa flags
324value in the
325.Vt RSA
326key itself, not by the
327.Fa flags
328value in the
329.Vt RSA_METHOD
330attached to the RSA key (which is what this function returns).
331If the flags element of an
332.Vt RSA
333key is changed, the changes will be honoured by RSA functionality
334but will not be reflected in the return value of the
335.Fn RSA_flags
336function - in effect
337.Fn RSA_flags
338behaves more like a RSA_default_flags() function, which does not
339currently exist.