Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package grub2 for openSUSE:Factory checked 
in at 2023-04-30 16:07:39
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/grub2 (Old)
 and      /work/SRC/openSUSE:Factory/.grub2.new.1533 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "grub2"

Sun Apr 30 16:07:39 2023 rev:294 rq:1082902 version:2.06

Changes:
--------
--- /work/SRC/openSUSE:Factory/grub2/grub2.changes      2023-04-22 
21:57:36.604193973 +0200
+++ /work/SRC/openSUSE:Factory/.grub2.new.1533/grub2.changes    2023-04-30 
16:07:48.844166566 +0200
@@ -1,0 +2,49 @@
+Wed Apr 26 07:22:03 UTC 2023 - Gary Ching-Pang Lin <g...@suse.com>
+
+- Exclude the deprecated EFI location, /usr/lib64/efi/, from
+  Tumbleweed and ALP
+
+-------------------------------------------------------------------
+Fri Apr 21 07:53:30 UTC 2023 - Gary Ching-Pang Lin <g...@suse.com>
+
+- Update TPM 2.0 key unsealing patches
+  * Add the new upstreaming patches
+    0001-protectors-Add-key-protectors-framework.patch
+    0002-tpm2-Add-TPM-Software-Stack-TSS.patch
+    0003-protectors-Add-TPM2-Key-Protector.patch
+    0004-cryptodisk-Support-key-protectors.patch
+    0005-util-grub-protect-Add-new-tool.patch
+  * Add the authorized policy patches based on the upstreaming
+    patches
+    0001-tpm2-Add-TPM2-types-structures-and-command-constants.patch
+    0002-tpm2-Add-more-marshal-unmarshal-functions.patch
+    0003-tpm2-Implement-more-TPM2-commands.patch
+    0004-tpm2-Support-authorized-policy.patch
+  * Drop the old patches
+    0010-protectors-Add-key-protectors-framework.patch
+    0011-tpm2-Add-TPM-Software-Stack-TSS.patch
+    0012-protectors-Add-TPM2-Key-Protector.patch
+    0013-cryptodisk-Support-key-protectors.patch
+    0014-util-grub-protect-Add-new-tool.patch
+    fix-tpm2-build.patch
+    tpm-protector-dont-measure-sealed-key.patch
+    tpm-protector-export-secret-key.patch
+    grub-unseal-debug.patch
+    0001-tpm2-adjust-the-input-parameters-of-TPM2_EvictContro.patch
+    0002-tpm2-declare-the-input-arguments-of-TPM2-functions-a.patch
+    0003-tpm2-resend-the-command-on-TPM_RC_RETRY.patch
+    0004-tpm2-add-new-TPM2-types-structures-and-command-const.patch
+    0005-tpm2-add-more-marshal-unmarshal-functions.patch
+    0006-tpm2-check-the-command-parameters-of-TPM2-commands.patch
+    0007-tpm2-pack-the-missing-authorization-command-for-TPM2.patch
+    0008-tpm2-allow-some-command-parameters-to-be-NULL.patch
+    0009-tpm2-remove-the-unnecessary-variables.patch
+    0010-tpm2-add-TPM2-commands-to-support-authorized-policy.patch
+    0011-tpm2-make-the-file-reading-unmarshal-functions-gener.patch
+    0012-tpm2-initialize-the-PCR-selection-list-early.patch
+    0013-tpm2-support-unsealing-key-with-authorized-policy.patch
+  * Refresh grub-read-pcr.patch
+  * Introduce a new build requirement: libtasn1-devel
+- Only package grub2-protect for the architectures with EFI support
+
+-------------------------------------------------------------------

Old:
----
  0001-tpm2-adjust-the-input-parameters-of-TPM2_EvictContro.patch
  0002-tpm2-declare-the-input-arguments-of-TPM2-functions-a.patch
  0003-tpm2-resend-the-command-on-TPM_RC_RETRY.patch
  0004-tpm2-add-new-TPM2-types-structures-and-command-const.patch
  0005-tpm2-add-more-marshal-unmarshal-functions.patch
  0006-tpm2-check-the-command-parameters-of-TPM2-commands.patch
  0007-tpm2-pack-the-missing-authorization-command-for-TPM2.patch
  0008-tpm2-allow-some-command-parameters-to-be-NULL.patch
  0009-tpm2-remove-the-unnecessary-variables.patch
  0010-protectors-Add-key-protectors-framework.patch
  0010-tpm2-add-TPM2-commands-to-support-authorized-policy.patch
  0011-tpm2-Add-TPM-Software-Stack-TSS.patch
  0011-tpm2-make-the-file-reading-unmarshal-functions-gener.patch
  0012-protectors-Add-TPM2-Key-Protector.patch
  0012-tpm2-initialize-the-PCR-selection-list-early.patch
  0013-cryptodisk-Support-key-protectors.patch
  0013-tpm2-support-unsealing-key-with-authorized-policy.patch
  0014-util-grub-protect-Add-new-tool.patch
  fix-tpm2-build.patch
  grub-unseal-debug.patch
  tpm-protector-dont-measure-sealed-key.patch
  tpm-protector-export-secret-key.patch

New:
----
  0001-protectors-Add-key-protectors-framework.patch
  0001-tpm2-Add-TPM2-types-structures-and-command-constants.patch
  0002-tpm2-Add-TPM-Software-Stack-TSS.patch
  0002-tpm2-Add-more-marshal-unmarshal-functions.patch
  0003-protectors-Add-TPM2-Key-Protector.patch
  0003-tpm2-Implement-more-TPM2-commands.patch
  0004-cryptodisk-Support-key-protectors.patch
  0004-tpm2-Support-authorized-policy.patch
  0005-util-grub-protect-Add-new-tool.patch

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ grub2.spec ++++++
--- /var/tmp/diff_new_pack.3qedkw/_old  2023-04-30 16:07:52.336187870 +0200
+++ /var/tmp/diff_new_pack.3qedkw/_new  2023-04-30 16:07:52.344187919 +0200
@@ -48,6 +48,7 @@
 BuildRequires:  gnu-unifont
 %endif
 BuildRequires:  help2man
+BuildRequires:  libtasn1-devel
 BuildRequires:  xz
 %if 0%{?suse_version} >= 1210
 BuildRequires:  makeinfo
@@ -413,13 +414,15 @@
 Patch891:       0007-cryptodisk-Refactor-password-input-out-of-crypto-dev.patch
 Patch892:       0008-cryptodisk-Move-global-variables-into-grub_cryptomou.patch
 Patch893:       0009-cryptodisk-Improve-handling-of-partition-name-in-cry.patch
-Patch894:       0010-protectors-Add-key-protectors-framework.patch
-Patch895:       0011-tpm2-Add-TPM-Software-Stack-TSS.patch
-Patch896:       0012-protectors-Add-TPM2-Key-Protector.patch
-Patch897:       0013-cryptodisk-Support-key-protectors.patch
-Patch898:       0014-util-grub-protect-Add-new-tool.patch
-Patch899:       fix-tpm2-build.patch
-Patch900:       0001-crytodisk-fix-cryptodisk-module-looking-up.patch
+
+# TPM 2.0 protector
+Patch894:       0001-protectors-Add-key-protectors-framework.patch
+Patch895:       0002-tpm2-Add-TPM-Software-Stack-TSS.patch
+Patch896:       0003-protectors-Add-TPM2-Key-Protector.patch
+Patch897:       0004-cryptodisk-Support-key-protectors.patch
+Patch898:       0005-util-grub-protect-Add-new-tool.patch
+Patch899:       0001-crytodisk-fix-cryptodisk-module-looking-up.patch
+
 # fde
 Patch901:       0001-devmapper-getroot-Have-devmapper-recognize-LUKS2.patch
 Patch902:       0002-devmapper-getroot-Set-up-cheated-LUKS2-cryptodisk-mo.patch
@@ -434,10 +437,8 @@
 Patch911:       grub-read-pcr.patch
 Patch912:       efi-set-variable-with-attrs.patch
 Patch913:       tpm-record-pcrs.patch
-Patch914:       tpm-protector-dont-measure-sealed-key.patch
-Patch915:       tpm-protector-export-secret-key.patch
+
 Patch916:       grub-install-record-pcrs.patch
-Patch917:       grub-unseal-debug.patch
 # efi mm
 Patch919:       0001-mm-Allow-dynamically-requesting-additional-memory-re.patch
 Patch920:       0002-kern-efi-mm-Always-request-a-fixed-number-of-pages-o.patch
@@ -480,19 +481,13 @@
 Patch954:       0001-grub2-Set-multiple-device-path-for-a-nvmf-boot-devic.patch
 Patch955:       0001-grub-core-modify-sector-by-sysfs-as-disk-sector.patch
 Patch956:       0001-grub2-Can-t-setup-a-default-boot-device-correctly-on.patch
-Patch957:       0001-tpm2-adjust-the-input-parameters-of-TPM2_EvictContro.patch
-Patch958:       0002-tpm2-declare-the-input-arguments-of-TPM2-functions-a.patch
-Patch959:       0003-tpm2-resend-the-command-on-TPM_RC_RETRY.patch
-Patch960:       0004-tpm2-add-new-TPM2-types-structures-and-command-const.patch
-Patch961:       0005-tpm2-add-more-marshal-unmarshal-functions.patch
-Patch962:       0006-tpm2-check-the-command-parameters-of-TPM2-commands.patch
-Patch963:       0007-tpm2-pack-the-missing-authorization-command-for-TPM2.patch
-Patch964:       0008-tpm2-allow-some-command-parameters-to-be-NULL.patch
-Patch965:       0009-tpm2-remove-the-unnecessary-variables.patch
-Patch966:       0010-tpm2-add-TPM2-commands-to-support-authorized-policy.patch
-Patch967:       0011-tpm2-make-the-file-reading-unmarshal-functions-gener.patch
-Patch968:       0012-tpm2-initialize-the-PCR-selection-list-early.patch
-Patch969:       0013-tpm2-support-unsealing-key-with-authorized-policy.patch
+
+# Support TPM 2.0 Authorized Policy
+Patch957:       0001-tpm2-Add-TPM2-types-structures-and-command-constants.patch
+Patch958:       0002-tpm2-Add-more-marshal-unmarshal-functions.patch
+Patch959:       0003-tpm2-Implement-more-TPM2-commands.patch
+Patch960:       0004-tpm2-Support-authorized-policy.patch
+
 # Set efi variables LoaderDevicePartUUID & LoaderInfo (needed for UKI)
 Patch970:       grub2-add-module-for-boot-loader-interface.patch
 # Fix out of memory error on lpar installation from virtual cdrom (bsc#1208024)
@@ -1056,6 +1051,7 @@
 %define sysefidir %{sysefibasedir}/%{_target_cpu}
 install -d %{buildroot}/%{sysefidir}
 ln -sr %{buildroot}/%{_datadir}/%{name}/%{grubefiarch}/grub.efi 
%{buildroot}%{sysefidir}/grub.efi
+%if 0%{?suse_version} < 1600
 %ifarch x86_64
 # provide compatibility sym-link for previous shim-install and the like
 install -d %{buildroot}/usr/lib64/efi
@@ -1066,6 +1062,7 @@
        may vanish at any point in time.  Please use the new location!
 EoM
 %endif
+%endif
 
 %ifarch x86_64 aarch64
 export BRP_PESIGN_FILES="%{_datadir}/%{name}/%{grubefiarch}/grub.efi"
@@ -1415,7 +1412,9 @@
 %{_bindir}/%{name}-render-label
 %{_bindir}/%{name}-script-check
 %{_bindir}/%{name}-syslinux2cfg
+%ifarch %{efi}
 %{_bindir}/%{name}-protect
+%endif
 %if 0%{?has_systemd:1}
 %{_unitdir}/grub2-once.service
 %endif

++++++ 0010-protectors-Add-key-protectors-framework.patch -> 
0001-protectors-Add-key-protectors-framework.patch ++++++
--- 
/work/SRC/openSUSE:Factory/grub2/0010-protectors-Add-key-protectors-framework.patch
 2022-11-09 12:56:55.552175555 +0100
+++ 
/work/SRC/openSUSE:Factory/.grub2.new.1533/0001-protectors-Add-key-protectors-framework.patch
       2023-04-30 16:07:48.648165371 +0200
@@ -1,21 +1,22 @@
-From 2d959549857305d5e4d95a19a0850885f85179d6 Mon Sep 17 00:00:00 2001
+From 5affde982dea827580e36ccc658e439397f51ce8 Mon Sep 17 00:00:00 2001
 From: Hernan Gatta <hega...@linux.microsoft.com>
 Date: Tue, 1 Feb 2022 05:02:53 -0800
-Subject: [PATCH 10/14] protectors: Add key protectors framework
+Subject: [PATCH 1/5] protectors: Add key protectors framework
 
-A key protector encapsulates functionality to retrieve an unlocking key for a
-fully-encrypted disk from a specific source. A key protector module registers
-itself with the key protectors framework when it is loaded and unregisters when
-unloaded. Additionally, a key protector may accept parameters that describe how
-it should operate.
+A key protector encapsulates functionality to retrieve an unlocking key
+for a fully-encrypted disk from a specific source. A key protector
+module registers itself with the key protectors framework when it is
+loaded and unregisters when unloaded. Additionally, a key protector may
+accept parameters that describe how it should operate.
 
-The key protectors framework, besides offering registration and unregistration
-functions, also offers a one-stop routine for finding and invoking a key
-protector by name. If a key protector with the specified name exists and if an
-unlocking key is successfully retrieved by it, the function returns to the
-caller the retrieved key and its length.
+The key protectors framework, besides offering registration and
+unregistration functions, also offers a one-stop routine for finding and
+invoking a key protector by name. If a key protector with the specified
+name exists and if an unlocking key is successfully retrieved by it, the
+function returns to the caller the retrieved key and its length.
 
 Signed-off-by: Hernan Gatta <hega...@linux.microsoft.com>
+Signed-off-by: Gary Lin <g...@suse.com>
 ---
  grub-core/Makefile.am       |  1 +
  grub-core/Makefile.core.def |  1 +
@@ -26,7 +27,7 @@
  create mode 100644 include/grub/protector.h
 
 diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am
-index de241f0d04..dc07ba6f87 100644
+index 80e7a83ed..79d17a3d2 100644
 --- a/grub-core/Makefile.am
 +++ b/grub-core/Makefile.am
 @@ -90,6 +90,7 @@ endif
@@ -38,10 +39,10 @@
  KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/term.h
  KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/time.h
 diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
-index f3140815b8..b0001a33cf 100644
+index d83c9f7b6..0335d9add 100644
 --- a/grub-core/Makefile.core.def
 +++ b/grub-core/Makefile.core.def
-@@ -138,6 +138,7 @@ kernel = {
+@@ -144,6 +144,7 @@ kernel = {
    common = kern/misc.c;
    common = kern/parser.c;
    common = kern/partition.c;
@@ -51,7 +52,7 @@
    common = kern/term.c;
 diff --git a/grub-core/kern/protectors.c b/grub-core/kern/protectors.c
 new file mode 100644
-index 0000000000..21954dfa48
+index 000000000..5ee059565
 --- /dev/null
 +++ b/grub-core/kern/protectors.c
 @@ -0,0 +1,75 @@
@@ -83,16 +84,16 @@
 +grub_err_t
 +grub_key_protector_register (struct grub_key_protector *protector)
 +{
-+  if (!protector || !protector->name || !grub_strlen(protector->name))
++  if (protector == NULL || protector->name == NULL || 
grub_strlen(protector->name) == 0)
 +    return GRUB_ERR_BAD_ARGUMENT;
 +
 +  if (grub_key_protectors &&
 +      grub_named_list_find (GRUB_AS_NAMED_LIST (grub_key_protectors),
-+                            protector->name))
++                          protector->name))
 +    return GRUB_ERR_BAD_ARGUMENT;
 +
 +  grub_list_push (GRUB_AS_LIST_P (&grub_key_protectors),
-+                  GRUB_AS_LIST (protector));
++                GRUB_AS_LIST (protector));
 +
 +  return GRUB_ERR_NONE;
 +}
@@ -100,7 +101,7 @@
 +grub_err_t
 +grub_key_protector_unregister (struct grub_key_protector *protector)
 +{
-+  if (!protector)
++  if (protector == NULL)
 +    return GRUB_ERR_BAD_ARGUMENT;
 +
 +  grub_list_remove (GRUB_AS_LIST (protector));
@@ -110,29 +111,29 @@
 +
 +grub_err_t
 +grub_key_protector_recover_key (const char *protector, grub_uint8_t **key,
-+                                grub_size_t *key_size)
++                              grub_size_t *key_size)
 +{
 +  struct grub_key_protector *kp = NULL;
 +
-+  if (!grub_key_protectors)
++  if (grub_key_protectors == NULL)
 +    return GRUB_ERR_OUT_OF_RANGE;
 +
-+  if (!protector || !grub_strlen (protector))
++  if (protector == NULL || grub_strlen (protector) == 0)
 +    return GRUB_ERR_BAD_ARGUMENT;
 +
 +  kp = grub_named_list_find (GRUB_AS_NAMED_LIST (grub_key_protectors),
-+                             protector);
-+  if (!kp)
++                           protector);
++  if (kp == NULL)
 +    return grub_error (GRUB_ERR_OUT_OF_RANGE,
-+                       N_("A key protector with name '%s' could not be found. 
"
-+                          "Is the name spelled correctly and is the "
-+                          "corresponding module loaded?"), protector);
++                     N_("A key protector with name '%s' could not be found. "
++                        "Is the name spelled correctly and is the "
++                        "corresponding module loaded?"), protector);
 +
 +  return kp->recover_key (key, key_size);
 +}
 diff --git a/include/grub/protector.h b/include/grub/protector.h
 new file mode 100644
-index 0000000000..179020a344
+index 000000000..3d9f69bce
 --- /dev/null
 +++ b/include/grub/protector.h
 @@ -0,0 +1,48 @@
@@ -180,10 +181,10 @@
 +
 +grub_err_t
 +EXPORT_FUNC (grub_key_protector_recover_key) (const char *protector,
-+                                              grub_uint8_t **key,
-+                                              grub_size_t *key_size);
++                                            grub_uint8_t **key,
++                                            grub_size_t *key_size);
 +
 +#endif /* ! GRUB_PROTECTOR_HEADER */
 -- 
-2.34.1
+2.35.3
 

++++++ 0001-tpm2-Add-TPM2-types-structures-and-command-constants.patch ++++++
>From 5a417f32f1afe0ffca7f5cbff67145a157b1589b Mon Sep 17 00:00:00 2001
From: Gary Lin <g...@suse.com>
Date: Tue, 7 Feb 2023 18:31:12 +0800
Subject: [PATCH 1/4] tpm2: Add TPM2 types, structures, and command constants

Add new TPM2 types and structures as the preparation to support
authorized policy.

* New types:
  TPM_ALG_ECDAA, TPM_ALG_ECDSA, TPM_ALG_ECSCHNORR, TPM_ALG_RSASSA,
  TPM_ALG_RSAPSS, TPM_ALG_SM2, and TPMI_ALG_SIG_SCHEME

* New structures:
  TPMS_EMPTY, TPMS_SIGNATURE_RSA, TPMS_SIGNATURE_ECC,
  TPMS_SIGNATURE_ECDSA, TPMS_SIGNATURE_ECDAA, TPMS_SIGNATURE_SM2,
  TPMS_SIGNATURE_ECSCHNORR, TPMU_SIGNATURE, and TPMT_TK_VERIFIED

* New command constants:
  TPM_CC_LoadExternal, TPM_CC_HashSequenceStart, TPM_CC_SequenceUpdate,
  TPM_CC_SequenceComplete, TPM_CC_Hash, TPM_CC_VerifySignature,
  TPM_CC_PolicyAuthorize

Signed-off-by: Gary Lin <g...@suse.com>
---
 include/grub/tpm2/internal/structs.h | 86 ++++++++++++++++++++++++++++
 include/grub/tpm2/internal/types.h   | 42 +++++++++-----
 2 files changed, 114 insertions(+), 14 deletions(-)

diff --git a/include/grub/tpm2/internal/structs.h 
b/include/grub/tpm2/internal/structs.h
index 72d71eb70..db9eb6cf6 100644
--- a/include/grub/tpm2/internal/structs.h
+++ b/include/grub/tpm2/internal/structs.h
@@ -672,4 +672,90 @@ struct TPMT_TK_CREATION
 };
 typedef struct TPMT_TK_CREATION TPMT_TK_CREATION;
 
+/* TPMS_EMPTY Structure */
+struct TPMS_EMPTY {
+  grub_uint8_t empty[1]; /* a structure with no member */
+};
+typedef struct TPMS_EMPTY TPMS_EMPTY;
+
+/* TPMS_SIGNATURE_RSA Structure */
+struct TPMS_SIGNATURE_RSA {
+  TPMI_ALG_HASH hash;
+  TPM2B_PUBLIC_KEY_RSA sig;
+};
+typedef struct TPMS_SIGNATURE_RSA TPMS_SIGNATURE_RSA;
+
+/* Definition of Types for RSA Signature */
+typedef TPMS_SIGNATURE_RSA TPMS_SIGNATURE_RSASSA;
+typedef TPMS_SIGNATURE_RSA TPMS_SIGNATURE_RSAPSS;
+
+/* TPMS_SIGNATURE_ECC Structure */
+struct TPMS_SIGNATURE_ECC {
+  TPMI_ALG_HASH hash;
+  TPM2B_ECC_PARAMETER signatureR;
+  TPM2B_ECC_PARAMETER signatureS;
+};
+typedef struct TPMS_SIGNATURE_ECC TPMS_SIGNATURE_ECC;
+
+/* Definition of Types for ECC TPMS_SIGNATURE_ECC */
+typedef TPMS_SIGNATURE_ECC TPMS_SIGNATURE_ECDSA;
+typedef TPMS_SIGNATURE_ECC TPMS_SIGNATURE_ECDAA;
+typedef TPMS_SIGNATURE_ECC TPMS_SIGNATURE_SM2;
+typedef TPMS_SIGNATURE_ECC TPMS_SIGNATURE_ECSCHNORR;
+
+/* TPMU_SIGNATURE Structure */
+union TPMU_SIGNATURE {
+  TPMS_SIGNATURE_RSASSA rsassa;
+  TPMS_SIGNATURE_RSAPSS rsapss;
+  TPMS_SIGNATURE_ECDSA ecdsa;
+  TPMS_SIGNATURE_ECDAA ecdaa;
+  TPMS_SIGNATURE_SM2 sm2;
+  TPMS_SIGNATURE_ECSCHNORR ecschnorr;
+  TPMT_HA hmac;
+  TPMS_SCHEME_HASH any;
+  TPMS_EMPTY null;
+};
+typedef union TPMU_SIGNATURE TPMU_SIGNATURE;
+
+/* TPMT_SIGNATURE Structure */
+struct TPMT_SIGNATURE {
+  TPMI_ALG_SIG_SCHEME sigAlg;
+  TPMU_SIGNATURE signature;
+};
+typedef struct TPMT_SIGNATURE TPMT_SIGNATURE;
+
+static inline TPMI_ALG_HASH
+TPMT_SIGNATURE_get_hash_alg (TPMT_SIGNATURE *sig)
+{
+  switch (sig->sigAlg)
+    {
+    case TPM_ALG_RSASSA:
+      return sig->signature.rsassa.hash;
+    case TPM_ALG_RSAPSS:
+      return sig->signature.rsapss.hash;
+    case TPM_ALG_ECDSA:
+      return sig->signature.ecdsa.hash;
+    case TPM_ALG_ECDAA:
+      return sig->signature.ecdaa.hash;
+    case TPM_ALG_SM2:
+      return sig->signature.sm2.hash;
+    case TPM_ALG_ECSCHNORR:
+      return sig->signature.ecschnorr.hash;
+    case TPM_ALG_HMAC:
+      return sig->signature.hmac.hashAlg;
+    default:
+      break;
+    }
+
+  return TPM_ALG_NULL;
+}
+
+/* TPMT_TK_VERIFIED Structure */
+struct TPMT_TK_VERIFIED {
+  TPM_ST tag;
+  TPMI_RH_HIERARCHY hierarchy;
+  TPM2B_DIGEST digest;
+};
+typedef struct TPMT_TK_VERIFIED TPMT_TK_VERIFIED;
+
 #endif /* ! GRUB_TPM2_INTERNAL_STRUCTS_HEADER */
diff --git a/include/grub/tpm2/internal/types.h 
b/include/grub/tpm2/internal/types.h
index 9714f75d4..a1902ef0c 100644
--- a/include/grub/tpm2/internal/types.h
+++ b/include/grub/tpm2/internal/types.h
@@ -181,6 +181,9 @@ typedef grub_uint16_t TPM_ALG_ID;
 #define TPM_ALG_CFB            ((TPM_ALG_ID) 0x0043)
 #define TPM_ALG_ECB            ((TPM_ALG_ID) 0x0044)
 #define TPM_ALG_ECC            ((TPM_ALG_ID) 0x0023)
+#define TPM_ALG_ECDAA          ((TPM_ALG_ID) 0x001A)
+#define TPM_ALG_ECDSA          ((TPM_ALG_ID) 0x0018)
+#define TPM_ALG_ECSCHNORR      ((TPM_ALG_ID) 0x001C)
 #define TPM_ALG_HMAC           ((TPM_ALG_ID) 0x0005)
 #define TPM_ALG_KDF1_SP800_108 ((TPM_ALG_ID) 0x0022)
 #define TPM_ALG_KDF1_SP800_56A ((TPM_ALG_ID) 0x0020)
@@ -189,10 +192,13 @@ typedef grub_uint16_t TPM_ALG_ID;
 #define TPM_ALG_MGF1           ((TPM_ALG_ID) 0x0007)
 #define TPM_ALG_NULL           ((TPM_ALG_ID) 0x0010)
 #define TPM_ALG_RSA            ((TPM_ALG_ID) 0x0001)
+#define TPM_ALG_RSASSA         ((TPM_ALG_ID) 0x0014)
+#define TPM_ALG_RSAPSS         ((TPM_ALG_ID) 0x0016)
 #define TPM_ALG_SHA1           ((TPM_ALG_ID) 0x0004)
 #define TPM_ALG_SHA256         ((TPM_ALG_ID) 0x000B)
 #define TPM_ALG_SHA384         ((TPM_ALG_ID) 0x000C)
 #define TPM_ALG_SHA512         ((TPM_ALG_ID) 0x000D)
+#define TPM_ALG_SM2            ((TPM_ALG_ID) 0x001B)
 #define TPM_ALG_SM3_256        ((TPM_ALG_ID) 0x0012)
 #define TPM_ALG_SM4            ((TPM_ALG_ID) 0x0013)
 #define TPM_ALG_SYMCIPHER      ((TPM_ALG_ID) 0x0025)
@@ -299,20 +305,27 @@ typedef grub_uint16_t TPM2_ECC_CURVE;
 /* TPM_CC Constants */
 typedef grub_uint32_t TPM_CC;
 
-#define TPM_CC_EvictControl     ((TPM_CC) 0x00000120)
-#define TPM_CC_CreatePrimary    ((TPM_CC) 0x00000131)
-#define TPM_CC_Create           ((TPM_CC) 0x00000153)
-#define TPM_CC_FlushContext     ((TPM_CC) 0x00000165)
-#define TPM_CC_ReadPublic       ((TPM_CC) 0x00000173)
-#define TPM_CC_StartAuthSession ((TPM_CC) 0x00000176)
-#define TPM_CC_PolicyPCR        ((TPM_CC) 0x0000017f)
-#define TPM_CC_NV_Read          ((TPM_CC) 0x0000014e)
-#define TPM_CC_NV_ReadPublic    ((TPM_CC) 0x00000169)
-#define TPM_CC_GetCapability    ((TPM_CC) 0x0000017a)
-#define TPM_CC_PCR_Read         ((TPM_CC) 0x0000017e)
-#define TPM_CC_Load             ((TPM_CC) 0x00000157)
-#define TPM_CC_Unseal           ((TPM_CC) 0x0000015e)
-#define TPM_CC_PolicyGetDigest  ((TPM_CC) 0x00000189)
+#define TPM_CC_EvictControl      ((TPM_CC) 0x00000120)
+#define TPM_CC_CreatePrimary     ((TPM_CC) 0x00000131)
+#define TPM_CC_Create            ((TPM_CC) 0x00000153)
+#define TPM_CC_FlushContext      ((TPM_CC) 0x00000165)
+#define TPM_CC_ReadPublic        ((TPM_CC) 0x00000173)
+#define TPM_CC_StartAuthSession  ((TPM_CC) 0x00000176)
+#define TPM_CC_PolicyPCR         ((TPM_CC) 0x0000017f)
+#define TPM_CC_NV_Read           ((TPM_CC) 0x0000014e)
+#define TPM_CC_NV_ReadPublic     ((TPM_CC) 0x00000169)
+#define TPM_CC_GetCapability     ((TPM_CC) 0x0000017a)
+#define TPM_CC_PCR_Read          ((TPM_CC) 0x0000017e)
+#define TPM_CC_Load              ((TPM_CC) 0x00000157)
+#define TPM_CC_LoadExternal      ((TPM_CC) 0x00000167)
+#define TPM_CC_Unseal            ((TPM_CC) 0x0000015e)
+#define TPM_CC_PolicyGetDigest   ((TPM_CC) 0x00000189)
+#define TPM_CC_HashSequenceStart ((TPM_CC) 0x00000186)
+#define TPM_CC_SequenceUpdate    ((TPM_CC) 0x0000015c)
+#define TPM_CC_SequenceComplete  ((TPM_CC) 0x0000013e)
+#define TPM_CC_Hash              ((TPM_CC) 0x0000017d)
+#define TPM_CC_VerifySignature   ((TPM_CC) 0x00000177)
+#define TPM_CC_PolicyAuthorize   ((TPM_CC) 0x0000016a)
 
 /* Hash algorithm sizes */
 #define TPM_SHA1_DIGEST_SIZE    20
@@ -354,6 +367,7 @@ typedef TPM_ALG_ID TPMI_ALG_ECC_SCHEME;
 typedef TPM_ALG_ID TPMI_ALG_ASYM_SCHEME;
 typedef TPM_ALG_ID TPMI_ALG_RSA_SCHEME;
 typedef TPM_ALG_ID TPMI_ALG_SYM;
+typedef TPM_ALG_ID TPMI_ALG_SIG_SCHEME;
 
 /* TPM_KEY_BITS Type */
 typedef grub_uint16_t TPM_KEY_BITS;
-- 
2.35.3


++++++ 0011-tpm2-Add-TPM-Software-Stack-TSS.patch -> 
0002-tpm2-Add-TPM-Software-Stack-TSS.patch ++++++
++++ 1977 lines (skipped)
++++ between 
/work/SRC/openSUSE:Factory/grub2/0011-tpm2-Add-TPM-Software-Stack-TSS.patch
++++ and 
/work/SRC/openSUSE:Factory/.grub2.new.1533/0002-tpm2-Add-TPM-Software-Stack-TSS.patch

++++++ 0002-tpm2-Add-more-marshal-unmarshal-functions.patch ++++++
>From 1d34522075949581ccb34a08dd73607566517824 Mon Sep 17 00:00:00 2001
From: Gary Lin <g...@suse.com>
Date: Tue, 7 Feb 2023 18:33:42 +0800
Subject: [PATCH 2/4] tpm2: Add more marshal/unmarshal functions

Add a few more marshal/unmarshal functions to support authorized policy.

* Marshal:
  grub_tpm2_mu_TPMU_SENSITIVE_COMPOSITE_Marshal()
  grub_tpm2_mu_TPMT_SENSITIVE_Marshal()
  grub_tpm2_mu_TPM2B_SENSITIVE_Marshal()
  grub_tpm2_mu_TPMS_SIGNATURE_RSA_Marshal()
  grub_tpm2_mu_TPMS_SIGNATURE_ECC_Marshal()
  grub_tpm2_mu_TPMU_HA_Marshal()
  grub_tpm2_mu_TPMT_HA_Marshal()
  grub_tpm2_mu_TPMU_SIGNATURE_Marshal()
  grub_tpm2_mu_TPMT_SIGNATURE_Marshal()
  grub_tpm2_mu_TPMT_TK_VERIFIED_Marshal()

* Unmarshal:
  grub_tpm2_mu_TPMT_TK_HASHCHECK_Unmarshal()
  grub_tpm2_mu_TPMT_TK_VERIFIED_Unmarshal()
  grub_tpm2_mu_TPMS_SIGNATURE_RSA_Unmarshal()
  grub_tpm2_mu_TPMS_SIGNATURE_ECC_Unmarshal()
  grub_tpm2_mu_TPMU_HA_Unmarshal()
  grub_tpm2_mu_TPMT_HA_Unmarshal()
  grub_tpm2_mu_TPMU_SIGNATURE_Unmarshal()
  grub_tpm2_mu_TPMT_SIGNATURE_Unmarshal()

Signed-off-by: Gary Lin <g...@suse.com>
---
 grub-core/tpm2/mu.c    | 262 +++++++++++++++++++++++++++++++++++++++++
 include/grub/tpm2/mu.h |  75 ++++++++++++
 2 files changed, 337 insertions(+)

diff --git a/grub-core/tpm2/mu.c b/grub-core/tpm2/mu.c
index 1617f37cd..3a9a3c1be 100644
--- a/grub-core/tpm2/mu.c
+++ b/grub-core/tpm2/mu.c
@@ -383,6 +383,49 @@ grub_tpm2_mu_TPMS_SENSITIVE_CREATE_Marshal 
(grub_tpm2_buffer_t buffer,
   grub_tpm2_mu_TPM2B_Marshal (buffer, p->data.size, p->data.buffer);
 }
 
+void
+grub_tpm2_mu_TPMU_SENSITIVE_COMPOSITE_Marshal (grub_tpm2_buffer_t buffer,
+                                               const TPMI_ALG_PUBLIC type,
+                                               const TPMU_SENSITIVE_COMPOSITE 
*p)
+{
+  switch(type)
+    {
+    case TPM_ALG_RSA:
+      grub_tpm2_mu_TPM2B_Marshal (buffer, p->rsa.size, p->rsa.buffer);
+      break;
+    case TPM_ALG_ECC:
+      grub_tpm2_mu_TPM2B_Marshal (buffer, p->ecc.size, p->ecc.buffer);
+      break;
+    case TPM_ALG_KEYEDHASH:
+      grub_tpm2_mu_TPM2B_Marshal (buffer, p->bits.size, p->bits.buffer);
+      break;
+    case TPM_ALG_SYMCIPHER:
+      grub_tpm2_mu_TPM2B_Marshal (buffer, p->sym.size, p->sym.buffer);
+      break;
+    default:
+      buffer->error = 1;
+    }
+}
+
+void
+grub_tpm2_mu_TPMT_SENSITIVE_Marshal (grub_tpm2_buffer_t buffer,
+                                     const TPMT_SENSITIVE *p)
+{
+  grub_tpm2_buffer_pack_u16 (buffer, p->sensitiveType);
+  grub_tpm2_mu_TPM2B_Marshal (buffer, p->authValue.size, p->authValue.buffer);
+  grub_tpm2_mu_TPM2B_Marshal (buffer, p->seedValue.size, p->seedValue.buffer);
+  grub_tpm2_mu_TPMU_SENSITIVE_COMPOSITE_Marshal (buffer, p->sensitiveType,
+                                                 &p->sensitive);
+}
+
+void
+grub_tpm2_mu_TPM2B_SENSITIVE_Marshal (grub_tpm2_buffer_t buffer,
+                                      const TPM2B_SENSITIVE *p)
+{
+  grub_tpm2_buffer_pack_u16 (buffer, p->size);
+  grub_tpm2_mu_TPMT_SENSITIVE_Marshal (buffer, &p->sensitiveArea);
+}
+
 void
 grub_tpm2_mu_TPM2B_SENSITIVE_CREATE_Marshal (grub_tpm2_buffer_t buffer,
                                             const TPM2B_SENSITIVE_CREATE 
*sensitiveCreate)
@@ -405,6 +448,113 @@ grub_tpm2_mu_TPM2B_SENSITIVE_CREATE_Marshal 
(grub_tpm2_buffer_t buffer,
     grub_tpm2_buffer_pack_u16 (buffer, 0);
 }
 
+void
+grub_tpm2_mu_TPMS_SIGNATURE_RSA_Marshal (grub_tpm2_buffer_t buffer,
+                                         const TPMS_SIGNATURE_RSA *p)
+{
+  grub_tpm2_buffer_pack_u16 (buffer, p->hash);
+  grub_tpm2_mu_TPM2B_Marshal (buffer, p->sig.size, p->sig.buffer);
+}
+
+void
+grub_tpm2_mu_TPMS_SIGNATURE_ECC_Marshal (grub_tpm2_buffer_t buffer,
+                                         const TPMS_SIGNATURE_ECC *p)
+{
+  grub_tpm2_buffer_pack_u16 (buffer, p->hash);
+  grub_tpm2_mu_TPM2B_Marshal (buffer, p->signatureR.size, 
p->signatureR.buffer);
+  grub_tpm2_mu_TPM2B_Marshal (buffer, p->signatureS.size, 
p->signatureS.buffer);
+}
+
+void
+grub_tpm2_mu_TPMU_HA_Marshal (grub_tpm2_buffer_t buffer,
+                              const TPMI_ALG_HASH hashAlg,
+                              const TPMU_HA *p)
+{
+  switch (hashAlg)
+    {
+    case TPM_ALG_SHA1:
+      for (grub_uint16_t i = 0; i < TPM_SHA1_DIGEST_SIZE; i++)
+        grub_tpm2_buffer_pack_u8 (buffer, p->sha1[i]);
+      break;
+    case TPM_ALG_SHA256:
+      for (grub_uint16_t i = 0; i < TPM_SHA256_DIGEST_SIZE; i++)
+        grub_tpm2_buffer_pack_u8 (buffer, p->sha256[i]);
+      break;
+    case TPM_ALG_SHA384:
+      for (grub_uint16_t i = 0; i < TPM_SHA384_DIGEST_SIZE; i++)
+        grub_tpm2_buffer_pack_u8 (buffer, p->sha384[i]);
+      break;
+    case TPM_ALG_SHA512:
+      for (grub_uint16_t i = 0; i < TPM_SHA512_DIGEST_SIZE; i++)
+        grub_tpm2_buffer_pack_u8 (buffer, p->sha512[i]);
+      break;
+    default:
+      buffer->error = 1;
+      break;
+    }
+}
+
+void
+grub_tpm2_mu_TPMT_HA_Marshal (grub_tpm2_buffer_t buffer,
+                              const TPMT_HA *p)
+{
+  grub_tpm2_buffer_pack_u16 (buffer, p->hashAlg);
+  grub_tpm2_mu_TPMU_HA_Marshal (buffer, p->hashAlg, &p->digest);
+}
+
+void
+grub_tpm2_mu_TPMU_SIGNATURE_Marshal (grub_tpm2_buffer_t buffer,
+                                     const TPMI_ALG_SIG_SCHEME sigAlg,
+                                     const TPMU_SIGNATURE *p)
+{
+  switch (sigAlg)
+    {
+    case TPM_ALG_RSASSA:
+      grub_tpm2_mu_TPMS_SIGNATURE_RSA_Marshal (buffer, (TPMS_SIGNATURE_RSA 
*)&p->rsassa);
+      break;
+    case TPM_ALG_RSAPSS:
+      grub_tpm2_mu_TPMS_SIGNATURE_RSA_Marshal (buffer, (TPMS_SIGNATURE_RSA 
*)&p->rsapss);
+      break;
+    case TPM_ALG_ECDSA:
+      grub_tpm2_mu_TPMS_SIGNATURE_ECC_Marshal (buffer, (TPMS_SIGNATURE_ECC 
*)&p->ecdsa);
+      break;
+    case TPM_ALG_ECDAA:
+      grub_tpm2_mu_TPMS_SIGNATURE_ECC_Marshal (buffer, (TPMS_SIGNATURE_ECC 
*)&p->ecdaa);
+      break;
+    case TPM_ALG_SM2:
+      grub_tpm2_mu_TPMS_SIGNATURE_ECC_Marshal (buffer, (TPMS_SIGNATURE_ECC 
*)&p->sm2);
+      break;
+    case TPM_ALG_ECSCHNORR:
+      grub_tpm2_mu_TPMS_SIGNATURE_ECC_Marshal (buffer, (TPMS_SIGNATURE_ECC 
*)&p->ecschnorr);
+      break;
+    case TPM_ALG_HMAC:
+      grub_tpm2_mu_TPMT_HA_Marshal (buffer, &p->hmac);
+      break;
+    case TPM_ALG_NULL:
+      break;
+    default:
+      buffer->error = 1;
+      break;
+    }
+}
+
+void
+grub_tpm2_mu_TPMT_SIGNATURE_Marshal (grub_tpm2_buffer_t buffer,
+                                     const TPMT_SIGNATURE *p)
+{
+  grub_tpm2_buffer_pack_u16 (buffer, p->sigAlg);
+  grub_tpm2_mu_TPMU_SIGNATURE_Marshal (buffer, p->sigAlg, &p->signature);
+}
+
+void
+grub_tpm2_mu_TPMT_TK_VERIFIED_Marshal (grub_tpm2_buffer_t buffer,
+                                       const TPMT_TK_VERIFIED *p)
+{
+  grub_tpm2_buffer_pack_u16 (buffer, p->tag);
+  grub_tpm2_buffer_pack_u32 (buffer, p->hierarchy);
+  grub_tpm2_mu_TPM2B_Marshal (buffer, p->digest.size, p->digest.buffer);
+}
+
 void
 grub_tpm2_mu_TPM2B_Unmarshal (grub_tpm2_buffer_t buffer,
                              TPM2B* p)
@@ -775,6 +925,24 @@ grub_tpm2_mu_TPMT_TK_CREATION_Unmarshal 
(grub_tpm2_buffer_t buffer,
   grub_tpm2_mu_TPM2B_Unmarshal (buffer, (TPM2B*) &p->digest);
 }
 
+void
+grub_tpm2_mu_TPMT_TK_HASHCHECK_Unmarshal (grub_tpm2_buffer_t buffer,
+                                          TPMT_TK_HASHCHECK *p)
+{
+  grub_tpm2_buffer_unpack_u16 (buffer, &p->tag);
+  grub_tpm2_buffer_unpack_u32 (buffer, &p->hierarchy);
+  grub_tpm2_mu_TPM2B_Unmarshal (buffer, (TPM2B*) &p->digest);
+}
+
+void
+grub_tpm2_mu_TPMT_TK_VERIFIED_Unmarshal (grub_tpm2_buffer_t buffer,
+                                         TPMT_TK_VERIFIED *p)
+{
+  grub_tpm2_buffer_unpack_u16 (buffer, &p->tag);
+  grub_tpm2_buffer_unpack_u32 (buffer, &p->hierarchy);
+  grub_tpm2_mu_TPM2B_Unmarshal (buffer, (TPM2B*) &p->digest);
+}
+
 void
 grub_tpm2_mu_TPMS_PCR_SELECTION_Unmarshal (grub_tpm2_buffer_t buf,
                                           TPMS_PCR_SELECTION* pcrSelection)
@@ -805,3 +973,97 @@ grub_tpm2_mu_TPML_DIGEST_Unmarshal (grub_tpm2_buffer_t buf,
   for (grub_uint32_t i = 0; i < digest->count; i++)
     grub_tpm2_mu_TPM2B_DIGEST_Unmarshal (buf, &digest->digests[i]);
 }
+
+void
+grub_tpm2_mu_TPMS_SIGNATURE_RSA_Unmarshal (grub_tpm2_buffer_t buffer,
+                                           TPMS_SIGNATURE_RSA *rsa)
+{
+  grub_tpm2_buffer_unpack_u16 (buffer, &rsa->hash);
+  grub_tpm2_mu_TPM2B_Unmarshal (buffer, (TPM2B*)&rsa->sig);
+}
+
+void
+grub_tpm2_mu_TPMS_SIGNATURE_ECC_Unmarshal (grub_tpm2_buffer_t buffer,
+                                           TPMS_SIGNATURE_ECC *ecc)
+{
+  grub_tpm2_buffer_unpack_u16 (buffer, &ecc->hash);
+  grub_tpm2_mu_TPM2B_Unmarshal (buffer, (TPM2B*)&ecc->signatureR);
+  grub_tpm2_mu_TPM2B_Unmarshal (buffer, (TPM2B*)&ecc->signatureS);
+}
+
+void
+grub_tpm2_mu_TPMU_HA_Unmarshal (grub_tpm2_buffer_t buffer,
+                                TPMI_ALG_HASH hashAlg,
+                                TPMU_HA *p)
+{
+  switch (hashAlg)
+    {
+    case TPM_ALG_SHA1:
+      grub_tpm2_buffer_unpack (buffer, &p->sha1, TPM_SHA1_DIGEST_SIZE);
+      break;
+    case TPM_ALG_SHA256:
+      grub_tpm2_buffer_unpack (buffer, &p->sha256, TPM_SHA256_DIGEST_SIZE);
+      break;
+    case TPM_ALG_SHA384:
+      grub_tpm2_buffer_unpack (buffer, &p->sha384, TPM_SHA384_DIGEST_SIZE);
+      break;
+    case TPM_ALG_SHA512:
+      grub_tpm2_buffer_unpack (buffer, &p->sha512, TPM_SHA512_DIGEST_SIZE);
+      break;
+    default:
+      buffer->error = 1;
+      break;
+    }
+}
+
+void
+grub_tpm2_mu_TPMT_HA_Unmarshal (grub_tpm2_buffer_t buffer,
+                                TPMT_HA *p)
+{
+  grub_tpm2_buffer_unpack_u16 (buffer, &p->hashAlg);
+  grub_tpm2_mu_TPMU_HA_Unmarshal (buffer, p->hashAlg, &p->digest);
+}
+
+void
+grub_tpm2_mu_TPMU_SIGNATURE_Unmarshal (grub_tpm2_buffer_t buffer,
+                                       TPMI_ALG_SIG_SCHEME sigAlg,
+                                       TPMU_SIGNATURE *p)
+{
+  switch (sigAlg)
+    {
+    case TPM_ALG_RSASSA:
+      grub_tpm2_mu_TPMS_SIGNATURE_RSA_Unmarshal (buffer, (TPMS_SIGNATURE_RSA 
*)&p->rsassa);
+      break;
+    case TPM_ALG_RSAPSS:
+      grub_tpm2_mu_TPMS_SIGNATURE_RSA_Unmarshal (buffer, (TPMS_SIGNATURE_RSA 
*)&p->rsapss);
+      break;
+    case TPM_ALG_ECDSA:
+      grub_tpm2_mu_TPMS_SIGNATURE_ECC_Unmarshal (buffer, (TPMS_SIGNATURE_ECC 
*)&p->ecdsa);
+      break;
+    case TPM_ALG_ECDAA:
+      grub_tpm2_mu_TPMS_SIGNATURE_ECC_Unmarshal (buffer, (TPMS_SIGNATURE_ECC 
*)&p->ecdaa);
+      break;
+    case TPM_ALG_SM2:
+      grub_tpm2_mu_TPMS_SIGNATURE_ECC_Unmarshal (buffer, (TPMS_SIGNATURE_ECC 
*)&p->sm2);
+      break;
+    case TPM_ALG_ECSCHNORR:
+      grub_tpm2_mu_TPMS_SIGNATURE_ECC_Unmarshal (buffer, (TPMS_SIGNATURE_ECC 
*)&p->ecschnorr);
+      break;
+    case TPM_ALG_HMAC:
+      grub_tpm2_mu_TPMT_HA_Unmarshal (buffer, &p->hmac);
+      break;
+    case TPM_ALG_NULL:
+      break;
+    default:
+      buffer->error = 1;
+      break;
+    }
+}
+
+void
+grub_tpm2_mu_TPMT_SIGNATURE_Unmarshal (grub_tpm2_buffer_t buffer,
+                                       TPMT_SIGNATURE *p)
+{
+  grub_tpm2_buffer_unpack_u16 (buffer, &p->sigAlg);
+  grub_tpm2_mu_TPMU_SIGNATURE_Unmarshal (buffer, p->sigAlg, &p->signature);
+}
diff --git a/include/grub/tpm2/mu.h b/include/grub/tpm2/mu.h
index c545976db..afb842ab5 100644
--- a/include/grub/tpm2/mu.h
+++ b/include/grub/tpm2/mu.h
@@ -147,6 +147,47 @@ grub_tpm2_mu_TPM2B_SENSITIVE_CREATE_Marshal 
(grub_tpm2_buffer_t buf,
                                             const TPM2B_SENSITIVE_CREATE 
*sensitiveCreate);
 
 void
+grub_tpm2_mu_TPMU_SENSITIVE_COMPOSITE_Marshal (grub_tpm2_buffer_t buf,
+                                               const TPMI_ALG_PUBLIC type,
+                                               const TPMU_SENSITIVE_COMPOSITE 
*p);
+void
+grub_tpm2_mu_TPMT_SENSITIVE_Marshal (grub_tpm2_buffer_t buf,
+                                     const TPMT_SENSITIVE *p);
+
+void
+grub_tpm2_mu_TPM2B_SENSITIVE_Marshal (grub_tpm2_buffer_t buf,
+                                      const TPM2B_SENSITIVE *p);
+
+void
+grub_tpm2_mu_TPMS_SIGNATURE_RSA_Marshal (grub_tpm2_buffer_t buf,
+                                         const TPMS_SIGNATURE_RSA *p);
+
+void
+grub_tpm2_mu_TPMS_SIGNATURE_ECC_Marshal (grub_tpm2_buffer_t buf,
+                                         const TPMS_SIGNATURE_ECC *p);
+
+void
+grub_tpm2_mu_TPMU_HA_Marshal (grub_tpm2_buffer_t buf,
+                              const TPMI_ALG_HASH hashAlg,
+                              const TPMU_HA *p);
+
+void
+grub_tpm2_mu_TPMT_HA_Marshal (grub_tpm2_buffer_t buf,
+                              const TPMT_HA *p);
+
+void
+grub_tpm2_mu_TPMU_SIGNATURE_Marshal (grub_tpm2_buffer_t buf,
+                                     const TPMI_ALG_SIG_SCHEME sigAlg,
+                                     const TPMU_SIGNATURE *p);
+
+void
+grub_tpm2_mu_TPMT_SIGNATURE_Marshal (grub_tpm2_buffer_t buf,
+                                     const TPMT_SIGNATURE *p);
+
+void
+grub_tpm2_mu_TPMT_TK_VERIFIED_Marshal (grub_tpm2_buffer_t buf,
+                                       const TPMT_TK_VERIFIED *p);
+void
 grub_tpm2_mu_TPM2B_Unmarshal (grub_tpm2_buffer_t buf,
                              TPM2B* p);
 
@@ -277,6 +318,14 @@ void
 grub_tpm2_mu_TPMT_TK_CREATION_Unmarshal (grub_tpm2_buffer_t buf,
                                         TPMT_TK_CREATION *p);
 
+void
+grub_tpm2_mu_TPMT_TK_HASHCHECK_Unmarshal (grub_tpm2_buffer_t buf,
+                                          TPMT_TK_HASHCHECK *p);
+
+void
+grub_tpm2_mu_TPMT_TK_VERIFIED_Unmarshal (grub_tpm2_buffer_t buf,
+                                         TPMT_TK_VERIFIED *p);
+
 void
 grub_tpm2_mu_TPMS_PCR_SELECTION_Unmarshal (grub_tpm2_buffer_t buf,
                                           TPMS_PCR_SELECTION* pcrSelection);
@@ -289,4 +338,30 @@ void
 grub_tpm2_mu_TPML_DIGEST_Unmarshal (grub_tpm2_buffer_t buf,
                                    TPML_DIGEST* digest);
 
+void
+grub_tpm2_mu_TPMS_SIGNATURE_RSA_Unmarshal (grub_tpm2_buffer_t buf,
+                                           TPMS_SIGNATURE_RSA *p);
+
+void
+grub_tpm2_mu_TPMS_SIGNATURE_ECC_Unmarshal (grub_tpm2_buffer_t buf,
+                                           TPMS_SIGNATURE_ECC *p);
+
+void
+grub_tpm2_mu_TPMU_HA_Unmarshal (grub_tpm2_buffer_t buf,
+                                TPMI_ALG_HASH hashAlg,
+                                TPMU_HA *p);
+
+void
+grub_tpm2_mu_TPMT_HA_Unmarshal (grub_tpm2_buffer_t buf,
+                                TPMT_HA *p);
+
+void
+grub_tpm2_mu_TPMU_SIGNATURE_Unmarshal (grub_tpm2_buffer_t buf,
+                                       TPMI_ALG_SIG_SCHEME sigAlg,
+                                       TPMU_SIGNATURE *p);
+
+void
+grub_tpm2_mu_TPMT_SIGNATURE_Unmarshal (grub_tpm2_buffer_t buf,
+                                       TPMT_SIGNATURE *p);
+
 #endif /* ! GRUB_TPM2_MU_HEADER */
-- 
2.35.3


++++++ 0012-protectors-Add-TPM2-Key-Protector.patch -> 
0003-protectors-Add-TPM2-Key-Protector.patch ++++++
++++ 2126 lines (skipped)
++++ between 
/work/SRC/openSUSE:Factory/grub2/0012-protectors-Add-TPM2-Key-Protector.patch
++++ and 
/work/SRC/openSUSE:Factory/.grub2.new.1533/0003-protectors-Add-TPM2-Key-Protector.patch

++++++ 0003-tpm2-Implement-more-TPM2-commands.patch ++++++
>From a49c4dcbcb04078434f461ed3356c04042be461a Mon Sep 17 00:00:00 2001
From: Gary Lin <g...@suse.com>
Date: Wed, 8 Feb 2023 10:30:55 +0800
Subject: [PATCH 3/4] tpm2: Implement more TPM2 commands

This commit implements a few more TPM2 commands as the preparation for
the authorized policy support.

* TPM2_LoadExternal
  This command is added to load the external public key to verify the
  signed policy digest
* TPM2_HashSequenceStart, TPM2_SequenceUpdate, TPM2_SequenceComplete,
  and TPM2_Hash
  With those commands, we can use the TPM as a coprocessor to calculate
  the hash of a given binary blob.
* TPM2_VerifySignature
  This command verifies the given signature with the given public key
  and returns the validation ticket to authorize the policy.
* TPM2_PolicyAuthorize
  This command approves the given policy digest so that we can unseal
  the key with the newly authorized policy.

Signed-off-by: Gary Lin <g...@suse.com>
---
 grub-core/tpm2/tpm2.c                  | 424 +++++++++++++++++++++++++
 include/grub/tpm2/internal/functions.h |  57 ++++
 2 files changed, 481 insertions(+)

diff --git a/grub-core/tpm2/tpm2.c b/grub-core/tpm2/tpm2.c
index d67699a24..159353b08 100644
--- a/grub-core/tpm2/tpm2.c
+++ b/grub-core/tpm2/tpm2.c
@@ -427,6 +427,73 @@ TPM2_Load (const TPMI_DH_OBJECT parent_handle,
   return TPM_RC_SUCCESS;
 }
 
+TPM_RC
+TPM2_LoadExternal (const TPMS_AUTH_COMMAND *authCommand,
+                   const TPM2B_SENSITIVE *inPrivate,
+                   const TPM2B_PUBLIC *inPublic,
+                   const TPMI_RH_HIERARCHY hierarchy,
+                   TPM_HANDLE *objectHandle,
+                   TPM2B_NAME *name,
+                   TPMS_AUTH_RESPONSE *authResponse)
+{
+  TPM_RC rc;
+  struct grub_tpm2_buffer in;
+  struct grub_tpm2_buffer out;
+  TPM_HANDLE objectHandleTmp;
+  TPM2B_NAME nameTmp;
+  TPMS_AUTH_RESPONSE authResponseTmp;
+  TPMI_ST_COMMAND_TAG tag = authCommand ? TPM_ST_SESSIONS : TPM_ST_NO_SESSIONS;
+  TPM_RC responseCode;
+  grub_uint32_t param_size;
+
+  if (!inPublic)
+    return TPM_RC_VALUE;
+
+  if (!objectHandle)
+    objectHandle = &objectHandleTmp;
+  if (!name)
+    name = &nameTmp;
+  if (!authResponse)
+    authResponse = &authResponseTmp;
+
+  grub_memset (objectHandle, 0, sizeof (*objectHandle));
+  grub_memset (name, 0, sizeof (*name));
+  grub_memset (authResponse, 0, sizeof (*authResponse));
+
+  /* Marshal */
+  grub_tpm2_buffer_init (&in);
+  if (authCommand)
+    grub_tpm2_mu_TPMS_AUTH_COMMAND_Marshal (&in, authCommand);
+  if (inPrivate)
+    grub_tpm2_mu_TPM2B_SENSITIVE_Marshal (&in, inPrivate);
+  else
+    grub_tpm2_buffer_pack_u16 (&in, 0);
+  grub_tpm2_mu_TPM2B_PUBLIC_Marshal (&in, inPublic);
+  grub_tpm2_buffer_pack_u32 (&in, hierarchy);
+  if (in.error)
+    return TPM_RC_FAILURE;
+
+  /* Submit */
+  grub_tpm2_buffer_init (&out);
+  rc = grub_tpm2_submit_command (tag, TPM_CC_LoadExternal, &responseCode, &in, 
&out);
+  if (rc != TPM_RC_SUCCESS)
+    return rc;
+  if (responseCode != TPM_RC_SUCCESS)
+    return responseCode;
+
+  /* Unmarshal*/
+  grub_tpm2_buffer_unpack_u32 (&out, objectHandle);
+  if (tag == TPM_ST_SESSIONS)
+    grub_tpm2_buffer_unpack_u32 (&out, &param_size);
+  grub_tpm2_mu_TPM2B_Unmarshal (&out, (TPM2B*)name);
+  if (tag == TPM_ST_SESSIONS)
+    grub_tpm2_mu_TPMS_AUTH_RESPONSE_Unmarshal (&out, authResponse);
+  if (out.error)
+    return TPM_RC_FAILURE;
+
+  return TPM_RC_SUCCESS;
+}
+
 TPM_RC
 TPM2_Unseal (const TPMI_DH_OBJECT itemHandle,
             const TPMS_AUTH_COMMAND *authCommand,
@@ -759,3 +826,360 @@ TPM2_EvictControl (const TPMI_RH_PROVISION auth,
 
   return TPM_RC_SUCCESS;
 }
+
+TPM_RC
+TPM2_HashSequenceStart (const TPMS_AUTH_COMMAND *authCommand,
+                        const TPM2B_AUTH *auth,
+                        const TPMI_ALG_HASH hashAlg,
+                        TPMI_DH_OBJECT *sequenceHandle,
+                        TPMS_AUTH_RESPONSE *authResponse)
+{
+  struct grub_tpm2_buffer in;
+  struct grub_tpm2_buffer out;
+  TPMI_DH_OBJECT sequenceHandleTmp;
+  TPMS_AUTH_RESPONSE authResponseTmp;
+  TPMI_ST_COMMAND_TAG tag = authCommand ? TPM_ST_SESSIONS : TPM_ST_NO_SESSIONS;
+  TPM_RC responseCode;
+  TPM_RC rc;
+  grub_uint32_t parameterSize;
+
+  if (!auth)
+    return TPM_RC_VALUE;
+
+  if (!sequenceHandle)
+    sequenceHandle = &sequenceHandleTmp;
+  if (!authResponse)
+    authResponse = &authResponseTmp;
+
+  grub_memset (sequenceHandle, 0, sizeof (*sequenceHandle));
+  grub_memset (authResponse, 0, sizeof (*authResponse));
+
+  /* Marshal */
+  grub_tpm2_buffer_init (&in);
+  if (authCommand)
+    grub_tpm2_mu_TPMS_AUTH_COMMAND_Marshal (&in, authCommand);
+  grub_tpm2_mu_TPM2B_Marshal (&in, auth->size, auth->buffer);
+  grub_tpm2_buffer_pack_u16 (&in, hashAlg);
+  if (in.error)
+    return TPM_RC_FAILURE;
+
+  /* Submit */
+  grub_tpm2_buffer_init (&out);
+  rc = grub_tpm2_submit_command (tag, TPM_CC_HashSequenceStart, &responseCode, 
&in,
+                                 &out);
+  if (rc != TPM_RC_SUCCESS)
+    return rc;
+  if (responseCode != TPM_RC_SUCCESS)
+    return responseCode;
+
+  /* Unmarshal */
+  grub_tpm2_buffer_unpack_u32 (&out, sequenceHandle);
+  if (tag == TPM_ST_SESSIONS)
+    {
+      grub_tpm2_buffer_unpack_u32 (&out, &parameterSize);
+      grub_tpm2_mu_TPMS_AUTH_RESPONSE_Unmarshal(&out, authResponse);
+    }
+  if (out.error)
+    return TPM_RC_FAILURE;
+
+  return TPM_RC_SUCCESS;
+}
+
+TPM_RC
+TPM2_SequenceUpdate (const TPMI_DH_OBJECT sequenceHandle,
+                     const TPMS_AUTH_COMMAND *authCommand,
+                     const TPM2B_MAX_BUFFER *buffer,
+                     TPMS_AUTH_RESPONSE *authResponse)
+{
+  struct grub_tpm2_buffer in;
+  struct grub_tpm2_buffer out;
+  TPMS_AUTH_RESPONSE authResponseTmp;
+  TPM_RC responseCode;
+  TPM_RC rc;
+  grub_uint32_t parameterSize;
+
+  if (!authCommand)
+    return TPM_RC_VALUE;
+
+  if (!authResponse)
+    authResponse = &authResponseTmp;
+
+  grub_memset (authResponse, 0, sizeof (*authResponse));
+
+  /* Marshal */
+  grub_tpm2_buffer_init (&in);
+  grub_tpm2_buffer_pack_u32 (&in, sequenceHandle);
+  grub_tpm2_mu_TPMS_AUTH_COMMAND_Marshal (&in, authCommand);
+  if (buffer)
+    grub_tpm2_mu_TPM2B_Marshal (&in, buffer->size, buffer->buffer);
+  else
+    grub_tpm2_buffer_pack_u16 (&in, 0);
+  if (in.error)
+    return TPM_RC_FAILURE;
+
+  /* Submit */
+  grub_tpm2_buffer_init (&out);
+  rc = grub_tpm2_submit_command (TPM_ST_SESSIONS, TPM_CC_SequenceUpdate,
+                                 &responseCode, &in, &out);
+  if (rc != TPM_RC_SUCCESS)
+    return rc;
+  if (responseCode != TPM_RC_SUCCESS)
+    return responseCode;
+
+  /* Unmarshal */
+  grub_tpm2_buffer_unpack_u32 (&out, &parameterSize);
+  grub_tpm2_mu_TPMS_AUTH_RESPONSE_Unmarshal(&out, authResponse);
+  if (out.error)
+    return TPM_RC_FAILURE;
+
+  return TPM_RC_SUCCESS;
+}
+
+TPM_RC
+TPM2_SequenceComplete (const TPMI_DH_OBJECT sequenceHandle,
+                       const TPMS_AUTH_COMMAND *authCommand,
+                       const TPM2B_MAX_BUFFER *buffer,
+                       const TPMI_RH_HIERARCHY hierarchy,
+                       TPM2B_DIGEST *result,
+                       TPMT_TK_HASHCHECK *validation,
+                       TPMS_AUTH_RESPONSE *authResponse)
+{
+  struct grub_tpm2_buffer in;
+  struct grub_tpm2_buffer out;
+  TPM2B_DIGEST resultTmp;
+  TPMT_TK_HASHCHECK validationTmp;
+  TPMS_AUTH_RESPONSE authResponseTmp;
+  TPM_RC responseCode;
+  TPM_RC rc;
+  grub_uint32_t parameterSize;
+
+  if (!authCommand)
+    return TPM_RC_VALUE;
+
+  if (!result)
+    result = &resultTmp;
+  if (!validation)
+    validation = &validationTmp;
+  if (!authResponse)
+    authResponse = &authResponseTmp;
+
+  grub_memset (result, 0, sizeof (*result));
+  grub_memset (validation, 0, sizeof (*validation));
+  grub_memset (authResponse, 0, sizeof (*authResponse));
+
+  /* Marshal */
+  grub_tpm2_buffer_init (&in);
+  grub_tpm2_buffer_pack_u32 (&in, sequenceHandle);
+  grub_tpm2_mu_TPMS_AUTH_COMMAND_Marshal (&in, authCommand);
+  if (buffer)
+    grub_tpm2_mu_TPM2B_Marshal (&in, buffer->size, buffer->buffer);
+  else
+    grub_tpm2_buffer_pack_u16 (&in, 0);
+  grub_tpm2_buffer_pack_u32 (&in, hierarchy);
+
+  if (in.error)
+    return TPM_RC_FAILURE;
+
+  /* Submit */
+  grub_tpm2_buffer_init (&out);
+  rc = grub_tpm2_submit_command (TPM_ST_SESSIONS, TPM_CC_SequenceComplete,
+                                 &responseCode, &in, &out);
+  if (rc != TPM_RC_SUCCESS)
+    return rc;
+  if (responseCode != TPM_RC_SUCCESS)
+    return responseCode;
+
+  /* Unmarshal */
+  grub_tpm2_buffer_unpack_u32 (&out, &parameterSize);
+  grub_tpm2_mu_TPM2B_DIGEST_Unmarshal (&out, result);
+  grub_tpm2_mu_TPMT_TK_HASHCHECK_Unmarshal (&out, validation);
+  grub_tpm2_mu_TPMS_AUTH_RESPONSE_Unmarshal(&out, authResponse);
+  if (out.error)
+    return TPM_RC_FAILURE;
+
+  return TPM_RC_SUCCESS;
+}
+
+TPM_RC
+TPM2_Hash (const TPMS_AUTH_COMMAND *authCommand,
+           const TPM2B_MAX_BUFFER *data,
+           const TPMI_ALG_HASH hashAlg,
+           const TPMI_RH_HIERARCHY hierarchy,
+           TPM2B_DIGEST *outHash,
+           TPMT_TK_HASHCHECK *validation,
+           TPMS_AUTH_RESPONSE *authResponse)
+{
+  TPM_RC rc;
+  struct grub_tpm2_buffer in;
+  struct grub_tpm2_buffer out;
+  TPMS_AUTH_RESPONSE authResponseTmp;
+  TPM2B_DIGEST outHashTmp;
+  TPMT_TK_HASHCHECK validationTmp;
+  TPMI_ST_COMMAND_TAG tag = authCommand ? TPM_ST_SESSIONS : TPM_ST_NO_SESSIONS;
+  TPM_RC responseCode;
+  grub_uint32_t param_size;
+
+  if (hashAlg == TPM_ALG_NULL)
+    return TPM_RC_VALUE;
+
+  if (!outHash)
+    outHash = &outHashTmp;
+  if (!validation)
+    validation = &validationTmp;
+  if (!authResponse)
+    authResponse = &authResponseTmp;
+
+  grub_memset (outHash, 0, sizeof (*outHash));
+  grub_memset (validation, 0, sizeof (*validation));
+  grub_memset (authResponse, 0, sizeof (*authResponse));
+
+  /* Marshal */
+  grub_tpm2_buffer_init (&in);
+  if (authCommand)
+    grub_tpm2_mu_TPMS_AUTH_COMMAND_Marshal (&in, authCommand);
+  if (data)
+    grub_tpm2_mu_TPM2B_Marshal (&in, data->size, data->buffer);
+  else
+    grub_tpm2_buffer_pack_u16 (&in, 0);
+  grub_tpm2_buffer_pack_u16 (&in, hashAlg);
+  grub_tpm2_buffer_pack_u32 (&in, hierarchy);
+  if (in.error)
+    return TPM_RC_FAILURE;
+
+  /* Submit */
+  grub_tpm2_buffer_init (&out);
+  rc = grub_tpm2_submit_command (tag, TPM_CC_Hash, &responseCode, &in, &out);
+  if (rc != TPM_RC_SUCCESS)
+    return rc;
+  if (responseCode != TPM_RC_SUCCESS)
+    return responseCode;
+
+  /* Unmarshal*/
+  if (tag == TPM_ST_SESSIONS)
+    grub_tpm2_buffer_unpack_u32 (&out, &param_size);
+  grub_tpm2_mu_TPM2B_DIGEST_Unmarshal (&out, outHash);
+  grub_tpm2_mu_TPMT_TK_HASHCHECK_Unmarshal (&out, validation);
+  if (tag == TPM_ST_SESSIONS)
+    grub_tpm2_mu_TPMS_AUTH_RESPONSE_Unmarshal (&out, authResponse);
+  if (out.error)
+    return TPM_RC_FAILURE;
+
+  return TPM_RC_SUCCESS;
+}
+
+TPM_RC
+TPM2_VerifySignature (const TPMI_DH_OBJECT keyHandle,
+                      const TPMS_AUTH_COMMAND *authCommand,
+                      const TPM2B_DIGEST *digest,
+                      const TPMT_SIGNATURE *signature,
+                      TPMT_TK_VERIFIED *validation,
+                      TPMS_AUTH_RESPONSE *authResponse)
+{
+  TPM_RC rc;
+  struct grub_tpm2_buffer in;
+  struct grub_tpm2_buffer out;
+  TPMS_AUTH_RESPONSE authResponseTmp;
+  TPMI_ST_COMMAND_TAG tag = authCommand ? TPM_ST_SESSIONS : TPM_ST_NO_SESSIONS;
+  TPMT_TK_VERIFIED validationTmp;
+  TPM_RC responseCode;
+  grub_uint32_t param_size;
+
+  if (!digest || !signature)
+    return TPM_RC_VALUE;
+
+  if (!validation)
+    validation = &validationTmp;
+  if (!authResponse)
+    authResponse = &authResponseTmp;
+
+  grub_memset (validation, 0, sizeof (*validation));
+  grub_memset (authResponse, 0, sizeof (*authResponse));
+
+  /* Marshal */
+  grub_tpm2_buffer_init (&in);
+  if (authCommand)
+    grub_tpm2_mu_TPMS_AUTH_COMMAND_Marshal (&in, authCommand);
+  grub_tpm2_buffer_pack_u32 (&in, keyHandle);
+  grub_tpm2_mu_TPM2B_Marshal (&in, digest->size, digest->buffer);
+  grub_tpm2_mu_TPMT_SIGNATURE_Marshal (&in, signature);
+  if (in.error)
+    return TPM_RC_FAILURE;
+
+  /* Submit */
+  grub_tpm2_buffer_init (&out);
+  rc = grub_tpm2_submit_command (tag, TPM_CC_VerifySignature, &responseCode, 
&in, &out);
+  if (rc != TPM_RC_SUCCESS)
+    return rc;
+  if (responseCode != TPM_RC_SUCCESS)
+    return responseCode;
+
+  /* Unmarshal*/
+  if (tag == TPM_ST_SESSIONS)
+    grub_tpm2_buffer_unpack_u32 (&out, &param_size);
+  grub_tpm2_mu_TPMT_TK_VERIFIED_Unmarshal (&out, validation);
+  if (tag == TPM_ST_SESSIONS)
+    grub_tpm2_mu_TPMS_AUTH_RESPONSE_Unmarshal (&out, authResponse);
+  if (out.error)
+    return TPM_RC_FAILURE;
+
+  return TPM_RC_SUCCESS;
+}
+
+TPM_RC
+TPM2_PolicyAuthorize (const TPMI_SH_POLICY policySession,
+                      const TPMS_AUTH_COMMAND *authCommand,
+                      const TPM2B_DIGEST *approvedPolicy,
+                      const TPM2B_NONCE *policyRef,
+                      const TPM2B_NAME *keySign,
+                      const TPMT_TK_VERIFIED *checkTicket,
+                      TPMS_AUTH_RESPONSE *authResponse)
+{
+  TPM_RC rc;
+  struct grub_tpm2_buffer in;
+  struct grub_tpm2_buffer out;
+  TPMS_AUTH_RESPONSE authResponseTmp;
+  TPMI_ST_COMMAND_TAG tag = authCommand ? TPM_ST_SESSIONS : TPM_ST_NO_SESSIONS;
+  TPM_RC responseCode;
+  grub_uint32_t param_size;
+
+  if (!approvedPolicy || !keySign || !checkTicket)
+    return TPM_RC_VALUE;
+
+  if (!authResponse)
+    authResponse = &authResponseTmp;
+
+  grub_memset (authResponse, 0, sizeof (*authResponse));
+
+  /* Marshal */
+  grub_tpm2_buffer_init (&in);
+  grub_tpm2_buffer_pack_u32 (&in, policySession);
+  if (authCommand)
+    grub_tpm2_mu_TPMS_AUTH_COMMAND_Marshal (&in, authCommand);
+  grub_tpm2_mu_TPM2B_Marshal (&in, approvedPolicy->size, 
approvedPolicy->buffer);
+  if (policyRef)
+    grub_tpm2_mu_TPM2B_Marshal (&in, policyRef->size, policyRef->buffer);
+  else
+    grub_tpm2_buffer_pack_u16 (&in, 0);
+  grub_tpm2_mu_TPM2B_Marshal (&in, keySign->size, keySign->name);
+  grub_tpm2_mu_TPMT_TK_VERIFIED_Marshal (&in, checkTicket);
+  if (in.error)
+    return TPM_RC_FAILURE;
+
+  /* Submit */
+  grub_tpm2_buffer_init (&out);
+  rc = grub_tpm2_submit_command (tag, TPM_CC_PolicyAuthorize, &responseCode, 
&in, &out);
+  if (rc != TPM_RC_SUCCESS)
+    return rc;
+  if (responseCode != TPM_RC_SUCCESS)
+    return responseCode;
+
+  /* Unmarshal*/
+  if (tag == TPM_ST_SESSIONS)
+    grub_tpm2_buffer_unpack_u32 (&out, &param_size);
+  if (tag == TPM_ST_SESSIONS)
+    grub_tpm2_mu_TPMS_AUTH_RESPONSE_Unmarshal (&out, authResponse);
+  if (out.error)
+    return TPM_RC_FAILURE;
+
+  return TPM_RC_SUCCESS;
+}
diff --git a/include/grub/tpm2/internal/functions.h 
b/include/grub/tpm2/internal/functions.h
index 9380f26a2..67b78fab8 100644
--- a/include/grub/tpm2/internal/functions.h
+++ b/include/grub/tpm2/internal/functions.h
@@ -70,6 +70,15 @@ TPM2_Load (const TPMI_DH_OBJECT parent_handle,
           TPM2B_NAME *name,
           TPMS_AUTH_RESPONSE *authResponse);
 
+TPM_RC
+TPM2_LoadExternal (const TPMS_AUTH_COMMAND *authCommand,
+                   const TPM2B_SENSITIVE *inPrivate,
+                   const TPM2B_PUBLIC *inPublic,
+                   const TPMI_RH_HIERARCHY hierarchy,
+                   TPM_HANDLE *objectHandle,
+                   TPM2B_NAME *name,
+                   TPMS_AUTH_RESPONSE *authResponse);
+
 TPM_RC
 TPM2_Unseal (const TPMI_DH_OBJECT item_handle,
             const TPMS_AUTH_COMMAND *authCommand,
@@ -114,4 +123,52 @@ TPM2_EvictControl (const TPMI_RH_PROVISION auth,
                   const TPMI_DH_PERSISTENT persistentHandle,
                   TPMS_AUTH_RESPONSE *authResponse);
 
+TPM_RC
+TPM2_HashSequenceStart (const TPMS_AUTH_COMMAND *authCommand,
+                        const TPM2B_AUTH *auth,
+                        const TPMI_ALG_HASH hashAlg,
+                        TPMI_DH_OBJECT *sequenceHandle,
+                        TPMS_AUTH_RESPONSE *authResponse);
+
+TPM_RC
+TPM2_SequenceUpdate (const TPMI_DH_OBJECT sequenceHandle,
+                     const TPMS_AUTH_COMMAND *authCommand,
+                     const TPM2B_MAX_BUFFER *buffer,
+                     TPMS_AUTH_RESPONSE *authResponse);
+
+TPM_RC
+TPM2_SequenceComplete (const TPMI_DH_OBJECT sequenceHandle,
+                       const TPMS_AUTH_COMMAND *authCommand,
+                       const TPM2B_MAX_BUFFER *buffer,
+                       const TPMI_RH_HIERARCHY hierarchy,
+                       TPM2B_DIGEST *result,
+                       TPMT_TK_HASHCHECK *validation,
+                       TPMS_AUTH_RESPONSE *authResponse);
+
+TPM_RC
+TPM2_Hash (const TPMS_AUTH_COMMAND *authCommand,
+           const TPM2B_MAX_BUFFER *data,
+           const TPMI_ALG_HASH hashAlg,
+           const TPMI_RH_HIERARCHY hierarchy,
+           TPM2B_DIGEST *outHash,
+           TPMT_TK_HASHCHECK *validation,
+           TPMS_AUTH_RESPONSE *authResponse);
+
+TPM_RC
+TPM2_VerifySignature (const TPMI_DH_OBJECT keyHandle,
+                      const TPMS_AUTH_COMMAND *authCommand,
+                      const TPM2B_DIGEST *digest,
+                      const TPMT_SIGNATURE *signature,
+                      TPMT_TK_VERIFIED *validation,
+                      TPMS_AUTH_RESPONSE *authResponse);
+
+TPM_RC
+TPM2_PolicyAuthorize (const TPMI_SH_POLICY policySession,
+                      const TPMS_AUTH_COMMAND *authCommand,
+                      const TPM2B_DIGEST *approvedPolicy,
+                      const TPM2B_NONCE *policyRef,
+                      const TPM2B_NAME *keySign,
+                      const TPMT_TK_VERIFIED *checkTicket,
+                      TPMS_AUTH_RESPONSE *authResponse);
+
 #endif /* ! GRUB_TPM2_INTERNAL_FUNCTIONS_HEADER */
-- 
2.35.3


++++++ 0013-cryptodisk-Support-key-protectors.patch -> 
0004-cryptodisk-Support-key-protectors.patch ++++++

++++++ 0004-tpm2-Support-authorized-policy.patch ++++++
>From d6e2d32d53d9a1aac2383fc6c075f3827111b643 Mon Sep 17 00:00:00 2001
From: Gary Lin <g...@suse.com>
Date: Thu, 6 Apr 2023 16:00:25 +0800
Subject: [PATCH 4/4] tpm2: Support authorized policy

TPM2_PolicyAuthorize is the key command to support authorized policy
which allows the users to sign TPM policies with their own keys.

Per TPM 2.0 Key File(*), CommandPolicy for TPM2_PolicyAuthorize
comprises 'TPM2B_PUBLIC pubkey', 'TPM2B_DIGEST policy_ref', and
'TPMT_SIGNATURE signature'. This commit unmarshals those data
structures, fetches the current policy digest, hashes the policy digest
with the hash algorithm written in 'signature', and then verifies
'signature' with 'pubkey'. If everything goes well, TPM2_PolicyAuthorize
is invoked to authorize the signed policy.

(*) https://www.hansenpartnership.com/draft-bottomley-tpm2-keys.html

Signed-off-by: Gary Lin <g...@suse.com>
---
 grub-core/tpm2/module.c | 98 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 98 insertions(+)

diff --git a/grub-core/tpm2/module.c b/grub-core/tpm2/module.c
index 5274296b7..e5235c2ac 100644
--- a/grub-core/tpm2/module.c
+++ b/grub-core/tpm2/module.c
@@ -454,6 +454,101 @@ grub_tpm2_protector_policypcr (TPMI_SH_AUTH_SESSION 
session,
   return GRUB_ERR_NONE;
 }
 
+static grub_err_t
+grub_tpm2_protector_policyauthorize (TPMI_SH_AUTH_SESSION session,
+                                    struct grub_tpm2_buffer *cmd_buf)
+{
+  TPM2B_PUBLIC pubkey;
+  TPM2B_DIGEST policy_ref;
+  TPMT_SIGNATURE signature;
+  TPM2B_DIGEST pcr_policy;
+  TPM2B_DIGEST pcr_policy_hash;
+  TPMI_ALG_HASH sig_hash;
+  TPMT_TK_VERIFIED verification_ticket;
+  TPM_HANDLE pubkey_handle = 0;
+  TPM2B_NAME pubname;
+  TPM_RC rc;
+  grub_err_t err;
+
+  grub_tpm2_mu_TPM2B_PUBLIC_Unmarshal (cmd_buf, &pubkey);
+  grub_tpm2_mu_TPM2B_DIGEST_Unmarshal (cmd_buf, &policy_ref);
+  grub_tpm2_mu_TPMT_SIGNATURE_Unmarshal (cmd_buf, &signature);
+  if (cmd_buf->error != 0)
+    {
+      err = GRUB_ERR_BAD_ARGUMENT;
+      return grub_error (err, N_("Failed to unmarshal the buffer for "
+                                "TPM2_PolicyAuthorize"));
+    }
+
+  /* Retrieve Policy Digest */
+  rc = TPM2_PolicyGetDigest (session, NULL, &pcr_policy, NULL);
+  if (rc != TPM_RC_SUCCESS)
+    {
+      err = GRUB_ERR_BAD_DEVICE;
+      grub_error (err, N_("Failed to get policy digest (TPM error: 0x%x)."),
+                 rc);
+      return err;
+    }
+
+  /* Calculate the digest of the polcy for VerifySignature */
+  sig_hash = TPMT_SIGNATURE_get_hash_alg (&signature);
+  if (sig_hash == TPM_ALG_NULL)
+    {
+      err = GRUB_ERR_BAD_ARGUMENT;
+      grub_error (err, N_("Failed to get the hash algorithm of the 
signature"));
+      return err;
+    }
+  rc = TPM2_Hash (NULL, (TPM2B_MAX_BUFFER *)&pcr_policy, sig_hash,
+                 TPM_RH_NULL, &pcr_policy_hash, NULL, NULL);
+  if (rc != TPM_RC_SUCCESS)
+    {
+      err = GRUB_ERR_BAD_DEVICE;
+      grub_error (err, N_("Failed to create PCR policy hash (TPM2_Hash failed "
+                         "with TSS/TPM error %u)"), rc);
+      return err;
+    }
+
+  /* Load the public key */
+  rc = TPM2_LoadExternal (NULL, NULL, &pubkey, TPM_RH_OWNER,
+                         &pubkey_handle, &pubname, NULL);
+  if (rc != TPM_RC_SUCCESS)
+    {
+      err = GRUB_ERR_BAD_DEVICE;
+      grub_error (err, N_("Failed to load public key (TPM2_LoadExternal failed 
"
+                         "with TSS/TPM error %u)"), rc);
+      return err;
+    }
+
+  /* Verify the signature against the public key and the policy digest */
+  rc = TPM2_VerifySignature (pubkey_handle, NULL, &pcr_policy_hash, &signature,
+                            &verification_ticket, NULL);
+  if (rc != TPM_RC_SUCCESS)
+    {
+      err = GRUB_ERR_BAD_DEVICE;
+      grub_error (err, N_("Failed to verify signature (TPM2_VerifySignature "
+                         "failed with TSS/TPM error %u)"), rc);
+      goto error;
+    }
+
+  /* Authorize the signed policy with the public key and the verification 
ticket */
+  rc = TPM2_PolicyAuthorize (session, NULL, &pcr_policy, &policy_ref, &pubname,
+                            &verification_ticket, NULL);
+  if (rc != TPM_RC_SUCCESS)
+    {
+      err = GRUB_ERR_BAD_DEVICE;
+      grub_error (err, N_("Failed to authorize PCR policy 
(TPM2_PolicyAuthorize "
+                         "failed with TSS/TPM error: 0x%u).\n"), rc);
+      goto error;
+    }
+
+  err = GRUB_ERR_NONE;
+
+error:
+  TPM2_FlushContext (pubkey_handle);
+
+  return err;
+}
+
 static grub_err_t
 grub_tpm2_protector_enforce_policy (tpm2key_policy_t policy, 
TPMI_SH_AUTH_SESSION session)
 {
@@ -473,6 +568,9 @@ grub_tpm2_protector_enforce_policy (tpm2key_policy_t 
policy, TPMI_SH_AUTH_SESSIO
     case TPM_CC_PolicyPCR:
       err = grub_tpm2_protector_policypcr (session, &buf);
       break;
+    case TPM_CC_PolicyAuthorize:
+      err = grub_tpm2_protector_policyauthorize (session, &buf);
+      break;
     default:
       return grub_error (GRUB_ERR_BAD_ARGUMENT,
                         N_("Unknown TPM Command: 0x%x"), policy->cmd_code);
-- 
2.35.3


++++++ 0014-util-grub-protect-Add-new-tool.patch -> 
0005-util-grub-protect-Add-new-tool.patch ++++++
++++ 1411 lines (skipped)
++++ between 
/work/SRC/openSUSE:Factory/grub2/0014-util-grub-protect-Add-new-tool.patch
++++ and 
/work/SRC/openSUSE:Factory/.grub2.new.1533/0005-util-grub-protect-Add-new-tool.patch


++++++ grub-read-pcr.patch ++++++
--- /var/tmp/diff_new_pack.3qedkw/_old  2023-04-30 16:07:55.636208002 +0200
+++ /var/tmp/diff_new_pack.3qedkw/_new  2023-04-30 16:07:55.640208026 +0200
@@ -42,7 +42,7 @@
 +  pcr = &o->pcrSelections[o->count++];
 +  pcr->hash = algo;
 +  pcr->sizeOfSelect = 3;
-+  pcr->pcrSelect[TPM2_PCR_TO_SELECT(pcrIndex)] |= TPM2_PCR_TO_BIT(pcrIndex);
++  TPMS_PCR_SELECTION_SelectPCR (pcr, pcrIndex);
 +}
 +
 +struct grub_tpm_hash_info {

Reply via email to