Skip to content

Commit

Permalink
Add dupctx support to rc4_hmac_md5 algo
Browse files Browse the repository at this point in the history
Pretty straightforward, just clone the requested context, no pointers to
fixup

Fixes #21887

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #21933)
  • Loading branch information
nhorman authored and t8m committed Sep 12, 2023
1 parent df93b3c commit 123c858
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
18 changes: 18 additions & 0 deletions providers/implementations/ciphers/cipher_aes_cbc_hmac_sha.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,16 @@ static void *aes_cbc_hmac_sha1_newctx(void *provctx, size_t kbits,
return ctx;
}

static void *aes_cbc_hmac_sha1_dupctx(void *provctx)
{
PROV_AES_HMAC_SHA1_CTX *ctx = provctx;

if (ctx == NULL)
return NULL;

return OPENSSL_memdup(ctx, sizeof(*ctx));
}

static void aes_cbc_hmac_sha1_freectx(void *vctx)
{
PROV_AES_HMAC_SHA1_CTX *ctx = (PROV_AES_HMAC_SHA1_CTX *)vctx;
Expand Down Expand Up @@ -361,6 +371,13 @@ static void *aes_cbc_hmac_sha256_newctx(void *provctx, size_t kbits,
return ctx;
}

static void *aes_cbc_hmac_sha256_dupctx(void *provctx)
{
PROV_AES_HMAC_SHA256_CTX *ctx = provctx;

return OPENSSL_memdup(ctx, sizeof(*ctx));
}

static void aes_cbc_hmac_sha256_freectx(void *vctx)
{
PROV_AES_HMAC_SHA256_CTX *ctx = (PROV_AES_HMAC_SHA256_CTX *)vctx;
Expand All @@ -386,6 +403,7 @@ static int nm##_##kbits##_##sub##_get_params(OSSL_PARAM params[]) \
const OSSL_DISPATCH ossl_##nm##kbits##sub##_functions[] = { \
{ OSSL_FUNC_CIPHER_NEWCTX, (void (*)(void))nm##_##kbits##_##sub##_newctx },\
{ OSSL_FUNC_CIPHER_FREECTX, (void (*)(void))nm##_##sub##_freectx }, \
{ OSSL_FUNC_CIPHER_DUPCTX, (void (*)(void))nm##_##sub##_dupctx}, \
{ OSSL_FUNC_CIPHER_ENCRYPT_INIT, (void (*)(void))nm##_einit }, \
{ OSSL_FUNC_CIPHER_DECRYPT_INIT, (void (*)(void))nm##_dinit }, \
{ OSSL_FUNC_CIPHER_UPDATE, (void (*)(void))nm##_update }, \
Expand Down
11 changes: 11 additions & 0 deletions providers/implementations/ciphers/cipher_rc4_hmac_md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ static OSSL_FUNC_cipher_encrypt_init_fn rc4_hmac_md5_einit;
static OSSL_FUNC_cipher_decrypt_init_fn rc4_hmac_md5_dinit;
static OSSL_FUNC_cipher_newctx_fn rc4_hmac_md5_newctx;
static OSSL_FUNC_cipher_freectx_fn rc4_hmac_md5_freectx;
static OSSL_FUNC_cipher_dupctx_fn rc4_hmac_md5_dupctx;
static OSSL_FUNC_cipher_get_ctx_params_fn rc4_hmac_md5_get_ctx_params;
static OSSL_FUNC_cipher_gettable_ctx_params_fn rc4_hmac_md5_gettable_ctx_params;
static OSSL_FUNC_cipher_set_ctx_params_fn rc4_hmac_md5_set_ctx_params;
Expand Down Expand Up @@ -71,6 +72,15 @@ static void rc4_hmac_md5_freectx(void *vctx)
OPENSSL_clear_free(ctx, sizeof(*ctx));
}

static void *rc4_hmac_md5_dupctx(void *vctx)
{
PROV_RC4_HMAC_MD5_CTX *ctx = vctx;

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

static int rc4_hmac_md5_einit(void *ctx, const unsigned char *key,
size_t keylen, const unsigned char *iv,
size_t ivlen, const OSSL_PARAM params[])
Expand Down Expand Up @@ -214,6 +224,7 @@ static int rc4_hmac_md5_get_params(OSSL_PARAM params[])
const OSSL_DISPATCH ossl_rc4_hmac_ossl_md5_functions[] = {
{ OSSL_FUNC_CIPHER_NEWCTX, (void (*)(void))rc4_hmac_md5_newctx },
{ OSSL_FUNC_CIPHER_FREECTX, (void (*)(void))rc4_hmac_md5_freectx },
{ OSSL_FUNC_CIPHER_DUPCTX, (void (*)(void))rc4_hmac_md5_dupctx },
{ OSSL_FUNC_CIPHER_ENCRYPT_INIT, (void (*)(void))rc4_hmac_md5_einit },
{ OSSL_FUNC_CIPHER_DECRYPT_INIT, (void (*)(void))rc4_hmac_md5_dinit },
{ OSSL_FUNC_CIPHER_UPDATE, (void (*)(void))rc4_hmac_md5_update },
Expand Down

0 comments on commit 123c858

Please sign in to comment.