• Show log

    Commit

  • Hash : 745cf7d9
    Author : Collin Funk
    Date : 2025-09-06T10:55:40

    crypto/sha3, crypto/sha3-buffer: Don't leak memory when using OpenSSL.
    
    Reported by Pádraig Brady in:
    <https://lists.gnu.org/archive/html/bug-gnulib/2025-09/msg00058.html>.
    
    * lib/sha3.c (DEFINE_SHA3_INIT_CTX) [!HAVE_OPENSSL_SHA3]: Always return
    true.
    [HAVE_OPENSSL_SHA3]: Call EVP_MD_CTX_create to allocate an EVP_MD_CTX.
    (DEFINE_SHA3_BUFFER, sha3_process_bytes, sha3_process_block)
    [!HAVE_OPENSSL_SHA3]: Always return true.
    [HAVE_OPENSSL_SHA3]: Return NULL if any function calls fail.
    (sha3_finish_ctx) [HAVE_OPENSSL_SHA3]: Free memory allocated by
    EV_MD_CTX_create.
    (sha3_free_ctx): New function.
    * lib/sha3.h (struct sha3_ctx): Use a heap allocated EVP_MD_CTX.
    (sha3_224_init_ctx, sha3_256_init_ctx, sha3_384_init_ctx)
    (sha3_512_init_ctx, sha3_process_block, sha3_process_bytes): Change
    prototype to return a bool. Mention that they return false if an OpenSSL
    function fails.
    (sha3_finish_ctx, sha3_read_ctx, sha3_224_buffer, sha3_256_buffer)
    (sha3_384_buffer, sha3_512_buffer): Mention that these functions return
    NULL if an OpenSSL function fails.
    (sha3_free_ctx): New function.
    * lib/sha3-stream.c (sha3_xxx_stream): Expect a function parameter that
    returns bool. Check the return values of the sha3 functions, cleaning up
    memory on failure.
    * modules/crypto/sha3-buffer: Add bool.