Skip to content

Commit

Permalink
Add missing sm4_ccm_dupctx() and sm4_gcm_dupctx()
Browse files Browse the repository at this point in the history
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #23217)
  • Loading branch information
t8m committed Jan 8, 2024
1 parent 143a091 commit 5802de9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions providers/implementations/ciphers/cipher_sm4_ccm.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ static void *sm4_ccm_newctx(void *provctx, size_t keybits)
return ctx;
}

static void *sm4_ccm_dupctx(void *provctx)
{
PROV_SM4_CCM_CTX *ctx = provctx;
PROV_SM4_CCM_CTX *dctx = NULL;

if (ctx == NULL)
return NULL;

dctx = OPENSSL_memdup(ctx, sizeof(*ctx));
if (dctx != NULL && dctx->base.ccm_ctx.key != NULL)
dctx->base.ccm_ctx.key = &dctx->ks.ks;

return dctx;
}

static void sm4_ccm_freectx(void *vctx)
{
PROV_SM4_CCM_CTX *ctx = (PROV_SM4_CCM_CTX *)vctx;
Expand Down
15 changes: 15 additions & 0 deletions providers/implementations/ciphers/cipher_sm4_gcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ static void *sm4_gcm_newctx(void *provctx, size_t keybits)
return ctx;
}

static void *sm4_gcm_dupctx(void *provctx)
{
PROV_SM4_GCM_CTX *ctx = provctx;
PROV_SM4_GCM_CTX *dctx = NULL;

if (ctx == NULL)
return NULL;

dctx = OPENSSL_memdup(ctx, sizeof(*ctx));
if (dctx != NULL && dctx->base.gcm.key != NULL)
dctx->base.gcm.key = &dctx->ks.ks;

return dctx;
}

static void sm4_gcm_freectx(void *vctx)
{
PROV_SM4_GCM_CTX *ctx = (PROV_SM4_GCM_CTX *)vctx;
Expand Down

0 comments on commit 5802de9

Please sign in to comment.