summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorschwarze <>2023-08-31 17:27:41 +0000
committerschwarze <>2023-08-31 17:27:41 +0000
commit6adafa1ed9ad28e76b0a4bf339267f23a85c6bcf (patch)
treeab74fd16ac9e22d139215fe0e871eac001715264 /src/lib
parent9939c389dea4955b2a84815d7c821f036c266e0f (diff)
downloadopenbsd-6adafa1ed9ad28e76b0a4bf339267f23a85c6bcf.tar.gz
openbsd-6adafa1ed9ad28e76b0a4bf339267f23a85c6bcf.tar.bz2
openbsd-6adafa1ed9ad28e76b0a4bf339267f23a85c6bcf.zip
Split three new manual pages EVP_CIPHER_nid(3), EVP_CIPHER_CTX_ctrl(3),
and EVP_CIPHER_CTX_set_flags(3) out of the excessively large and unwieldy EVP_EncryptInit(3). This causes a number of inaccuracies and gaps to stand out, but i'm not mixing text changes or content additions into this split. Using very useful feedback from tb@ regarding what belongs together and how important the various functions are. I refrained from bothering him with the complete patch, but he likes the general direction.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/man/EVP_CIPHER_CTX_ctrl.3260
-rw-r--r--src/lib/libcrypto/man/EVP_CIPHER_CTX_set_flags.3228
-rw-r--r--src/lib/libcrypto/man/EVP_CIPHER_nid.3215
-rw-r--r--src/lib/libcrypto/man/EVP_EncryptInit.3463
-rw-r--r--src/lib/libcrypto/man/Makefile5
-rw-r--r--src/lib/libcrypto/man/evp.37
6 files changed, 727 insertions, 451 deletions
diff --git a/src/lib/libcrypto/man/EVP_CIPHER_CTX_ctrl.3 b/src/lib/libcrypto/man/EVP_CIPHER_CTX_ctrl.3
new file mode 100644
index 0000000000..40ed524ffa
--- /dev/null
+++ b/src/lib/libcrypto/man/EVP_CIPHER_CTX_ctrl.3
@@ -0,0 +1,260 @@
1.\" $OpenBSD: EVP_CIPHER_CTX_ctrl.3,v 1.1 2023/08/31 17:27:41 schwarze Exp $
2.\" full merge up to: OpenSSL 5211e094 Nov 11 14:39:11 2014 -0800
3.\"
4.\" This file is a derived work.
5.\" The changes are covered by the following Copyright and license:
6.\"
7.\" Copyright (c) 2018, 2023 Ingo Schwarze <schwarze@openbsd.org>
8.\" Copyright (c) 2018 Damien Miller <djm@openbsd.org>
9.\"
10.\" Permission to use, copy, modify, and distribute this software for any
11.\" purpose with or without fee is hereby granted, provided that the above
12.\" copyright notice and this permission notice appear in all copies.
13.\"
14.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21.\"
22.\" The original file was written by Dr. Stephen Henson <steve@openssl.org>.
23.\" Copyright (c) 2000, 2001, 2016 The OpenSSL Project.
24.\" All rights reserved.
25.\"
26.\" Redistribution and use in source and binary forms, with or without
27.\" modification, are permitted provided that the following conditions
28.\" are met:
29.\"
30.\" 1. Redistributions of source code must retain the above copyright
31.\" notice, this list of conditions and the following disclaimer.
32.\"
33.\" 2. Redistributions in binary form must reproduce the above copyright
34.\" notice, this list of conditions and the following disclaimer in
35.\" the documentation and/or other materials provided with the
36.\" distribution.
37.\"
38.\" 3. All advertising materials mentioning features or use of this
39.\" software must display the following acknowledgment:
40.\" "This product includes software developed by the OpenSSL Project
41.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
42.\"
43.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
44.\" endorse or promote products derived from this software without
45.\" prior written permission. For written permission, please contact
46.\" openssl-core@openssl.org.
47.\"
48.\" 5. Products derived from this software may not be called "OpenSSL"
49.\" nor may "OpenSSL" appear in their names without prior written
50.\" permission of the OpenSSL Project.
51.\"
52.\" 6. Redistributions of any form whatsoever must retain the following
53.\" acknowledgment:
54.\" "This product includes software developed by the OpenSSL Project
55.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
56.\"
57.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
58.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
59.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
60.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
61.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
62.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
63.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
64.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
66.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
67.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
68.\" OF THE POSSIBILITY OF SUCH DAMAGE.
69.\"
70.Dd $Mdocdate: August 31 2023 $
71.Dt EVP_CIPHER_CTX_CTRL 3
72.Os
73.Sh NAME
74.Nm EVP_CIPHER_CTX_ctrl ,
75.Nm EVP_CIPHER_CTX_set_padding ,
76.Nm EVP_CIPHER_CTX_set_key_length ,
77.Nm EVP_CIPHER_CTX_key_length ,
78.Nm EVP_CIPHER_key_length ,
79.Nm EVP_CIPHER_CTX_iv_length ,
80.Nm EVP_CIPHER_iv_length ,
81.Nm EVP_CIPHER_CTX_set_iv ,
82.Nm EVP_CIPHER_CTX_get_iv
83.Nd configure EVP cipher contexts
84.Sh SYNOPSIS
85.In openssl/evp.h
86.Ft int
87.Fo EVP_CIPHER_CTX_ctrl
88.Fa "EVP_CIPHER_CTX *ctx"
89.Fa "int type"
90.Fa "int arg"
91.Fa "void *ptr"
92.Fc
93.Ft int
94.Fo EVP_CIPHER_CTX_set_padding
95.Fa "EVP_CIPHER_CTX *x"
96.Fa "int padding"
97.Fc
98.Ft int
99.Fo EVP_CIPHER_CTX_set_key_length
100.Fa "EVP_CIPHER_CTX *x"
101.Fa "int keylen"
102.Fc
103.Ft int
104.Fo EVP_CIPHER_CTX_key_length
105.Fa "const EVP_CIPHER_CTX *ctx"
106.Fc
107.Ft int
108.Fo EVP_CIPHER_key_length
109.Fa "const EVP_CIPHER *e"
110.Fc
111.Ft int
112.Fo EVP_CIPHER_CTX_iv_length
113.Fa "const EVP_CIPHER_CTX *ctx"
114.Fc
115.Ft int
116.Fo EVP_CIPHER_iv_length
117.Fa "const EVP_CIPHER *e"
118.Fc
119.Ft int
120.Fo EVP_CIPHER_CTX_set_iv
121.Fa "EVP_CIPHER_CTX *ctx"
122.Fa "const unsigned char *iv"
123.Fa "size_t len"
124.Fc
125.Ft int
126.Fo EVP_CIPHER_CTX_get_iv
127.Fa "const EVP_CIPHER_CTX *ctx"
128.Fa "unsigned char *iv"
129.Fa "size_t len"
130.Fc
131.Sh DESCRIPTION
132.Fn EVP_CIPHER_CTX_ctrl
133allows various cipher specific parameters to be determined and set.
134Currently only the RC2 effective key length can be set.
135.Pp
136.Fn EVP_CIPHER_CTX_set_padding
137enables or disables padding.
138This function should be called after the context is set up for
139encryption or decryption with
140.Xr EVP_EncryptInit_ex 3 ,
141.Xr EVP_DecryptInit_ex 3 ,
142or
143.Xr EVP_CipherInit_ex 3 .
144By default encryption operations are padded using standard block padding
145and the padding is checked and removed when decrypting.
146If the
147.Fa padding
148parameter is zero, then no padding is performed, the total amount of data
149encrypted or decrypted must then be a multiple of the block size or an
150error will occur.
151.Pp
152.Fn EVP_CIPHER_CTX_set_key_length
153sets the key length of the cipher ctx.
154If the cipher is a fixed length cipher, then attempting to set the key
155length to any value other than the fixed value is an error.
156.Pp
157.Fn EVP_CIPHER_CTX_key_length
158and
159.Fn EVP_CIPHER_key_length
160return the key length of a cipher when passed an
161.Vt EVP_CIPHER_CTX
162or
163.Vt EVP_CIPHER
164structure.
165The constant
166.Dv EVP_MAX_KEY_LENGTH
167is the maximum key length for all ciphers.
168Note: although
169.Fn EVP_CIPHER_key_length
170is fixed for a given cipher, the value of
171.Fn EVP_CIPHER_CTX_key_length
172may be different for variable key length ciphers.
173.Pp
174.Fn EVP_CIPHER_CTX_iv_length
175and
176.Fn EVP_CIPHER_iv_length
177return the IV length of a cipher when passed an
178.Vt EVP_CIPHER_CTX
179or
180.Vt EVP_CIPHER .
181It will return zero if the cipher does not use an IV.
182The constant
183.Dv EVP_MAX_IV_LENGTH
184is the maximum IV length for all ciphers.
185.Pp
186.Fn EVP_CIPHER_CTX_set_iv
187and
188.Fn EVP_CIPHER_CTX_get_iv
189set and retrieve the IV for an
190.Vt EVP_CIPHER_CTX ,
191respectively.
192In both cases, the specified IV length must exactly equal the expected
193IV length for the context as returned by
194.Fn EVP_CIPHER_CTX_iv_length .
195.Sh RETURN VALUES
196.Fn EVP_CIPHER_CTX_ctrl
197usually returns 1 for success, 0 for failure, or \-1 if the
198.Fa type
199is not supported by the
200.Fa ctx ,
201but there may be exceptions for some
202.Fa type
203arguments.
204.Pp
205.Fn EVP_CIPHER_CTX_set_padding
206always returns 1.
207.Pp
208.Fn EVP_CIPHER_CTX_set_key_length ,
209.Fn EVP_CIPHER_CTX_set_iv ,
210and
211.Fn EVP_CIPHER_CTX_get_iv
212return 1 for success or 0 for failure.
213.Pp
214.Fn EVP_CIPHER_CTX_key_length
215and
216.Fn EVP_CIPHER_key_length
217return the key length.
218.Pp
219.Fn EVP_CIPHER_CTX_iv_length
220and
221.Fn EVP_CIPHER_iv_length
222return the IV length or zero if the cipher does not use an IV.
223.Sh SEE ALSO
224.Xr evp 3 ,
225.Xr EVP_CIPHER_nid 3 ,
226.Xr EVP_EncryptInit 3
227.Sh HISTORY
228.Fn EVP_CIPHER_CTX_key_length ,
229.Fn EVP_CIPHER_key_length ,
230.Fn EVP_CIPHER_CTX_iv_length ,
231and
232.Fn EVP_CIPHER_iv_length
233first appeared in SSLeay 0.6.5 and have been available since
234.Ox 2.4 .
235.Pp
236.Fn EVP_CIPHER_CTX_ctrl
237and
238.Fn EVP_CIPHER_CTX_set_key_length
239first appeared in OpenSSL 0.9.6 and have been available since
240.Ox 2.9 .
241.Pp
242.Fn EVP_CIPHER_CTX_set_padding
243first appeared in OpenSSL 0.9.7 and has been available since
244.Ox 3.2 .
245.Pp
246.Fn EVP_CIPHER_CTX_set_iv
247and
248.Fn EVP_CIPHER_CTX_get_iv
249first appeared in LibreSSL 2.8.1 and have been available since
250.Ox 6.4 .
251.Sh BUGS
252.Dv EVP_MAX_KEY_LENGTH
253and
254.Dv EVP_MAX_IV_LENGTH
255only refer to the internal ciphers with default key lengths.
256If custom ciphers exceed these values, the results are unpredictable.
257This is because it has become standard practice to define a generic key
258as a fixed unsigned char array containing
259.Dv EVP_MAX_KEY_LENGTH
260bytes.
diff --git a/src/lib/libcrypto/man/EVP_CIPHER_CTX_set_flags.3 b/src/lib/libcrypto/man/EVP_CIPHER_CTX_set_flags.3
new file mode 100644
index 0000000000..a8e32cdc55
--- /dev/null
+++ b/src/lib/libcrypto/man/EVP_CIPHER_CTX_set_flags.3
@@ -0,0 +1,228 @@
1.\" $OpenBSD: EVP_CIPHER_CTX_set_flags.3,v 1.1 2023/08/31 17:27:41 schwarze Exp $
2.\" full merge up to: OpenSSL 5211e094 Nov 11 14:39:11 2014 -0800
3.\"
4.\" This file is a derived work.
5.\" The changes are covered by the following Copyright and license:
6.\"
7.\" Copyright (c) 2019 Ingo Schwarze <schwarze@openbsd.org>
8.\"
9.\" 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.\" copyright notice and this permission notice appear in all copies.
12.\"
13.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20.\"
21.\" The original file was written by Dr. Stephen Henson <steve@openssl.org>
22.\" and Patrick Steuer <patrick.steuer@de.ibm.com>.
23.\" Copyright (c) 2000, 2017 The OpenSSL Project.
24.\" All rights reserved.
25.\"
26.\" Redistribution and use in source and binary forms, with or without
27.\" modification, are permitted provided that the following conditions
28.\" are met:
29.\"
30.\" 1. Redistributions of source code must retain the above copyright
31.\" notice, this list of conditions and the following disclaimer.
32.\"
33.\" 2. Redistributions in binary form must reproduce the above copyright
34.\" notice, this list of conditions and the following disclaimer in
35.\" the documentation and/or other materials provided with the
36.\" distribution.
37.\"
38.\" 3. All advertising materials mentioning features or use of this
39.\" software must display the following acknowledgment:
40.\" "This product includes software developed by the OpenSSL Project
41.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
42.\"
43.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
44.\" endorse or promote products derived from this software without
45.\" prior written permission. For written permission, please contact
46.\" openssl-core@openssl.org.
47.\"
48.\" 5. Products derived from this software may not be called "OpenSSL"
49.\" nor may "OpenSSL" appear in their names without prior written
50.\" permission of the OpenSSL Project.
51.\"
52.\" 6. Redistributions of any form whatsoever must retain the following
53.\" acknowledgment:
54.\" "This product includes software developed by the OpenSSL Project
55.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
56.\"
57.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
58.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
59.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
60.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
61.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
62.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
63.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
64.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
66.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
67.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
68.\" OF THE POSSIBILITY OF SUCH DAMAGE.
69.\"
70.Dd $Mdocdate: August 31 2023 $
71.Dt EVP_CIPHER_CTX_SET_FLAGS 3
72.Os
73.Sh NAME
74.Nm EVP_CIPHER_CTX_set_flags ,
75.Nm EVP_CIPHER_CTX_clear_flags ,
76.Nm EVP_CIPHER_CTX_test_flags ,
77.Nm EVP_CIPHER_CTX_rand_key ,
78.Nm EVP_CIPHER_param_to_asn1 ,
79.Nm EVP_CIPHER_asn1_to_param ,
80.Nm EVP_CIPHER_CTX_get_app_data ,
81.Nm EVP_CIPHER_CTX_set_app_data
82.Nd unusual EVP cipher context configuration
83.Sh SYNOPSIS
84.In openssl/evp.h
85.Ft void
86.Fo EVP_CIPHER_CTX_set_flags
87.Fa "EVP_CIPHER_CTX *ctx"
88.Fa "int flags"
89.Fc
90.Ft void
91.Fo EVP_CIPHER_CTX_clear_flags
92.Fa "EVP_CIPHER_CTX *ctx"
93.Fa "int flags"
94.Fc
95.Ft int
96.Fo EVP_CIPHER_CTX_test_flags
97.Fa "EVP_CIPHER_CTX *ctx"
98.Fa "int flags"
99.Fc
100.Ft int
101.Fo EVP_CIPHER_CTX_rand_key
102.Fa "EVP_CIPHER_CTX *ctx"
103.Fa "unsigned char *key"
104.Fc
105.Ft int
106.Fo EVP_CIPHER_param_to_asn1
107.Fa "EVP_CIPHER_CTX *c"
108.Fa "ASN1_TYPE *type"
109.Fc
110.Ft int
111.Fo EVP_CIPHER_asn1_to_param
112.Fa "EVP_CIPHER_CTX *c"
113.Fa "ASN1_TYPE *type"
114.Fc
115.Ft void *
116.Fo EVP_CIPHER_CTX_get_app_data
117.Fa "const EVP_CIPHER_CTX *ctx"
118.Fc
119.Ft void
120.Fo EVP_CIPHER_CTX_set_app_data
121.Fa "const EVP_CIPHER_CTX *ctx"
122.Fa "void *data"
123.Fc
124.Sh DESCRIPTION
125.Fn EVP_CIPHER_CTX_set_flags
126enables the given
127.Fa flags
128in
129.Fa ctx .
130.Fn EVP_CIPHER_CTX_clear_flags
131disables the given
132.Fa flags
133in
134.Fa ctx .
135.Fn EVP_CIPHER_CTX_test_flags
136checks whether any of the given
137.Fa flags
138are currently set in
139.Fa ctx ,
140returning the subset of the
141.Fa flags
142that are set, or 0 if none of them are set.
143Currently, the only supported cipher context flag is
144.Dv EVP_CIPHER_CTX_FLAG_WRAP_ALLOW ;
145see
146.Xr EVP_aes_128_wrap 3
147for details.
148.Pp
149.Fn EVP_CIPHER_CTX_rand_key
150generates a random key of the appropriate length based on the cipher
151context.
152The
153.Vt EVP_CIPHER
154can provide its own random key generation routine to support keys
155of a specific form.
156The
157.Fa key
158argument must point to a buffer at least as big as the value returned by
159.Xr EVP_CIPHER_CTX_key_length 3 .
160.Pp
161.Fn EVP_CIPHER_param_to_asn1
162sets the ASN.1
163.Vt AlgorithmIdentifier
164parameter based on the passed cipher.
165This will typically include any parameters and an IV.
166The cipher IV (if any) must be set when this call is made.
167This call should be made before the cipher is actually "used" (before any
168.Xr EVP_EncryptUpdate 3
169or
170.Xr EVP_DecryptUpdate 3
171calls, for example).
172This function may fail if the cipher does not have any ASN.1 support.
173.Pp
174.Fn EVP_CIPHER_asn1_to_param
175sets the cipher parameters based on an ASN.1
176.Vt AlgorithmIdentifier
177parameter.
178The precise effect depends on the cipher.
179In the case of RC2, for example, it will set the IV and effective
180key length.
181This function should be called after the base cipher type is set but
182before the key is set.
183For example
184.Xr EVP_CipherInit 3
185will be called with the IV and key set to
186.Dv NULL ,
187.Fn EVP_CIPHER_asn1_to_param
188will be called and finally
189.Xr EVP_CipherInit 3
190again with all parameters except the key set to
191.Dv NULL .
192It is possible for this function to fail if the cipher does not
193have any ASN.1 support or the parameters cannot be set (for example
194the RC2 effective key length is not supported).
195.Sh RETURN VALUES
196.Fn EVP_CIPHER_CTX_rand_key
197return 1 for success or 0 for failure.
198.Pp
199.Fn EVP_CIPHER_param_to_asn1
200and
201.Fn EVP_CIPHER_asn1_to_param
202return greater than zero for success and zero or a negative number
203for failure.
204.Sh SEE ALSO
205.Xr evp 3 ,
206.Xr EVP_CIPHER_CTX_ctrl 3 ,
207.Xr EVP_CIPHER_CTX_get_cipher_data 3 ,
208.Xr EVP_CIPHER_nid 3 ,
209.Xr EVP_EncryptInit 3
210.Sh HISTORY
211.Fn EVP_CIPHER_CTX_set_app_data
212and
213.Fn EVP_CIPHER_CTX_get_app_data
214first appeared in SSLeay 0.8.0.
215.Fn EVP_CIPHER_param_to_asn1
216and
217.Fn EVP_CIPHER_asn1_to_param
218first appeared in SSLeay 0.9.0.
219These functions have been available since
220.Ox 2.4 .
221.Pp
222.Fn EVP_CIPHER_CTX_rand_key
223first appeared in OpenSSL 0.9.8 and has been available since
224.Ox 4.5 .
225.Sh BUGS
226The ASN.1 code is incomplete (and sometimes inaccurate).
227It has only been tested for certain common S/MIME ciphers
228(RC2, DES, triple DES) in CBC mode.
diff --git a/src/lib/libcrypto/man/EVP_CIPHER_nid.3 b/src/lib/libcrypto/man/EVP_CIPHER_nid.3
new file mode 100644
index 0000000000..3a3c42d0b4
--- /dev/null
+++ b/src/lib/libcrypto/man/EVP_CIPHER_nid.3
@@ -0,0 +1,215 @@
1.\" $OpenBSD: EVP_CIPHER_nid.3,v 1.1 2023/08/31 17:27:41 schwarze Exp $
2.\" full merge up to: OpenSSL 5211e094 Nov 11 14:39:11 2014 -0800
3.\"
4.\" This file is a derived work.
5.\" The changes are covered by the following Copyright and license:
6.\"
7.\" Copyright (c) 2018 Ingo Schwarze <schwarze@openbsd.org>
8.\"
9.\" 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.\" copyright notice and this permission notice appear in all copies.
12.\"
13.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20.\"
21.\" The original file was written by Dr. Stephen Henson <steve@openssl.org>.
22.\" Copyright (c) 2000 The OpenSSL Project. All rights reserved.
23.\"
24.\" Redistribution and use in source and binary forms, with or without
25.\" modification, are permitted provided that the following conditions
26.\" are met:
27.\"
28.\" 1. Redistributions of source code must retain the above copyright
29.\" notice, this list of conditions and the following disclaimer.
30.\"
31.\" 2. Redistributions in binary form must reproduce the above copyright
32.\" notice, this list of conditions and the following disclaimer in
33.\" the documentation and/or other materials provided with the
34.\" distribution.
35.\"
36.\" 3. All advertising materials mentioning features or use of this
37.\" software must display the following acknowledgment:
38.\" "This product includes software developed by the OpenSSL Project
39.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
40.\"
41.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
42.\" endorse or promote products derived from this software without
43.\" prior written permission. For written permission, please contact
44.\" openssl-core@openssl.org.
45.\"
46.\" 5. Products derived from this software may not be called "OpenSSL"
47.\" nor may "OpenSSL" appear in their names without prior written
48.\" permission of the OpenSSL Project.
49.\"
50.\" 6. Redistributions of any form whatsoever must retain the following
51.\" acknowledgment:
52.\" "This product includes software developed by the OpenSSL Project
53.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
54.\"
55.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
56.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
59.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
60.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
61.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
62.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
64.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
66.\" OF THE POSSIBILITY OF SUCH DAMAGE.
67.\"
68.Dd $Mdocdate: August 31 2023 $
69.Dt EVP_CIPHER_NID 3
70.Os
71.Sh NAME
72.Nm EVP_CIPHER_nid ,
73.Nm EVP_CIPHER_CTX_nid ,
74.Nm EVP_CIPHER_type ,
75.Nm EVP_CIPHER_CTX_type ,
76.Nm EVP_CIPHER_block_size ,
77.Nm EVP_CIPHER_CTX_block_size ,
78.Nm EVP_CIPHER_flags ,
79.Nm EVP_CIPHER_CTX_flags ,
80.Nm EVP_CIPHER_mode ,
81.Nm EVP_CIPHER_CTX_mode
82.Nd inspect EVP_CIPHER objects
83.Sh SYNOPSIS
84.In openssl/evp.h
85.Ft int
86.Fo EVP_CIPHER_nid
87.Fa "const EVP_CIPHER *e"
88.Fc
89.Ft int
90.Fo EVP_CIPHER_CTX_nid
91.Fa "const EVP_CIPHER_CTX *ctx"
92.Fc
93.Ft int
94.Fo EVP_CIPHER_type
95.Fa "const EVP_CIPHER *ctx"
96.Fc
97.Ft int
98.Fo EVP_CIPHER_CTX_type
99.Fa "const EVP_CIPHER_CTX *ctx"
100.Fc
101.Ft int
102.Fo EVP_CIPHER_block_size
103.Fa "const EVP_CIPHER *e"
104.Fc
105.Ft int
106.Fo EVP_CIPHER_CTX_block_size
107.Fa "const EVP_CIPHER_CTX *ctx"
108.Fc
109.Ft unsigned long
110.Fo EVP_CIPHER_flags
111.Fa "const EVP_CIPHER *e"
112.Fc
113.Ft unsigned long
114.Fo EVP_CIPHER_CTX_flags
115.Fa "const EVP_CIPHER_CTX *ctx"
116.Fc
117.Ft unsigned long
118.Fo EVP_CIPHER_mode
119.Fa "const EVP_CIPHER *e"
120.Fc
121.Ft unsigned long
122.Fo EVP_CIPHER_CTX_mode
123.Fa "const EVP_CIPHER_CTX *ctx"
124.Fc
125.Sh DESCRIPTION
126.Fn EVP_CIPHER_nid
127and
128.Fn EVP_CIPHER_CTX_nid
129return the NID of a cipher when passed an
130.Vt EVP_CIPHER
131or
132.Vt EVP_CIPHER_CTX
133structure.
134The actual NID value is an internal value which may not have a
135corresponding OBJECT IDENTIFIER.
136.Pp
137.Fn EVP_CIPHER_type
138and
139.Fn EVP_CIPHER_CTX_type
140return the type of the passed cipher or context.
141This "type" is the actual NID of the cipher OBJECT IDENTIFIER as such it
142ignores the cipher parameters and 40-bit RC2 and 128-bit RC2 have the
143same NID.
144If the cipher does not have an object identifier or does not
145have ASN.1 support, this function will return
146.Dv NID_undef .
147.Pp
148.Fn EVP_CIPHER_block_size
149and
150.Fn EVP_CIPHER_CTX_block_size
151return the block size of a cipher when passed an
152.Vt EVP_CIPHER
153or
154.Vt EVP_CIPHER_CTX
155structure.
156The constant
157.Dv EVP_MAX_BLOCK_LENGTH
158is also the maximum block length for all ciphers.
159.Pp
160.Fn EVP_CIPHER_mode
161and
162.Fn EVP_CIPHER_CTX_mode
163return the block cipher mode:
164.Dv EVP_CIPH_ECB_MODE ,
165.Dv EVP_CIPH_CBC_MODE ,
166.Dv EVP_CIPH_CFB_MODE ,
167.Dv EVP_CIPH_OFB_MODE ,
168.Dv EVP_CIPH_CTR_MODE ,
169or
170.Dv EVP_CIPH_XTS_MODE .
171If the cipher is a stream cipher then
172.Dv EVP_CIPH_STREAM_CIPHER
173is returned.
174.Sh RETURN VALUES
175.Fn EVP_CIPHER_nid
176and
177.Fn EVP_CIPHER_CTX_nid
178return a NID.
179.Pp
180.Fn EVP_CIPHER_type
181and
182.Fn EVP_CIPHER_CTX_type
183return the NID of the cipher's OBJECT IDENTIFIER or
184.Dv NID_undef
185if it has no defined OBJECT IDENTIFIER.
186.Pp
187.Fn EVP_CIPHER_block_size
188and
189.Fn EVP_CIPHER_CTX_block_size
190return the block size.
191.Sh SEE ALSO
192.Xr evp 3 ,
193.Xr EVP_CIPHER_CTX_ctrl 3 ,
194.Xr EVP_EncryptInit 3
195.Sh HISTORY
196.Fn EVP_CIPHER_type ,
197.Fn EVP_CIPHER_CTX_type ,
198.Fn EVP_CIPHER_block_size ,
199and
200.Fn EVP_CIPHER_CTX_block_size
201first appeared in SSLeay 0.6.5.
202.Fn EVP_CIPHER_nid
203and
204.Fn EVP_CIPHER_CTX_nid
205first appeared in SSLeay 0.8.0.
206All these functions have been available since
207.Ox 2.4 .
208.Pp
209.Fn EVP_CIPHER_flags ,
210.Fn EVP_CIPHER_CTX_flags ,
211.Fn EVP_CIPHER_mode ,
212and
213.Fn EVP_CIPHER_CTX_mode
214first appeared in OpenSSL 0.9.6 and have been available since
215.Ox 2.9 .
diff --git a/src/lib/libcrypto/man/EVP_EncryptInit.3 b/src/lib/libcrypto/man/EVP_EncryptInit.3
index b6d9080bea..ddec4e7e79 100644
--- a/src/lib/libcrypto/man/EVP_EncryptInit.3
+++ b/src/lib/libcrypto/man/EVP_EncryptInit.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: EVP_EncryptInit.3,v 1.47 2023/08/26 15:01:56 schwarze Exp $ 1.\" $OpenBSD: EVP_EncryptInit.3,v 1.48 2023/08/31 17:27:41 schwarze Exp $
2.\" full merge up to: OpenSSL 5211e094 Nov 11 14:39:11 2014 -0800 2.\" full merge up to: OpenSSL 5211e094 Nov 11 14:39:11 2014 -0800
3.\" EVP_bf_cbc.pod EVP_cast5_cbc.pod EVP_idea_cbc.pod EVP_rc2_cbc.pod 3.\" EVP_bf_cbc.pod EVP_cast5_cbc.pod EVP_idea_cbc.pod EVP_rc2_cbc.pod
4.\" 7c6d372a Nov 20 13:20:01 2018 +0000 4.\" 7c6d372a Nov 20 13:20:01 2018 +0000
@@ -69,7 +69,7 @@
69.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 69.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
70.\" OF THE POSSIBILITY OF SUCH DAMAGE. 70.\" OF THE POSSIBILITY OF SUCH DAMAGE.
71.\" 71.\"
72.Dd $Mdocdate: August 26 2023 $ 72.Dd $Mdocdate: August 31 2023 $
73.Dt EVP_ENCRYPTINIT 3 73.Dt EVP_ENCRYPTINIT 3
74.Os 74.Os
75.Sh NAME 75.Sh NAME
@@ -96,37 +96,10 @@
96.Nm EVP_CipherFinal , 96.Nm EVP_CipherFinal ,
97.Nm EVP_Cipher , 97.Nm EVP_Cipher ,
98.Nm EVP_CIPHER_CTX_encrypting , 98.Nm EVP_CIPHER_CTX_encrypting ,
99.Nm EVP_CIPHER_CTX_set_flags ,
100.Nm EVP_CIPHER_CTX_clear_flags ,
101.Nm EVP_CIPHER_CTX_test_flags ,
102.Nm EVP_CIPHER_CTX_set_padding ,
103.Nm EVP_CIPHER_CTX_set_key_length ,
104.Nm EVP_CIPHER_CTX_ctrl ,
105.Nm EVP_CIPHER_CTX_rand_key ,
106.Nm EVP_get_cipherbyname , 99.Nm EVP_get_cipherbyname ,
107.Nm EVP_get_cipherbynid , 100.Nm EVP_get_cipherbynid ,
108.Nm EVP_get_cipherbyobj , 101.Nm EVP_get_cipherbyobj ,
109.Nm EVP_CIPHER_nid ,
110.Nm EVP_CIPHER_block_size ,
111.Nm EVP_CIPHER_key_length ,
112.Nm EVP_CIPHER_iv_length ,
113.Nm EVP_CIPHER_flags ,
114.Nm EVP_CIPHER_mode ,
115.Nm EVP_CIPHER_type ,
116.Nm EVP_CIPHER_CTX_cipher , 102.Nm EVP_CIPHER_CTX_cipher ,
117.Nm EVP_CIPHER_CTX_nid ,
118.Nm EVP_CIPHER_CTX_block_size ,
119.Nm EVP_CIPHER_CTX_key_length ,
120.Nm EVP_CIPHER_CTX_iv_length ,
121.Nm EVP_CIPHER_CTX_get_iv ,
122.Nm EVP_CIPHER_CTX_set_iv ,
123.Nm EVP_CIPHER_CTX_get_app_data ,
124.Nm EVP_CIPHER_CTX_set_app_data ,
125.Nm EVP_CIPHER_CTX_type ,
126.Nm EVP_CIPHER_CTX_flags ,
127.Nm EVP_CIPHER_CTX_mode ,
128.Nm EVP_CIPHER_param_to_asn1 ,
129.Nm EVP_CIPHER_asn1_to_param ,
130.Nm EVP_enc_null , 103.Nm EVP_enc_null ,
131.Nm EVP_idea_cbc , 104.Nm EVP_idea_cbc ,
132.Nm EVP_idea_ecb , 105.Nm EVP_idea_ecb ,
@@ -294,43 +267,6 @@
294.Fo EVP_CIPHER_CTX_encrypting 267.Fo EVP_CIPHER_CTX_encrypting
295.Fa "const EVP_CIPHER_CTX *ctx" 268.Fa "const EVP_CIPHER_CTX *ctx"
296.Fc 269.Fc
297.Ft void
298.Fo EVP_CIPHER_CTX_set_flags
299.Fa "EVP_CIPHER_CTX *ctx"
300.Fa "int flags"
301.Fc
302.Ft void
303.Fo EVP_CIPHER_CTX_clear_flags
304.Fa "EVP_CIPHER_CTX *ctx"
305.Fa "int flags"
306.Fc
307.Ft int
308.Fo EVP_CIPHER_CTX_test_flags
309.Fa "EVP_CIPHER_CTX *ctx"
310.Fa "int flags"
311.Fc
312.Ft int
313.Fo EVP_CIPHER_CTX_set_padding
314.Fa "EVP_CIPHER_CTX *x"
315.Fa "int padding"
316.Fc
317.Ft int
318.Fo EVP_CIPHER_CTX_set_key_length
319.Fa "EVP_CIPHER_CTX *x"
320.Fa "int keylen"
321.Fc
322.Ft int
323.Fo EVP_CIPHER_CTX_ctrl
324.Fa "EVP_CIPHER_CTX *ctx"
325.Fa "int type"
326.Fa "int arg"
327.Fa "void *ptr"
328.Fc
329.Ft int
330.Fo EVP_CIPHER_CTX_rand_key
331.Fa "EVP_CIPHER_CTX *ctx"
332.Fa "unsigned char *key"
333.Fc
334.Ft const EVP_CIPHER * 270.Ft const EVP_CIPHER *
335.Fo EVP_get_cipherbyname 271.Fo EVP_get_cipherbyname
336.Fa "const char *name" 272.Fa "const char *name"
@@ -343,97 +279,10 @@
343.Fo EVP_get_cipherbyobj 279.Fo EVP_get_cipherbyobj
344.Fa "const ASN1_OBJECT *a" 280.Fa "const ASN1_OBJECT *a"
345.Fc 281.Fc
346.Ft int
347.Fo EVP_CIPHER_nid
348.Fa "const EVP_CIPHER *e"
349.Fc
350.Ft int
351.Fo EVP_CIPHER_block_size
352.Fa "const EVP_CIPHER *e"
353.Fc
354.Ft int
355.Fo EVP_CIPHER_key_length
356.Fa "const EVP_CIPHER *e"
357.Fc
358.Ft int
359.Fo EVP_CIPHER_iv_length
360.Fa "const EVP_CIPHER *e"
361.Fc
362.Ft unsigned long
363.Fo EVP_CIPHER_flags
364.Fa "const EVP_CIPHER *e"
365.Fc
366.Ft unsigned long
367.Fo EVP_CIPHER_mode
368.Fa "const EVP_CIPHER *e"
369.Fc
370.Ft int
371.Fo EVP_CIPHER_type
372.Fa "const EVP_CIPHER *ctx"
373.Fc
374.Ft const EVP_CIPHER * 282.Ft const EVP_CIPHER *
375.Fo EVP_CIPHER_CTX_cipher 283.Fo EVP_CIPHER_CTX_cipher
376.Fa "const EVP_CIPHER_CTX *ctx" 284.Fa "const EVP_CIPHER_CTX *ctx"
377.Fc 285.Fc
378.Ft int
379.Fo EVP_CIPHER_CTX_nid
380.Fa "const EVP_CIPHER_CTX *ctx"
381.Fc
382.Ft int
383.Fo EVP_CIPHER_CTX_block_size
384.Fa "const EVP_CIPHER_CTX *ctx"
385.Fc
386.Ft int
387.Fo EVP_CIPHER_CTX_key_length
388.Fa "const EVP_CIPHER_CTX *ctx"
389.Fc
390.Ft int
391.Fo EVP_CIPHER_CTX_iv_length
392.Fa "const EVP_CIPHER_CTX *ctx"
393.Fc
394.Ft int
395.Fo EVP_CIPHER_CTX_get_iv
396.Fa "const EVP_CIPHER_CTX *ctx"
397.Fa "unsigned char *iv"
398.Fa "size_t len"
399.Fc
400.Ft int
401.Fo EVP_CIPHER_CTX_set_iv
402.Fa "EVP_CIPHER_CTX *ctx"
403.Fa "const unsigned char *iv"
404.Fa "size_t len"
405.Fc
406.Ft void *
407.Fo EVP_CIPHER_CTX_get_app_data
408.Fa "const EVP_CIPHER_CTX *ctx"
409.Fc
410.Ft void
411.Fo EVP_CIPHER_CTX_set_app_data
412.Fa "const EVP_CIPHER_CTX *ctx"
413.Fa "void *data"
414.Fc
415.Ft int
416.Fo EVP_CIPHER_CTX_type
417.Fa "const EVP_CIPHER_CTX *ctx"
418.Fc
419.Ft unsigned long
420.Fo EVP_CIPHER_CTX_flags
421.Fa "const EVP_CIPHER_CTX *ctx"
422.Fc
423.Ft unsigned long
424.Fo EVP_CIPHER_CTX_mode
425.Fa "const EVP_CIPHER_CTX *ctx"
426.Fc
427.Ft int
428.Fo EVP_CIPHER_param_to_asn1
429.Fa "EVP_CIPHER_CTX *c"
430.Fa "ASN1_TYPE *type"
431.Fc
432.Ft int
433.Fo EVP_CIPHER_asn1_to_param
434.Fa "EVP_CIPHER_CTX *c"
435.Fa "ASN1_TYPE *type"
436.Fc
437.Sh DESCRIPTION 286.Sh DESCRIPTION
438The EVP cipher routines are a high level interface to certain symmetric 287The EVP cipher routines are a high level interface to certain symmetric
439ciphers. 288ciphers.
@@ -492,7 +341,7 @@ and
492objects used by 341objects used by
493.Fa in 342.Fa in
494and any application specific data set with 343and any application specific data set with
495.Fn EVP_CIPHER_CTX_set_app_data 344.Xr EVP_CIPHER_CTX_set_app_data 3
496are not copied and 345are not copied and
497.Fa out 346.Fa out
498will point to the same three objects. 347will point to the same three objects.
@@ -507,7 +356,7 @@ If the bit
507.Dv EVP_CIPH_CUSTOM_COPY 356.Dv EVP_CIPH_CUSTOM_COPY
508has been set with 357has been set with
509.Xr EVP_CIPHER_meth_set_flags 3 , 358.Xr EVP_CIPHER_meth_set_flags 3 ,
510.Fn EVP_CIPHER_CTX_ctrl 359.Xr EVP_CIPHER_CTX_ctrl 3
511is called at the end with arguments 360is called at the end with arguments
512.Fa in , 361.Fa in ,
513.Dv EVP_CTRL_COPY , 362.Dv EVP_CTRL_COPY ,
@@ -690,123 +539,6 @@ structure when passed a cipher name, a NID or an
690.Vt ASN1_OBJECT 539.Vt ASN1_OBJECT
691structure. 540structure.
692.Pp 541.Pp
693.Fn EVP_CIPHER_nid
694and
695.Fn EVP_CIPHER_CTX_nid
696return the NID of a cipher when passed an
697.Vt EVP_CIPHER
698or
699.Vt EVP_CIPHER_CTX
700structure.
701The actual NID value is an internal value which may not have a
702corresponding OBJECT IDENTIFIER.
703.Pp
704.Fn EVP_CIPHER_CTX_set_flags
705enables the given
706.Fa flags
707in
708.Fa ctx .
709.Fn EVP_CIPHER_CTX_clear_flags
710disables the given
711.Fa flags
712in
713.Fa ctx .
714.Fn EVP_CIPHER_CTX_test_flags
715checks whether any of the given
716.Fa flags
717are currently set in
718.Fa ctx ,
719returning the subset of the
720.Fa flags
721that are set, or 0 if none of them are set.
722Currently, the only supported cipher context flag is
723.Dv EVP_CIPHER_CTX_FLAG_WRAP_ALLOW ;
724see
725.Xr EVP_aes_128_wrap 3
726for details.
727.Pp
728.Fn EVP_CIPHER_CTX_set_padding
729enables or disables padding.
730This function should be called after the context is set up for
731encryption or decryption with
732.Fn EVP_EncryptInit_ex ,
733.Fn EVP_DecryptInit_ex ,
734or
735.Fn EVP_CipherInit_ex .
736By default encryption operations are padded using standard block padding
737and the padding is checked and removed when decrypting.
738If the
739.Fa padding
740parameter is zero, then no padding is performed, the total amount of data
741encrypted or decrypted must then be a multiple of the block size or an
742error will occur.
743.Pp
744.Fn EVP_CIPHER_key_length
745and
746.Fn EVP_CIPHER_CTX_key_length
747return the key length of a cipher when passed an
748.Vt EVP_CIPHER
749or
750.Vt EVP_CIPHER_CTX
751structure.
752The constant
753.Dv EVP_MAX_KEY_LENGTH
754is the maximum key length for all ciphers.
755Note: although
756.Fn EVP_CIPHER_key_length
757is fixed for a given cipher, the value of
758.Fn EVP_CIPHER_CTX_key_length
759may be different for variable key length ciphers.
760.Pp
761.Fn EVP_CIPHER_CTX_set_key_length
762sets the key length of the cipher ctx.
763If the cipher is a fixed length cipher, then attempting to set the key
764length to any value other than the fixed value is an error.
765.Pp
766.Fn EVP_CIPHER_iv_length
767and
768.Fn EVP_CIPHER_CTX_iv_length
769return the IV length of a cipher when passed an
770.Vt EVP_CIPHER
771or
772.Vt EVP_CIPHER_CTX .
773It will return zero if the cipher does not use an IV.
774The constant
775.Dv EVP_MAX_IV_LENGTH
776is the maximum IV length for all ciphers.
777.Pp
778.Fn EVP_CIPHER_CTX_get_iv
779and
780.Fn EVP_CIPHER_CTX_set_iv
781will respectively retrieve and set the IV for an
782.Vt EVP_CIPHER_CTX .
783In both cases, the specified IV length must exactly equal the expected
784IV length for the context as returned by
785.Fn EVP_CIPHER_CTX_iv_length .
786.Pp
787.Fn EVP_CIPHER_block_size
788and
789.Fn EVP_CIPHER_CTX_block_size
790return the block size of a cipher when passed an
791.Vt EVP_CIPHER
792or
793.Vt EVP_CIPHER_CTX
794structure.
795The constant
796.Dv EVP_MAX_BLOCK_LENGTH
797is also the maximum block length for all ciphers.
798.Pp
799.Fn EVP_CIPHER_type
800and
801.Fn EVP_CIPHER_CTX_type
802return the type of the passed cipher or context.
803This "type" is the actual NID of the cipher OBJECT IDENTIFIER as such it
804ignores the cipher parameters and 40-bit RC2 and 128-bit RC2 have the
805same NID.
806If the cipher does not have an object identifier or does not
807have ASN.1 support, this function will return
808.Dv NID_undef .
809.Pp
810.Fn EVP_CIPHER_CTX_cipher 542.Fn EVP_CIPHER_CTX_cipher
811returns the 543returns the
812.Vt EVP_CIPHER 544.Vt EVP_CIPHER
@@ -814,72 +546,6 @@ structure when passed an
814.Vt EVP_CIPHER_CTX 546.Vt EVP_CIPHER_CTX
815structure. 547structure.
816.Pp 548.Pp
817.Fn EVP_CIPHER_mode
818and
819.Fn EVP_CIPHER_CTX_mode
820return the block cipher mode:
821.Dv EVP_CIPH_ECB_MODE ,
822.Dv EVP_CIPH_CBC_MODE ,
823.Dv EVP_CIPH_CFB_MODE ,
824.Dv EVP_CIPH_OFB_MODE ,
825.Dv EVP_CIPH_CTR_MODE ,
826or
827.Dv EVP_CIPH_XTS_MODE .
828If the cipher is a stream cipher then
829.Dv EVP_CIPH_STREAM_CIPHER
830is returned.
831.Pp
832.Fn EVP_CIPHER_param_to_asn1
833sets the ASN.1
834.Vt AlgorithmIdentifier
835parameter based on the passed cipher.
836This will typically include any parameters and an IV.
837The cipher IV (if any) must be set when this call is made.
838This call should be made before the cipher is actually "used" (before any
839.Fn EVP_EncryptUpdate
840or
841.Fn EVP_DecryptUpdate
842calls, for example).
843This function may fail if the cipher does not have any ASN.1 support.
844.Pp
845.Fn EVP_CIPHER_asn1_to_param
846sets the cipher parameters based on an ASN.1
847.Vt AlgorithmIdentifier
848parameter.
849The precise effect depends on the cipher.
850In the case of RC2, for example, it will set the IV and effective
851key length.
852This function should be called after the base cipher type is set but
853before the key is set.
854For example
855.Fn EVP_CipherInit
856will be called with the IV and key set to
857.Dv NULL ,
858.Fn EVP_CIPHER_asn1_to_param
859will be called and finally
860.Fn EVP_CipherInit
861again with all parameters except the key set to
862.Dv NULL .
863It is possible for this function to fail if the cipher does not
864have any ASN.1 support or the parameters cannot be set (for example
865the RC2 effective key length is not supported).
866.Pp
867.Fn EVP_CIPHER_CTX_ctrl
868allows various cipher specific parameters to be determined and set.
869Currently only the RC2 effective key length can be set.
870.Pp
871.Fn EVP_CIPHER_CTX_rand_key
872generates a random key of the appropriate length based on the cipher
873context.
874The
875.Vt EVP_CIPHER
876can provide its own random key generation routine to support keys
877of a specific form.
878The
879.Fa key
880argument must point to a buffer at least as big as the value returned by
881.Fn EVP_CIPHER_CTX_key_length .
882.Pp
883Where possible the EVP interface to symmetric ciphers should be 549Where possible the EVP interface to symmetric ciphers should be
884used in preference to the low level interfaces. 550used in preference to the low level interfaces.
885This is because the code then becomes transparent to the cipher used and 551This is because the code then becomes transparent to the cipher used and
@@ -938,8 +604,6 @@ for failure.
938.Fn EVP_CIPHER_CTX_reset , 604.Fn EVP_CIPHER_CTX_reset ,
939.Fn EVP_CIPHER_CTX_cleanup , 605.Fn EVP_CIPHER_CTX_cleanup ,
940.Fn EVP_CIPHER_CTX_copy , 606.Fn EVP_CIPHER_CTX_copy ,
941.Fn EVP_CIPHER_CTX_get_iv ,
942.Fn EVP_CIPHER_CTX_set_iv ,
943.Fn EVP_EncryptInit_ex , 607.Fn EVP_EncryptInit_ex ,
944.Fn EVP_EncryptUpdate , 608.Fn EVP_EncryptUpdate ,
945.Fn EVP_EncryptFinal_ex , 609.Fn EVP_EncryptFinal_ex ,
@@ -955,10 +619,8 @@ for failure.
955.Fn EVP_DecryptFinal , 619.Fn EVP_DecryptFinal ,
956.Fn EVP_CipherInit , 620.Fn EVP_CipherInit ,
957.Fn EVP_CipherFinal , 621.Fn EVP_CipherFinal ,
958.Fn EVP_Cipher ,
959.Fn EVP_CIPHER_CTX_set_key_length ,
960and 622and
961.Fn EVP_CIPHER_CTX_rand_key 623.Fn EVP_Cipher
962return 1 for success or 0 for failure. 624return 1 for success or 0 for failure.
963.Pp 625.Pp
964.Fn EVP_CIPHER_CTX_encrypting 626.Fn EVP_CIPHER_CTX_encrypting
@@ -967,18 +629,6 @@ returns 1 if
967is initialized for encryption or 0 otherwise, in which case 629is initialized for encryption or 0 otherwise, in which case
968it may be uninitialized or initialized for decryption. 630it may be uninitialized or initialized for decryption.
969.Pp 631.Pp
970.Fn EVP_CIPHER_CTX_set_padding
971always returns 1.
972.Pp
973.Fn EVP_CIPHER_CTX_ctrl
974usually returns 1 for success, 0 for failure, or \-1 if the
975.Fa type
976is not supported by the
977.Fa ctx ,
978but there may be exceptions for some
979.Fa type
980arguments.
981.Pp
982.Fn EVP_get_cipherbyname , 632.Fn EVP_get_cipherbyname ,
983.Fn EVP_get_cipherbynid , 633.Fn EVP_get_cipherbynid ,
984and 634and
@@ -989,43 +639,10 @@ structure or
989.Dv NULL 639.Dv NULL
990on error. 640on error.
991.Pp 641.Pp
992.Fn EVP_CIPHER_nid
993and
994.Fn EVP_CIPHER_CTX_nid
995return a NID.
996.Pp
997.Fn EVP_CIPHER_block_size
998and
999.Fn EVP_CIPHER_CTX_block_size
1000return the block size.
1001.Pp
1002.Fn EVP_CIPHER_key_length
1003and
1004.Fn EVP_CIPHER_CTX_key_length
1005return the key length.
1006.Pp
1007.Fn EVP_CIPHER_iv_length
1008and
1009.Fn EVP_CIPHER_CTX_iv_length
1010return the IV length or zero if the cipher does not use an IV.
1011.Pp
1012.Fn EVP_CIPHER_type
1013and
1014.Fn EVP_CIPHER_CTX_type
1015return the NID of the cipher's OBJECT IDENTIFIER or
1016.Dv NID_undef
1017if it has no defined OBJECT IDENTIFIER.
1018.Pp
1019.Fn EVP_CIPHER_CTX_cipher 642.Fn EVP_CIPHER_CTX_cipher
1020returns an 643returns an
1021.Vt EVP_CIPHER 644.Vt EVP_CIPHER
1022structure. 645structure.
1023.Pp
1024.Fn EVP_CIPHER_param_to_asn1
1025and
1026.Fn EVP_CIPHER_asn1_to_param
1027return greater than zero for success and zero or a negative number
1028for failure.
1029.Sh CIPHER LISTING 646.Sh CIPHER LISTING
1030All algorithms have a fixed key length unless otherwise stated. 647All algorithms have a fixed key length unless otherwise stated.
1031.Bl -tag -width Ds 648.Bl -tag -width Ds
@@ -1064,9 +681,9 @@ RC2 algorithm in CBC mode with a default key length and effective key
1064length of 40 and 64 bits. 681length of 40 and 64 bits.
1065These are obsolete and new code should use 682These are obsolete and new code should use
1066.Fn EVP_rc2_cbc , 683.Fn EVP_rc2_cbc ,
1067.Fn EVP_CIPHER_CTX_set_key_length , 684.Xr EVP_CIPHER_CTX_set_key_length 3 ,
1068and 685and
1069.Fn EVP_CIPHER_CTX_ctrl 686.Xr EVP_CIPHER_CTX_ctrl 3
1070to set the key length and effective key length. 687to set the key length and effective key length.
1071.It Xo 688.It Xo
1072.Fn EVP_bf_cbc , 689.Fn EVP_bf_cbc ,
@@ -1310,7 +927,10 @@ do_crypt(FILE *in, FILE *out, int do_encrypt)
1310.Xr EVP_aes_128_cbc 3 , 927.Xr EVP_aes_128_cbc 3 ,
1311.Xr EVP_camellia_128_cbc 3 , 928.Xr EVP_camellia_128_cbc 3 ,
1312.Xr EVP_chacha20 3 , 929.Xr EVP_chacha20 3 ,
930.Xr EVP_CIPHER_CTX_ctrl 3 ,
1313.Xr EVP_CIPHER_CTX_get_cipher_data 3 , 931.Xr EVP_CIPHER_CTX_get_cipher_data 3 ,
932.Xr EVP_CIPHER_CTX_set_flags 3 ,
933.Xr EVP_CIPHER_nid 3 ,
1314.Xr EVP_des_cbc 3 , 934.Xr EVP_des_cbc 3 ,
1315.Xr EVP_OpenInit 3 , 935.Xr EVP_OpenInit 3 ,
1316.Xr EVP_rc4 3 , 936.Xr EVP_rc4 3 ,
@@ -1339,16 +959,7 @@ first appeared in SSLeay 0.5.1.
1339and 959and
1340.Fn EVP_rc2_ofb 960.Fn EVP_rc2_ofb
1341first appeared in SSLeay 0.5.2. 961first appeared in SSLeay 0.5.2.
1342.Fn EVP_Cipher , 962.Fn EVP_Cipher
1343.Fn EVP_CIPHER_block_size ,
1344.Fn EVP_CIPHER_key_length ,
1345.Fn EVP_CIPHER_iv_length ,
1346.Fn EVP_CIPHER_type ,
1347.Fn EVP_CIPHER_CTX_block_size ,
1348.Fn EVP_CIPHER_CTX_key_length ,
1349.Fn EVP_CIPHER_CTX_iv_length ,
1350and
1351.Fn EVP_CIPHER_CTX_type
1352first appeared in SSLeay 0.6.5. 963first appeared in SSLeay 0.6.5.
1353.Fn EVP_bf_cbc , 964.Fn EVP_bf_cbc ,
1354.Fn EVP_bf_ecb , 965.Fn EVP_bf_ecb ,
@@ -1358,20 +969,13 @@ and
1358first appeared in SSLeay 0.6.6. 969first appeared in SSLeay 0.6.6.
1359.Fn EVP_CIPHER_CTX_cleanup , 970.Fn EVP_CIPHER_CTX_cleanup ,
1360.Fn EVP_get_cipherbyobj , 971.Fn EVP_get_cipherbyobj ,
1361.Fn EVP_CIPHER_nid ,
1362.Fn EVP_CIPHER_CTX_cipher , 972.Fn EVP_CIPHER_CTX_cipher ,
1363.Fn EVP_CIPHER_CTX_nid ,
1364.Fn EVP_CIPHER_CTX_get_app_data ,
1365.Fn EVP_CIPHER_CTX_set_app_data ,
1366and 973and
1367.Fn EVP_enc_null 974.Fn EVP_enc_null
1368first appeared in SSLeay 0.8.0. 975first appeared in SSLeay 0.8.0.
1369.Fn EVP_get_cipherbynid 976.Fn EVP_get_cipherbynid
1370first appeared in SSLeay 0.8.1. 977first appeared in SSLeay 0.8.1.
1371.Fn EVP_CIPHER_CTX_init , 978.Fn EVP_CIPHER_CTX_init
1372.Fn EVP_CIPHER_param_to_asn1 ,
1373and
1374.Fn EVP_CIPHER_asn1_to_param
1375first appeared in SSLeay 0.9.0. 979first appeared in SSLeay 0.9.0.
1376All these functions have been available since 980All these functions have been available since
1377.Ox 2.4 . 981.Ox 2.4 .
@@ -1379,30 +983,16 @@ All these functions have been available since
1379.Fn EVP_rc2_40_cbc 983.Fn EVP_rc2_40_cbc
1380and 984and
1381.Fn EVP_rc2_64_cbc 985.Fn EVP_rc2_64_cbc
1382first appeared in SSL_eay 0.9.1. 986first appeared in SSLeay 0.9.1 and have been available since
1383.Fn EVP_CIPHER_CTX_type
1384first appeared in OpenSSL 0.9.3.
1385These functions have been available since
1386.Ox 2.6 . 987.Ox 2.6 .
1387.Pp 988.Pp
1388.Fn EVP_CIPHER_CTX_set_key_length ,
1389.Fn EVP_CIPHER_CTX_ctrl ,
1390.Fn EVP_CIPHER_flags ,
1391.Fn EVP_CIPHER_mode ,
1392.Fn EVP_CIPHER_CTX_flags ,
1393and
1394.Fn EVP_CIPHER_CTX_mode
1395first appeared in OpenSSL 0.9.6 and have been available since
1396.Ox 2.9 .
1397.Pp
1398.Fn EVP_EncryptInit_ex , 989.Fn EVP_EncryptInit_ex ,
1399.Fn EVP_EncryptFinal_ex , 990.Fn EVP_EncryptFinal_ex ,
1400.Fn EVP_DecryptInit_ex , 991.Fn EVP_DecryptInit_ex ,
1401.Fn EVP_DecryptFinal_ex , 992.Fn EVP_DecryptFinal_ex ,
1402.Fn EVP_CipherInit_ex , 993.Fn EVP_CipherInit_ex ,
1403.Fn EVP_CipherFinal_ex ,
1404and 994and
1405.Fn EVP_CIPHER_CTX_set_padding 995.Fn EVP_CipherFinal_ex
1406first appeared in OpenSSL 0.9.7 and have been available since 996first appeared in OpenSSL 0.9.7 and have been available since
1407.Ox 3.2 . 997.Ox 3.2 .
1408.Pp 998.Pp
@@ -1414,13 +1004,10 @@ and
1414first appeared in OpenSSL 0.9.7e and have been available since 1004first appeared in OpenSSL 0.9.7e and have been available since
1415.Ox 3.8 . 1005.Ox 3.8 .
1416.Pp 1006.Pp
1417.Fn EVP_CIPHER_CTX_rand_key
1418first appeared in OpenSSL 0.9.8.
1419.Fn EVP_CIPHER_CTX_new 1007.Fn EVP_CIPHER_CTX_new
1420and 1008and
1421.Fn EVP_CIPHER_CTX_free 1009.Fn EVP_CIPHER_CTX_free
1422first appeared in OpenSSL 0.9.8b. 1010first appeared in OpenSSL 0.9.8b and have been available since
1423These functions have been available since
1424.Ox 4.5 . 1011.Ox 4.5 .
1425.Pp 1012.Pp
1426.Fn EVP_CIPHER_CTX_copy 1013.Fn EVP_CIPHER_CTX_copy
@@ -1435,27 +1022,7 @@ first appeared in OpenSSL 1.1.0 and has been available since
1435.Fn EVP_CIPHER_CTX_encrypting 1022.Fn EVP_CIPHER_CTX_encrypting
1436first appeared in OpenSSL 1.1.0 and has been available since 1023first appeared in OpenSSL 1.1.0 and has been available since
1437.Ox 6.4 . 1024.Ox 6.4 .
1438.Pp
1439.Fn EVP_CIPHER_CTX_get_iv
1440and
1441.Fn EVP_CIPHER_CTX_set_iv
1442first appeared in LibreSSL 2.8.1 and have been available since
1443.Ox 6.4 .
1444.Sh BUGS 1025.Sh BUGS
1445.Dv EVP_MAX_KEY_LENGTH
1446and
1447.Dv EVP_MAX_IV_LENGTH
1448only refer to the internal ciphers with default key lengths.
1449If custom ciphers exceed these values, the results are unpredictable.
1450This is because it has become standard practice to define a generic key
1451as a fixed unsigned char array containing
1452.Dv EVP_MAX_KEY_LENGTH
1453bytes.
1454.Pp
1455The ASN.1 code is incomplete (and sometimes inaccurate).
1456It has only been tested for certain common S/MIME ciphers
1457(RC2, DES, triple DES) in CBC mode.
1458.Pp
1459.Fn EVP_CIPHER_CTX_copy 1026.Fn EVP_CIPHER_CTX_copy
1460may already have cleared the data in 1027may already have cleared the data in
1461.Fa out 1028.Fa out
diff --git a/src/lib/libcrypto/man/Makefile b/src/lib/libcrypto/man/Makefile
index 4052638e0e..654a4f02a2 100644
--- a/src/lib/libcrypto/man/Makefile
+++ b/src/lib/libcrypto/man/Makefile
@@ -1,4 +1,4 @@
1# $OpenBSD: Makefile,v 1.265 2023/08/30 00:58:57 tb Exp $ 1# $OpenBSD: Makefile,v 1.266 2023/08/31 17:27:41 schwarze Exp $
2 2
3.include <bsd.own.mk> 3.include <bsd.own.mk>
4 4
@@ -164,9 +164,12 @@ MAN= \
164 ESS_SIGNING_CERT_new.3 \ 164 ESS_SIGNING_CERT_new.3 \
165 EVP_AEAD_CTX_init.3 \ 165 EVP_AEAD_CTX_init.3 \
166 EVP_BytesToKey.3 \ 166 EVP_BytesToKey.3 \
167 EVP_CIPHER_CTX_ctrl.3 \
167 EVP_CIPHER_CTX_get_cipher_data.3 \ 168 EVP_CIPHER_CTX_get_cipher_data.3 \
169 EVP_CIPHER_CTX_set_flags.3 \
168 EVP_CIPHER_do_all.3 \ 170 EVP_CIPHER_do_all.3 \
169 EVP_CIPHER_meth_new.3 \ 171 EVP_CIPHER_meth_new.3 \
172 EVP_CIPHER_nid.3 \
170 EVP_DigestInit.3 \ 173 EVP_DigestInit.3 \
171 EVP_DigestSignInit.3 \ 174 EVP_DigestSignInit.3 \
172 EVP_DigestVerifyInit.3 \ 175 EVP_DigestVerifyInit.3 \
diff --git a/src/lib/libcrypto/man/evp.3 b/src/lib/libcrypto/man/evp.3
index 3b93d8ba64..d2b92ae6a5 100644
--- a/src/lib/libcrypto/man/evp.3
+++ b/src/lib/libcrypto/man/evp.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: evp.3,v 1.21 2023/08/30 00:58:57 tb Exp $ 1.\" $OpenBSD: evp.3,v 1.22 2023/08/31 17:27:41 schwarze Exp $
2.\" full merge up to: OpenSSL man7/evp 24a535ea Sep 22 13:14:20 2020 +0100 2.\" full merge up to: OpenSSL man7/evp 24a535ea Sep 22 13:14:20 2020 +0100
3.\" 3.\"
4.\" This file was written by Ulf Moeller <ulf@openssl.org>, 4.\" This file was written by Ulf Moeller <ulf@openssl.org>,
@@ -51,7 +51,7 @@
51.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 51.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
52.\" OF THE POSSIBILITY OF SUCH DAMAGE. 52.\" OF THE POSSIBILITY OF SUCH DAMAGE.
53.\" 53.\"
54.Dd $Mdocdate: August 30 2023 $ 54.Dd $Mdocdate: August 31 2023 $
55.Dt EVP 3 55.Dt EVP 3
56.Os 56.Os
57.Sh NAME 57.Sh NAME
@@ -199,9 +199,12 @@ operations are more efficient using the high-level interfaces.
199.Xr EVP_BytesToKey 3 , 199.Xr EVP_BytesToKey 3 ,
200.Xr EVP_camellia_128_cbc 3 , 200.Xr EVP_camellia_128_cbc 3 ,
201.Xr EVP_chacha20 3 , 201.Xr EVP_chacha20 3 ,
202.Xr EVP_CIPHER_CTX_ctrl 3 ,
202.Xr EVP_CIPHER_CTX_get_cipher_data 3 , 203.Xr EVP_CIPHER_CTX_get_cipher_data 3 ,
204.Xr EVP_CIPHER_CTX_set_flags 3 ,
203.Xr EVP_CIPHER_do_all 3 , 205.Xr EVP_CIPHER_do_all 3 ,
204.Xr EVP_CIPHER_meth_new 3 , 206.Xr EVP_CIPHER_meth_new 3 ,
207.Xr EVP_CIPHER_nid 3 ,
205.Xr EVP_des_cbc 3 , 208.Xr EVP_des_cbc 3 ,
206.Xr EVP_DigestInit 3 , 209.Xr EVP_DigestInit 3 ,
207.Xr EVP_DigestSignInit 3 , 210.Xr EVP_DigestSignInit 3 ,