summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorschwarze <>2019-06-08 09:53:15 +0000
committerschwarze <>2019-06-08 09:53:15 +0000
commitc7efff3e254b868e292d5726e03e83b957c0dd15 (patch)
tree19f63916a773468b6ac2c1b73fbac3a6aff56964 /src
parent75842177a9c23b09df0eb4e427a0a4a120a095c4 (diff)
downloadopenbsd-c7efff3e254b868e292d5726e03e83b957c0dd15.tar.gz
openbsd-c7efff3e254b868e292d5726e03e83b957c0dd15.tar.bz2
openbsd-c7efff3e254b868e292d5726e03e83b957c0dd15.zip
In rsa.h rev. 1.40, gilles@ provided several new RSA_METHOD accessors.
Update the documentation. OK tb@ jmc@
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/man/RSA_generate_key.35
-rw-r--r--src/lib/libcrypto/man/RSA_meth_new.3454
-rw-r--r--src/lib/libcrypto/man/RSA_new.314
-rw-r--r--src/lib/libcrypto/man/RSA_set_method.367
-rw-r--r--src/lib/libcrypto/man/RSA_sign.35
5 files changed, 499 insertions, 46 deletions
diff --git a/src/lib/libcrypto/man/RSA_generate_key.3 b/src/lib/libcrypto/man/RSA_generate_key.3
index 3ac3885f13..80bae6824c 100644
--- a/src/lib/libcrypto/man/RSA_generate_key.3
+++ b/src/lib/libcrypto/man/RSA_generate_key.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: RSA_generate_key.3,v 1.11 2018/03/27 17:35:50 schwarze Exp $ 1.\" $OpenBSD: RSA_generate_key.3,v 1.12 2019/06/08 09:53:15 schwarze Exp $
2.\" OpenSSL RSA_generate_key.pod bb6c5e7f Feb 5 10:29:22 2017 -0500 2.\" OpenSSL RSA_generate_key.pod bb6c5e7f Feb 5 10:29:22 2017 -0500
3.\" 3.\"
4.\" This file was written by Ulf Moeller <ulf@openssl.org>. 4.\" This file was written by Ulf Moeller <ulf@openssl.org>.
@@ -48,7 +48,7 @@
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE. 49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\" 50.\"
51.Dd $Mdocdate: March 27 2018 $ 51.Dd $Mdocdate: June 8 2019 $
52.Dt RSA_GENERATE_KEY 3 52.Dt RSA_GENERATE_KEY 3
53.Os 53.Os
54.Sh NAME 54.Sh NAME
@@ -144,6 +144,7 @@ The error codes can be obtained by
144.Xr BN_generate_prime 3 , 144.Xr BN_generate_prime 3 ,
145.Xr ERR_get_error 3 , 145.Xr ERR_get_error 3 ,
146.Xr RSA_get0_key 3 , 146.Xr RSA_get0_key 3 ,
147.Xr RSA_meth_set_keygen 3 ,
147.Xr RSA_new 3 148.Xr RSA_new 3
148.Sh HISTORY 149.Sh HISTORY
149.Fn RSA_generate_key 150.Fn RSA_generate_key
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 .
diff --git a/src/lib/libcrypto/man/RSA_new.3 b/src/lib/libcrypto/man/RSA_new.3
index 8f0e2c2a5e..7e40c11987 100644
--- a/src/lib/libcrypto/man/RSA_new.3
+++ b/src/lib/libcrypto/man/RSA_new.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: RSA_new.3,v 1.11 2019/06/06 01:06:59 schwarze Exp $ 1.\" $OpenBSD: RSA_new.3,v 1.12 2019/06/08 09:53:15 schwarze Exp $
2.\" OpenSSL doc/man3/RSA_new.pod 99d63d46 Oct 26 13:56:48 2016 -0400 2.\" OpenSSL doc/man3/RSA_new.pod 99d63d46 Oct 26 13:56:48 2016 -0400
3.\" OpenSSL doc/crypto/rsa.pod 35d2e327 Jun 3 16:19:49 2016 -0400 3.\" OpenSSL doc/crypto/rsa.pod 35d2e327 Jun 3 16:19:49 2016 -0400
4.\" 4.\"
@@ -49,7 +49,7 @@
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE. 50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\" 51.\"
52.Dd $Mdocdate: June 6 2019 $ 52.Dd $Mdocdate: June 8 2019 $
53.Dt RSA_NEW 3 53.Dt RSA_NEW 3
54.Os 54.Os
55.Sh NAME 55.Sh NAME
@@ -88,7 +88,15 @@ increments the reference count by 1.
88.Pp 88.Pp
89.Fn RSA_free 89.Fn RSA_free
90decrements the reference count by 1. 90decrements the reference count by 1.
91If it reaches 0, it frees the 91If it reaches 0, it calls the optional
92.Fa finish
93function set up with
94.Xr RSA_meth_set_finish 3 ,
95calls
96.Xr ENGINE_finish 3
97if
98.Fa rsa
99uses an engine, and frees the
92.Vt RSA 100.Vt RSA
93structure and its components. 101structure and its components.
94The key is erased before the memory is returned to the system. 102The key is erased before the memory is returned to the system.
diff --git a/src/lib/libcrypto/man/RSA_set_method.3 b/src/lib/libcrypto/man/RSA_set_method.3
index 524430b6f8..53d41f5516 100644
--- a/src/lib/libcrypto/man/RSA_set_method.3
+++ b/src/lib/libcrypto/man/RSA_set_method.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: RSA_set_method.3,v 1.13 2019/05/20 06:04:45 jmc Exp $ 1.\" $OpenBSD: RSA_set_method.3,v 1.14 2019/06/08 09:53:15 schwarze Exp $
2.\" OpenSSL 99d63d46 Oct 26 13:56:48 2016 -0400 2.\" OpenSSL 99d63d46 Oct 26 13:56:48 2016 -0400
3.\" 3.\"
4.\" This file was written by Ulf Moeller <ulf@openssl.org> 4.\" This file was written by Ulf Moeller <ulf@openssl.org>
@@ -50,7 +50,7 @@
50.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 50.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51.\" OF THE POSSIBILITY OF SUCH DAMAGE. 51.\" OF THE POSSIBILITY OF SUCH DAMAGE.
52.\" 52.\"
53.Dd $Mdocdate: May 20 2019 $ 53.Dd $Mdocdate: June 8 2019 $
54.Dt RSA_SET_METHOD 3 54.Dt RSA_SET_METHOD 3
55.Os 55.Os
56.Sh NAME 56.Sh NAME
@@ -121,12 +121,25 @@ selects
121.Fa meth 121.Fa meth
122to perform all operations using the key 122to perform all operations using the key
123.Fa rsa . 123.Fa rsa .
124This replaces the 124This replaces the previous
125.Vt RSA_METHOD 125.Vt RSA_METHOD
126used by the RSA key, and if the previous method was supplied by an 126used by the RSA key, calling the
127.Fa finish
128function set up with
129.Xr RSA_meth_set_finish 3
130if any, and if the previous method was supplied by an
127.Vt ENGINE , 131.Vt ENGINE ,
128.Xr ENGINE_finish 3 132.Xr ENGINE_finish 3
129is called on it. 133is called on it.
134If
135.Fa meth
136contains an
137.Fa init
138function set up with
139.Xr RSA_meth_set_init 3 ,
140that function is called just before returning from
141.Fn RSA_set_method .
142.Pp
130It is possible to have RSA keys that only work with certain 143It is possible to have RSA keys that only work with certain
131.Vt RSA_METHOD 144.Vt RSA_METHOD
132implementations (e.g. from an 145implementations (e.g. from an
@@ -148,14 +161,19 @@ to be valid as long as the RSA key itself is valid and does not
148have its implementation changed by 161have its implementation changed by
149.Fn RSA_set_method . 162.Fn RSA_set_method .
150.Pp 163.Pp
164The misleadingly named function
151.Fn RSA_flags 165.Fn RSA_flags
152returns the flags that are set for the current 166returns the flags that are set for the current
153.Vt RSA_METHOD 167.Vt RSA_METHOD
154of 168of
155.Fa rsa . 169.Fa rsa .
170The flags used by
171.Fa rsa
172itself can instead be tested with
173.Xr RSA_test_flags 3 .
156See the 174See the
157.Sx BUGS 175.Sx BUGS
158section. 176section for more details.
159.Pp 177.Pp
160.Fn RSA_new_method 178.Fn RSA_new_method
161allocates and initializes an 179allocates and initializes an
@@ -175,6 +193,18 @@ the default method controlled by
175.Fn RSA_set_default_method 193.Fn RSA_set_default_method
176is used. 194is used.
177.Pp 195.Pp
196The initial
197.Fa flags
198are copied from the
199.Vt RSA_METHOD
200object used and will not be affected by later changes to that object,
201but may be modified by the optional
202.Fa init
203function which may have been set up with
204.Xr RSA_meth_set_init 3
205and which is called just before returning from
206.Fn RSA_new_method .
207.Pp
178The 208The
179.Dv RSA_METHOD 209.Dv RSA_METHOD
180structure is defined as follows: 210structure is defined as follows:
@@ -185,27 +215,28 @@ typedef struct rsa_meth_st
185 const char *name; 215 const char *name;
186 216
187 /* encrypt */ 217 /* encrypt */
188 int (*rsa_pub_enc)(int flen, unsigned char *from, 218 int (*rsa_pub_enc)(int flen, const unsigned char *from,
189 unsigned char *to, RSA *rsa, int padding); 219 unsigned char *to, RSA *rsa, int padding);
190 220
191 /* verify arbitrary data */ 221 /* verify arbitrary data */
192 int (*rsa_pub_dec)(int flen, unsigned char *from, 222 int (*rsa_pub_dec)(int flen, const unsigned char *from,
193 unsigned char *to, RSA *rsa, int padding); 223 unsigned char *to, RSA *rsa, int padding);
194 224
195 /* sign arbitrary data */ 225 /* sign arbitrary data */
196 int (*rsa_priv_enc)(int flen, unsigned char *from, 226 int (*rsa_priv_enc)(int flen, const unsigned char *from,
197 unsigned char *to, RSA *rsa, int padding); 227 unsigned char *to, RSA *rsa, int padding);
198 228
199 /* decrypt */ 229 /* decrypt */
200 int (*rsa_priv_dec)(int flen, unsigned char *from, 230 int (*rsa_priv_dec)(int flen, const unsigned char *from,
201 unsigned char *to, RSA *rsa, int padding); 231 unsigned char *to, RSA *rsa, int padding);
202 232
203 /* compute r0 = r0 ^ I mod rsa->n (May be NULL for some 233 /* compute r0 = r0 ^ I mod rsa->n (May be NULL for some
204 implementations) */ 234 implementations) */
205 int (*rsa_mod_exp)(BIGNUM *r0, BIGNUM *I, RSA *rsa); 235 int (*rsa_mod_exp)(BIGNUM *r0, const BIGNUM *I, RSA *rsa,
236 BN_CTX *ctx);
206 237
207 /* compute r = a ^ p mod m (May be NULL for some implementations) */ 238 /* compute r = a ^ p mod m (May be NULL for some implementations) */
208 int (*bn_mod_exp)(BIGNUM *r, BIGNUM *a, const BIGNUM *p, 239 int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
209 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); 240 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
210 241
211 /* called at RSA_new */ 242 /* called at RSA_new */
@@ -218,7 +249,6 @@ typedef struct rsa_meth_st
218 * operations, even if p,q,dmp1,dmq1,iqmp 249 * operations, even if p,q,dmp1,dmq1,iqmp
219 * are NULL 250 * are NULL
220 * RSA_FLAG_SIGN_VER - enable rsa_sign and rsa_verify 251 * RSA_FLAG_SIGN_VER - enable rsa_sign and rsa_verify
221 * RSA_METHOD_FLAG_NO_CHECK - don't check pub/private match
222 */ 252 */
223 int flags; 253 int flags;
224 254
@@ -227,14 +257,19 @@ typedef struct rsa_meth_st
227 /* sign. For backward compatibility, this is used only 257 /* sign. For backward compatibility, this is used only
228 * if (flags & RSA_FLAG_SIGN_VER) 258 * if (flags & RSA_FLAG_SIGN_VER)
229 */ 259 */
230 int (*rsa_sign)(int type, unsigned char *m, unsigned int m_len, 260 int (*rsa_sign)(int type, const unsigned char *m,
231 unsigned char *sigret, unsigned int *siglen, RSA *rsa); 261 unsigned int m_len, unsigned char *sigret,
262 unsigned int *siglen, const RSA *rsa);
232 263
233 /* verify. For backward compatibility, this is used only 264 /* verify. For backward compatibility, this is used only
234 * if (flags & RSA_FLAG_SIGN_VER) 265 * if (flags & RSA_FLAG_SIGN_VER)
235 */ 266 */
236 int (*rsa_verify)(int type, unsigned char *m, unsigned int m_len, 267 int (*rsa_verify)(int type, const unsigned char *m,
237 unsigned char *sigbuf, unsigned int siglen, RSA *rsa); 268 unsigned int m_len, const unsigned char *sigbuf,
269 unsigned int siglen, const RSA *rsa);
270
271 /* called at RSA_generate_key_ex; may be NULL */
272 int (*rsa_keygen)(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
238 273
239} RSA_METHOD; 274} RSA_METHOD;
240.Ed 275.Ed
diff --git a/src/lib/libcrypto/man/RSA_sign.3 b/src/lib/libcrypto/man/RSA_sign.3
index 80e0b0e957..166f2310a5 100644
--- a/src/lib/libcrypto/man/RSA_sign.3
+++ b/src/lib/libcrypto/man/RSA_sign.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: RSA_sign.3,v 1.6 2018/03/27 17:35:50 schwarze Exp $ 1.\" $OpenBSD: RSA_sign.3,v 1.7 2019/06/08 09:53:15 schwarze Exp $
2.\" OpenSSL aa90ca11 Aug 20 15:48:56 2016 -0400 2.\" OpenSSL aa90ca11 Aug 20 15:48:56 2016 -0400
3.\" 3.\"
4.\" This file was written by Ulf Moeller <ulf@openssl.org>. 4.\" This file was written by Ulf Moeller <ulf@openssl.org>.
@@ -49,7 +49,7 @@
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE. 50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\" 51.\"
52.Dd $Mdocdate: March 27 2018 $ 52.Dd $Mdocdate: June 8 2019 $
53.Dt RSA_SIGN 3 53.Dt RSA_SIGN 3
54.Os 54.Os
55.Sh NAME 55.Sh NAME
@@ -133,6 +133,7 @@ The error codes can be obtained by
133.Xr ERR_get_error 3 . 133.Xr ERR_get_error 3 .
134.Sh SEE ALSO 134.Sh SEE ALSO
135.Xr ERR_get_error 3 , 135.Xr ERR_get_error 3 ,
136.Xr RSA_meth_set_sign 3 ,
136.Xr RSA_new 3 , 137.Xr RSA_new 3 ,
137.Xr RSA_private_encrypt 3 , 138.Xr RSA_private_encrypt 3 ,
138.Xr RSA_public_decrypt 3 139.Xr RSA_public_decrypt 3