From patchwork Thu Apr 22 11:32:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 425856 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp270328jao; Thu, 22 Apr 2021 04:32:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7bvQcAZ5U4i4eDIG//qiZkBieTdHwnBnk/n6n2pkoDmIAumK6Y3XjCcRtYRogERgDRKzZ X-Received: by 2002:a17:906:1a0d:: with SMTP id i13mr2814570ejf.197.1619091144533; Thu, 22 Apr 2021 04:32:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619091144; cv=none; d=google.com; s=arc-20160816; b=qmSMTi0SprlwReV1WRgICzgRhQyqUPaOO8qUJismh8Oi56vEsaO3XzCmAXy9b/M20I ZZo0fiYmucAjLdcC5eOLO7ur0Y4S9dFgYg0Z31jmccUAcVmkgxvhKHH0kWbMdNgdHUzw zoSkPMNWsQkRvcbPsUaQf8PUTO44Umovkmyf302jrvpzkW8hMAKOaonPPvAVEsQphP5c YbAmgV7n0ohO3v/HdwC7pOxpCCegHCL+b2imJG6TEugJ3as0tYVGYWXxjXlFyHbs+jLA 42xWHGTIGT04PpcqQZ56YsfDvWdw2jAXdkerpg4LemiSljVzthLLAPQMVT2z7BP0nAXB DtRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=Qfw8jJQftjPHFautAiDOSwEauRDeRh/wSY0zr6emhiY=; b=GzY2D/fHaTIGpnbj/z/iQpGnnxyFJidNUbHP8aC79ntn52FMJ2Ngi9l5F3Z6qR/mPh UVui2vlfDvk3LJ/2oKfbMCH09CJwZEzgsPjUoeuuCc4kFnwuquRMuAjsMxQjOaF3ehMP wT52h8k7ClaTHOaIvKw9AYgvNCRJt4/94dbS9Tmw0nRv5n+Znur4nX9mCqGGDMt48ZAU pE2spKh73K8HENpiRVjjs9KO9bx8ymmfknU6O9n43As1nq+F0miq8vGDC1PqAKi7CAjA oxxH/Bp+igXG1LwD1hUPOP9B1xdaHUh1Xw9nAQmRusqi5w9w3AUzhbA3YsYEDOmDBMrT ZWhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Egov+p9r; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id u19si2293270edo.410.2021.04.22.04.32.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Apr 2021 04:32:24 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Egov+p9r; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DEA5D82B55; Thu, 22 Apr 2021 13:32:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Egov+p9r"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1EC7882B59; Thu, 22 Apr 2021 13:32:21 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4FE7982B42 for ; Thu, 22 Apr 2021 13:32:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wm1-x329.google.com with SMTP id d200-20020a1c1dd10000b02901384767d4a5so3048667wmd.3 for ; Thu, 22 Apr 2021 04:32:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Qfw8jJQftjPHFautAiDOSwEauRDeRh/wSY0zr6emhiY=; b=Egov+p9rr8my7hJjAsR2XtIJAgGRgHQSs5cqazZg1pVLXpC5IxHHWao65r1f00mJHX mbRrbt8kWh73c9e/Tg0RkAt2gwH3BQAUF6eozOv3HMJtc051YEBnzg4NtWjEaAgesy6O FIl/2PncjAcJNOk/GyFAj0GdgpDtXKFPLiq6dH8p3ji/niW8fcz17aeO2T5NRiKp3Cha pcMVMs6KqxJUY7UO1tVt6tDZ7o+WTsZTfDV38PSNMtiFfZMb2zs/nqjhMCJDMWjiEBWz 8/kLwJStdNfTz5wRdH4j8ujwxHn2diyAE+OY2FYYIeobnF0/IcXCiPndqyIwqmAG79H2 fDCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Qfw8jJQftjPHFautAiDOSwEauRDeRh/wSY0zr6emhiY=; b=jmoKobajOw3m4TWcCVCZfabH4ypnStsgZcMybn6a4kDitpgFtFimsrMAGSp47tvO0k BDDhadoFIMOcC+wph0kXjs5YrqcUvZnM4YRRGmNRG+h18drn1jcBsw7tBW2xZhARenle qMOSYoQO1/xN5h/z3SjFowFDz9fl6xNePVYqk8afBE/S77FB2WkpT+hn6fWyY99SRz98 NCl1qJI+rERnnztuuH29Ea+E2m4w58+oOXKO0IoTXCGH8ad/d7k8/Y2vXI8VyfcGajXl pxB0AxSL8xBgC5f0Zays5I5Rw6WwdjxnVj+T4Yz4y6wdQZW1UoomEOS0MfePd57cDNUM rEaQ== X-Gm-Message-State: AOAM533oiimFcom2Y/eiNr/jBrksH+aalkgy2TrE/l8iq9gsePn4KcPR lU+5/77cB3q8b+63wZ5eF5KMzA== X-Received: by 2002:a7b:c316:: with SMTP id k22mr14809534wmj.176.1619091137929; Thu, 22 Apr 2021 04:32:17 -0700 (PDT) Received: from apalos.home ([2a02:587:464f:bfd6:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id q5sm5885062wmj.20.2021.04.22.04.32.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Apr 2021 04:32:17 -0700 (PDT) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: Ilias Apalodimas , Alexander Graf , u-boot@lists.denx.de Subject: [PATCH] efi_loader: simplify tcg2_create_digest() Date: Thu, 22 Apr 2021 14:32:14 +0300 Message-Id: <20210422113214.42079-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean Bumping the digest list count, for all supported algorithms, can be calculated outside of the individual switch statements. So let's do that for every loop iteration instead and simplify the code a bit. Signed-off-by: Ilias Apalodimas --- lib/efi_loader/efi_tcg2.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) -- 2.31.0 Reviewed-by: Heinrich Schuchardt diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c index d5eca68769b0..94e8f22bbb69 100644 --- a/lib/efi_loader/efi_tcg2.c +++ b/lib/efi_loader/efi_tcg2.c @@ -535,30 +535,27 @@ static efi_status_t tcg2_create_digest(const u8 *input, u32 length, sha1_starts(&ctx); sha1_update(&ctx, input, length); sha1_finish(&ctx, final); - digest_list->count++; break; case TPM2_ALG_SHA256: sha256_starts(&ctx_256); sha256_update(&ctx_256, input, length); sha256_finish(&ctx_256, final); - digest_list->count++; break; case TPM2_ALG_SHA384: sha384_starts(&ctx_512); sha384_update(&ctx_512, input, length); sha384_finish(&ctx_512, final); - digest_list->count++; break; case TPM2_ALG_SHA512: sha512_starts(&ctx_512); sha512_update(&ctx_512, input, length); sha512_finish(&ctx_512, final); - digest_list->count++; break; default: EFI_PRINT("Unsupported algorithm %x\n", hash_alg); return EFI_INVALID_PARAMETER; } + digest_list->count++; digest_list->digests[i].hash_alg = hash_alg; memcpy(&digest_list->digests[i].digest, final, (u32)alg_to_len(hash_alg)); }