From patchwork Tue Dec 24 16:01:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raymond Mao X-Patchwork-Id: 853204 Delivered-To: patch@linaro.org Received: by 2002:a5d:4888:0:b0:385:e875:8a9e with SMTP id g8csp3983061wrq; Tue, 24 Dec 2024 08:02:58 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXJ7iryulPE9ri2U4rMPs6bVoKrPpYJtGIt5IPqI4EZbahlUCoUfXu/il4aq3sZSDkSOBxCbA==@linaro.org X-Google-Smtp-Source: AGHT+IF/h+MNNo0o5guMiFYX0YN2K8MJxhXS9jWk+ISsshn3xqwJyqbmkPq0FWllYQfLuJ5CkEtE X-Received: by 2002:a17:907:2d93:b0:aa6:7c8e:808c with SMTP id a640c23a62f3a-aac3367569dmr1724487066b.17.1735056178091; Tue, 24 Dec 2024 08:02:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1735056178; cv=none; d=google.com; s=arc-20240605; b=X0HahkEs7v7Itx0wRi4QZmVyWIzAk3WD+ElfdhQW1SM/Yuv3rWGpQvz4vJfscRiwcV zNq96Bbw3+IynHkywS5oq/4/pCSCEytlecVzAO+LfwWEj0UvrMVY4GSg5CoVjVz71sPO eMWY3LFdBRrmMic185LTjASYgzfZLb4q/TKEdexL4pwGYkJErd6PLRozF1bYn8lUWt+F t78Xt25+IeWVHw9I49hHM/mvq4h6gvWGzcD9OzyIjjZ92rA0LaSyJnP+SA6dHNdnae1c w/thMF6ylUyl4lG+wvD+COGeUPDmnw9KRcwNczfB8ka0VQA1X00U3EijSjVHCkHI/d+V n9Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6f+1zk888DmInzSB52Q94w0za4Cy2rrga3HxC6WEDSU=; fh=2PQn9VYLpJKxCZvO/7KmIPfD9OVQ1hnJ0DtzeHBMtNQ=; b=cigqLGtKP0e+2OJrZcK6FD+CeTdohJpG5JCtDagWtronma32Cf4p7ZsfwfC3zeoHfx QC4JaYjDqwuVKG6JhIj9cYLiXx/4ZflogatEcxX3dpKoo073hHrTgBZ5nkWTRVSBoBoQ E6pIPhRi/KxpYuIVbi7uhstHvo+mQByhUttuikZVoc1DcIQulENg836ahEmZbqLTI5dr MxRm0AsY4lRigkANJJ1vzyc5eQLJzoj6NsTMsfGPSJlEu6+Vm8ZclmhIzpTkIDha822s 0vsiVpQmKv7OeLUFKcdqqEtwlyDxy6Aoy97CgvX0THnNYWLJisWIigfjM1+4is5zg+X7 lEcQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KN8L4Ni1; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id a640c23a62f3a-aac0e7f1101si729751466b.37.2024.12.24.08.02.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2024 08:02:58 -0800 (PST) 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=KN8L4Ni1; 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; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4803180831; Tue, 24 Dec 2024 17:02:36 +0100 (CET) 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="KN8L4Ni1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0BC72807DE; Tue, 24 Dec 2024 17:02:35 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) (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 D28C0801F5 for ; Tue, 24 Dec 2024 17:02:31 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=raymond.mao@linaro.org Received: by mail-qv1-xf2c.google.com with SMTP id 6a1803df08f44-6d91653e9d7so44495236d6.1 for ; Tue, 24 Dec 2024 08:02:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1735056150; x=1735660950; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6f+1zk888DmInzSB52Q94w0za4Cy2rrga3HxC6WEDSU=; b=KN8L4Ni1bqIuM0cb7h7XRMrPFyh9X7y2k6Q0/z6dDzyFqR6FMMTzeZA3WgDwm53G4f 6CL6ySUkTxgCEs0Esa1b2i18P8t7xvCE7YDZn18qMmKlkdHQaYZnjp3ZNkYPOv0TH7e1 o16HsxkPe4u/tLmFRGZqYxvGwEP3mrislq1hYJPUjyFxL4PCEglw8NttBqUHLaZWFAwI UXutNWa3Gikr3ymMoi36ZloVqRB/DFk1Wfs2sr1RsmXp8NlU+Lc69qsa0T0JffkLnBEw 7aYgPe1uVuvTl92cVctefRRMD0MhHPnhzYa9O/Ri1JYoNQx2D6qxrSWBRT6Pez/bIGwS aZaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735056150; x=1735660950; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6f+1zk888DmInzSB52Q94w0za4Cy2rrga3HxC6WEDSU=; b=TJho/kzP/9kUnnpclNbJD28rEWWjQEaX9G0I3GpXOZ3qWIEkrNdgxhPhbGRMESePL6 6GIwYwJNgH7cBgqNksEeRixW7DvKlCWum7AtHJbb+u3gIBEkGP9h2VUFqEzjdOQCQ3ys MBp3wWd0Ka697cGa+AqO21cZHc1MT4nAhRFQLP5q6dkMvkF1UGVghZpwd0DTA1t0mVOC Yt0LXonC8dunQB7bdjjAphuukbO7+hceHY1VjoJvN6aukmDziNQXgqRYejq9rOK1Ht49 siDeceecK/2U6t5gWs3l1pq7Xzw2LI2KmOjrwE2NNd5l8EDAj3zkLiQ0XzXZssco2awd LfwA== X-Gm-Message-State: AOJu0YzF9gVy9GW+vKyxCU/rySqSuihwPpP+rjruDl+IoeWMohm8n1i6 cal09gxsliAMVxFDg0sx9q3cNot6ZSo+3uYtbhkO8Uwg30ZuzTrONn9UfT5INeT/JpinpbAdNqb i X-Gm-Gg: ASbGncvslnC3jHso6JfCW6/NkCChrSCAqpNYfO2LTTZ0OQQMFmhfca1PA1yNAaPnX53 7XPiPBUlc2Irvh6ABv3XTrcwg4WP3UCE4UXgzzNoNuq/sqfWMvOYjNi8DjjGItL6KEHtZES5XtY CxCXf1WM2HZROMj4tkklML6onn/BWlELsS5ipKFSyt0uKm8KB6gAlcY/lngpfSLuOwULKyonyCw +dV5yPKr72g4aQGttgJojLTQkjtw5CpeFtvnGx/8I5qwNcUUvSfAp/JcV7QnVHIeLwfANRaCWau k3lGYDR09sKV4u8vnfg1TkcA7z61cSRXYsa9Cnp2FiatGRuhbFFNBQY= X-Received: by 2002:ad4:5ba5:0:b0:6d8:a84b:b50d with SMTP id 6a1803df08f44-6dd2339ff8cmr236448426d6.33.1735056150363; Tue, 24 Dec 2024 08:02:30 -0800 (PST) Received: from ubuntu.localdomain (pool-174-114-184-37.cpe.net.cable.rogers.com. [174.114.184.37]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6dd181d432asm53840816d6.110.2024.12.24.08.02.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2024 08:02:29 -0800 (PST) From: Raymond Mao To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Raymond Mao , Tom Rini , Heinrich Schuchardt , Simon Glass , Tim Harvey , Masahisa Kojima , Eddie James Subject: [PATCH v2 09/11] tpm: Simplify tcg2_log_init() Date: Tue, 24 Dec 2024 08:01:11 -0800 Message-Id: <20241224160118.675977-10-raymond.mao@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241224160118.675977-1-raymond.mao@linaro.org> References: <20241224160118.675977-1-raymond.mao@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.8 at phobos.denx.de X-Virus-Status: Clean From: Ilias Apalodimas A previous patch is storing the active PCR banks on the TPM private data. Instead of parsing them on the fly use the stored values. This allows us to simplify our checks during the log creation and parsing. Signed-off-by: Ilias Apalodimas Signed-off-by: Raymond Mao --- Changes in v2 - None. lib/tpm_tcg2.c | 42 +++++++----------------------------------- 1 file changed, 7 insertions(+), 35 deletions(-) diff --git a/lib/tpm_tcg2.c b/lib/tpm_tcg2.c index 9e63204f24..6c72688b80 100644 --- a/lib/tpm_tcg2.c +++ b/lib/tpm_tcg2.c @@ -207,37 +207,17 @@ static int tcg2_log_append_check(struct tcg2_event_log *elog, u32 pcr_index, static int tcg2_log_init(struct udevice *dev, struct tcg2_event_log *elog) { + struct tpm_chip_priv *priv = dev_get_uclass_priv(dev); struct tcg_efi_spec_id_event *ev; struct tcg_pcr_event *log; u32 event_size; u32 count = 0; u32 log_size; - u32 active; size_t i; u16 len; - int rc; - - rc = tcg2_get_active_pcr_banks(dev, &active); - if (rc) - return rc; + count = priv->active_bank_count; event_size = offsetof(struct tcg_efi_spec_id_event, digest_sizes); - for (i = 0; i < ARRAY_SIZE(hash_algo_list); ++i) { - if (!(active & hash_algo_list[i].hash_mask)) - continue; - - switch (hash_algo_list[i].hash_alg) { - case TPM2_ALG_SHA1: - case TPM2_ALG_SHA256: - case TPM2_ALG_SHA384: - case TPM2_ALG_SHA512: - count++; - break; - default: - continue; - } - } - event_size += 1 + (sizeof(struct tcg_efi_spec_id_event_algorithm_size) * count); log_size = offsetof(struct tcg_pcr_event, event) + event_size; @@ -264,19 +244,11 @@ static int tcg2_log_init(struct udevice *dev, struct tcg2_event_log *elog) ev->uintn_size = sizeof(size_t) / sizeof(u32); put_unaligned_le32(count, &ev->number_of_algorithms); - count = 0; - for (i = 0; i < ARRAY_SIZE(hash_algo_list); ++i) { - if (!(active & hash_algo_list[i].hash_mask)) - continue; - - len = hash_algo_list[i].hash_len; - if (!len) - continue; - - put_unaligned_le16(hash_algo_list[i].hash_alg, - &ev->digest_sizes[count].algorithm_id); - put_unaligned_le16(len, &ev->digest_sizes[count].digest_size); - count++; + for (i = 0; i < count; ++i) { + len = tpm2_algorithm_to_len(priv->active_banks[i]); + put_unaligned_le16(priv->active_banks[i], + &ev->digest_sizes[i].algorithm_id); + put_unaligned_le16(len, &ev->digest_sizes[i].digest_size); } *((u8 *)ev + (event_size - 1)) = 0;