Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5103014ybi; Tue, 28 May 2019 07:35:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqx6Rf0JpwA0UK2PdFAgE6v6Mp2aD1f4gWB4GYpReImxQr1JL7Fmyzvgdz0RF0jQfcyG+Qxl X-Received: by 2002:a17:902:b70b:: with SMTP id d11mr22556038pls.84.1559054138275; Tue, 28 May 2019 07:35:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559054138; cv=none; d=google.com; s=arc-20160816; b=fnoD8x0u6A9AqjslRNZ3Xwc1hNU5P4taGrbu80r9q7fr9lhgQN8F6JwmpXJqNM9a53 BISEPBxRK3b4xvjYQIawpAlKdjkji4X3QYmzpPC1BL6L36YJRq/glBLSu/27cM/svjut HX7dcV1F4i4fSHocHsSGrtdOmQWjASXPhIWpcbMAwjAIKCgFlD5Lr3hr9HfMOopjdOtc UdHg5ucEot7UB5rSVodDQ3ZiqE8A/GnTmMj0xLp/SoHmoyVnQfpq4eSu5AiJJDgHwQAo dQurSCaHZpnONI3nT3Z4DeXIB5miZL7YMoOon1kLIjMtAcqKKJ7QsXbj86UukDawgzE7 F44Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=u6Hmqn+VoyKdzrtqe2ho0SlGWPLtiXGeTWqFLUr85co=; b=oXD39eZjQUITHczPwyAjqO3Gv5llCgXTBVyWLCAgnGrctYPTNyxn9cQdc0jRSk1p4p SKvd9xeh8gLdKV+pU5pV6y9Ntptjl+ZYpn4juHbgoZDOSXG7qb4BpO3gROsw9E1F9c9O m/+sYpvn3yZzvLPF29K+swY+eweEXuGSuqtwWmO1PZaZbKeLCAN/gJyPrx3FY2mEQKmq KK4MJ8cSx/FEjQ9IEDFcK0ux8ygmiU+5dlRpNCyfTEXNK1pvu5irXspgUOjyvQkcBudT DfWUDxMxdcgtHYqy0CYPvZLOxPF9pvgfRcaxl6vPzhIZKl0ft8ClFPD0Bv721XnYKsYo fUyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=NL9yD5jU; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 90si22840034pla.323.2019.05.28.07.35.24; Tue, 28 May 2019 07:35:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=NL9yD5jU; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726425AbfE1OfU (ORCPT + 99 others); Tue, 28 May 2019 10:35:20 -0400 Received: from mail-qk1-f202.google.com ([209.85.222.202]:34523 "EHLO mail-qk1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726453AbfE1OfU (ORCPT ); Tue, 28 May 2019 10:35:20 -0400 Received: by mail-qk1-f202.google.com with SMTP id h11so28059453qkk.1 for ; Tue, 28 May 2019 07:35:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=u6Hmqn+VoyKdzrtqe2ho0SlGWPLtiXGeTWqFLUr85co=; b=NL9yD5jUYvPP4qO7lNiSZk/ZyRLfJT27GCzl2DrrIySI1M4qxs8VLhV9Ij/1iHZbeL DYgibIRy9GaEfaRewIgFK2nDCGKCtzIAGfW4B8M+/jDP/Tc2E/RAQ7S7zLUzkBZllV79 pJpAl+Z356uejo4Q8EnxoiHmVSEXpclqN83l22WLXyJyRBg7BFVqYkE1R31nhm5TE7+A 516KZ+V951PWR3Imh1zxvsmJH+LtKKdvukLVx18bhH5qKhhyU5tlSC7evYFodJwTzjAu 2oXNs8+rgMXzrUgoce5qtzwgKMsmZX3tnKMzQ62n9vgOWavkcD8+Xmp0ZfG1IdJngvEG y4fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=u6Hmqn+VoyKdzrtqe2ho0SlGWPLtiXGeTWqFLUr85co=; b=djqt1E7EmNwGztjAlFqDc+sNcoL35zBVqKMV7jTUtq5D+i2aAfDQbG2VV76pQ4Iq/E 3eo52yVl4xd5X43vlfNm4rglw9Jff3c4aGq4+5iU9IRIOGurlHT59do292QUXEDPLInj 5lz9aKmgH4K93kGlRWgtwIZda5uXF4Yl4PhR/ShTfRuh96QFYZPgEw9IHA991uaR/3lG VSoAvSxPpUrl9CP0sGLlVXkEFWnF8y5mdD3GWOI0xth3UqpA2o7TZo98puQzYH7rDbe6 raP0RwQvJKrMUsQJg89bzTDb7aCfuI3mbUZctUdXeNFdQAgGuI5m/V7X44PniXJuXvVr aCaA== X-Gm-Message-State: APjAAAUpRJzb79djhRfdjuhLKUNga+MC9TL0ZyxfEvhzUXX3BZ3bsRC3 g8MK37w+KYLtLVuotpUWd4Vndu45mNMqh23UpYkWJV9Ih3h4+fF1unAuWtEzYTLj7w7InuZipbB Rk6mR8P4VR1IWWdP+KLUsYI7xkkc3X4N6MsOHp8z/Tljh5bKunQiUdHYOfsPl+OM5w7/Pjd0Z X-Received: by 2002:a0c:b626:: with SMTP id f38mr39955266qve.223.1559054119482; Tue, 28 May 2019 07:35:19 -0700 (PDT) Date: Tue, 28 May 2019 15:35:06 +0100 Message-Id: <20190528143506.212198-1-lenaptr@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.22.0.rc1.257.g3120a18244-goog Subject: [PATCH] arm64 sha2-ce finup: correct digest for empty data From: Elena Petrova To: linux-crypto@vger.kernel.org Cc: Elena Petrova , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The sha256-ce finup implementation for ARM64 produces wrong digest for empty input (len=0). Expected: the actual digest, result: initial value of SHA internal state. The error is in sha256_ce_finup: for empty data `finalize` will be 1, so the code is relying on sha2_ce_transform to make the final round. However, in sha256_base_do_update, the block function will not be called when len == 0. Fix it by setting finalize to 0 if data is empty. Fixes: 03802f6a80b3a ("crypto: arm64/sha2-ce - move SHA-224/256 ARMv8 implementation to base layer") Cc: stable@vger.kernel.org Signed-off-by: Elena Petrova --- arch/arm64/crypto/sha2-ce-glue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/crypto/sha2-ce-glue.c b/arch/arm64/crypto/sha2-ce-glue.c index a725997e55f2..6a5ade974a35 100644 --- a/arch/arm64/crypto/sha2-ce-glue.c +++ b/arch/arm64/crypto/sha2-ce-glue.c @@ -60,7 +60,7 @@ static int sha256_ce_finup(struct shash_desc *desc, const u8 *data, unsigned int len, u8 *out) { struct sha256_ce_state *sctx = shash_desc_ctx(desc); - bool finalize = !sctx->sst.count && !(len % SHA256_BLOCK_SIZE); + bool finalize = !sctx->sst.count && !(len % SHA256_BLOCK_SIZE) && len; if (!crypto_simd_usable()) { if (len) -- 2.22.0.rc1.257.g3120a18244-goog