summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorreyk <>2015-10-14 07:41:28 +0000
committerreyk <>2015-10-14 07:41:28 +0000
commit9d97a73291fdf754ac433bb870b979ef8c5ff3c4 (patch)
tree7f4867395e575d1b4040494f072e867f05b550b7 /src
parent9e151aaca6e7363dac26dfe6ce30adf712fc7102 (diff)
downloadopenbsd-9d97a73291fdf754ac433bb870b979ef8c5ff3c4.tar.gz
openbsd-9d97a73291fdf754ac433bb870b979ef8c5ff3c4.tar.bz2
openbsd-9d97a73291fdf754ac433bb870b979ef8c5ff3c4.zip
Add EVP_AEAD_CTX_init(3) manpage to document the new(ish) AEAD API.
The "authenticated encryption with additional data" API is used for ciphers like AES-GCM or ChaCha20-Poly1305. The manpage is a beginning and certainly needs more work, especially improvements in the EXAMPLES section. Based on agl's source code comments. Converted from pod to mandoc by schwarze@ OK schwarze@ jsing@
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/doc/evp.pod4
-rw-r--r--src/lib/libcrypto/man/EVP_AEAD_CTX_init.3275
-rw-r--r--src/lib/libcrypto/man/Makefile3
-rw-r--r--src/lib/libssl/src/doc/crypto/evp.pod4
4 files changed, 285 insertions, 1 deletions
diff --git a/src/lib/libcrypto/doc/evp.pod b/src/lib/libcrypto/doc/evp.pod
index 57c761d01f..dfd96d3b98 100644
--- a/src/lib/libcrypto/doc/evp.pod
+++ b/src/lib/libcrypto/doc/evp.pod
@@ -25,6 +25,9 @@ functions.
25Symmetric encryption is available with the L<B<EVP_Encrypt>I<...>|EVP_EncryptInit(3)> 25Symmetric encryption is available with the L<B<EVP_Encrypt>I<...>|EVP_EncryptInit(3)>
26functions. The L<B<EVP_Digest>I<...>|EVP_DigestInit(3)> functions provide message digests. 26functions. The L<B<EVP_Digest>I<...>|EVP_DigestInit(3)> functions provide message digests.
27 27
28Authenticated encryption with additional data (AEAD) is available with
29the L<B<EVP_AEAD>I<...>|EVP_AEAD_CTX_init(3)> functions.
30
28The B<EVP_PKEY>I<...> functions provide a high level interface to 31The B<EVP_PKEY>I<...> functions provide a high level interface to
29asymmetric algorithms. To create a new EVP_PKEY see 32asymmetric algorithms. To create a new EVP_PKEY see
30L<EVP_PKEY_new(3)|EVP_PKEY_new(3)>. EVP_PKEYs can be associated 33L<EVP_PKEY_new(3)|EVP_PKEY_new(3)>. EVP_PKEYs can be associated
@@ -81,6 +84,7 @@ using the high level interface.
81 84
82L<EVP_DigestInit(3)|EVP_DigestInit(3)>, 85L<EVP_DigestInit(3)|EVP_DigestInit(3)>,
83L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>, 86L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>,
87L<EVP_AEAD_CTX_init(3)|EVP_AEAD_CTX_init(3)>,
84L<EVP_OpenInit(3)|EVP_OpenInit(3)>, 88L<EVP_OpenInit(3)|EVP_OpenInit(3)>,
85L<EVP_SealInit(3)|EVP_SealInit(3)>, 89L<EVP_SealInit(3)|EVP_SealInit(3)>,
86L<EVP_DigestSignInit(3)|EVP_DigestSignInit(3)>, 90L<EVP_DigestSignInit(3)|EVP_DigestSignInit(3)>,
diff --git a/src/lib/libcrypto/man/EVP_AEAD_CTX_init.3 b/src/lib/libcrypto/man/EVP_AEAD_CTX_init.3
new file mode 100644
index 0000000000..47531123b4
--- /dev/null
+++ b/src/lib/libcrypto/man/EVP_AEAD_CTX_init.3
@@ -0,0 +1,275 @@
1.\" $OpenBSD: EVP_AEAD_CTX_init.3,v 1.1 2015/10/14 07:41:28 reyk Exp $
2.\"
3.\" Copyright (c) 2014, Google Inc.
4.\" Parts of the text were written by Adam Langley and David Benjamin.
5.\" Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
6.\"
7.\" Permission to use, copy, modify, and/or distribute this software for any
8.\" purpose with or without fee is hereby granted, provided that the above
9.\" copyright notice and this permission notice appear in all copies.
10.\"
11.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18.\"
19.Dd $Mdocdate: October 14 2015 $
20.Dt EVP_AEAD_CTX_INIT 3
21.Os
22.Sh NAME
23.Nm EVP_AEAD_CTX_init ,
24.Nm EVP_AEAD_CTX_cleanup ,
25.Nm EVP_AEAD_CTX_open ,
26.Nm EVP_AEAD_CTX_seal ,
27.Nm EVP_AEAD_key_length ,
28.Nm EVP_AEAD_max_overhead ,
29.Nm EVP_AEAD_max_tag_len ,
30.Nm EVP_AEAD_nonce_length ,
31.Nm EVP_aead_aes_128_gcm ,
32.Nm EVP_aead_aes_256_gcm ,
33.Nm EVP_aead_chacha20_poly1305
34.Nd authenticated encryption with additional data
35.Sh SYNOPSIS
36.In openssl/evp.h
37.Ft int
38.Fo EVP_AEAD_CTX_init
39.Fa "EVP_AEAD_CTX *ctx"
40.Fa "const EVP_AEAD *aead"
41.Fa "const unsigned char *key"
42.Fa "size_t key_len"
43.Fa "size_t tag_len"
44.Fa "ENGINE *impl"
45.Fc
46.Ft void
47.Fo EVP_AEAD_CTX_cleanup
48.Fa "EVP_AEAD_CTX *ctx"
49.Fc
50.Ft int
51.Fo EVP_AEAD_CTX_open
52.Fa "const EVP_AEAD_CTX *ctx"
53.Fa "unsigned char *out"
54.Fa "size_t *out_len"
55.Fa "size_t max_out_len"
56.Fa "const unsigned char *nonce"
57.Fa "size_t nonce_len"
58.Fa "const unsigned char *in"
59.Fa "size_t in_len"
60.Fa "const unsigned char *ad"
61.Fa "size_t ad_len"
62.Fc
63.Ft int
64.Fo EVP_AEAD_CTX_seal
65.Fa "const EVP_AEAD_CTX *ctx"
66.Fa "unsigned char *out"
67.Fa "size_t *out_len"
68.Fa "size_t max_out_len"
69.Fa "const unsigned char *nonce"
70.Fa "size_t nonce_len"
71.Fa "const unsigned char *in"
72.Fa "size_t in_len"
73.Fa "const unsigned char *ad"
74.Fa "size_t ad_len"
75.Fc
76.Ft size_t
77.Fo EVP_AEAD_key_length
78.Fa "const EVP_AEAD *aead"
79.Fc
80.Ft size_t
81.Fo EVP_AEAD_max_overhead
82.Fa "const EVP_AEAD *aead"
83.Fc
84.Ft size_t
85.Fo EVP_AEAD_max_tag_len
86.Fa "const EVP_AEAD *aead"
87.Fc
88.Ft size_t
89.Fo EVP_AEAD_nonce_length
90.Fa "const EVP_AEAD *aead"
91.Fc
92.Ft const EVP_AEAD *
93.Fo EVP_aead_aes_128_gcm
94.Fa void
95.Fc
96.Ft const EVP_AEAD *
97.Fo EVP_aead_aes_256_gcm
98.Fa void
99.Fc
100.Ft const EVP_AEAD *
101.Fo EVP_aead_chacha20_poly1305
102.Fa void
103.Fc
104.Sh DESCRIPTION
105AEAD (Authenticated Encryption with Additional Data) couples
106confidentiality and integrity in a single primitive.
107AEAD algorithms take a key and can then seal and open individual
108messages.
109Each message has a unique, per-message nonce and, optionally, additional
110data which is authenticated but not included in the output.
111.Pp
112.Fn EVP_AEAD_CTX_init
113initializes the context
114.Fa ctx
115for the given AEAD algorithm
116.Fa aead .
117The
118.Fa impl argument must be
119.Dv NULL
120for the default implementation;
121other values are currently not supported.
122Authentication tags may be truncated by passing a tag length.
123A tag length of zero indicates the default tag length should be used.
124.Pp
125.Fn EVP_AEAD_CTX_cleanup
126frees any data allocated for the context
127.Fa ctx .
128.Pp
129.Fn EVP_AEAD_CTX_open
130authenticates the input
131.Fa in
132and optional additional data
133.Fa ad ,
134decrypting the input and writing it as output
135.Fa out .
136This function may be called (with the same
137.Vt EVP_AEAD_CTX )
138concurrently with itself or with
139.Fn EVP_AEAD_CTX_seal .
140At most the number of input bytes are written as output.
141In order to ensure success,
142.Fa max_out_len
143should be at least the same as the input length
144.Fa in_len .
145On successful return
146.Fa out_len
147is set to the actual number of bytes written.
148The length of the
149.Fa nonce
150specified with
151.Fa nonce_len
152must be equal to the result of EVP_AEAD_nonce_length for this AEAD.
153.Fn EVP_AEAD_CTX_open
154never results in partial output.
155If
156.Fa max_out_len
157is insufficient, zero will be returned and
158.Fa out_len
159will be set to zero.
160If the input and output are aliased then
161.Fa out
162must be <=
163.Fa in .
164.Pp
165.Fn EVP_AEAD_CTX_seal
166encrypts and authenticates the input and authenticates any additional
167data provided in
168.Fa ad ,
169the encrypted input and authentication tag being written as output
170.Fa out .
171This function may be called (with the same
172.Vt EVP_AEAD_CTX )
173concurrently with itself or with
174.Fn EVP_AEAD_CTX_open .
175At most
176.Fa max_out_len
177bytes are written as output and, in order to ensure success, this value
178should be the
179.Fa in_len
180plus the result of
181.Xr EVP_AEAD_overhead 3 .
182On successful return,
183.Fa out_len
184is set to the actual number of bytes written.
185The length of the
186.Fa nonce
187specified with
188.Fa nonce_len
189must be equal to the result of
190.Fn EVP_AEAD_nonce_length
191for this AEAD.
192.Fn EVP_AEAD_CTX_seal
193never results in a partial output.
194If
195.Fa max_out_len
196is insufficient, zero will be returned and
197.Fa out_len
198will be set to zero.
199If the input and output are aliased then
200.Fa out
201must be <=
202.Fa in .
203.Pp
204.Fn EVP_AEAD_key_length ,
205.Fn EVP_AEAD_max_overhead ,
206.Fn EVP_AEAD_max_tag_len ,
207and
208.Fn EVP_AEAD_nonce_length
209provide information about the AEAD algorithm
210.Fa aead .
211.Pp
212All cipher algorithms have a fixed key length unless otherwise stated.
213The following ciphers are available:
214.Bl -tag -width Ds -offset indent
215.It Fn EVP_aead_aes_128_gcm
216AES-128 in Galois Counter Mode.
217.It Fn EVP_aead_aes_256_gcm
218AES-256 in Galois Counter Mode.
219.It Fn EVP_aead_chacha20_poly1305
220ChaCha20 with a Poly1305 authenticator.
221.El
222.Pp
223Where possible the
224.Sy EVP_AEAD
225interface to AEAD ciphers should be used in preference to the older
226.Sy EVP
227variants or to the low level interfaces.
228This is because the code then becomes transparent to the AEAD cipher
229used and much more flexible,
230it is also safer to use as it prevents common mistakes with the native APIs.
231.Sh RETURN VALUES
232.Fn EVP_AEAD_CTX_init ,
233.Fn EVP_AEAD_CTX_open ,
234and
235.Fn EVP_AEAD_CTX_seal
236return 1 for success or zero for failure.
237.Pp
238.Fn EVP_AEAD_key_length
239returns the length of the key used for this AEAD.
240.Pp
241.Fn EVP_AEAD_max_overhead
242returns the maximum number of additional bytes added by the act of
243sealing data with the AEAD.
244.Pp
245.Fn EVP_AEAD_max_tag_len
246returns the maximum tag length when using this AEAD.
247This is the largest value that can be passed as a tag length to
248.Fn EVP_AEAD_CTX_init .
249.Pp
250.Fn EVP_AEAD_nonce_length
251returns the length of the per-message nonce.
252.Sh EXAMPLES
253Encrypt a string using ChaCha20-Poly1305:
254.Bd -literal
255.\" XXX
256const EVP_AEAD *aead = EVP_aead_chacha20_poly1305();
257static const unsigned char nonce[32] = {0};
258size_t buf_len, nonce_len;
259EVP_AEAD_CTX ctx;
260
261EVP_AEAD_CTX_init(&ctx, aead, key32, EVP_AEAD_key_length(aead),
262 EVP_AEAD_DEFAULT_TAG_LENGTH, NULL);
263nonce_len = EVP_AEAD_nonce_length(aead);
264
265EVP_AEAD_CTX_seal(&ctx, out, &out_len, BUFSIZE, nonce,
266 nonce_len, in, in_len, NULL, 0);
267
268EVP_AEAD_CTX_cleanup(&ctx);
269.Ed
270.Sh SEE ALSO
271.Xr evp 3
272.Sh HISTORY
273AEAD is based on the implementation by Adam Langley for
274Chromium/BoringSSL and first appeared in
275.Ox 5.6 .
diff --git a/src/lib/libcrypto/man/Makefile b/src/lib/libcrypto/man/Makefile
index 1ebde6fc16..d896f436bc 100644
--- a/src/lib/libcrypto/man/Makefile
+++ b/src/lib/libcrypto/man/Makefile
@@ -1,4 +1,4 @@
1# $OpenBSD: Makefile,v 1.24 2015/09/17 14:43:23 bcook Exp $ 1# $OpenBSD: Makefile,v 1.25 2015/10/14 07:41:28 reyk Exp $
2 2
3.include <bsd.own.mk> # for NOMAN 3.include <bsd.own.mk> # for NOMAN
4 4
@@ -52,6 +52,7 @@ MAN= \
52 BN_swap.3 \ 52 BN_swap.3 \
53 BN_zero.3 \ 53 BN_zero.3 \
54 BUF_MEM_new.3 \ 54 BUF_MEM_new.3 \
55 EVP_AEAD_CTX_init.3 \
55 56
56GENMAN= \ 57GENMAN= \
57 CONF_modules_free.3 \ 58 CONF_modules_free.3 \
diff --git a/src/lib/libssl/src/doc/crypto/evp.pod b/src/lib/libssl/src/doc/crypto/evp.pod
index 57c761d01f..dfd96d3b98 100644
--- a/src/lib/libssl/src/doc/crypto/evp.pod
+++ b/src/lib/libssl/src/doc/crypto/evp.pod
@@ -25,6 +25,9 @@ functions.
25Symmetric encryption is available with the L<B<EVP_Encrypt>I<...>|EVP_EncryptInit(3)> 25Symmetric encryption is available with the L<B<EVP_Encrypt>I<...>|EVP_EncryptInit(3)>
26functions. The L<B<EVP_Digest>I<...>|EVP_DigestInit(3)> functions provide message digests. 26functions. The L<B<EVP_Digest>I<...>|EVP_DigestInit(3)> functions provide message digests.
27 27
28Authenticated encryption with additional data (AEAD) is available with
29the L<B<EVP_AEAD>I<...>|EVP_AEAD_CTX_init(3)> functions.
30
28The B<EVP_PKEY>I<...> functions provide a high level interface to 31The B<EVP_PKEY>I<...> functions provide a high level interface to
29asymmetric algorithms. To create a new EVP_PKEY see 32asymmetric algorithms. To create a new EVP_PKEY see
30L<EVP_PKEY_new(3)|EVP_PKEY_new(3)>. EVP_PKEYs can be associated 33L<EVP_PKEY_new(3)|EVP_PKEY_new(3)>. EVP_PKEYs can be associated
@@ -81,6 +84,7 @@ using the high level interface.
81 84
82L<EVP_DigestInit(3)|EVP_DigestInit(3)>, 85L<EVP_DigestInit(3)|EVP_DigestInit(3)>,
83L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>, 86L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>,
87L<EVP_AEAD_CTX_init(3)|EVP_AEAD_CTX_init(3)>,
84L<EVP_OpenInit(3)|EVP_OpenInit(3)>, 88L<EVP_OpenInit(3)|EVP_OpenInit(3)>,
85L<EVP_SealInit(3)|EVP_SealInit(3)>, 89L<EVP_SealInit(3)|EVP_SealInit(3)>,
86L<EVP_DigestSignInit(3)|EVP_DigestSignInit(3)>, 90L<EVP_DigestSignInit(3)|EVP_DigestSignInit(3)>,