Implement dupctx for chacha20 cipher
authorNeil Horman <nhorman@openssl.org>
Mon, 28 Aug 2023 16:07:16 +0000 (12:07 -0400)
committerPauli <pauli@openssl.org>
Mon, 4 Sep 2023 00:15:58 +0000 (10:15 +1000)
commit61cfc22b60e33bc77b1e1944759af48c8e58f0d2
tree28532ea7f227fe8f7c5ab6f989678f837e39f061
parent12d08fe3a50f28fe80ff591e05d7f8253148afb4
Implement dupctx for chacha20 cipher

Implement the dupctx method for the chacha20 cipher, so that
EVP_PKEY_CTX_copy works

Its pretty straightforward, its basically just a memdup.  Checking the
pointers that might need fixing up:

in PROV_CHACHA20_CTX all members are statically declared, so memduping
should be fine

in PROV_CHACHA20_CTX->base (PROV_CIPHER_CTX):
        Non statically declared members:
                *tlsmac needs to get memduped to avoid double free
                 conditions, but only if base.alloced is set
                *hw pointer is always assigned to the chacha20_hw global
                 variable, so can be left alone
                *libctx can be left alone as provctx is always NULL in
                 chacha20_newctx
                *ks appears unused by chacha20, so can be ignored
Fixes #20978

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/21878)
providers/implementations/ciphers/cipher_chacha20.c