Skip to content

Commit a982016

Browse files
nhormant8m
authored andcommitted
Add dupctx support to aead ciphers
Add dupctx method support to to ciphers implemented with IMPLEMENT_aead_cipher This includes: aes-<kbits>-gcm aria-<kbits>-ccm aria-<kbits>-gcm sm4-<kibs>-gcm Fixes #21887 Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from #21933) (cherry picked from commit 0239fb3)
1 parent d739b3e commit a982016

7 files changed

Lines changed: 70 additions & 0 deletions

File tree

providers/implementations/ciphers/cipher_aes_ccm.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,26 @@ static void *aes_ccm_newctx(void *provctx, size_t keybits)
3333
return ctx;
3434
}
3535

36+
static void *aes_ccm_dupctx(void *provctx)
37+
{
38+
PROV_AES_CCM_CTX *ctx = provctx;
39+
PROV_AES_CCM_CTX *dupctx = NULL;
40+
41+
if (ctx == NULL)
42+
return NULL;
43+
dupctx = OPENSSL_memdup(provctx, sizeof(*ctx));
44+
if (dupctx == NULL)
45+
return NULL;
46+
/*
47+
* ossl_cm_initctx, via the ossl_prov_aes_hw_ccm functions assign a
48+
* provctx->ccm.ks.ks to the ccm context key so we need to point it to
49+
* the memduped copy
50+
*/
51+
dupctx->base.ccm_ctx.key = &dupctx->ccm.ks.ks;
52+
53+
return dupctx;
54+
}
55+
3656
static OSSL_FUNC_cipher_freectx_fn aes_ccm_freectx;
3757
static void aes_ccm_freectx(void *vctx)
3858
{

providers/implementations/ciphers/cipher_aes_gcm.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ static void *aes_gcm_newctx(void *provctx, size_t keybits)
3434
return ctx;
3535
}
3636

37+
static void *aes_gcm_dupctx(void *provctx)
38+
{
39+
PROV_AES_GCM_CTX *ctx = provctx;
40+
41+
if (ctx == NULL)
42+
return NULL;
43+
return OPENSSL_memdup(ctx, sizeof(*ctx));
44+
}
45+
3746
static OSSL_FUNC_cipher_freectx_fn aes_gcm_freectx;
3847
static void aes_gcm_freectx(void *vctx)
3948
{

providers/implementations/ciphers/cipher_aria_ccm.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ static void *aria_ccm_newctx(void *provctx, size_t keybits)
2828
return ctx;
2929
}
3030

31+
static void *aria_ccm_dupctx(void *provctx)
32+
{
33+
PROV_ARIA_CCM_CTX *ctx = provctx;
34+
35+
if (ctx == NULL)
36+
return NULL;
37+
return OPENSSL_memdup(ctx, sizeof(*ctx));
38+
}
39+
3140
static void aria_ccm_freectx(void *vctx)
3241
{
3342
PROV_ARIA_CCM_CTX *ctx = (PROV_ARIA_CCM_CTX *)vctx;

providers/implementations/ciphers/cipher_aria_gcm.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ static void *aria_gcm_newctx(void *provctx, size_t keybits)
2727
return ctx;
2828
}
2929

30+
static void *aria_gcm_dupctx(void *provctx)
31+
{
32+
PROV_ARIA_GCM_CTX *ctx = provctx;
33+
34+
if (ctx == NULL)
35+
return NULL;
36+
return OPENSSL_memdup(ctx, sizeof(*ctx));
37+
}
38+
3039
static OSSL_FUNC_cipher_freectx_fn aria_gcm_freectx;
3140
static void aria_gcm_freectx(void *vctx)
3241
{

providers/implementations/ciphers/cipher_sm4_ccm.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ static void *sm4_ccm_newctx(void *provctx, size_t keybits)
2828
return ctx;
2929
}
3030

31+
static void *sm4_ccm_dupctx(void *provctx)
32+
{
33+
PROV_SM4_CCM_CTX *ctx = provctx;
34+
35+
if (ctx == NULL)
36+
return NULL;
37+
return OPENSSL_memdup(ctx, sizeof(*ctx));
38+
}
39+
3140
static void sm4_ccm_freectx(void *vctx)
3241
{
3342
PROV_SM4_CCM_CTX *ctx = (PROV_SM4_CCM_CTX *)vctx;

providers/implementations/ciphers/cipher_sm4_gcm.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ static void *sm4_gcm_newctx(void *provctx, size_t keybits)
2929
return ctx;
3030
}
3131

32+
static void *sm4_gcm_dupctx(void *provctx)
33+
{
34+
PROV_SM4_GCM_CTX *ctx = provctx;
35+
36+
if (ctx == NULL)
37+
return NULL;
38+
return OPENSSL_memdup(ctx, sizeof(*ctx));
39+
}
40+
3241
static void sm4_gcm_freectx(void *vctx)
3342
{
3443
PROV_SM4_GCM_CTX *ctx = (PROV_SM4_GCM_CTX *)vctx;

providers/implementations/include/prov/ciphercommon_aead.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ static void * alg##kbits##lc##_newctx(void *provctx) \
2323
{ \
2424
return alg##_##lc##_newctx(provctx, kbits); \
2525
} \
26+
static void * alg##kbits##lc##_dupctx(void *src) \
27+
{ \
28+
return alg##_##lc##_dupctx(src); \
29+
} \
2630
const OSSL_DISPATCH ossl_##alg##kbits##lc##_functions[] = { \
2731
{ OSSL_FUNC_CIPHER_NEWCTX, (void (*)(void))alg##kbits##lc##_newctx }, \
2832
{ OSSL_FUNC_CIPHER_FREECTX, (void (*)(void))alg##_##lc##_freectx }, \
33+
{ OSSL_FUNC_CIPHER_DUPCTX, (void (*)(void))alg##kbits##lc##_dupctx }, \
2934
{ OSSL_FUNC_CIPHER_ENCRYPT_INIT, (void (*)(void))ossl_##lc##_einit }, \
3035
{ OSSL_FUNC_CIPHER_DECRYPT_INIT, (void (*)(void))ossl_##lc##_dinit }, \
3136
{ OSSL_FUNC_CIPHER_UPDATE, (void (*)(void))ossl_##lc##_stream_update }, \

0 commit comments

Comments
 (0)