From: tb Date: Fri, 7 Jan 2022 21:58:17 +0000 (+0000) Subject: Prepare to provide EVP_AEAD_CTX_{new,free}() X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=5724b79519a09f4f6910a58c78522baf042b4513;p=openbsd Prepare to provide EVP_AEAD_CTX_{new,free}() ok jsing --- diff --git a/lib/libcrypto/evp/evp.h b/lib/libcrypto/evp/evp.h index aa0a9e77c9e..b5afa477da9 100644 --- a/lib/libcrypto/evp/evp.h +++ b/lib/libcrypto/evp/evp.h @@ -1,4 +1,4 @@ -/* $OpenBSD: evp.h,v 1.90 2021/12/24 12:55:04 tb Exp $ */ +/* $OpenBSD: evp.h,v 1.91 2022/01/07 21:58:17 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -1331,7 +1331,17 @@ typedef struct evp_aead_ctx_st { * should be used. */ #define EVP_AEAD_DEFAULT_TAG_LENGTH 0 -/* EVP_AEAD_init initializes the context for the given AEAD algorithm. +#if defined(LIBRESSL_CRYPTO_INTERANL) || defined(LIBRESSL_NEXT_API) +/* EVP_AEAD_CTX_new allocates a new context for use with EVP_AEAD_CTX_init. + * It can be cleaned up for reuse with EVP_AEAD_CTX_cleanup and must be freed + * with EVP_AEAD_CTX_free. */ +EVP_AEAD_CTX *EVP_AEAD_CTX_new(void); + +/* EVP_AEAD_CTX_free releases all memory owned by the context. */ +void EVP_AEAD_CTX_free(EVP_AEAD_CTX *ctx); +#endif + +/* EVP_AEAD_CTX_init initializes the context for the given AEAD algorithm. * The implementation argument may be NULL to choose the default implementation. * Authentication tags may be truncated by passing a tag length. A tag length * of zero indicates the default tag length should be used. */ diff --git a/lib/libcrypto/evp/evp_aead.c b/lib/libcrypto/evp/evp_aead.c index 40471b00226..93d523af7cf 100644 --- a/lib/libcrypto/evp/evp_aead.c +++ b/lib/libcrypto/evp/evp_aead.c @@ -1,4 +1,4 @@ -/* $OpenBSD: evp_aead.c,v 1.6 2017/01/29 17:49:23 beck Exp $ */ +/* $OpenBSD: evp_aead.c,v 1.7 2022/01/07 21:58:17 tb Exp $ */ /* * Copyright (c) 2014, Google Inc. * @@ -68,6 +68,22 @@ EVP_AEAD_CTX_cleanup(EVP_AEAD_CTX *ctx) ctx->aead = NULL; } +EVP_AEAD_CTX * +EVP_AEAD_CTX_new(void) +{ + return calloc(1, sizeof(EVP_AEAD_CTX)); +} + +void +EVP_AEAD_CTX_free(EVP_AEAD_CTX *ctx) +{ + if (ctx == NULL) + return; + + EVP_AEAD_CTX_cleanup(ctx); + free(ctx); +} + /* check_alias returns 0 if out points within the buffer determined by in * and in_len and 1 otherwise. *