summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/man/RSA_meth_new.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/man/RSA_meth_new.3')
-rw-r--r--src/lib/libcrypto/man/RSA_meth_new.3454
1 files changed, 431 insertions, 23 deletions
diff --git a/src/lib/libcrypto/man/RSA_meth_new.3 b/src/lib/libcrypto/man/RSA_meth_new.3
index 137e0cad87..8faab9490d 100644
--- a/src/lib/libcrypto/man/RSA_meth_new.3
+++ b/src/lib/libcrypto/man/RSA_meth_new.3
@@ -1,10 +1,11 @@
1.\" $OpenBSD: RSA_meth_new.3,v 1.3 2018/09/12 15:09:22 jmc Exp $ 1.\" $OpenBSD: RSA_meth_new.3,v 1.4 2019/06/08 09:53:15 schwarze Exp $
2.\" selective merge up to: OpenSSL a970b14f Jul 31 18:58:40 2017 -0400 2.\" full merge up to: OpenSSL a970b14f Jul 31 18:58:40 2017 -0400
3.\" selective merge up to: OpenSSL 24907560 Sep 17 07:47:42 2018 +1000
3.\" 4.\"
4.\" This file is a derived work. 5.\" This file is a derived work.
5.\" The changes are covered by the following Copyright and license: 6.\" The changes are covered by the following Copyright and license:
6.\" 7.\"
7.\" Copyright (c) 2018 Ingo Schwarze <schwarze@openbsd.org> 8.\" Copyright (c) 2018, 2019 Ingo Schwarze <schwarze@openbsd.org>
8.\" 9.\"
9.\" Permission to use, copy, modify, and distribute this software for any 10.\" Permission to use, copy, modify, and distribute this software for any
10.\" purpose with or without fee is hereby granted, provided that the above 11.\" purpose with or without fee is hereby granted, provided that the above
@@ -65,18 +66,41 @@
65.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 66.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
66.\" OF THE POSSIBILITY OF SUCH DAMAGE. 67.\" OF THE POSSIBILITY OF SUCH DAMAGE.
67.\" 68.\"
68.Dd $Mdocdate: September 12 2018 $ 69.Dd $Mdocdate: June 8 2019 $
69.Dt RSA_METH_NEW 3 70.Dt RSA_METH_NEW 3
70.Os 71.Os
71.Sh NAME 72.Sh NAME
72.Nm RSA_meth_new , 73.Nm RSA_meth_new ,
73.Nm RSA_meth_dup , 74.Nm RSA_meth_dup ,
74.Nm RSA_meth_free , 75.Nm RSA_meth_free ,
75.Nm RSA_meth_get_finish , 76.Nm RSA_meth_get0_name ,
76.Nm RSA_meth_set1_name , 77.Nm RSA_meth_set1_name ,
78.Nm RSA_meth_get_flags ,
79.Nm RSA_meth_set_flags ,
80.Nm RSA_meth_get0_app_data ,
81.Nm RSA_meth_set0_app_data ,
82.Nm RSA_meth_get_init ,
83.Nm RSA_meth_set_init ,
84.Nm RSA_meth_get_finish ,
77.Nm RSA_meth_set_finish , 85.Nm RSA_meth_set_finish ,
86.Nm RSA_meth_get_pub_enc ,
87.Nm RSA_meth_set_pub_enc ,
88.Nm RSA_meth_get_pub_dec ,
89.Nm RSA_meth_set_pub_dec ,
90.Nm RSA_meth_get_priv_enc ,
78.Nm RSA_meth_set_priv_enc , 91.Nm RSA_meth_set_priv_enc ,
79.Nm RSA_meth_set_priv_dec 92.Nm RSA_meth_get_priv_dec ,
93.Nm RSA_meth_set_priv_dec ,
94.Nm RSA_meth_get_sign ,
95.Nm RSA_meth_set_sign ,
96.Nm RSA_meth_get_verify ,
97.Nm RSA_meth_set_verify ,
98.Nm RSA_meth_get_mod_exp ,
99.Nm RSA_meth_set_mod_exp ,
100.Nm RSA_meth_get_bn_mod_exp ,
101.Nm RSA_meth_set_bn_mod_exp ,
102.Nm RSA_meth_get_keygen ,
103.Nm RSA_meth_set_keygen
80.Nd build up RSA methods 104.Nd build up RSA methods
81.Sh SYNOPSIS 105.Sh SYNOPSIS
82.In openssl/rsa.h 106.In openssl/rsa.h
@@ -93,30 +117,177 @@
93.Fo RSA_meth_free 117.Fo RSA_meth_free
94.Fa "RSA_METHOD *meth" 118.Fa "RSA_METHOD *meth"
95.Fc 119.Fc
120.Ft const char *
121.Fo RSA_meth_get0_name
122.Fa "const RSA_METHOD *meth"
123.Fc
96.Ft int 124.Ft int
97.Fo RSA_meth_set1_name 125.Fo RSA_meth_set1_name
98.Fa "RSA_METHOD *meth" 126.Fa "RSA_METHOD *meth"
99.Fa "const char *name" 127.Fa "const char *name"
100.Fc 128.Fc
101.Ft int 129.Ft int
102.Fn "(*RSA_meth_get_finish(const RSA_METHOD *meth))" "RSA *rsa" 130.Fo RSA_meth_get_flags
131.Fa "const RSA_METHOD *meth"
132.Fc
133.Ft int
134.Fo RSA_meth_set_flags
135.Fa "RSA_METHOD *meth"
136.Fa "int flags"
137.Fc
138.Ft void *
139.Fo RSA_meth_get0_app_data
140.Fa "const RSA_METHOD *meth"
141.Fc
142.Ft int
143.Fo RSA_meth_set0_app_data
144.Fa "RSA_METHOD *meth"
145.Fa "void *app_data"
146.Fc
147.Ft int
148.Fo "(*RSA_meth_get_init(const RSA_METHOD *meth))"
149.Fa "RSA *rsa"
150.Fc
151.Ft int
152.Fo "RSA_meth_set_init"
153.Fa "RSA_METHOD *meth"
154.Fa "int (*init)(RSA *rsa)"
155.Fc
156.Ft int
157.Fo "(*RSA_meth_get_finish(const RSA_METHOD *meth))"
158.Fa "RSA *rsa"
159.Fc
103.Ft int 160.Ft int
104.Fo RSA_meth_set_finish 161.Fo RSA_meth_set_finish
105.Fa "RSA_METHOD *meth" 162.Fa "RSA_METHOD *meth"
106.Fa "int (*finish)(RSA *rsa)" 163.Fa "int (*finish)(RSA *rsa)"
107.Fc 164.Fc
108.Ft int 165.Ft int
166.Fo "(*RSA_meth_get_pub_enc(const RSA_METHOD *meth))"
167.Fa "int flen"
168.Fa "const unsigned char *from"
169.Fa "unsigned char *to"
170.Fa "RSA *rsa"
171.Fa "int padding"
172.Fc
173.Ft int
174.Fo RSA_meth_set_pub_enc
175.Fa "RSA_METHOD *meth"
176.Fa "int (*pub_enc)(int flen, const unsigned char *from,\
177 unsigned char *to, RSA *rsa, int padding)"
178.Fc
179.Ft int
180.Fo "(*RSA_meth_get_pub_dec(const RSA_METHOD *meth))"
181.Fa "int flen"
182.Fa "const unsigned char *from"
183.Fa "unsigned char *to"
184.Fa "RSA *rsa"
185.Fa "int padding"
186.Fc
187.Ft int
188.Fo RSA_meth_set_pub_dec
189.Fa "RSA_METHOD *meth"
190.Fa "int (*pub_dec)(int flen, const unsigned char *from,\
191 unsigned char *to, RSA *rsa, int padding)"
192.Fc
193.Ft int
194.Fo "(*RSA_meth_get_priv_enc(const RSA_METHOD *meth))"
195.Fa "int flen"
196.Fa "const unsigned char *from"
197.Fa "unsigned char *to"
198.Fa "RSA *rsa"
199.Fa "int padding"
200.Fc
201.Ft int
109.Fo RSA_meth_set_priv_enc 202.Fo RSA_meth_set_priv_enc
110.Fa "RSA_METHOD *meth" 203.Fa "RSA_METHOD *meth"
111.Fa "int (*priv_enc)(int flen, const unsigned char *from,\ 204.Fa "int (*priv_enc)(int flen, const unsigned char *from,\
112 unsigned char *to, RSA *rsa, int padding)" 205 unsigned char *to, RSA *rsa, int padding)"
113.Fc 206.Fc
114.Ft int 207.Ft int
208.Fo "(*RSA_meth_get_priv_dec(const RSA_METHOD *meth))"
209.Fa "int flen"
210.Fa "const unsigned char *from"
211.Fa "unsigned char *to"
212.Fa "RSA *rsa"
213.Fa "int padding"
214.Fc
215.Ft int
115.Fo RSA_meth_set_priv_dec 216.Fo RSA_meth_set_priv_dec
116.Fa "RSA_METHOD *meth" 217.Fa "RSA_METHOD *meth"
117.Fa "int (*priv_dec)(int flen, const unsigned char *from,\ 218.Fa "int (*priv_dec)(int flen, const unsigned char *from,\
118 unsigned char *to, RSA *rsa, int padding)" 219 unsigned char *to, RSA *rsa, int padding)"
119.Fc 220.Fc
221.Ft int
222.Fo "(*RSA_meth_get_sign(const RSA_METHOD *meth))"
223.Fa "int type"
224.Fa "const unsigned char *m"
225.Fa "unsigned int m_length"
226.Fa "unsigned char *sigret"
227.Fa "unsigned int *siglen"
228.Fa "const RSA *rsa"
229.Fc
230.Ft int
231.Fo RSA_meth_set_sign
232.Fa "RSA_METHOD *rsa"
233.Fa "int (*sign)(int type, const unsigned char *m, unsigned int m_length,\
234 unsigned char *sigret, unsigned int *siglen, const RSA *rsa)"
235.Fc
236.Ft int
237.Fo "(*RSA_meth_get_verify(const RSA_METHOD *meth))"
238.Fa "int dtype"
239.Fa "const unsigned char *m"
240.Fa "unsigned int m_length"
241.Fa "const unsigned char *sigbuf"
242.Fa "unsigned int siglen"
243.Fa "const RSA *rsa"
244.Fc
245.Ft int
246.Fo RSA_meth_set_verify
247.Fa "RSA_METHOD *rsa"
248.Fa "int (*verify)(int dtype, const unsigned char *m,\
249 unsigned int m_length, const unsigned char *sigbuf,\
250 unsigned int siglen, const RSA *rsa)"
251.Fc
252.Ft int
253.Fo "(*RSA_meth_get_mod_exp(const RSA_METHOD *meth))"
254.Fa "BIGNUM *r0"
255.Fa "const BIGNUM *i"
256.Fa "RSA *rsa"
257.Fa "BN_CTX *ctx"
258.Fc
259.Ft int
260.Fo RSA_meth_set_mod_exp
261.Fa "RSA_METHOD *meth"
262.Fa "int (*mod_exp)(BIGNUM *r0, const BIGNUM *i, RSA *rsa, BN_CTX *ctx)"
263.Fc
264.Ft int
265.Fo "(*RSA_meth_get_bn_mod_exp(const RSA_METHOD *meth))"
266.Fa "BIGNUM *r"
267.Fa "const BIGNUM *a"
268.Fa "const BIGNUM *p"
269.Fa "const BIGNUM *m"
270.Fa "BN_CTX *ctx"
271.Fa "BN_MONT_CTX *m_ctx"
272.Fc
273.Ft int
274.Fo RSA_meth_set_bn_mod_exp
275.Fa "RSA_METHOD *meth"
276.Fa "int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\
277 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)"
278.Fc
279.Ft int
280.Fo "(*RSA_meth_get_keygen(const RSA_METHOD *meth))"
281.Fa "RSA *rsa"
282.Fa "int bits"
283.Fa "BIGNUM *e"
284.Fa "BN_GENCB *cb"
285.Fc
286.Ft int
287.Fo RSA_meth_set_keygen
288.Fa "RSA_METHOD *meth"
289.Fa "int (*keygen)(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb)"
290.Fc
120.Sh DESCRIPTION 291.Sh DESCRIPTION
121The 292The
122.Vt RSA_METHOD 293.Vt RSA_METHOD
@@ -137,11 +308,15 @@ object constructed from this
137.Vt RSA_METHOD 308.Vt RSA_METHOD
138will have the given 309will have the given
139.Fa flags 310.Fa flags
140set by default. 311set by default, as if they were set with
312.Xr RSA_set_flags 3 .
141.Pp 313.Pp
142.Fn RSA_meth_dup 314.Fn RSA_meth_dup
143creates a deep copy of 315creates a deep copy of
144.Fa meth . 316.Fa meth ,
317except that a pointer stored into it with
318.Fn RSA_meth_set0_app_data
319is copied as a pointer without creating a copy of its content.
145This might be useful for creating a new 320This might be useful for creating a new
146.Vt RSA_METHOD 321.Vt RSA_METHOD
147based on an existing one, but with some differences. 322based on an existing one, but with some differences.
@@ -149,15 +324,80 @@ based on an existing one, but with some differences.
149.Fn RSA_meth_free 324.Fn RSA_meth_free
150destroys 325destroys
151.Fa meth 326.Fa meth
152and frees any memory associated with it. 327and frees any memory associated with it,
328except that memory pointed to by a pointer set with
329.Fn RSA_meth_set0_app_data
330is not freed.
331If
332.Fa meth
333is
334.Dv NULL ,
335no action occurs.
153.Pp 336.Pp
337.Fn RSA_meth_get0_name
338returns an internal pointer to the name of
339.Fa meth .
154.Fn RSA_meth_set1_name 340.Fn RSA_meth_set1_name
155Stores a copy of the NUL-terminated 341stores a copy of the NUL-terminated
156.Fa name 342.Fa name
157in the 343in the
158.Vt RSA_METHOD 344.Vt RSA_METHOD
159object after freeing the previously stored 345object after freeing the previously stored name.
160.Fa name . 346Method names are ignored by the default RSA implementation
347but can be used by alternative implementations
348and by the application program.
349.Pp
350.Fn RSA_meth_get_flags
351retrieves the flags from
352.Fa meth .
353Flags are documented in
354.Xr RSA_test_flags 3 .
355.Fn RSA_meth_set_flags
356overwrites all flags in
357.Fa meth .
358Unlike
359.Xr RSA_set_flags 3 ,
360it does not preserve any flags that were set before the call.
361.Pp
362.Fn RSA_meth_get0_app_data
363and
364.Fn RSA_meth_set0_app_data
365get and set a pointer to implementation-specific data.
366The function
367.Fn RSA_meth_free
368does not
369.Xr free 3
370the memory pointed to by
371.Fa app_data .
372The default RSA implementation does not use
373.Fa app_data .
374.Pp
375.Fn RSA_meth_get_init
376and
377.Fn RSA_meth_set_init
378get and set an optional function used when creating a new
379.Vt RSA
380object.
381Unless
382.Fa init
383is
384.Dv NULL ,
385it will be called at the end of
386.Xr RSA_new 3 ,
387.Xr RSA_new_method 3 ,
388and
389.Xr RSA_set_method 3 ,
390passing a pointer to the newly allocated or reset
391.Vt RSA
392object as an argument.
393The default RSA implementation,
394.Xr RSA_PKCS1_SSLeay 3 ,
395contains an
396.Fa init
397function equivalent to calling
398.Xr RSA_set_flags 3
399with an argument of
400.Dv RSA_FLAG_CACHE_PUBLIC | RSA_FLAG_CACHE_PRIVATE .
161.Pp 401.Pp
162.Fn RSA_meth_get_finish 402.Fn RSA_meth_get_finish
163and 403and
@@ -170,24 +410,125 @@ Unless
170is 410is
171.Dv NULL , 411.Dv NULL ,
172it will be called from 412it will be called from
413.Xr RSA_set_method 3
414and from
173.Xr RSA_free 3 . 415.Xr RSA_free 3 .
174It takes the same argument 416It takes the same argument as
417.Xr RSA_free 3
175and is intended to do RSA implementation specific cleanup. 418and is intended to do RSA implementation specific cleanup.
176The memory used by the 419The memory used by the
177.Vt RSA 420.Vt RSA
178object itself should not be freed by the 421object itself should not be freed by the
179.Fa finish 422.Fa finish
180function. 423function.
424The default RSA implementation contains a
425.Fa finish
426function freeing the memory used by the
427.Dv RSA_FLAG_CACHE_PUBLIC
428and
429.Dv RSA_FLAG_CACHE_PRIVATE
430caches.
181.Pp 431.Pp
182.Fn RSA_meth_set_priv_enc 432.Fn RSA_meth_get_pub_enc ,
433.Fn RSA_meth_set_pub_enc ,
434.Fn RSA_meth_get_pub_dec ,
435.Fn RSA_meth_set_pub_dec ,
436.Fn RSA_meth_get_priv_enc ,
437.Fn RSA_meth_set_priv_enc ,
438.Fn RSA_meth_get_priv_dec ,
183and 439and
184.Fn RSA_meth_set_priv_dec 440.Fn RSA_meth_set_priv_dec
185set the functions used for private key encryption and decryption. 441get and set the mandatory functions
442used for public and private key encryption and decryption.
186These functions will be called from 443These functions will be called from
444.Xr RSA_public_encrypt 3 ,
445.Xr RSA_public_decrypt 3 ,
446.Xr RSA_private_encrypt 3 ,
447and
448.Xr RSA_private_decrypt 3 ,
449respectively, and take the same parameters as those.
450.Pp
451.Fn RSA_meth_get_sign ,
452.Fn RSA_meth_set_sign ,
453.Fn RSA_meth_get_verify ,
454and
455.Fn RSA_meth_set_verify
456get and set the optional functions
457used for creating and verifying an RSA signature.
458If the flag
459.Dv RSA_FLAG_SIGN_VER
460is set on the
461.Vt RSA
462object in question and
463.Fa sign
464or
465.Fa verify
466is not
467.Dv NULL ,
468it will be called from
469.Xr RSA_sign 3
470or
471.Xr RSA_verify 3 ,
472respectively, and take the same parameters as those.
473Otherwise,
474.Xr RSA_private_encrypt 3
475or
476.Xr RSA_public_decrypt 3
477will be used instead.
478.Pp
479.Fn RSA_meth_get_mod_exp
480and
481.Fn RSA_meth_set_mod_exp
482get and set the function used for CRT computations involving the
483.Fa p ,
484.Fa q ,
485.Fa dmp1 ,
486.Fa dmq1 ,
487and
488.Fa iqmp
489fields of an
490.Vt RSA
491object.
492It is used by the default RSA implementation during
493.Xr RSA_private_encrypt 3
494and
187.Xr RSA_private_decrypt 3 495.Xr RSA_private_decrypt 3
496when the required components of the private key are available
497or when the
498.Dv RSA_FLAG_EXT_PKEY
499flag is set.
500.Pp
501.Fn RSA_meth_get_bn_mod_exp
502and
503.Fn RSA_meth_set_bn_mod_exp
504get and set the function used for CRT computations,
505specifically the value r =
506.Fa a
507\(ha
508.Fa p
509mod
510.Fa m .
511It is used by the default RSA implementation during
512.Xr RSA_public_encrypt 3
188and 513and
514.Xr RSA_public_decrypt 3
515and as a fallback during
189.Xr RSA_private_encrypt 3 516.Xr RSA_private_encrypt 3
190and take the same parameters as those. 517and
518.Xr RSA_private_decrypt 3 .
519.Pp
520.Fn RSA_meth_get_keygen
521and
522.Fn RSA_meth_set_keygen
523get and set the optional function used for generating a new RSA key pair.
524Unless
525.Fa keygen
526is
527.Dv NULL ,
528it will be called from
529.Xr RSA_generate_key_ex 3
530and takes the same parameters.
531Otherwise, a builtin default implementation is used.
191.Sh RETURN VALUES 532.Sh RETURN VALUES
192.Fn RSA_meth_new 533.Fn RSA_meth_new
193and 534and
@@ -198,20 +539,87 @@ object or
198.Dv NULL 539.Dv NULL
199on failure. 540on failure.
200.Pp 541.Pp
542.Fn RSA_meth_get0_name
543returns an internal pointer which must not be freed by the caller.
544.Pp
545.Fn RSA_meth_get_flags
546returns zero or more
547.Dv RSA_FLAG_*
548constants OR'ed together, or 0 if no flags are set in
549.Fa meth .
550.Pp
551.Fn RSA_meth_get0_app_data
552returns the pointer that was earlier passed to
553.Fn RSA_meth_set0_app_data
554or
555.Dv NULL
556otherwise.
557.Pp
558All other
559.Fn RSA_meth_get_*
560functions return the appropriate function pointer that has been set
561with the corresponding
562.Fn RSA_meth_set_*
563function, or
564.Dv NULL
565if no such pointer has been set in
566.Fa meth .
567.Pp
201All 568All
202.Fn RSA_meth_set* 569.Fn RSA_meth_set*
203functions return 1 on success or 0 on failure. 570functions return 1 on success or 0 on failure.
571In the current implementation, only
572.Fn RSA_meth_set1_name
573can actually fail.
204.Sh SEE ALSO 574.Sh SEE ALSO
575.Xr RSA_generate_key_ex 3 ,
205.Xr RSA_new 3 , 576.Xr RSA_new 3 ,
206.Xr RSA_private_decrypt 3 ,
207.Xr RSA_private_encrypt 3 , 577.Xr RSA_private_encrypt 3 ,
208.Xr RSA_set_method 3 578.Xr RSA_public_encrypt 3 ,
579.Xr RSA_set_flags 3 ,
580.Xr RSA_set_method 3 ,
581.Xr RSA_sign 3
209.Sh HISTORY 582.Sh HISTORY
210These functions first appeared in OpenSSL 1.1.0. 583These functions first appeared in OpenSSL 1.1.0.
211.Fn RSA_meth_get_finish 584.Fn RSA_meth_new ,
585.Fn RSA_meth_dup ,
586.Fn RSA_meth_free ,
587.Fn RSA_meth_set_finish ,
588.Fn RSA_meth_set_priv_enc ,
212and 589and
213.Fn RSA_meth_set1_name 590.Fn RSA_meth_set_priv_dec
214have been available since 591have been available since
592.Ox 6.3 ,
593.Fn RSA_meth_set1_name
594and
595.Fn RSA_meth_get_finish
596since
215.Ox 6.4 , 597.Ox 6.4 ,
216all the other functions since 598and
217.Ox 6.3 . 599.Fn RSA_meth_get0_name ,
600.Fn RSA_meth_get_flags ,
601.Fn RSA_meth_set_flags ,
602.Fn RSA_meth_get0_app_data ,
603.Fn RSA_meth_set0_app_data ,
604.Fn RSA_meth_get_init ,
605.Fn RSA_meth_set_init ,
606.Fn RSA_meth_set_finish ,
607.Fn RSA_meth_get_pub_enc ,
608.Fn RSA_meth_set_pub_enc ,
609.Fn RSA_meth_get_pub_dec ,
610.Fn RSA_meth_set_pub_dec ,
611.Fn RSA_meth_get_priv_enc ,
612.Fn RSA_meth_get_priv_dec ,
613.Fn RSA_meth_get_sign ,
614.Fn RSA_meth_set_sign ,
615.Fn RSA_meth_get_verify ,
616.Fn RSA_meth_set_verify ,
617.Fn RSA_meth_get_mod_exp ,
618.Fn RSA_meth_set_mod_exp ,
619.Fn RSA_meth_get_bn_mod_exp ,
620.Fn RSA_meth_set_bn_mod_exp ,
621.Fn RSA_meth_get_keygen ,
622and
623.Fn RSA_meth_set_keygen
624since
625.Ox 6.6 .