From patchwork Tue Nov 10 07:49:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 321007 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:5ce:0:0:0:0 with SMTP id l14csp16214ils; Mon, 9 Nov 2020 23:49:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJyR094G361XC1ahelshfrrstftLDZqTp13T8fwAlkuXS5o00cOC3CGEoKUAEhGOCtaLlcK4 X-Received: by 2002:aa7:c2d7:: with SMTP id m23mr19795935edp.230.1604994593872; Mon, 09 Nov 2020 23:49:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604994593; cv=none; d=google.com; s=arc-20160816; b=tLtfm/OQVt/a0+swe8GDPhI2zrwpgQ7E9kjJzACZqLcK/85xW2rBDxxpkB9m/j5965 zf7FhoviCa1QRnF7WO3xEgktPd2mPnP6Y24aCTuIOUSEnwR1d3K+JKeOjsp9f0d9Ttje o7on6ZBZkmpKgVnRsNdFqDtEg7Hx7aQaoBr+F4it2ls6i7DMfnWfoKuQQCPeyzFrWAbp yI8EjfaNPLPbjYVLhjLt/M3m604wyvEyf+OAwjuLSPn40cwRUcDoD9aa4l40RwQOg/iS t4ZrUBR37RaAR5YvPmyNZ0ipeIFOp/3alzzT4NkpZiaijUu52dnn1hCOCO7NQ49HJUwD tPaw== 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=eRvtyjdCdRTOjwn7w+lL10dRqNun6eihBwpQn7YO9Ik=; b=VZQv9jKpy1btcOFq8bSvBmmxbk1gb7cZNWup5xE9KNyWQkic0hOggKMMLUUGppxvWO d1fMWQEAb4AHwd0QqfM1dQJdfHzQgKzHXyAXC2ofV+eerps5pxFocPBAcaExQmYOVVtD oJ9pqSWpqVjmoJcPCl8t9wcw0AImvA0D+D2yRztiSpi+MnKCVjQMYIEViSrmVKS3d2Tg THjltemI+sv55rbQoPgFZ/RmyCGctKrPjKrbiy2asNNT3tYomTozH8hd/kYkzovVHQXP pvkH4l7mEudX7GwaETDXuu98xvYm37248zr1sVi89l58iyFOpxV4AcksLevrvrtMMJQG JJ5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B7Bk2fk8; 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 c13si8891577ejs.117.2020.11.09.23.49.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 23:49:53 -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=B7Bk2fk8; 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 34C5B8253A; Tue, 10 Nov 2020 08:49:51 +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="B7Bk2fk8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D5F108252A; Tue, 10 Nov 2020 08:49:49 +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-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) (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 49F0A8252A for ; Tue, 10 Nov 2020 08:49:46 +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-wr1-x441.google.com with SMTP id s8so4461669wrw.10 for ; Mon, 09 Nov 2020 23:49:46 -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=eRvtyjdCdRTOjwn7w+lL10dRqNun6eihBwpQn7YO9Ik=; b=B7Bk2fk8uGSMhW2qKtDA8nyso9Z+B1qAX3kszNl3lqFVDKPPR+1qDFG7Vu1GXjsRSE nlt/sZmcFrgMsvZv8HzLQYhM9ANpXzvtnR1uW32p3uF65IBlpNk5PvkS+PAi/5ybDTDr WJPbnznK/fM3dJnlktzhmwMdSAcWRmB96eIrFq6KmnzZ+sjqgw1uE3iuh6Y9GfCLdvRp SBdleIujsyvREJBcV9YU/pim7riAgib1OyLoxt8zQ3TIXaa8a2Qn5EfMhrw7xPtHOJU8 DlijsMOiE+u2euvKyuP8d3MtNIEDMSBJZnTDRtPG0MgkU7vtyIQWUjytWTirgHolY4Fi Llvg== 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=eRvtyjdCdRTOjwn7w+lL10dRqNun6eihBwpQn7YO9Ik=; b=nhQP9S3XMa/n5j1lLrqFc+CUCZwD1AYQoftwfyZ7xmMjIAcQo8q2eixxHWgNO9bSVD aboxKw4M26P1fQ/D/TjlfT5BFxVIlnRe+86RRLEkjQtF0PbyJ2A0YBh9luvifv36zThv NphM5ZpwyJ/ZdwBah5q2WsquPeT3XzPX4PqqgPZbp0x1jjSGyPdKmptycyMyNdCCAotT teh1bhpW1WvUHxx3RNRIFpYG8j0T3W+Y1kJO0hdv4d1HUjAXqncXn6Vd2AoHi2N512iV 6H2WYJZ7Mo83RG8y83Iswgh/7RdWzqowMpDK2NTRyh4BMZyM2ofmJeA0JlBF89C1yVzG JICg== X-Gm-Message-State: AOAM532zS7oy2H9Edw/3VORmlizKeuRJYt9a1Tn26kQhI2tDjKE4aIFD ndYm7LdzMKWHg1vpPUcrW0Q16w== X-Received: by 2002:a5d:51cd:: with SMTP id n13mr12564867wrv.87.1604994585874; Mon, 09 Nov 2020 23:49:45 -0800 (PST) Received: from apalos.home ([2a02:587:4615:c071:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id b63sm2268726wme.9.2020.11.09.23.49.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 23:49:45 -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 v3] tpm: Add some headers from the spec Date: Tue, 10 Nov 2020 09:49:41 +0200 Message-Id: <20201110074942.49130-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 --- 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: Heinrich Schuchardt Reviewed-by: Simon Glass diff --git a/include/tpm-v2.h b/include/tpm-v2.h index f6c045d35480..c75cd5d8dfe8 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 PT_GROUP (u32)(0x00000100) +#define PT_FIXED (u32)(PT_GROUP * 1) +#define TPM2_PT_MANUFACTURER (u32)(PT_FIXED + 5) +#define TPM2_PT_PCR_COUNT (u32)(PT_FIXED + 18) +#define TPM2_PT_MAX_COMMAND_SIZE (u32)(PT_FIXED + 30) +#define TPM2_PT_MAX_RESPONSE_SIZE (u32)(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 */