From patchwork Sat Nov 21 17:47:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 329946 Delivered-To: patch@linaro.org Received: by 2002:a92:ae0b:0:0:0:0:0 with SMTP id s11csp823631ilh; Sat, 21 Nov 2020 09:47:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJwH2NVt67YQahSWMUd+ZK5Hgl1VemETEsZzBybT5BhDPVJqv/sjAJVCK6bOPfuqCxS6jIt8 X-Received: by 2002:a05:6402:14cf:: with SMTP id f15mr39669604edx.18.1605980851926; Sat, 21 Nov 2020 09:47:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605980851; cv=none; d=google.com; s=arc-20160816; b=qAnmW9QGfFoqpAcfOlO00n8jcAb1NSJm/gPbXm37A/Z7JGP3+DjJa9L3aw+iUdqaya zKUSJkP7zYbIc5ig2DLCTgaWi+aH78OgcG87+QA5BezAJ15EvyS1axE4gkRSljxan4cb NvFW5RPLiYJ5hU6UgYDK3ZP7SezG3R5YqSwocijXTt5iktzcVS3022RhjdXrFvGJwUph SBpYnEs5meCmCikJAA9SSEDthAyeRlJgU1kLjpMhxFhdxAE9yDvp4618aIoLV7UyEvzR wVt6mR+7I4fVzqDyA1fqxITsP0oCDsNPfnOqXbvezEc6f7S6erXqYz+24SyTIIoJvzT9 5/ew== 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=ghpPbFUDYsJzVoHA9dr4yEF+YOyLMRB2L67ez4HC5vk=; b=JBd1ALRWu/wfxAfMHOZq+j1wIU5yVUrtPY7E2R/137vEXNS0U0V3Rtnoo+TGxC4Jva NMTavwPnF2K1CP7z5tBEY+x67EeN/vRJHs1Dr6ZeY1mEamEiBRT/abP2UmVfAFp8mu7I V7h+8cjS83HyuIJJbvLIM2Uo2p+UpTmGxcWHHbR2kkvSoAj6J3oSFwlWS87ORQ3SrZJd GCbULYR5z6P3VUQzKvh4VY4xyUvXGpFQCMuDlQcfc1hTIRmBiN2nFQ8GnAGFvAguYRxj SlwjyIaYNrjmWMZfVZdInEOcbb+vE3sdo7Vy3wTIYF/74C0PojgMNdTEnhM4uZy6r0Lo 4X4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="IgZpwbB/"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id e21si4091334edr.26.2020.11.21.09.47.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Nov 2020 09:47:31 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="IgZpwbB/"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 8EB1E82591; Sat, 21 Nov 2020 18:47:27 +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="IgZpwbB/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EB496825A1; Sat, 21 Nov 2020 18:47:25 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) (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 56E5B821A4 for ; Sat, 21 Nov 2020 18:47:22 +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=ilias.apalodimas@linaro.org Received: by mail-wm1-x344.google.com with SMTP id c9so13975865wml.5 for ; Sat, 21 Nov 2020 09:47:22 -0800 (PST) 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=ghpPbFUDYsJzVoHA9dr4yEF+YOyLMRB2L67ez4HC5vk=; b=IgZpwbB/6C92drAGwQrlxRYEnosWDVpxn1urFLEedDr0gE4KYjAaiG5ISYupFFoKwq huCwEEvMxW3q2mTsIziz47/BWd791a09sH+56msHPGuyobl2cOJdWQafrgh+BGdpNQfK jhr0UWwSFabqx+2Ml6LgnTZs1odNmChFtomsd8rkOF4756UxCw46ycvE+EiscD0c0RCN Qzdcm2BaNQf5oKZU7GaysqdIeiJNJx9cwvXVt1kxlCo1q6d4yNdqpAJodBdI3XK/ZUGD jBMXN9ZYesK7P+iZGkylhMDoMrr4xZaUbgXe/UbQ0Lyljux0QgKZmunlutVPSXtah68C fuWg== 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=ghpPbFUDYsJzVoHA9dr4yEF+YOyLMRB2L67ez4HC5vk=; b=ODpcwbybyINY6ygC0KEdYJB8TEu4puZ+5TuCRlvhPLAE5J5kIMTSCI3E6Z4K70wlkI hTJzPYI0EkW+o4uio9OlnmMpuTqX6x+0POzgYvvsW/IpftecRDrpghtTNrApwsTptSPK me7aqI8P9BuDbkWNchIqLNI11u3V8y6xFyD56wfOEQZSbZYdBE8ll9AA0yxCTUg3ZSTW CToweLCT/NQZqCHoLzkzGd7NXSi9kCcPptbm058hg6GpLTOaAXl7TyPJwLPPBDzq4n2s FWqpyONWuO9O3eOfttXBiCSH5aH8gfCXcGA/7w7lJ+AQ64OiHwCf9t9agHVJOPGgPaSi +2Eg== X-Gm-Message-State: AOAM532R7IbiT28XB+i3SJt11rUur1B+cxc+as2VxdOOKkWj1ys6Xagy ls+O3cHRyH537D2M9DDvzq9ghA== X-Received: by 2002:a1c:5605:: with SMTP id k5mr14824820wmb.99.1605980841578; Sat, 21 Nov 2020 09:47:21 -0800 (PST) Received: from apalos.home ([2a02:587:4641:1e88:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id t15sm7823075wmn.19.2020.11.21.09.47.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Nov 2020 09:47:21 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: Ilias Apalodimas , Miquel Raynal , Philippe Reynes , Simon Glass , Dhananjay Phadke , Bin Meng , u-boot@lists.denx.de Subject: [PATCH] tpm: use more than sha256 on pcr_extend Date: Sat, 21 Nov 2020 19:47:17 +0200 Message-Id: <20201121174718.949000-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.29.2 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.3 at phobos.denx.de X-Virus-Status: Clean The current tpm2_pcr_extend is hardcoded using SHA256. Let's make the actual command to the TPM2 configurable so we can support a wider range of algorithms and keep the current command line as-is i.e limited to SHA256 only Signed-off-by: Ilias Apalodimas --- cmd/tpm-v2.c | 3 ++- include/tpm-v2.h | 5 ++++- lib/tpm-v2.c | 11 ++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) -- 2.29.2 Reviewed-by: Simon Glass diff --git a/cmd/tpm-v2.c b/cmd/tpm-v2.c index 5fa4788a72de..daae91100a2b 100644 --- a/cmd/tpm-v2.c +++ b/cmd/tpm-v2.c @@ -116,7 +116,8 @@ static int do_tpm2_pcr_extend(struct cmd_tbl *cmdtp, int flag, int argc, if (index >= priv->pcr_count) return -EINVAL; - rc = tpm2_pcr_extend(dev, index, digest); + rc = tpm2_pcr_extend(dev, index, TPM2_ALG_SHA256, digest, + TPM2_DIGEST_LEN); unmap_sysmem(digest); diff --git a/include/tpm-v2.h b/include/tpm-v2.h index d8cf0ab05185..fde44e5d98cd 100644 --- a/include/tpm-v2.h +++ b/include/tpm-v2.h @@ -376,11 +376,14 @@ u32 tpm2_clear(struct udevice *dev, u32 handle, const char *pw, * * @dev TPM device * @index Index of the PCR + * @algorithm Algorithm used * @digest Value representing the event to be recorded + * @digest_len len of the hash * * @return code of the operation */ -u32 tpm2_pcr_extend(struct udevice *dev, u32 index, const uint8_t *digest); +u32 tpm2_pcr_extend(struct udevice *dev, u32 index, u32 algorithm, + const u8 *digest, u32 digest_len); /** * Issue a TPM2_PCR_Read command. diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c index 91759068cf03..1f3deb06e487 100644 --- a/lib/tpm-v2.c +++ b/lib/tpm-v2.c @@ -80,11 +80,12 @@ u32 tpm2_clear(struct udevice *dev, u32 handle, const char *pw, return tpm_sendrecv_command(dev, command_v2, NULL, NULL); } -u32 tpm2_pcr_extend(struct udevice *dev, u32 index, const uint8_t *digest) +u32 tpm2_pcr_extend(struct udevice *dev, u32 index, u32 algorithm, + const u8 *digest, u32 digest_len) { u8 command_v2[COMMAND_BUFFER_SIZE] = { tpm_u16(TPM2_ST_SESSIONS), /* TAG */ - tpm_u32(33 + TPM2_DIGEST_LEN), /* Length */ + tpm_u32(33 + digest_len), /* Length */ tpm_u32(TPM2_CC_PCR_EXTEND), /* Command code */ /* HANDLE */ @@ -99,7 +100,7 @@ u32 tpm2_pcr_extend(struct udevice *dev, u32 index, const uint8_t *digest) tpm_u16(0), /* Size of */ /* (if any) */ tpm_u32(1), /* Count (number of hashes) */ - tpm_u16(TPM2_ALG_SHA256), /* Algorithm of the hash */ + tpm_u16(algorithm), /* Algorithm of the hash */ /* STRING(digest) Digest */ }; unsigned int offset = 33; @@ -110,8 +111,8 @@ u32 tpm2_pcr_extend(struct udevice *dev, u32 index, const uint8_t *digest) * - the digest */ ret = pack_byte_string(command_v2, sizeof(command_v2), "s", - offset, digest, TPM2_DIGEST_LEN); - offset += TPM2_DIGEST_LEN; + offset, digest, digest_len); + offset += digest_len; if (ret) return TPM_LIB_ERROR;