summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libcrypto/man/EVP_chacha20.3204
1 files changed, 185 insertions, 19 deletions
diff --git a/src/lib/libcrypto/man/EVP_chacha20.3 b/src/lib/libcrypto/man/EVP_chacha20.3
index 000ac88290..01193638b8 100644
--- a/src/lib/libcrypto/man/EVP_chacha20.3
+++ b/src/lib/libcrypto/man/EVP_chacha20.3
@@ -1,9 +1,25 @@
1.\" $OpenBSD: EVP_chacha20.3,v 1.1 2023/08/15 11:26:49 schwarze Exp $ 1.\" $OpenBSD: EVP_chacha20.3,v 1.2 2023/08/16 13:47:18 schwarze Exp $
2.\" full merge up to: OpenSSL 35fd9953 May 28 14:49:38 2019 +0200 2.\" full merge up to: OpenSSL 35fd9953 May 28 14:49:38 2019 +0200
3.\" 3.\"
4.\" This file was written by Ronald Tse <ronald.tse@ribose.com> 4.\" This file is a derived work.
5.\" and Matt Caswell <matt@openssl.org>. 5.\" The changes are covered by the following Copyright and license:
6.\" Copyright (c) 2017, 2019 The OpenSSL Project. All rights reserved. 6.\"
7.\" Copyright (c) 2023 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 Ronald Tse <ronald.tse@ribose.com>.
22.\" Copyright (c) 2017 The OpenSSL Project. All rights reserved.
7.\" 23.\"
8.\" Redistribution and use in source and binary forms, with or without 24.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions 25.\" modification, are permitted provided that the following conditions
@@ -49,7 +65,7 @@
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 65.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE. 66.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\" 67.\"
52.Dd $Mdocdate: August 15 2023 $ 68.Dd $Mdocdate: August 16 2023 $
53.Dt EVP_CHACHA20 3 69.Dt EVP_CHACHA20 3
54.Os 70.Os
55.Sh NAME 71.Sh NAME
@@ -65,29 +81,179 @@
65.Sh DESCRIPTION 81.Sh DESCRIPTION
66.Fn EVP_chacha20 82.Fn EVP_chacha20
67provides the ChaCha20 stream cipher in the EVP framework. 83provides the ChaCha20 stream cipher in the EVP framework.
68The key length is 256 bits, the IV is 128 bits long. 84.Xr EVP_EncryptInit_ex 3 ,
69The first 32 bits consists of a counter in little-endian order followed 85.Xr EVP_DecryptInit_ex 3 ,
70by a 96 bit nonce. 86and
71For example a nonce of: 87.Xr EVP_CipherInit_ex 3
72.Pp 88take a
73000000000000000000000002 89.Fa key
74.Pp 90argument of 32 bytes = 256 bits and an
75With an initial counter of 42 (2a in hex) would be expressed as: 91.Fa iv
76.Pp 92argument of 16 bytes = 128 bits, internally using
772a000000000000000000000000000002 93.Xr ChaCha_set_key 3
94and
95.Xr ChaCha_set_iv 3 .
96Due to the symmetry of the internal cipher state, interpreting the
97.Fa iv
98argument as a 4 byte counter followed by a 12 byte nonce
99or interpreting it as an 8 byte counter followed by an 8 byte nonce
100is functionally equivalent.
101.Xr EVP_EncryptUpdate 3 ,
102.Xr EVP_EncryptFinal_ex 3 ,
103.Xr EVP_DecryptUpdate 3 ,
104and
105.Xr EVP_DecryptFinal_ex 3
106internally use
107.Xr ChaCha 3
108to perform encryption and decryption.
109.Xr EVP_CIPHER_CTX_ctrl 3
110always fails for
111.Fa ctx
112objects created from
113.Fn EVP_chacha20 .
78.Pp 114.Pp
79.Fn EVP_chacha20_poly1305 115.Fn EVP_chacha20_poly1305
80provides authenticated encryption with ChaCha20-Poly1305. 116provides authenticated encryption with ChaCha20-Poly1305.
81Like 117.Xr EVP_EncryptInit_ex 3 ,
82.Fn EVP_chacha20 , 118.Xr EVP_DecryptInit_ex 3 ,
83the key is 256 bits and the IV is 96 bits. 119and
120.Xr EVP_CipherInit_ex 3
121take a
122.Fa key
123argument of 32 bytes = 256 bits and an
124.Fa iv
125argument of 12 bytes = 96 bits.
84This supports additional authenticated data (AAD) and produces a 128-bit 126This supports additional authenticated data (AAD) and produces a 128-bit
85authentication tag. 127authentication tag.
128.Pp
129The following
130.Fa type
131arguments are supported for
132.Xr EVP_CIPHER_CTX_ctrl 3 :
133.Bl -tag -width Ds
134.It Dv EVP_CTRL_AEAD_GET_TAG
135Copy the number of bytes indicated by the
136.Fa arg
137argument from the tag to the location indicated by the
138.Fa ptr
139argument;
140to be called after
141.Xr EVP_EncryptFinal_ex 3 .
142This control operation fails if the
143.Fa ctx
144is not configured for encryption or if
145.Fa arg
146is less than 1 or greater than 16.
147.It Dv EVP_CTRL_AEAD_SET_TAG
148Copy the number of bytes indicated by the
149.Fa arg
150argument from the location indicated by the
151.Fa ptr
152argument and designate them as the expected tag length and tag,
153causing subsequent
154.Xr EVP_DecryptFinal_ex 3
155to fail if the tag calculated during decryption does not match.
156It is strongly recommended to specify
157.Fa arg
158as exactly 16.
159Otherwise, only the initial part of the tag may be compared
160and mismatches near the end of the tag may get silently irgnored.
161This control operation fails if the
162.Fa ctx
163is configured for encryption or if
164.Fa arg
165is less than 1 or greater than 16.
166If the
167.Fa ptr
168argument is a
169.Dv NULL
170pointer, this control operation succeeds without having any effect.
171.It EVP_CTRL_AEAD_SET_IV_FIXED
172Set the initialization vector by reading the 12 bytes pointed to by the
173.Fa ptr
174argument, independently of
175.Xr EVP_EncryptInit_ex 3 ,
176.Xr EVP_DecryptInit_ex 3 ,
177and
178.Xr EVP_CipherInit_ex 3 .
179This control operation fails if the
180.Fa arg
181argument is not exactly 12.
182.It Dv EVP_CTRL_AEAD_SET_IVLEN
183Instruct subsequent
184.Xr EVP_EncryptInit_ex 3 ,
185.Xr EVP_DecryptInit_ex 3 ,
186or
187.Xr EVP_CipherInit_ex 3
188to expect an
189.Fa iv
190argument shorter than the default of 12 bytes; the
191.Fa arg
192argument specifies the number of bytes to be used.
193The initialization functions will only read
194the specified smaller number of bytes from
195.Fa iv
196and internally zero-pad them on the left.
197Using this is not recommended because it is likely more fragile
198and less often tested than the equivalent method of simply providing
199a full-sized
200.Fa iv .
201This control operation fails if
202.Fa arg
203is less than 1 or greater than 16.
204.It Dv EVP_CTRL_INIT
205Set the length of the initialization vector to the default value
206of 12 bytes and clear the Poly1305 internal state.
207The application program usually does not need to invoke this contol
208operation manually because it is automatically called internally by
209.Xr EVP_EncryptInit_ex 3 ,
210.Xr EVP_DecryptInit_ex 3 ,
211and
212.Xr EVP_CipherInit_ex 3 .
213.El
86.Sh RETURN VALUES 214.Sh RETURN VALUES
87These functions return return pointers to static 215.Fn EVP_chacha20
216and
217.Fn EVP_chacha20_poly1305
218return pointers to static
88.Vt EVP_CIPHER 219.Vt EVP_CIPHER
89objects that contain the implementations of the symmetric cipher. 220objects that contain the implementations of the symmetric cipher.
221.Pp
222If
223.Fa ctx
224was created from
225.Fn EVP_chacha20
226or
227.Fn EVP_chacha20_poly1305 ,
228.Xr EVP_CIPHER_CTX_ctrl 3
229returns 1 for success or 0 for failure.
90.Sh SEE ALSO 230.Sh SEE ALSO
231.Xr ChaCha 3 ,
91.Xr evp 3 , 232.Xr evp 3 ,
233.Xr EVP_aead_chacha20_poly1305 3 ,
92.Xr EVP_CIPHER_meth_new 3 , 234.Xr EVP_CIPHER_meth_new 3 ,
93.Xr EVP_EncryptInit 3 235.Xr EVP_EncryptInit 3
236.Sh STANDARDS
237.Rs
238.%A A. Langley
239.%A W. Chang
240.%D November 2013
241.%R draft-agl-tls-chacha20poly1305-04
242.%T ChaCha20 and Poly1305 based Cipher Suites for TLS
243.Re
244.Pp
245.Rs
246.%A Y. Nir
247.%A A. Langley
248.%D May 2015
249.%R RFC 7539
250.%T ChaCha20 and Poly1305 for IETF Protocols
251.Re
252.Sh HISTORY
253.Fn EVP_chacha20
254first appeared in
255.Ox 5.6 .
256.Pp
257.Fn EVP_chacha20_poly1305
258first appeared in OpenSSL 1.1.0 and has been available since
259.Ox 7.2 .