From patchwork Wed Nov 11 09:18:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 322915 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:5ce:0:0:0:0 with SMTP id l14csp230814ils; Wed, 11 Nov 2020 01:18:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJyzS2xg2yJrqdws5OxD3hvrU0edfA5UusWG5CzYYpZip7ONSUg9uls3ScHu+FeCCxDP054c X-Received: by 2002:aa7:d591:: with SMTP id r17mr26133074edq.274.1605086320045; Wed, 11 Nov 2020 01:18:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605086320; cv=none; d=google.com; s=arc-20160816; b=k8SK4flhycyylXY2grOoNQ4T2sIzL1aiu/GpyEaQSpuc5NpFlYV9TKo0UfT3ya+WKp bPOmImaN5FUNTKdf+f+2bPTPaUF5OfNXS+wCDXT4Zaxzxuhgoxapn5SnYHEeh3WKihnx Zuh06HS+AeAKzzBwWBwoCDspRSmxDHnAQqXtAt+GkR7Za4IKW6YVJhAOY8EtzF9Lqy8P L79dlwfF+iPl8lmJhPwhH0/rz/BBnX/IO1UIxr1esji/WCgIjJMtIzTb+L9EpqsjujuI EaCch3ORsxY789iflyMueb0PXBaRh+CinA4bcO9HLqBPjNKbkkFcZVQ26vHXxzYFjzeX 1F7A== 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=xqCTWNcqNaskBUcbCxD3XUTJadQcuKbSZohF61Zj3aI=; b=zM9yWpXUWF14H15Ka2eM0iXtLZkY1j9tc/X65lqjOtIjwkC88UTN4ehLNWwMBdKV4j f1R1AcIxYZqtf0+QACLGFLgTcxDCoORAgn+YB9Z/lWDenpmwDFRazShwfejg8QgDGUYW dTWRrvxlCLjRRgmDNU8AEh0xkh/+QfLkZJLkt7lV0l77eCvzgmrSeNMwhwmcwbtiRaqJ OU0aQkXBpddOBv5p4NQ8yLGTqo9Cs/+1HTvc/j9eSQXXjb6BaWW9SsvStT0v+SmDXfwa PoUtV+MOlTBz49uWmSpaoedKgixPWfKWu2SDv3ZByO5cicl9FUZAfEPKxjRLjX4F/lNT IhXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=p54FVonq; 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 hs10si1065830ejc.239.2020.11.11.01.18.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Nov 2020 01:18:40 -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=p54FVonq; 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 6E95D823FE; Wed, 11 Nov 2020 10:18: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=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="p54FVonq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2F4FF824F7; Wed, 11 Nov 2020 10:18:24 +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-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) (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 16DEC81F67 for ; Wed, 11 Nov 2020 10:18:16 +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-x343.google.com with SMTP id h2so1591573wmm.0 for ; Wed, 11 Nov 2020 01:18:16 -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=xqCTWNcqNaskBUcbCxD3XUTJadQcuKbSZohF61Zj3aI=; b=p54FVonqfm15RRhzbGYcvx4a1xlJsELC13AipFwntfcUfXUg6H7k0h4sHErGWBhXFq kGdyWaFBzx5R8mZYlPJQKnJtd8bA0LVfwGR2MKlRZx9YkHJcoYJJ07198dRu1OhT8srn xmP4FVJoazeL0CeKEKgDJVPFQa1dmT3/ZoYANa4FIENLvQCfpuk2NoTULe7R8Ya7ebjr HJcFNeH8XkI9Ous+j0+v1oQDvSQrKCLJetm+vb2m2kl35/Jj28Q3rEVbXqwhxt7OX+Y7 ot3ufEDFJLaIy1gSh4wQzhOMONKiT35njOGG2rrhPAm5DUZPBEuYFdwzfIqLmV1MUMaC KbqA== 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=xqCTWNcqNaskBUcbCxD3XUTJadQcuKbSZohF61Zj3aI=; b=mOop9jBVPe96uNa0B6oCOVQNhY2EIamZZEFfoqn9zQuwibFfU22koIVH+gGW2+Dlzz o2ht2dN3WLD0inUGvmgUAZwGeMPw81vPCgQm7YRf5r//IgDt6kFcJuR33sE0L36+lX/S zcq4xxz9RwoXsREDo6abVuMtCxGJGDj007nHxLB4Cx7FV/ZBPzYCXjUylQpO6GLwJ4ic xN3x0Lho+fy2CCFyHOdFjoKYRykYW/4Jqfn5S2bNYo2NIUIh7azABoCz6VtjscwQXVs+ sbLAUnexoro9WQq55Ya0lk54iIR55REIwOAJm1g66s3oNBM8Klac+RbUfsziqZbln3W8 fxvg== X-Gm-Message-State: AOAM531ShzprWvttSkpXPy/QqlEhacpWOv5WXBH+swRW8lcRyRxohwWQ CXfS2OEr2aVD7HQciXzAENaIlw== X-Received: by 2002:a1c:1d82:: with SMTP id d124mr3052063wmd.12.1605086295505; Wed, 11 Nov 2020 01:18:15 -0800 (PST) Received: from apalos.home ([2a02:587:4615:c071:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id 18sm1752617wmo.3.2020.11.11.01.18.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Nov 2020 01:18:15 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: ard.biesheuvel@arm.com, trini@konsulko.com, Ilias Apalodimas , Alexander Graf , Simon Glass , Bin Meng , Dhananjay Phadke , u-boot@lists.denx.de Subject: [PATCH 1/2 v4] tpm: Add some headers from the spec Date: Wed, 11 Nov 2020 11:18:10 +0200 Message-Id: <20201111091812.400969-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 A following patch introduces EFI_TCG2_PROTOCOL. Add the required TPMv2 headers to support it. Signed-off-by: Ilias Apalodimas Reviewed-by: Heinrich Schuchardt --- * changes since v3: - Add TPM2 prefix on PT_GROUP, PT_FIXED * changes since v2: - Added description and pointers to TCG specs - updated copyright info include/tpm-v2.h | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) -- 2.29.2 Reviewed-by: Simon Glass diff --git a/include/tpm-v2.h b/include/tpm-v2.h index f6c045d35480..74c14fe7c51d 100644 --- a/include/tpm-v2.h +++ b/include/tpm-v2.h @@ -1,6 +1,13 @@ /* SPDX-License-Identifier: GPL-2.0+ */ /* + * Defines APIs and structures that allow software to interact with a + * TPM2 device + * + * Copyright (c) 2020 Linaro * Copyright (c) 2018 Bootlin + * + * https://trustedcomputinggroup.org/resource/tss-overview-common-structures-specification/ + * * Author: Miquel Raynal */ @@ -11,6 +18,74 @@ #define TPM2_DIGEST_LEN 32 +#define TPM2_MAX_PCRS 32 +#define TPM2_PCR_SELECT_MAX ((TPM2_MAX_PCRS + 7) / 8) +#define TPM2_MAX_CAP_BUFFER 1024 +#define TPM2_MAX_TPM_PROPERTIES ((TPM2_MAX_CAP_BUFFER - sizeof(u32) /* TPM2_CAP */ - \ + sizeof(u32)) / sizeof(struct tpms_tagged_property)) + +/* + * We deviate from this draft of the specification by increasing the value of + * TPM2_NUM_PCR_BANKS from 3 to 16 to ensure compatibility with TPM2 + * implementations that have enabled a larger than typical number of PCR + * banks. This larger value for TPM2_NUM_PCR_BANKS is expected to be included + * in a future revision of the specification. + */ +#define TPM2_NUM_PCR_BANKS 16 + +/* Definition of (UINT32) TPM2_CAP Constants */ +#define TPM2_CAP_PCRS 0x00000005U +#define TPM2_CAP_TPM_PROPERTIES 0x00000006U + +/* Definition of (UINT32) TPM2_PT Constants */ +#define TPM2_PT_GROUP (u32)(0x00000100) +#define TPM2_PT_FIXED (u32)(TPM2_PT_GROUP * 1) +#define TPM2_PT_MANUFACTURER (u32)(TPM2_PT_FIXED + 5) +#define TPM2_PT_PCR_COUNT (u32)(TPM2_PT_FIXED + 18) +#define TPM2_PT_MAX_COMMAND_SIZE (u32)(TPM2_PT_FIXED + 30) +#define TPM2_PT_MAX_RESPONSE_SIZE (u32)(TPM2_PT_FIXED + 31) + +/* TPMS_TAGGED_PROPERTY Structure */ +struct tpms_tagged_property { + u32 property; + u32 value; +} __packed; + +/* TPMS_PCR_SELECTION Structure */ +struct tpms_pcr_selection { + u16 hash; + u8 size_of_select; + u8 pcr_select[TPM2_PCR_SELECT_MAX]; +} __packed; + +/* TPML_PCR_SELECTION Structure */ +struct tpml_pcr_selection { + u32 count; + struct tpms_pcr_selection selection[TPM2_NUM_PCR_BANKS]; +} __packed; + +/* TPML_TAGGED_TPM_PROPERTY Structure */ +struct tpml_tagged_tpm_property { + u32 count; + struct tpms_tagged_property tpm_property[TPM2_MAX_TPM_PROPERTIES]; +} __packed; + +/* TPMU_CAPABILITIES Union */ +union tpmu_capabilities { + /* + * Non exhaustive. Only added the structs needed for our + * current code + */ + struct tpml_pcr_selection assigned_pcr; + struct tpml_tagged_tpm_property tpm_properties; +} __packed; + +/* TPMS_CAPABILITY_DATA Structure */ +struct tpms_capability_data { + u32 capability; + union tpmu_capabilities data; +} __packed; + /** * TPM2 Structure Tags for command/response buffers. * @@ -123,11 +198,13 @@ enum tpm2_return_codes { * TPM2 algorithms. */ enum tpm2_algorithms { + TPM2_ALG_SHA1 = 0x04, TPM2_ALG_XOR = 0x0A, TPM2_ALG_SHA256 = 0x0B, TPM2_ALG_SHA384 = 0x0C, TPM2_ALG_SHA512 = 0x0D, TPM2_ALG_NULL = 0x10, + TPM2_ALG_SM3_256 = 0x12, }; /* NV index attributes */