From patchwork Thu Nov 12 22:22:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 324253 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:5ce:0:0:0:0 with SMTP id l14csp716688ils; Thu, 12 Nov 2020 14:22:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJwKkkgUuzINdUOJcfnI+++l6yQYaD3QNF6Q1oWKWmsfywd4mxvVx32RAcxRuzIjw0+XmYUT X-Received: by 2002:aa7:d64b:: with SMTP id v11mr2168165edr.253.1605219748143; Thu, 12 Nov 2020 14:22:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605219748; cv=none; d=google.com; s=arc-20160816; b=BUSGEPj8rOWxQdjv8IMfcfOwKU/likowdNbtKsYTaqUmkWYanNZ0Cdhuua9FoXjOih vBsyc9zgCmaPL7PZfSaVEeQcgPV01r5f9u7KmO/piZOW5P9fGYER/XJnmnE/rmg4mQDO oBUflAOf2787tbiN/MtTV8BmL6vM8m4amWN4/xQdmFI3Z4VtThy9lIPYBScQvkyIfjZM U4P+MreIlHON8vgGZCdFKudSsXqXDUZiRACFInT6/laxBRb8mHkzhXr3mINrV/uzVebg whhiNc8FIHmy/YVxeYkjF0SwbBgZ391sgAnm/UxNBpP2y8fuSp8437PzDBG45JFd2ytj gSUg== 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=DQoSJbyynS4r0PWyb7DvKr9htBHFoCWOUcf0QlX7LKY=; b=1CTXxbQwHgCDyxDlkJOOjwoV3jVNexeFxZKh9pgvVAKGeSa4laqwR2jwmTJDLA6YS5 yRlSYjbn4nLZ9JQl8hTQkq95vlIvw6hzQ3ZeupNdSqL+DUJuNMWhzFS85tmu6jsyQA7c 8zzoE8mCwK/rFMgBPsYQipbkicUZpB5GA2OEcL9GFW308QmQzKBUlGRqs5I6Cj3rLcDl BpvUkpm39tBVo4G7aOBTDDMBoxBy2qY+2D9rpT8i2rdfPSYsGY+PWllIzDZM8Cbn/w1x tPpbUkEBR4hdsTtR3a/QyYwxSzb0qPkmG74JkiS0HKn+5hPkAOP3uyRo2p3OgIZC+bYn 5hQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yRQD0P8q; 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 j20si4754912eja.715.2020.11.12.14.22.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2020 14:22:28 -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=yRQD0P8q; 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 1C22C822DF; Thu, 12 Nov 2020 23:22: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=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="yRQD0P8q"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8C3AC82300; Thu, 12 Nov 2020 23:22:19 +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 58624801D8 for ; Thu, 12 Nov 2020 23:22:15 +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 c9so6549018wml.5 for ; Thu, 12 Nov 2020 14:22:15 -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=DQoSJbyynS4r0PWyb7DvKr9htBHFoCWOUcf0QlX7LKY=; b=yRQD0P8q7mjx2BOySI0/XMuv9g1FpWuFITyegAKZot5q6EcOvzBCEwWnHCDm5yn/YW gu+cof6xe15+M2GPnuVLvjjOfDXhVJoooj2LuRtux/btP00BS6ijvq9NnSzXPbrx/jcB rfkoPRqsls/JOud33DLuM+oUD4czVNiZU1HLCfDHeniCstyadBX2tQrnj/gT21oPSXtH CNl01uE+keBKYIJ2UPTLXyMPObtqqubKe934dGj6GNrcYuXAwyIvESrYlfxyBfM/WeH7 5FPoVoXmO++m9JuCIqyTBS+lEWyrAWM3FN3ihEkCI1MAoVJFmyu8PH4eivd2wphGeCxN so5g== 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=DQoSJbyynS4r0PWyb7DvKr9htBHFoCWOUcf0QlX7LKY=; b=twMxRk36QZJxAnjj58iX2pw/d7lfRPZSrigtHc1ahoMOZ5pxfTR43Szi6f3YrV+5tW vn/mBnF8xKBfoid7ugX2rjC1OW8RTLCV0xIy+lJMmQUw2cGw2UrVXJ/8+c+pva+GzWVB gY/ICE6VgxP42CIYilf0J1Amxqr5gEuByQ7u/uX8RJwzKLHVQ29NDkpBZpMWbLBXb6Do FFnt+9egrZzg7/m4v/RLJ5GXQkDEiWBETkgkAn5/UrGXF8ZmyPjqmnWrhBwvoFzo+KgT TfcD76bmS1emLff+vF+2ZiNdTQspvwxusH5ivZaQQ0Gfs+wNRMHJ7JlAUTm40VFFVpCe 3wQw== X-Gm-Message-State: AOAM532kWqt3AMpEZeGMbzn9PH2kQUySkFCRExY16bspaEKqIjxUtR30 v81G3boJp6EFriEvYTuJM0t90w== X-Received: by 2002:a1c:3846:: with SMTP id f67mr1757614wma.33.1605219734666; Thu, 12 Nov 2020 14:22:14 -0800 (PST) Received: from apalos.home ([2a02:587:4641:1e88:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id f23sm7612613wmb.43.2020.11.12.14.22.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2020 14:22:13 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: ard.biesheuvel@arm.com, trini@konsulko.com, Ilias Apalodimas , Simon Glass , Alexander Graf , Bin Meng , Dhananjay Phadke , u-boot@lists.denx.de Subject: [PATCH 1/2 v5] tpm: Add some headers from the spec Date: Fri, 13 Nov 2020 00:22:09 +0200 Message-Id: <20201112222210.876652-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 Reviewed-by: Simon Glass --- * 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 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 */