diff options
author | tb <> | 2022-01-10 22:44:22 +0000 |
---|---|---|
committer | tb <> | 2022-01-10 22:44:22 +0000 |
commit | 92a0a272516cf93a0613290a82dc2128d6a125cb (patch) | |
tree | b1c3a4b790213ea7bb95314fbe5f1c219789e3b2 | |
parent | 32562df385c7970c163af35228653a782ecf39bb (diff) | |
download | openbsd-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.3 | 51 |
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. | |||
114 | Each message has a unique, per-message nonce and, optionally, additional | 122 | Each message has a unique, per-message nonce and, optionally, additional |
115 | data which is authenticated but not included in the output. | 123 | data which is authenticated but not included in the output. |
116 | .Pp | 124 | .Pp |
125 | .Fn EVP_AEAD_CTX_new | ||
126 | allocates a new context for use with | ||
127 | .Fn EVP_AEAD_CTX_init . | ||
128 | It can be cleaned up for reuse with | ||
129 | .Fn EVP_AEAD_CTX_cleanup | ||
130 | and must be freed with | ||
131 | .Fn EVP_AEAD_CTX_free . | ||
132 | .Pp | ||
133 | .Fn EVP_AEAD_CTX_free | ||
134 | cleans up | ||
135 | .Fa ctx | ||
136 | and frees the space allocated to it. | ||
137 | .Pp | ||
117 | .Fn EVP_AEAD_CTX_init | 138 | .Fn EVP_AEAD_CTX_init |
118 | initializes the context | 139 | initializes 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 |
132 | frees any data allocated for the context | 153 | frees any data allocated for the context |
133 | .Fa ctx . | 154 | .Fa ctx . |
155 | After | ||
156 | .Fn EVP_AEAD_CTX_cleanup , | ||
157 | .Fa ctx | ||
158 | is 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 |
136 | authenticates the input | 162 | authenticates the input |
@@ -237,6 +263,12 @@ This is because the code then becomes transparent to the AEAD cipher | |||
237 | used and much more flexible. | 263 | used and much more flexible. |
238 | It is also safer to use as it prevents common mistakes with the native APIs. | 264 | It 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 | ||
267 | returns the new | ||
268 | .Vt EVP_AEAD_CTX | ||
269 | object or | ||
270 | .Dv NULL | ||
271 | on 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 , |
242 | and | 274 | and |
@@ -263,16 +295,17 @@ Encrypt a string using ChaCha20-Poly1305: | |||
263 | const EVP_AEAD *aead = EVP_aead_chacha20_poly1305(); | 295 | const EVP_AEAD *aead = EVP_aead_chacha20_poly1305(); |
264 | static const unsigned char nonce[32] = {0}; | 296 | static const unsigned char nonce[32] = {0}; |
265 | size_t buf_len, nonce_len; | 297 | size_t buf_len, nonce_len; |
266 | EVP_AEAD_CTX ctx; | 298 | EVP_AEAD_CTX *ctx; |
267 | 299 | ||
268 | EVP_AEAD_CTX_init(&ctx, aead, key32, EVP_AEAD_key_length(aead), | 300 | ctx = EVP_AEAD_CTX_new(); |
301 | EVP_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); |
270 | nonce_len = EVP_AEAD_nonce_length(aead); | 303 | nonce_len = EVP_AEAD_nonce_length(aead); |
271 | 304 | ||
272 | EVP_AEAD_CTX_seal(&ctx, out, &out_len, BUFSIZE, nonce, | 305 | EVP_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 | ||
275 | EVP_AEAD_CTX_cleanup(&ctx); | 308 | EVP_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 |
306 | for Chromium/BoringSSL and first appeared in | 339 | for Chromium/BoringSSL and first appeared in |
307 | .Ox 5.6 . | 340 | .Ox 5.6 . |
341 | .Pp | ||
342 | .Fn EVP_AEAD_CTX_new | ||
343 | and | ||
344 | .Fn EVP_AEAD_CTX_free | ||
345 | first appeared in | ||
346 | .Ox 7.1 . | ||