summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2022-01-10 22:44:22 +0000
committertb <>2022-01-10 22:44:22 +0000
commit92a0a272516cf93a0613290a82dc2128d6a125cb (patch)
treeb1c3a4b790213ea7bb95314fbe5f1c219789e3b2
parent32562df385c7970c163af35228653a782ecf39bb (diff)
downloadopenbsd-92a0a272516cf93a0613290a82dc2128d6a125cb.tar.gz
openbsd-92a0a272516cf93a0613290a82dc2128d6a125cb.tar.bz2
openbsd-92a0a272516cf93a0613290a82dc2128d6a125cb.zip
Document EVP_AEAD_CTX_{new,free}() and adjust example code.
looks good to jsing
-rw-r--r--src/lib/libcrypto/man/EVP_AEAD_CTX_init.351
1 files changed, 45 insertions, 6 deletions
diff --git a/src/lib/libcrypto/man/EVP_AEAD_CTX_init.3 b/src/lib/libcrypto/man/EVP_AEAD_CTX_init.3
index 5c4def1740..b6e872be0b 100644
--- a/src/lib/libcrypto/man/EVP_AEAD_CTX_init.3
+++ b/src/lib/libcrypto/man/EVP_AEAD_CTX_init.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: EVP_AEAD_CTX_init.3,v 1.9 2019/06/06 01:06:58 schwarze Exp $ 1.\" $OpenBSD: EVP_AEAD_CTX_init.3,v 1.10 2022/01/10 22:44:22 tb Exp $
2.\" 2.\"
3.\" Copyright (c) 2014, Google Inc. 3.\" Copyright (c) 2014, Google Inc.
4.\" Parts of the text were written by Adam Langley and David Benjamin. 4.\" Parts of the text were written by Adam Langley and David Benjamin.
@@ -16,10 +16,12 @@
16.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18.\" 18.\"
19.Dd $Mdocdate: June 6 2019 $ 19.Dd $Mdocdate: January 10 2022 $
20.Dt EVP_AEAD_CTX_INIT 3 20.Dt EVP_AEAD_CTX_INIT 3
21.Os 21.Os
22.Sh NAME 22.Sh NAME
23.Nm EVP_AEAD_CTX_new ,
24.Nm EVP_AEAD_CTX_free ,
23.Nm EVP_AEAD_CTX_init , 25.Nm EVP_AEAD_CTX_init ,
24.Nm EVP_AEAD_CTX_cleanup , 26.Nm EVP_AEAD_CTX_cleanup ,
25.Nm EVP_AEAD_CTX_open , 27.Nm EVP_AEAD_CTX_open ,
@@ -35,6 +37,12 @@
35.Nd authenticated encryption with additional data 37.Nd authenticated encryption with additional data
36.Sh SYNOPSIS 38.Sh SYNOPSIS
37.In openssl/evp.h 39.In openssl/evp.h
40.Ft EVP_AEAD_CTX *
41.Fn EVP_AEAD_CTX_new void
42.Ft void
43.Fo EVP_AEAD_CTX_free
44.Fa "EVP_AEAD_CTX *ctx"
45.Fc
38.Ft int 46.Ft int
39.Fo EVP_AEAD_CTX_init 47.Fo EVP_AEAD_CTX_init
40.Fa "EVP_AEAD_CTX *ctx" 48.Fa "EVP_AEAD_CTX *ctx"
@@ -114,6 +122,19 @@ messages.
114Each message has a unique, per-message nonce and, optionally, additional 122Each message has a unique, per-message nonce and, optionally, additional
115data which is authenticated but not included in the output. 123data which is authenticated but not included in the output.
116.Pp 124.Pp
125.Fn EVP_AEAD_CTX_new
126allocates a new context for use with
127.Fn EVP_AEAD_CTX_init .
128It can be cleaned up for reuse with
129.Fn EVP_AEAD_CTX_cleanup
130and must be freed with
131.Fn EVP_AEAD_CTX_free .
132.Pp
133.Fn EVP_AEAD_CTX_free
134cleans up
135.Fa ctx
136and frees the space allocated to it.
137.Pp
117.Fn EVP_AEAD_CTX_init 138.Fn EVP_AEAD_CTX_init
118initializes the context 139initializes the context
119.Fa ctx 140.Fa ctx
@@ -131,6 +152,11 @@ A tag length of zero indicates the default tag length should be used.
131.Fn EVP_AEAD_CTX_cleanup 152.Fn EVP_AEAD_CTX_cleanup
132frees any data allocated for the context 153frees any data allocated for the context
133.Fa ctx . 154.Fa ctx .
155After
156.Fn EVP_AEAD_CTX_cleanup ,
157.Fa ctx
158is in the same state as after
159.Fn EVP_AEAD_CTX_new .
134.Pp 160.Pp
135.Fn EVP_AEAD_CTX_open 161.Fn EVP_AEAD_CTX_open
136authenticates the input 162authenticates the input
@@ -237,6 +263,12 @@ This is because the code then becomes transparent to the AEAD cipher
237used and much more flexible. 263used and much more flexible.
238It is also safer to use as it prevents common mistakes with the native APIs. 264It is also safer to use as it prevents common mistakes with the native APIs.
239.Sh RETURN VALUES 265.Sh RETURN VALUES
266.Fn EVP_AEAD_CTX_new
267returns the new
268.Vt EVP_AEAD_CTX
269object or
270.Dv NULL
271on failure.
240.Fn EVP_AEAD_CTX_init , 272.Fn EVP_AEAD_CTX_init ,
241.Fn EVP_AEAD_CTX_open , 273.Fn EVP_AEAD_CTX_open ,
242and 274and
@@ -263,16 +295,17 @@ Encrypt a string using ChaCha20-Poly1305:
263const EVP_AEAD *aead = EVP_aead_chacha20_poly1305(); 295const EVP_AEAD *aead = EVP_aead_chacha20_poly1305();
264static const unsigned char nonce[32] = {0}; 296static const unsigned char nonce[32] = {0};
265size_t buf_len, nonce_len; 297size_t buf_len, nonce_len;
266EVP_AEAD_CTX ctx; 298EVP_AEAD_CTX *ctx;
267 299
268EVP_AEAD_CTX_init(&ctx, aead, key32, EVP_AEAD_key_length(aead), 300ctx = EVP_AEAD_CTX_new();
301EVP_AEAD_CTX_init(ctx, aead, key32, EVP_AEAD_key_length(aead),
269 EVP_AEAD_DEFAULT_TAG_LENGTH, NULL); 302 EVP_AEAD_DEFAULT_TAG_LENGTH, NULL);
270nonce_len = EVP_AEAD_nonce_length(aead); 303nonce_len = EVP_AEAD_nonce_length(aead);
271 304
272EVP_AEAD_CTX_seal(&ctx, out, &out_len, BUFSIZE, nonce, 305EVP_AEAD_CTX_seal(ctx, out, &out_len, BUFSIZE, nonce,
273 nonce_len, in, in_len, NULL, 0); 306 nonce_len, in, in_len, NULL, 0);
274 307
275EVP_AEAD_CTX_cleanup(&ctx); 308EVP_AEAD_CTX_free(ctx);
276.Ed 309.Ed
277.Sh SEE ALSO 310.Sh SEE ALSO
278.Xr evp 3 , 311.Xr evp 3 ,
@@ -305,3 +338,9 @@ AEAD is based on the implementation by
305.An Adam Langley 338.An Adam Langley
306for Chromium/BoringSSL and first appeared in 339for Chromium/BoringSSL and first appeared in
307.Ox 5.6 . 340.Ox 5.6 .
341.Pp
342.Fn EVP_AEAD_CTX_new
343and
344.Fn EVP_AEAD_CTX_free
345first appeared in
346.Ox 7.1 .