Directly return from final sha3/keccak_final if no bytes are requested
authorPatrick Steuer <patrick.steuer@de.ibm.com>
Mon, 5 Aug 2019 14:53:16 +0000 (16:53 +0200)
committerPatrick Steuer <patrick.steuer@de.ibm.com>
Sun, 18 Aug 2019 19:33:49 +0000 (21:33 +0200)
Requesting zero bytes from shake previously led to out-of-bounds write
on some platforms.

Signed-off-by: Patrick Steuer <patrick.steuer@de.ibm.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9433)

(cherry picked from commit a890ef833d114da3430c2f2efd95e01714704d34)

crypto/evp/m_sha3.c

index 31379c0f6b995315efb2d6fa2f9fa58e65061131..b6bbf58211e20392a83ac5d829b3558696906789 100644 (file)
@@ -108,6 +108,9 @@ static int sha3_final(EVP_MD_CTX *evp_ctx, unsigned char *md)
     size_t bsz = ctx->block_size;
     size_t num = ctx->num;
 
+    if (ctx->md_size == 0)
+        return 1;
+
     /*
      * Pad the data with 10*1. Note that |num| can be |bsz - 1|
      * in which case both byte operations below are performed on