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:16:31 +0000 (10:16 +1000)
commit9e39ee5d9374c06dc50bff6e2c69dee567443a70
tree65a92c2b2590030427227b96219fd60f5bb5cc92
parent4bfac4471f53c4f74c8d81020beb938f92d84ca5
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)

(cherry picked from commit 61cfc22b60e33bc77b1e1944759af48c8e58f0d2)
providers/implementations/ciphers/cipher_chacha20.c