Skip to content

Commit

Permalink
implement dupctx for aes_WRAP methods
Browse files Browse the repository at this point in the history
create a dupctx method for aes_WRAP implementations of all sizes

Fixes #21887

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #21933)

(cherry picked from commit 2c021e7)
  • Loading branch information
nhorman authored and t8m committed Sep 12, 2023
1 parent a982016 commit 819ae76
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions providers/implementations/ciphers/cipher_aes_wrp.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,26 @@ static void *aes_wrap_newctx(size_t kbits, size_t blkbits,
return wctx;
}

static void *aes_wrap_dupctx(void *wctx)
{
PROV_AES_WRAP_CTX *ctx = wctx;
PROV_AES_WRAP_CTX *dctx = wctx;

if (ctx == NULL)
return NULL;
dctx = OPENSSL_memdup(ctx, sizeof(*ctx));

if (dctx != NULL && dctx->base.tlsmac != NULL && dctx->base.alloced) {
dctx->base.tlsmac = OPENSSL_memdup(dctx->base.tlsmac,
dctx->base.tlsmacsize);
if (dctx->base.tlsmac == NULL) {
OPENSSL_free(dctx);
dctx = NULL;
}
}
return dctx;
}

static void aes_wrap_freectx(void *vctx)
{
PROV_AES_WRAP_CTX *wctx = (PROV_AES_WRAP_CTX *)vctx;
Expand Down Expand Up @@ -281,6 +301,7 @@ static int aes_wrap_set_ctx_params(void *vctx, const OSSL_PARAM params[])
{ OSSL_FUNC_CIPHER_UPDATE, (void (*)(void))aes_##mode##_cipher }, \
{ OSSL_FUNC_CIPHER_FINAL, (void (*)(void))aes_##mode##_final }, \
{ OSSL_FUNC_CIPHER_FREECTX, (void (*)(void))aes_##mode##_freectx }, \
{ OSSL_FUNC_CIPHER_DUPCTX, (void (*)(void))aes_##mode##_dupctx }, \
{ OSSL_FUNC_CIPHER_GET_PARAMS, \
(void (*)(void))aes_##kbits##_##fname##_get_params }, \
{ OSSL_FUNC_CIPHER_GETTABLE_PARAMS, \
Expand Down

0 comments on commit 819ae76

Please sign in to comment.