From a890ef833d114da3430c2f2efd95e01714704d34 Mon Sep 17 00:00:00 2001 From: Patrick Steuer Date: Mon, 5 Aug 2019 16:53:16 +0200 Subject: Directly return from final sha3/keccak_final if no bytes are requested Requesting zero bytes from shake previously led to out-of-bounds write on some platforms. Signed-off-by: Patrick Steuer Reviewed-by: Richard Levitte (Merged from https://github.com/openssl/openssl/pull/9433) --- crypto/sha/sha3.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'crypto/sha') diff --git a/crypto/sha/sha3.c b/crypto/sha/sha3.c index 19ef4266d0..fafa3556f3 100644 --- a/crypto/sha/sha3.c +++ b/crypto/sha/sha3.c @@ -89,6 +89,9 @@ int sha3_final(unsigned char *md, KECCAK1600_CTX *ctx) size_t bsz = ctx->block_size; size_t num = ctx->bufsz; + 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 -- cgit v1.2.1