Automatic Disk Unlock with TPM2
v18 cover Automatic Disk Unlock with TPM2
GIT repo for v18: https://github.com/lcp/grub2/tree/tpm2-unlock-v18
This patch series is based on "Automatic TPM Disk Unlock"(*1) posted by Hernan Gatta to introduce the key protector framework and TPM2 stack to GRUB2, and this could be a useful feature for the systems to implement full disk encryption.
To support TPM 2.0 Key File format(*2), patch 1~6,8-10 are grabbed from Daniel Axtens's "appended signature secure boot support" (*3) to import libtasn1 into grub2. Besides, the libtasn1 version is upgraded to 4.19.0 instead of 4.16.0 in the original patch.
Patch 7 fixes a potential buffer overrun in libtasn1.
(https://gitlab.com/gnutls/libtasn1/-/issues/49)
Patch 11 adds the document for libtasn1 and the steps to upgrade the library.
Patch 12~18 are based on Hernan Gatta's patches with the follow-up fixes and improvements:
- Converting 8 spaces into 1 tab
- Merging the minor build fix from Michael Chang
- Replacing "lu" with "PRIuGRUB_SIZE" for grub_dprintf
- Adding "enable = efi" to the tpm2 module in grub-core/Makefile.core.def
- Rebasing "cryptodisk: Support key protectors" to the git master
- Removing the measurement on the sealed key
- Based on the patch from Olaf Kirch <[email protected]>
- Adjusting the input parameters of TPM2_EvictControl to match the order in "TCG TPM2 Part3 Commands"
- Declaring the input arguments of TPM2 functions as const
- Resending TPM2 commands on TPM_RC_RETRY
- Adding checks for the parameters of TPM2 commands
- Packing the missing authorization command for TPM2_PCR_Read
- Tweaking the TPM2 command functions to allow some parameters to be NULL so that we don't have to declare empty variables
- Using grub_cpu_to_be*() in the TPM2 stack instead of grub_swap_bytes*() which may cause problems in big-indian machines
- Changing the short name of "--protector" of "cryptomount" from "-k" to "-P" to avoid the conflict with "--key-file"
- Supporting TPM 2.0 Key File Format besides the raw sealed key
- Adding the external libtasn1 dependency to grub-protect to write the TPM 2.0 Key files
- Extending the TPM2 TSS stack to support authorized policy
Patch 19 implements the authorized policy support.
Patch 20 implements the missing NV index mode. (Thanks to Patrick Colp)
Patch 21 improves the 'cryptomount' command to fall back to the passphrase mode when the key protector fails to unlock the encrypted partition. (Another patch from Patrick Colp)
Patch 22 and 23 fix the potential security issues spotted by Fabian Vogt.
Patch 24 and 25 implement the TPM2 key unsealing testcases.
To utilize the TPM2 key protector to unlock the encrypted partition (sdb1), here are the sample steps:
1. Add an extra random key for LUKS (luks-key)
$ dd if=/dev/urandom of=luks-key bs=1 count=32 $ sudo cryptsetup luksAddKey /dev/sdb1 luks-key --pbkdf=pbkdf2
2. Seal the key
$ sudo grub-protect --action=add \
--protector=tpm2 \
--tpm2key \
--tpm2-keyfile=luks-key \
--tpm2-outfile=/boot/efi/boot/grub2/sealed.tpm3. Unseal the key with the proper commands in grub.cfg:
tpm2_key_protector_init --tpm2key=(hd0,gpt1)/boot/grub2/sealed.tpm cryptomount -u <SDB1_UUID> -P tpm2
(*1) https://lists.gnu.org/archive/html/grub-devel/2022-02/msg00006.html
(*2) https://www.hansenpartnership.com/draft-bottomley-tpm2-keys.html
(*3) https://lists.gnu.org/archive/html/grub-devel/2021-06/msg00044.html
v18:
- Updating the steps to import libtasn1
- Importing test cases from libtasn1 and then applying the follow-up patch by autogen.sh
- The patch files in patch 3~8 are created with the following repo
against the libtasn1-4.19.0-base-v2 tag:
https://github.com/lcp/grub2/tree/import-libtasn1-4.19.0-v2- Splitting the grub compatibility patch for libtasn1
- Moving the TSS2 code to grub-core/lib/tss2 and renaming grub_tpm2_mu_*() functions to grub_Tss2_MU_*()
- Splitting the TSS2 patch into 3 patches
- Fixing the types of TPMA_SESSION, TPMA_OBJECT, and TPMA_LOCALITY
- Renaming the tpm2 module to tpm2_key_protector
- Adding more comments to asn1_read_uint32() and defining the lower and upper bounds for tpm2key elements
- Also fixing a bug that allows 100 elements in the key file
- Fixing the copyright headers
- Fixing the coding style
v17:
- https://lists.gnu.org/archive/html/grub-devel/2024-06/msg00108.html
- GIT repo: https://github.com/lcp/grub2/tree/tpm2-unlock-v17
- Fixing the missing space in strncat()
- Updating the steps to import libtasn1
- Moving libtasn1.h to grub-core/lib/libtasn1/ and fixing the affected patches
- libtasn1.h is included in tpm2key.h, so there is no need to include the header again in module.c and tpm2key.c.
- Applying the libtasn1 patches in a different way
- Instead of applying the patches directly in the grub2 source code, libtasn1 is copied to grub-core/lib/libtasn1-grub by autogen.sh and then the script applies the libtasn1 patches to libtasn1-grub.
- The patch files in patch 3, 4, and 5 are created by the following repo against the libtasn1-4.19.0-base tag.
https://github.com/lcp/grub2/tree/import-libtasn1-4.19.0
- Correcting the description of the tpm2_test commit to replace swtpm_cuse with "swtpm chardev"
v16:
- https://lists.gnu.org/archive/html/grub-devel/2024-05/msg00093.html
- GIT repo: https://github.com/lcp/grub2/tree/tpm2-unlock-v16
- Rebasing patch 6, 12, and 16 to fix the conflicts with the latest master branch
- Changes in cryptodisk:
- Disallowing that both OPTION_KEYFILE and OPTION_PROTECTOR are set since the key data for "--key-file" would be overwritten by the key protectors
- Resetting the cargs key data when the key from a key protector doesn't work for the disk to ensure the passphrase prompt will be triggered later
- Adding the comment to address why grub_errno is only cleared for
cargs->key_len == 0
v15:
- https://lists.gnu.org/archive/html/grub-devel/2024-05/msg00059.html
- GIT repo: https://github.com/lcp/grub2/tree/tpm2-unlock-v15
- Changes in tpm2_test
- Quoting the variables which contain file paths
- Correcting the exit code for several commands
- Writing the verification text directly into the LUKS device
- Amending the waiting loop for swtpm
- Replacing exit with return in tpm2_seal_unseal() and
tpm2_seal_unseal_nv()
- Collecting the parameters for the SRK mode testcases in an array and invoking tpm2_seal_unseal() with a for loop
- Moving the tpm2-tools commands for the NV index mode to a separate function
- Using tpm2_evictcontrol to remove the object from the NV index to match the key sealing commands
- Printing the test results
- Printing error messages to stderr
v14:
- https://lists.gnu.org/archive/html/grub-devel/2024-05/msg00011.html
- GIT repo: https://github.com/lcp/grub2/tree/tpm2-unlock-v14
- Addressing the libtasn1 patches more in the document
- Various improvements in tpm2_test
- Verifying the test inside the LUKS device
- Improving the return status checks and the waiting loop for swtpm
- Fixing the portability issues
- Making all variables braced
- Renaming grub-emu-opts to --emu-opts (grub-shell)
v13:
- https://lists.gnu.org/archive/html/grub-devel/2024-04/msg00155.html
- GIT repo: https://github.com/lcp/grub2/tree/tpm2-unlock-v13
- Fixing typos and a few multi-line comments
- Improving the conditional checks for the arguments of tpm2_key_protector_init
- Updating to the latest TPM 2.0 Key File format
- Adding the new optional fields: description and rsaParent
- Handling "rsaParent == TRUE" when unsealing the tpm2key
- Setting "rsaParent" to "TRUE" when sealing the key with RSA SRK
- Removing non-standard SRKs: RSA3072, RSA4096, ECC_NIST_P384, ECC_NIST_P521, and ECC_SM2_P256
- Adding more error messages to grub-protect
- Improving the error checking for the swtpm chardev instance
- Exiting the tpm2_test script if grub-protect failed to seal the key
v12:
- https://lists.gnu.org/archive/html/grub-devel/2024-04/msg00108.html
- GIT repo: https://github.com/lcp/grub2/tree/tpm2-unlock-v12
- Fixing typos and indentation
- Removing the unused TPM commands: TPM2_HashSequenceStart, TPM2_SequenceUpdate, and TPM2_SequenceComplete,
- Following the TCG EK templates to set the parameters of SRK
- Removing ECC_BN_P256 and ECC_BN_P638 from the SRK algorithm list since those two algorithms are not mentioned in the TCG EK templates
- Updating the help messages of the tpm2 module and grub-protect
- Removing the unnecessary NULL checks
- Adding the manpage for grub-protect
- Replacing grub_crypto_hash() with TPM2_Hash() in grub-protect to support SHA384 PCR banks
- Using 'swtpm chardev' to start swtpm instead of 'swtpm_cuse' since some distros may not build swtpm with cuse
- Adding a new testcase without specifying the SRK type to test the default SRK settings
- Amending tpm2_test to remove the duplicate error checking code
- Silencing the tpm2-tools commands in tpm2_test
- Fixing the exit trap of tpm2_test to removing the working directory on success
v11:
- https://lists.gnu.org/archive/html/grub-devel/2024-04/msg00052.html
- GIT repo: https://github.com/lcp/grub2/tree/tpm2-unlock-v11
- Adding the missing default: handlers in grub-core/tpm2/mu.c
- Updating the help messages and commit messages to reflect the change of the default SRK algorithm (RSA2048 -> ECC_NIST_P256)
- Adding the testcase for the NV index mode
v10:
- https://lists.gnu.org/archive/html/grub-devel/2024-04/msg00019.html
- GIT repo: https://github.com/lcp/grub2/tree/tpm2-unlock-v10
- Fixing the coverity issues: CID 435775, CID 435771, CID 435770, CID 435769, CID 435767, CID 435761
https://lists.gnu.org/archive/html/grub-devel/2024-02/txtKIuUb5lf3O.txt
- Fixing the potential memory leak (CID 435775)
- Removing the unnecessary grub_protect_get_grub_drive_for_file() from
util/grub-protect.c (CID 435771)
- Using the grub_tpm2_mu_TPM2B_*_Unmarshal functions to unmarshal the
TPM2B structs instead of a generic grub_tpm2_mu_TPM2B_Unmarshal
(CID 435770)
- Fixing Null pointer dereference (CID 435769)
- Adding bound checks to grub_tpm2_mu_TPML_DIGEST_Unmarshal()
(CID 435767) - Improving the check for the return value of ftell() (CID 435761)
- Adding a quick fix for CID 435762
- Removing the empty ending line in tests/asn1_test.in
- Fixing docs/grub-dev.texi and updating the libtasn1 patches in grub-core/lib/libtasn1-patches/
- Merging all the TPM2 TSS stack patches into one to reduce the total patch number
- Switching the default asymmetric algorithm from RSA2048 to TPM_ECC_NIST_P256 for the faster key generation
- Adding the fallback SRK templates to try a few more SRK types in case grub2 failed to associate the sealed key with the SRK in the persistent handle or the default SRK
- Improving the test script to add tests for the persistent handle and the fallback SRKs
v9:
- https://lists.gnu.org/archive/html/grub-devel/2024-02/msg00007.html
- GIT repo: https://github.com/lcp/grub2/tree/tpm2-unlock-v9
- Introducing c-ctype.h to posix_wrap and implementing strncat
- Adding the descriptive comments to the disabled code in libtasn1
- Replacing strcat with the bound-checked _asn1_str_cat in libtasn1 and including c-ctype.h directly
- Integrating the asn1 testcases into "functional_test"
- Updating the libtasn1 patches mentioned in the documentation
- Moving the key protector to a module
- Amending configure.ac to enable/disable grub-protect
- Fixing an timeout issue in the tpm2_test script by feeding the config through stdin
v8:
- https://lists.gnu.org/archive/html/grub-devel/2024-01/msg00013.html
- GIT repo: https://github.com/lcp/grub2/tree/tpm2-unlock-v8
- Introducing TPM device support to grub-emu and adding the TPM key unsealing testcase
v7:
- https://lists.gnu.org/archive/html/grub-devel/2023-11/msg00127.html
- GIT repo: https://github.com/lcp/grub2/tree/tpm2-unlock-v7
- Stopping reading SRK from the well-known persistent handle (TPM2_SRK_HANDLE, i.e. 0x81000001) by default since the persistent handle may be created by other OS and causes unsealing failure due to SRK mismatching
- The user now has to specify the persistent handle with "--srk" explicitly.
- Utilizing grub_error() to print more error messages
- Unifying the format of the error messages from TPM2 commands
v6:
- https://lists.gnu.org/archive/html/grub-devel/2023-10/msg00026.html
- GIT repo: https://github.com/lcp/grub2/tree/tpm2-unlock-v6
- Supporting more SRK types than RSA2048 and ECC_NIST_P256
- Documenting SHA512 as the supported PCR bank type in the tpm2 protector
- Removing the redundant error message for grub_tpm2_protector_srk_get() since it may overwrite the real error message.
- Updating the supported SRK types and PCR bank types in grub-protect
- Removing the unused type: TPM2_ECC_CURVE
v5:
- https://lists.gnu.org/archive/html/grub-devel/2023-08/msg00113.html
- GIT repo: https://github.com/lcp/grub2/tree/tpm2-unlock-v5
- Rebasing to the latest git HEAD and improving the commit messages
- Implementing authorized poilcy support
- Implementing NV index mode
- Improving the 'cryptomount' command to fall back to the passphrase mode when the key protector fails to unlock the encrypted partition
- Fixing the potential security issues
v4:
- https://lists.gnu.org/archive/html/grub-devel/2023-04/msg00104.html
- GIT repo: https://github.com/lcp/grub2/tree/tpm2-unlock-v4
- Improving the error condition checks in cryptodisk.c
- Moving the code to unseal with the standalone policy sequence below the code for authpolicy sequence
- The standalone policy sequence was mistakenly prepended to to the authpolicy sequence with grub_list_push() while it should be appended.
- Pushing the error messages from the authpolicy sequence into the grub_error stack so that we can list all errors from the sequence
- Improving the error messages in the TPM2 protector
- Amending the calculation of the max string lengths of 'Policy', 'CommandCode' and 'CommandPolicy'
- Skipping the error path in grub_tpm2key_get_authpolicy_seq() on success to avoid freeing the authpolicy sequence
v3:
- https://lists.gnu.org/archive/html/grub-devel/2023-04/msg00055.html
- GIT repo: https://github.com/lcp/grub2/tree/tpm2-unlock-v3
- Adding the document for libtasn1
- Improving the error condition checks
ex: "if (!ptr)" ==> "if (ptr == NULL)"
"if (err)" ==> "if (err != GRUB_ERR_NONE)"
"if (rc)" ==> "if (rc != TPM_RC_SUCCESS)"- Supporting the "TPMPolicy" and "TPMAuthPolicy" sequence in the TPM 2.0 key File
- Refactoring the key recover function to support "TPMPolicy" and "TPMAuthPolicy" sequence
- Using TPMS_PCR_SELECTION_SelectPCR() to set the PCR bit mask
- Also dropping TPM2_PCR_TO_SELECT() and TPM2_PCR_TO_BIT() which are not necessary anymore
- Removing the redundant variable, 'crd', from grub_cryptodisk_scan_device_real()
- Fixing the spaces/tabs in cryptodisk.c
- Fixing the comment format in cryptodisk.h
- Adding the defensive check for "cargs->protectors" in grub_cryptodisk_scan_device()
- Improving 'grub-protect' for the better support of TPM 2.0 Key File
- Adding more comments
v2:
- https://lists.gnu.org/archive/html/grub-devel/2023-03/msg00094.html
- GIT repo: https://github.com/lcp/grub2/tree/tpm2-unlock-v2
v1:
- https://lists.gnu.org/archive/html/grub-devel/2023-02/msg00130.html
- GIT repo: https://github.com/lcp/grub2/tree/tpm2-unlock
*********************************************
* Anaylses for Coverity issuses on libtasn1 *
*********************************************
2 Memory corruptions: CID 435762, CID 435766
________________________________________________________________________________________________________
*** CID 435762: Memory - corruptions (OVERRUN) /grub-core/lib/libtasn1/lib/coding.c: 152 in _asn1_tag_der()
146 if (k > ASN1_MAX_TAG_SIZE - 1) 147 break; /* will not encode larger tags */ 148 } 149 *ans_len = k + 1; 150 while (k--) 151 ans[*ans_len - 1 - k] = temp[k] + 128; >>> CID 435762: Memory - corruptions (OVERRUN) >>> Overrunning array of 4 bytes at byte offset 4 by dereferencing pointer "ans + (*ans_len - 1)".
152 ans[*ans_len - 1] -= 128;
153 }
154 }
155
156 /**
157 * asn1_octet_der:
Reported to upstream: https://gitlab.com/gnutls/libtasn1/-/issues/49
A quick fix is also provided in patch 7.
________________________________________________________________________________________________________
*** CID 435766: Memory - corruptions (OVERRUN) /grub-core/lib/libtasn1/lib/decoding.c: 1204 in asn1_der_decoding2()
1198 }
1199
1200 DECR_LEN (ider_len, len2);
1201
1202 tlen = strlen (temp); 1203 if (tlen > 0)
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
CID 435766: Memory - corruptions (OVERRUN)
Allocating insufficient memory for the terminating null of the string.
1204 _asn1_set_value (p, temp, tlen);
1205
1206 counter += len2; 1207 move = RIGHT; 1208 break; 1209 case ASN1_ETYPE_OCTET_STRING:
It's likely to be false positive. See the upstream report:
https://gitlab.com/gnutls/libtasn1/-/issues/50
==
7 Integer handling issues:
CID 435774, CID 435773, CID 435772, CID 435768, CID 435765, CID 435764, CID 435763
Those are related to Gnulib macros and false positive. Here are the analyses:
________________________________________________________________________________________________________
*** CID 435774: Integer handling issues (CONSTANT_EXPRESSION_RESULT) /grub-core/lib/libtasn1/lib/decoding.c: 481 in asn1_get_object_id_der()
475 */
476 if (leading != 0 && der[len_len + k] == 0x80)
477 return ASN1_DER_ERROR;
478 leading = 0;
479
480 /* check for wrap around */
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
CID 435774: Integer handling issues (
CONSTANT_EXPRESSION_RESULT)
"val < ((((1 ? 0 : val) - 1 < 0) ? ~((((1 ? 0 : val) + 1 << 62UL /* sizeof (+val) * 8 - 2 */) - 1) * 2 + 1) : ((1 ? 0 : val) + 0)) >> 7)" is always false regardless of the values of its operands. This occurs as the second operand of "?:".
481 if (INT_LEFT_SHIFT_OVERFLOW (val, 7))
482 return ASN1_DER_ERROR;
483
484 val = val << 7;
485 val |= der[len_len + k] & 0x7F;
486
/grub-core/lib/libtasn1/lib/decoding.c: 481 in asn1_get_object_id_der()
Here are the related macros:
#define _GL_INT_NEGATE_CONVERT(e, v) ((1 ? 0 : (e)) - (v))
#define EXPR_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0)
#define _GL_INT_CONVERT(e, v) ((1 ? 0 : (e)) + (v))
#define TYPE_WIDTH(t) (sizeof (t) * CHAR_BIT)
#define _GL_SIGNED_INT_MAXIMUM(e) \
(((_GL_INT_CONVERT (e, 1) << (TYPE_WIDTH (+ (e)) - 2)) - 1) * 2 + 1)
#define _GL_INT_MINIMUM(e) \ (EXPR_SIGNED (e) \ ? ~ _GL_SIGNED_INT_MAXIMUM (e) \
: _GL_INT_CONVERT (e, 0))
#define _GL_INT_MAXIMUM(e) \ (EXPR_SIGNED (e) \ ? _GL_SIGNED_INT_MAXIMUM (e) \
: _GL_INT_NEGATE_CONVERT (e, 1))
#define INT_LEFT_SHIFT_RANGE_OVERFLOW(a, b, min, max) \ ((a) < 0 \ ? (a) < (min) >> (b) \
: (max) >> (b) < (a))
#define INT_LEFT_SHIFT_OVERFLOW(a, b) \
INT_LEFT_SHIFT_RANGE_OVERFLOW (a, b, \
_GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a))The statement in question is expanded "(a) < (min) >> (b)" of INT_LEFT_SHIFT_RANGE_OVERFLOW.
'(a) < (min) >> (b)'
=> '(val) < _GL_INT_MINIMUM (val) >> (7)'
=> '(val) < \
(EXPR_SIGNED (val) \
? ~ _GL_SIGNED_INT_MAXIMUM (val) \
: _GL_INT_CONVERT (val, 0)) \
>> (7)'
=> '(val) < \
((_GL_INT_NEGATE_CONVERT (val, 1) < 0) \
? ~ _GL_SIGNED_INT_MAXIMUM (val) \
: _GL_INT_CONVERT (val, 0)) \
>> (7)'
=> '(val) < \
((((1 ? 0 : (val)) - (1)) < 0) \
? ~ _GL_SIGNED_INT_MAXIMUM (val) \
: _GL_INT_CONVERT (val, 0)) \
>> (7)'
=> '(val) < \
((((1 ? 0 : (val)) - (1)) < 0) \
? ~ (((_GL_INT_CONVERT (val, 1) << (TYPE_WIDTH (+ (val)) - 2)) - 1) * 2 + 1) \
: _GL_INT_CONVERT (val, 0)) \
>> (7)'
=> '(val) < \
((((1 ? 0 : (val)) - (1)) < 0) \
? ~ (((((1 ? 0 : (val)) + (1)) << (TYPE_WIDTH (+ (val)) - 2)) - 1) * 2 + 1) \
: _GL_INT_CONVERT (val, 0)) \
>> (7)'
=> '(val) < \
((((1 ? 0 : (val)) - (1)) < 0) \
? ~ (((((1 ? 0 : (val)) + (1)) << ((sizeof (val) * CHAR_BIT) - 2)) - 1) * 2 + 1) \
: _GL_INT_CONVERT (val, 0)) \
>> (7)'
=> '(val) < \
((((1 ? 0 : (val)) - (1)) < 0) \
? ~ (((((1 ? 0 : (val)) + (1)) << ((sizeof (val) * CHAR_BIT) - 2)) - 1) * 2 + 1) \
: ((1 ? 0 : (val)) + (0))) \
>> (7)''_GL_INT_MINIMUM' returns the minimum value of the given type. Since 'val' is 'uint64_t', '_GL_INT_MINIMUM (val)' is 0, thus '(val) < 0 >> (7)' is always false. Besides, '(val) < 0' is false, so "(max) >> (b) < (a))" becomes the only valid statement to check if 'a' overflows after left shift.
________________________________________________________________________________________________________
*** CID 435773: Integer handling issues (NO_EFFECT) /grub-core/lib/libtasn1/lib/decoding.c: 439 in asn1_get_object_id_der()
433 return ASN1_DER_ERROR;
434
435 val0 = 0;
436
437 for (k = 0; k < len; k++)
438 {
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
CID 435773: Integer handling issues (
NO_EFFECT)
This less-than-zero comparison of an unsigned value is never true. "(1 ? 0UL : val0) - 1UL < 0UL".
439 if (INT_LEFT_SHIFT_OVERFLOW (val0, 7))
440 return ASN1_DER_ERROR;
441
442 val0 <<= 7; 443 val0 |= der[len_len + k] & 0x7F; 444 if (!(der[len_len + k] & 0x80))
Here are the related macros:
#define _GL_INT_NEGATE_CONVERT(e, v) ((1 ? 0 : (e)) - (v))
#define EXPR_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0)
#define _GL_INT_CONVERT(e, v) ((1 ? 0 : (e)) + (v))
#define TYPE_WIDTH(t) (sizeof (t) * CHAR_BIT)
#define _GL_SIGNED_INT_MAXIMUM(e) \
(((_GL_INT_CONVERT (e, 1) << (TYPE_WIDTH (+ (e)) - 2)) - 1) * 2 + 1)
#define _GL_INT_MINIMUM(e) \ (EXPR_SIGNED (e) \ ? ~ _GL_SIGNED_INT_MAXIMUM (e) \
: _GL_INT_CONVERT (e, 0))
#define _GL_INT_MAXIMUM(e) \ (EXPR_SIGNED (e) \ ? _GL_SIGNED_INT_MAXIMUM (e) \
: _GL_INT_NEGATE_CONVERT (e, 1))
#define INT_LEFT_SHIFT_RANGE_OVERFLOW(a, b, min, max) \ ((a) < 0 \ ? (a) < (min) >> (b) \
: (max) >> (b) < (a))
#define INT_LEFT_SHIFT_OVERFLOW(a, b) \
INT_LEFT_SHIFT_RANGE_OVERFLOW (a, b, \
_GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a))The statement in question is the expanded 'EXPR_SIGNED (val0)' from either '_GL_INT_MAXIMUM' or '_GL_INT_MINIMUM'
'EXPR_SIGNED (val0)'
=> '(_GL_INT_NEGATE_CONVERT (val0, 1) < 0)'
=> '(((1 ? 0 : (val0)) - (1)) < 0)'
Since 'EXPR_SIGNED' is to test if the given expression is signed or not. For 'uint64_t val0', it's expected to be false, and '_GL_INT_MINIMUM' returns the minimum value of 'uint64_t' while '_GL_INT_MAXIMUM' returns the maximum value of 'uint64_t'.
________________________________________________________________________________________________________
*** CID 435772: Integer handling issues (NO_EFFECT) /grub-core/lib/libtasn1/lib/decoding.c: 204 in asn1_get_tag_der()
198 /* Long form */ 199 punt = 1; 200 ris = 0; 201 while (punt < der_len && der[punt] & 128)
202 {
203
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
CID 435772: Integer handling issues (
NO_EFFECT)
This less-than-zero comparison of an unsigned value is never true. "(1 ? 0U : ((1 ? 0U : ris) + 128U)) - 1U < 0U".
204 if (INT_MULTIPLY_OVERFLOW (ris, 128)) 205 return ASN1_DER_ERROR; 206 ris *= 128;
207
208 if (INT_ADD_OVERFLOW (ris, ((unsigned) (der[punt] & 0x7F))))
209 return ASN1_DER_ERROR;
Here are the related macros:
#define _GL_INT_NEGATE_CONVERT(e, v) ((1 ? 0 : (e)) - (v))
#define _GL_INT_CONVERT(e, v) ((1 ? 0 : (e)) + (v))
#define EXPR_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0)
#define TYPE_WIDTH(t) (sizeof (t) * CHAR_BIT)
#define _GL_SIGNED_INT_MAXIMUM(e) \
(((_GL_INT_CONVERT (e, 1) << (TYPE_WIDTH (+ (e)) - 2)) - 1) * 2 + 1)
#define _GL_INT_MINIMUM(e) \ (EXPR_SIGNED (e) \ ? ~ _GL_SIGNED_INT_MAXIMUM (e) \
: _GL_INT_CONVERT (e, 0))
#define _GL_INT_MAXIMUM(e) \ (EXPR_SIGNED (e) \ ? _GL_SIGNED_INT_MAXIMUM (e) \
: _GL_INT_NEGATE_CONVERT (e, 1))
#define INT_MULTIPLY_RANGE_OVERFLOW(a, b, min, max) \
((b) < 0 \
? ((a) < 0 \
? (a) < (max) / (b) \
: (b) == -1 \
? 0 \
: (min) / (b) < (a)) \
: (b) == 0 \
? 0 \
: ((a) < 0 \
? (a) < (min) / (b) \
: (max) / (b) < (a)))# define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \
(((min) == 0 && (((a) < 0 && 0 < (b)) || ((b) < 0 && 0 < (a)))) \
|| INT_MULTIPLY_RANGE_OVERFLOW (a, b, min, max))#define _GL_BINARY_OP_OVERFLOW(a, b, op_result_overflow) \
op_result_overflow (a, b, \
_GL_INT_MINIMUM (_GL_INT_CONVERT (a, b)), \
_GL_INT_MAXIMUM (_GL_INT_CONVERT (a, b)))#define INT_MULTIPLY_OVERFLOW(a, b) \
_GL_BINARY_OP_OVERFLOW (a, b, _GL_MULTIPLY_OVERFLOW)
The statement in question is the expanded 'EXPR_SIGNED (_GL_INT_CONVERT (ris, 128))' from either '_GL_INT_MINIMUM' or '_GL_INT_MAXIMUM'.
'EXPR_SIGNED (_GL_INT_CONVERT (ris, 128))'
=> 'EXPR_SIGNED ((1 ? 0 : (ris)) + (128))'
=> '(_GL_INT_NEGATE_CONVERT (((1 ? 0 : (ris)) + (128), 1) < 0))' => '((1 ? 0 : ((1 ? 0 : ris) + 128)) - 1 < 0)'
Since 'ris' is 'unsigned int', the compiler treats 128 as 'unsigned int' too. 'EXPR_SIGNED' is designed to check if the given expression is signed or not. Thus, the result is expected to be false and '_GL_INT_MINIMUM' returns the minimum value of 'unsigned int' while '_GL_INT_MAXIMUM' returns the maximum value of 'unsigned int'.
________________________________________________________________________________________________________
*** CID 435768: (CONSTANT_EXPRESSION_RESULT)
/grub-core/lib/libtasn1/lib/decoding.c: 204 in asn1_get_tag_der()
198 /* Long form */ 199 punt = 1; 200 ris = 0; 201 while (punt < der_len && der[punt] & 128)
202 {
203
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
CID 435768: (CONSTANT_EXPRESSION_RESULT) "ris < (((1 ? 0 : ((1 ? 0 : ris) + 128)) - 1 < 0) ? ~((((1 ? 0 : ((1 ? 0 : ris) + 128)) + 1 << 30UL /* sizeof (+((1 ? 0 : ris) + 128)) * 8 - 2 */) - 1) * 2 + 1) : ((1 ? 0 : ((1 ? 0 : ris) + 128)) + 0)) / 128" is always false regardless of the values of its operands. This occurs as the second operand of "?:".
204 if (INT_MULTIPLY_OVERFLOW (ris, 128)) 205 return ASN1_DER_ERROR; 206 ris *= 128;
207
208 if (INT_ADD_OVERFLOW (ris, ((unsigned) (der[punt] & 0x7F))))
209 return ASN1_DER_ERROR;
/grub-core/lib/libtasn1/lib/decoding.c: 217 in asn1_get_tag_der()
211 punt++;
212 }
213
214 if (punt >= der_len)
215 return ASN1_DER_ERROR;
216
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
CID 435768: (CONSTANT_EXPRESSION_RESULT) "ris < (((1 ? 0 : ((1 ? 0 : ris) + 128)) - 1 < 0) ? ~((((1 ? 0 : ((1 ? 0 : ris) + 128)) + 1 << 30UL /* sizeof (+((1 ? 0 : ris) + 128)) * 8 - 2 */) - 1) * 2 + 1) : ((1 ? 0 : ((1 ? 0 : ris) + 128)) + 0)) / 128" is always false regardless of the values of its operands. This occurs as the second operand of "?:".
217 if (INT_MULTIPLY_OVERFLOW (ris, 128))
218 return ASN1_DER_ERROR;
219 ris *= 128;
220
221 if (INT_ADD_OVERFLOW (ris, ((unsigned) (der[punt] & 0x7F))))
222 return ASN1_DER_ERROR;
Here are the related macros:
#define _GL_INT_NEGATE_CONVERT(e, v) ((1 ? 0 : (e)) - (v))
#define _GL_INT_CONVERT(e, v) ((1 ? 0 : (e)) + (v))
#define EXPR_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0)
#define TYPE_WIDTH(t) (sizeof (t) * CHAR_BIT)
#define _GL_SIGNED_INT_MAXIMUM(e) \
(((_GL_INT_CONVERT (e, 1) << (TYPE_WIDTH (+ (e)) - 2)) - 1) * 2 + 1)
#define _GL_INT_MINIMUM(e) \ (EXPR_SIGNED (e) \ ? ~ _GL_SIGNED_INT_MAXIMUM (e) \
: _GL_INT_CONVERT (e, 0))
#define _GL_INT_MAXIMUM(e) \ (EXPR_SIGNED (e) \ ? _GL_SIGNED_INT_MAXIMUM (e) \
: _GL_INT_NEGATE_CONVERT (e, 1))
#define INT_MULTIPLY_RANGE_OVERFLOW(a, b, min, max) \
((b) < 0 \
? ((a) < 0 \
? (a) < (max) / (b) \
: (b) == -1 \
? 0 \
: (min) / (b) < (a)) \
: (b) == 0 \
? 0 \
: ((a) < 0 \
? (a) < (min) / (b) \
: (max) / (b) < (a)))# define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \
(((min) == 0 && (((a) < 0 && 0 < (b)) || ((b) < 0 && 0 < (a)))) \
|| INT_MULTIPLY_RANGE_OVERFLOW (a, b, min, max))#define _GL_BINARY_OP_OVERFLOW(a, b, op_result_overflow) \
op_result_overflow (a, b, \
_GL_INT_MINIMUM (_GL_INT_CONVERT (a, b)), \
_GL_INT_MAXIMUM (_GL_INT_CONVERT (a, b)))#define INT_MULTIPLY_OVERFLOW(a, b) \
_GL_BINARY_OP_OVERFLOW (a, b, _GL_MULTIPLY_OVERFLOW)
The statement in question is expanded from '(a) < (min) / (b)' in INT_MULTIPLY_RANGE_OVERFLOW.
'(a) < (min) / (b)'
=> '(a) < (_GL_INT_MINIMUM (_GL_INT_CONVERT (a, b))) / (b)' => '(ris) < (_GL_INT_MINIMUM (_GL_INT_CONVERT (ris, 128))) / (128)'
=> '(ris) < \
(EXPR_SIGNED (_GL_INT_CONVERT (ris, 128)) \
? ~ _GL_SIGNED_INT_MAXIMUM (_GL_INT_CONVERT (ris, 128)) \
: _GL_INT_CONVERT (_GL_INT_CONVERT (ris, 128), 0)) \
/ (128)'
=> '(ris) < \
((_GL_INT_NEGATE_CONVERT (_GL_INT_CONVERT (ris, 128), 1) < 0) \
? ~ _GL_SIGNED_INT_MAXIMUM (_GL_INT_CONVERT (ris, 128)) \
: _GL_INT_CONVERT (_GL_INT_CONVERT (ris, 128), 0)) \
/ (128)'
=> '(ris) < \
((((1 ? 0 : (_GL_INT_CONVERT (ris, 128))) - (1)) < 0) \
? ~ _GL_SIGNED_INT_MAXIMUM (_GL_INT_CONVERT (ris, 128)) \
: _GL_INT_CONVERT (_GL_INT_CONVERT (ris, 128), 0)) \
/ (128)'
=> '(ris) < \
((((1 ? 0 : ((1 ? 0 : (ris)) + (128))) - (1)) < 0) \
? ~ _GL_SIGNED_INT_MAXIMUM (_GL_INT_CONVERT (ris, 128)) \
: _GL_INT_CONVERT (_GL_INT_CONVERT (ris, 128), 0)) \
/ (128)'
=> '(ris) < \
((((1 ? 0 : ((1 ? 0 : (ris)) + (128))) - (1)) < 0) \
? ~ (((_GL_INT_CONVERT (_GL_INT_CONVERT (ris, 128), 1) << (TYPE_WIDTH (+ (_GL_INT_CONVERT (ris, 128))) - 2)) - 1) * 2 + 1) \
: _GL_INT_CONVERT (_GL_INT_CONVERT (ris, 128), 0)) \
/ (128)'
=> '(ris) < \
((((1 ? 0 : ((1 ? 0 : (ris)) + (128))) - (1)) < 0) \
? ~ (((((1 ? 0 : (_GL_INT_CONVERT (ris, 128))) + (1)) << (TYPE_WIDTH (+ (_GL_INT_CONVERT (ris, 128))) - 2)) - 1) * 2 + 1) \
: _GL_INT_CONVERT (_GL_INT_CONVERT (ris, 128), 0)) \
/ (128)'
=> '(ris) < \
((((1 ? 0 : ((1 ? 0 : (ris)) + (128))) - (1)) < 0) \
? ~ (((((1 ? 0 : ((1 ? 0 : (ris)) + (128))) + (1)) << (TYPE_WIDTH (+ (_GL_INT_CONVERT (ris, 128))) - 2)) - 1) * 2 + 1) \
: _GL_INT_CONVERT (_GL_INT_CONVERT (ris, 128), 0)) \
/ (128)'
=> '(ris) < \
((((1 ? 0 : ((1 ? 0 : (ris)) + (128))) - (1)) < 0) \
? ~ (((((1 ? 0 : ((1 ? 0 : (ris)) + (128))) + (1)) << ((sizeof (+ (_GL_INT_CONVERT (ris, 128))) * CHAR_BIT) - 2)) - 1) * 2 + 1) \
: _GL_INT_CONVERT (_GL_INT_CONVERT (ris, 128), 0)) \
/ (128)'
=> '(ris) < \
((((1 ? 0 : ((1 ? 0 : (ris)) + (128))) - (1)) < 0) \
? ~ (((((1 ? 0 : ((1 ? 0 : (ris)) + (128))) + (1)) << ((sizeof (+ ((1 ? 0 : (ris)) + (128))) * CHAR_BIT) - 2)) - 1) * 2 + 1) \
: _GL_INT_CONVERT (_GL_INT_CONVERT (ris, 128), 0)) \
/ (128)'
=> '(ris) < \
((((1 ? 0 : ((1 ? 0 : (ris)) + (128))) - (1)) < 0) \
? ~ (((((1 ? 0 : ((1 ? 0 : (ris)) + (128))) + (1)) << ((sizeof (+ ((1 ? 0 : (ris)) + (128))) * CHAR_BIT) - 2)) - 1) * 2 + 1) \
: _GL_INT_CONVERT (_GL_INT_CONVERT (ris, 128), 0)) \
/ (128)'
=> '(ris) < \
((((1 ? 0 : ((1 ? 0 : (ris)) + (128))) - (1)) < 0) \
? ~ (((((1 ? 0 : ((1 ? 0 : (ris)) + (128))) + (1)) << ((sizeof (+ ((1 ? 0 : (ris)) + (128))) * CHAR_BIT) - 2)) - 1) * 2 + 1) \
: ((1 ? 0 : (_GL_INT_CONVERT (ris, 128)) + (0)) \
/ (128)'
=> '(ris) < \
((((1 ? 0 : ((1 ? 0 : (ris)) + (128))) - (1)) < 0) \
? ~ (((((1 ? 0 : ((1 ? 0 : (ris)) + (128))) + (1)) << ((sizeof (+ ((1 ? 0 : (ris)) + (128))) * CHAR_BIT) - 2)) - 1) * 2 + 1) \
: ((1 ? 0 : ((1 ? 0 : (ris)) + (128)) + (0)) \
/ (128)'Since 'ris' is 'unsigned int', and the compiler also treats '128' as 'unsigned int', thus '_GL_INT_CONVERT (ris, 128)' is '128U' and '_GL_INT_MINIMUM (128U)' is 0. So, '(ris) < 0 / (128)' is expected to be false. Besides, '(ris) < 0' is false, so the result of '(a) < (min) / (b)' is always skipped, and '(max) / (b) < (a)' becomes the only valid statement to check if 'ris' overflows after multiplying the 128.
________________________________________________________________________________________________________
*** CID 435765: Integer handling issues (CONSTANT_EXPRESSION_RESULT) /grub-core/lib/libtasn1/lib/decoding.c: 439 in asn1_get_object_id_der()
433 return ASN1_DER_ERROR;
434
435 val0 = 0;
436
437 for (k = 0; k < len; k++)
438 {
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
CID 435765: Integer handling issues (
CONSTANT_EXPRESSION_RESULT)
"val0 < ((((1 ? 0 : val0) - 1 < 0) ? ~((((1 ? 0 : val0) + 1 << 62UL /* sizeof (+val0) * 8 - 2 */) - 1) * 2 + 1) : ((1 ? 0 : val0) + 0)) >> 7)" is always false regardless of the values of its operands. This occurs as the second operand of "?:".
439 if (INT_LEFT_SHIFT_OVERFLOW (val0, 7))
440 return ASN1_DER_ERROR;
441
442 val0 <<= 7; 443 val0 |= der[len_len + k] & 0x7F; 444 if (!(der[len_len + k] & 0x80))
Here are the related macros:
#define _GL_INT_NEGATE_CONVERT(e, v) ((1 ? 0 : (e)) - (v))
#define EXPR_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0)
#define _GL_INT_CONVERT(e, v) ((1 ? 0 : (e)) + (v))
#define TYPE_WIDTH(t) (sizeof (t) * CHAR_BIT)
#define _GL_SIGNED_INT_MAXIMUM(e) \
(((_GL_INT_CONVERT (e, 1) << (TYPE_WIDTH (+ (e)) - 2)) - 1) * 2 + 1)
#define _GL_INT_MINIMUM(e) \ (EXPR_SIGNED (e) \ ? ~ _GL_SIGNED_INT_MAXIMUM (e) \
: _GL_INT_CONVERT (e, 0))
#define _GL_INT_MAXIMUM(e) \ (EXPR_SIGNED (e) \ ? _GL_SIGNED_INT_MAXIMUM (e) \
: _GL_INT_NEGATE_CONVERT (e, 1))
#define INT_LEFT_SHIFT_RANGE_OVERFLOW(a, b, min, max) \ ((a) < 0 \ ? (a) < (min) >> (b) \
: (max) >> (b) < (a))
#define INT_LEFT_SHIFT_OVERFLOW(a, b) \
INT_LEFT_SHIFT_RANGE_OVERFLOW (a, b, \
_GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a))The statement in question is expanded '(a) < (min) >> (b)' from INT_LEFT_SHIFT_RANGE_OVERFLOW.
'(a) < (min) >> (b)'
=> '(val) < (_GL_INT_MINIMUM (val)) >> (7)'
=> '(val) < \
(EXPR_SIGNED (val) \
? ~ _GL_SIGNED_INT_MAXIMUM (val) \
: _GL_INT_CONVERT (val, 0)) \
>> (7)'
=> '(val) < \
((_GL_INT_NEGATE_CONVERT (val, 1) < 0) \
? ~ _GL_SIGNED_INT_MAXIMUM (val) \
: _GL_INT_CONVERT (val, 0)) \
>> (7)'
=> '(val) < \
((((1 ? 0 : (val)) - (1)) < 0) \
? ~ _GL_SIGNED_INT_MAXIMUM (val) \
: _GL_INT_CONVERT (val, 0)) \
>> (7)'
=> '(val) < \
((((1 ? 0 : (val)) - (1)) < 0) \
? ~ (((_GL_INT_CONVERT (val, 1) << (TYPE_WIDTH (+ (val)) - 2)) - 1) * 2 + 1) \
: _GL_INT_CONVERT (val, 0)) \
>> (7)'
=> '(val) < \
((((1 ? 0 : (val)) - (1)) < 0) \
? ~ (((((1 ? 0 : (val)) + (1)) << (TYPE_WIDTH (+ (val)) - 2)) - 1) * 2 + 1) \
: _GL_INT_CONVERT (val, 0)) \
>> (7)'
=> '(val) < \
((((1 ? 0 : (val)) - (1)) < 0) \
? ~ (((((1 ? 0 : (val)) + (1)) << ((sizeof (+ (val)) * CHAR_BIT) - 2)) - 1) * 2 + 1) \
: _GL_INT_CONVERT (val, 0)) \
>> (7)'
=> '(val) < \
((((1 ? 0 : (val)) - (1)) < 0) \
? ~ (((((1 ? 0 : (val)) + (1)) << ((sizeof (+ (val)) * CHAR_BIT) - 2)) - 1) * 2 + 1) \
: ((1 ? 0 : (val)) + (0))) \
>> (7)''_GL_INT_MINIMUM' returns the minimum value of the given type. Since 'val' is 'uint64_t', '_GL_INT_MINIMUM (val)' is 0, thus '(val) < 0 >> (7)' is expected to be false. Besides, '(val) < 0' is false, so "(max) >> (b) < (a))" becomes the only valid statement to check if 'a' overflows after left shift.
________________________________________________________________________________________________________
*** CID 435764: Integer handling issues (NO_EFFECT) /grub-core/lib/libtasn1/lib/decoding.c: 137 in asn1_get_length_der()
131 punt = 1;
132 if (k)
133 { /* definite length method */
134 ans = 0;
135 while (punt <= k && punt < der_len)
136 {
>>> CID 435764: Integer handling issues (NO_EFFECT)
>>> This less-than-zero comparison of an unsigned value is never true. "(1 ? 0U : ((1 ? 0U : ans) + 256U)) - 1U < 0U".
137 if (INT_MULTIPLY_OVERFLOW (ans, 256))
138 return -2;
139 ans *= 256;140
141 if (INT_ADD_OVERFLOW (ans, ((unsigned) der[punt])))
142 return -2;
Here are the related macros:
#define _GL_INT_NEGATE_CONVERT(e, v) ((1 ? 0 : (e)) - (v))
#define _GL_INT_CONVERT(e, v) ((1 ? 0 : (e)) + (v))
#define EXPR_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0)
#define TYPE_WIDTH(t) (sizeof (t) * CHAR_BIT)
#define _GL_SIGNED_INT_MAXIMUM(e) \
(((_GL_INT_CONVERT (e, 1) << (TYPE_WIDTH (+ (e)) - 2)) - 1) * 2 + 1)
#define _GL_INT_MINIMUM(e) \ (EXPR_SIGNED (e) \ ? ~ _GL_SIGNED_INT_MAXIMUM (e) \
: _GL_INT_CONVERT (e, 0))
#define _GL_INT_MAXIMUM(e) \ (EXPR_SIGNED (e) \ ? _GL_SIGNED_INT_MAXIMUM (e) \
: _GL_INT_NEGATE_CONVERT (e, 1))
#define INT_MULTIPLY_RANGE_OVERFLOW(a, b, min, max) \
((b) < 0 \
? ((a) < 0 \
? (a) < (max) / (b) \
: (b) == -1 \
? 0 \
: (min) / (b) < (a)) \
: (b) == 0 \
? 0 \
: ((a) < 0 \
? (a) < (min) / (b) \
: (max) / (b) < (a)))# define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \
(((min) == 0 && (((a) < 0 && 0 < (b)) || ((b) < 0 && 0 < (a)))) \
|| INT_MULTIPLY_RANGE_OVERFLOW (a, b, min, max))#define _GL_BINARY_OP_OVERFLOW(a, b, op_result_overflow) \
op_result_overflow (a, b, \
_GL_INT_MINIMUM (_GL_INT_CONVERT (a, b)), \
_GL_INT_MAXIMUM (_GL_INT_CONVERT (a, b)))#define INT_MULTIPLY_OVERFLOW(a, b) \
_GL_BINARY_OP_OVERFLOW (a, b, _GL_MULTIPLY_OVERFLOW)
The statement in question is expanded 'EXPR_SIGNED (_GL_INT_CONVERT (ans, 256))' from either '_GL_INT_MINIMUM' or '_GL_INT_MAXIMUM'.
'EXPR_SIGNED (_GL_INT_CONVERT (ans, 256))'
=> 'EXPR_SIGNED ((1 ? 0 : (ans)) + (256))'
=> '(_GL_INT_NEGATE_CONVERT (((1 ? 0 : (ans)) + (256)), 1) < 0)' => '((1 ? 0 : ((1 ? 0 : (ans)) + (256))) - (1))'
Since 'ans' is 'unsigned int', the compiler treats '256' as 'unsigned int', thus '_GL_INT_CONVERT (ans, 256)' is '256U'. 'EXPR_SIGNED' is designed to check if the given expression is signed, so 'EXPR_SIGNED (256U)' is expected to be false and '_GL_INT_MINIMUM' returns the minimum value of 'unsigned int' while '_GL_INT_MAXIMUM' returns the maximum of 'unsigned int'.
________________________________________________________________________________________________________
*** CID 435763: Integer handling issues (CONSTANT_EXPRESSION_RESULT) /grub-core/lib/libtasn1/lib/decoding.c: 137 in asn1_get_length_der()
131 punt = 1;
132 if (k)
133 { /* definite length method */
134 ans = 0;
135 while (punt <= k && punt < der_len)
136 {
>>> CID 435763: Integer handling issues (CONSTANT_EXPRESSION_RESULT)
>>> "ans < (((1 ? 0 : ((1 ? 0 : ans) + 256)) - 1 < 0) ? ~((((1 ? 0 : ((1 ? 0 : ans) + 256)) + 1 << 30UL /* sizeof (+((1 ? 0 : ans) + 256)) * 8 - 2 */) - 1) * 2 + 1) : ((1 ? 0 : ((1 ? 0 : ans) + 256)) + 0)) / 256" is always false regardless of the values of its operands. This occurs as the second operand of "?:".
137 if (INT_MULTIPLY_OVERFLOW (ans, 256))
138 return -2;
139 ans *= 256;140
141 if (INT_ADD_OVERFLOW (ans, ((unsigned) der[punt])))
142 return -2;
Here are the related macros:
#define _GL_INT_NEGATE_CONVERT(e, v) ((1 ? 0 : (e)) - (v))
#define _GL_INT_CONVERT(e, v) ((1 ? 0 : (e)) + (v))
#define EXPR_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0)
#define TYPE_WIDTH(t) (sizeof (t) * CHAR_BIT)
#define _GL_SIGNED_INT_MAXIMUM(e) \
(((_GL_INT_CONVERT (e, 1) << (TYPE_WIDTH (+ (e)) - 2)) - 1) * 2 + 1)
#define _GL_INT_MINIMUM(e) \ (EXPR_SIGNED (e) \ ? ~ _GL_SIGNED_INT_MAXIMUM (e) \
: _GL_INT_CONVERT (e, 0))
#define _GL_INT_MAXIMUM(e) \ (EXPR_SIGNED (e) \ ? _GL_SIGNED_INT_MAXIMUM (e) \
: _GL_INT_NEGATE_CONVERT (e, 1))
#define INT_MULTIPLY_RANGE_OVERFLOW(a, b, min, max) \
((b) < 0 \
? ((a) < 0 \
? (a) < (max) / (b) \
: (b) == -1 \
? 0 \
: (min) / (b) < (a)) \
: (b) == 0 \
? 0 \
: ((a) < 0 \
? (a) < (min) / (b) \
: (max) / (b) < (a)))# define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \
(((min) == 0 && (((a) < 0 && 0 < (b)) || ((b) < 0 && 0 < (a)))) \
|| INT_MULTIPLY_RANGE_OVERFLOW (a, b, min, max))#define _GL_BINARY_OP_OVERFLOW(a, b, op_result_overflow) \
op_result_overflow (a, b, \
_GL_INT_MINIMUM (_GL_INT_CONVERT (a, b)), \
_GL_INT_MAXIMUM (_GL_INT_CONVERT (a, b)))#define INT_MULTIPLY_OVERFLOW(a, b) \
_GL_BINARY_OP_OVERFLOW (a, b, _GL_MULTIPLY_OVERFLOW)
The statement in question is expanded '(a) < (min) / (b)' from INT_MULTIPLY_RANGE_OVERFLOW.
'(a) < (min) / (b)'
=> '(a) < (_GL_INT_MINIMUM (_GL_INT_CONVERT (a, b))) / (b)' => '(ans) < (_GL_INT_MINIMUM (_GL_INT_CONVERT (ans, 256))) / (256)'
=> '(ans) < \
(EXPR_SIGNED (_GL_INT_CONVERT (ans, 256)) \
? ~ _GL_SIGNED_INT_MAXIMUM (_GL_INT_CONVERT (ans, 256)) \
: _GL_INT_CONVERT (_GL_INT_CONVERT (ans, 256), 0)) \
/ (256)'
=> '(ans) < \
(_GL_INT_NEGATE_CONVERT (_GL_INT_CONVERT (ans, 256), 1) < 0) \
? ~ _GL_SIGNED_INT_MAXIMUM (_GL_INT_CONVERT (ans, 256)) \
: _GL_INT_CONVERT (_GL_INT_CONVERT (ans, 256), 0)) \
/ (256)'
=> '(ans) < \
(((1 ? 0 : (_GL_INT_CONVERT (ans, 256))) - (1)) < 0) \
? ~ _GL_SIGNED_INT_MAXIMUM (_GL_INT_CONVERT (ans, 256)) \
: _GL_INT_CONVERT (_GL_INT_CONVERT (ans, 256), 0)) \
/ (256)'
=> '(ans) < \
(((1 ? 0 : ((1 ? 0 : (ans)) + (256))) - (1)) < 0) \
? ~ (((_GL_INT_CONVERT (_GL_INT_CONVERT (ans, 256), 1) << (TYPE_WIDTH (+ (_GL_INT_CONVERT (ans, 256))) - 2)) - 1) * 2 + 1) \
: _GL_INT_CONVERT (_GL_INT_CONVERT (ans, 256), 0)) \
/ (256)'
=> '(ans) < \
(((1 ? 0 : ((1 ? 0 : (ans)) + (256))) - (1)) < 0) \
? ~ ((((1 ? 0 : (_GL_INT_CONVERT (ans, 256))) + (1)) << (TYPE_WIDTH (+ (_GL_INT_CONVERT (ans, 256))) - 2)) - 1) * 2 + 1) \
: _GL_INT_CONVERT (_GL_INT_CONVERT (ans, 256), 0)) \
/ (256)'
=> '(ans) < \
(((1 ? 0 : ((1 ? 0 : (ans)) + (256))) - (1)) < 0) \
? ~ ((((1 ? 0 : ((1 ? 0 : (ans)) + (256))) + (1)) << (TYPE_WIDTH (+ (_GL_INT_CONVERT (ans, 256))) - 2)) - 1) * 2 + 1) \
: _GL_INT_CONVERT (_GL_INT_CONVERT (ans, 256), 0)) \
/ (256)'
=> '(ans) < \
(((1 ? 0 : ((1 ? 0 : (ans)) + (256))) - (1)) < 0) \
? ~ ((((1 ? 0 : ((1 ? 0 : (ans)) + (256))) + (1)) << ((sizeof (+ (_GL_INT_CONVERT (ans, 256))) * CHAR_BIT) - 2)) - 1) * 2 + 1) \
: _GL_INT_CONVERT (_GL_INT_CONVERT (ans, 256), 0)) \
/ (256)'
=> '(ans) < \
(((1 ? 0 : ((1 ? 0 : (ans)) + (256))) - (1)) < 0) \
? ~ ((((1 ? 0 : ((1 ? 0 : (ans)) + (256))) + (1)) << ((sizeof (+ ((1 ? 0 : (ans)) + (1))) * CHAR_BIT) - 2)) - 1) * 2 + 1) \
: _GL_INT_CONVERT (_GL_INT_CONVERT (ans, 256), 0)) \
/ (256)'
=> '(ans) < \
(((1 ? 0 : ((1 ? 0 : (ans)) + (256))) - (1)) < 0) \
? ~ ((((1 ? 0 : ((1 ? 0 : (ans)) + (256))) + (1)) << ((sizeof (+ ((1 ? 0 : (ans)) + (1))) * CHAR_BIT) - 2)) - 1) * 2 + 1) \
: ((1 ? 0 : (_GL_INT_CONVERT (ans, 256))) + (0)) ) \
/ (256)'
=> '(ans) < \
(((1 ? 0 : ((1 ? 0 : (ans)) + (256))) - (1)) < 0) \
? ~ ((((1 ? 0 : ((1 ? 0 : (ans)) + (256))) + (1)) << ((sizeof (+ ((1 ? 0 : (ans)) + (1))) * CHAR_BIT) - 2)) - 1) * 2 + 1) \
: ((1 ? 0 : ((1 ? 0 : (ans)) + (256))) + (0)) ) \
/ (256)'Since 'ans' is 'unsigned int', the compiler treats '256' as 'unsigned int', thus '_GL_INT_CONVERT (ans, 256)' is '256U'. Then, '_GL_INT_MINIMUM (256U)' returns 0, so '(ans) < 0 / (256)' is expected to be false. Besides, '(ans) < 0' is false, so '(a) < (min) / (b)' is always skipped, and '(max) / (b) < (a)' becomes the only valid statement to check if 'ans' overflows after multiplying 256.
Daniel Axtens (4):
posix_wrap: tweaks in preparation for libtasn1
libtasn1: import libtasn1-4.19.0
libtasn1: compile into asn1 module
asn1_test: test module for libtasn1
Gary Lin (15):
libtasn1: disable code not needed in grub
libtasn1: use bound-checked _asn1_str_cat()
libtasn1: adjust the header paths in libtasn1.h
libtasn1: Use grub_divmod64() for division
libtasn1: fix the potential buffer overrun
asn1_test: changes for grub compatibility
libtasn1: Add the documentation
tss2: Add TPM2 buffer handling functions
tss2: Add TPM2 types and Marshal/Unmarshal functions
tss2: Add TPM2 Software Stack (TSS2) support
tpm2_key_protector: Support authorized policy
cryptodisk: wipe out the cached keys from protectors
diskfilter: look up cryptodisk devices first
tpm2_key_protector: Add grub-emu support
tests: Add tpm2_key_protector_test
Hernan Gatta (4):
key_protector: Add key protectors framework
key_protector: Add TPM2 Key Protector
cryptodisk: Support key protectors
util/grub-protect: Add new tool
Patrick Colp (2):
tpm2_key_protector: Implement NV index
cryptodisk: Fallback to passphrase
.gitignore | 2 + Makefile.util.def | 39 + autogen.sh | 26 + configure.ac | 30 + docs/grub-dev.texi | 35 + docs/man/grub-protect.h2m | 4 + grub-core/Makefile.am | 1 + grub-core/Makefile.core.def | 60 + grub-core/commands/tpm2_key_protector/args.c | 130 + .../commands/tpm2_key_protector/module.c | 1253 +++++++++ grub-core/commands/tpm2_key_protector/tpm2.h | 36 + .../commands/tpm2_key_protector/tpm2_args.h | 51 + .../commands/tpm2_key_protector/tpm2key.asn | 49 + .../commands/tpm2_key_protector/tpm2key.c | 499 ++++ .../commands/tpm2_key_protector/tpm2key.h | 87 + .../tpm2_key_protector/tpm2key_asn1_tab.c | 63 + grub-core/disk/cryptodisk.c | 262 +- grub-core/disk/diskfilter.c | 35 +- grub-core/disk/key_protector.c | 79 + grub-core/kern/emu/main.c | 11 +- grub-core/kern/emu/misc.c | 51 + grub-core/lib/efi/tcg2.c | 144 + ...asn1-disable-code-not-needed-in-grub.patch | 319 +++ ...asn1-use-bound-checked-_asn1_str_cat.patch | 85 + ...djust-the-header-paths-in-libtasn1.h.patch | 32 + ...tasn1-Use-grub_divmod64-for-division.patch | 30 + ...sn1-fix-the-potential-buffer-overrun.patch | 35 + ..._test-changes-for-grub-compatibility.patch | 844 ++++++ grub-core/lib/libtasn1/COPYING | 16 + grub-core/lib/libtasn1/README.md | 98 + grub-core/lib/libtasn1/lib/coding.c | 1425 ++++++++++ grub-core/lib/libtasn1/lib/decoding.c | 2501 +++++++++++++++++ grub-core/lib/libtasn1/lib/element.c | 1109 ++++++++ grub-core/lib/libtasn1/lib/element.h | 42 + grub-core/lib/libtasn1/lib/errors.c | 100 + grub-core/lib/libtasn1/lib/gstr.c | 74 + grub-core/lib/libtasn1/lib/gstr.h | 50 + grub-core/lib/libtasn1/lib/int.h | 221 ++ grub-core/lib/libtasn1/lib/parser_aux.c | 1178 ++++++++ grub-core/lib/libtasn1/lib/parser_aux.h | 172 ++ grub-core/lib/libtasn1/lib/structure.c | 1225 ++++++++ grub-core/lib/libtasn1/lib/structure.h | 46 + grub-core/lib/libtasn1/libtasn1.h | 643 +++++ .../tests/CVE-2018-1000654-1_asn1_tab.h | 32 + .../tests/CVE-2018-1000654-2_asn1_tab.h | 36 + .../lib/libtasn1/tests/CVE-2018-1000654.c | 72 + grub-core/lib/libtasn1/tests/Test_overflow.c | 168 ++ grub-core/lib/libtasn1/tests/Test_simple.c | 226 ++ grub-core/lib/libtasn1/tests/Test_strings.c | 156 + .../lib/libtasn1/tests/object-id-decoding.c | 121 + .../lib/libtasn1/tests/object-id-encoding.c | 133 + grub-core/lib/libtasn1/tests/octet-string.c | 230 ++ grub-core/lib/libtasn1/tests/reproducers.c | 90 + grub-core/lib/libtasn1_wrap/wrap.c | 27 + grub-core/lib/posix_wrap/c-ctype.h | 114 + grub-core/lib/posix_wrap/limits.h | 1 + grub-core/lib/posix_wrap/stdlib.h | 8 + grub-core/lib/posix_wrap/string.h | 21 + grub-core/lib/posix_wrap/sys/types.h | 1 + grub-core/lib/tss2/buffer.c | 149 + grub-core/lib/tss2/tcg2.h | 35 + grub-core/lib/tss2/tcg2_emu.c | 54 + grub-core/lib/tss2/tpm2_cmd.c | 1054 +++++++ grub-core/lib/tss2/tpm2_cmd.h | 157 ++ grub-core/lib/tss2/tss2.c | 21 + grub-core/lib/tss2/tss2_buffer.h | 66 + grub-core/lib/tss2/tss2_mu.c | 1170 ++++++++ grub-core/lib/tss2/tss2_mu.h | 397 +++ grub-core/lib/tss2/tss2_structs.h | 768 +++++ grub-core/lib/tss2/tss2_types.h | 404 +++ grub-core/tests/asn1/asn1_test.c | 49 + grub-core/tests/asn1/asn1_test.h | 44 + grub-core/tests/lib/functional_test.c | 1 + include/grub/cryptodisk.h | 16 + include/grub/emu/misc.h | 5 + include/grub/key_protector.h | 47 + tests/asn1_test.in | 11 + tests/tpm2_key_protector_test.in | 389 +++ tests/util/grub-shell.in | 6 +- util/grub-protect.c | 1423 ++++++++++ 80 files changed, 20819 insertions(+), 75 deletions(-) create mode 100644 docs/man/grub-protect.h2m create mode 100644 grub-core/commands/tpm2_key_protector/args.c create mode 100644 grub-core/commands/tpm2_key_protector/module.c create mode 100644 grub-core/commands/tpm2_key_protector/tpm2.h create mode 100644 grub-core/commands/tpm2_key_protector/tpm2_args.h create mode 100644 grub-core/commands/tpm2_key_protector/tpm2key.asn create mode 100644 grub-core/commands/tpm2_key_protector/tpm2key.c create mode 100644 grub-core/commands/tpm2_key_protector/tpm2key.h create mode 100644 grub-core/commands/tpm2_key_protector/tpm2key_asn1_tab.c create mode 100644 grub-core/disk/key_protector.c create mode 100644 grub-core/lib/efi/tcg2.c create mode 100644 grub-core/lib/libtasn1-patches/0001-libtasn1-disable-code-not-needed-in-grub.patch create mode 100644 grub-core/lib/libtasn1-patches/0002-libtasn1-use-bound-checked-_asn1_str_cat.patch create mode 100644 grub-core/lib/libtasn1-patches/0003-libtasn1-adjust-the-header-paths-in-libtasn1.h.patch create mode 100644 grub-core/lib/libtasn1-patches/0004-libtasn1-Use-grub_divmod64-for-division.patch create mode 100644 grub-core/lib/libtasn1-patches/0005-libtasn1-fix-the-potential-buffer-overrun.patch create mode 100644 grub-core/lib/libtasn1-patches/0006-asn1_test-changes-for-grub-compatibility.patch create mode 100644 grub-core/lib/libtasn1/COPYING create mode 100644 grub-core/lib/libtasn1/README.md create mode 100644 grub-core/lib/libtasn1/lib/coding.c create mode 100644 grub-core/lib/libtasn1/lib/decoding.c create mode 100644 grub-core/lib/libtasn1/lib/element.c create mode 100644 grub-core/lib/libtasn1/lib/element.h create mode 100644 grub-core/lib/libtasn1/lib/errors.c create mode 100644 grub-core/lib/libtasn1/lib/gstr.c create mode 100644 grub-core/lib/libtasn1/lib/gstr.h create mode 100644 grub-core/lib/libtasn1/lib/int.h create mode 100644 grub-core/lib/libtasn1/lib/parser_aux.c create mode 100644 grub-core/lib/libtasn1/lib/parser_aux.h create mode 100644 grub-core/lib/libtasn1/lib/structure.c create mode 100644 grub-core/lib/libtasn1/lib/structure.h create mode 100644 grub-core/lib/libtasn1/libtasn1.h create mode 100644 grub-core/lib/libtasn1/tests/CVE-2018-1000654-1_asn1_tab.h create mode 100644 grub-core/lib/libtasn1/tests/CVE-2018-1000654-2_asn1_tab.h create mode 100644 grub-core/lib/libtasn1/tests/CVE-2018-1000654.c create mode 100644 grub-core/lib/libtasn1/tests/Test_overflow.c create mode 100644 grub-core/lib/libtasn1/tests/Test_simple.c create mode 100644 grub-core/lib/libtasn1/tests/Test_strings.c create mode 100644 grub-core/lib/libtasn1/tests/object-id-decoding.c create mode 100644 grub-core/lib/libtasn1/tests/object-id-encoding.c create mode 100644 grub-core/lib/libtasn1/tests/octet-string.c create mode 100644 grub-core/lib/libtasn1/tests/reproducers.c create mode 100644 grub-core/lib/libtasn1_wrap/wrap.c create mode 100644 grub-core/lib/posix_wrap/c-ctype.h create mode 100644 grub-core/lib/tss2/buffer.c create mode 100644 grub-core/lib/tss2/tcg2.h create mode 100644 grub-core/lib/tss2/tcg2_emu.c create mode 100644 grub-core/lib/tss2/tpm2_cmd.c create mode 100644 grub-core/lib/tss2/tpm2_cmd.h create mode 100644 grub-core/lib/tss2/tss2.c create mode 100644 grub-core/lib/tss2/tss2_buffer.h create mode 100644 grub-core/lib/tss2/tss2_mu.c create mode 100644 grub-core/lib/tss2/tss2_mu.h create mode 100644 grub-core/lib/tss2/tss2_structs.h create mode 100644 grub-core/lib/tss2/tss2_types.h create mode 100644 grub-core/tests/asn1/asn1_test.c create mode 100644 grub-core/tests/asn1/asn1_test.h create mode 100644 include/grub/key_protector.h create mode 100644 tests/asn1_test.in create mode 100644 tests/tpm2_key_protector_test.in create mode 100644 util/grub-protect.c
Range-diff against v17:
1: 834e3b578 = 1: 77d52a5b7 posix_wrap: tweaks in preparation for libtasn1
2: cdf54d25a ! 2: 931fccd49 libtasn1: import libtasn1-4.19.0
@@ Commit message
tar xf libtasn1-4.19.0.tar.gz
rm -rf grub-core/lib/libtasn1/
mkdir -p grub-core/lib/libtasn1/lib/
+ mkdir -p grub-core/lib/libtasn1/tests/
cp libtasn1-4.19.0/{README.md,COPYING} grub-core/lib/libtasn1/
cp libtasn1-4.19.0/lib/{coding.c,decoding.c,element.c,element.h,errors.c,gstr.c,gstr.h,int.h,parser_aux.c,parser_aux.h,structure.c,structure.h} grub-core/libtasn1/lib/
cp libtasn1-4.19.0/lib/includes/libtasn1.h grub-core/lib/libtasn1/
+ cp libtasn1-4.19.0/tests/{CVE-2018-1000654-1_asn1_tab.h,CVE-2018-1000654-2_asn1_tab.h,CVE-2018-1000654.c,object-id-decoding.c,object-id-encoding.c,octet-string.c,reproducers.c,Test_overflow.c,Test_simple.c,Test_strings.c} grub-core/lib/libtasn1/tests
rm -rf libtasn1-4.19.0*
Signed-off-by: Daniel Axtens <[email protected]>
Signed-off-by: Gary Lin <[email protected]>
Reviewed-by: Vladimir Serbinenko <[email protected]>
+ Reviewed-by: Daniel Kiper <[email protected]>
## grub-core/lib/libtasn1/COPYING (new) ##
@@
@@ grub-core/lib/libtasn1/libtasn1.h (new)
+# endif
+
+#endif /* LIBTASN1_H */
+
+ ## grub-core/lib/libtasn1/tests/CVE-2018-1000654-1_asn1_tab.h (new) ##
+@@
++#if HAVE_CONFIG_H
++# include "config.h"
++#endif
++
++#include <libtasn1.h>
++
++const asn1_static_node CVE_2018_1000654_1_asn1_tab[] = {
++ { "TEST_TREE", 536875024, NULL },
++ { NULL, 1610612748, NULL },
++ { "iso", 1073741825, "1"},
++ { "identified-organization", 1073741825, "3"},
++ { "dod", 1073741825, "6"},
++ { "internet", 1073741825, "1"},
++ { "security", 1073741825, "5"},
++ { "mechanisms", 1073741825, "5"},
++ { "pkix", 1073741825, "7"},
++ { "id-mod", 1073741825, "0"},
++ { "id-pkix1-implicit-88", 1, "2"},
++ { "id-xnyTest", 1879048204, NULL },
++ { NULL, 1073741825, "id-ix"},
++ { NULL, 1073741825, "29"},
++ { NULL, 1, "1"},
++ { "id-ix", 1880096780, "OBJECR"},
++ { NULL, 1073741825, "id-ix"},
++ { NULL, 1073741825, "29"},
++ { NULL, 1, "2"},
++ { "id-xnyTest", 805306380, NULL },
++ { NULL, 1073741825, "id-ix"},
++ { NULL, 1073741825, "29"},
++ { NULL, 1, "1"},
++ { NULL, 0, NULL }
++};
+
+ ## grub-core/lib/libtasn1/tests/CVE-2018-1000654-2_asn1_tab.h (new) ##
+@@
++#if HAVE_CONFIG_H
++# include "config.h"
++#endif
++
++#include <libtasn1.h>
++
++const asn1_static_node CVE_2018_1000654_2_asn1_tab[] = {
++ { "TEST_TREE", 536875024, NULL },
++ { NULL, 1610612748, NULL },
++ { "iso", 1073741825, "1"},
++ { "identified-organization", 1073741825, "3"},
++ { "dod", 1073741825, "6"},
++ { "internet", 1073741825, "1"},
++ { "security", 1073741825, "5"},
++ { "mechanisms", 1073741825, "5"},
++ { "pkix", 1073741825, "7"},
++ { "id-mod", 1073741825, "0"},
++ { "id-pkix1-implicit-88", 1, "2"},
++ { "id-oneTest", 1879048204, NULL },
++ { NULL, 1073741825, "id-two"},
++ { NULL, 1073741825, "9"},
++ { NULL, 1, "1"},
++ { "id-two", 1879048204, NULL },
++ { NULL, 1073741825, "id-three"},
++ { NULL, 1073741825, "2"},
++ { NULL, 1, "2"},
++ { "id-three", 1879048204, NULL },
++ { NULL, 1073741825, "id-four"},
++ { NULL, 1073741825, "3"},
++ { NULL, 1, "3"},
++ { "id-four", 805306380, NULL },
++ { NULL, 1073741825, "id-two"},
++ { NULL, 1073741825, "3"},
++ { NULL, 1, "3"},
++ { NULL, 0, NULL }
++};
+
+ ## grub-core/lib/libtasn1/tests/CVE-2018-1000654.c (new) ##
+@@
++/*
++ * Copyright (C) 2002-2022 Free Software Foundation, Inc.
++ *
++ * This file is part of LIBTASN1.
++ *
++ * This program is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation, either version 3 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
++ *
++ */
++
++/****************************************************************/
++/* Description: reproducer for CVE-2018-1000654 */
++/****************************************************************/
++
++#include <stdio.h>
++#include <string.h>
++#include <stdlib.h>
++#include "CVE-2018-1000654-1_asn1_tab.h"
++#include "CVE-2018-1000654-2_asn1_tab.h"
++
++int
++main (int argc, char *argv[])
++{
++ int result, verbose = 0;
++ asn1_node definitions = NULL;
++ char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE];
++
++ if (argc > 1)
++ verbose = 1;
++
++ printf ("Test 1\n");
++
++ result =
++ asn1_array2tree (CVE_2018_1000654_1_asn1_tab, &definitions,
++ errorDescription);
++ if (result != ASN1_RECURSION)
++ {
++ asn1_perror (result);
++ printf ("ErrorDescription = %s\n\n", errorDescription);
++ exit (1);
++ }
++
++ asn1_delete_structure (&definitions);
++
++ printf ("Test 2\n");
++
++ result =
++ asn1_array2tree (CVE_2018_1000654_2_asn1_tab, &definitions,
++ errorDescription);
++ if (result != ASN1_RECURSION)
++ {
++ asn1_perror (result);
++ printf ("ErrorDescription = %s\n\n", errorDescription);
++ exit (1);
++ }
++
++ asn1_delete_structure (&definitions);
++
++ if (verbose)
++ printf ("Success\n");
++ exit (0);
++}
+
+ ## grub-core/lib/libtasn1/tests/Test_overflow.c (new) ##
+@@
++/*
++ * Copyright (C) 2012-2022 Free Software Foundation, Inc.
++ *
++ * This file is part of LIBTASN1.
++ *
++ * This program is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation, either version 3 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
++ *
++ */
++
++/* Written by Simon Josefsson */
++
++#include <stdio.h>
++#include <string.h>
++#include <stdlib.h>
++#include <limits.h>
++
++#include "libtasn1.h"
++
++int
++main (int argc, char **argv)
++{
++ /* Test that values larger than long are rejected. This has worked
++ fine with all versions of libtasn1. */
++ int verbose = 0;
++
++ if (argc > 1)
++ verbose = 1;
++
++ {
++ unsigned char der[] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF";
++ long l;
++ int len;
++
++ l = asn1_get_length_der (der, sizeof der, &len);
++
++ if (l == -2L)
++ {
++ if (verbose)
++ puts ("OK: asn1_get_length_der bignum");
++ }
++ else
++ {
++ printf ("ERROR: asn1_get_length_der bignum (l %ld len %d)\n", l, len);
++ return 1;
++ }
++ }
++
++ /* Test that values larger than int but smaller than long are
++ rejected. This limitation was introduced with libtasn1 2.12. */
++ if (LONG_MAX > INT_MAX)
++ {
++ unsigned long num = ((long) UINT_MAX) << 2;
++ unsigned char der[20];
++ int der_len;
++ long l;
++ int len;
++
++ asn1_length_der (num, der, &der_len);
++
++ l = asn1_get_length_der (der, der_len, &len);
++
++ if (l == -2L)
++ {
++ if (verbose)
++ puts ("OK: asn1_get_length_der intnum");
++ }
++ else
++ {
++ printf ("ERROR: asn1_get_length_der intnum (l %ld len %d)\n", l,
++ len);
++ return 1;
++ }
++ }
++
++ /* Test that values larger than would fit in the input string are
++ rejected. This problem was fixed in libtasn1 2.12. */
++ {
++ unsigned long num = 64;
++ unsigned char der[20];
++ int der_len;
++ long l;
++ int len;
++
++ asn1_length_der (num, der, &der_len);
++
++ der_len = sizeof (der);
++ l = asn1_get_length_der (der, der_len, &len);
++
++ if (l == -4L)
++ {
++ if (verbose)
++ puts ("OK: asn1_get_length_der overflow-small");
++ }
++ else
++ {
++ printf ("ERROR: asn1_get_length_der overflow-small (l %ld len %d)\n",
++ l, len);
++ return 1;
++ }
++ }
++
++ /* Test that values larger than would fit in the input string are
++ rejected. This problem was fixed in libtasn1 2.12. */
++ {
++ unsigned long num = 1073741824;
++ unsigned char der[20];
++ int der_len;
++ long l;
++ int len;
++
++ asn1_length_der (num, der, &der_len);
++
++ der_len = sizeof (der);
++ l = asn1_get_length_der (der, der_len, &len);
++
++ if (l == -4L)
++ {
++ if (verbose)
++ puts ("OK: asn1_get_length_der overflow-large1");
++ }
++ else
++ {
++ printf ("ERROR: asn1_get_length_der overflow-large1 (l %ld len %d)\n",
++ l, len);
++ return 1;
++ }
++ }
++
++ /* Test that values larger than would fit in the input string are
++ rejected. This problem was fixed in libtasn1 2.12. */
++ {
++ unsigned long num = 2147483649;
++ unsigned char der[20];
++ int der_len;
++ long l;
++ int len;
++
++ asn1_length_der (num, der, &der_len);
++
++ der_len = sizeof (der);
++ l = asn1_get_length_der (der, der_len, &len);
++
++ if (l == -2L)
++ {
++ if (verbose)
++ puts ("OK: asn1_get_length_der overflow-large2");
++ }
++ else
++ {
++ printf ("ERROR: asn1_get_length_der overflow-large2 (l %ld len %d)\n",
++ l, len);
++ return 1;
++ }
++ }
++
++ return 0;
++}
+
+ ## grub-core/lib/libtasn1/tests/Test_simple.c (new) ##
+@@
++/*
++ * Copyright (C) 2011-2022 Free Software Foundation, Inc.
++ *
++ * This file is part of LIBTASN1.
++ *
++ * This program is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation, either version 3 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
++ *
++ * Written by Simon Josefsson
++ *
++ */
++
++#include <stdio.h>
++#include <string.h>
++#include <stdlib.h>
++
++#include "libtasn1.h"
++
++struct tv
++{
++ int bitlen;
++ const char *bitstr;
++ int derlen;
++ const char *der;
++};
++
++static const struct tv tv[] = {
++ {0, "", 2, "\x01\x00"},
++ {1, "\x00", 3, "\x02\x07\x00"},
++ {2, "\x00", 3, "\x02\x06\x00"},
++ {3, "\x00", 3, "\x02\x05\x00"},
++ {4, "\x00", 3, "\x02\x04\x00"},
++ {5, "\x00", 3, "\x02\x03\x00"},
++ {6, "\x00", 3, "\x02\x02\x00"},
++ {7, "\x00", 3, "\x02\x01\x00"},
++ {8, "\x00\x00", 3, "\x02\x00\x00"},
++ {9, "\x00\x00", 4, "\x03\x07\x00\x00"},
++ {10, "\x00\x00", 4, "\x03\x06\x00\x00"},
++ {11, "\x00\x00", 4, "\x03\x05\x00\x00"},
++ {12, "\x00\x00", 4, "\x03\x04\x00\x00"},
++ {13, "\x00\x00", 4, "\x03\x03\x00\x00"},
++ {14, "\x00\x00", 4, "\x03\x02\x00\x00"},
++ {15, "\x00\x00", 4, "\x03\x01\x00\x00"},
++ {16, "\x00\x00", 4, "\x03\x00\x00\x00"},
++ {17, "\x00\x00\x00", 5, "\x04\x07\x00\x00\x00"},
++ {18, "\x00\x00\x00", 5, "\x04\x06\x00\x00\x00"},
++ {19, "\x00\x00\x00", 5, "\x04\x05\x00\x00\x00"},
++ {1, "\xFF", 3, "\x02\x07\x80"},
++ {2, "\xFF", 3, "\x02\x06\xc0"},
++ {3, "\xFF", 3, "\x02\x05\xe0"},
++ {4, "\xFF", 3, "\x02\x04\xf0"},
++ {5, "\xFF", 3, "\x02\x03\xf8"},
++ {6, "\xFF", 3, "\x02\x02\xfc"},
++ {7, "\xFF", 3, "\x02\x01\xfe"},
++ {8, "\xFF\xFF", 3, "\x02\x00\xff"},
++ {9, "\xFF\xFF", 4, "\x03\x07\xff\x80"},
++ {10, "\xFF\xFF", 4, "\x03\x06\xff\xc0"},
++ {11, "\xFF\xFF", 4, "\x03\x05\xff\xe0"},
++ {12, "\xFF\xFF", 4, "\x03\x04\xff\xf0"},
++ {13, "\xFF\xFF", 4, "\x03\x03\xff\xf8"},
++ {14, "\xFF\xFF", 4, "\x03\x02\xff\xfc"},
++ {15, "\xFF\xFF", 4, "\x03\x01\xff\xfe"},
++ {16, "\xFF\xFF", 4, "\x03\x00\xff\xff"},
++ {17, "\xFF\xFF\xFF", 5, "\x04\x07\xff\xff\x80"},
++ {18, "\xFF\xFF\xFF", 5, "\x04\x06\xff\xff\xc0"},
++ {19, "\xFF\xFF\xFF", 5, "\x04\x05\xff\xff\xe0"},
++};
++
++int
++main (int argc, char *argv[])
++{
++ int result;
++ unsigned char der[100];
++ unsigned char str[100];
++ int der_len = sizeof (der);
++ int str_size = sizeof (str);
++ int ret_len, bit_len;
++ size_t i;
++
++ {
++ unsigned int etype = 38;
++ unsigned int my_str_len = 10;
++ unsigned char my_str[10];
++ unsigned int tl_len = 10;
++ unsigned char tl[10];
++
++ /* https://gitlab.com/gnutls/libtasn1/-/issues/32 */
++ result = asn1_encode_simple_der (etype, my_str, my_str_len, tl, &tl_len);
++ if (result != ASN1_VALUE_NOT_VALID)
++ {
++ fprintf (stderr, "asn1_encode_simple_der out of range etype\n");
++ return 1;
++ }
++ }
++
++ /* Dummy test */
++
++ asn1_bit_der (NULL, 0, der, &der_len);
++ result = asn1_get_bit_der (der, 0, &ret_len, str, str_size, &bit_len);
++ if (result != ASN1_GENERIC_ERROR)
++ {
++ fprintf (stderr, "asn1_get_bit_der zero\n");
++ return 1;
++ }
++
++ /* Encode short strings with increasing bit lengths */
++
++ for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++)
++ {
++ /* Encode */
++
++ asn1_bit_der ((const unsigned char *) tv[i].bitstr, tv[i].bitlen,
++ der, &der_len);
++
++#if 0
++ {
++ size_t j;
++ for (j = 0; j < der_len; j++)
++ printf ("\\x%02x", der[j]);
++ printf ("\n");
++ }
++#endif
++
++ if (der_len != tv[i].derlen || memcmp (der, tv[i].der, der_len) != 0)
++ {
++ fprintf (stderr, "asn1_bit_der iter %lu\n", (unsigned long) i);
++ return 1;
++ }
++
++ /* Decode it */
++
++ result = asn1_get_bit_der (der, der_len, &ret_len, str,
++ str_size, &bit_len);
++ if (result != ASN1_SUCCESS || ret_len != tv[i].derlen
++ || bit_len != tv[i].bitlen)
++ {
++ fprintf (stderr, "asn1_get_bit_der iter %lu, err: %d\n",
++ (unsigned long) i, result);
++ return 1;
++ }
++ }
++
++
++ /* Decode sample from "A Layman's Guide to a Subset of ASN.1, BER,
++ and DER" section 5.4 "BIT STRING": "The BER encoding of the BIT
++ STRING value "011011100101110111" can be any of the following,
++ among others, depending on the choice of padding bits, the form
++ of length octets [...]".
++ */
++
++ /* 03 04 06 6e 5d c0 DER encoding */
++
++ memcpy (der, "\x04\x06\x6e\x5d\xc0", 5);
++ der_len = 5;
++
++ result = asn1_get_bit_der (der, der_len, &ret_len, str, str_size, &bit_len);
++ if (result != ASN1_SUCCESS || ret_len != 5
++ || bit_len != 18 || memcmp (str, "\x6e\x5d\xc0", 3) != 0)
++ {
++ fprintf (stderr, "asn1_get_bit_der example\n");
++ return 1;
++ }
++
++ der_len = sizeof (der);
++ asn1_bit_der (str, bit_len, der, &der_len);
++ if (der_len != 5 || memcmp (der, "\x04\x06\x6e\x5d\xc0", 5) != 0)
++ {
++ fprintf (stderr, "asn1_bit_der example roundtrip\n");
++ return 1;
++ }
++
++ /* 03 04 06 6e 5d e0 padded with "100000" */
++
++ memcpy (der, "\x04\x06\x6e\x5d\xe0", 5);
++ der_len = 5;
++
++ result = asn1_get_bit_der (der, der_len, &ret_len, str, str_size, &bit_len);
++ if (result != ASN1_SUCCESS || ret_len != 5
++ || bit_len != 18 || memcmp (str, "\x6e\x5d\xe0", 3) != 0)
++ {
++ fprintf (stderr, "asn1_get_bit_der example padded\n");
++ return 1;
++ }
++
++ der_len = sizeof (der);
++ asn1_bit_der (str, bit_len, der, &der_len);
++ if (der_len != 5 || memcmp (der, "\x04\x06\x6e\x5d\xc0", 5) != 0)
++ {
++ fprintf (stderr, "asn1_bit_der example roundtrip\n");
++ return 1;
++ }
++
++ /* 03 81 04 06 6e 5d c0 long form of length octets */
++
++ memcpy (der, "\x81\x04\x06\x6e\x5d\xc0", 6);
++ der_len = 6;
++
++ result = asn1_get_bit_der (der, der_len, &ret_len, str, str_size, &bit_len);
++
++ if (result != ASN1_SUCCESS || ret_len != 6
++ || bit_len != 18 || memcmp (str, "\x6e\x5d\xc0", 3) != 0)
++ {
++ fprintf (stderr, "asn1_get_bit_der example long form\n");
++ return 1;
++ }
++
++ der_len = sizeof (der);
++ asn1_bit_der (str, bit_len, der, &der_len);
++ if (der_len != 5 || memcmp (der, "\x04\x06\x6e\x5d\xc0", 5) != 0)
++ {
++ fprintf (stderr, "asn1_bit_der example roundtrip\n");
++ return 1;
++ }
++
++ return 0;
++}
+
+ ## grub-core/lib/libtasn1/tests/Test_strings.c (new) ##
+@@
++/*
++ * Copyright (C) 2012-2022 Free Software Foundation, Inc.
++ *
++ * This file is part of LIBTASN1.
++ *
++ * This program is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation, either version 3 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
++ *
++ * Written by Simon Josefsson
++ *
++ */
++
++#include <stdio.h>
++#include <string.h>
++#include <stdlib.h>
++
++#include "libtasn1.h"
++
++struct tv
++{
++ unsigned int etype;
++ unsigned int str_len;
++ const void *str;
++ unsigned int der_len;
++ const void *der;
++};
++
++static const struct tv tv[] = {
++ {ASN1_ETYPE_IA5_STRING, 20,
++ "\x63\x73\x63\x61\x40\x70\x61\x73\x73\x70\x6f\x72\x74\x2e\x67\x6f\x76\x2e\x67\x72",
++ 22,
++ "\x16\x14\x63\x73\x63\x61\x40\x70\x61\x73\x73\x70\x6f\x72\x74\x2e\x67\x6f\x76\x2e\x67\x72"},
++ {ASN1_ETYPE_PRINTABLE_STRING, 5, "\x4e\x69\x6b\x6f\x73",
++ 7, "\x13\x05\x4e\x69\x6b\x6f\x73"},
++ {ASN1_ETYPE_UTF8_STRING, 12, "Αττική",
++ 14, "\x0c\x0c\xce\x91\xcf\x84\xcf\x84\xce\xb9\xce\xba\xce\xae"},
++ {ASN1_ETYPE_TELETEX_STRING, 15,
++ "\x53\x69\x6d\x6f\x6e\x20\x4a\x6f\x73\x65\x66\x73\x73\x6f\x6e",
++ 17,
++ "\x14\x0f\x53\x69\x6d\x6f\x6e\x20\x4a\x6f\x73\x65\x66\x73\x73\x6f\x6e"},
++ {ASN1_ETYPE_OCTET_STRING, 36,
++ "\x30\x22\x80\x0F\x32\x30\x31\x31\x30\x38\x32\x31\x30\x38\x30\x30\x30\x36\x5A\x81\x0F\x32\x30\x31\x31\x30\x38\x32\x33\x32\x30\x35\x39\x35\x39\x5A",
++ 38,
++ "\x04\x24\x30\x22\x80\x0F\x32\x30\x31\x31\x30\x38\x32\x31\x30\x38\x30\x30\x30\x36\x5A\x81\x0F\x32\x30\x31\x31\x30\x38\x32\x33\x32\x30\x35\x39\x35\x39\x5A"}
++};
++
++#define SSTR(x) sizeof(x)-1,x
++static const struct tv ber[] = {
++ {ASN1_ETYPE_OCTET_STRING,
++ SSTR ("\xa0\xa0"),
++ SSTR ("\x24\x80\x04\x82\x00\x02\xa0\xa0\x00\x00")},
++ {ASN1_ETYPE_OCTET_STRING,
++ SSTR ("\xa0\xa0\xb0\xb0\xb0"),
++ SSTR
++ ("\x24\x80\x04\x82\x00\x02\xa0\xa0\x04\x82\x00\x03\xb0\xb0\xb0\x00\x00")},
++ {ASN1_ETYPE_OCTET_STRING,
++ SSTR ("\xa0\xa0\xb0\xb0\xb0\xa1\xa1"),
++ SSTR
++ ("\x24\x80\x04\x82\x00\x02\xa0\xa0\x04\x82\x00\x03\xb0\xb0\xb0\x24\x80\x04\x82\x00\x02\xa1\xa1\x00\x00\x00\x00")},
++ {ASN1_ETYPE_OCTET_STRING,
++ SSTR ("\xa0\xa0\xb0\xb0\xb0\xa1\xa1\xc1"),
++ SSTR
++ ("\x24\x80\x04\x82\x00\x02\xa0\xa0\x04\x82\x00\x03\xb0\xb0\xb0\x24\x80\x04\x82\x00\x02\xa1\xa1\x04\x82\x00\x01\xc1\x00\x00\x00\x00")},
++};
++
++int
++main (int argc, char *argv[])
++{
++ int ret;
++ unsigned char tl[ASN1_MAX_TL_SIZE];
++ unsigned int tl_len, der_len, str_len;
++ const unsigned char *str;
++ unsigned char *b;
++ unsigned int i;
++
++ /* Dummy test */
++
++ for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++)
++ {
++ /* Encode */
++ tl_len = sizeof (tl);
++ ret = asn1_encode_simple_der (tv[i].etype, tv[i].str, tv[i].str_len,
++ tl, &tl_len);
++ if (ret != ASN1_SUCCESS)
++ {
++ fprintf (stderr, "Encoding error in %u: %s\n", i,
++ asn1_strerror (ret));
++ return 1;
++ }
++ der_len = tl_len + tv[i].str_len;
++
++ if (der_len != tv[i].der_len || memcmp (tl, tv[i].der, tl_len) != 0)
++ {
++ fprintf (stderr,
++ "DER encoding differs in %u! (size: %u, expected: %u)\n",
++ i, der_len, tv[i].der_len);
++ return 1;
++ }
++
++ /* decoding */
++ ret =
++ asn1_decode_simple_der (tv[i].etype, tv[i].der, tv[i].der_len, &str,
++ &str_len);
++ if (ret != ASN1_SUCCESS)
++ {
++ fprintf (stderr, "Decoding error in %u: %s\n", i,
++ asn1_strerror (ret));
++ return 1;
++ }
++
++ if (str_len != tv[i].str_len || memcmp (str, tv[i].str, str_len) != 0)
++ {
++ fprintf (stderr,
++ "DER decoded data differ in %u! (size: %u, expected: %u)\n",
++ i, der_len, tv[i].str_len);
++ return 1;
++ }
++ }
++
++ /* BER decoding */
++ for (i = 0; i < sizeof (ber) / sizeof (ber[0]); i++)
++ {
++ /* decoding */
++ ret =
++ asn1_decode_simple_ber (ber[i].etype, ber[i].der, ber[i].der_len, &b,
++ &str_len, NULL);
++ if (ret != ASN1_SUCCESS)
++ {
++ fprintf (stderr, "BER decoding error in %u: %s\n", i,
++ asn1_strerror (ret));
++ return 1;
++ }
++
++ if (str_len != ber[i].str_len || memcmp (b, ber[i].str, str_len) != 0)
++ {
++ fprintf (stderr,
++ "BER decoded data differ in %u! (size: %u, expected: %u)\n",
++ i, str_len, ber[i].str_len);
++ return 1;
++ }
++ free (b);
++ }
++
++
++ return 0;
++}
+
+ ## grub-core/lib/libtasn1/tests/object-id-decoding.c (new) ##
+@@
++/*
++ * Copyright (C) 2016 Red Hat, Inc.
++ *
++ * This file is part of LIBTASN1.
++ *
++ * This program is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation, either version 3 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
++ *
++ */
++
++#include <stdio.h>
++#include <string.h>
++#include <stdlib.h>
++
++#include "libtasn1.h"
++
++struct tv
++{
++ int der_len;
++ const unsigned char *der;
++ const char *oid;
++ int expected_error;
++};
++
++static const struct tv tv[] = {
++ {.der_len = 5,
++ .der = (void *) "\x06\x03\x80\x37\x03",
++ .oid = "2.999.3",
++ .expected_error = ASN1_DER_ERROR /* leading 0x80 */
++ },
++ {.der_len = 12,
++ .der = (void *) "\x06\x0a\x2b\x06\x01\x80\x01\x92\x08\x09\x05\x01",
++ .oid = "1.3.6.1.4.1.2312.9.5.1",
++ .expected_error = ASN1_DER_ERROR /* leading 0x80 */
++ },
++ {.der_len = 6,
++ .der = (void *) "\x06\x04\x01\x02\x03\x04",
++ .oid = "0.1.2.3.4",
++ .expected_error = ASN1_SUCCESS},
++ {.der_len = 5,
++ .der = (void *) "\x06\x03\x51\x02\x03",
++ .oid = "2.1.2.3",
++ .expected_error = ASN1_SUCCESS},
++ {.der_len = 5,
++ .der = (void *) "\x06\x03\x88\x37\x03",
++ .oid = "2.999.3",
++ .expected_error = ASN1_SUCCESS},
++ {.der_len = 12,
++ .der = (void *) "\x06\x0a\x2b\x06\x01\x04\x01\x92\x08\x09\x05\x01",
++ .oid = "1.3.6.1.4.1.2312.9.5.1",
++ .expected_error = ASN1_SUCCESS},
++ {.der_len = 19,
++ .der =
++ (void *)
++ "\x06\x11\xfa\x80\x00\x00\x00\x0e\x01\x0e\xfa\x80\x00\x00\x00\x0e\x63\x6f\x6d",
++ .oid = "2.1998768.0.0.14.1.14.1998848.0.0.14.99.111.109",
++ .expected_error = ASN1_SUCCESS},
++ {.der_len = 19,
++ .der =
++ (void *)
++ "\x06\x11\x2b\x06\x01\x04\x01\x92\x08\x09\x02\xaa\xda\xbe\xbe\xfa\x72\x01\x07",
++ .oid = "1.3.6.1.4.1.2312.9.2.1467399257458.1.7",
++ .expected_error = ASN1_SUCCESS},
++};
++
++int
++main (int argc, char *argv[])
++{
++ char str[128];
++ int ret, ret_len;
++ size_t i;
++
++ for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++)
++ {
++ /* decode */
++ ret =
++ asn1_get_object_id_der (tv[i].der + 1,
++ tv[i].der_len - 1, &ret_len, str,
++ sizeof (str));
++ if (ret != tv[i].expected_error)
++ {
++ fprintf (stderr,
++ "%d: asn1_get_object_id_der iter %lu: got '%s' expected %d\n",
++ __LINE__, (unsigned long) i, asn1_strerror (ret),
++ tv[i].expected_error);
++ return 1;
++ }
++
++ if (tv[i].expected_error != ASN1_SUCCESS)
++ continue;
++
++ if (ret_len != tv[i].der_len - 1)
++ {
++ fprintf (stderr,
++ "%d: iter %lu: error in DER, length returned is %d, had %d\n",
++ __LINE__, (unsigned long) i, ret_len, tv[i].der_len - 1);
++ return 1;
++ }
++
++ if (strcmp (tv[i].oid, str) != 0)
++ {
++ fprintf (stderr,
++ "%d: strcmp iter %lu: got invalid OID: %s, expected: %s\n",
++ __LINE__, (unsigned long) i, str, tv[i].oid);
++ return 1;
++ }
++
++ }
++
++ return 0;
++}
+
+ ## grub-core/lib/libtasn1/tests/object-id-encoding.c (new) ##
+@@
++/*
++ * Copyright (C) 2019 Nikos Mavrogiannopoulos
++ *
++ * This file is part of LIBTASN1.
++ *
++ * This program is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation, either version 3 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
++ *
++ */
++
++#include <stdio.h>
++#include <string.h>
++#include <stdlib.h>
++
++#include "libtasn1.h"
++
++struct tv
++{
++ int der_len;
++ const unsigned char *der;
++ const char *oid;
++ int expected_error;
++};
++
++static const struct tv tv[] = {
++ {.der_len = 0,
++ .der = (void *) "",
++ .oid = "5.999.3",
++ .expected_error = ASN1_VALUE_NOT_VALID /* cannot start with 5 */
++ },
++ {.der_len = 0,
++ .der = (void *) "",
++ .oid = "0.48.9",
++ .expected_error = ASN1_VALUE_NOT_VALID /* second field cannot be 48 */
++ },
++ {.der_len = 0,
++ .der = (void *) "",
++ .oid = "1.40.9",
++ .expected_error = ASN1_VALUE_NOT_VALID /* second field cannot be 40 */
++ },
++ {.der_len = 4,
++ .der = (void *) "\x06\x02\x4f\x63",
++ .oid = "1.39.99",
++ .expected_error = ASN1_SUCCESS,
++ },
++ {.der_len = 6,
++ .der = (void *) "\x06\x04\x01\x02\x03\x04",
++ .oid = "0.1.2.3.4",
++ .expected_error = ASN1_SUCCESS},
++ {.der_len = 5,
++ .der = (void *) "\x06\x03\x51\x02\x03",
++ .oid = "2.1.2.3",
++ .expected_error = ASN1_SUCCESS},
++ {.der_len = 5,
++ .der = (void *) "\x06\x03\x88\x37\x03",
++ .oid = "2.999.3",
++ .expected_error = ASN1_SUCCESS},
++ {.der_len = 12,
++ .der = (void *) "\x06\x0a\x2b\x06\x01\x04\x01\x92\x08\x09\x05\x01",
++ .oid = "1.3.6.1.4.1.2312.9.5.1",
++ .expected_error = ASN1_SUCCESS},
++ {.der_len = 19,
++ .der =
++ (void *)
++ "\x06\x11\xfa\x80\x00\x00\x00\x0e\x01\x0e\xfa\x80\x00\x00\x00\x0e\x63\x6f\x6d",
++ .oid = "2.1998768.0.0.14.1.14.1998848.0.0.14.99.111.109",
++ .expected_error = ASN1_SUCCESS},
++ {.der_len = 19,
++ .der =
++ (void *)
++ "\x06\x11\x2b\x06\x01\x04\x01\x92\x08\x09\x02\xaa\xda\xbe\xbe\xfa\x72\x01\x07",
++ .oid = "1.3.6.1.4.1.2312.9.2.1467399257458.1.7",
++ .expected_error = ASN1_SUCCESS},
++};
++
++int
++main (int argc, char *argv[])
++{
++ unsigned char der[128];
++ int ret, der_len, i, j;
++
++ for (i = 0; i < (int) (sizeof (tv) / sizeof (tv[0])); i++)
++ {
++ der_len = sizeof (der);
++ ret = asn1_object_id_der (tv[i].oid, der, &der_len, 0);
++ if (ret != ASN1_SUCCESS)
++ {
++ if (ret == tv[i].expected_error)
++ continue;
++ fprintf (stderr,
++ "%d: iter %lu, encoding of OID failed: %s\n",
++ __LINE__, (unsigned long) i, asn1_strerror (ret));
++ return 1;
++ }
++ else if (ret != tv[i].expected_error)
++ {
++ fprintf (stderr,
++ "%d: iter %lu, encoding of OID %s succeeded when expecting failure\n",
++ __LINE__, (unsigned long) i, tv[i].oid);
++ return 1;
++ }
++
++ if (der_len != tv[i].der_len || memcmp (der, tv[i].der, der_len) != 0)
++ {
++ fprintf (stderr,
++ "%d: iter %lu, re-encoding of OID %s resulted to different string (%d vs %d bytes)\n",
++ __LINE__, (unsigned long) i, tv[i].oid, der_len,
++ tv[i].der_len);
++ fprintf (stderr, "\nGot:\t\t");
++ for (j = 0; j < der_len; j++)
++ fprintf (stderr, "%.2x", der[j]);
++
++ fprintf (stderr, "\nExpected:\t");
++ for (j = 0; j < tv[i].der_len; j++)
++ fprintf (stderr, "%.2x", tv[i].der[j]);
++ fprintf (stderr, "\n");
++
++ return 1;
++ }
++ }
++
++ return 0;
++}
+
+ ## grub-core/lib/libtasn1/tests/octet-string.c (new) ##
+@@
++/*
++ * Copyright (C) 2011-2022 Free Software Foundation, Inc.
++ *
++ * This file is part of LIBTASN1.
++ *
++ * This program is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation, either version 3 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
++ *
++ * Written by Simon Josefsson and Nikos Mavrogiannopoulos
++ *
++ */
++
++#include <stdio.h>
++#include <string.h>
++#include <stdlib.h>
++
++#include "libtasn1.h"
++
++struct tv
++{
++ const char *name;
++ int der_len;
++ const unsigned char *der_str;
++ int len;
++ const unsigned char *string;
++ int expected_error;
++ int ber;
++};
++
++static const struct tv tv[] = {
++ {.name = "primitive octet strings",
++ .der_len = 10,
++ .der_str = (void *) "\x04\x08\x01\x23\x45\x67\x89\xab\xcd\xef",
++ .len = 8,
++ .string = (void *) "\x01\x23\x45\x67\x89\xab\xcd\xef",
++ .ber = 0},
++ {.der_len = 22,
++ .der_str =
++ (void *)
++ "\x04\x14\x13\x00\xd9\xa8\x47\xf7\xf2\x1c\xf4\xb0\xec\x5f\xc1\x73\xe5\x1b\x25\xc2\x62\x27",
++ .len = 20,
++ .string =
++ (void *)
++ "\x13\x00\xD9\xA8\x47\xF7\xF2\x1C\xF4\xB0\xEC\x5F\xC1\x73\xE5\x1B\x25\xC2\x62\x27"},
++
++ {.name = "long type of length",
++ .der_len = 23,
++ .der_str =
++ (void *)
++ "\x04\x81\x14\x13\x00\xd9\xa8\x47\xf7\xf2\x1c\xf4\xb0\xec\x5f\xc1\x73\xe5\x1b\x25\xc2\x62\x27",
++ .len = 20,
++ .string =
++ (void *)
++ "\x13\x00\xD9\xA8\x47\xF7\xF2\x1C\xF4\xB0\xEC\x5F\xC1\x73\xE5\x1B\x25\xC2\x62\x27",
++ .ber = 1},
++ {.der_len = 11,
++ .der_str = (void *) "\x04\x81\x08\x01\x23\x45\x67\x89\xab\xcd\xef",
++ .len = 8,
++ .string = (void *) "\x01\x23\x45\x67\x89\xab\xcd\xef",
++ .ber = 1},
++
++ {.name = "constructed - indefinite",
++ .der_len = 11,
++ .der_str = (void *) "\x24\x80\x04\x05\x01\x02\x03\x04\x05\x00\x00",
++ .len = 5,
++ .string = (void *) "\x01\x02\x03\x04\x05",
++ .ber = 1,
++ },
++
++ {.name = "constructed - definite - concat",
++ .der_len = 12,
++ .der_str = (void *) "\x24\x0a\x04\x04\x0a\x0b\x0c\x0d\x04\x02\x0e\x0f",
++ .len = 6,
++ .string = (void *) "\x0a\x0b\x0c\x0d\x0e\x0f",
++ .ber = 1,
++ },
++ {.name = "constructed - definite - recursive",
++ .der_len = 15,
++ .der_str =
++ (void *) "\x24\x0d\x04\x04\x0a\x0b\x0c\x0d\x24\x05\x04\x00\x04\x01\x0f",
++ .len = 5,
++ .string = (void *) "\x0a\x0b\x0c\x0d\x0f",
++ .ber = 1,
++ },
++ {.name = "constructed - definite - single",
++ .der_len = 7,
++ .der_str = (void *) "\x24\x05\x04\x03\x01\x02\x03",
++ .len = 3,
++ .string = (void *) "\x01\x02\x03",
++ .ber = 1,
++ },
++
++ /* a large amount of recursive indefinite encoding */
++ {.name = "a large amount of recursive indefinite encoding",
++ .der_len = 29325,
++ .der_str =
++ (void *)
++ "\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80\x24\x80",
++ .len = 0,
++ .ber = 1,
++ .expected_error = ASN1_DER_ERROR}
++};
++
++int
++main (int argc, char *argv[])
++{
++ unsigned char str[100];
++ unsigned char der[100];
++ int der_len = sizeof (der);
++ int str_size = sizeof (str);
++ unsigned char *tmp = NULL;
++ int ret, ret_len, j;
++ size_t i;
++
++ for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++)
++ {
++ /* Decode */
++
++ if (tv[i].ber == 0)
++ {
++ str_size = sizeof (str);
++ ret =
++ asn1_get_octet_der (tv[i].der_str + 1,
++ tv[i].der_len - 1, &ret_len, str,
++ sizeof (str), &str_size);
++ if (ret != tv[i].expected_error)
++ {
++ fprintf (stderr,
++ "%d: asn1_get_octet_der: %s: got %d expected %d\n",
++ __LINE__, tv[i].name, ret, tv[i].expected_error);
++ return 1;
++ }
++ if (tv[i].expected_error)
++ continue;
++
++ if (ret_len != tv[i].der_len - 1)
++ {
++ fprintf (stderr,
++ "%d: error in DER, length returned is %d, had %d\n",
++ __LINE__, ret_len, tv[i].der_len - 1);
++ return 1;
++ }
++
++ if (str_size != tv[i].len
++ || memcmp (tv[i].string, str, tv[i].len) != 0)
++ {
++ fprintf (stderr,
++ "%d: memcmp: %s: got invalid decoding\n",
++ __LINE__, tv[i].name);
++
++ fprintf (stderr, "\nGot:\t\t");
++ for (j = 0; j < str_size; j++)
++ fprintf (stderr, "%.2x", str[j]);
++
++ fprintf (stderr, "\nExpected:\t");
++ for (j = 0; j < tv[i].len; j++)
++ fprintf (stderr, "%.2x", tv[i].string[j]);
++ fprintf (stderr, "\n");
++ return 1;
++ }
++
++ /* Encode */
++ der_len = sizeof (der);
++ asn1_octet_der (str, str_size, der, &der_len);
++
++ if (der_len != tv[i].der_len - 1
++ || memcmp (tv[i].der_str + 1, der, tv[i].der_len - 1) != 0)
++ {
++ fprintf (stderr,
++ "encoding: %s: got invalid encoding\n", tv[i].name);
++ return 1;
++ }
++ }
++
++ ret =
++ asn1_decode_simple_ber (ASN1_ETYPE_OCTET_STRING,
++ tv[i].der_str, tv[i].der_len,
++ &tmp, (unsigned int *) &str_size,
++ (unsigned int *) &der_len);
++ if (ret != tv[i].expected_error)
++ {
++ fprintf (stderr,
++ "%d: asn1_decode_simple_ber: %s: got %s expected %s\n",
++ __LINE__, tv[i].name, asn1_strerror (ret),
++ asn1_strerror (tv[i].expected_error));
++ return 1;
++ }
++ if (tv[i].expected_error)
++ continue;
++
++ if (der_len != tv[i].der_len)
++ {
++ fprintf (stderr,
++ "%d: error: %s: DER, length returned is %d, had %d\n",
++ __LINE__, tv[i].name, der_len, tv[i].der_len);
++ return 1;
++ }
++
++ if (str_size != tv[i].len || memcmp (tv[i].string, tmp, tv[i].len) != 0)
++ {
++ fprintf (stderr,
++ "%d: memcmp: %s: got invalid decoding\n",
++ __LINE__, tv[i].name);
++ fprintf (stderr, "\nGot:\t\t");
++ for (j = 0; j < str_size; j++)
++ fprintf (stderr, "%.2x", tmp[j]);
++
++ fprintf (stderr, "\nExpected:\t");
++ for (j = 0; j < tv[i].len; j++)
++ fprintf (stderr, "%.2x", tv[i].string[j]);
++ fprintf (stderr, "\n");
++ return 1;
++ }
++ free (tmp);
++ tmp = NULL;
++
++ }
++
++ return 0;
++}
+
+ ## grub-core/lib/libtasn1/tests/reproducers.c (new) ##
+@@
++/*
++ * Copyright (C) 2019-2022 Free Software Foundation, Inc.
++ *
++ * This file is part of LIBTASN1.
++ *
++ * This program is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation, either version 3 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
++ *
++ */
++
++/****************************************************************/
++/* Description: run reproducers for several fixed issues */
++/****************************************************************/
++
++#include <stdio.h>
++#include <string.h>
++#include <stdlib.h>
++
++#include <libtasn1.h>
++
++#include <int.h>
++
++/* produces endless loop (fixed by d4b624b2):
++ * The following translates into a single node with all pointers
++ * (right,left,down) set to NULL. */
++const asn1_static_node endless_asn1_tab[] = {
++ {"TEST_TREE", 536875024, NULL},
++ {NULL, 0, NULL}
++};
++
++/* produces memory leak (fixed by f16d1ff9):
++ * 152 bytes in 1 blocks are definitely lost in loss record 1 of 1
++ * at 0x4837B65: calloc (vg_replace_malloc.c:762)
++ * by 0x4851C0D: _asn1_add_static_node (parser_aux.c:71)
++ * by 0x4853AAC: asn1_array2tree (structure.c:200)
++ * by 0x10923B: main (single_node.c:67)
++ */
++const asn1_static_node tab[] = {
++ {"a", CONST_DOWN, ""},
++ {"b", 0, ""},
++ {"c", 0, ""},
++ {NULL, 0, NULL}
++};
++
++int
++main (int argc, char *argv[])
++{
++ int result, verbose = 0;
++ asn1_node definitions = NULL;
++ char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE];
++
++ if (argc > 1)
++ verbose = 1;
++
++ result = asn1_array2tree (endless_asn1_tab, &definitions, errorDescription);
++ if (result != ASN1_SUCCESS)
++ {
++ asn1_perror (result);
++ printf ("ErrorDescription = %s\n\n", errorDescription);
++ exit (EXIT_FAILURE);
++ }
++
++ asn1_delete_structure (&definitions);
++
++ definitions = NULL;
++ result = asn1_array2tree (tab, &definitions, errorDescription);
++ if (result != ASN1_SUCCESS)
++ {
++ asn1_perror (result);
++ printf ("ErrorDescription = %s\n\n", errorDescription);
++ exit (EXIT_FAILURE);
++ }
++
++ asn1_delete_structure (&definitions);
++
++ if (verbose)
++ printf ("Success\n");
++
++ exit (EXIT_SUCCESS);
++} 3: 4055c72d0 ! 3: 1ca207217 libtasn1: disable code not needed in grub
@@ Metadata
## Commit message ##
libtasn1: disable code not needed in grub
- Based on the patch from "Daniel Axtens <[email protected]>"
-
We don't expect to be able to write ASN.1, only read it, so we can disable some code.
@@ Commit message
which is convenient because it means we don't have to import it from gnulib.
+ Signed-off-by: Daniel Axtens <[email protected]>
+ Reviewed-by: Daniel Kiper <[email protected]>
## grub-core/lib/libtasn1-patches/0001-libtasn1-disable-code-not-needed-in-grub.patch (new) ##
@@
-+From f95a7b9c72fe91e44a90067c9008791a15e490c0 Mon Sep 17 00:00:00 2001
++From 6b61d48782dc67bed72af70aa5db5b9cb1b4f1d0 Mon Sep 17 00:00:00 2001
+From: Daniel Axtens <[email protected]>
+Date: Fri, 1 May 2020 17:12:23 +1000
-+Subject: [PATCH 1/3] libtasn1: disable code not needed in grub
++Subject: [PATCH 1/6] libtasn1: disable code not needed in grub
+
+We don't expect to be able to write ASN.1, only read it,
+so we can disable some code.
@@ grub-core/lib/libtasn1-patches/0001-libtasn1-disable-code-not-needed-in-grub.pat
+which is convenient because it means we don't have to
+import it from gnulib.
+
-+Cc: Vladimir Serbinenko <[email protected]>
+Signed-off-by: Daniel Axtens <[email protected]>
+Signed-off-by: Gary Lin <[email protected]>
+---
4: 11cb1c021 ! 4: bf48cf8f8 libtasn1: changes for grub compatibility
@@ Metadata
Author: Gary Lin <[email protected]>
## Commit message ##
- libtasn1: changes for grub compatibility
+ libtasn1: use bound-checked _asn1_str_cat()
- Based on the patch from "Daniel Axtens <[email protected]>"
-
- Do a few things to make libtasn1 compile as part of grub:
-
- - remove _asn1_strcat and replace strcat with the bound-checked
- _asn1_str_cat except the one inside _asn1_str_cat. That strcat is
- replaced with strcpy.
-
- - adjust header paths in libtasn1.h
-
- - replace a 64 bit division with a call to grub_divmod64, preventing
- creation of __udivdi3 calls on 32 bit platforms.
+ Remove _asn1_strcat() and replace strcat() with the bound-checked
+ _asn1_str_cat() except the one inside _asn1_str_cat(). That strcat
+ is replaced with strcpy.
+ Signed-off-by: Daniel Axtens <[email protected]>
Signed-off-by: Gary Lin <[email protected]>
- ## grub-core/lib/libtasn1-patches/0002-libtasn1-changes-for-grub-compatibility.patch (new) ##
+ ## grub-core/lib/libtasn1-patches/0002-libtasn1-use-bound-checked-_asn1_str_cat.patch (new) ##
@@
-+From 1d62aa76a833855f58261fc69f40bd7763182274 Mon Sep 17 00:00:00 2001
-+From: Daniel Axtens <[email protected]>
-+Date: Fri, 1 May 2020 20:44:29 +1000
-+Subject: [PATCH 2/3] libtasn1: changes for grub compatibility
-+
-+Do a few things to make libtasn1 compile as part of grub:
++From d87d8e78371e3afbdd876193295ab9e3f60c140b Mon Sep 17 00:00:00 2001
++From: Gary Lin <[email protected]>
++Date: Tue, 25 Jun 2024 16:27:57 +0800
++Subject: [PATCH 2/6] libtasn1: use bound-checked _asn1_str_cat()
+
-+ - remove _asn1_strcat and replace strcat with the bound-checked
-+ _asn1_str_cat except the one inside _asn1_str_cat. That strcat is
-+ replaced with strcpy.
++Remove _asn1_strcat() and replace strcat() with the bound-checked
++_asn1_str_cat() except the one inside _asn1_str_cat(). That strcat
++is replaced with strcpy.
+
-+ - adjust header paths in libtasn1.h
-+
-+ - replace a 64 bit division with a call to grub_divmod64, preventing
-+ creation of __udivdi3 calls on 32 bit platforms.
-+
-+Cc: Vladimir Serbinenko <[email protected]>
+Signed-off-by: Daniel Axtens <[email protected]>
+Signed-off-by: Gary Lin <[email protected]>
-+Reviewed-by: Stefan Berger <[email protected]>
+---
-+ grub-core/lib/libtasn1-grub/lib/decoding.c | 8 ++++----
-+ grub-core/lib/libtasn1-grub/lib/element.c | 2 +-
-+ grub-core/lib/libtasn1-grub/lib/gstr.c | 2 +-
-+ grub-core/lib/libtasn1-grub/lib/int.h | 1 -
-+ grub-core/lib/libtasn1-grub/lib/parser_aux.c | 2 +-
-+ grub-core/lib/libtasn1-grub/libtasn1.h | 5 ++---
-+ 6 files changed, 9 insertions(+), 11 deletions(-)
++ grub-core/lib/libtasn1-grub/lib/decoding.c | 8 ++++----
++ grub-core/lib/libtasn1-grub/lib/element.c | 2 +-
++ grub-core/lib/libtasn1-grub/lib/gstr.c | 2 +-
++ grub-core/lib/libtasn1-grub/lib/int.h | 1 -
++ 4 files changed, 6 insertions(+), 7 deletions(-)
+
+diff --git a/grub-core/lib/libtasn1-grub/lib/decoding.c b/grub-core/lib/libtasn1-grub/lib/decoding.c
+index bf9cb13ac..51859fe36 100644
@@ -115,7 +115,6 @@ extern const tag_and_class_st _asn1_tags[];
+
+ # if SIZEOF_UNSIGNED_LONG_INT == 8
+ # define _asn1_strtou64(n,e,b) strtoul((const char *) n, e, b)
-+diff --git a/grub-core/lib/libtasn1-grub/lib/parser_aux.c b/grub-core/lib/libtasn1-grub/lib/parser_aux.c
-+index c05bd2339..e4e4c0556 100644
-+--- a/grub-core/lib/libtasn1-grub/lib/parser_aux.c
-++++ b/grub-core/lib/libtasn1-grub/lib/parser_aux.c
-+@@ -632,7 +632,7 @@ _asn1_ltostr (int64_t v, char str[LTOSTR_MAX_SIZE])
-+ count = 0;
-+ do
-+ {
-+- d = val / 10;
-++ d = grub_divmod64(val, 10, NULL);
-+ r = val - d * 10;
-+ temp[start + count] = '0' + (char) r;
-+ count++;
-+diff --git a/grub-core/lib/libtasn1-grub/libtasn1.h b/grub-core/lib/libtasn1-grub/libtasn1.h
-+index 058ab27b0..7d64b6ab7 100644
-+--- a/grub-core/lib/libtasn1-grub/libtasn1.h
-++++ b/grub-core/lib/libtasn1-grub/libtasn1.h
-+@@ -54,9 +54,8 @@
-+ # define __LIBTASN1_PURE__
-+ # endif
-+
-+-# include <sys/types.h>
-+-# include <time.h>
-+-# include <stdio.h> /* for FILE* */
-++# include <grub/types.h>
-++# include <grub/time.h>
-+
-+ # ifdef __cplusplus
-+ extern "C"
+--
+2.35.3
+
-: --------- > 5: 0f93bcdf5 libtasn1: adjust the header paths in libtasn1.h
-: --------- > 6: ab1fdab6f libtasn1: Use grub_divmod64() for division
5: ff1aacb5e ! 7: caa413fd4 libtasn1: fix the potential buffer overrun @@ Commit message
libtasn1 issue: https://gitlab.com/gnutls/libtasn1/-/issues/49
+ Reviewed-by: Daniel Kiper <[email protected]>
- ## grub-core/lib/libtasn1-patches/0003-libtasn1-fix-the-potential-buffer-overrun.patch (new) ##
+ ## grub-core/lib/libtasn1-patches/0005-libtasn1-fix-the-potential-buffer-overrun.patch (new) ## @@
-+From 636c1cbfe1e244ba887c6e1a18fabbcb3bb8b1b8 Mon Sep 17 00:00:00 2001
++From 38cc5e33cf89ed5d3152923fbedd9869bf566bb5 Mon Sep 17 00:00:00 2001
+From: Gary Lin <[email protected]>
+Date: Mon, 8 Apr 2024 14:57:21 +0800
-+Subject: [PATCH 3/3] libtasn1: fix the potential buffer overrun
++Subject: [PATCH 5/6] libtasn1: fix the potential buffer overrun
+
+In _asn1_tag_der(), the first while loop for the long form may end up
+with a 'k' value with 'ASN1_MAX_TAG_SIZE' and cause the buffer overrun
-: --------- > 8: 28045abf2 asn1_test: changes for grub compatibility 6: 73dfd01bd ! 9: 87b0b3860 libtasn1: compile into asn1 module
@@ Commit message
- Reviewed-by: Vladimir Serbinenko <[email protected]>
+ Reviewed-by: Daniel Kiper <[email protected]>
## autogen.sh ##
@@ autogen.sh: for x in mpi-asm-defs.h mpih-add1.c mpih-sub1.c mpih-mul1.c mpih-mul2.c mpih-mul
@@ autogen.sh: for x in mpi-asm-defs.h mpih-add1.c mpih-sub1.c mpih-mul1.c mpih-mul
+
+for patch in \
+ 0001-libtasn1-disable-code-not-needed-in-grub.patch \
-+ 0002-libtasn1-changes-for-grub-compatibility.patch \
-+ 0003-libtasn1-fix-the-potential-buffer-overrun.patch ; do
++ 0002-libtasn1-use-bound-checked-_asn1_str_cat.patch \
++ 0003-libtasn1-adjust-the-header-paths-in-libtasn1.h.patch \
++ 0004-libtasn1-Use-grub_divmod64-for-division.patch \
++ 0005-libtasn1-fix-the-potential-buffer-overrun.patch ; do
+ patch -p1 -i grub-core/lib/libtasn1-patches/$patch
+done
+
@@ grub-core/Makefile.core.def: module = {
+ common = lib/libtasn1-grub/lib/errors.c;
+ common = lib/libtasn1_wrap/wrap.c;
+ cflags = '$(CFLAGS_POSIX) $(CFLAGS_GNULIB)';
-+ // -Wno-type-limits comes from libtasn1's configure.ac
++ /* -Wno-type-limits comes from configure.ac of libtasn1 */
+ cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB) -I$(srcdir)/lib/libtasn1-grub -I$(srcdir)/lib/libtasn1-grub/lib -Wno-type-limits'; +};
@@ grub-core/lib/libtasn1_wrap/wrap.c (new)
@@
+/*
+ * GRUB -- GRand Unified Bootloader
++ * Copyright (C) 2024 Free Software Foundation, Inc.
+ * Copyright (C) 2020 IBM Corporation
+ *
+ * GRUB is free software: you can redistribute it and/or modify
@@ grub-core/lib/libtasn1_wrap/wrap.c (new)
+
+/*
+ * libtasn1 is provided under LGPL2.1+, which is compatible
-+ * with GPL3+. As Grub as a whole is under GPL3+, this module ++ * with GPL3+. As GRUB as a whole is under GPL3+, this module
+ * is therefore under GPL3+ also.
+ */
+GRUB_MOD_LICENSE ("GPLv3+");
7: 6dbd9060f < -: --------- asn1_test: test module for libtasn1 -: --------- > 10: 6e39c7766 asn1_test: test module for libtasn1 8: a0b370b0b ! 11: 5a8b24309 libtasn1: Add the documentation
@@ docs/grub-dev.texi: cp minilzo-2.10/*.[hc] grub-core/lib/minilzo
+tar xf libtasn1-4.19.0.tar.gz
+rm -rf grub-core/lib/libtasn1/
+mkdir -p grub-core/lib/libtasn1/lib/
++mkdir -p grub-core/lib/libtasn1/tests/
+cp libtasn1-4.19.0/@lbracechar{}README.md,COPYING@rbracechar{} grub-core/lib/libtasn1/
+cp libtasn1-4.19.0/lib/@lbracechar{}coding.c,decoding.c,element.c,element.h,errors.c,gstr.c,gstr.h,int.h,parser_aux.c,parser_aux.h,structure.c,structure.h@rbracechar{} grub-core/lib/libtasn1/lib/
+cp libtasn1-4.19.0/lib/includes/libtasn1.h grub-core/lib/libtasn1/
++cp libtasn1-4.19.0/tests/@lbracechar{}CVE-2018-1000654-1_asn1_tab.h,CVE-2018-1000654-2_asn1_tab.h,CVE-2018-1000654.c,object-id-decoding.c,object-id-encoding.c,octet-string.c,reproducers.c,Test_overflow.c,Test_simple.c,Test_strings.c@rbracechar{} grub-core/lib/libtasn1/tests
+rm -rf libtasn1-4.19.0*
+@end example
+
+After upgrading the library, it may be necessary to apply the patches in
+@file{grub-core/lib/libtasn1-patches/} to adjust the code to be compatible with
-+grub. These patches were needed to use the current version of libtasn1. The
++GRUB. These patches were needed to use the current version of libtasn1. The
+existing patches may not apply cleanly, apply at all, or even be needed for a
-+newer version of the library, and other patches maybe needed due to changes in
++newer version of the library, and other patches may be needed due to changes in
+the newer version. If existing patches need to be refreshed to apply cleanly,
+please include updated patches as part of the a patch set sent to the list.
+If new patches are needed or existing patches are not needed, also please send
9: 46f29445b ! 12: 3059a8df6 key_protector: Add key protectors framework
@@ Commit message
+ Reviewed-by: Daniel Kiper <[email protected]>
## grub-core/Makefile.am ##
@@ grub-core/Makefile.am: endif
@@ grub-core/disk/key_protector.c (new)
@@
+/*
+ * GRUB -- GRand Unified Bootloader
++ * Copyright (C) 2024 Free Software Foundation, Inc.
+ * Copyright (C) 2022 Microsoft Corporation
+ *
+ * GRUB is free software: you can redistribute it and/or modify
@@ include/grub/key_protector.h (new)
@@
+/*
+ * GRUB -- GRand Unified Bootloader
++ * Copyright (C) 2024 Free Software Foundation, Inc.
+ * Copyright (C) 2022 Microsoft Corporation
+ *
+ * GRUB is free software: you can redistribute it and/or modify
-: --------- > 13: 584346494 tss2: Add TPM2 buffer handling functions
10: ba02aa532 ! 14: c2c071d9c tpm2: Add TPM Software Stack (TSS)
@@
## Metadata ##
-Author: Hernan Gatta <[email protected]>
+Author: Gary Lin <[email protected]>
## Commit message ##
- tpm2: Add TPM Software Stack (TSS)
+ tss2: Add TPM2 types and Marshal/Unmarshal functions
- A Trusted Platform Module (TPM) Software Stack (TSS) provides logic to
- compose and submit TPM commands and parse reponses.
-
- A limited number of TPM commands may be accessed via the EFI TCG2
- protocol. This protocol exposes functionality that is primarily geared
- toward TPM usage within the context of Secure Boot. For all other TPM
- commands, however, such as sealing and unsealing, this protocol does not
- provide any help, with the exception of passthrough command submission.
-
- The SubmitCommand method allows a caller to send raw commands to the
- system's TPM and to receive the corresponding response. These
- command/response pairs are formatted using the TPM wire protocol. To
- construct commands in this way, and to parse the TPM's response, it is
- necessary to, first, possess knowledge of the various TPM structures, and,
- second, of the TPM wire protocol itself.
-
- As such, this patch includes a set of header files that define the
- necessary TPM structures and TSS functions, implementations of various
- TPM2_* functions (inventoried below), and logic to write and read command
- and response buffers, respectively, using the TPM wire protocol.
-
- Functions: TPM2_Create, TPM2_CreatePrimary, TPM2_EvictControl,
- TPM2_FlushContext, TPM2_Load, TPM2_PCR_Read, TPM2_PolicyGetDigest,
- TPM2_PolicyPCR, TPM2_ReadPublic, TPM2_StartAuthSession, TPM2_Unseal,
- TPM2_LoadExternal, TPM2_Hash, TPM2_VerifySignature,
- TPM2_PolicyAuthorize, TPM2_TestParms
+ This commit adds the necessary TPM2 types and structs as the preparation
+ for the TPM2 Software Stack (TSS2) support. The Marshal/Unmarshal
+ functions are also added to handle the data structure to be submitted to
+ TPM2 commands and to be received from the response.
+ Cc: Stefan Berger <[email protected]>
Signed-off-by: Hernan Gatta <[email protected]>
Signed-off-by: Gary Lin <[email protected]>
- Reviewed-by: Stefan Berger <[email protected]>
- ## grub-core/tpm2/buffer.c (new) ##
+ ## grub-core/lib/tss2/tss2_mu.c (new) ##
@@
+/*
+ * GRUB -- GRand Unified Bootloader
++ * Copyright (C) 2024 Free Software Foundation, Inc.
+ * Copyright (C) 2022 Microsoft Corporation
+ *
+ * GRUB is free software: you can redistribute it and/or modify
@@ grub-core/tpm2/buffer.c (new)
+ */
+
+#include <grub/misc.h>
-+#include <grub/tpm2/buffer.h>
-+
-+void grub_tpm2_buffer_init (grub_tpm2_buffer_t buffer)
-+{
-+ grub_memset (buffer->data, 0xDD, sizeof (buffer->data));
-+ buffer->size = 0;
-+ buffer->offset = 0;
-+ buffer->cap = sizeof (buffer->data);
-+ buffer->error = 0;
-+}
-+
-+void
-+grub_tpm2_buffer_pack (grub_tpm2_buffer_t buffer, const void* data,
-+ grub_size_t size)
-+{
-+ grub_uint32_t r = buffer->cap - buffer->size;
-+
-+ if (buffer->error)
-+ return;
-+
-+ if (size > r)
-+ {
-+ buffer->error = 1;
-+ return;
-+ }
-+
-+ grub_memcpy (&buffer->data[buffer->size], (void*) data, size);
-+ buffer->size += size;
-+}
-+
-+void
-+grub_tpm2_buffer_pack_u8 (grub_tpm2_buffer_t buffer, grub_uint8_t value)
-+{
-+ grub_tpm2_buffer_pack (buffer, (const char*) &value, sizeof (value));
-+}
-+
-+void
-+grub_tpm2_buffer_pack_u16 (grub_tpm2_buffer_t buffer, grub_uint16_t value)
-+{
-+ grub_uint16_t tmp = grub_cpu_to_be16 (value);
-+ grub_tpm2_buffer_pack (buffer, (const char*) &tmp, sizeof (tmp));
-+}
-+
-+void
-+grub_tpm2_buffer_pack_u32 (grub_tpm2_buffer_t buffer, grub_uint32_t value)
-+{
-+ grub_uint32_t tmp = grub_cpu_to_be32 (value);
-+ grub_tpm2_buffer_pack (buffer, (const char*) &tmp, sizeof (tmp));
-+}
-+
-+void
-+grub_tpm2_buffer_unpack (grub_tpm2_buffer_t buffer, void* data,
-+ grub_size_t size)
-+{
-+ grub_uint32_t r = buffer->size - buffer->offset;
-+
-+ if (buffer->error)
-+ return;
-+
-+ if (size > r)
-+ {
-+ buffer->error = 1;
-+ return;
-+ }
-+
-+ grub_memcpy (data, &buffer->data[buffer->offset], size);
-+ buffer->offset += size;
-+}
-+
-+void
-+grub_tpm2_buffer_unpack_u8 (grub_tpm2_buffer_t buffer, grub_uint8_t* value)
-+{
-+ grub_uint32_t r = buffer->size - buffer->offset;
-+
-+ if (buffer->error)
-+ return;
-+
-+ if (sizeof (*value) > r)
-+ {
-+ buffer->error = 1;
-+ return;
-+ }
-+
-+ grub_memcpy (value, &buffer->data[buffer->offset], sizeof (*value));
-+ buffer->offset += sizeof (*value);
-+}
-+
-+void
-+grub_tpm2_buffer_unpack_u16 (grub_tpm2_buffer_t buffer, grub_uint16_t* value)
-+{
-+ grub_uint16_t tmp;
-+ grub_uint32_t r = buffer->size - buffer->offset;
-+
-+ if (buffer->error)
-+ return;
-+
-+ if (sizeof (tmp) > r)
-+ {
-+ buffer->error = 1;
-+ return;
-+ }
-+
-+ grub_memcpy (&tmp, &buffer->data[buffer->offset], sizeof (tmp));
-+ buffer->offset += sizeof (tmp);
-+ *value = grub_be_to_cpu16 (tmp);
-+}
-+
-+void
-+grub_tpm2_buffer_unpack_u32 (grub_tpm2_buffer_t buffer, grub_uint32_t* value)
-+{
-+ grub_uint32_t tmp;
-+ grub_uint32_t r = buffer->size - buffer->offset;
-+
-+ if (buffer->error)
-+ return;
-+
-+ if (sizeof (tmp) > r)
-+ {
-+ buffer->error = 1;
-+ return;
-+ }
-+
-+ grub_memcpy (&tmp, &buffer->data[buffer->offset], sizeof (tmp));
-+ buffer->offset += sizeof (tmp);
-+ *value = grub_be_to_cpu32 (tmp);
-+}
-
- ## grub-core/tpm2/mu.c (new) ##
-@@
-+/*
-+ * GRUB -- GRand Unified Bootloader
-+ * Copyright (C) 2022 Microsoft Corporation
-+ *
-+ * GRUB is free software: you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation, either version 3 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * GRUB is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
-+ */
+
-+#include <grub/misc.h>
-+#include <grub/tpm2/mu.h>
++#include <tss2_mu.h>
+
+void
-+grub_tpm2_mu_TPMS_AUTH_COMMAND_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMS_AUTH_COMMAND_Marshal (grub_tpm2_buffer_t buffer,
+ const TPMS_AUTH_COMMAND* authCommand)
+{
+ grub_uint32_t start;
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPM2B_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPM2B_Marshal (grub_tpm2_buffer_t buffer,
+ const grub_uint16_t size,
+ const grub_uint8_t* b)
+{
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPMU_SYM_KEY_BITS_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMU_SYM_KEY_BITS_Marshal (grub_tpm2_buffer_t buffer,
+ const TPMI_ALG_SYM_OBJECT algorithm,
+ const TPMU_SYM_KEY_BITS *p)
+{
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPMU_SYM_MODE_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMU_SYM_MODE_Marshal (grub_tpm2_buffer_t buffer,
+ const TPMI_ALG_SYM_OBJECT algorithm,
+ const TPMU_SYM_MODE *p)
+{
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPMT_SYM_DEF_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMT_SYM_DEF_Marshal (grub_tpm2_buffer_t buffer,
+ const TPMT_SYM_DEF *p)
+{
+ grub_tpm2_buffer_pack_u16 (buffer, p->algorithm);
-+ grub_tpm2_mu_TPMU_SYM_KEY_BITS_Marshal (buffer, p->algorithm, &p->keyBits);
-+ grub_tpm2_mu_TPMU_SYM_MODE_Marshal (buffer, p->algorithm, &p->mode);
++ grub_Tss2_MU_TPMU_SYM_KEY_BITS_Marshal (buffer, p->algorithm, &p->keyBits);
++ grub_Tss2_MU_TPMU_SYM_MODE_Marshal (buffer, p->algorithm, &p->mode);
+}
+
+void
-+grub_tpm2_mu_TPMS_PCR_SELECTION_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMS_PCR_SELECTION_Marshal (grub_tpm2_buffer_t buffer,
+ const TPMS_PCR_SELECTION* pcrSelection)
+{
+ grub_tpm2_buffer_pack_u16 (buffer, pcrSelection->hash);
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPML_PCR_SELECTION_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPML_PCR_SELECTION_Marshal (grub_tpm2_buffer_t buffer,
+ const TPML_PCR_SELECTION* pcrSelection)
+{
+ grub_tpm2_buffer_pack_u32 (buffer, pcrSelection->count);
+
+ for (grub_uint32_t i = 0; i < pcrSelection->count; i++)
-+ grub_tpm2_mu_TPMS_PCR_SELECTION_Marshal (buffer,
++ grub_Tss2_MU_TPMS_PCR_SELECTION_Marshal (buffer,
+ &pcrSelection->pcrSelections[i]);
+}
+
+void
-+grub_tpm2_mu_TPMA_OBJECT_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMA_OBJECT_Marshal (grub_tpm2_buffer_t buffer,
+ const TPMA_OBJECT *p)
+{
+ grub_tpm2_buffer_pack_u32 (buffer, *((const grub_uint32_t*) p));
+}
+
+void
-+grub_tpm2_mu_TPMS_SCHEME_XOR_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMS_SCHEME_XOR_Marshal (grub_tpm2_buffer_t buffer,
+ const TPMS_SCHEME_XOR *p)
+{
+ grub_tpm2_buffer_pack_u16 (buffer, p->hashAlg);
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPMS_SCHEME_HMAC_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMS_SCHEME_HMAC_Marshal (grub_tpm2_buffer_t buffer,
+ const TPMS_SCHEME_HMAC *p)
+{
+ grub_tpm2_buffer_pack_u16 (buffer, p->hashAlg);
+}
+
+void
-+grub_tpm2_mu_TPMU_SCHEME_KEYEDHASH_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMU_SCHEME_KEYEDHASH_Marshal (grub_tpm2_buffer_t buffer,
+ const TPMI_ALG_KEYEDHASH_SCHEME scheme,
+ const TPMU_SCHEME_KEYEDHASH *p)
+{
+ switch (scheme)
+ {
+ case TPM_ALG_HMAC:
-+ grub_tpm2_mu_TPMS_SCHEME_HMAC_Marshal (buffer, &p->hmac);
++ grub_Tss2_MU_TPMS_SCHEME_HMAC_Marshal (buffer, &p->hmac);
+ break;
+ case TPM_ALG_XOR:
-+ grub_tpm2_mu_TPMS_SCHEME_XOR_Marshal (buffer, &p->exclusiveOr);
++ grub_Tss2_MU_TPMS_SCHEME_XOR_Marshal (buffer, &p->exclusiveOr);
+ break;
+ case TPM_ALG_NULL:
+ break;
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPMT_KEYEDHASH_SCHEME_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMT_KEYEDHASH_SCHEME_Marshal (grub_tpm2_buffer_t buffer,
+ const TPMT_KEYEDHASH_SCHEME *p)
+{
+ grub_tpm2_buffer_pack_u16 (buffer, p->scheme);
-+ grub_tpm2_mu_TPMU_SCHEME_KEYEDHASH_Marshal (buffer, p->scheme, &p->details);
++ grub_Tss2_MU_TPMU_SCHEME_KEYEDHASH_Marshal (buffer, p->scheme, &p->details);
+}
+
+void
-+grub_tpm2_mu_TPMS_KEYEDHASH_PARMS_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMS_KEYEDHASH_PARMS_Marshal (grub_tpm2_buffer_t buffer,
+ const TPMS_KEYEDHASH_PARMS *p)
+{
-+ grub_tpm2_mu_TPMT_KEYEDHASH_SCHEME_Marshal (buffer, &p->scheme);
++ grub_Tss2_MU_TPMT_KEYEDHASH_SCHEME_Marshal (buffer, &p->scheme);
+}
+
+void
-+grub_tpm2_mu_TPMT_SYM_DEF_OBJECT_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMT_SYM_DEF_OBJECT_Marshal (grub_tpm2_buffer_t buffer,
+ const TPMT_SYM_DEF_OBJECT *p)
+{
+ grub_tpm2_buffer_pack_u16 (buffer, p->algorithm);
-+ grub_tpm2_mu_TPMU_SYM_KEY_BITS_Marshal (buffer, p->algorithm, &p->keyBits);
-+ grub_tpm2_mu_TPMU_SYM_MODE_Marshal (buffer, p->algorithm, &p->mode);
++ grub_Tss2_MU_TPMU_SYM_KEY_BITS_Marshal (buffer, p->algorithm, &p->keyBits);
++ grub_Tss2_MU_TPMU_SYM_MODE_Marshal (buffer, p->algorithm, &p->mode);
+}
+
+void
-+grub_tpm2_mu_TPMU_ASYM_SCHEME_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMU_ASYM_SCHEME_Marshal (grub_tpm2_buffer_t buffer,
+ const TPMI_ALG_RSA_DECRYPT scheme,
+ const TPMU_ASYM_SCHEME *p __attribute__ ((unused)))
+{
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPMT_RSA_SCHEME_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMT_RSA_SCHEME_Marshal (grub_tpm2_buffer_t buffer,
+ const TPMT_RSA_SCHEME *p)
+{
+ grub_tpm2_buffer_pack_u16 (buffer, p->scheme);
-+ grub_tpm2_mu_TPMU_ASYM_SCHEME_Marshal (buffer, p->scheme, &p->details);
++ grub_Tss2_MU_TPMU_ASYM_SCHEME_Marshal (buffer, p->scheme, &p->details);
+}
+
+void
-+grub_tpm2_mu_TPMS_RSA_PARMS_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMS_RSA_PARMS_Marshal (grub_tpm2_buffer_t buffer,
+ const TPMS_RSA_PARMS *p)
+{
-+ grub_tpm2_mu_TPMT_SYM_DEF_OBJECT_Marshal (buffer, &p->symmetric);
-+ grub_tpm2_mu_TPMT_RSA_SCHEME_Marshal (buffer, &p->scheme);
++ grub_Tss2_MU_TPMT_SYM_DEF_OBJECT_Marshal (buffer, &p->symmetric);
++ grub_Tss2_MU_TPMT_RSA_SCHEME_Marshal (buffer, &p->scheme);
+ grub_tpm2_buffer_pack_u16 (buffer, p->keyBits);
+ grub_tpm2_buffer_pack_u32 (buffer, p->exponent);
+}
+
+void
-+grub_tpm2_mu_TPMS_SYMCIPHER_PARMS_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMS_SYMCIPHER_PARMS_Marshal (grub_tpm2_buffer_t buffer,
+ const TPMS_SYMCIPHER_PARMS *p)
+{
-+ grub_tpm2_mu_TPMT_SYM_DEF_OBJECT_Marshal (buffer, &p->sym);
++ grub_Tss2_MU_TPMT_SYM_DEF_OBJECT_Marshal (buffer, &p->sym);
+}
+
+void
-+grub_tpm2_mu_TPMT_ECC_SCHEME_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMT_ECC_SCHEME_Marshal (grub_tpm2_buffer_t buffer,
+ const TPMT_ECC_SCHEME *p)
+{
+ grub_tpm2_buffer_pack_u16 (buffer, p->scheme);
-+ grub_tpm2_mu_TPMU_ASYM_SCHEME_Marshal (buffer, p->scheme, &p->details);
++ grub_Tss2_MU_TPMU_ASYM_SCHEME_Marshal (buffer, p->scheme, &p->details);
+}
+
+void
-+grub_tpm2_mu_TPMU_KDF_SCHEME_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMU_KDF_SCHEME_Marshal (grub_tpm2_buffer_t buffer,
+ const TPMI_ALG_KDF scheme,
+ const TPMU_KDF_SCHEME *p)
+{
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPMT_KDF_SCHEME_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMT_KDF_SCHEME_Marshal (grub_tpm2_buffer_t buffer,
+ const TPMT_KDF_SCHEME *p)
+{
+ grub_tpm2_buffer_pack_u16 (buffer, p->scheme);
-+ grub_tpm2_mu_TPMU_KDF_SCHEME_Marshal (buffer, p->scheme, &p->details);
++ grub_Tss2_MU_TPMU_KDF_SCHEME_Marshal (buffer, p->scheme, &p->details);
+}
+
+void
-+grub_tpm2_mu_TPMS_ECC_PARMS_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMS_ECC_PARMS_Marshal (grub_tpm2_buffer_t buffer,
+ const TPMS_ECC_PARMS *p)
+{
-+ grub_tpm2_mu_TPMT_SYM_DEF_OBJECT_Marshal (buffer, &p->symmetric);
-+ grub_tpm2_mu_TPMT_ECC_SCHEME_Marshal (buffer, &p->scheme);
++ grub_Tss2_MU_TPMT_SYM_DEF_OBJECT_Marshal (buffer, &p->symmetric);
++ grub_Tss2_MU_TPMT_ECC_SCHEME_Marshal (buffer, &p->scheme);
+ grub_tpm2_buffer_pack_u16 (buffer, p->curveID);
-+ grub_tpm2_mu_TPMT_KDF_SCHEME_Marshal (buffer, &p->kdf);
++ grub_Tss2_MU_TPMT_KDF_SCHEME_Marshal (buffer, &p->kdf);
+}
+
+void
-+grub_tpm2_mu_TPMU_PUBLIC_PARMS_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMU_PUBLIC_PARMS_Marshal (grub_tpm2_buffer_t buffer,
+ const grub_uint32_t type,
+ const TPMU_PUBLIC_PARMS *p)
+{
+ switch (type)
+ {
+ case TPM_ALG_KEYEDHASH:
-+ grub_tpm2_mu_TPMS_KEYEDHASH_PARMS_Marshal (buffer, &p->keyedHashDetail);
++ grub_Tss2_MU_TPMS_KEYEDHASH_PARMS_Marshal (buffer, &p->keyedHashDetail);
+ break;
+ case TPM_ALG_SYMCIPHER:
-+ grub_tpm2_mu_TPMS_SYMCIPHER_PARMS_Marshal (buffer, &p->symDetail);
++ grub_Tss2_MU_TPMS_SYMCIPHER_PARMS_Marshal (buffer, &p->symDetail);
+ break;
+ case TPM_ALG_RSA:
-+ grub_tpm2_mu_TPMS_RSA_PARMS_Marshal (buffer, &p->rsaDetail);
++ grub_Tss2_MU_TPMS_RSA_PARMS_Marshal (buffer, &p->rsaDetail);
+ break;
+ case TPM_ALG_ECC:
-+ grub_tpm2_mu_TPMS_ECC_PARMS_Marshal (buffer, &p->eccDetail);
++ grub_Tss2_MU_TPMS_ECC_PARMS_Marshal (buffer, &p->eccDetail);
+ break;
+ default:
+ buffer->error = 1;
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPMS_ECC_POINT_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMS_ECC_POINT_Marshal (grub_tpm2_buffer_t buffer,
+ const TPMS_ECC_POINT *p)
+{
-+ grub_tpm2_mu_TPM2B_Marshal (buffer, p->x.size, p->x.buffer);
-+ grub_tpm2_mu_TPM2B_Marshal (buffer, p->y.size, p->y.buffer);
++ grub_Tss2_MU_TPM2B_Marshal (buffer, p->x.size, p->x.buffer);
++ grub_Tss2_MU_TPM2B_Marshal (buffer, p->y.size, p->y.buffer);
+}
+
+void
-+grub_tpm2_mu_TPMU_PUBLIC_ID_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMU_PUBLIC_ID_Marshal (grub_tpm2_buffer_t buffer,
+ const TPMI_ALG_PUBLIC type,
+ const TPMU_PUBLIC_ID *p)
+{
+ switch(type)
+ {
+ case TPM_ALG_KEYEDHASH:
-+ grub_tpm2_mu_TPM2B_Marshal (buffer, p->keyedHash.size,
++ grub_Tss2_MU_TPM2B_Marshal (buffer, p->keyedHash.size,
+ p->keyedHash.buffer);
+ break;
+ case TPM_ALG_SYMCIPHER:
-+ grub_tpm2_mu_TPM2B_Marshal (buffer, p->sym.size, p->sym.buffer);
++ grub_Tss2_MU_TPM2B_Marshal (buffer, p->sym.size, p->sym.buffer);
+ break;
+ case TPM_ALG_RSA:
-+ grub_tpm2_mu_TPM2B_Marshal (buffer, p->rsa.size, p->rsa.buffer);
++ grub_Tss2_MU_TPM2B_Marshal (buffer, p->rsa.size, p->rsa.buffer);
+ break;
+ case TPM_ALG_ECC:
-+ grub_tpm2_mu_TPMS_ECC_POINT_Marshal (buffer, &p->ecc);
++ grub_Tss2_MU_TPMS_ECC_POINT_Marshal (buffer, &p->ecc);
+ break;
+ default:
+ buffer->error = 1;
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPMT_PUBLIC_PARMS_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMT_PUBLIC_PARMS_Marshal (grub_tpm2_buffer_t buffer,
+ const TPMT_PUBLIC_PARMS *p)
+{
+ grub_tpm2_buffer_pack_u16 (buffer, p->type);
-+ grub_tpm2_mu_TPMU_PUBLIC_PARMS_Marshal (buffer, p->type, &p->parameters);
++ grub_Tss2_MU_TPMU_PUBLIC_PARMS_Marshal (buffer, p->type, &p->parameters);
+}
+
+void
-+grub_tpm2_mu_TPMT_PUBLIC_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMT_PUBLIC_Marshal (grub_tpm2_buffer_t buffer,
+ const TPMT_PUBLIC *p)
+{
+ grub_tpm2_buffer_pack_u16 (buffer, p->type);
+ grub_tpm2_buffer_pack_u16 (buffer, p->nameAlg);
-+ grub_tpm2_mu_TPMA_OBJECT_Marshal (buffer, &p->objectAttributes);
-+ grub_tpm2_mu_TPM2B_Marshal (buffer, p->authPolicy.size, p->authPolicy.buffer);
-+ grub_tpm2_mu_TPMU_PUBLIC_PARMS_Marshal (buffer, p->type, &p->parameters);
-+ grub_tpm2_mu_TPMU_PUBLIC_ID_Marshal (buffer, p->type, &p->unique);
++ grub_Tss2_MU_TPMA_OBJECT_Marshal (buffer, &p->objectAttributes);
++ grub_Tss2_MU_TPM2B_Marshal (buffer, p->authPolicy.size, p->authPolicy.buffer);
++ grub_Tss2_MU_TPMU_PUBLIC_PARMS_Marshal (buffer, p->type, &p->parameters);
++ grub_Tss2_MU_TPMU_PUBLIC_ID_Marshal (buffer, p->type, &p->unique);
+}
+
+void
-+grub_tpm2_mu_TPM2B_PUBLIC_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPM2B_PUBLIC_Marshal (grub_tpm2_buffer_t buffer,
+ const TPM2B_PUBLIC *p)
+{
+ grub_uint32_t start;
@@ grub-core/tpm2/mu.c (new)
+ grub_tpm2_buffer_pack_u16 (buffer, p->size);
+
+ start = buffer->size;
-+ grub_tpm2_mu_TPMT_PUBLIC_Marshal (buffer, &p->publicArea);
++ grub_Tss2_MU_TPMT_PUBLIC_Marshal (buffer, &p->publicArea);
+ size = grub_cpu_to_be16 (buffer->size - start);
+ grub_memcpy (&buffer->data[start - sizeof (grub_uint16_t)], &size,
+ sizeof (size));
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPMS_SENSITIVE_CREATE_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMS_SENSITIVE_CREATE_Marshal (grub_tpm2_buffer_t buffer,
+ const TPMS_SENSITIVE_CREATE *p)
+{
-+ grub_tpm2_mu_TPM2B_Marshal (buffer, p->userAuth.size, p->userAuth.buffer);
-+ grub_tpm2_mu_TPM2B_Marshal (buffer, p->data.size, p->data.buffer);
++ grub_Tss2_MU_TPM2B_Marshal (buffer, p->userAuth.size, p->userAuth.buffer);
++ grub_Tss2_MU_TPM2B_Marshal (buffer, p->data.size, p->data.buffer);
+}
+
+void
-+grub_tpm2_mu_TPMU_SENSITIVE_COMPOSITE_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_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);
++ grub_Tss2_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);
++ grub_Tss2_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);
++ grub_Tss2_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);
++ grub_Tss2_MU_TPM2B_Marshal (buffer, p->sym.size, p->sym.buffer);
+ break;
+ default:
+ buffer->error = 1;
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPMT_SENSITIVE_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_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,
++ grub_Tss2_MU_TPM2B_Marshal (buffer, p->authValue.size, p->authValue.buffer);
++ grub_Tss2_MU_TPM2B_Marshal (buffer, p->seedValue.size, p->seedValue.buffer);
++ grub_Tss2_MU_TPMU_SENSITIVE_COMPOSITE_Marshal (buffer, p->sensitiveType,
+ &p->sensitive);
+}
+
+void
-+grub_tpm2_mu_TPM2B_SENSITIVE_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_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);
++ grub_Tss2_MU_TPMT_SENSITIVE_Marshal (buffer, &p->sensitiveArea);
+}
+
+void
-+grub_tpm2_mu_TPM2B_SENSITIVE_CREATE_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPM2B_SENSITIVE_CREATE_Marshal (grub_tpm2_buffer_t buffer,
+ const TPM2B_SENSITIVE_CREATE *sensitiveCreate)
+{
+ grub_uint32_t start;
@@ grub-core/tpm2/mu.c (new)
+ {
+ grub_tpm2_buffer_pack_u16 (buffer, sensitiveCreate->size);
+ start = buffer->size;
-+ grub_tpm2_mu_TPMS_SENSITIVE_CREATE_Marshal (buffer,
++ grub_Tss2_MU_TPMS_SENSITIVE_CREATE_Marshal (buffer,
+ &sensitiveCreate->sensitive);
+ size = grub_cpu_to_be16 (buffer->size - start);
+
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPMS_SIGNATURE_RSA_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_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);
++ grub_Tss2_MU_TPM2B_Marshal (buffer, p->sig.size, p->sig.buffer);
+}
+
+void
-+grub_tpm2_mu_TPMS_SIGNATURE_ECC_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_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);
++ grub_Tss2_MU_TPM2B_Marshal (buffer, p->signatureR.size, p->signatureR.buffer);
++ grub_Tss2_MU_TPM2B_Marshal (buffer, p->signatureS.size, p->signatureS.buffer);
+}
+
+void
-+grub_tpm2_mu_TPMU_HA_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMU_HA_Marshal (grub_tpm2_buffer_t buffer,
+ const TPMI_ALG_HASH hashAlg,
+ const TPMU_HA *p)
+{
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPMT_HA_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_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);
++ grub_Tss2_MU_TPMU_HA_Marshal (buffer, p->hashAlg, &p->digest);
+}
+
+void
-+grub_tpm2_mu_TPMU_SIGNATURE_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_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);
++ grub_Tss2_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);
++ grub_Tss2_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);
++ grub_Tss2_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);
++ grub_Tss2_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);
++ grub_Tss2_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);
++ grub_Tss2_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);
++ grub_Tss2_MU_TPMT_HA_Marshal (buffer, &p->hmac);
+ break;
+ case TPM_ALG_NULL:
+ break;
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPMT_SIGNATURE_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_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);
++ grub_Tss2_MU_TPMU_SIGNATURE_Marshal (buffer, p->sigAlg, &p->signature);
+}
+
+void
-+grub_tpm2_mu_TPMT_TK_VERIFIED_Marshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_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);
++ grub_Tss2_MU_TPM2B_Marshal (buffer, p->digest.size, p->digest.buffer);
+}
+
+static void
-+__tpm2_mu_TPM2B_BUFFER_Unmarshal (grub_tpm2_buffer_t buffer,
++__Tss2_MU_TPM2B_BUFFER_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPM2B* p, grub_uint16_t bound)
+{
+ grub_tpm2_buffer_unpack_u16 (buffer, &p->size);
@@ grub-core/tpm2/mu.c (new)
+}
+
+#define TPM2B_BUFFER_UNMARSHAL(buffer, type, data) \
-+ __tpm2_mu_TPM2B_BUFFER_Unmarshal(buffer, (TPM2B *)data, sizeof(type) - sizeof(grub_uint16_t))
++ __Tss2_MU_TPM2B_BUFFER_Unmarshal(buffer, (TPM2B *)data, sizeof(type) - sizeof(grub_uint16_t))
+
+void
-+grub_tpm2_mu_TPMS_AUTH_RESPONSE_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMS_AUTH_RESPONSE_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMS_AUTH_RESPONSE* p)
+{
+ grub_uint8_t tmp;
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPM2B_DIGEST_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPM2B_DIGEST_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPM2B_DIGEST* digest)
+{
+ TPM2B_BUFFER_UNMARSHAL (buffer, TPM2B_DIGEST, digest);
+}
+
+void
-+grub_tpm2_mu_TPM2B_NONCE_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPM2B_NONCE_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPM2B_NONCE* nonce)
+{
+ TPM2B_BUFFER_UNMARSHAL (buffer, TPM2B_NONCE, nonce);
+}
+
+void
-+grub_tpm2_mu_TPM2B_DATA_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPM2B_DATA_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPM2B_DATA* data)
+{
+ TPM2B_BUFFER_UNMARSHAL (buffer, TPM2B_DATA, data);
+}
+
+void
-+grub_tpm2_mu_TPMS_CREATION_DATA_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMS_CREATION_DATA_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMS_CREATION_DATA *data)
+{
-+ grub_tpm2_mu_TPML_PCR_SELECTION_Unmarshal (buffer, &data->pcrSelect);
-+ grub_tpm2_mu_TPM2B_DIGEST_Unmarshal (buffer, &data->pcrDigest);
++ grub_Tss2_MU_TPML_PCR_SELECTION_Unmarshal (buffer, &data->pcrSelect);
++ grub_Tss2_MU_TPM2B_DIGEST_Unmarshal (buffer, &data->pcrDigest);
+ grub_tpm2_buffer_unpack_u8 (buffer, (grub_uint8_t *)&data->locality);
+ grub_tpm2_buffer_unpack_u16 (buffer, &data->parentNameAlg);
-+ grub_tpm2_mu_TPM2B_NAME_Unmarshal (buffer, &data->parentName);
-+ grub_tpm2_mu_TPM2B_NAME_Unmarshal (buffer, &data->parentQualifiedName);
-+ grub_tpm2_mu_TPM2B_DATA_Unmarshal (buffer, &data->outsideInfo);
++ grub_Tss2_MU_TPM2B_NAME_Unmarshal (buffer, &data->parentName);
++ grub_Tss2_MU_TPM2B_NAME_Unmarshal (buffer, &data->parentQualifiedName);
++ grub_Tss2_MU_TPM2B_DATA_Unmarshal (buffer, &data->outsideInfo);
+}
+
+void
-+grub_tpm2_mu_TPM2B_CREATION_DATA_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPM2B_CREATION_DATA_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPM2B_CREATION_DATA *data)
+{
+ grub_tpm2_buffer_unpack_u16 (buffer, &data->size);
-+ grub_tpm2_mu_TPMS_CREATION_DATA_Unmarshal (buffer, &data->creationData);
++ grub_Tss2_MU_TPMS_CREATION_DATA_Unmarshal (buffer, &data->creationData);
+}
+
+void
-+grub_tpm2_mu_TPM2B_PRIVATE_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPM2B_PRIVATE_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPM2B_PRIVATE *private)
+{
+ TPM2B_BUFFER_UNMARSHAL (buffer, TPM2B_PRIVATE, private);
+}
+
+void
-+grub_tpm2_mu_TPM2B_SENSITIVE_DATA_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPM2B_SENSITIVE_DATA_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPM2B_SENSITIVE_DATA *data)
+{
+ TPM2B_BUFFER_UNMARSHAL (buffer, TPM2B_SENSITIVE_DATA, data);
+}
+
+void
-+grub_tpm2_mu_TPM2B_PUBLIC_KEY_RSA_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPM2B_PUBLIC_KEY_RSA_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPM2B_PUBLIC_KEY_RSA *rsa)
+{
+ TPM2B_BUFFER_UNMARSHAL (buffer, TPM2B_PUBLIC_KEY_RSA, rsa);
+}
+
+void
-+grub_tpm2_mu_TPM2B_ECC_PARAMETER_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPM2B_ECC_PARAMETER_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPM2B_ECC_PARAMETER *param)
+{
+ TPM2B_BUFFER_UNMARSHAL (buffer, TPM2B_ECC_PARAMETER, param);
+}
+
+void
-+grub_tpm2_mu_TPMA_OBJECT_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMA_OBJECT_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMA_OBJECT *p)
+{
+ grub_tpm2_buffer_unpack_u32 (buffer, (grub_uint32_t*)p);
+}
+
+void
-+grub_tpm2_mu_TPMS_SCHEME_HMAC_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMS_SCHEME_HMAC_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMS_SCHEME_HMAC *p)
+{
+ grub_tpm2_buffer_unpack_u16 (buffer, &p->hashAlg);
+}
+
+void
-+grub_tpm2_mu_TPMS_SCHEME_XOR_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMS_SCHEME_XOR_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMS_SCHEME_XOR *p)
+{
+ grub_tpm2_buffer_unpack_u16 (buffer, &p->hashAlg);
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPMU_SCHEME_KEYEDHASH_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMU_SCHEME_KEYEDHASH_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMI_ALG_KEYEDHASH_SCHEME scheme,
+ TPMU_SCHEME_KEYEDHASH *p)
+{
+ switch (scheme)
+ {
+ case TPM_ALG_HMAC:
-+ grub_tpm2_mu_TPMS_SCHEME_HMAC_Unmarshal (buffer, &p->hmac);
++ grub_Tss2_MU_TPMS_SCHEME_HMAC_Unmarshal (buffer, &p->hmac);
+ break;
+ case TPM_ALG_XOR:
-+ grub_tpm2_mu_TPMS_SCHEME_XOR_Unmarshal (buffer, &p->exclusiveOr);
++ grub_Tss2_MU_TPMS_SCHEME_XOR_Unmarshal (buffer, &p->exclusiveOr);
+ break;
+ case TPM_ALG_NULL:
+ break;
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPMT_KEYEDHASH_SCHEME_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMT_KEYEDHASH_SCHEME_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMT_KEYEDHASH_SCHEME *p)
+{
+ grub_tpm2_buffer_unpack_u16 (buffer, &p->scheme);
-+ grub_tpm2_mu_TPMU_SCHEME_KEYEDHASH_Unmarshal (buffer, p->scheme, &p->details);
++ grub_Tss2_MU_TPMU_SCHEME_KEYEDHASH_Unmarshal (buffer, p->scheme, &p->details);
+}
+
+void
-+grub_tpm2_mu_TPMS_KEYEDHASH_PARMS_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMS_KEYEDHASH_PARMS_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMS_KEYEDHASH_PARMS *p)
+{
-+ grub_tpm2_mu_TPMT_KEYEDHASH_SCHEME_Unmarshal (buffer, &p->scheme);
++ grub_Tss2_MU_TPMT_KEYEDHASH_SCHEME_Unmarshal (buffer, &p->scheme);
+}
+
+void
-+grub_tpm2_mu_TPMU_SYM_KEY_BITS_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMU_SYM_KEY_BITS_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMI_ALG_SYM_OBJECT algorithm,
+ TPMU_SYM_KEY_BITS *p)
+{
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPMU_SYM_MODE_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMU_SYM_MODE_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMI_ALG_SYM_OBJECT algorithm,
+ TPMU_SYM_MODE *p)
+{
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPMT_SYM_DEF_OBJECT_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMT_SYM_DEF_OBJECT_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMT_SYM_DEF_OBJECT *p)
+{
+ grub_tpm2_buffer_unpack_u16 (buffer, &p->algorithm);
-+ grub_tpm2_mu_TPMU_SYM_KEY_BITS_Unmarshal (buffer, p->algorithm, &p->keyBits);
-+ grub_tpm2_mu_TPMU_SYM_MODE_Unmarshal (buffer, p->algorithm, &p->mode);
++ grub_Tss2_MU_TPMU_SYM_KEY_BITS_Unmarshal (buffer, p->algorithm, &p->keyBits);
++ grub_Tss2_MU_TPMU_SYM_MODE_Unmarshal (buffer, p->algorithm, &p->mode);
+}
+
+void
-+grub_tpm2_mu_TPMS_SYMCIPHER_PARMS_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMS_SYMCIPHER_PARMS_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMS_SYMCIPHER_PARMS *p)
+{
-+ grub_tpm2_mu_TPMT_SYM_DEF_OBJECT_Unmarshal (buffer, &p->sym);
++ grub_Tss2_MU_TPMT_SYM_DEF_OBJECT_Unmarshal (buffer, &p->sym);
+}
+
+void
-+grub_tpm2_mu_TPMU_ASYM_SCHEME_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMU_ASYM_SCHEME_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMI_ALG_RSA_DECRYPT scheme,
+ TPMU_ASYM_SCHEME *p __attribute__((unused)))
+{
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPMT_RSA_SCHEME_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMT_RSA_SCHEME_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMT_RSA_SCHEME *p)
+{
+ grub_tpm2_buffer_unpack_u16 (buffer, &p->scheme);
-+ grub_tpm2_mu_TPMU_ASYM_SCHEME_Unmarshal (buffer, p->scheme, &p->details);
++ grub_Tss2_MU_TPMU_ASYM_SCHEME_Unmarshal (buffer, p->scheme, &p->details);
+}
+
+void
-+grub_tpm2_mu_TPMS_RSA_PARMS_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMS_RSA_PARMS_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMS_RSA_PARMS *p)
+{
-+ grub_tpm2_mu_TPMT_SYM_DEF_OBJECT_Unmarshal (buffer, &p->symmetric);
-+ grub_tpm2_mu_TPMT_RSA_SCHEME_Unmarshal (buffer, &p->scheme);
++ grub_Tss2_MU_TPMT_SYM_DEF_OBJECT_Unmarshal (buffer, &p->symmetric);
++ grub_Tss2_MU_TPMT_RSA_SCHEME_Unmarshal (buffer, &p->scheme);
+ grub_tpm2_buffer_unpack_u16 (buffer, &p->keyBits);
+ grub_tpm2_buffer_unpack_u32 (buffer, &p->exponent);
+}
+
+void
-+grub_tpm2_mu_TPMT_ECC_SCHEME_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMT_ECC_SCHEME_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMT_ECC_SCHEME *p)
+{
+ grub_tpm2_buffer_unpack_u16 (buffer, &p->scheme);
-+ grub_tpm2_mu_TPMU_ASYM_SCHEME_Unmarshal (buffer, p->scheme, &p->details);
++ grub_Tss2_MU_TPMU_ASYM_SCHEME_Unmarshal (buffer, p->scheme, &p->details);
+}
+
+void
-+grub_tpm2_mu_TPMU_KDF_SCHEME_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMU_KDF_SCHEME_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMI_ALG_KDF scheme,
+ TPMU_KDF_SCHEME *p)
+{
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPMT_KDF_SCHEME_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMT_KDF_SCHEME_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMT_KDF_SCHEME *p)
+{
+ grub_tpm2_buffer_unpack_u16 (buffer, &p->scheme);
-+ grub_tpm2_mu_TPMU_KDF_SCHEME_Unmarshal (buffer, p->scheme, &p->details);
++ grub_Tss2_MU_TPMU_KDF_SCHEME_Unmarshal (buffer, p->scheme, &p->details);
+}
+
+void
-+grub_tpm2_mu_TPMS_ECC_PARMS_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMS_ECC_PARMS_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMS_ECC_PARMS *p)
+{
-+ grub_tpm2_mu_TPMT_SYM_DEF_OBJECT_Unmarshal (buffer, &p->symmetric);
-+ grub_tpm2_mu_TPMT_ECC_SCHEME_Unmarshal (buffer, &p->scheme );
++ grub_Tss2_MU_TPMT_SYM_DEF_OBJECT_Unmarshal (buffer, &p->symmetric);
++ grub_Tss2_MU_TPMT_ECC_SCHEME_Unmarshal (buffer, &p->scheme );
+ grub_tpm2_buffer_unpack_u16 (buffer, &p->curveID);
-+ grub_tpm2_mu_TPMT_KDF_SCHEME_Unmarshal (buffer, &p->kdf);
++ grub_Tss2_MU_TPMT_KDF_SCHEME_Unmarshal (buffer, &p->kdf);
+}
+
+void
-+grub_tpm2_mu_TPMU_PUBLIC_PARMS_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMU_PUBLIC_PARMS_Unmarshal (grub_tpm2_buffer_t buffer,
+ grub_uint32_t type,
+ TPMU_PUBLIC_PARMS *p)
+{
+ switch (type)
+ {
+ case TPM_ALG_KEYEDHASH:
-+ grub_tpm2_mu_TPMS_KEYEDHASH_PARMS_Unmarshal (buffer, &p->keyedHashDetail);
++ grub_Tss2_MU_TPMS_KEYEDHASH_PARMS_Unmarshal (buffer, &p->keyedHashDetail);
+ break;
+ case TPM_ALG_SYMCIPHER:
-+ grub_tpm2_mu_TPMS_SYMCIPHER_PARMS_Unmarshal (buffer, &p->symDetail);
++ grub_Tss2_MU_TPMS_SYMCIPHER_PARMS_Unmarshal (buffer, &p->symDetail);
+ break;
+ case TPM_ALG_RSA:
-+ grub_tpm2_mu_TPMS_RSA_PARMS_Unmarshal (buffer, &p->rsaDetail);
++ grub_Tss2_MU_TPMS_RSA_PARMS_Unmarshal (buffer, &p->rsaDetail);
+ break;
+ case TPM_ALG_ECC:
-+ grub_tpm2_mu_TPMS_ECC_PARMS_Unmarshal (buffer, &p->eccDetail);
++ grub_Tss2_MU_TPMS_ECC_PARMS_Unmarshal (buffer, &p->eccDetail);
+ break;
+ default:
+ buffer->error = 1;
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPMS_ECC_POINT_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMS_ECC_POINT_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMS_ECC_POINT *p)
+{
-+ grub_tpm2_mu_TPM2B_ECC_PARAMETER_Unmarshal (buffer, &p->x);
-+ grub_tpm2_mu_TPM2B_ECC_PARAMETER_Unmarshal (buffer, &p->y);
++ grub_Tss2_MU_TPM2B_ECC_PARAMETER_Unmarshal (buffer, &p->x);
++ grub_Tss2_MU_TPM2B_ECC_PARAMETER_Unmarshal (buffer, &p->y);
+}
+
+void
-+grub_tpm2_mu_TPMU_PUBLIC_ID_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMU_PUBLIC_ID_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMI_ALG_PUBLIC type,
+ TPMU_PUBLIC_ID *p)
+{
+ switch(type)
+ {
+ case TPM_ALG_KEYEDHASH:
-+ grub_tpm2_mu_TPM2B_DIGEST_Unmarshal (buffer, &p->keyedHash);
++ grub_Tss2_MU_TPM2B_DIGEST_Unmarshal (buffer, &p->keyedHash);
+ break;
+ case TPM_ALG_SYMCIPHER:
-+ grub_tpm2_mu_TPM2B_DIGEST_Unmarshal (buffer, &p->sym);
++ grub_Tss2_MU_TPM2B_DIGEST_Unmarshal (buffer, &p->sym);
+ break;
+ case TPM_ALG_RSA:
-+ grub_tpm2_mu_TPM2B_PUBLIC_KEY_RSA_Unmarshal (buffer, &p->rsa);
++ grub_Tss2_MU_TPM2B_PUBLIC_KEY_RSA_Unmarshal (buffer, &p->rsa);
+ break;
+ case TPM_ALG_ECC:
-+ grub_tpm2_mu_TPMS_ECC_POINT_Unmarshal (buffer, &p->ecc);
++ grub_Tss2_MU_TPMS_ECC_POINT_Unmarshal (buffer, &p->ecc);
+ break;
+ default:
+ buffer->error = 1;
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPMT_PUBLIC_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMT_PUBLIC_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMT_PUBLIC *p)
+{
+ grub_tpm2_buffer_unpack_u16 (buffer, &p->type);
+ grub_tpm2_buffer_unpack_u16 (buffer, &p->nameAlg);
-+ grub_tpm2_mu_TPMA_OBJECT_Unmarshal (buffer, &p->objectAttributes);
-+ grub_tpm2_mu_TPM2B_DIGEST_Unmarshal (buffer, &p->authPolicy);
-+ grub_tpm2_mu_TPMU_PUBLIC_PARMS_Unmarshal (buffer, p->type, &p->parameters);
-+ grub_tpm2_mu_TPMU_PUBLIC_ID_Unmarshal (buffer, p->type, &p->unique);
++ grub_Tss2_MU_TPMA_OBJECT_Unmarshal (buffer, &p->objectAttributes);
++ grub_Tss2_MU_TPM2B_DIGEST_Unmarshal (buffer, &p->authPolicy);
++ grub_Tss2_MU_TPMU_PUBLIC_PARMS_Unmarshal (buffer, p->type, &p->parameters);
++ grub_Tss2_MU_TPMU_PUBLIC_ID_Unmarshal (buffer, p->type, &p->unique);
+}
+
+void
-+grub_tpm2_mu_TPM2B_PUBLIC_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPM2B_PUBLIC_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPM2B_PUBLIC *p)
+{
+ grub_tpm2_buffer_unpack_u16 (buffer, &p->size);
-+ grub_tpm2_mu_TPMT_PUBLIC_Unmarshal (buffer, &p->publicArea);
++ grub_Tss2_MU_TPMT_PUBLIC_Unmarshal (buffer, &p->publicArea);
+}
+
+void
-+grub_tpm2_mu_TPMS_NV_PUBLIC_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMS_NV_PUBLIC_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMS_NV_PUBLIC *p)
+{
+ grub_tpm2_buffer_unpack_u32 (buffer, &p->nvIndex);
+ grub_tpm2_buffer_unpack_u16 (buffer, &p->nameAlg);
+ grub_tpm2_buffer_unpack_u32 (buffer, &p->attributes);
-+ grub_tpm2_mu_TPM2B_DIGEST_Unmarshal (buffer, &p->authPolicy);
++ grub_Tss2_MU_TPM2B_DIGEST_Unmarshal (buffer, &p->authPolicy);
+ grub_tpm2_buffer_unpack_u16 (buffer, &p->dataSize);
+}
+
+void
-+grub_tpm2_mu_TPM2B_NV_PUBLIC_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPM2B_NV_PUBLIC_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPM2B_NV_PUBLIC *p)
+{
+ grub_tpm2_buffer_unpack_u16 (buffer, &p->size);
-+ grub_tpm2_mu_TPMS_NV_PUBLIC_Unmarshal (buffer, &p->nvPublic);
++ grub_Tss2_MU_TPMS_NV_PUBLIC_Unmarshal (buffer, &p->nvPublic);
+}
+
+void
-+grub_tpm2_mu_TPM2B_NAME_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPM2B_NAME_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPM2B_NAME *n)
+{
+ TPM2B_BUFFER_UNMARSHAL (buffer, TPM2B_NAME, n);
+}
+
+void
-+grub_tpm2_mu_TPMS_TAGGED_PROPERTY_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMS_TAGGED_PROPERTY_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMS_TAGGED_PROPERTY* property)
+{
+ grub_tpm2_buffer_unpack_u32 (buffer, &property->property);
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPMT_TK_CREATION_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMT_TK_CREATION_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMT_TK_CREATION *p)
+{
+ grub_tpm2_buffer_unpack_u16 (buffer, &p->tag);
+ grub_tpm2_buffer_unpack_u32 (buffer, &p->hierarchy);
-+ grub_tpm2_mu_TPM2B_DIGEST_Unmarshal (buffer, &p->digest);
++ grub_Tss2_MU_TPM2B_DIGEST_Unmarshal (buffer, &p->digest);
+}
+
+void
-+grub_tpm2_mu_TPMT_TK_HASHCHECK_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_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_DIGEST_Unmarshal (buffer, &p->digest);
++ grub_Tss2_MU_TPM2B_DIGEST_Unmarshal (buffer, &p->digest);
+}
+
+void
-+grub_tpm2_mu_TPMT_TK_VERIFIED_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_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_DIGEST_Unmarshal (buffer, &p->digest);
++ grub_Tss2_MU_TPM2B_DIGEST_Unmarshal (buffer, &p->digest);
+}
+
+void
-+grub_tpm2_mu_TPMS_PCR_SELECTION_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMS_PCR_SELECTION_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMS_PCR_SELECTION* pcrSelection)
+{
+ grub_tpm2_buffer_unpack_u16 (buffer, &pcrSelection->hash);
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPML_PCR_SELECTION_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPML_PCR_SELECTION_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPML_PCR_SELECTION* pcrSelection)
+{
+ grub_tpm2_buffer_unpack_u32 (buffer, &pcrSelection->count);
@@ grub-core/tpm2/mu.c (new)
+ }
+
+ for (grub_uint32_t i = 0; i < pcrSelection->count; i++)
-+ grub_tpm2_mu_TPMS_PCR_SELECTION_Unmarshal (buffer, &pcrSelection->pcrSelections[i]);
++ grub_Tss2_MU_TPMS_PCR_SELECTION_Unmarshal (buffer, &pcrSelection->pcrSelections[i]);
+}
+
+void
-+grub_tpm2_mu_TPML_DIGEST_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPML_DIGEST_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPML_DIGEST* digest)
+{
+ grub_tpm2_buffer_unpack_u32 (buffer, &digest->count);
@@ grub-core/tpm2/mu.c (new)
+ }
+
+ for (grub_uint32_t i = 0; i < digest->count; i++)
-+ grub_tpm2_mu_TPM2B_DIGEST_Unmarshal (buffer, &digest->digests[i]);
++ grub_Tss2_MU_TPM2B_DIGEST_Unmarshal (buffer, &digest->digests[i]);
+}
+
+void
-+grub_tpm2_mu_TPMS_SIGNATURE_RSA_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_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_PUBLIC_KEY_RSA_Unmarshal (buffer, &rsa->sig);
++ grub_Tss2_MU_TPM2B_PUBLIC_KEY_RSA_Unmarshal (buffer, &rsa->sig);
+}
+
+void
-+grub_tpm2_mu_TPMS_SIGNATURE_ECC_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_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_ECC_PARAMETER_Unmarshal (buffer, &ecc->signatureR);
-+ grub_tpm2_mu_TPM2B_ECC_PARAMETER_Unmarshal (buffer, &ecc->signatureS);
++ grub_Tss2_MU_TPM2B_ECC_PARAMETER_Unmarshal (buffer, &ecc->signatureR);
++ grub_Tss2_MU_TPM2B_ECC_PARAMETER_Unmarshal (buffer, &ecc->signatureS);
+}
+
+void
-+grub_tpm2_mu_TPMU_HA_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_MU_TPMU_HA_Unmarshal (grub_tpm2_buffer_t buffer,
+ TPMI_ALG_HASH hashAlg,
+ TPMU_HA *p)
+{
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPMT_HA_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_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);
++ grub_Tss2_MU_TPMU_HA_Unmarshal (buffer, p->hashAlg, &p->digest);
+}
+
+void
-+grub_tpm2_mu_TPMU_SIGNATURE_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_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);
++ grub_Tss2_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);
++ grub_Tss2_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);
++ grub_Tss2_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);
++ grub_Tss2_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);
++ grub_Tss2_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);
++ grub_Tss2_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);
++ grub_Tss2_MU_TPMT_HA_Unmarshal (buffer, &p->hmac);
+ break;
+ case TPM_ALG_NULL:
+ break;
@@ grub-core/tpm2/mu.c (new)
+}
+
+void
-+grub_tpm2_mu_TPMT_SIGNATURE_Unmarshal (grub_tpm2_buffer_t buffer,
++grub_Tss2_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);
++ grub_Tss2_MU_TPMU_SIGNATURE_Unmarshal (buffer, p->sigAlg, &p->signature);
+}
- ## grub-core/tpm2/tcg2.c (new) ##
+ ## grub-core/lib/tss2/tss2_mu.h (new) ##
@@
+/*
+ * GRUB -- GRand Unified Bootloader
++ * Copyright (C) 2024 Free Software Foundation, Inc.
+ * Copyright (C) 2022 Microsoft Corporation
+ *
+ * GRUB is free software: you can redistribute it and/or modify
@@ grub-core/tpm2/tcg2.c (new)
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
-+#include <grub/efi/api.h>
-+#include <grub/efi/efi.h>
-+#include <grub/efi/tpm.h>
-+#include <grub/mm.h>
-+#include <grub/tpm2/tcg2.h>
++#ifndef GRUB_TPM2_MU_HEADER
++#define GRUB_TPM2_MU_HEADER 1
+
-+static grub_err_t
-+grub_tcg2_get_caps (grub_efi_tpm2_protocol_t *protocol, int *tpm2,
-+ grub_size_t *max_output_size)
-+{
-+ grub_efi_status_t status;
++#include <tss2_buffer.h>
++#include <tss2_structs.h>
+
-+ static int has_caps = 0;
-+ static EFI_TCG2_BOOT_SERVICE_CAPABILITY caps =
-+ {
-+ .Size = (grub_uint8_t) sizeof (caps)
-+ };
++void
++grub_Tss2_MU_TPMS_AUTH_COMMAND_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMS_AUTH_COMMAND* authCommand);
+
-+ if (has_caps)
-+ goto exit;
++void
++grub_Tss2_MU_TPM2B_Marshal (grub_tpm2_buffer_t buffer,
++ const grub_uint16_t size,
++ const grub_uint8_t* b);
+
-+ status = protocol->get_capability (protocol, &caps);
-+ if (status != GRUB_EFI_SUCCESS || !caps.TPMPresentFlag)
-+ return GRUB_ERR_FILE_NOT_FOUND;
++void
++grub_Tss2_MU_TPMU_SYM_KEY_BITS_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMI_ALG_SYM_OBJECT algorithm,
++ const TPMU_SYM_KEY_BITS *p);
+
-+ has_caps = 1;
++void
++grub_Tss2_MU_TPMU_SYM_MODE_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMI_ALG_SYM_OBJECT algorithm,
++ const TPMU_SYM_MODE *p);
+
-+exit:
-+ if (tpm2)
-+ *tpm2 = caps.TPMPresentFlag;
-+ if (max_output_size)
-+ *max_output_size = caps.MaxResponseSize;
++void
++grub_Tss2_MU_TPMT_SYM_DEF_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMT_SYM_DEF *p);
+
-+ return GRUB_ERR_NONE;
-+}
++void
++grub_Tss2_MU_TPMS_PCR_SELECTION_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMS_PCR_SELECTION* pcrSelection);
+
-+static grub_err_t
-+grub_tcg2_get_protocol (grub_efi_tpm2_protocol_t **protocol)
-+{
-+ static grub_guid_t tpm2_guid = EFI_TPM2_GUID;
-+ static grub_efi_tpm2_protocol_t *tpm2_protocol = NULL;
++void
++grub_Tss2_MU_TPML_PCR_SELECTION_Marshal (grub_tpm2_buffer_t buffer,
++ const TPML_PCR_SELECTION* pcrSelection);
+
-+ int tpm2;
-+ grub_efi_handle_t *handles;
-+ grub_efi_uintn_t num_handles;
-+ grub_efi_handle_t tpm2_handle;
-+ grub_err_t err = GRUB_ERR_FILE_NOT_FOUND;
++void
++grub_Tss2_MU_TPMA_OBJECT_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMA_OBJECT *p);
+
-+ if (tpm2_protocol)
-+ {
-+ *protocol = tpm2_protocol;
-+ return GRUB_ERR_NONE;
-+ }
++void
++grub_Tss2_MU_TPMS_SCHEME_XOR_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMS_SCHEME_XOR *p);
+
-+ handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, &tpm2_guid, NULL,
-+ &num_handles);
-+ if (!handles || !num_handles)
-+ return err;
++void
++grub_Tss2_MU_TPMS_SCHEME_HMAC_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMS_SCHEME_HMAC *p);
+
-+ tpm2_handle = handles[0];
++void
++grub_Tss2_MU_TPMU_SCHEME_KEYEDHASH_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMI_ALG_KEYEDHASH_SCHEME scheme,
++ const TPMU_SCHEME_KEYEDHASH *p);
+
-+ tpm2_protocol = grub_efi_open_protocol (tpm2_handle, &tpm2_guid,
-+ GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL);
-+ if (!tpm2_protocol)
-+ goto exit;
++void
++grub_Tss2_MU_TPMT_KEYEDHASH_SCHEME_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMT_KEYEDHASH_SCHEME *p);
+
-+ err = grub_tcg2_get_caps (tpm2_protocol, &tpm2, NULL);
-+ if (err || !tpm2)
-+ goto exit;
++void
++grub_Tss2_MU_TPMS_KEYEDHASH_PARMS_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMS_KEYEDHASH_PARMS *p);
+
-+ *protocol = tpm2_protocol;
-+ err = GRUB_ERR_NONE;
++void
++grub_Tss2_MU_TPMT_SYM_DEF_OBJECT_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMT_SYM_DEF_OBJECT *p);
+
-+exit:
-+ grub_free (handles);
-+ return err;
-+}
++void
++grub_Tss2_MU_TPMU_ASYM_SCHEME_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMI_ALG_RSA_DECRYPT scheme,
++ const TPMU_ASYM_SCHEME *p);
+
-+grub_err_t
-+grub_tcg2_get_max_output_size (grub_size_t *size)
-+{
-+ grub_err_t err;
-+ grub_size_t max;
-+ grub_efi_tpm2_protocol_t *protocol;
++void
++grub_Tss2_MU_TPMT_RSA_SCHEME_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMT_RSA_SCHEME *p);
+
-+ if (!size)
-+ return GRUB_ERR_BAD_ARGUMENT;
++void
++grub_Tss2_MU_TPMS_RSA_PARMS_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMS_RSA_PARMS *p);
+
-+ err = grub_tcg2_get_protocol (&protocol);
-+ if (err)
-+ return err;
++void
++grub_Tss2_MU_TPMS_SYMCIPHER_PARMS_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMS_SYMCIPHER_PARMS *p);
+
-+ err = grub_tcg2_get_caps (protocol, NULL, &max);
-+ if (err)
-+ return err;
++void
++grub_Tss2_MU_TPMT_ECC_SCHEME_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMT_ECC_SCHEME *p);
+
-+ *size = max;
++void
++grub_Tss2_MU_TPMU_KDF_SCHEME_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMI_ALG_KDF scheme,
++ const TPMU_KDF_SCHEME *p);
+
-+ return GRUB_ERR_NONE;
-+}
++void
++grub_Tss2_MU_TPMT_KDF_SCHEME_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMT_KDF_SCHEME *p);
+
-+grub_err_t
-+grub_tcg2_submit_command (grub_size_t input_size,
-+ grub_uint8_t *input,
-+ grub_size_t output_size,
-+ grub_uint8_t *output)
-+{
-+ grub_err_t err;
-+ grub_efi_status_t status;
-+ grub_efi_tpm2_protocol_t *protocol;
++void
++grub_Tss2_MU_TPMS_ECC_PARMS_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMS_ECC_PARMS *p);
+
-+ if (!input_size || !input || !output_size || !output)
-+ return GRUB_ERR_BAD_ARGUMENT;
++void
++grub_Tss2_MU_TPMU_PUBLIC_PARMS_Marshal (grub_tpm2_buffer_t buffer,
++ const grub_uint32_t type,
++ const TPMU_PUBLIC_PARMS *p);
+
-+ err = grub_tcg2_get_protocol (&protocol);
-+ if (err)
-+ return err;
++void
++grub_Tss2_MU_TPMS_ECC_POINT_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMS_ECC_POINT *p);
+
-+ status = protocol->submit_command (protocol, input_size, input,
-+ output_size, output);
-+ if (status != GRUB_EFI_SUCCESS)
-+ return GRUB_ERR_INVALID_COMMAND;
++void
++grub_Tss2_MU_TPMU_PUBLIC_ID_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMI_ALG_PUBLIC type,
++ const TPMU_PUBLIC_ID *p);
+
-+ return GRUB_ERR_NONE;
-+}
-
- ## grub-core/tpm2/tpm2.c (new) ##
-@@
-+/*
-+ * GRUB -- GRand Unified Bootloader
-+ * Copyright (C) 2022 Microsoft Corporation
-+ *
-+ * GRUB is free software: you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation, either version 3 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * GRUB is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
-+ */
++void
++grub_Tss2_MU_TPMT_PUBLIC_PARMS_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMT_PUBLIC_PARMS *p);
+
-+#include <grub/err.h>
-+#include <grub/misc.h>
-+#include <grub/tpm2/buffer.h>
-+#include <grub/tpm2/mu.h>
-+#include <grub/tpm2/tcg2.h>
-+#include <grub/tpm2/tpm2.h>
-+#include <grub/types.h>
++void
++grub_Tss2_MU_TPMT_PUBLIC_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMT_PUBLIC *p);
+
-+static TPM_RC
-+grub_tpm2_submit_command_real (const TPMI_ST_COMMAND_TAG tag,
-+ const TPM_CC commandCode,
-+ TPM_RC *responseCode,
-+ const struct grub_tpm2_buffer *in,
-+ struct grub_tpm2_buffer *out)
-+{
-+ grub_err_t err;
-+ struct grub_tpm2_buffer buf;
-+ TPMI_ST_COMMAND_TAG tag_out;
-+ grub_uint32_t command_size;
-+ grub_size_t max_output_size;
-+
-+ /* Marshal */
-+ grub_tpm2_buffer_init (&buf);
-+ grub_tpm2_buffer_pack_u16 (&buf, tag);
-+ grub_tpm2_buffer_pack_u32 (&buf, 0);
-+ grub_tpm2_buffer_pack_u32 (&buf, commandCode);
-+ grub_tpm2_buffer_pack (&buf, in->data, in->size);
-+
-+ if (buf.error)
-+ return TPM_RC_FAILURE;
-+
-+ command_size = grub_swap_bytes32 (buf.size);
-+ grub_memcpy (&buf.data[sizeof (grub_uint16_t)], &command_size,
-+ sizeof (command_size));
-+
-+ /* Stay within output block limits */
-+ err = grub_tcg2_get_max_output_size (&max_output_size);
-+ if (err || max_output_size > out->cap)
-+ max_output_size = out->cap - 1;
-+
-+ /* Submit */
-+ err = grub_tcg2_submit_command (buf.size, buf.data, max_output_size,
-+ out->data);
-+ if (err)
-+ return TPM_RC_FAILURE;
-+
-+ /* Unmarshal */
-+ out->size = sizeof (grub_uint16_t) + sizeof (grub_uint32_t) +
-+ sizeof (grub_uint32_t);
-+ grub_tpm2_buffer_unpack_u16 (out, &tag_out);
-+ grub_tpm2_buffer_unpack_u32 (out, &command_size);
-+ grub_tpm2_buffer_unpack_u32 (out, responseCode);
-+ out->size = command_size;
-+ if (out->error)
-+ return TPM_RC_FAILURE;
-+
-+ return TPM_RC_SUCCESS;
-+}
++void
++grub_Tss2_MU_TPM2B_PUBLIC_Marshal (grub_tpm2_buffer_t buffer,
++ const TPM2B_PUBLIC *p);
+
-+static TPM_RC
-+grub_tpm2_submit_command (const TPMI_ST_COMMAND_TAG tag,
-+ const TPM_CC commandCode,
-+ TPM_RC *responseCode,
-+ const struct grub_tpm2_buffer *in,
-+ struct grub_tpm2_buffer *out)
-+{
-+ TPM_RC err;
-+ int retry_cnt = 0;
-+
-+ /* Catch TPM_RC_RETRY and send the command again */
-+ do {
-+ err = grub_tpm2_submit_command_real (tag, commandCode, responseCode,
-+ in, out);
-+ if (*responseCode != TPM_RC_RETRY)
-+ break;
++void
++grub_Tss2_MU_TPMS_SENSITIVE_CREATE_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMS_SENSITIVE_CREATE *p);
+
-+ retry_cnt++;
-+ } while (retry_cnt < 3);
++void
++grub_Tss2_MU_TPM2B_SENSITIVE_CREATE_Marshal (grub_tpm2_buffer_t buffer,
++ const TPM2B_SENSITIVE_CREATE *sensitiveCreate);
+
-+ return err;
-+}
++void
++grub_Tss2_MU_TPMU_SENSITIVE_COMPOSITE_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMI_ALG_PUBLIC type,
++ const TPMU_SENSITIVE_COMPOSITE *p);
++void
++grub_Tss2_MU_TPMT_SENSITIVE_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMT_SENSITIVE *p);
+
-+TPM_RC
-+TPM2_CreatePrimary (const TPMI_RH_HIERARCHY primaryHandle,
-+ const TPMS_AUTH_COMMAND *authCommand,
-+ const TPM2B_SENSITIVE_CREATE *inSensitive,
-+ const TPM2B_PUBLIC *inPublic,
-+ const TPM2B_DATA *outsideInfo,
-+ const TPML_PCR_SELECTION *creationPCR,
-+ TPM_HANDLE *objectHandle,
-+ TPM2B_PUBLIC *outPublic,
-+ TPM2B_CREATION_DATA *creationData,
-+ TPM2B_DIGEST *creationHash,
-+ TPMT_TK_CREATION *creationTicket,
-+ TPM2B_NAME *name,
-+ TPMS_AUTH_RESPONSE *authResponse)
-+{
-+ TPM_RC rc;
-+ struct grub_tpm2_buffer in;
-+ struct grub_tpm2_buffer out;
-+ TPM_HANDLE objectHandleTmp;
-+ TPM2B_PUBLIC outPublicTmp;
-+ TPM2B_CREATION_DATA creationDataTmp;
-+ TPM2B_DIGEST creationHashTmp;
-+ TPMT_TK_CREATION creationTicketTmp;
-+ 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 parameterSize;
-+
-+ if (!inSensitive || !inPublic || !outsideInfo || !creationPCR)
-+ return TPM_RC_VALUE;
-+
-+ if (!objectHandle)
-+ objectHandle = &objectHandleTmp;
-+ if (!outPublic)
-+ outPublic = &outPublicTmp;
-+ if (!creationData)
-+ creationData = &creationDataTmp;
-+ if (!creationHash)
-+ creationHash = &creationHashTmp;
-+ if (!creationTicket)
-+ creationTicket = &creationTicketTmp;
-+ if (!name)
-+ name = &nameTmp;
-+ if (!authResponse)
-+ authResponse = &authResponseTmp;
-+
-+ grub_memset (outPublic, 0, sizeof (*outPublic));
-+ grub_memset (creationData, 0, sizeof (*creationData));
-+ grub_memset (creationHash, 0, sizeof (*creationHash));
-+ grub_memset (creationTicket, 0, sizeof (*creationTicket));
-+ grub_memset (name, 0, sizeof (*name));
-+ grub_memset (authResponse, 0, sizeof (*authResponse));
-+
-+ /* Marshal */
-+ grub_tpm2_buffer_init (&in);
-+ grub_tpm2_buffer_pack_u32 (&in, primaryHandle);
-+ if (authCommand)
-+ grub_tpm2_mu_TPMS_AUTH_COMMAND_Marshal (&in, authCommand);
-+ grub_tpm2_mu_TPM2B_SENSITIVE_CREATE_Marshal (&in, inSensitive);
-+ grub_tpm2_mu_TPM2B_PUBLIC_Marshal (&in, inPublic);
-+ grub_tpm2_mu_TPM2B_Marshal (&in, outsideInfo->size, outsideInfo->buffer);
-+ grub_tpm2_mu_TPML_PCR_SELECTION_Marshal (&in, creationPCR);
-+ if (in.error)
-+ return TPM_RC_FAILURE;
-+
-+ /* Submit */
-+ grub_tpm2_buffer_init (&out);
-+ rc = grub_tpm2_submit_command (tag, TPM_CC_CreatePrimary, &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, ¶meterSize);
-+ grub_tpm2_mu_TPM2B_PUBLIC_Unmarshal (&out, outPublic);
-+ grub_tpm2_mu_TPM2B_CREATION_DATA_Unmarshal (&out, creationData);
-+ grub_tpm2_mu_TPM2B_DIGEST_Unmarshal (&out, creationHash);
-+ grub_tpm2_mu_TPMT_TK_CREATION_Unmarshal (&out, creationTicket);
-+ grub_tpm2_mu_TPM2B_NAME_Unmarshal (&out, 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;
-+}
++void
++grub_Tss2_MU_TPM2B_SENSITIVE_Marshal (grub_tpm2_buffer_t buffer,
++ const TPM2B_SENSITIVE *p);
+
-+TPM_RC
-+TPM2_StartAuthSession (const TPMI_DH_OBJECT tpmKey,
-+ const TPMI_DH_ENTITY bind,
-+ const TPMS_AUTH_COMMAND *authCommand,
-+ const TPM2B_NONCE *nonceCaller,
-+ const TPM2B_ENCRYPTED_SECRET *encryptedSalt,
-+ const TPM_SE sessionType,
-+ const TPMT_SYM_DEF *symmetric,
-+ const TPMI_ALG_HASH authHash,
-+ TPMI_SH_AUTH_SESSION *sessionHandle,
-+ TPM2B_NONCE *nonceTpm,
-+ TPMS_AUTH_RESPONSE *authResponse)
-+{
-+ TPM_RC rc;
-+ struct grub_tpm2_buffer in;
-+ struct grub_tpm2_buffer out;
-+ TPMI_SH_AUTH_SESSION sessionHandleTmp;
-+ TPM2B_NONCE nonceTpmTmp;
-+ 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 (!nonceCaller || !symmetric)
-+ return TPM_RC_VALUE;
-+
-+ if (tpmKey == TPM_RH_NULL &&
-+ (encryptedSalt && encryptedSalt->size != 0))
-+ return TPM_RC_VALUE;
-+
-+ if (!sessionHandle)
-+ sessionHandle = &sessionHandleTmp;
-+ if (!nonceTpm)
-+ nonceTpm = &nonceTpmTmp;
-+ if (!authResponse)
-+ authResponse = &authResponseTmp;
-+
-+ grub_memset (sessionHandle, 0, sizeof (*sessionHandle));
-+ grub_memset (nonceTpm, 0, sizeof (*nonceTpm));
-+ grub_memset (authResponse, 0, sizeof (*authResponse));
-+
-+ /* Marshal */
-+ grub_tpm2_buffer_init (&in);
-+ grub_tpm2_buffer_pack_u32 (&in, tpmKey);
-+ grub_tpm2_buffer_pack_u32 (&in, bind);
-+ if (tag == TPM_ST_SESSIONS)
-+ grub_tpm2_mu_TPMS_AUTH_COMMAND_Marshal (&in, authCommand);
-+ grub_tpm2_mu_TPM2B_Marshal (&in, nonceCaller->size, nonceCaller->buffer);
-+ if (encryptedSalt)
-+ grub_tpm2_mu_TPM2B_Marshal (&in, encryptedSalt->size, encryptedSalt->secret);
-+ else
-+ grub_tpm2_buffer_pack_u16 (&in, 0);
-+ grub_tpm2_buffer_pack_u8 (&in, sessionType);
-+ grub_tpm2_mu_TPMT_SYM_DEF_Marshal (&in, symmetric);
-+ grub_tpm2_buffer_pack_u16 (&in, authHash);
-+ if (in.error)
-+ return TPM_RC_FAILURE;
-+
-+ /* Submit */
-+ grub_tpm2_buffer_init (&out);
-+ rc = grub_tpm2_submit_command (tag, TPM_CC_StartAuthSession, &responseCode,
-+ &in, &out);
-+ if (rc != TPM_RC_SUCCESS)
-+ return rc;
-+ if (responseCode != TPM_RC_SUCCESS)
-+ return responseCode;
-+
-+ /* Unmarshal */
-+ grub_tpm2_buffer_unpack_u32 (&out, sessionHandle);
-+ if (tag == TPM_ST_SESSIONS)
-+ grub_tpm2_buffer_unpack_u32 (&out, ¶m_size);
-+ grub_tpm2_mu_TPM2B_NONCE_Unmarshal (&out, nonceTpm);
-+ 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;
-+}
++void
++grub_Tss2_MU_TPMS_SIGNATURE_RSA_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMS_SIGNATURE_RSA *p);
+
-+TPM_RC
-+TPM2_PolicyPCR (const TPMI_SH_POLICY policySessions,
-+ const TPMS_AUTH_COMMAND *authCommand,
-+ const TPM2B_DIGEST *pcrDigest,
-+ const TPML_PCR_SELECTION *pcrs,
-+ 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 (!pcrs)
-+ 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, policySessions);
-+ if (tag == TPM_ST_SESSIONS)
-+ grub_tpm2_mu_TPMS_AUTH_COMMAND_Marshal (&in, authCommand);
-+ if (pcrDigest)
-+ grub_tpm2_mu_TPM2B_Marshal (&in, pcrDigest->size, pcrDigest->buffer);
-+ else
-+ grub_tpm2_buffer_pack_u16 (&in, 0);
-+ grub_tpm2_mu_TPML_PCR_SELECTION_Marshal (&in, pcrs);
-+ if (in.error)
-+ return TPM_RC_FAILURE;
-+
-+ /* Submit */
-+ grub_tpm2_buffer_init (&out);
-+ rc = grub_tpm2_submit_command (tag, TPM_CC_PolicyPCR, &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, ¶m_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;
-+}
++void
++grub_Tss2_MU_TPMS_SIGNATURE_ECC_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMS_SIGNATURE_ECC *p);
+
-+TPM_RC
-+TPM2_ReadPublic (const TPMI_DH_OBJECT objectHandle,
-+ const TPMS_AUTH_COMMAND* authCommand,
-+ TPM2B_PUBLIC *outPublic)
-+{
-+ TPM_RC rc;
-+ struct grub_tpm2_buffer in;
-+ struct grub_tpm2_buffer out;
-+ TPMI_ST_COMMAND_TAG tag = authCommand ? TPM_ST_SESSIONS : TPM_ST_NO_SESSIONS;
-+ TPM_RC responseCode;
-+ grub_uint32_t parameterSize;
-+
-+ /* Marshal */
-+ grub_tpm2_buffer_init (&in);
-+ grub_tpm2_buffer_pack_u32 (&in, objectHandle);
-+ if (in.error)
-+ return TPM_RC_FAILURE;
-+
-+ /* Submit */
-+ grub_tpm2_buffer_init (&out);
-+ rc = grub_tpm2_submit_command (tag, TPM_CC_ReadPublic, &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, ¶meterSize);
-+ grub_tpm2_mu_TPM2B_PUBLIC_Unmarshal (&out, outPublic);
-+ if (out.error)
-+ return TPM_RC_FAILURE;
-+
-+ return TPM_RC_SUCCESS;
-+}
++void
++grub_Tss2_MU_TPMU_HA_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMI_ALG_HASH hashAlg,
++ const TPMU_HA *p);
+
-+TPM_RC
-+TPM2_Load (const TPMI_DH_OBJECT parent_handle,
-+ const TPMS_AUTH_COMMAND *authCommand,
-+ const TPM2B_PRIVATE *inPrivate,
-+ const TPM2B_PUBLIC *inPublic,
-+ 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 nonceTmp;
-+ 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 (!inPrivate || !inPublic)
-+ return TPM_RC_VALUE;
-+
-+ if (!objectHandle)
-+ objectHandle = &objectHandleTmp;
-+ if (!name)
-+ name = &nonceTmp;
-+ 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);
-+ grub_tpm2_buffer_pack_u32 (&in, parent_handle);
-+ if (authCommand)
-+ grub_tpm2_mu_TPMS_AUTH_COMMAND_Marshal (&in, authCommand);
-+ grub_tpm2_mu_TPM2B_Marshal (&in, inPrivate->size, inPrivate->buffer);
-+ grub_tpm2_mu_TPM2B_PUBLIC_Marshal (&in, inPublic);
-+ if (in.error)
-+ return TPM_RC_FAILURE;
-+
-+ /* Submit */
-+ grub_tpm2_buffer_init (&out);
-+ rc = grub_tpm2_submit_command (tag, TPM_CC_Load, &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, ¶m_size);
-+ grub_tpm2_mu_TPM2B_NAME_Unmarshal (&out, 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;
-+}
++void
++grub_Tss2_MU_TPMT_HA_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMT_HA *p);
+
-+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, ¶m_size);
-+ grub_tpm2_mu_TPM2B_NAME_Unmarshal (&out, 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;
-+}
++void
++grub_Tss2_MU_TPMU_SIGNATURE_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMI_ALG_SIG_SCHEME sigAlg,
++ const TPMU_SIGNATURE *p);
+
-+TPM_RC
-+TPM2_Unseal (const TPMI_DH_OBJECT itemHandle,
-+ const TPMS_AUTH_COMMAND *authCommand,
-+ TPM2B_SENSITIVE_DATA *outData,
-+ TPMS_AUTH_RESPONSE *authResponse)
-+{
-+ TPM_RC rc;
-+ struct grub_tpm2_buffer in;
-+ struct grub_tpm2_buffer out;
-+ TPM2B_SENSITIVE_DATA outDataTmp;
-+ 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 (!outData)
-+ outData = &outDataTmp;
-+ if (!authResponse)
-+ authResponse = &authResponseTmp;
-+
-+ grub_memset (outData, 0, sizeof (*outData));
-+ grub_memset (authResponse, 0, sizeof (*authResponse));
-+
-+ /* Marshal */
-+ grub_tpm2_buffer_init (&in);
-+ grub_tpm2_buffer_pack_u32 (&in, itemHandle);
-+ if (authCommand)
-+ grub_tpm2_mu_TPMS_AUTH_COMMAND_Marshal (&in, authCommand);
-+ if (in.error)
-+ return TPM_RC_FAILURE;
-+
-+ /* Submit */
-+ grub_tpm2_buffer_init (&out);
-+ rc = grub_tpm2_submit_command (tag, TPM_CC_Unseal, &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, ¶m_size);
-+ grub_tpm2_mu_TPM2B_SENSITIVE_DATA_Unmarshal (&out, outData);
-+ 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;
-+}
++void
++grub_Tss2_MU_TPMT_SIGNATURE_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMT_SIGNATURE *p);
+
-+TPM_RC
-+TPM2_FlushContext (const TPMI_DH_CONTEXT handle)
-+{
-+ TPM_RC rc;
-+ struct grub_tpm2_buffer in;
-+ struct grub_tpm2_buffer out;
-+ TPM_RC responseCode;
-+
-+ /* Marshal */
-+ grub_tpm2_buffer_init (&in);
-+ grub_tpm2_buffer_pack_u32 (&in, handle);
-+ if (in.error)
-+ return TPM_RC_FAILURE;
-+
-+ /* Submit */
-+ grub_tpm2_buffer_init (&out);
-+ rc = grub_tpm2_submit_command (TPM_ST_NO_SESSIONS, TPM_CC_FlushContext,
-+ &responseCode, &in, &out);
-+ if (rc != TPM_RC_SUCCESS)
-+ return rc;
-+ if (responseCode != TPM_RC_SUCCESS)
-+ return responseCode;
-+
-+ /* Unmarshal */
-+ if (out.error)
-+ return TPM_RC_FAILURE;
-+
-+ return TPM_RC_SUCCESS;
-+}
++void
++grub_Tss2_MU_TPMT_TK_VERIFIED_Marshal (grub_tpm2_buffer_t buffer,
++ const TPMT_TK_VERIFIED *p);
+
-+TPM_RC
-+TPM2_PCR_Read (const TPMS_AUTH_COMMAND *authCommand,
-+ const TPML_PCR_SELECTION *pcrSelectionIn,
-+ grub_uint32_t *pcrUpdateCounter,
-+ TPML_PCR_SELECTION *pcrSelectionOut,
-+ TPML_DIGEST *pcrValues,
-+ TPMS_AUTH_RESPONSE *authResponse)
-+{
-+ TPM_RC rc;
-+ struct grub_tpm2_buffer in;
-+ struct grub_tpm2_buffer out;
-+ grub_uint32_t pcrUpdateCounterTmp;
-+ TPML_PCR_SELECTION pcrSelectionOutTmp;
-+ TPML_DIGEST pcrValuesTmp;
-+ TPMS_AUTH_RESPONSE authResponseTmp;
-+ TPMI_ST_COMMAND_TAG tag = authCommand ? TPM_ST_SESSIONS : TPM_ST_NO_SESSIONS;
-+ TPM_RC responseCode;
-+ grub_uint32_t parameterSize;
-+
-+ if (!pcrSelectionIn)
-+ return TPM_RC_VALUE;
-+
-+ if (!pcrUpdateCounter)
-+ pcrUpdateCounter = &pcrUpdateCounterTmp;
-+ if (!pcrSelectionOut)
-+ pcrSelectionOut = &pcrSelectionOutTmp;
-+ if (!pcrValues)
-+ pcrValues = &pcrValuesTmp;
-+ if (!authResponse)
-+ authResponse = &authResponseTmp;
-+
-+ /* Marshal */
-+ grub_tpm2_buffer_init (&in);
-+ if (authCommand)
-+ grub_tpm2_mu_TPMS_AUTH_COMMAND_Marshal (&in, authCommand);
-+ grub_tpm2_mu_TPML_PCR_SELECTION_Marshal (&in, pcrSelectionIn);
-+ if (in.error)
-+ return TPM_RC_FAILURE;
-+
-+ /* Submit */
-+ grub_tpm2_buffer_init (&out);
-+ rc = grub_tpm2_submit_command (tag, TPM_CC_PCR_Read, &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, ¶meterSize);
-+ grub_tpm2_buffer_unpack_u32 (&out, pcrUpdateCounter);
-+ grub_tpm2_mu_TPML_PCR_SELECTION_Unmarshal (&out, pcrSelectionOut);
-+ grub_tpm2_mu_TPML_DIGEST_Unmarshal (&out, pcrValues);
-+ 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;
-+}
++void
++grub_Tss2_MU_TPMS_AUTH_RESPONSE_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMS_AUTH_RESPONSE* p);
+
-+TPM_RC
-+TPM2_PolicyGetDigest (const TPMI_SH_POLICY policySession,
-+ const TPMS_AUTH_COMMAND *authCommand,
-+ TPM2B_DIGEST *policyDigest,
-+ TPMS_AUTH_RESPONSE *authResponse)
-+{
-+ TPM_RC rc;
-+ struct grub_tpm2_buffer in;
-+ struct grub_tpm2_buffer out;
-+ TPMS_AUTH_RESPONSE authResponseTmp;
-+ TPM2B_DIGEST policyDigestTmp;
-+ TPMI_ST_COMMAND_TAG tag = authCommand ? TPM_ST_SESSIONS : TPM_ST_NO_SESSIONS;
-+ TPM_RC responseCode;
-+ grub_uint32_t parameterSize;
-+
-+ if (!authResponse)
-+ authResponse = &authResponseTmp;
-+ if (!policyDigest)
-+ policyDigest = &policyDigestTmp;
-+
-+ grub_memset (authResponse, 0, sizeof (*authResponse));
-+ grub_memset (policyDigest, 0, sizeof (*policyDigest));
-+
-+ /* Submit */
-+ grub_tpm2_buffer_init (&in);
-+ grub_tpm2_buffer_pack_u32 (&in, policySession);
-+ if (tag == TPM_ST_SESSIONS)
-+ grub_tpm2_mu_TPMS_AUTH_COMMAND_Marshal (&in, authCommand);
-+ if (in.error)
-+ return TPM_RC_FAILURE;
-+
-+ /* Submit */
-+ grub_tpm2_buffer_init (&out);
-+ rc = grub_tpm2_submit_command (tag, TPM_CC_PolicyGetDigest, &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, ¶meterSize);
-+ grub_tpm2_mu_TPM2B_DIGEST_Unmarshal (&out, policyDigest);
-+ 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;
-+}
++void
++grub_Tss2_MU_TPM2B_DIGEST_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPM2B_DIGEST* digest);
+
-+TPM_RC
-+TPM2_Create (const TPMI_DH_OBJECT parentHandle,
-+ const TPMS_AUTH_COMMAND *authCommand,
-+ const TPM2B_SENSITIVE_CREATE *inSensitive,
-+ const TPM2B_PUBLIC *inPublic,
-+ const TPM2B_DATA *outsideInfo,
-+ const TPML_PCR_SELECTION *creationPCR,
-+ TPM2B_PRIVATE *outPrivate,
-+ TPM2B_PUBLIC *outPublic,
-+ TPM2B_CREATION_DATA *creationData,
-+ TPM2B_DIGEST *creationHash,
-+ TPMT_TK_CREATION *creationTicket,
-+ TPMS_AUTH_RESPONSE *authResponse)
-+{
-+ struct grub_tpm2_buffer in;
-+ struct grub_tpm2_buffer out;
-+ TPM2B_PUBLIC outPublicTmp;
-+ TPM2B_PRIVATE outPrivateTmp;
-+ TPM2B_CREATION_DATA creationDataTmp;
-+ TPM2B_DIGEST creationHashTmp;
-+ TPMT_TK_CREATION creationTicketTmp;
-+ 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 (!inSensitive || !inPublic || !outsideInfo || !creationPCR)
-+ return TPM_RC_VALUE;
-+
-+ if (!outPrivate)
-+ outPrivate = &outPrivateTmp;
-+ if (!outPublic)
-+ outPublic = &outPublicTmp;
-+ if (!creationData)
-+ creationData = &creationDataTmp;
-+ if (!creationHash)
-+ creationHash = &creationHashTmp;
-+ if (!creationTicket)
-+ creationTicket = &creationTicketTmp;
-+ if (!authResponse)
-+ authResponse = &authResponseTmp;
-+
-+ grub_memset (outPrivate, 0, sizeof (*outPrivate));
-+ grub_memset (outPublic, 0, sizeof (*outPublic));
-+ grub_memset (creationData, 0, sizeof (*creationData));
-+ grub_memset (creationHash, 0, sizeof (*creationHash));
-+ grub_memset (creationTicket, 0, sizeof (*creationTicket));
-+ grub_memset (authResponse, 0, sizeof (*authResponse));
-+
-+ /* Marshal */
-+ grub_tpm2_buffer_init (&in);
-+ grub_tpm2_buffer_pack_u32 (&in, parentHandle);
-+ if (authCommand)
-+ grub_tpm2_mu_TPMS_AUTH_COMMAND_Marshal (&in, authCommand);
-+ grub_tpm2_mu_TPM2B_SENSITIVE_CREATE_Marshal (&in, inSensitive);
-+ grub_tpm2_mu_TPM2B_PUBLIC_Marshal (&in, inPublic);
-+ grub_tpm2_mu_TPM2B_Marshal (&in, outsideInfo->size, outsideInfo->buffer);
-+ grub_tpm2_mu_TPML_PCR_SELECTION_Marshal (&in, creationPCR);
-+ if (in.error)
-+ return TPM_RC_FAILURE;
-+
-+ /* Submit */
-+ grub_tpm2_buffer_init (&out);
-+ rc = grub_tpm2_submit_command (tag, TPM_CC_Create, &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, ¶meterSize);
-+ grub_tpm2_mu_TPM2B_PRIVATE_Unmarshal (&out, outPrivate);
-+ grub_tpm2_mu_TPM2B_PUBLIC_Unmarshal (&out, outPublic);
-+ grub_tpm2_mu_TPM2B_CREATION_DATA_Unmarshal (&out, creationData);
-+ grub_tpm2_mu_TPM2B_DIGEST_Unmarshal (&out, creationHash);
-+ grub_tpm2_mu_TPMT_TK_CREATION_Unmarshal (&out, creationTicket);
-+ 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;
-+}
++void
++grub_Tss2_MU_TPM2B_NONCE_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPM2B_NONCE* nonce);
+
-+TPM_RC
-+TPM2_EvictControl (const TPMI_RH_PROVISION auth,
-+ const TPMI_DH_OBJECT objectHandle,
-+ const TPMS_AUTH_COMMAND *authCommand,
-+ const TPMI_DH_PERSISTENT persistentHandle,
-+ TPMS_AUTH_RESPONSE *authResponse)
-+{
-+ 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;
-+ TPM_RC rc;
-+ grub_uint32_t parameterSize;
-+
-+ if (!authResponse)
-+ authResponse = &authResponseTmp;
-+
-+ grub_memset (authResponse, 0, sizeof (*authResponse));
-+
-+ /* Marshal */
-+ grub_tpm2_buffer_init (&in);
-+ grub_tpm2_buffer_pack_u32 (&in, auth);
-+ grub_tpm2_buffer_pack_u32 (&in, objectHandle);
-+ if (authCommand)
-+ grub_tpm2_mu_TPMS_AUTH_COMMAND_Marshal (&in, authCommand);
-+ grub_tpm2_buffer_pack_u32 (&in, persistentHandle);
-+ if (in.error)
-+ return TPM_RC_FAILURE;
-+
-+ /* Submit */
-+ grub_tpm2_buffer_init (&out);
-+ rc = grub_tpm2_submit_command (tag, TPM_CC_EvictControl, &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, ¶meterSize);
-+ grub_tpm2_mu_TPMS_AUTH_RESPONSE_Unmarshal(&out, authResponse);
-+ }
-+ if (out.error)
-+ return TPM_RC_FAILURE;
++void
++grub_Tss2_MU_TPM2B_DATA_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPM2B_DATA* data);
+
-+ return TPM_RC_SUCCESS;
-+}
++void
++grub_Tss2_MU_TPMS_CREATION_DATA_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMS_CREATION_DATA *data);
+
-+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, ¶m_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;
-+}
++void
++grub_Tss2_MU_TPM2B_CREATION_DATA_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPM2B_CREATION_DATA *data);
+
-+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, ¶m_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;
-+}
++void
++grub_Tss2_MU_TPM2B_PRIVATE_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPM2B_PRIVATE* private);
+
-+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, ¶m_size);
-+ grub_tpm2_mu_TPMS_AUTH_RESPONSE_Unmarshal (&out, authResponse);
-+ }
-+ if (out.error)
-+ return TPM_RC_FAILURE;
++void
++grub_Tss2_MU_TPM2B_SENSITIVE_DATA_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPM2B_SENSITIVE_DATA *data);
+
-+ return TPM_RC_SUCCESS;
-+}
++void
++grub_Tss2_MU_TPM2B_PUBLIC_KEY_RSA_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPM2B_PUBLIC_KEY_RSA *rsa);
+
-+TPM_RC
-+TPM2_TestParms (const TPMT_PUBLIC_PARMS *parms,
-+ const TPMS_AUTH_COMMAND* authCommand)
-+{
-+ TPM_RC rc;
-+ struct grub_tpm2_buffer in;
-+ struct grub_tpm2_buffer out;
-+ TPMI_ST_COMMAND_TAG tag = authCommand ? TPM_ST_SESSIONS : TPM_ST_NO_SESSIONS;
-+ TPM_RC responseCode;
-+
-+ if (!parms)
-+ return TPM_RC_VALUE;
-+
-+ /* Marshal */
-+ grub_tpm2_buffer_init (&in);
-+ grub_tpm2_mu_TPMT_PUBLIC_PARMS_Marshal (&in, parms);
-+ if (in.error)
-+ return TPM_RC_FAILURE;
-+
-+ /* Submit */
-+ grub_tpm2_buffer_init (&out);
-+ rc = grub_tpm2_submit_command (tag, TPM_CC_TestParms, &responseCode, &in,
-+ &out);
-+ if (rc != TPM_RC_SUCCESS)
-+ return rc;
-+ if (responseCode != TPM_RC_SUCCESS)
-+ return responseCode;
-+
-+ /* Unmarshal */
-+ if (out.error)
-+ return TPM_RC_FAILURE;
-+
-+ return TPM_RC_SUCCESS;
-+}
-
- ## include/grub/tpm2/buffer.h (new) ##
-@@
-+/*
-+ * GRUB -- GRand Unified Bootloader
-+ * Copyright (C) 2022 Microsoft Corporation
-+ *
-+ * GRUB is free software: you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation, either version 3 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * GRUB is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
-+ */
++void
++grub_Tss2_MU_TPM2B_ECC_PARAMETER_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPM2B_ECC_PARAMETER *param);
+
-+#ifndef GRUB_TPM2_BUFFER_HEADER
-+#define GRUB_TPM2_BUFFER_HEADER 1
++void
++grub_Tss2_MU_TPMA_OBJECT_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMA_OBJECT *p);
+
-+#include <grub/types.h>
++void
++grub_Tss2_MU_TPMS_SCHEME_HMAC_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMS_SCHEME_HMAC *p);
+
-+#define GRUB_TPM2_BUFFER_CAPACITY 4096
++void
++grub_Tss2_MU_TPMS_SCHEME_XOR_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMS_SCHEME_XOR *p);
+
-+struct grub_tpm2_buffer
-+{
-+ grub_uint8_t data[GRUB_TPM2_BUFFER_CAPACITY];
-+ grub_size_t size;
-+ grub_size_t offset;
-+ grub_size_t cap;
-+ int error;
-+};
-+typedef struct grub_tpm2_buffer *grub_tpm2_buffer_t;
++void
++grub_Tss2_MU_TPMU_SCHEME_KEYEDHASH_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMI_ALG_KEYEDHASH_SCHEME scheme,
++ TPMU_SCHEME_KEYEDHASH *p);
+
+void
-+grub_tpm2_buffer_init (grub_tpm2_buffer_t buffer);
++grub_Tss2_MU_TPMT_KEYEDHASH_SCHEME_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMT_KEYEDHASH_SCHEME *p);
+
+void
-+grub_tpm2_buffer_pack (grub_tpm2_buffer_t buffer, const void* data,
-+ grub_size_t size);
++grub_Tss2_MU_TPMS_KEYEDHASH_PARMS_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMS_KEYEDHASH_PARMS *p);
+
+void
-+grub_tpm2_buffer_pack_u8 (grub_tpm2_buffer_t buffer, grub_uint8_t value);
++grub_Tss2_MU_TPMU_SYM_KEY_BITS_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMI_ALG_SYM_OBJECT algorithm,
++ TPMU_SYM_KEY_BITS *p);
+
+void
-+grub_tpm2_buffer_pack_u16 (grub_tpm2_buffer_t buffer, grub_uint16_t value);
++grub_Tss2_MU_TPMU_SYM_MODE_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMI_ALG_SYM_OBJECT algorithm,
++ TPMU_SYM_MODE *p);
+
+void
-+grub_tpm2_buffer_pack_u32 (grub_tpm2_buffer_t buffer, grub_uint32_t value);
++grub_Tss2_MU_TPMT_SYM_DEF_OBJECT_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMT_SYM_DEF_OBJECT *p);
+
+void
-+grub_tpm2_buffer_unpack (grub_tpm2_buffer_t buffer, void* data,
-+ grub_size_t size);
++grub_Tss2_MU_TPMS_SYMCIPHER_PARMS_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMS_SYMCIPHER_PARMS *p);
+
+void
-+grub_tpm2_buffer_unpack_u8 (grub_tpm2_buffer_t buffer, grub_uint8_t* value);
++grub_Tss2_MU_TPMU_ASYM_SCHEME_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMI_ALG_RSA_DECRYPT scheme,
++ TPMU_ASYM_SCHEME *p);
+
+void
-+grub_tpm2_buffer_unpack_u16 (grub_tpm2_buffer_t buffer, grub_uint16_t* value);
++grub_Tss2_MU_TPMT_RSA_SCHEME_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMT_RSA_SCHEME *p);
+
+void
-+grub_tpm2_buffer_unpack_u32 (grub_tpm2_buffer_t buffer, grub_uint32_t* value);
++grub_Tss2_MU_TPMS_RSA_PARMS_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMS_RSA_PARMS *p);
+
-+#endif /* ! GRUB_TPM2_BUFFER_HEADER */
-
- ## include/grub/tpm2/internal/functions.h (new) ##
-@@
-+/*
-+ * GRUB -- GRand Unified Bootloader
-+ * Copyright (C) 2022 Microsoft Corporation
-+ *
-+ * GRUB is free software: you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation, either version 3 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * GRUB is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
-+ */
++void
++grub_Tss2_MU_TPMT_ECC_SCHEME_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMT_ECC_SCHEME *p);
++
++void
++grub_Tss2_MU_TPMU_KDF_SCHEME_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMI_ALG_KDF scheme,
++ TPMU_KDF_SCHEME *p);
++
++void
++grub_Tss2_MU_TPMT_KDF_SCHEME_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMT_KDF_SCHEME *p);
++
++void
++grub_Tss2_MU_TPMS_ECC_PARMS_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMS_ECC_PARMS *p);
++
++void
++grub_Tss2_MU_TPMU_PUBLIC_PARMS_Unmarshal (grub_tpm2_buffer_t buffer,
++ grub_uint32_t type,
++ TPMU_PUBLIC_PARMS *p);
++
++void
++grub_Tss2_MU_TPMS_ECC_POINT_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMS_ECC_POINT *p);
++
++void
++grub_Tss2_MU_TPMU_PUBLIC_ID_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMI_ALG_PUBLIC type,
++ TPMU_PUBLIC_ID *p);
+
-+#ifndef GRUB_TPM2_INTERNAL_FUNCTIONS_HEADER
-+#define GRUB_TPM2_INTERNAL_FUNCTIONS_HEADER 1
-+
-+#include <grub/tpm2/internal/structs.h>
-+
-+TPM_RC
-+TPM2_CreatePrimary (const TPMI_RH_HIERARCHY primaryHandle,
-+ const TPMS_AUTH_COMMAND *authCommand,
-+ const TPM2B_SENSITIVE_CREATE *inSensitive,
-+ const TPM2B_PUBLIC *inPublic,
-+ const TPM2B_DATA *outsideInfo,
-+ const TPML_PCR_SELECTION *creationPCR,
-+ TPM_HANDLE *objectHandle,
-+ TPM2B_PUBLIC *outPublic,
-+ TPM2B_CREATION_DATA *creationData,
-+ TPM2B_DIGEST *creationHash,
-+ TPMT_TK_CREATION *creationTicket,
-+ TPM2B_NAME *name,
-+ TPMS_AUTH_RESPONSE *authResponse);
-+
-+TPM_RC
-+TPM2_StartAuthSession (const TPMI_DH_OBJECT tpmKey,
-+ const TPMI_DH_ENTITY bind,
-+ const TPMS_AUTH_COMMAND *authCommand,
-+ const TPM2B_NONCE *nonceCaller,
-+ const TPM2B_ENCRYPTED_SECRET *encryptedSalt,
-+ const TPM_SE sessionType,
-+ const TPMT_SYM_DEF *symmetric,
-+ const TPMI_ALG_HASH authHash,
-+ TPMI_SH_AUTH_SESSION *sessionHandle,
-+ TPM2B_NONCE *nonceTpm,
-+ TPMS_AUTH_RESPONSE *authResponse);
-+
-+TPM_RC
-+TPM2_PolicyPCR (const TPMI_SH_POLICY policySession,
-+ const TPMS_AUTH_COMMAND *authCommand,
-+ const TPM2B_DIGEST *pcrDigest,
-+ const TPML_PCR_SELECTION *pcrs,
-+ TPMS_AUTH_RESPONSE *authResponse);
-+
-+TPM_RC
-+TPM2_ReadPublic (const TPMI_DH_OBJECT objectHandle,
-+ const TPMS_AUTH_COMMAND* authCommand,
-+ TPM2B_PUBLIC *outPublic);
-+
-+TPM_RC
-+TPM2_Load (const TPMI_DH_OBJECT parent_handle,
-+ const TPMS_AUTH_COMMAND *authCommand,
-+ const TPM2B_PRIVATE *inPrivate,
-+ const TPM2B_PUBLIC *inPublic,
-+ TPM_HANDLE *objectHandle,
-+ 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,
-+ TPM2B_SENSITIVE_DATA *outData,
-+ TPMS_AUTH_RESPONSE *authResponse);
-+
-+TPM_RC
-+TPM2_FlushContext (const TPMI_DH_CONTEXT handle);
-+
-+TPM_RC
-+TPM2_PCR_Read (const TPMS_AUTH_COMMAND *authCommand,
-+ const TPML_PCR_SELECTION *pcrSelectionIn,
-+ grub_uint32_t *pcrUpdateCounter,
-+ TPML_PCR_SELECTION *pcrSelectionOut,
-+ TPML_DIGEST *pcrValues,
-+ TPMS_AUTH_RESPONSE *authResponse);
-+
-+TPM_RC
-+TPM2_PolicyGetDigest (const TPMI_SH_POLICY policySession,
-+ const TPMS_AUTH_COMMAND *authCommand,
-+ TPM2B_DIGEST *policyDigest,
-+ TPMS_AUTH_RESPONSE *authResponse);
-+
-+TPM_RC
-+TPM2_Create (const TPMI_DH_OBJECT parentHandle,
-+ const TPMS_AUTH_COMMAND *authCommand,
-+ const TPM2B_SENSITIVE_CREATE *inSensitive,
-+ const TPM2B_PUBLIC *inPublic,
-+ const TPM2B_DATA *outsideInfo,
-+ const TPML_PCR_SELECTION *creationPCR,
-+ TPM2B_PRIVATE *outPrivate,
-+ TPM2B_PUBLIC *outPublic,
-+ TPM2B_CREATION_DATA *creationData,
-+ TPM2B_DIGEST *creationHash,
-+ TPMT_TK_CREATION *creationTicket,
-+ TPMS_AUTH_RESPONSE *authResponse);
-+
-+TPM_RC
-+TPM2_EvictControl (const TPMI_RH_PROVISION auth,
-+ const TPMI_DH_OBJECT objectHandle,
-+ const TPMS_AUTH_COMMAND *authCommand,
-+ const TPMI_DH_PERSISTENT persistentHandle,
-+ 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);
-+
-+TPM_RC
-+TPM2_TestParms (const TPMT_PUBLIC_PARMS *parms,
-+ const TPMS_AUTH_COMMAND* authCommand);
-+
-+#endif /* ! GRUB_TPM2_INTERNAL_FUNCTIONS_HEADER */
++void
++grub_Tss2_MU_TPMT_PUBLIC_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMT_PUBLIC *p);
++
++void
++grub_Tss2_MU_TPM2B_PUBLIC_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPM2B_PUBLIC *p);
++
++void
++grub_Tss2_MU_TPMS_NV_PUBLIC_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMS_NV_PUBLIC *p);
++
++void
++grub_Tss2_MU_TPM2B_NV_PUBLIC_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPM2B_NV_PUBLIC *p);
++
++void
++grub_Tss2_MU_TPM2B_NAME_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPM2B_NAME *n);
++
++void
++grub_Tss2_MU_TPMS_TAGGED_PROPERTY_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMS_TAGGED_PROPERTY* property);
++
++void
++grub_Tss2_MU_TPMT_TK_CREATION_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMT_TK_CREATION *p);
++
++void
++grub_Tss2_MU_TPMT_TK_HASHCHECK_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMT_TK_HASHCHECK *p);
++
++void
++grub_Tss2_MU_TPMT_TK_VERIFIED_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMT_TK_VERIFIED *p);
++
++void
++grub_Tss2_MU_TPMS_PCR_SELECTION_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMS_PCR_SELECTION* pcrSelection);
++
++void
++grub_Tss2_MU_TPML_PCR_SELECTION_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPML_PCR_SELECTION* pcrSelection);
++
++void
++grub_Tss2_MU_TPML_DIGEST_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPML_DIGEST* digest);
++
++void
++grub_Tss2_MU_TPMS_SIGNATURE_RSA_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMS_SIGNATURE_RSA *p);
++
++void
++grub_Tss2_MU_TPMS_SIGNATURE_ECC_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMS_SIGNATURE_ECC *p);
++
++void
++grub_Tss2_MU_TPMU_HA_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMI_ALG_HASH hashAlg,
++ TPMU_HA *p);
++
++void
++grub_Tss2_MU_TPMT_HA_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMT_HA *p);
++
++void
++grub_Tss2_MU_TPMU_SIGNATURE_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMI_ALG_SIG_SCHEME sigAlg,
++ TPMU_SIGNATURE *p);
++
++void
++grub_Tss2_MU_TPMT_SIGNATURE_Unmarshal (grub_tpm2_buffer_t buffer,
++ TPMT_SIGNATURE *p);
++
++#endif /* ! GRUB_TPM2_MU_HEADER */
- ## include/grub/tpm2/internal/structs.h (new) ##
+ ## grub-core/lib/tss2/tss2_structs.h (new) ##
@@
+/*
+ * GRUB -- GRand Unified Bootloader
++ * Copyright (C) 2024 Free Software Foundation, Inc.
+ * Copyright (C) 2022 Microsoft Corporation
+ *
+ * GRUB is free software: you can redistribute it and/or modify
@@ include/grub/tpm2/internal/structs.h (new)
+#ifndef GRUB_TPM2_INTERNAL_STRUCTS_HEADER
+#define GRUB_TPM2_INTERNAL_STRUCTS_HEADER 1
+
-+#include <grub/tpm2/internal/types.h>
++#include <tss2_types.h>
+
+/* TPMS_TAGGED_PROPERTY Structure */
+struct TPMS_TAGGED_PROPERTY
@@ include/grub/tpm2/internal/structs.h (new)
+/* TPMA_SESSION Structure */
+struct TPMA_SESSION
+{
-+ unsigned int continueSession:1;
-+ unsigned int auditExclusive:1;
-+ unsigned int auditReset:1;
-+ unsigned int reserved1:2;
-+ unsigned int decrypt:1;
-+ unsigned int encrypt:1;
-+ unsigned int audit:1;
-+ unsigned int reserved:24;
++ grub_uint8_t continueSession:1;
++ grub_uint8_t auditExclusive:1;
++ grub_uint8_t auditReset:1;
++ grub_uint8_t reserved:2;
++ grub_uint8_t decrypt:1;
++ grub_uint8_t encrypt:1;
++ grub_uint8_t audit:1;
+};
+typedef struct TPMA_SESSION TPMA_SESSION;
+
@@ include/grub/tpm2/internal/structs.h (new)
+/* TPMA_OBJECT Structure */
+struct TPMA_OBJECT
+{
-+ unsigned int reserved1:1;
-+ unsigned int fixedTPM:1;
-+ unsigned int stClear:1;
-+ unsigned int reserved2:1;
-+ unsigned int fixedParent:1;
-+ unsigned int sensitiveDataOrigin:1;
-+ unsigned int userWithAuth:1;
-+ unsigned int adminWithPolicy:1;
-+ unsigned int reserved3:2;
-+ unsigned int noDA:1;
-+ unsigned int encryptedDuplication:1;
-+ unsigned int reserved4:4;
-+ unsigned int restricted:1;
-+ unsigned int decrypt:1;
-+ unsigned int sign:1;
-+ unsigned int reserved5:13;
++ grub_uint32_t reserved1:1;
++ grub_uint32_t fixedTPM:1;
++ grub_uint32_t stClear:1;
++ grub_uint32_t reserved2:1;
++ grub_uint32_t fixedParent:1;
++ grub_uint32_t sensitiveDataOrigin:1;
++ grub_uint32_t userWithAuth:1;
++ grub_uint32_t adminWithPolicy:1;
++ grub_uint32_t reserved3:2;
++ grub_uint32_t noDA:1;
++ grub_uint32_t encryptedDuplication:1;
++ grub_uint32_t reserved4:4;
++ grub_uint32_t restricted:1;
++ grub_uint32_t decrypt:1;
++ grub_uint32_t sign:1;
++ grub_uint32_t reserved5:13;
+};
+typedef struct TPMA_OBJECT TPMA_OBJECT;
+
@@ include/grub/tpm2/internal/structs.h (new)
+/* TPMA_LOCALITY Structure */
+struct TPMA_LOCALITY
+{
-+ unsigned char TPM_LOC_ZERO:1;
-+ unsigned char TPM_LOC_ONE:1;
-+ unsigned char TPM_LOC_TWO:1;
-+ unsigned char TPM_LOC_THREE:1;
-+ unsigned char TPM_LOC_FOUR:1;
-+ unsigned char Extended:3;
++ grub_uint8_t TPM_LOC_ZERO:1;
++ grub_uint8_t TPM_LOC_ONE:1;
++ grub_uint8_t TPM_LOC_TWO:1;
++ grub_uint8_t TPM_LOC_THREE:1;
++ grub_uint8_t TPM_LOC_FOUR:1;
++ grub_uint8_t Extended:3;
+};
+typedef struct TPMA_LOCALITY TPMA_LOCALITY;
+
@@ include/grub/tpm2/internal/structs.h (new)
+
+#endif /* ! GRUB_TPM2_INTERNAL_STRUCTS_HEADER */
- ## include/grub/tpm2/internal/types.h (new) ##
+ ## grub-core/lib/tss2/tss2_types.h (new) ##
@@
+/*
+ * GRUB -- GRand Unified Bootloader
++ * Copyright (C) 2024 Free Software Foundation, Inc.
+ * Copyright (C) 2022 Microsoft Corporation
+ *
+ * GRUB is free software: you can redistribute it and/or modify
@@ include/grub/tpm2/internal/types.h (new)
+typedef TPM_HANDLE TPMI_DH_PERSISTENT;
+
+#endif /* ! GRUB_TPM2_INTERNAL_TYPES_HEADER */
-
- ## include/grub/tpm2/mu.h (new) ##
-@@
-+/*
-+ * GRUB -- GRand Unified Bootloader
-+ * Copyright (C) 2022 Microsoft Corporation
-+ *
-+ * GRUB is free software: you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation, either version 3 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * GRUB is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
-+ */
-+
-+#ifndef GRUB_TPM2_MU_HEADER
-+#define GRUB_TPM2_MU_HEADER 1
-+
-+#include <grub/tpm2/buffer.h>
-+#include <grub/tpm2/tpm2.h>
-+
-+void
-+grub_tpm2_mu_TPMS_AUTH_COMMAND_Marshal (grub_tpm2_buffer_t buffer,
-+ const TPMS_AUTH_COMMAND* authCommand);
-+
-+void
-+grub_tpm2_mu_TPM2B_Marshal (grub_tpm2_buffer_t buffer,
-+ const grub_uint16_t size,
-+ const grub_uint8_t* b);
-+
-+void
-+grub_tpm2_mu_TPMU_SYM_KEY_BITS_Marshal (grub_tpm2_buffer_t buffer,
-+ const TPMI_ALG_SYM_OBJECT algorithm,
-+ const TPMU_SYM_KEY_BITS *p);
-+
-+void
-+grub_tpm2_mu_TPMU_SYM_MODE_Marshal (grub_tpm2_buffer_t buffer,
-+ const TPMI_ALG_SYM_OBJECT algorithm,
-+ const TPMU_SYM_MODE *p);
-+
-+void
-+grub_tpm2_mu_TPMT_SYM_DEF_Marshal (grub_tpm2_buffer_t buffer,
-+ const TPMT_SYM_DEF *p);
-+
-+void
-+grub_tpm2_mu_TPMS_PCR_SELECTION_Marshal (grub_tpm2_buffer_t buffer,
-+ const TPMS_PCR_SELECTION* pcrSelection);
-+
-+void
-+grub_tpm2_mu_TPML_PCR_SELECTION_Marshal (grub_tpm2_buffer_t buffer,
-+ const TPML_PCR_SELECTION* pcrSelection);
-+
-+void
-+grub_tpm2_mu_TPMA_OBJECT_Marshal (grub_tpm2_buffer_t buffer,
-+ const TPMA_OBJECT *p);
-+
-+void
-+grub_tpm2_mu_TPMS_SCHEME_XOR_Marshal (grub_tpm2_buffer_t buffer,
-+ const TPMS_SCHEME_XOR *p);
-+
-+void
-+grub_tpm2_mu_TPMS_SCHEME_HMAC_Marshal (grub_tpm2_buffer_t buffer,
-+ const TPMS_SCHEME_HMAC *p);
-+
-+void
-+grub_tpm2_mu_TPMU_SCHEME_KEYEDHASH_Marshal (grub_tpm2_buffer_t buffer,
-+ const TPMI_ALG_KEYEDHASH_SCHEME scheme,
-+ const TPMU_SCHEME_KEYEDHASH *p);
-+
-+void
-+grub_tpm2_mu_TPMT_KEYEDHASH_SCHEME_Marshal (grub_tpm2_buffer_t buffer,
-+ const TPMT_KEYEDHASH_SCHEME *p);
-+
-+void
-+grub_tpm2_mu_TPMS_KEYEDHASH_PARMS_Marshal (grub_tpm2_buffer_t buffer,
-+ const TPMS_KEYEDHASH_PARMS *p);
-+
-+void
-+grub_tpm2_mu_TPMT_SYM_DEF_OBJECT_Marshal (grub_tpm2_buffer_t buffer,
-+ const TPMT_SYM_DEF_OBJECT *p);
-+
-+void
-+grub_tpm2_mu_TPMU_ASYM_SCHEME_Marshal (grub_tpm2_buffer_t buffer,
-+ const TPMI_ALG_RSA_DECRYPT scheme,
-+ const TPMU_ASYM_SCHEME *p);
-+
-+void
-+grub_tpm2_mu_TPMT_RSA_SCHEME_Marshal (grub_tpm2_buffer_t buffer,
-+ const TPMT_RSA_SCHEME *p);
-+
-+void
-+grub_tpm2_mu_TPMS_RSA_PARMS_Marshal (grub_tpm2_buffer_t buffer,
-+ const TPMS_RSA_PARMS *p);
-+
-+void
-+grub_tpm2_mu_TPMS_SYMCIPHER_PARMS_Marshal (grub_tpm2_buffer_t buffer,
-+ const TPMS_SYMCIPHER_PARMS *p);
-+
-+void
-+grub_tpm2_mu_TPMT_ECC_SCHEME_Marshal (grub_tpm2_buffer_t buffer,
-+ const TPMT_ECC_SCHEME *p);
-+
-+void
-+grub_tpm2_mu_TPMU_KDF_SCHEME_Marshal (grub_tpm2_buffer_t buffer,
-+ const TPMI_ALG_KDF scheme,
-+ const TPMU_KDF_SCHEME *p);
-+
-+void
-+grub_tpm2_mu_TPMT_KDF_SCHEME_Marshal (grub_tpm2_buffer_t buffer,
-+ const TPMT_KDF_SCHEME *p);
-+
-+void
-+grub_tpm2_mu_TPMS_ECC_PARMS_Marshal (grub_tpm2_buffer_t buffer,
-+ const TPMS_ECC_PARMS *p);
-+
-+void
-+grub_tpm2_mu_TPMU_PUBLIC_PARMS_Marshal (grub_tpm2_buffer_t buffer,
-+ const grub_uint32_t type,
-+ const TPMU_PUBLIC_PARMS *p);
-+
-+void
-+grub_tpm2_mu_TPMS_ECC_POINT_Marshal (grub_tpm2_buffer_t buffer,
-+ const TPMS_ECC_POINT *p);
-+
-+void
-+grub_tpm2_mu_TPMU_PUBLIC_ID_Marshal (grub_tpm2_buffer_t buffer,
-+ const TPMI_ALG_PUBLIC type,
-+ const TPMU_PUBLIC_ID *p);
-+
-+void
-+grub_tpm2_mu_TPMT_PUBLIC_PARMS_Marshal (grub_tpm2_buffer_t buffer,
-+ const TPMT_PUBLIC_PARMS *p);
-+
-+void
-+grub_tpm2_mu_TPMT_PUBLIC_Marshal (grub_tpm2_buffer_t buffer,
-+ const TPMT_PUBLIC *p);
-+
-+void
-+grub_tpm2_mu_TPM2B_PUBLIC_Marshal (grub_tpm2_buffer_t buffer,
-+ const TPM2B_PUBLIC *p);1,823 lines not shown · raw message
289 lines not shown · raw message
Part of this message is not shown here. View the raw message.
PATCH v18 1/25 posix_wrap: tweaks in preparation for libtasn1
From: Daniel Axtens <[email protected]>
- Define SIZEOF_UNSIGNED_LONG_INT, it's the same as SIZEOF_UNSIGNED_LONG.
- Define WORD_BIT, the size in bits of an int. This is a defined in the Single Unix Specification and in gnulib's limits.h. gnulib assumes it's 32 bits on all our platforms, including 64 bit platforms, so we also use that value.
- Provide strto[u]l[l] preprocessor macros that resolve to grub_strto[u]l[l]. To avoid gcrypt redefining strtoul, we also define HAVE_STRTOUL here.
- Implement c-ctype.h and the functions defined in the header.
- Implement strncat in string.h.
--- grub-core/lib/posix_wrap/c-ctype.h | 114 +++++++++++++++++++++++++++ grub-core/lib/posix_wrap/limits.h | 1 + grub-core/lib/posix_wrap/stdlib.h | 8 ++ grub-core/lib/posix_wrap/string.h | 21 +++++ grub-core/lib/posix_wrap/sys/types.h | 1 + 5 files changed, 145 insertions(+) create mode 100644 grub-core/lib/posix_wrap/c-ctype.h
grub-core/lib/posix_wrap/c-ctype.h new file +114 -0
@@ -0,0 +1,114 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 Free Software Foundation, Inc. +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef GRUB_POSIX_C_CTYPE_H +#define GRUB_POSIX_C_CTYPE_H 1 + +#include <grub/misc.h> + +static inline bool +c_isspace (int c) +{ +return !!grub_isspace (c); +} + +static inline bool +c_isdigit (int c) +{ +return !!grub_isdigit (c); +} + +static inline bool +c_islower (int c) +{ +return !!grub_islower (c); +} + +static inline bool +c_isascii (int c) +{ +return !(c & ~0x7f ); +} + +static inline bool +c_isupper (int c) +{ +return !!grub_isupper (c); +} + +static inline bool +c_isxdigit (int c) +{ +return !!grub_isxdigit (c); +} + +static inline bool +c_isprint (int c) +{ +return !!grub_isprint (c); +} + +static inline bool +c_iscntrl (int c) +{ +return !grub_isprint (c); +} + +static inline bool +c_isgraph (int c) +{ +return grub_isprint (c) && !grub_isspace (c); +} + +static inline bool +c_isalnum (int c) +{ +return grub_isalpha (c) ||grub_isdigit (c); +} + +static inline bool +c_ispunct (int c) +{ +return grub_isprint (c) && !grub_isspace (c) && !c_isalnum (c); +} + +static inline bool +c_isalpha (int c) +{ +return !!grub_isalpha (c); +} + +static inline bool +c_isblank (int c) +{ +return c ==' ' || c =='\t' ; +} + +static inline int +c_tolower (int c) +{ +return grub_tolower (c); +} + +static inline int +c_toupper (int c) +{ +return grub_toupper (c); +} + +#endif
grub-core/lib/posix_wrap/limits.h +1 -0
@@ -41,5 +41,6 @@#define LONG_MAX GRUB_LONG_MAX#define CHAR_BIT 8 +#define WORD_BIT 32#endif
grub-core/lib/posix_wrap/stdlib.h +8 -0
@@ -64,4 +64,12 @@ abort (void) grub_abort (); } +#define strtol grub_strtol + +/* for libgcrypt */ +#define HAVE_STRTOUL +#define strtoul grub_strtoul + +#define strtoull grub_strtoull +#endif
grub-core/lib/posix_wrap/string.h +21 -0
@@ -84,6 +84,27 @@ memchr (const void *s, int c, grub_size_t n)return grub_memchr (s, c, n); } +static inline char * +strncat (char *dest,const char *src,grub_size_t n) +{ +const char *end; +char *str = dest; +grub_size_t src_len; + + dest +=grub_strlen (dest); + + end =grub_memchr (src,'\0' , n); +if (end !=NULL ) + src_len = (grub_size_t) (end - src); +else + src_len = n; + + dest[src_len] ='\0' ; +grub_memcpy (dest, src, src_len); + +return str; +} +#define memcmp grub_memcmp#define memcpy grub_memcpy#define memmove grub_memmove
grub-core/lib/posix_wrap/sys/types.h +1 -0
@@ -50,6 +50,7 @@ typedef grub_uint8_t byte;typedef grub_addr_t uintptr_t ;#define SIZEOF_UNSIGNED_LONG GRUB_CPU_SIZEOF_LONG +#define SIZEOF_UNSIGNED_LONG_INT GRUB_CPU_SIZEOF_LONG#define SIZEOF_UNSIGNED_INT 4#define SIZEOF_UNSIGNED_LONG_LONG 8#define SIZEOF_UNSIGNED_SHORT 2
Signature · 7 lines
2.35.3 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v18 2/25 libtasn1: import libtasn1-4.19.0
In reply to Gary Lin via Grub-develFrom: Daniel Axtens <[email protected]>
Import a very trimmed-down set of libtasn1 files:
curl -L -O https://ftp.gnu.org/gnu/libtasn1/libtasn1-4.19.0.tar.gz
tar xf libtasn1-4.19.0.tar.gz
rm -rf grub-core/lib/libtasn1/
mkdir -p grub-core/lib/libtasn1/lib/
mkdir -p grub-core/lib/libtasn1/tests/
cp libtasn1-4.19.0/{README.md,COPYING} grub-core/lib/libtasn1/
cp libtasn1-4.19.0/lib/{coding.c,decoding.c,element.c,element.h,errors.c,gstr.c,gstr.h,int.h,parser_aux.c,parser_aux.h,structure.c,structure.h} grub-core/libtasn1/lib/
cp libtasn1-4.19.0/lib/includes/libtasn1.h grub-core/lib/libtasn1/
cp libtasn1-4.19.0/tests/{CVE-2018-1000654-1_asn1_tab.h,CVE-2018-1000654-2_asn1_tab.h,CVE-2018-1000654.c,object-id-decoding.c,object-id-encoding.c,octet-string.c,reproducers.c,Test_overflow.c,Test_simple.c,Test_strings.c} grub-core/lib/libtasn1/tests rm -rf libtasn1-4.19.0*
--- grub-core/lib/libtasn1/COPYING | 16 + grub-core/lib/libtasn1/README.md | 98 + grub-core/lib/libtasn1/lib/coding.c | 1425 ++++++++++ grub-core/lib/libtasn1/lib/decoding.c | 2501 +++++++++++++++++ grub-core/lib/libtasn1/lib/element.c | 1109 ++++++++ grub-core/lib/libtasn1/lib/element.h | 42 + grub-core/lib/libtasn1/lib/errors.c | 100 + grub-core/lib/libtasn1/lib/gstr.c | 74 + grub-core/lib/libtasn1/lib/gstr.h | 50 + grub-core/lib/libtasn1/lib/int.h | 221 ++ grub-core/lib/libtasn1/lib/parser_aux.c | 1178 ++++++++ grub-core/lib/libtasn1/lib/parser_aux.h | 172 ++ grub-core/lib/libtasn1/lib/structure.c | 1225 ++++++++ grub-core/lib/libtasn1/lib/structure.h | 46 + grub-core/lib/libtasn1/libtasn1.h | 643 +++++ .../tests/CVE-2018-1000654-1_asn1_tab.h | 32 + .../tests/CVE-2018-1000654-2_asn1_tab.h | 36 + .../lib/libtasn1/tests/CVE-2018-1000654.c | 72 + grub-core/lib/libtasn1/tests/Test_overflow.c | 168 ++ grub-core/lib/libtasn1/tests/Test_simple.c | 226 ++ grub-core/lib/libtasn1/tests/Test_strings.c | 156 + .../lib/libtasn1/tests/object-id-decoding.c | 121 + .../lib/libtasn1/tests/object-id-encoding.c | 133 + grub-core/lib/libtasn1/tests/octet-string.c | 230 ++ grub-core/lib/libtasn1/tests/reproducers.c | 90 + 25 files changed, 10164 insertions(+) create mode 100644 grub-core/lib/libtasn1/COPYING create mode 100644 grub-core/lib/libtasn1/README.md create mode 100644 grub-core/lib/libtasn1/lib/coding.c create mode 100644 grub-core/lib/libtasn1/lib/decoding.c create mode 100644 grub-core/lib/libtasn1/lib/element.c create mode 100644 grub-core/lib/libtasn1/lib/element.h create mode 100644 grub-core/lib/libtasn1/lib/errors.c create mode 100644 grub-core/lib/libtasn1/lib/gstr.c create mode 100644 grub-core/lib/libtasn1/lib/gstr.h create mode 100644 grub-core/lib/libtasn1/lib/int.h create mode 100644 grub-core/lib/libtasn1/lib/parser_aux.c create mode 100644 grub-core/lib/libtasn1/lib/parser_aux.h create mode 100644 grub-core/lib/libtasn1/lib/structure.c create mode 100644 grub-core/lib/libtasn1/lib/structure.h create mode 100644 grub-core/lib/libtasn1/libtasn1.h create mode 100644 grub-core/lib/libtasn1/tests/CVE-2018-1000654-1_asn1_tab.h create mode 100644 grub-core/lib/libtasn1/tests/CVE-2018-1000654-2_asn1_tab.h create mode 100644 grub-core/lib/libtasn1/tests/CVE-2018-1000654.c create mode 100644 grub-core/lib/libtasn1/tests/Test_overflow.c create mode 100644 grub-core/lib/libtasn1/tests/Test_simple.c create mode 100644 grub-core/lib/libtasn1/tests/Test_strings.c create mode 100644 grub-core/lib/libtasn1/tests/object-id-decoding.c create mode 100644 grub-core/lib/libtasn1/tests/object-id-encoding.c create mode 100644 grub-core/lib/libtasn1/tests/octet-string.c create mode 100644 grub-core/lib/libtasn1/tests/reproducers.c
grub-core/lib/libtasn1/COPYING new file +16 -0
@@ -0,0 +1,16 @@ +LICENSING +========= + +The libtasn1 library is released under the GNU Lesser General Public +License (LGPL) version 2.1 or later; see [COPYING.LESSER](doc/COPYING.LESSER) +for the license terms. + +The GNU LGPL applies to the main libtasn1 library, while the +included applications library are under the GNU GPL version 3. +The libtasn1 library is located in the lib directory, while the applications +in src/. + +The documentation in doc/ is under the GNU FDL license 1.3. + +For any copyright year range specified as YYYY-ZZZZ in this package +note that the range specifies every single year in that closed interval.
grub-core/lib/libtasn1/README.md new file +98 -0
98 lines not on this page · raw message
grub-core/lib/libtasn1/lib/coding.c new file +1425 -0
1,425 lines not on this page · raw message
grub-core/lib/libtasn1/lib/decoding.c new file +2501 -0
1,461 lines not on this page · raw message
grub-core/lib/libtasn1/lib/element.c new file +1109 -0
1,109 lines not on this page · raw message
grub-core/lib/libtasn1/lib/element.h new file +42 -0
42 lines not on this page · raw message
grub-core/lib/libtasn1/lib/errors.c new file +100 -0
100 lines not on this page · raw message
grub-core/lib/libtasn1/lib/gstr.c new file +74 -0
74 lines not on this page · raw message
grub-core/lib/libtasn1/lib/gstr.h new file +50 -0
50 lines not on this page · raw message
grub-core/lib/libtasn1/lib/int.h new file +221 -0
221 lines not on this page · raw message
grub-core/lib/libtasn1/lib/parser_aux.c new file +1178 -0
1,178 lines not on this page · raw message
grub-core/lib/libtasn1/lib/parser_aux.h new file +172 -0
172 lines not on this page · raw message
grub-core/lib/libtasn1/lib/structure.c new file +1225 -0
1,225 lines not on this page · raw message
grub-core/lib/libtasn1/lib/structure.h new file +46 -0
46 lines not on this page · raw message
grub-core/lib/libtasn1/libtasn1.h new file +643 -0
643 lines not on this page · raw message
grub-core/lib/libtasn1/tests/CVE-2018-1000654-1_asn1_tab.h new file +32 -0
Lines of this file are not shown. View the raw message.
grub-core/lib/libtasn1/tests/CVE-2018-1000654-2_asn1_tab.h new file +36 -0
Lines of this file are not shown. View the raw message.
grub-core/lib/libtasn1/tests/CVE-2018-1000654.c new file +72 -0
72 lines not on this page · raw message
grub-core/lib/libtasn1/tests/Test_overflow.c new file +168 -0
168 lines not on this page · raw message
grub-core/lib/libtasn1/tests/Test_simple.c new file +226 -0
226 lines not on this page · raw message
grub-core/lib/libtasn1/tests/Test_strings.c new file +156 -0
156 lines not on this page · raw message
grub-core/lib/libtasn1/tests/object-id-decoding.c new file +121 -0
121 lines not on this page · raw message
grub-core/lib/libtasn1/tests/object-id-encoding.c new file +133 -0
133 lines not on this page · raw message
grub-core/lib/libtasn1/tests/octet-string.c new file +230 -0
230 lines not on this page · raw message
grub-core/lib/libtasn1/tests/reproducers.c new file +90 -0
90 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 7 lines
2.35.3 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Part of the diff is not shown here. View the raw message.
PATCH v18 3/25 libtasn1: disable code not needed in grub
In reply to Gary Lin via Grub-develWe don't expect to be able to write ASN.1, only read it, so we can disable some code.
Do that with #if 0/#endif, rather than deletion. This means that the difference between upstream and grub is smaller, which should make updating libtasn1 easier in the future.
With these exclusions we also avoid the need for minmax.h, which is convenient because it means we don't have to import it from gnulib.
--- ...asn1-disable-code-not-needed-in-grub.patch | 319 ++++++++++++++++++ 1 file changed, 319 insertions(+) create mode 100644 grub-core/lib/libtasn1-patches/0001-libtasn1-disable-code-not-needed-in-grub.patch
grub-core/lib/libtasn1-patches/0001-libtasn1-disable-code-not-needed-in-grub.patch new file +319 -0
@@ -0,0 +1,319 @@ +From 6b61d48782dc67bed72af70aa5db5b9cb1b4f1d0 Mon Sep 17 00:00:00 2001 +From: Daniel Axtens <[email protected]> +Date: Fri, 1 May 2020 17:12:23 +1000 +Subject: [PATCH 1/6] libtasn1: disable code not needed in grub + +We don't expect to be able to write ASN.1, only read it, +so we can disable some code. + +Do that with #if 0/#endif, rather than deletion. This means +that the difference between upstream and grub is smaller, +which should make updating libtasn1 easier in the future. + +With these exclusions we also avoid the need for minmax.h, +which is convenient because it means we don't have to +import it from gnulib. + +Signed-off-by: Daniel Axtens <[email protected]> +Signed-off-by: Gary Lin <[email protected]> +--- + grub-core/lib/libtasn1-grub/lib/coding.c | 12 ++++++++++-- + grub-core/lib/libtasn1-grub/lib/decoding.c | 2 ++ + grub-core/lib/libtasn1-grub/lib/element.c | 6 +++--- + grub-core/lib/libtasn1-grub/lib/errors.c | 3 +++ + grub-core/lib/libtasn1-grub/lib/structure.c | 10 ++++++---- + grub-core/lib/libtasn1-grub/libtasn1.h | 15 +++++++++++++++ + 6 files changed, 39 insertions(+), 9 deletions(-) + +diff --git a/grub-core/lib/libtasn1-grub/lib/coding.c b/grub-core/lib/libtasn1-grub/lib/coding.c +index ea5bc370e..5d03bca9d 100644 +--- a/grub-core/lib/libtasn1-grub/lib/coding.c ++++ b/grub-core/lib/libtasn1-grub/lib/coding.c +@@ -30,11 +30,11 @@ + #include "parser_aux.h" + #include <gstr.h> + #include "element.h" +-#include "minmax.h" + #include <structure.h> + + #define MAX_TAG_LEN 16 + ++#if 0 /* GRUB SKIPPED IMPORTING */ + /******************************************************/ + /* Function : _asn1_error_description_value_not_found */ + /* Description: creates the ErrorDescription string */ +@@ -58,6 +58,7 @@ _asn1_error_description_value_not_found (asn1_node node, + Estrcat (ErrorDescription, "' not found"); + + } ++#endif + + /** + * asn1_length_der: +@@ -244,6 +245,7 @@ asn1_encode_simple_der (unsigned int etype, const unsigned char *str, + return ASN1_SUCCESS; + } + ++#if 0 /* GRUB SKIPPED IMPORTING */ + /******************************************************/ + /* Function : _asn1_time_der */ + /* Description: creates the DER coding for a TIME */ +@@ -278,7 +280,7 @@ _asn1_time_der (unsigned char *str, int str_len, unsigned char *der, + + return ASN1_SUCCESS; + } +- ++#endif + + /* + void +@@ -519,6 +521,7 @@ asn1_bit_der (const unsigned char *str, int bit_len, + } + + ++#if 0 /* GRUB SKIPPED IMPORTING */ + /******************************************************/ + /* Function : _asn1_complete_explicit_tag */ + /* Description: add the length coding to the EXPLICIT */ +@@ -595,6 +598,7 @@ _asn1_complete_explicit_tag (asn1_node node, unsigned char *der, + + return ASN1_SUCCESS; + } ++#endif + + const tag_and_class_st _asn1_tags[] = { + [ASN1_ETYPE_GENERALSTRING] = +@@ -647,6 +651,8 @@ const tag_and_class_st _asn1_tags[] = { + + unsigned int _asn1_tags_size = sizeof (_asn1_tags) / sizeof (_asn1_tags[0]); + ++ ++#if 0 /* GRUB SKIPPED IMPORTING */ + /******************************************************/ + /* Function : _asn1_insert_tag_der */ + /* Description: creates the DER coding of tags of one */ +@@ -1423,3 +1429,5 @@ error: + asn1_delete_structure (&node); + return err; + } ++ ++#endif +diff --git a/grub-core/lib/libtasn1-grub/lib/decoding.c b/grub-core/lib/libtasn1-grub/lib/decoding.c +index b9245c486..bf9cb13ac 100644 +--- a/grub-core/lib/libtasn1-grub/lib/decoding.c ++++ b/grub-core/lib/libtasn1-grub/lib/decoding.c +@@ -1620,6 +1620,7 @@ asn1_der_decoding (asn1_node * element, const void *ider, int ider_len, + return asn1_der_decoding2 (element, ider, &ider_len, 0, errorDescription); + } + ++#if 0 /* GRUB SKIPPED IMPORTING */ + /** + * asn1_der_decoding_element: + * @structure: pointer to an ASN1 structure +@@ -1650,6 +1651,7 @@ asn1_der_decoding_element (asn1_node * structure, const char *elementName, + { + return asn1_der_decoding (structure, ider, len, errorDescription); + } ++#endif + + /** + * asn1_der_decoding_startEnd: +diff --git a/grub-core/lib/libtasn1-grub/lib/element.c b/grub-core/lib/libtasn1-grub/lib/element.c +index d4c558e10..bc4c3c8d7 100644 +--- a/grub-core/lib/libtasn1-grub/lib/element.c ++++ b/grub-core/lib/libtasn1-grub/lib/element.c +@@ -118,7 +118,7 @@ _asn1_convert_integer (const unsigned char *value, unsigned char *value_out, + value_out[k2 - k] = val[k2]; + } + +-#if 0 ++#if 0 /* GRUB SKIPPED IMPORTING */ + printf ("_asn1_convert_integer: valueIn=%s, lenOut=%d", value, *len); + for (k = 0; k < SIZEOF_UNSIGNED_LONG_INT; k++) + printf (", vOut[%d]=%d", k, value_out[k]); +@@ -191,7 +191,7 @@ _asn1_append_sequence_set (asn1_node node, struct node_tail_cache_st *pcache) + return ASN1_SUCCESS; + } + +- ++#if 0 + /** + * asn1_write_value: + * @node_root: pointer to a structure +@@ -646,7 +646,7 @@ asn1_write_value (asn1_node node_root, const char *name, + + return ASN1_SUCCESS; + } +- ++#endif + + #define PUT_VALUE( ptr, ptr_size, data, data_size) \ + *len = data_size; \ +diff --git a/grub-core/lib/libtasn1-grub/lib/errors.c b/grub-core/lib/libtasn1-grub/lib/errors.c +index aef5dfe6f..2b2322152 100644 +--- a/grub-core/lib/libtasn1-grub/lib/errors.c ++++ b/grub-core/lib/libtasn1-grub/lib/errors.c +@@ -57,6 +57,8 @@ static const libtasn1_error_entry error_algorithms[] = { + {0, 0} + }; + ++ ++#if 0 /* GRUB SKIPPED IMPORTING */ + /** + * asn1_perror: + * @error: is an error returned by a libtasn1 function. +@@ -73,6 +75,7 @@ asn1_perror (int error) + const char *str = asn1_strerror (error); + fprintf (stderr, "LIBTASN1 ERROR: %s\n", str ? str : "(null)"); + } ++#endif + + /** + * asn1_strerror: +diff --git a/grub-core/lib/libtasn1-grub/lib/structure.c b/grub-core/lib/libtasn1-grub/lib/structure.c +index 512dd601f..f5a947d57 100644 +--- a/grub-core/lib/libtasn1-grub/lib/structure.c ++++ b/grub-core/lib/libtasn1-grub/lib/structure.c +@@ -76,7 +76,7 @@ _asn1_find_left (asn1_node_const node) + return node->left; + } + +- ++#if 0 /* GRUB SKIPPED IMPORTING */ + int + _asn1_create_static_structure (asn1_node_const pointer, + char *output_file_name, char *vector_name) +@@ -155,7 +155,7 @@ _asn1_create_static_structure (asn1_node_const pointer, + + return ASN1_SUCCESS; + } +- ++#endif + + /** + * asn1_array2tree: +@@ -721,7 +721,7 @@ asn1_create_element (asn1_node_const definitions, const char *source_name, + return res; + } + +- ++#if 0 /* GRUB SKIPPED IMPORTING */ + /** + * asn1_print_structure: + * @out: pointer to the output file (e.g. stdout). +@@ -1062,7 +1062,7 @@ asn1_print_structure (FILE * out, asn1_node_const structure, const char *name, + } + } + } +- ++#endif + + + /** +@@ -1158,6 +1158,7 @@ asn1_find_structure_from_oid (asn1_node_const definitions, + return NULL; /* ASN1_ELEMENT_NOT_FOUND; */ + } + ++#if 0 /* GRUB SKIPPED IMPORTING */ + /** + * asn1_copy_node: + * @dst: Destination asn1 node. +@@ -1207,6 +1208,7 @@ asn1_copy_node (asn1_node dst, const char *dst_name, + + return result; + } ++#endif + + /** + * asn1_dup_node: +diff --git a/grub-core/lib/libtasn1-grub/libtasn1.h b/grub-core/lib/libtasn1-grub/libtasn1.h +index 51cc7879f..058ab27b0 100644 +--- a/grub-core/lib/libtasn1-grub/libtasn1.h ++++ b/grub-core/lib/libtasn1-grub/libtasn1.h +@@ -318,6 +318,8 @@ extern "C" + /* Functions definitions */ + /***********************************/ + ++/* These functions are not used in grub and should not be referenced. */ ++# if 0 /* GRUB SKIPPED IMPORTING */ + extern ASN1_API int + asn1_parser2tree (const char *file, + asn1_node * definitions, char *error_desc); +@@ -326,14 +328,17 @@ extern "C" + asn1_parser2array (const char *inputFileName, + const char *outputFileName, + const char *vectorName, char *error_desc); ++# endif + + extern ASN1_API int + asn1_array2tree (const asn1_static_node * array, + asn1_node * definitions, char *errorDescription); + ++# if 0 /* GRUB SKIPPED IMPORTING */ + extern ASN1_API void + asn1_print_structure (FILE * out, asn1_node_const structure, + const char *name, int mode); ++# endif + + extern ASN1_API int + asn1_create_element (asn1_node_const definitions, +@@ -347,9 +352,11 @@ extern "C" + extern ASN1_API int + asn1_delete_element (asn1_node structure, const char *element_name); + ++# if 0 /* GRUB SKIPPED IMPORTING */ + extern ASN1_API int + asn1_write_value (asn1_node node_root, const char *name, + const void *ivalue, int len); ++# endif + + extern ASN1_API int + asn1_read_value (asn1_node_const root, const char *name, +@@ -366,9 +373,11 @@ extern "C" + asn1_number_of_elements (asn1_node_const element, const char *name, + int *num); + ++# if 0 /* GRUB SKIPPED IMPORTING */ + extern ASN1_API int + asn1_der_coding (asn1_node_const element, const char *name, + void *ider, int *len, char *ErrorDescription); ++# endif + + extern ASN1_API int + asn1_der_decoding2 (asn1_node * element, const void *ider, +@@ -379,6 +388,7 @@ extern "C" + asn1_der_decoding (asn1_node * element, const void *ider, + int ider_len, char *errorDescription); + ++# if 0 /* GRUB SKIPPED IMPORTING */ + /* Do not use. Use asn1_der_decoding() instead. */ + extern ASN1_API int + asn1_der_decoding_element (asn1_node * structure, +@@ -386,6 +396,7 @@ extern "C" + const void *ider, int len, + char *errorDescription) + _ASN1_GCC_ATTR_DEPRECATED; ++# endif + + extern ASN1_API int + asn1_der_decoding_startEnd (asn1_node element, +@@ -411,12 +422,16 @@ extern "C" + const char + *oidValue); + ++# if 0 /* GRUB SKIPPED IMPORTING */ + __LIBTASN1_PURE__ + extern ASN1_API const char *asn1_check_version (const char *req_version); ++# endif + + __LIBTASN1_PURE__ extern ASN1_API const char *asn1_strerror (int error); + ++# if 0 /* GRUB SKIPPED IMPORTING */ + extern ASN1_API void asn1_perror (int error); ++# endif + + # define ASN1_MAX_TAG_SIZE 4 + # define ASN1_MAX_LENGTH_SIZE 9 +-- +2.35.3 +
Signature · 7 lines
2.35.3 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v18 4/25 libtasn1: use bound-checked _asn1_str_cat()
In reply to Gary Lin via Grub-develRemove _asn1_strcat() and replace strcat() with the bound-checked _asn1_str_cat() except the one inside _asn1_str_cat(). That strcat is replaced with strcpy.
--- ...asn1-use-bound-checked-_asn1_str_cat.patch | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 grub-core/lib/libtasn1-patches/0002-libtasn1-use-bound-checked-_asn1_str_cat.patch
grub-core/lib/libtasn1-patches/0002-libtasn1-use-bound-checked-_asn1_str_cat.patch new file +85 -0
@@ -0,0 +1,85 @@ +From d87d8e78371e3afbdd876193295ab9e3f60c140b Mon Sep 17 00:00:00 2001 +From: Gary Lin <[email protected]> +Date: Tue, 25 Jun 2024 16:27:57 +0800 +Subject: [PATCH 2/6] libtasn1: use bound-checked _asn1_str_cat() + +Remove _asn1_strcat() and replace strcat() with the bound-checked +_asn1_str_cat() except the one inside _asn1_str_cat(). That strcat +is replaced with strcpy. + +Signed-off-by: Daniel Axtens <[email protected]> +Signed-off-by: Gary Lin <[email protected]> +--- + grub-core/lib/libtasn1-grub/lib/decoding.c | 8 ++++---- + grub-core/lib/libtasn1-grub/lib/element.c | 2 +- + grub-core/lib/libtasn1-grub/lib/gstr.c | 2 +- + grub-core/lib/libtasn1-grub/lib/int.h | 1 - + 4 files changed, 6 insertions(+), 7 deletions(-) + +diff --git a/grub-core/lib/libtasn1-grub/lib/decoding.c b/grub-core/lib/libtasn1-grub/lib/decoding.c +index bf9cb13ac..51859fe36 100644 +--- a/grub-core/lib/libtasn1-grub/lib/decoding.c ++++ b/grub-core/lib/libtasn1-grub/lib/decoding.c +@@ -2016,8 +2016,8 @@ asn1_expand_octet_string (asn1_node_const definitions, asn1_node * element, + (p2->type & CONST_ASSIGN)) + { + strcpy (name, definitions->name); +- strcat (name, "."); +- strcat (name, p2->name); ++ _asn1_str_cat (name, sizeof (name), "."); ++ _asn1_str_cat (name, sizeof (name), p2->name); + + len = sizeof (value); + result = asn1_read_value (definitions, name, value, &len); +@@ -2034,8 +2034,8 @@ asn1_expand_octet_string (asn1_node_const definitions, asn1_node * element, + if (p2) + { + strcpy (name, definitions->name); +- strcat (name, "."); +- strcat (name, p2->name); ++ _asn1_str_cat (name, sizeof (name), "."); ++ _asn1_str_cat (name, sizeof (name), p2->name); + + result = asn1_create_element (definitions, name, &aux); + if (result == ASN1_SUCCESS) +diff --git a/grub-core/lib/libtasn1-grub/lib/element.c b/grub-core/lib/libtasn1-grub/lib/element.c +index bc4c3c8d7..8694fecb9 100644 +--- a/grub-core/lib/libtasn1-grub/lib/element.c ++++ b/grub-core/lib/libtasn1-grub/lib/element.c +@@ -688,7 +688,7 @@ asn1_write_value (asn1_node node_root, const char *name, + return ASN1_MEM_ERROR; \ + } else { \ + /* this strcat is checked */ \ +- if (ptr) _asn1_strcat (ptr, data); \ ++ if (ptr) _asn1_str_cat ((char *)ptr, ptr_size, (const char *)data); \ + } + + /** +diff --git a/grub-core/lib/libtasn1-grub/lib/gstr.c b/grub-core/lib/libtasn1-grub/lib/gstr.c +index eef419554..a9c16f5d3 100644 +--- a/grub-core/lib/libtasn1-grub/lib/gstr.c ++++ b/grub-core/lib/libtasn1-grub/lib/gstr.c +@@ -36,7 +36,7 @@ _asn1_str_cat (char *dest, size_t dest_tot_size, const char *src) + + if (dest_tot_size - dest_size > str_size) + { +- strcat (dest, src); ++ strcpy (dest + dest_size, src); + } + else + { +diff --git a/grub-core/lib/libtasn1-grub/lib/int.h b/grub-core/lib/libtasn1-grub/lib/int.h +index d94d51c8c..cadd80df6 100644 +--- a/grub-core/lib/libtasn1-grub/lib/int.h ++++ b/grub-core/lib/libtasn1-grub/lib/int.h +@@ -115,7 +115,6 @@ extern const tag_and_class_st _asn1_tags[]; + # define _asn1_strtoul(n,e,b) strtoul((const char *) n, e, b) + # define _asn1_strcmp(a,b) strcmp((const char *)a, (const char *)b) + # define _asn1_strcpy(a,b) strcpy((char *)a, (const char *)b) +-# define _asn1_strcat(a,b) strcat((char *)a, (const char *)b) + + # if SIZEOF_UNSIGNED_LONG_INT == 8 + # define _asn1_strtou64(n,e,b) strtoul((const char *) n, e, b) +-- +2.35.3 +
Signature · 7 lines
2.35.3 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 04/25] libtasn1: use bound-checked _asn1_str_cat()
Quoted 2 lines · Gary Lin via Grub-devel
Remove
_asn1_strcat()and replacestrcat()with the bound-checked_asn1_str_cat()except the one inside_asn1_str_cat(). That strcat
s/strcat/strcat()/
Quoted 1 line
is replaced with strcpy.
s/strcpy/strcpy()/
This commit message and one below miss explanation why these changes are needed. And I think this patch should be split into two...
Quoted 14 lines
Signed-off-by Daniel Axtens <[email protected]>Signed-off-by Gary Lin <[email protected]>--- ...asn1-use-bound-checked-_asn1_str_cat.patch | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 grub-core/lib/libtasn1-patches/0002-libtasn1-use-bound-checked-_asn1_str_cat.patchgrub-core/lib/libtasn1-patches/0002-libtasn1-use-bound-checked-_asn1_str_cat.patch new file +1
-0@@ -0,0 +1,85 @@ +From d87d8e78371e3afbdd876193295ab9e3f60c140b Mon Sep 17 00:00:00 2001
grub-core/lib/libtasn1-patches/0002-libtasn1-use-bound-checked-_asn1_str_cat.patch line 11
Quoted 10 lines
grub-core/lib/libtasn1-patches/0002-libtasn1-use-bound-checked-_asn1_str_cat.patch new file +10
-0+From: Gary Lin <[email protected]> +Date: Tue, 25 Jun 2024 16:27:57 +0800 +Subject: [PATCH 2/6] libtasn1: use bound-checked _asn1_str_cat() + +Remove _asn1_strcat() and replace strcat() with the bound-checked +_asn1_str_cat() except the one inside _asn1_str_cat(). That strcat +is replaced with strcpy. + +Signed-off-by: Daniel Axtens <[email protected]> +Signed-off-by: Gary Lin <[email protected]>
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 04/25] libtasn1: use bound-checked _asn1_str_cat()
Quoted 10 lines · Daniel Kiper
Quoted 2 lines · Gary Lin via Grub-devel
Remove
_asn1_strcat()and replacestrcat()with the bound-checked_asn1_str_cat()except the one inside_asn1_str_cat(). That strcats/strcat/strcat()/
Quoted 1 line
is replaced with strcpy.
s/strcpy/strcpy()/
Will fix them in the next version.
Quoted 2 lines
This commit message and one below miss explanation why these changes are needed.
Ok, I'll add more details about the change.
Quoted 1 line
And I think this patch should be split into two...
The changes are all about the same thing: replacing strcat() with a bound-checked function. What kind of splitting woud you suggest?
Gary Lin
Quoted 19 lines
Quoted 19 lines
Signed-off-by Daniel Axtens <[email protected]>Signed-off-by Gary Lin <[email protected]>--- ...asn1-use-bound-checked-_asn1_str_cat.patch | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 grub-core/lib/libtasn1-patches/0002-libtasn1-use-bound-checked-_asn1_str_cat.patchgrub-core/lib/libtasn1-patches/0002-libtasn1-use-bound-checked-_asn1_str_cat.patch new file +5
-0@@ -0,0 +1,85 @@ +From d87d8e78371e3afbdd876193295ab9e3f60c140b Mon Sep 17 00:00:00 2001 +From: Gary Lin <[email protected]> +Date: Tue, 25 Jun 2024 16:27:57 +0800 +Subject: [PATCH 2/6] libtasn1: use bound-checked _asn1_str_cat() +
Quoted 8 lines
grub-core/lib/libtasn1-patches/0002-libtasn1-use-bound-checked-_asn1_str_cat.patch line 11
Quoted 6 lines
grub-core/lib/libtasn1-patches/0002-libtasn1-use-bound-checked-_asn1_str_cat.patch new file +6
-0+Remove _asn1_strcat() and replace strcat() with the bound-checked +_asn1_str_cat() except the one inside _asn1_str_cat(). That strcat +is replaced with strcpy. + +Signed-off-by: Daniel Axtens <[email protected]> +Signed-off-by: Gary Lin <[email protected]>Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 04/25] libtasn1: use bound-checked _asn1_str_cat()
Quoted 13 lines · Gary Lin
Quoted 10 lines · Daniel Kiper
Quoted 2 lines · Gary Lin via Grub-devel
Remove
_asn1_strcat()and replacestrcat()with the bound-checked_asn1_str_cat()except the one inside_asn1_str_cat(). That strcats/strcat/strcat()/
Quoted 1 line
is replaced with strcpy.
s/strcpy/strcpy()/
Will fix them in the next version.
Quoted 7 lines
Quoted 2 lines
This commit message and one below miss explanation why these changes are needed.
Ok, I'll add more details about the change.
Quoted 1 line
And I think this patch should be split into two...
The changes are all about the same thing: replacing
strcat()with a bound-checked function. What kind of splitting woud you suggest?
The strcat() and strcpy() are two distinct changes. So, both begs for separate patches.
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 04/25] libtasn1: use bound-checked _asn1_str_cat()
Quoted 16 lines · Daniel Kiper
Quoted 15 lines · Gary Lin
Quoted 10 lines · Daniel Kiper
Quoted 2 lines · Gary Lin via Grub-devel
Remove
_asn1_strcat()and replacestrcat()with the bound-checked_asn1_str_cat()except the one inside_asn1_str_cat(). That strcats/strcat/strcat()/
Quoted 1 line
is replaced with strcpy.
s/strcpy/strcpy()/
Will fix them in the next version.
Quoted 2 lines
This commit message and one below miss explanation why these changes are needed.
Quoted 9 lines
Quoted 5 lines
Ok, I'll add more details about the change.
Quoted 1 line
And I think this patch should be split into two...
The changes are all about the same thing: replacing
strcat()with a bound-checked function. What kind of splitting woud you suggest?The
strcat()andstrcpy()are two distinct changes. So, both begs for separate patches.
Got it. I'll split this patch in the next version.
Gary Lin
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v18 5/25 libtasn1: adjust the header paths in libtasn1.h
In reply to Gary Lin via Grub-develUse the grub headers instead of the standard POSIX headers.
--- ...djust-the-header-paths-in-libtasn1.h.patch | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 grub-core/lib/libtasn1-patches/0003-libtasn1-adjust-the-header-paths-in-libtasn1.h.patch
grub-core/lib/libtasn1-patches/0003-libtasn1-adjust-the-header-paths-in-libtasn1.h.patch new file +32 -0
@@ -0,0 +1,32 @@ +From da7ac4d6dff8876fc18f006de3c72da3c93833f5 Mon Sep 17 00:00:00 2001 +From: Gary Lin <[email protected]> +Date: Tue, 25 Jun 2024 16:30:40 +0800 +Subject: [PATCH 3/6] libtasn1: adjust the header paths in libtasn1.h + +Use the grub headers instead of the standard POSIX headers. + +Signed-off-by: Daniel Axtens <[email protected]> +Signed-off-by: Gary Lin <[email protected]> +--- + grub-core/lib/libtasn1-grub/libtasn1.h | 5 ++--- + 1 file changed, 2 insertions(+), 3 deletions(-) + +diff --git a/grub-core/lib/libtasn1-grub/libtasn1.h b/grub-core/lib/libtasn1-grub/libtasn1.h +index 058ab27b0..7d64b6ab7 100644 +--- a/grub-core/lib/libtasn1-grub/libtasn1.h ++++ b/grub-core/lib/libtasn1-grub/libtasn1.h +@@ -54,9 +54,8 @@ + # define __LIBTASN1_PURE__ + # endif + +-# include <sys/types.h> +-# include <time.h> +-# include <stdio.h> /* for FILE* */ ++# include <grub/types.h> ++# include <grub/time.h> + + # ifdef __cplusplus + extern "C" +-- +2.35.3 +
Signature · 7 lines
2.35.3 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 05/25] libtasn1: adjust the header paths in libtasn1.h
Quoted 1 line · Gary Lin via Grub-devel
Use the grub headers instead of the standard POSIX headers.
Again, why?
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 05/25] libtasn1: adjust the header paths in libtasn1.h
Quoted 5 lines · Daniel Kiper
Quoted 1 line · Gary Lin via Grub-devel
Use the grub headers instead of the standard POSIX headers.
Again, why?
"libtasn1.h" is to be included by users, not only the library. If the POSIX headers are used here, then the users have to add CPPFLAGS_POSIX before using the library, and I feel it's not necessary.
Gary Lin
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 05/25] libtasn1: adjust the header paths in libtasn1.h
Quoted 9 lines · Gary Lin
Quoted 5 lines · Daniel Kiper
Quoted 1 line · Gary Lin via Grub-devel
Use the grub headers instead of the standard POSIX headers.
Again, why?
"
libtasn1.h" is to be included by users, not only the library. If the POSIX headers are used here, then the users have to addCPPFLAGS_POSIXbefore using the library, and I feel it's not necessary.
OK, please add this explanation to the commit message.
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 05/25] libtasn1: adjust the header paths in libtasn1.h
Quoted 5 lines · Daniel Kiper
Quoted 4 lines · Gary Lin
Quoted 3 lines · Daniel Kiper
Quoted 1 line · Gary Lin via Grub-devel
Use the grub headers instead of the standard POSIX headers.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Again, why?
"
libtasn1.h" is to be included by users, not only the library. If the POSIX headers are used here, then the users have to addCPPFLAGS_POSIXbefore using the library, and I feel it's not necessary.OK, please add this explanation to the commit message.
Sure. Will update the decription in the next version.
Gary Lin
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v18 6/25 libtasn1: Use grub_divmod64() for division
In reply to Gary Lin via Grub-develReplace a 64 bit division with a call to grub_divmod64, preventing creation of __udivdi3 calls on 32 bit platforms.
--- ...tasn1-Use-grub_divmod64-for-division.patch | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 grub-core/lib/libtasn1-patches/0004-libtasn1-Use-grub_divmod64-for-division.patch
grub-core/lib/libtasn1-patches/0004-libtasn1-Use-grub_divmod64-for-division.patch new file +30 -0
@@ -0,0 +1,30 @@ +From 52ad4fb6a023f27fdcea490d8e4956ce3957b1f9 Mon Sep 17 00:00:00 2001 +From: Gary Lin <[email protected]> +Date: Tue, 25 Jun 2024 16:32:50 +0800 +Subject: [PATCH 4/6] libtasn1: Use grub_divmod64() for division + +Replace a 64 bit division with a call to grub_divmod64, preventing +creation of __udivdi3 calls on 32 bit platforms. + +Signed-off-by: Daniel Axtens <[email protected]> +Signed-off-by: Gary Lin <[email protected]> +--- + grub-core/lib/libtasn1-grub/lib/parser_aux.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/lib/libtasn1-grub/lib/parser_aux.c b/grub-core/lib/libtasn1-grub/lib/parser_aux.c +index c05bd2339..e4e4c0556 100644 +--- a/grub-core/lib/libtasn1-grub/lib/parser_aux.c ++++ b/grub-core/lib/libtasn1-grub/lib/parser_aux.c +@@ -632,7 +632,7 @@ _asn1_ltostr (int64_t v, char str[LTOSTR_MAX_SIZE]) + count = 0; + do + { +- d = val / 10; ++ d = grub_divmod64(val, 10, NULL); + r = val - d * 10; + temp[start + count] = '0' + (char) r; + count++; +-- +2.35.3 +
Signature · 7 lines
2.35.3 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 06/25] libtasn1: Use grub_divmod64() for division
Quoted 1 line · Gary Lin via Grub-devel
Replace a 64 bit division with a call to
grub_divmod64, preventing
s/64 bit/64-bit/
s/grub_divmod64/grub_divmod64()/
Quoted 1 line
creation of
__udivdi3calls on 32 bit platforms.
s/__udivdi3/__udivdi3()/
Quoted 2 lines
Signed-off-by Daniel Axtens <[email protected]>Signed-off-by Gary Lin <[email protected]>
If you fix the issues mentioned above (and same below) you can add
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 06/25] libtasn1: Use grub_divmod64() for division
Quoted 8 lines · Daniel Kiper
Quoted 1 line · Gary Lin via Grub-devel
Replace a 64 bit division with a call to
grub_divmod64, preventings/64 bit/64-bit/
s/grub_divmod64/grub_divmod64()/Quoted 1 line
creation of
__udivdi3calls on 32 bit platforms.
Quoted 8 lines
s/__udivdi3/__udivdi3()/
Quoted 2 lines
Signed-off-by Daniel Axtens <[email protected]>Signed-off-by Gary Lin <[email protected]>If you fix the issues mentioned above (and same below) you can add
Reviewed-by Daniel Kiper <[email protected]>...
Thanks. I'll fix them in the next version.
Gary Lin
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v18 7/25 libtasn1: fix the potential buffer overrun
In reply to Gary Lin via Grub-develIn _asn1_tag_der(), the first while loop for the long form may end up with a 'k' value with 'ASN1_MAX_TAG_SIZE' and cause the buffer overrun in the second while loop. This commit tweaks the conditional check to avoid producing a too large 'k'.
This is a quick fix and may differ from the official upstream fix.
libtasn1 issue: https://gitlab.com/gnutls/libtasn1/-/issues/49
--- ...sn1-fix-the-potential-buffer-overrun.patch | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 grub-core/lib/libtasn1-patches/0005-libtasn1-fix-the-potential-buffer-overrun.patch
grub-core/lib/libtasn1-patches/0005-libtasn1-fix-the-potential-buffer-overrun.patch new file +35 -0
@@ -0,0 +1,35 @@ +From 38cc5e33cf89ed5d3152923fbedd9869bf566bb5 Mon Sep 17 00:00:00 2001 +From: Gary Lin <[email protected]> +Date: Mon, 8 Apr 2024 14:57:21 +0800 +Subject: [PATCH 5/6] libtasn1: fix the potential buffer overrun + +In _asn1_tag_der(), the first while loop for the long form may end up +with a 'k' value with 'ASN1_MAX_TAG_SIZE' and cause the buffer overrun +in the second while loop. This commit tweaks the conditional check to +avoid producing a too large 'k'. + +This is a quick fix and may differ from the official upstream fix. + +libtasn1 issue: https://gitlab.com/gnutls/libtasn1/-/issues/49 + +Signed-off-by: Gary Lin <[email protected]> +--- + grub-core/lib/libtasn1-grub/lib/coding.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grub-core/lib/libtasn1-grub/lib/coding.c b/grub-core/lib/libtasn1-grub/lib/coding.c +index 5d03bca9d..0458829a5 100644 +--- a/grub-core/lib/libtasn1-grub/lib/coding.c ++++ b/grub-core/lib/libtasn1-grub/lib/coding.c +@@ -143,7 +143,7 @@ _asn1_tag_der (unsigned char class, unsigned int tag_value, + temp[k++] = tag_value & 0x7F; + tag_value >>= 7; + +- if (k > ASN1_MAX_TAG_SIZE - 1) ++ if (k >= ASN1_MAX_TAG_SIZE - 1) + break; /* will not encode larger tags */ + } + *ans_len = k + 1; +-- +2.35.3 +
Signature · 7 lines
2.35.3 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v18 8/25 asn1_test: changes for grub compatibility
In reply to Gary Lin via Grub-develDo a few things to make asn1 tests compile as part of grub:
- include asn1_test.h only
- rename the main functions to the test names
- remove 'verbose' and the unnecessary printf()
- print the error messages with grub_printf()
- return either 0 or 1 to reflect the results of the tests
- replace the system functions with grub functions, ex: memcmp() -> grub_memcmp()
--- ..._test-changes-for-grub-compatibility.patch | 844 ++++++++++++++++++ 1 file changed, 844 insertions(+) create mode 100644 grub-core/lib/libtasn1-patches/0006-asn1_test-changes-for-grub-compatibility.patch
grub-core/lib/libtasn1-patches/0006-asn1_test-changes-for-grub-compatibility.patch new file +844 -0
@@ -0,0 +1,844 @@ +From 650259866464a0f54df0c18fbcb9068d6536cfc3 Mon Sep 17 00:00:00 2001 +From: Gary Lin <[email protected]> +Date: Tue, 18 Jun 2024 14:33:01 +0800 +Subject: [PATCH 6/6] asn1_test: changes for grub compatibility + +Do a few things to make asn1 tests compile as part of grub: + +- include asn1_test.h only + +- rename the main functions to the test names + +- remove 'verbose' and the unnecessary printf() + +- print the error messages with grub_printf() + +- return either 0 or 1 to reflect the results of the tests + +- replace the system functions with grub functions, ex: memcmp() -> + grub_memcmp() + +Signed-off-by: Daniel Axtens <[email protected]> +Signed-off-by: Gary Lin <[email protected]> +--- + grub-core/tests/asn1/tests/CVE-2018-1000654.c | 32 +++----- + grub-core/tests/asn1/tests/Test_overflow.c | 71 +++++------------- + grub-core/tests/asn1/tests/Test_simple.c | 51 ++++++------- + grub-core/tests/asn1/tests/Test_strings.c | 40 ++++------ + .../tests/asn1/tests/object-id-decoding.c | 28 +++---- + .../tests/asn1/tests/object-id-encoding.c | 42 ++++------- + grub-core/tests/asn1/tests/octet-string.c | 75 ++++++------------- + grub-core/tests/asn1/tests/reproducers.c | 32 +++----- + 8 files changed, 126 insertions(+), 245 deletions(-) + +diff --git a/grub-core/tests/asn1/tests/CVE-2018-1000654.c b/grub-core/tests/asn1/tests/CVE-2018-1000654.c +index 0c22b7012..6320af338 100644 +--- a/grub-core/tests/asn1/tests/CVE-2018-1000654.c ++++ b/grub-core/tests/asn1/tests/CVE-2018-1000654.c +@@ -22,51 +22,41 @@ + /* Description: reproducer for CVE-2018-1000654 */ + /****************************************************************/ + +-#include <stdio.h> +-#include <string.h> +-#include <stdlib.h> ++#include "asn1_test.h" ++ + #include "CVE-2018-1000654-1_asn1_tab.h" + #include "CVE-2018-1000654-2_asn1_tab.h" + + int +-main (int argc, char *argv[]) ++test_CVE_2018_1000654 (void) + { +- int result, verbose = 0; ++ int result; + asn1_node definitions = NULL; + char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE]; + +- if (argc > 1) +- verbose = 1; +- +- printf ("Test 1\n"); +- + result = + asn1_array2tree (CVE_2018_1000654_1_asn1_tab, &definitions, + errorDescription); + if (result != ASN1_RECURSION) + { +- asn1_perror (result); +- printf ("ErrorDescription = %s\n\n", errorDescription); +- exit (1); ++ grub_printf ("Error: %s\nErrorDescription = %s\n\n", ++ asn1_strerror (result), errorDescription); ++ return 1; + } + + asn1_delete_structure (&definitions); + +- printf ("Test 2\n"); +- + result = + asn1_array2tree (CVE_2018_1000654_2_asn1_tab, &definitions, + errorDescription); + if (result != ASN1_RECURSION) + { +- asn1_perror (result); +- printf ("ErrorDescription = %s\n\n", errorDescription); +- exit (1); ++ grub_printf ("Error: %s\nErrorDescription = %s\n\n", ++ asn1_strerror (result), errorDescription); ++ return 1; + } + + asn1_delete_structure (&definitions); + +- if (verbose) +- printf ("Success\n"); +- exit (0); ++ return 0; + } +diff --git a/grub-core/tests/asn1/tests/Test_overflow.c b/grub-core/tests/asn1/tests/Test_overflow.c +index c61dea4bb..7367f1af1 100644 +--- a/grub-core/tests/asn1/tests/Test_overflow.c ++++ b/grub-core/tests/asn1/tests/Test_overflow.c +@@ -20,22 +20,13 @@ + + /* Written by Simon Josefsson */ + +-#include <stdio.h> +-#include <string.h> +-#include <stdlib.h> +-#include <limits.h> +- +-#include "libtasn1.h" ++#include "asn1_test.h" + + int +-main (int argc, char **argv) ++test_overflow(void) + { + /* Test that values larger than long are rejected. This has worked + fine with all versions of libtasn1. */ +- int verbose = 0; +- +- if (argc > 1) +- verbose = 1; + + { + unsigned char der[] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"; +@@ -44,23 +35,18 @@ main (int argc, char **argv) + + l = asn1_get_length_der (der, sizeof der, &len); + +- if (l == -2L) +- { +- if (verbose) +- puts ("OK: asn1_get_length_der bignum"); +- } +- else ++ if (l != -2L) + { +- printf ("ERROR: asn1_get_length_der bignum (l %ld len %d)\n", l, len); ++ grub_printf ("ERROR: asn1_get_length_der bignum (l %ld len %d)\n", l, len); + return 1; + } + } + + /* Test that values larger than int but smaller than long are + rejected. This limitation was introduced with libtasn1 2.12. */ +- if (LONG_MAX > INT_MAX) ++#if (GRUB_LONG_MAX > GRUB_INT_MAX) + { +- unsigned long num = ((long) UINT_MAX) << 2; ++ unsigned long num = ((long) GRUB_UINT_MAX) << 2; + unsigned char der[20]; + int der_len; + long l; +@@ -70,18 +56,14 @@ main (int argc, char **argv) + + l = asn1_get_length_der (der, der_len, &len); + +- if (l == -2L) +- { +- if (verbose) +- puts ("OK: asn1_get_length_der intnum"); +- } +- else ++ if (l != -2L) + { +- printf ("ERROR: asn1_get_length_der intnum (l %ld len %d)\n", l, +- len); ++ grub_printf ("ERROR: asn1_get_length_der intnum (l %ld len %d)\n", l, ++ len); + return 1; + } + } ++#endif + + /* Test that values larger than would fit in the input string are + rejected. This problem was fixed in libtasn1 2.12. */ +@@ -97,15 +79,10 @@ main (int argc, char **argv) + der_len = sizeof (der); + l = asn1_get_length_der (der, der_len, &len); + +- if (l == -4L) ++ if (l != -4L) + { +- if (verbose) +- puts ("OK: asn1_get_length_der overflow-small"); +- } +- else +- { +- printf ("ERROR: asn1_get_length_der overflow-small (l %ld len %d)\n", +- l, len); ++ grub_printf ("ERROR: asn1_get_length_der overflow-small (l %ld len %d)\n", ++ l, len); + return 1; + } + } +@@ -124,15 +101,10 @@ main (int argc, char **argv) + der_len = sizeof (der); + l = asn1_get_length_der (der, der_len, &len); + +- if (l == -4L) +- { +- if (verbose) +- puts ("OK: asn1_get_length_der overflow-large1"); +- } +- else ++ if (l != -4L) + { +- printf ("ERROR: asn1_get_length_der overflow-large1 (l %ld len %d)\n", +- l, len); ++ grub_printf ("ERROR: asn1_get_length_der overflow-large1 (l %ld len %d)\n", ++ l, len); + return 1; + } + } +@@ -151,15 +123,10 @@ main (int argc, char **argv) + der_len = sizeof (der); + l = asn1_get_length_der (der, der_len, &len); + +- if (l == -2L) +- { +- if (verbose) +- puts ("OK: asn1_get_length_der overflow-large2"); +- } +- else ++ if (l != -2L) + { +- printf ("ERROR: asn1_get_length_der overflow-large2 (l %ld len %d)\n", +- l, len); ++ grub_printf ("ERROR: asn1_get_length_der overflow-large2 (l %ld len %d)\n", ++ l, len); + return 1; + } + } +diff --git a/grub-core/tests/asn1/tests/Test_simple.c b/grub-core/tests/asn1/tests/Test_simple.c +index 6cd07e069..19613cae8 100644 +--- a/grub-core/tests/asn1/tests/Test_simple.c ++++ b/grub-core/tests/asn1/tests/Test_simple.c +@@ -20,11 +20,7 @@ + * + */ + +-#include <stdio.h> +-#include <string.h> +-#include <stdlib.h> +- +-#include "libtasn1.h" ++#include "asn1_test.h" + + struct tv + { +@@ -77,7 +73,7 @@ static const struct tv tv[] = { + }; + + int +-main (int argc, char *argv[]) ++test_simple (void) + { + int result; + unsigned char der[100]; +@@ -85,7 +81,7 @@ main (int argc, char *argv[]) + int der_len = sizeof (der); + int str_size = sizeof (str); + int ret_len, bit_len; +- size_t i; ++ grub_size_t i; + + { + unsigned int etype = 38; +@@ -98,7 +94,7 @@ main (int argc, char *argv[]) + result = asn1_encode_simple_der (etype, my_str, my_str_len, tl, &tl_len); + if (result != ASN1_VALUE_NOT_VALID) + { +- fprintf (stderr, "asn1_encode_simple_der out of range etype\n"); ++ grub_printf ("asn1_encode_simple_der out of range etype\n"); + return 1; + } + } +@@ -109,7 +105,7 @@ main (int argc, char *argv[]) + result = asn1_get_bit_der (der, 0, &ret_len, str, str_size, &bit_len); + if (result != ASN1_GENERIC_ERROR) + { +- fprintf (stderr, "asn1_get_bit_der zero\n"); ++ grub_printf ("asn1_get_bit_der zero\n"); + return 1; + } + +@@ -131,9 +127,9 @@ main (int argc, char *argv[]) + } + #endif + +- if (der_len != tv[i].derlen || memcmp (der, tv[i].der, der_len) != 0) ++ if (der_len != tv[i].derlen || grub_memcmp (der, tv[i].der, der_len) != 0) + { +- fprintf (stderr, "asn1_bit_der iter %lu\n", (unsigned long) i); ++ grub_printf ("asn1_bit_der iter %lu\n", (unsigned long) i); + return 1; + } + +@@ -144,8 +140,7 @@ main (int argc, char *argv[]) + if (result != ASN1_SUCCESS || ret_len != tv[i].derlen + || bit_len != tv[i].bitlen) + { +- fprintf (stderr, "asn1_get_bit_der iter %lu, err: %d\n", +- (unsigned long) i, result); ++ grub_printf ("asn1_get_bit_der iter %lu, err: %d\n", (unsigned long) i, result); + return 1; + } + } +@@ -160,65 +155,65 @@ main (int argc, char *argv[]) + + /* 03 04 06 6e 5d c0 DER encoding */ + +- memcpy (der, "\x04\x06\x6e\x5d\xc0", 5); ++ grub_memcpy (der, "\x04\x06\x6e\x5d\xc0", 5); + der_len = 5; + + result = asn1_get_bit_der (der, der_len, &ret_len, str, str_size, &bit_len); + if (result != ASN1_SUCCESS || ret_len != 5 +- || bit_len != 18 || memcmp (str, "\x6e\x5d\xc0", 3) != 0) ++ || bit_len != 18 || grub_memcmp (str, "\x6e\x5d\xc0", 3) != 0) + { +- fprintf (stderr, "asn1_get_bit_der example\n"); ++ grub_printf ("asn1_get_bit_der example\n"); + return 1; + } + + der_len = sizeof (der); + asn1_bit_der (str, bit_len, der, &der_len); +- if (der_len != 5 || memcmp (der, "\x04\x06\x6e\x5d\xc0", 5) != 0) ++ if (der_len != 5 || grub_memcmp (der, "\x04\x06\x6e\x5d\xc0", 5) != 0) + { +- fprintf (stderr, "asn1_bit_der example roundtrip\n"); ++ grub_printf ("asn1_bit_der example roundtrip\n"); + return 1; + } + + /* 03 04 06 6e 5d e0 padded with "100000" */ + +- memcpy (der, "\x04\x06\x6e\x5d\xe0", 5); ++ grub_memcpy (der, "\x04\x06\x6e\x5d\xe0", 5); + der_len = 5; + + result = asn1_get_bit_der (der, der_len, &ret_len, str, str_size, &bit_len); + if (result != ASN1_SUCCESS || ret_len != 5 +- || bit_len != 18 || memcmp (str, "\x6e\x5d\xe0", 3) != 0) ++ || bit_len != 18 || grub_memcmp (str, "\x6e\x5d\xe0", 3) != 0) + { +- fprintf (stderr, "asn1_get_bit_der example padded\n"); ++ grub_printf ("asn1_get_bit_der example padded\n"); + return 1; + } + + der_len = sizeof (der); + asn1_bit_der (str, bit_len, der, &der_len); +- if (der_len != 5 || memcmp (der, "\x04\x06\x6e\x5d\xc0", 5) != 0) ++ if (der_len != 5 || grub_memcmp (der, "\x04\x06\x6e\x5d\xc0", 5) != 0) + { +- fprintf (stderr, "asn1_bit_der example roundtrip\n"); ++ grub_printf ("asn1_bit_der example roundtrip\n"); + return 1; + } + + /* 03 81 04 06 6e 5d c0 long form of length octets */ + +- memcpy (der, "\x81\x04\x06\x6e\x5d\xc0", 6); ++ grub_memcpy (der, "\x81\x04\x06\x6e\x5d\xc0", 6); + der_len = 6; + + result = asn1_get_bit_der (der, der_len, &ret_len, str, str_size, &bit_len); + + if (result != ASN1_SUCCESS || ret_len != 6 +- || bit_len != 18 || memcmp (str, "\x6e\x5d\xc0", 3) != 0) ++ || bit_len != 18 || grub_memcmp (str, "\x6e\x5d\xc0", 3) != 0) + { +- fprintf (stderr, "asn1_get_bit_der example long form\n"); ++ grub_printf ("asn1_get_bit_der example long form\n"); + return 1; + } + + der_len = sizeof (der); + asn1_bit_der (str, bit_len, der, &der_len); +- if (der_len != 5 || memcmp (der, "\x04\x06\x6e\x5d\xc0", 5) != 0) ++ if (der_len != 5 || grub_memcmp (der, "\x04\x06\x6e\x5d\xc0", 5) != 0) + { +- fprintf (stderr, "asn1_bit_der example roundtrip\n"); ++ grub_printf ("asn1_bit_der example roundtrip\n"); + return 1; + } + +diff --git a/grub-core/tests/asn1/tests/Test_strings.c b/grub-core/tests/asn1/tests/Test_strings.c +index 27f7215e1..1807e71e4 100644 +--- a/grub-core/tests/asn1/tests/Test_strings.c ++++ b/grub-core/tests/asn1/tests/Test_strings.c +@@ -20,11 +20,7 @@ + * + */ + +-#include <stdio.h> +-#include <string.h> +-#include <stdlib.h> +- +-#include "libtasn1.h" ++#include "asn1_test.h" + + struct tv + { +@@ -74,7 +70,7 @@ static const struct tv ber[] = { + }; + + int +-main (int argc, char *argv[]) ++test_strings () + { + int ret; + unsigned char tl[ASN1_MAX_TL_SIZE]; +@@ -93,17 +89,15 @@ main (int argc, char *argv[]) + tl, &tl_len); + if (ret != ASN1_SUCCESS) + { +- fprintf (stderr, "Encoding error in %u: %s\n", i, +- asn1_strerror (ret)); ++ grub_printf ("Encoding error in %u: %s\n", i, asn1_strerror (ret)); + return 1; + } + der_len = tl_len + tv[i].str_len; + +- if (der_len != tv[i].der_len || memcmp (tl, tv[i].der, tl_len) != 0) ++ if (der_len != tv[i].der_len || grub_memcmp (tl, tv[i].der, tl_len) != 0) + { +- fprintf (stderr, +- "DER encoding differs in %u! (size: %u, expected: %u)\n", +- i, der_len, tv[i].der_len); ++ grub_printf ("DER encoding differs in %u! (size: %u, expected: %u)\n", ++ i, der_len, tv[i].der_len); + return 1; + } + +@@ -113,16 +107,14 @@ main (int argc, char *argv[]) + &str_len); + if (ret != ASN1_SUCCESS) + { +- fprintf (stderr, "Decoding error in %u: %s\n", i, +- asn1_strerror (ret)); ++ grub_printf ("Decoding error in %u: %s\n", i, asn1_strerror (ret)); + return 1; + } + +- if (str_len != tv[i].str_len || memcmp (str, tv[i].str, str_len) != 0) ++ if (str_len != tv[i].str_len || grub_memcmp (str, tv[i].str, str_len) != 0) + { +- fprintf (stderr, +- "DER decoded data differ in %u! (size: %u, expected: %u)\n", +- i, der_len, tv[i].str_len); ++ grub_printf ("DER decoded data differ in %u! (size: %u, expected: %u)\n", ++ i, der_len, tv[i].str_len); + return 1; + } + } +@@ -136,19 +128,17 @@ main (int argc, char *argv[]) + &str_len, NULL); + if (ret != ASN1_SUCCESS) + { +- fprintf (stderr, "BER decoding error in %u: %s\n", i, +- asn1_strerror (ret)); ++ grub_printf ("BER decoding error in %u: %s\n", i, asn1_strerror (ret)); + return 1; + } + +- if (str_len != ber[i].str_len || memcmp (b, ber[i].str, str_len) != 0) ++ if (str_len != ber[i].str_len || grub_memcmp (b, ber[i].str, str_len) != 0) + { +- fprintf (stderr, +- "BER decoded data differ in %u! (size: %u, expected: %u)\n", +- i, str_len, ber[i].str_len); ++ grub_printf ("BER decoded data differ in %u! (size: %u, expected: %u)\n", ++ i, str_len, ber[i].str_len); + return 1; + } +- free (b); ++ grub_free(b); + } + + +diff --git a/grub-core/tests/asn1/tests/object-id-decoding.c b/grub-core/tests/asn1/tests/object-id-decoding.c +index 06a6c52a2..edfb8beb4 100644 +--- a/grub-core/tests/asn1/tests/object-id-decoding.c ++++ b/grub-core/tests/asn1/tests/object-id-decoding.c +@@ -18,11 +18,7 @@ + * + */ + +-#include <stdio.h> +-#include <string.h> +-#include <stdlib.h> +- +-#include "libtasn1.h" ++#include "asn1_test.h" + + struct tv + { +@@ -74,11 +70,11 @@ static const struct tv tv[] = { + }; + + int +-main (int argc, char *argv[]) ++test_object_id_decoding (void) + { + char str[128]; + int ret, ret_len; +- size_t i; ++ grub_size_t i; + + for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++) + { +@@ -89,10 +85,8 @@ main (int argc, char *argv[]) + sizeof (str)); + if (ret != tv[i].expected_error) + { +- fprintf (stderr, +- "%d: asn1_get_object_id_der iter %lu: got '%s' expected %d\n", +- __LINE__, (unsigned long) i, asn1_strerror (ret), +- tv[i].expected_error); ++ grub_printf ("%d: asn1_get_object_id_der iter %lu: got '%s' expected %d\n", ++ __LINE__, (unsigned long) i, asn1_strerror(ret), tv[i].expected_error); + return 1; + } + +@@ -101,17 +95,15 @@ main (int argc, char *argv[]) + + if (ret_len != tv[i].der_len - 1) + { +- fprintf (stderr, +- "%d: iter %lu: error in DER, length returned is %d, had %d\n", +- __LINE__, (unsigned long) i, ret_len, tv[i].der_len - 1); ++ grub_printf ("%d: iter %lu: error in DER, length returned is %d, had %d\n", ++ __LINE__, (unsigned long)i, ret_len, tv[i].der_len-1); + return 1; + } + +- if (strcmp (tv[i].oid, str) != 0) ++ if (grub_strcmp (tv[i].oid, str) != 0) + { +- fprintf (stderr, +- "%d: strcmp iter %lu: got invalid OID: %s, expected: %s\n", +- __LINE__, (unsigned long) i, str, tv[i].oid); ++ grub_printf ("%d: strcmp iter %lu: got invalid OID: %s, expected: %s\n", ++ __LINE__, (unsigned long) i, str, tv[i].oid); + return 1; + } + +diff --git a/grub-core/tests/asn1/tests/object-id-encoding.c b/grub-core/tests/asn1/tests/object-id-encoding.c +index 1a3396986..d02af885a 100644 +--- a/grub-core/tests/asn1/tests/object-id-encoding.c ++++ b/grub-core/tests/asn1/tests/object-id-encoding.c +@@ -18,11 +18,7 @@ + * + */ + +-#include <stdio.h> +-#include <string.h> +-#include <stdlib.h> +- +-#include "libtasn1.h" ++#include "asn1_test.h" + + struct tv + { +@@ -84,10 +80,10 @@ static const struct tv tv[] = { + }; + + int +-main (int argc, char *argv[]) ++test_object_id_encoding(void) + { + unsigned char der[128]; +- int ret, der_len, i, j; ++ int ret, der_len, i; + + for (i = 0; i < (int) (sizeof (tv) / sizeof (tv[0])); i++) + { +@@ -97,33 +93,21 @@ main (int argc, char *argv[]) + { + if (ret == tv[i].expected_error) + continue; +- fprintf (stderr, +- "%d: iter %lu, encoding of OID failed: %s\n", +- __LINE__, (unsigned long) i, asn1_strerror (ret)); ++ grub_printf ("%d: iter %lu, encoding of OID failed: %s\n", ++ __LINE__, (unsigned long) i, asn1_strerror(ret)); + return 1; + } + else if (ret != tv[i].expected_error) +- { +- fprintf (stderr, +- "%d: iter %lu, encoding of OID %s succeeded when expecting failure\n", +- __LINE__, (unsigned long) i, tv[i].oid); +- return 1; +- } ++ { ++ grub_printf ("%d: iter %lu, encoding of OID %s succeeded when expecting failure\n", ++ __LINE__, (unsigned long) i, tv[i].oid); ++ return 1; ++ } + +- if (der_len != tv[i].der_len || memcmp (der, tv[i].der, der_len) != 0) ++ if (der_len != tv[i].der_len || grub_memcmp(der, tv[i].der, der_len) != 0) + { +- fprintf (stderr, +- "%d: iter %lu, re-encoding of OID %s resulted to different string (%d vs %d bytes)\n", +- __LINE__, (unsigned long) i, tv[i].oid, der_len, +- tv[i].der_len); +- fprintf (stderr, "\nGot:\t\t"); +- for (j = 0; j < der_len; j++) +- fprintf (stderr, "%.2x", der[j]); +- +- fprintf (stderr, "\nExpected:\t"); +- for (j = 0; j < tv[i].der_len; j++) +- fprintf (stderr, "%.2x", tv[i].der[j]); +- fprintf (stderr, "\n"); ++ grub_printf ("%d: iter %lu, re-encoding of OID %s resulted to different string (%d vs %d bytes)\n", ++ __LINE__, (unsigned long) i, tv[i].oid, der_len, tv[i].der_len); + + return 1; + } +diff --git a/grub-core/tests/asn1/tests/octet-string.c b/grub-core/tests/asn1/tests/octet-string.c +index 69eb18a62..8c24e67e0 100644 +--- a/grub-core/tests/asn1/tests/octet-string.c ++++ b/grub-core/tests/asn1/tests/octet-string.c +@@ -20,11 +20,8 @@ + * + */ + +-#include <stdio.h> +-#include <string.h> +-#include <stdlib.h> ++#include "asn1_test.h" + +-#include "libtasn1.h" + + struct tv + { +@@ -112,15 +109,15 @@ static const struct tv tv[] = { + }; + + int +-main (int argc, char *argv[]) ++test_octet_string (void) + { + unsigned char str[100]; + unsigned char der[100]; + int der_len = sizeof (der); + int str_size = sizeof (str); + unsigned char *tmp = NULL; +- int ret, ret_len, j; +- size_t i; ++ int ret, ret_len; ++ grub_size_t i; + + for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++) + { +@@ -135,9 +132,8 @@ main (int argc, char *argv[]) + sizeof (str), &str_size); + if (ret != tv[i].expected_error) + { +- fprintf (stderr, +- "%d: asn1_get_octet_der: %s: got %d expected %d\n", +- __LINE__, tv[i].name, ret, tv[i].expected_error); ++ grub_printf ("%d: asn1_get_octet_der: %s: got %d expected %d\n", ++ __LINE__, tv[i].name, ret, tv[i].expected_error); + return 1; + } + if (tv[i].expected_error) +@@ -145,28 +141,18 @@ main (int argc, char *argv[]) + + if (ret_len != tv[i].der_len - 1) + { +- fprintf (stderr, +- "%d: error in DER, length returned is %d, had %d\n", +- __LINE__, ret_len, tv[i].der_len - 1); ++ grub_printf ("%d: error in DER, length returned is %d, had %d\n", ++ __LINE__, ret_len, tv[i].der_len - 1); + return 1; + } + + if (str_size != tv[i].len +- || memcmp (tv[i].string, str, tv[i].len) != 0) ++ || grub_memcmp (tv[i].string, str, tv[i].len) != 0) + { +- fprintf (stderr, +- "%d: memcmp: %s: got invalid decoding\n", +- __LINE__, tv[i].name); +- +- fprintf (stderr, "\nGot:\t\t"); +- for (j = 0; j < str_size; j++) +- fprintf (stderr, "%.2x", str[j]); +- +- fprintf (stderr, "\nExpected:\t"); +- for (j = 0; j < tv[i].len; j++) +- fprintf (stderr, "%.2x", tv[i].string[j]); +- fprintf (stderr, "\n"); +- return 1; ++ grub_printf ("%d: memcmp: %s: got invalid decoding\n", ++ __LINE__, tv[i].name); ++ ++ return 1; + } + + /* Encode */ +@@ -174,10 +160,9 @@ main (int argc, char *argv[]) + asn1_octet_der (str, str_size, der, &der_len); + + if (der_len != tv[i].der_len - 1 +- || memcmp (tv[i].der_str + 1, der, tv[i].der_len - 1) != 0) ++ || grub_memcmp (tv[i].der_str + 1, der, tv[i].der_len - 1) != 0) + { +- fprintf (stderr, +- "encoding: %s: got invalid encoding\n", tv[i].name); ++ grub_printf ("encoding: %s: got invalid encoding\n", tv[i].name); + return 1; + } + } +@@ -189,10 +174,9 @@ main (int argc, char *argv[]) + (unsigned int *) &der_len); + if (ret != tv[i].expected_error) + { +- fprintf (stderr, +- "%d: asn1_decode_simple_ber: %s: got %s expected %s\n", +- __LINE__, tv[i].name, asn1_strerror (ret), +- asn1_strerror (tv[i].expected_error)); ++ grub_printf ("%d: asn1_decode_simple_ber: %s: got %s expected %s\n", ++ __LINE__, tv[i].name, asn1_strerror(ret), ++ asn1_strerror(tv[i].expected_error)); + return 1; + } + if (tv[i].expected_error) +@@ -200,28 +184,17 @@ main (int argc, char *argv[]) + + if (der_len != tv[i].der_len) + { +- fprintf (stderr, +- "%d: error: %s: DER, length returned is %d, had %d\n", +- __LINE__, tv[i].name, der_len, tv[i].der_len); ++ grub_printf ("%d: error: %s: DER, length returned is %d, had %d\n", ++ __LINE__, tv[i].name, der_len, tv[i].der_len); + return 1; + } + +- if (str_size != tv[i].len || memcmp (tv[i].string, tmp, tv[i].len) != 0) ++ if (str_size != tv[i].len || grub_memcmp (tv[i].string, tmp, tv[i].len) != 0) + { +- fprintf (stderr, +- "%d: memcmp: %s: got invalid decoding\n", +- __LINE__, tv[i].name); +- fprintf (stderr, "\nGot:\t\t"); +- for (j = 0; j < str_size; j++) +- fprintf (stderr, "%.2x", tmp[j]); +- +- fprintf (stderr, "\nExpected:\t"); +- for (j = 0; j < tv[i].len; j++) +- fprintf (stderr, "%.2x", tv[i].string[j]); +- fprintf (stderr, "\n"); +- return 1; ++ grub_printf ("%d: memcmp: %s: got invalid decoding\n", __LINE__, tv[i].name); ++ return 1; + } +- free (tmp); ++ grub_free (tmp); + tmp = NULL; + + } +diff --git a/grub-core/tests/asn1/tests/reproducers.c b/grub-core/tests/asn1/tests/reproducers.c +index a09d8b021..750c15416 100644 +--- a/grub-core/tests/asn1/tests/reproducers.c ++++ b/grub-core/tests/asn1/tests/reproducers.c +@@ -22,13 +22,9 @@ + /* Description: run reproducers for several fixed issues */ + /****************************************************************/ + +-#include <stdio.h> +-#include <string.h> +-#include <stdlib.h> ++#include "asn1_test.h" + +-#include <libtasn1.h> +- +-#include <int.h> ++#define CONST_DOWN (1U<<29) + + /* produces endless loop (fixed by d4b624b2): + * The following translates into a single node with all pointers +@@ -53,21 +49,18 @@ const asn1_static_node tab[] = { + }; + + int +-main (int argc, char *argv[]) ++test_reproducers (void) + { +- int result, verbose = 0; ++ int result; + asn1_node definitions = NULL; + char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE]; + +- if (argc > 1) +- verbose = 1; +- + result = asn1_array2tree (endless_asn1_tab, &definitions, errorDescription); + if (result != ASN1_SUCCESS) + { +- asn1_perror (result); +- printf ("ErrorDescription = %s\n\n", errorDescription); +- exit (EXIT_FAILURE); ++ grub_printf ("Error: %s\nErrorDescription = %s\n\n", ++ asn1_strerror (result), errorDescription); ++ return 1; + } + + asn1_delete_structure (&definitions); +@@ -76,15 +69,12 @@ main (int argc, char *argv[]) + result = asn1_array2tree (tab, &definitions, errorDescription); + if (result != ASN1_SUCCESS) + { +- asn1_perror (result); +- printf ("ErrorDescription = %s\n\n", errorDescription); +- exit (EXIT_FAILURE); ++ grub_printf ("Error: %s\nErrorDescription = %s\n\n", ++ asn1_strerror (result), errorDescription); ++ return 1; + } + + asn1_delete_structure (&definitions); + +- if (verbose) +- printf ("Success\n"); +- +- exit (EXIT_SUCCESS); ++ return 0; + } +-- +2.35.3 +
Signature · 7 lines
2.35.3 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 08/25] asn1_test: changes for grub compatibility
Quoted 6 lines · Gary Lin via Grub-devel
Do a few things to make asn1 tests compile as part of grub:
- include
asn1_test.honly- rename the main functions to the test names
Quoted 8 lines
- remove 'verbose' and the unnecessary
printf()- print the error messages with
grub_printf()- return either 0 or 1 to reflect the results of the tests
- replace the system functions with grub functions, ex:
memcmp()->grub_memcmp()
When I look at this commit message I think this patch can be split further. OK, the last bullet can stay as is.
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 08/25] asn1_test: changes for grub compatibility
Quoted 11 lines · Daniel Kiper
Quoted 10 lines · Gary Lin via Grub-devel
Do a few things to make asn1 tests compile as part of grub:
- include
asn1_test.honly- rename the main functions to the test names
- remove 'verbose' and the unnecessary
printf()- print the error messages with
grub_printf()
Quoted 8 lines
Quoted 4 lines
- return either 0 or 1 to reflect the results of the tests
- replace the system functions with grub functions, ex:
memcmp()->grub_memcmp()When I look at this commit message I think this patch can be split further. OK, the last bullet can stay as is.
I was struggling on whether to split this patch because this series has grown much bigger than I thought. Besides, the coverity issues are all about libtasn1. Maybe it's time to break this patch series into two:
libtasn1 and tpm2, so that we can focus on libtasn1, and then tpm2.
Gary Lin
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 08/25] asn1_test: changes for grub compatibility
Quoted 14 lines · Gary Lin
Quoted 13 lines · Daniel Kiper
Quoted 12 lines · Gary Lin via Grub-devel
Do a few things to make asn1 tests compile as part of grub:
- include
asn1_test.honly- rename the main functions to the test names
- remove 'verbose' and the unnecessary
printf()- print the error messages with
grub_printf()- return either 0 or 1 to reflect the results of the tests
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
- replace the system functions with grub functions, ex:
memcmp()->grub_memcmp()When I look at this commit message I think this patch can be split further. OK, the last bullet can stay as is.
I was struggling on whether to split this patch because this series has grown much bigger than I thought. Besides, the coverity issues are all
I am OK with number of patches until it has good justification. I think it is more important to have the patches split into distinct logical parts.
Quoted 2 lines
about libtasn1. Maybe it's time to break this patch series into two:
libtasn1 and tpm2, so that we can focus on libtasn1, and then tpm2.
I do not think so. The TPM unlock patches depend on the libtasn1 patches and the libtasn1 patches alone do make much sense.
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 08/25] asn1_test: changes for grub compatibility
Quoted 18 lines · Daniel Kiper
Quoted 17 lines · Gary Lin
Quoted 16 lines · Daniel Kiper
Quoted 14 lines · Gary Lin via Grub-devel
Do a few things to make asn1 tests compile as part of grub:
- include
asn1_test.honly- rename the main functions to the test names
- remove 'verbose' and the unnecessary
printf()- print the error messages with
grub_printf()- return either 0 or 1 to reflect the results of the tests
- replace the system functions with grub functions, ex:
memcmp()->grub_memcmp()
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
When I look at this commit message I think this patch can be split further. OK, the last bullet can stay as is.
I was struggling on whether to split this patch because this series has grown much bigger than I thought. Besides, the coverity issues are all
I am OK with number of patches until it has good justification. I think it is more important to have the patches split into distinct logical parts.
Ok, I've broken down this patch into 6 smaller patches in my working branch.
Quoted 6 lines
Quoted 2 lines
about libtasn1. Maybe it's time to break this patch series into two:
libtasn1 and tpm2, so that we can focus on libtasn1, and then tpm2.I do not think so. The TPM unlock patches depend on the libtasn1 patches and the libtasn1 patches alone do make much sense.
Fine. I'll keep all patches in one patchset.
Gary Lin
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v18 9/25 libtasn1: compile into asn1 module
In reply to Gary Lin via Grub-develFrom: Daniel Axtens <[email protected]>
Create a wrapper file that specifies the module license. Set up the makefile so it is built.
--- autogen.sh | 18 ++++++++++++++++++ grub-core/Makefile.core.def | 15 +++++++++++++++ grub-core/lib/libtasn1_wrap/wrap.c | 27 +++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 grub-core/lib/libtasn1_wrap/wrap.c
autogen.sh +18 -0
@@ -51,6 +51,24 @@ for x in mpi-asm-defs.h mpih-add1.c mpih-sub1.c mpih-mul1.c mpih-mul2.c mpih-mul cp grub-core/lib/libgcrypt-grub/mpi/generic/"$x" grub-core/lib/libgcrypt-grub/mpi/"$x" done +echo "Importing libtasn1..." +if [ -d grub-core/lib/libtasn1-grub ]; then + rm -rf grub-core/lib/libtasn1-grub +fi + +mkdir -p grub-core/lib/libtasn1-grub/lib +cp grub-core/lib/libtasn1/lib/*.[ch] grub-core/lib/libtasn1-grub/lib +cp grub-core/lib/libtasn1/libtasn1.h grub-core/lib/libtasn1-grub/ + +for patch in \ + 0001-libtasn1-disable-code-not-needed-in-grub.patch \ + 0002-libtasn1-use-bound-checked-_asn1_str_cat.patch \ + 0003-libtasn1-adjust-the-header-paths-in-libtasn1.h.patch \ + 0004-libtasn1-Use-grub_divmod64-for-division.patch \ + 0005-libtasn1-fix-the-potential-buffer-overrun.patch ; do + patch -p1 -i grub-core/lib/libtasn1-patches/$patch +done + echo "Generating Automake input..." # Automake doesn't like including files from a path outside the project.
grub-core/Makefile.core.def +15 -0
@@ -2606,3 +2606,18 @@ module = { enable = efi; depends = part_gpt; }; + +module = { + name = asn1; + common = lib/libtasn1-grub/lib/decoding.c; + common = lib/libtasn1-grub/lib/coding.c; + common = lib/libtasn1-grub/lib/element.c; + common = lib/libtasn1-grub/lib/structure.c; + common = lib/libtasn1-grub/lib/parser_aux.c; + common = lib/libtasn1-grub/lib/gstr.c; + common = lib/libtasn1-grub/lib/errors.c; + common = lib/libtasn1_wrap/wrap.c; + cflags = '$(CFLAGS_POSIX) $(CFLAGS_GNULIB)'; + /* -Wno-type-limits comes from configure.ac of libtasn1 */ + cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB) -I$(srcdir)/lib/libtasn1-grub -I$(srcdir)/lib/libtasn1-grub/lib -Wno-type-limits'; +};
grub-core/lib/libtasn1_wrap/wrap.c new file +27 -0
@@ -0,0 +1,27 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 Free Software Foundation, Inc. +* Copyright (C) 2020 IBM Corporation +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/dl.h> + +/* +* libtasn1 is provided under LGPL2.1+, which is compatible +* with GPL3+. As GRUB as a whole is under GPL3+, this module +* is therefore under GPL3+ also. +*/ +GRUB_MOD_LICENSE ("GPLv3+" );
Signature · 7 lines
2.35.3 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v18 10/25 asn1_test: test module for libtasn1
In reply to Gary Lin via Grub-develFrom: Daniel Axtens <[email protected]>
Import tests from libtasn1 that don't use functionality we don't import. This test module is integrated into functional_test so that the user can run the test in grub shell.
This doesn't test the full decoder but that will be exercised in test suites for coming patch sets.
Add testcase target in accordance with5e10be48e5 tests: Add check-native and check-nonnative make targets
--- Makefile.util.def | 6 ++++ autogen.sh | 10 +++++- grub-core/Makefile.core.def | 15 ++++++++ grub-core/tests/asn1/asn1_test.c | 49 +++++++++++++++++++++++++++ grub-core/tests/asn1/asn1_test.h | 44 ++++++++++++++++++++++++ grub-core/tests/lib/functional_test.c | 1 + tests/asn1_test.in | 11 ++++++ 7 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 grub-core/tests/asn1/asn1_test.c create mode 100644 grub-core/tests/asn1/asn1_test.h create mode 100644 tests/asn1_test.in
Makefile.util.def +6 -0
@@ -1257,6 +1257,12 @@ script = { common = tests/luks2_test.in; }; +script = { + testcase = native; + name = asn1_test; + common = tests/asn1_test.in; +}; + program = { testcase = native; name = example_unit_test;
autogen.sh +9 -1
@@ -60,12 +60,20 @@ mkdir -p grub-core/lib/libtasn1-grub/lib cp grub-core/lib/libtasn1/lib/*.[ch] grub-core/lib/libtasn1-grub/lib cp grub-core/lib/libtasn1/libtasn1.h grub-core/lib/libtasn1-grub/ +if [ -d grub-core/tests/asn1/tests ]; then + rm -rf grub-core/tests/asn1/tests +fi + +mkdir grub-core/tests/asn1/tests +cp grub-core/lib/libtasn1/tests/*.[ch] grub-core/tests/asn1/tests + for patch in \ 0001-libtasn1-disable-code-not-needed-in-grub.patch \ 0002-libtasn1-use-bound-checked-_asn1_str_cat.patch \ 0003-libtasn1-adjust-the-header-paths-in-libtasn1.h.patch \ 0004-libtasn1-Use-grub_divmod64-for-division.patch \ - 0005-libtasn1-fix-the-potential-buffer-overrun.patch ; do + 0005-libtasn1-fix-the-potential-buffer-overrun.patch \ + 0006-asn1_test-changes-for-grub-compatibility.patch ; do patch -p1 -i grub-core/lib/libtasn1-patches/$patch done
grub-core/Makefile.core.def +15 -0
@@ -2621,3 +2621,18 @@ module = { /* -Wno-type-limits comes from configure.ac of libtasn1 */ cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB) -I$(srcdir)/lib/libtasn1-grub -I$(srcdir)/lib/libtasn1-grub/lib -Wno-type-limits'; }; + +module = { + name = asn1_test; + common = tests/asn1/tests/CVE-2018-1000654.c; + common = tests/asn1/tests/object-id-decoding.c; + common = tests/asn1/tests/object-id-encoding.c; + common = tests/asn1/tests/octet-string.c; + common = tests/asn1/tests/reproducers.c; + common = tests/asn1/tests/Test_overflow.c; + common = tests/asn1/tests/Test_simple.c; + common = tests/asn1/tests/Test_strings.c; + common = tests/asn1/asn1_test.c; + cflags = '-Wno-uninitialized'; + cppflags = '-I$(srcdir)/lib/libtasn1-grub -I$(srcdir)/tests/asn1/'; +};
grub-core/tests/asn1/asn1_test.c new file +49 -0
49 lines not on this page · raw message
grub-core/tests/asn1/asn1_test.h new file +44 -0
44 lines not on this page · raw message
grub-core/tests/lib/functional_test.c +1 -0
@@ -79,6 +79,7 @@ grub_functional_all_tests (grub_extcmd_context_t ctxt __attribute__ ((unused)),grub_dl_load ("cmp_test" );grub_dl_load ("mul_test" );grub_dl_load ("shift_test" ); +grub_dl_load ("asn1_test" );FOR_LIST_ELEMENTS (test, grub_test_list) ok = !grub_test_run (test) && ok;
tests/asn1_test.in new file +11 -0
@@ -0,0 +1,11 @@ +#! @BUILD_SHEBANG@ +set -e + +. "@builddir@/grub-core/modinfo.sh" + +out=`echo functional_test asn1_test | @builddir@/grub-shell` + +if [ "$(echo "$out" | tail -n 1)" != "ALL TESTS PASSED" ]; then + echo "ASN.1 test failure: $out" + exit 1 +fi
Signature · 7 lines
2.35.3 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 10/25] asn1_test: test module for libtasn1
Quoted 4 lines · Gary Lin via Grub-devel
From: Daniel Axtens <[email protected]>
Import tests from libtasn1 that don't use functionality we don't import. This test module is integrated into
functional_testso that the
Would not be it easier if you say: Import tests from libtasn1 that use functionality we import?
Quoted 183 lines
user can run the test in grub shell.
This doesn't test the full decoder but that will be exercised in test suites for coming patch sets.
Add testcase target in accordance with
5e10be48e5tests: Add check-native and check-nonnative make targetsCc Vladimir Serbinenko <[email protected]>Signed-off-by Daniel Axtens <[email protected]>Signed-off-by Gary Lin <[email protected]>--- Makefile.util.def | 6 ++++ autogen.sh | 10 +++++- grub-core/Makefile.core.def | 15 ++++++++ grub-core/tests/asn1/asn1_test.c | 49 +++++++++++++++++++++++++++ grub-core/tests/asn1/asn1_test.h | 44 ++++++++++++++++++++++++ grub-core/tests/lib/functional_test.c | 1 + tests/asn1_test.in | 11 ++++++ 7 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 grub-core/tests/asn1/asn1_test.c create mode 100644 grub-core/tests/asn1/asn1_test.h create mode 100644 tests/asn1_test.inMakefile.util.def +6
-0@@ -1257,6 +1257,12 @@ script = { common = tests/luks2_test.in; }; +script = { + testcase = native; + name = asn1_test; + common = tests/asn1_test.in; +}; + program = { testcase = native; name = example_unit_test;autogen.sh +9
-1@@ -60,12 +60,20 @@ mkdir -p grub-core/lib/libtasn1-grub/lib cp grub-core/lib/libtasn1/lib/*.[ch] grub-core/lib/libtasn1-grub/lib cp grub-core/lib/libtasn1/libtasn1.h grub-core/lib/libtasn1-grub/ +if [ -d grub-core/tests/asn1/tests ]; then + rm -rf grub-core/tests/asn1/tests +fi + +mkdir grub-core/tests/asn1/tests +cp grub-core/lib/libtasn1/tests/*.[ch] grub-core/tests/asn1/tests + for patch in \ 0001-libtasn1-disable-code-not-needed-in-grub.patch \ 0002-libtasn1-use-bound-checked-_asn1_str_cat.patch \ 0003-libtasn1-adjust-the-header-paths-in-libtasn1.h.patch \ 0004-libtasn1-Use-grub_divmod64-for-division.patch \ - 0005-libtasn1-fix-the-potential-buffer-overrun.patch ; do + 0005-libtasn1-fix-the-potential-buffer-overrun.patch \ + 0006-asn1_test-changes-for-grub-compatibility.patch ; do patch -p1 -i grub-core/lib/libtasn1-patches/$patch donegrub-core/Makefile.core.def +15
-0@@ -2621,3 +2621,18 @@ module = { /* -Wno-type-limits comes from configure.ac of libtasn1 */ cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB) -I$(srcdir)/lib/libtasn1-grub -I$(srcdir)/lib/libtasn1-grub/lib -Wno-type-limits'; }; + +module = { + name = asn1_test; + common = tests/asn1/tests/CVE-2018-1000654.c; + common = tests/asn1/tests/object-id-decoding.c; + common = tests/asn1/tests/object-id-encoding.c; + common = tests/asn1/tests/octet-string.c; + common = tests/asn1/tests/reproducers.c; + common = tests/asn1/tests/Test_overflow.c; + common = tests/asn1/tests/Test_simple.c; + common = tests/asn1/tests/Test_strings.c; + common = tests/asn1/asn1_test.c; + cflags = '-Wno-uninitialized'; + cppflags = '-I$(srcdir)/lib/libtasn1-grub -I$(srcdir)/tests/asn1/'; +};grub-core/tests/asn1/asn1_test.c new file +49
-0@@ -0,0 +1,49 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2020 IBM Corporation +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/test.h> +#include <grub/dl.h> +#include "asn1_test.h" + +/* +* libtasn1 tests - from which this is derived - are provided under GPL3+. +*/ +GRUB_MOD_LICENSE ("GPLv3+" ); + +static void +asn1_test (void ) +{ +grub_test_assert (test_CVE_2018_1000654 () ==0 ,"CVE-2018-1000654 test failed" ); + +grub_test_assert (test_object_id_encoding () ==0 ,"ASN.1 object ID encoding test failed" ); + +grub_test_assert (test_object_id_decoding () ==0 ,"ASN.1 object ID decoding test failed" ); + +grub_test_assert (test_octet_string () ==0 ,"ASN.1 octet string test failed" ); + +grub_test_assert (test_overflow () ==0 ,"ASN.1 overflow test failed" ); + +grub_test_assert (test_reproducers () ==0 ,"ASN.1 reproducers test failed" ); + +grub_test_assert (test_simple () ==0 ,"ASN.1 simple test failed" ); + +grub_test_assert (test_strings () ==0 ,"ASN.1 strings test fail" ); +} + +/* Register asn1_test method as a functional test. */ +GRUB_FUNCTIONAL_TEST (asn1_test, asn1_test);grub-core/tests/asn1/asn1_test.h new file +32
-0@@ -0,0 +1,44 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2020 IBM Corporation +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef LIBTASN1_WRAP_TESTS_H +#define LIBTASN1_WRAP_TESTS_H + +#include <libtasn1.h> +#include <grub/err.h> +#include <grub/mm.h> +#include <grub/misc.h> +#include <grub/types.h> + +int test_CVE_2018_1000654 (void ); + +int test_object_id_encoding (void ); + +int test_object_id_decoding (void );
grub-core/tests/asn1/asn1_test.h line 42
Quoted 10 lines
grub-core/tests/asn1/asn1_test.h new file +10
-0+ +int test_octet_string (void ); + +int test_overflow (void ); + +int test_reproducers (void ); + +int test_simple (void ); + +int test_strings (void );
Please prefix all these declarations with "extern".
If you do that you can add my RB.
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 10/25] asn1_test: test module for libtasn1
Quoted 9 lines · Daniel Kiper
Quoted 4 lines · Gary Lin via Grub-devel
From: Daniel Axtens <[email protected]>
Import tests from libtasn1 that don't use functionality we don't import. This test module is integrated into
functional_testso that theWould not be it easier if you say: Import tests from libtasn1 that use functionality we import?
Will update the description in the next version.
Quoted 187 lines
Quoted 187 lines
user can run the test in grub shell.
This doesn't test the full decoder but that will be exercised in test suites for coming patch sets.
Add testcase target in accordance with
5e10be48e5tests: Add check-native and check-nonnative make targetsCc Vladimir Serbinenko <[email protected]>Signed-off-by Daniel Axtens <[email protected]>Signed-off-by Gary Lin <[email protected]>--- Makefile.util.def | 6 ++++ autogen.sh | 10 +++++- grub-core/Makefile.core.def | 15 ++++++++ grub-core/tests/asn1/asn1_test.c | 49 +++++++++++++++++++++++++++ grub-core/tests/asn1/asn1_test.h | 44 ++++++++++++++++++++++++ grub-core/tests/lib/functional_test.c | 1 + tests/asn1_test.in | 11 ++++++ 7 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 grub-core/tests/asn1/asn1_test.c create mode 100644 grub-core/tests/asn1/asn1_test.h create mode 100644 tests/asn1_test.inMakefile.util.def +6
-0@@ -1257,6 +1257,12 @@ script = { common = tests/luks2_test.in; }; +script = { + testcase = native; + name = asn1_test; + common = tests/asn1_test.in; +}; + program = { testcase = native; name = example_unit_test;autogen.sh +9
-1@@ -60,12 +60,20 @@ mkdir -p grub-core/lib/libtasn1-grub/lib cp grub-core/lib/libtasn1/lib/*.[ch] grub-core/lib/libtasn1-grub/lib cp grub-core/lib/libtasn1/libtasn1.h grub-core/lib/libtasn1-grub/ +if [ -d grub-core/tests/asn1/tests ]; then + rm -rf grub-core/tests/asn1/tests +fi + +mkdir grub-core/tests/asn1/tests +cp grub-core/lib/libtasn1/tests/*.[ch] grub-core/tests/asn1/tests + for patch in \ 0001-libtasn1-disable-code-not-needed-in-grub.patch \ 0002-libtasn1-use-bound-checked-_asn1_str_cat.patch \ 0003-libtasn1-adjust-the-header-paths-in-libtasn1.h.patch \ 0004-libtasn1-Use-grub_divmod64-for-division.patch \ - 0005-libtasn1-fix-the-potential-buffer-overrun.patch ; do + 0005-libtasn1-fix-the-potential-buffer-overrun.patch \ + 0006-asn1_test-changes-for-grub-compatibility.patch ; do patch -p1 -i grub-core/lib/libtasn1-patches/$patch donegrub-core/Makefile.core.def +15
-0@@ -2621,3 +2621,18 @@ module = { /* -Wno-type-limits comes from configure.ac of libtasn1 */ cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB) -I$(srcdir)/lib/libtasn1-grub -I$(srcdir)/lib/libtasn1-grub/lib -Wno-type-limits'; }; + +module = { + name = asn1_test; + common = tests/asn1/tests/CVE-2018-1000654.c; + common = tests/asn1/tests/object-id-decoding.c; + common = tests/asn1/tests/object-id-encoding.c; + common = tests/asn1/tests/octet-string.c; + common = tests/asn1/tests/reproducers.c; + common = tests/asn1/tests/Test_overflow.c; + common = tests/asn1/tests/Test_simple.c; + common = tests/asn1/tests/Test_strings.c; + common = tests/asn1/asn1_test.c; + cflags = '-Wno-uninitialized'; + cppflags = '-I$(srcdir)/lib/libtasn1-grub -I$(srcdir)/tests/asn1/'; +};grub-core/tests/asn1/asn1_test.c new file +49
-0@@ -0,0 +1,49 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2020 IBM Corporation +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/test.h> +#include <grub/dl.h> +#include "asn1_test.h" + +/* +* libtasn1 tests - from which this is derived - are provided under GPL3+. +*/ +GRUB_MOD_LICENSE ("GPLv3+" ); + +static void +asn1_test (void ) +{ +grub_test_assert (test_CVE_2018_1000654 () ==0 ,"CVE-2018-1000654 test failed" ); + +grub_test_assert (test_object_id_encoding () ==0 ,"ASN.1 object ID encoding test failed" ); + +grub_test_assert (test_object_id_decoding () ==0 ,"ASN.1 object ID decoding test failed" ); + +grub_test_assert (test_octet_string () ==0 ,"ASN.1 octet string test failed" ); + +grub_test_assert (test_overflow () ==0 ,"ASN.1 overflow test failed" ); + +grub_test_assert (test_reproducers () ==0 ,"ASN.1 reproducers test failed" ); + +grub_test_assert (test_simple () ==0 ,"ASN.1 simple test failed" ); + +grub_test_assert (test_strings () ==0 ,"ASN.1 strings test fail" ); +} + +/* Register asn1_test method as a functional test. */ +GRUB_FUNCTIONAL_TEST (asn1_test, asn1_test);grub-core/tests/asn1/asn1_test.h new file +36
-0@@ -0,0 +1,44 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2020 IBM Corporation +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef LIBTASN1_WRAP_TESTS_H +#define LIBTASN1_WRAP_TESTS_H + +#include <libtasn1.h> +#include <grub/err.h> +#include <grub/mm.h> +#include <grub/misc.h> +#include <grub/types.h> + +int test_CVE_2018_1000654 (void ); + +int test_object_id_encoding (void ); + +int test_object_id_decoding (void ); + +int test_octet_string (void ); + +int test_overflow (void );
Quoted 9 lines
grub-core/tests/asn1/asn1_test.h line 42
Quoted 6 lines
grub-core/tests/asn1/asn1_test.h new file +6
-0+ +int test_reproducers (void ); + +int test_simple (void ); + +int test_strings (void );Please prefix all these declarations with "extern".
No problem.
Quoted 1 line
If you do that you can add my RB.
Thanks!
Gary Lin
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v18 11/25 libtasn1: Add the documentation
In reply to Gary Lin via Grub-develDocument libtasn1 in docs/grub-dev.texi and add the upgrade steps. Also add the patches to make libtasn1 compatible with grub code.
--- docs/grub-dev.texi | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
docs/grub-dev.texi +35 -0
@@ -506,6 +506,7 @@ to update it. * Gnulib:: * jsmn:: * minilzo:: +* libtasn1:: @end menu @node Gnulib
@@ -596,6 +597,40 @@ cp minilzo-2.10/*.[hc] grub-core/lib/minilzo rm -r minilzo-2.10* @end example +@node libtasn1 +@section libtasn1 + +libtasn1 is a library providing Abstract Syntax Notation One (ASN.1, as +specified by the X.680 ITU-T recommendation) parsing and structures management, +and Distinguished Encoding Rules (DER, as per X.690) encoding and decoding +functions. + +To upgrade to a new version of the libtasn1 library, download the release +tarball and copy the files into the target directory: + +@example +curl -L -O https://ftp.gnu.org/gnu/libtasn1/libtasn1-4.19.0.tar.gz +tar xf libtasn1-4.19.0.tar.gz +rm -rf grub-core/lib/libtasn1/ +mkdir -p grub-core/lib/libtasn1/lib/ +mkdir -p grub-core/lib/libtasn1/tests/ +cp libtasn1-4.19.0/@lbracechar{}README.md,COPYING@rbracechar{} grub-core/lib/libtasn1/ +cp libtasn1-4.19.0/lib/@lbracechar{}coding.c,decoding.c,element.c,element.h,errors.c,gstr.c,gstr.h,int.h,parser_aux.c,parser_aux.h,structure.c,structure.h@rbracechar{} grub-core/lib/libtasn1/lib/ +cp libtasn1-4.19.0/lib/includes/libtasn1.h grub-core/lib/libtasn1/ +cp libtasn1-4.19.0/tests/@lbracechar{}CVE-2018-1000654-1_asn1_tab.h,CVE-2018-1000654-2_asn1_tab.h,CVE-2018-1000654.c,object-id-decoding.c,object-id-encoding.c,octet-string.c,reproducers.c,Test_overflow.c,Test_simple.c,Test_strings.c@rbracechar{} grub-core/lib/libtasn1/tests +rm -rf libtasn1-4.19.0* +@end example + +After upgrading the library, it may be necessary to apply the patches in +@file{grub-core/lib/libtasn1-patches/} to adjust the code to be compatible with +GRUB. These patches were needed to use the current version of libtasn1. The +existing patches may not apply cleanly, apply at all, or even be needed for a +newer version of the library, and other patches may be needed due to changes in +the newer version. If existing patches need to be refreshed to apply cleanly, +please include updated patches as part of the a patch set sent to the list. +If new patches are needed or existing patches are not needed, also please send +additions or removals as part of any patch set upgrading libtasn1. + @node Debugging @chapter Debugging
Signature · 7 lines
2.35.3 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 11/25] libtasn1: Add the documentation
Quoted 5 lines · Gary Lin via Grub-devel
Document libtasn1 in docs/grub-dev.texi and add the upgrade steps. Also add the patches to make libtasn1 compatible with grub code.
Signed-off-by Gary Lin <[email protected]>Reviewed-by Vladimir Serbinenko <[email protected]>
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v18 12/25 key_protector: Add key protectors framework
In reply to Gary Lin via Grub-develFrom: Hernan Gatta <[email protected]>
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.
--- grub-core/Makefile.am | 1 + grub-core/Makefile.core.def | 5 +++ grub-core/disk/key_protector.c | 79 ++++++++++++++++++++++++++++++++++ include/grub/key_protector.h | 47 ++++++++++++++++++++ 4 files changed, 132 insertions(+) create mode 100644 grub-core/disk/key_protector.c create mode 100644 include/grub/key_protector.h
grub-core/Makefile.am +1 -0
@@ -90,6 +90,7 @@ endif KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/parser.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/partition.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/key_protector.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/stack_protector.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/term.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/time.h
grub-core/Makefile.core.def +5 -0
@@ -1282,6 +1282,11 @@ module = { common = disk/raid6_recover.c; }; +module = { + name = key_protector; + common = disk/key_protector.c; +}; + module = { name = scsi; common = disk/scsi.c;
grub-core/disk/key_protector.c new file +79 -0
79 lines not on this page · raw message
include/grub/key_protector.h new file +47 -0
47 lines not on this page · raw message
Signature · 7 lines
2.35.3 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 12/25] key_protector: Add key protectors framework
grub-core/disk/key_protector.c line 35
Quoted 3 lines
grub-core/disk/key_protector.c new file +3
-0+if (protector ==NULL || protector->name ==NULL ||grub_strlen (protector->name) ==0 ) +return GRUB_ERR_BAD_ARGUMENT ; +
Here and in the other places you miss grub_error. Note that the message in such technical cases should be left untranslated (no N_ mark).
Quoted 1 line
+ if (protector == NULL ||
grub_strlen(protector) == 0)
Rather than checking strlen just do protector[0] == '\0'
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 12/25] key_protector: Add key protectors framework
Quoted 7 lines · Vladimir 'phcoder' Serbinenko
grub-core/disk/key_protector.c line 35
Quoted 3 lines
grub-core/disk/key_protector.c new file +3
-0+if (protector ==NULL || protector->name ==NULL ||grub_strlen (protector->name) ==0 ) +return GRUB_ERR_BAD_ARGUMENT ; +Here and in the other places you miss
grub_error. Note that the message in such technical cases should be left untranslated (no N_ mark).
Ok. I'll add grub_error to provide the better error messages.
Quoted 3 lines
Quoted 1 line
+ if (protector == NULL ||
grub_strlen(protector) == 0)Rather than checking strlen just do protector[0] == '\0'
Ah, right. It's more efficient.
Gary Lin
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v18 13/25 tss2: Add TPM2 buffer handling functions
In reply to Gary Lin via Grub-develAs the prepartion to support TPM2 Software Stack (TSS2), this commit implements the TPM2 buffer handling functions to pack data for the TPM2 commands and unpack the data from the response.
--- grub-core/lib/tss2/buffer.c | 149 +++++++++++++++++++++++++++++++ grub-core/lib/tss2/tss2_buffer.h | 66 ++++++++++++++ 2 files changed, 215 insertions(+) create mode 100644 grub-core/lib/tss2/buffer.c create mode 100644 grub-core/lib/tss2/tss2_buffer.h
grub-core/lib/tss2/buffer.c new file +149 -0
@@ -0,0 +1,149 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 Free Software Foundation, Inc. +* Copyright (C) 2022 Microsoft Corporation +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/misc.h> + +#include <tss2_buffer.h> + +void grub_tpm2_buffer_init (grub_tpm2_buffer_t buffer) +{ +grub_memset (buffer->data,0 ,sizeof (buffer->data)); + buffer->size =0 ; + buffer->offset =0 ; + buffer->cap =sizeof (buffer->data); + buffer->error =0 ; +} + +void +grub_tpm2_buffer_pack (grub_tpm2_buffer_t buffer,const void * data, +grub_size_t size) +{ +grub_uint32_t r = buffer->cap - buffer->size; + +if (buffer->error) +return ; + +if (size > r) + { + buffer->error =1 ; +return ; + } + +grub_memcpy (&buffer->data[buffer->size], (void *) data, size); + buffer->size += size; +} + +void +grub_tpm2_buffer_pack_u8 (grub_tpm2_buffer_t buffer,grub_uint8_t value) +{ +grub_tpm2_buffer_pack (buffer, (const char *) &value,sizeof (value)); +} + +void +grub_tpm2_buffer_pack_u16 (grub_tpm2_buffer_t buffer,grub_uint16_t value) +{ +grub_uint16_t tmp =grub_cpu_to_be16 (value); + +grub_tpm2_buffer_pack (buffer, (const char *) &tmp,sizeof (tmp)); +} + +void +grub_tpm2_buffer_pack_u32 (grub_tpm2_buffer_t buffer,grub_uint32_t value) +{ +grub_uint32_t tmp =grub_cpu_to_be32 (value); + +grub_tpm2_buffer_pack (buffer, (const char *) &tmp,sizeof (tmp)); +} + +void +grub_tpm2_buffer_unpack (grub_tpm2_buffer_t buffer,void * data, +grub_size_t size) +{ +grub_uint32_t r = buffer->size - buffer->offset; + +if (buffer->error) +return ; + +if (size > r) + { + buffer->error =1 ; +return ; + } + +grub_memcpy (data, &buffer->data[buffer->offset], size); + buffer->offset += size; +} + +void +grub_tpm2_buffer_unpack_u8 (grub_tpm2_buffer_t buffer,grub_uint8_t * value) +{ +grub_uint32_t r = buffer->size - buffer->offset; + +if (buffer->error) +return ; + +if (sizeof (*value) > r) + { + buffer->error =1 ; +return ; + } + +grub_memcpy (value, &buffer->data[buffer->offset],sizeof (*value)); + buffer->offset +=sizeof (*value); +} + +void +grub_tpm2_buffer_unpack_u16 (grub_tpm2_buffer_t buffer,grub_uint16_t * value) +{ +grub_uint16_t tmp; +grub_uint32_t r = buffer->size - buffer->offset; + +if (buffer->error) +return ; + +if (sizeof (tmp) > r) + { + buffer->error =1 ; +return ; + } + +grub_memcpy (&tmp, &buffer->data[buffer->offset],sizeof (tmp)); + buffer->offset +=sizeof (tmp); + *value =grub_be_to_cpu16 (tmp); +} + +void +grub_tpm2_buffer_unpack_u32 (grub_tpm2_buffer_t buffer,grub_uint32_t * value) +{ +grub_uint32_t tmp; +grub_uint32_t r = buffer->size - buffer->offset; + +if (buffer->error) +return ; + +if (sizeof (tmp) > r) + { + buffer->error =1 ; +return ; + } + +grub_memcpy (&tmp, &buffer->data[buffer->offset],sizeof (tmp)); + buffer->offset +=sizeof (tmp); + *value =grub_be_to_cpu32 (tmp); +}
grub-core/lib/tss2/tss2_buffer.h new file +66 -0
66 lines not on this page · raw message
Signature · 7 lines
2.35.3 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 13/25] tss2: Add TPM2 buffer handling functions
Quoted 20 lines · Gary Lin via Grub-devel
As the prepartion to support TPM2 Software Stack (TSS2), this commit implements the TPM2 buffer handling functions to pack data for the TPM2 commands and unpack the data from the response.
Cc Stefan Berger <[email protected]>Signed-off-by Hernan Gatta <[email protected]>Signed-off-by Gary Lin <[email protected]>--- grub-core/lib/tss2/buffer.c | 149 +++++++++++++++++++++++++++++++ grub-core/lib/tss2/tss2_buffer.h | 66 ++++++++++++++ 2 files changed, 215 insertions(+) create mode 100644 grub-core/lib/tss2/buffer.c create mode 100644 grub-core/lib/tss2/tss2_buffer.hgrub-core/lib/tss2/buffer.c new file +0
-0
grub-core/lib/tss2/buffer.c line 4
Quoted 4 lines
grub-core/lib/tss2/buffer.c new file +4
-0@@ -0,0 +1,149 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 Free Software Foundation, Inc. +* Copyright (C) 2022 Microsoft Corporation
Wrong order. The "Free Software Foundation" line should go behind the "Microsoft Corporation".
Quoted 19 lines
grub-core/lib/tss2/buffer.c new file +19
-0+* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/misc.h> + +#include <tss2_buffer.h> + +void grub_tpm2_buffer_init (grub_tpm2_buffer_t buffer)
grub-core/lib/tss2/buffer.c line 34
Quoted 10 lines
grub-core/lib/tss2/buffer.c new file +10
-0+{ +grub_memset (buffer->data,0 ,sizeof (buffer->data)); + buffer->size =0 ; + buffer->offset =0 ; + buffer->cap =sizeof (buffer->data); + buffer->error =0 ; +} + +void +grub_tpm2_buffer_pack (grub_tpm2_buffer_t buffer, const void* data,
s/void* data/void *data/
Quoted 4 lines
grub-core/lib/tss2/buffer.c new file +4
-0+ grub_size_t size) +{ +grub_uint32_t r = buffer->cap - buffer->size; +
grub-core/lib/tss2/buffer.c line 48
Quoted 10 lines
grub-core/lib/tss2/buffer.c new file +10
-0+if (buffer->error) +return ; + +if (size > r) + { + buffer->error =1 ; +return ; + } + +grub_memcpy (&buffer->data[buffer->size], (void *) data, size);
s/void*/void */
grub-core/lib/tss2/buffer.c line 55
Quoted 7 lines
grub-core/lib/tss2/buffer.c new file +7
-0+ buffer->size += size; +} + +void +grub_tpm2_buffer_pack_u8 (grub_tpm2_buffer_t buffer,grub_uint8_t value) +{ +grub_tpm2_buffer_pack (buffer, (const char *) &value,sizeof (value));
s/const char*/const char */
Wait, why do you cast to "const char*" if the grub_tpm2_buffer_pack() second argument is "const void *"? I think it should be changed. If yes please fix similar problems everywhere.
grub-core/lib/tss2/buffer.c line 63
Quoted 8 lines
grub-core/lib/tss2/buffer.c new file +8
-0+} + +void +grub_tpm2_buffer_pack_u16 (grub_tpm2_buffer_t buffer,grub_uint16_t value) +{ +grub_uint16_t tmp =grub_cpu_to_be16 (value); + +grub_tpm2_buffer_pack (buffer, (const char *) &tmp,sizeof (tmp));
Ditto and below please...
grub-core/lib/tss2/buffer.c line 75
Quoted 12 lines
grub-core/lib/tss2/buffer.c new file +12
-0+} + +void +grub_tpm2_buffer_pack_u32 (grub_tpm2_buffer_t buffer,grub_uint32_t value) +{ +grub_uint32_t tmp =grub_cpu_to_be32 (value); + +grub_tpm2_buffer_pack (buffer, (const char *) &tmp,sizeof (tmp)); +} + +void +grub_tpm2_buffer_unpack (grub_tpm2_buffer_t buffer, void* data,
s/void* data/void *data/
Quoted 9 lines
grub-core/lib/tss2/buffer.c new file +9
-0+ grub_size_t size) +{ +grub_uint32_t r = buffer->size - buffer->offset; + +if (buffer->error) +return ; + +if (size > r) + {
grub-core/lib/tss2/buffer.c line 94
Quoted 10 lines
grub-core/lib/tss2/buffer.c new file +10
-0+ buffer->error =1 ; +return ; + } + +grub_memcpy (data, &buffer->data[buffer->offset], size); + buffer->offset += size; +} + +void +grub_tpm2_buffer_unpack_u8 (grub_tpm2_buffer_t buffer,grub_uint8_t * value)
Again, s/grub_uint8_t* value/grub_uint8_t *value/. Please fix similar issues everywhere...
Quoted 61 lines
grub-core/lib/tss2/buffer.c new file +55
-0+{ +grub_uint32_t r = buffer->size - buffer->offset; + +if (buffer->error) +return ; + +if (sizeof (*value) > r) + { + buffer->error =1 ; +return ; + } + +grub_memcpy (value, &buffer->data[buffer->offset],sizeof (*value)); + buffer->offset +=sizeof (*value); +} + +void +grub_tpm2_buffer_unpack_u16 (grub_tpm2_buffer_t buffer,grub_uint16_t * value) +{ +grub_uint16_t tmp; +grub_uint32_t r = buffer->size - buffer->offset; + +if (buffer->error) +return ; + +if (sizeof (tmp) > r) + { + buffer->error =1 ; +return ; + } + +grub_memcpy (&tmp, &buffer->data[buffer->offset],sizeof (tmp)); + buffer->offset +=sizeof (tmp); + *value =grub_be_to_cpu16 (tmp); +} + +void +grub_tpm2_buffer_unpack_u32 (grub_tpm2_buffer_t buffer,grub_uint32_t * value) +{ +grub_uint32_t tmp; +grub_uint32_t r = buffer->size - buffer->offset; + +if (buffer->error) +return ; + +if (sizeof (tmp) > r) + { + buffer->error =1 ; +return ; + } + +grub_memcpy (&tmp, &buffer->data[buffer->offset],sizeof (tmp)); + buffer->offset +=sizeof (tmp); + *value =grub_be_to_cpu32 (tmp); +}grub-core/lib/tss2/tss2_buffer.h new file +0
-0
grub-core/lib/tss2/tss2_buffer.h line 4
Quoted 4 lines
grub-core/lib/tss2/tss2_buffer.h new file +4
-0@@ -0,0 +1,66 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 Free Software Foundation, Inc. +* Copyright (C) 2022 Microsoft Corporation
Again, wrong order...
Quoted 49 lines
grub-core/lib/tss2/tss2_buffer.h new file +49
-0+* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef GRUB_TPM2_BUFFER_HEADER +#define GRUB_TPM2_BUFFER_HEADER 1 + +#include <grub/types.h> + +#define GRUB_TPM2_BUFFER_CAPACITY 4096 + +struct grub_tpm2_buffer +{ +grub_uint8_t data[GRUB_TPM2_BUFFER_CAPACITY ]; +grub_size_t size; +grub_size_t offset; +grub_size_t cap; +grub_uint8_t error; +}; +typedef struct grub_tpm2_buffer *grub_tpm2_buffer_t ; + +void +grub_tpm2_buffer_init (grub_tpm2_buffer_t buffer); + +void +grub_tpm2_buffer_pack (grub_tpm2_buffer_t buffer,const void * data, +grub_size_t size); + +void +grub_tpm2_buffer_pack_u8 (grub_tpm2_buffer_t buffer,grub_uint8_t value); + +void +grub_tpm2_buffer_pack_u16 (grub_tpm2_buffer_t buffer,grub_uint16_t value); + +void +grub_tpm2_buffer_pack_u32 (grub_tpm2_buffer_t buffer,grub_uint32_t value); + +void +grub_tpm2_buffer_unpack (grub_tpm2_buffer_t buffer, void* data,
grub-core/lib/tss2/tss2_buffer.h line 64
Quoted 10 lines
grub-core/lib/tss2/tss2_buffer.h new file +10
-0+ grub_size_t size); + +void +grub_tpm2_buffer_unpack_u8 (grub_tpm2_buffer_t buffer,grub_uint8_t * value); + +void +grub_tpm2_buffer_unpack_u16 (grub_tpm2_buffer_t buffer,grub_uint16_t * value); + +void +grub_tpm2_buffer_unpack_u32 (grub_tpm2_buffer_t buffer,grub_uint32_t * value);
Missing extern for all functions. Please fix it (in all patches).
If you fix all these minor issues you can add my RB to the patch.
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 13/25] tss2: Add TPM2 buffer handling functions
Quoted 15 lines · Daniel Kiper
Quoted 14 lines · Gary Lin via Grub-devel
As the prepartion to support TPM2 Software Stack (TSS2), this commit implements the TPM2 buffer handling functions to pack data for the TPM2 commands and unpack the data from the response.
Cc Stefan Berger <[email protected]>Signed-off-by Hernan Gatta <[email protected]>Signed-off-by Gary Lin <[email protected]>--- grub-core/lib/tss2/buffer.c | 149 +++++++++++++++++++++++++++++++ grub-core/lib/tss2/tss2_buffer.h | 66 ++++++++++++++ 2 files changed, 215 insertions(+) create mode 100644 grub-core/lib/tss2/buffer.c create mode 100644 grub-core/lib/tss2/tss2_buffer.h
Quoted 14 lines
grub-core/lib/tss2/buffer.c line 4
Quoted 10 lines
grub-core/lib/tss2/buffer.c new file +4
-0@@ -0,0 +1,149 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 Free Software Foundation, Inc. +* Copyright (C) 2022 Microsoft Corporation Wrong order. The "Free Software Foundation" line should go behind the "Microsoft Corporation".
Oops. I'll fix the order in all affected files.
Quoted 23 lines
Quoted 23 lines
grub-core/lib/tss2/buffer.c new file +23
-0+* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/misc.h> + +#include <tss2_buffer.h> + +void grub_tpm2_buffer_init (grub_tpm2_buffer_t buffer) +{ +grub_memset (buffer->data,0 ,sizeof (buffer->data)); + buffer->size =0 ; + buffer->offset =0 ;
Quoted 9 lines
grub-core/lib/tss2/buffer.c line 34
Quoted 6 lines
grub-core/lib/tss2/buffer.c new file +6
-0+ buffer->cap =sizeof (buffer->data); + buffer->error =0 ; +} + +void +grub_tpm2_buffer_pack (grub_tpm2_buffer_t buffer, const void* data,s/void* data/void *data/
Will fix it in the next version.
Quoted 8 lines
Quoted 8 lines
grub-core/lib/tss2/buffer.c new file +8
-0+ grub_size_t size) +{ +grub_uint32_t r = buffer->cap - buffer->size; + +if (buffer->error) +return ; + +if (size > r)
Quoted 9 lines
grub-core/lib/tss2/buffer.c line 48
Quoted 6 lines
grub-core/lib/tss2/buffer.c new file +6
-0+ { + buffer->error =1 ; +return ; + } + +grub_memcpy (&buffer->data[buffer->size], (void *) data, size);s/void*/void */
Will fix it.
Quoted 10 lines
grub-core/lib/tss2/buffer.c line 55
Quoted 7 lines
grub-core/lib/tss2/buffer.c new file +7
-0+ buffer->size += size; +} + +void +grub_tpm2_buffer_pack_u8 (grub_tpm2_buffer_t buffer,grub_uint8_t value) +{ +grub_tpm2_buffer_pack (buffer, (const char *) &value,sizeof (value));s/const char*/const char */
Quoted 4 lines
Wait, why do you cast to "const char*" if the
grub_tpm2_buffer_pack()second argument is "const void *"? I think it should be changed. If yes please fix similar problems everywhere.
Right, it's should be "const void *". I'll fix all those pack functions.
Quoted 11 lines
grub-core/lib/tss2/buffer.c line 63
Quoted 8 lines
grub-core/lib/tss2/buffer.c new file +8
-0+} + +void +grub_tpm2_buffer_pack_u16 (grub_tpm2_buffer_t buffer,grub_uint16_t value) +{ +grub_uint16_t tmp =grub_cpu_to_be16 (value); + +grub_tpm2_buffer_pack (buffer, (const char *) &tmp,sizeof (tmp));Ditto and below please...
Got it.
Quoted 6 lines
Quoted 6 lines
grub-core/lib/tss2/buffer.c new file +6
-0+} + +void +grub_tpm2_buffer_pack_u32 (grub_tpm2_buffer_t buffer,grub_uint32_t value) +{ +grub_uint32_t tmp =grub_cpu_to_be32 (value);
Quoted 9 lines
grub-core/lib/tss2/buffer.c line 75
Quoted 6 lines
grub-core/lib/tss2/buffer.c new file +6
-0+ +grub_tpm2_buffer_pack (buffer, (const char *) &tmp,sizeof (tmp)); +} + +void +grub_tpm2_buffer_unpack (grub_tpm2_buffer_t buffer, void* data,s/void* data/void *data/
Okay.
Quoted 13 lines
Quoted 13 lines
grub-core/lib/tss2/buffer.c new file +13
-0+ grub_size_t size) +{ +grub_uint32_t r = buffer->size - buffer->offset; + +if (buffer->error) +return ; + +if (size > r) + { + buffer->error =1 ; +return ; + } +
Quoted 9 lines
grub-core/lib/tss2/buffer.c line 94
Quoted 6 lines
grub-core/lib/tss2/buffer.c new file +6
-0+grub_memcpy (data, &buffer->data[buffer->offset], size); + buffer->offset += size; +} + +void +grub_tpm2_buffer_unpack_u8 (grub_tpm2_buffer_t buffer,grub_uint8_t * value)Again, s/grub_uint8_t* value/grub_uint8_t *value/. Please fix similar issues everywhere...
I'll check all patchs again.
Quoted 121 lines
Quoted 61 lines
grub-core/lib/tss2/buffer.c new file +55
-0+{ +grub_uint32_t r = buffer->size - buffer->offset; + +if (buffer->error) +return ; + +if (sizeof (*value) > r) + { + buffer->error =1 ; +return ; + } + +grub_memcpy (value, &buffer->data[buffer->offset],sizeof (*value)); + buffer->offset +=sizeof (*value); +} + +void +grub_tpm2_buffer_unpack_u16 (grub_tpm2_buffer_t buffer,grub_uint16_t * value) +{ +grub_uint16_t tmp; +grub_uint32_t r = buffer->size - buffer->offset; + +if (buffer->error) +return ; + +if (sizeof (tmp) > r) + { + buffer->error =1 ; +return ; + } + +grub_memcpy (&tmp, &buffer->data[buffer->offset],sizeof (tmp)); + buffer->offset +=sizeof (tmp); + *value =grub_be_to_cpu16 (tmp); +} + +void +grub_tpm2_buffer_unpack_u32 (grub_tpm2_buffer_t buffer,grub_uint32_t * value) +{ +grub_uint32_t tmp; +grub_uint32_t r = buffer->size - buffer->offset; + +if (buffer->error) +return ; + +if (sizeof (tmp) > r) + { + buffer->error =1 ; +return ; + } + +grub_memcpy (&tmp, &buffer->data[buffer->offset],sizeof (tmp)); + buffer->offset +=sizeof (tmp); + *value =grub_be_to_cpu32 (tmp); +}grub-core/lib/tss2/tss2_buffer.h new file +0
-0grub-core/lib/tss2/tss2_buffer.h line 4
Quoted 4 lines
grub-core/lib/tss2/tss2_buffer.h new file +4
-0@@ -0,0 +1,66 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 Free Software Foundation, Inc. +* Copyright (C) 2022 Microsoft Corporation Again, wrong order...
Quoted 53 lines
grub-core/lib/tss2/tss2_buffer.h new file +53
-0+* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef GRUB_TPM2_BUFFER_HEADER +#define GRUB_TPM2_BUFFER_HEADER 1 + +#include <grub/types.h> + +#define GRUB_TPM2_BUFFER_CAPACITY 4096 + +struct grub_tpm2_buffer +{ +grub_uint8_t data[GRUB_TPM2_BUFFER_CAPACITY ]; +grub_size_t size; +grub_size_t offset; +grub_size_t cap; +grub_uint8_t error; +}; +typedef struct grub_tpm2_buffer *grub_tpm2_buffer_t ; + +void +grub_tpm2_buffer_init (grub_tpm2_buffer_t buffer); + +void +grub_tpm2_buffer_pack (grub_tpm2_buffer_t buffer,const void * data, +grub_size_t size); + +void +grub_tpm2_buffer_pack_u8 (grub_tpm2_buffer_t buffer,grub_uint8_t value); + +void +grub_tpm2_buffer_pack_u16 (grub_tpm2_buffer_t buffer,grub_uint16_t value); + +void +grub_tpm2_buffer_pack_u32 (grub_tpm2_buffer_t buffer,grub_uint32_t value); + +void +grub_tpm2_buffer_unpack (grub_tpm2_buffer_t buffer,void * data, +grub_size_t size); + +void +grub_tpm2_buffer_unpack_u8 (grub_tpm2_buffer_t buffer,grub_uint8_t * value);
Quoted 9 lines
grub-core/lib/tss2/tss2_buffer.h line 64
Quoted 6 lines
grub-core/lib/tss2/tss2_buffer.h new file +6
-0+ +void +grub_tpm2_buffer_unpack_u16 (grub_tpm2_buffer_t buffer,grub_uint16_t * value); + +void +grub_tpm2_buffer_unpack_u32 (grub_tpm2_buffer_t buffer,grub_uint32_t * value);Missing extern for all functions. Please fix it (in all patches).
Will add extern to the tss2 functions.
Quoted 2 lines
If you fix all these minor issues you can add my RB to the patch.
Thanks,
Gary Lin
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v18 14/25 tss2: Add TPM2 types and Marshal/Unmarshal functions
In reply to Gary Lin via Grub-develThis commit adds the necessary TPM2 types and structs as the preparation for the TPM2 Software Stack (TSS2) support. The Marshal/Unmarshal functions are also added to handle the data structure to be submitted to TPM2 commands and to be received from the response.
--- grub-core/lib/tss2/tss2_mu.c | 1170 +++++++++++++++++++++++++++++ grub-core/lib/tss2/tss2_mu.h | 397 ++++++++++ grub-core/lib/tss2/tss2_structs.h | 768 +++++++++++++++++++ grub-core/lib/tss2/tss2_types.h | 404 ++++++++++ 4 files changed, 2739 insertions(+) create mode 100644 grub-core/lib/tss2/tss2_mu.c create mode 100644 grub-core/lib/tss2/tss2_mu.h create mode 100644 grub-core/lib/tss2/tss2_structs.h create mode 100644 grub-core/lib/tss2/tss2_types.h
grub-core/lib/tss2/tss2_mu.c new file +1170 -0
@@ -0,0 +1,1170 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 Free Software Foundation, Inc. +* Copyright (C) 2022 Microsoft Corporation +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/misc.h> + +#include <tss2_mu.h> + +void +grub_Tss2_MU_TPMS_AUTH_COMMAND_Marshal (grub_tpm2_buffer_t buffer, +const TPMS_AUTH_COMMAND * authCommand) +{ +grub_uint32_t start; +grub_uint32_t tmp; + +grub_tpm2_buffer_pack_u32 (buffer,0 ); + start = buffer->size; + +grub_tpm2_buffer_pack_u32 (buffer, authCommand->sessionHandle); + +grub_tpm2_buffer_pack_u16 (buffer, authCommand->nonce.size); +grub_tpm2_buffer_pack (buffer, authCommand->nonce.buffer, + authCommand->nonce.size); + +grub_tpm2_buffer_pack_u8 (buffer, + *((const grub_uint8_t *) &authCommand->sessionAttributes)); + +grub_tpm2_buffer_pack_u16 (buffer, authCommand->hmac.size); +grub_tpm2_buffer_pack (buffer, authCommand->hmac.buffer, + authCommand->hmac.size); + + tmp =grub_cpu_to_be32 (buffer->size - start); +grub_memcpy (&buffer->data[start -sizeof (grub_uint32_t)], &tmp, +sizeof (tmp)); +} + +void +grub_Tss2_MU_TPM2B_Marshal (grub_tpm2_buffer_t buffer, +const grub_uint16_t size, +const grub_uint8_t * b) +{ +grub_tpm2_buffer_pack_u16 (buffer, size); + +for (grub_uint16_t i =0 ; i < size; i++) +grub_tpm2_buffer_pack_u8 (buffer, b[i]); +} + +void +grub_Tss2_MU_TPMU_SYM_KEY_BITS_Marshal (grub_tpm2_buffer_t buffer, +const TPMI_ALG_SYM_OBJECT algorithm, +const TPMU_SYM_KEY_BITS *p) +{ +switch (algorithm) + { +case TPM_ALG_AES : +case TPM_ALG_SM4 : +case TPM_ALG_CAMELLIA : +case TPM_ALG_XOR : +grub_tpm2_buffer_pack_u16 (buffer, *((const grub_uint16_t *) p)); +break ; +case TPM_ALG_NULL : +break ; +default : + buffer->error =1 ; +break ; + } +} + +void +grub_Tss2_MU_TPMU_SYM_MODE_Marshal (grub_tpm2_buffer_t buffer, +const TPMI_ALG_SYM_OBJECT algorithm, +const TPMU_SYM_MODE *p) +{ +switch (algorithm) + { +case TPM_ALG_AES : +case TPM_ALG_SM4 : +case TPM_ALG_CAMELLIA : +grub_tpm2_buffer_pack_u16 (buffer, *((const grub_uint16_t *) p)); +break ; +case TPM_ALG_XOR : +case TPM_ALG_NULL : +break ; +default : + buffer->error =1 ; +break ; + } +} + +void +grub_Tss2_MU_TPMT_SYM_DEF_Marshal (grub_tpm2_buffer_t buffer, +const TPMT_SYM_DEF *p) +{ +grub_tpm2_buffer_pack_u16 (buffer, p->algorithm); +grub_Tss2_MU_TPMU_SYM_KEY_BITS_Marshal (buffer, p->algorithm, &p->keyBits); +grub_Tss2_MU_TPMU_SYM_MODE_Marshal (buffer, p->algorithm, &p->mode); +} + +void +grub_Tss2_MU_TPMS_PCR_SELECTION_Marshal (grub_tpm2_buffer_t buffer, +const TPMS_PCR_SELECTION * pcrSelection) +{ +grub_tpm2_buffer_pack_u16 (buffer, pcrSelection->hash); +grub_tpm2_buffer_pack_u8 (buffer, pcrSelection->sizeOfSelect); + +for (grub_uint32_t i =0 ; i < pcrSelection->sizeOfSelect; i++) +grub_tpm2_buffer_pack_u8 (buffer, pcrSelection->pcrSelect[i]); +} + +void +grub_Tss2_MU_TPML_PCR_SELECTION_Marshal (grub_tpm2_buffer_t buffer, +const TPML_PCR_SELECTION * pcrSelection) +{ +grub_tpm2_buffer_pack_u32 (buffer, pcrSelection->count); + +for (grub_uint32_t i =0 ; i < pcrSelection->count; i++) +grub_Tss2_MU_TPMS_PCR_SELECTION_Marshal (buffer, + &pcrSelection->pcrSelections[i]); +} + +void +grub_Tss2_MU_TPMA_OBJECT_Marshal (grub_tpm2_buffer_t buffer, +const TPMA_OBJECT *p) +{ +grub_tpm2_buffer_pack_u32 (buffer, *((const grub_uint32_t *) p)); +} + +void +grub_Tss2_MU_TPMS_SCHEME_XOR_Marshal (grub_tpm2_buffer_t buffer, +const TPMS_SCHEME_XOR *p) +{ +grub_tpm2_buffer_pack_u16 (buffer, p->hashAlg); +grub_tpm2_buffer_pack_u16 (buffer, p->kdf); +} + +void +grub_Tss2_MU_TPMS_SCHEME_HMAC_Marshal (grub_tpm2_buffer_t buffer, +const TPMS_SCHEME_HMAC *p) +{ +grub_tpm2_buffer_pack_u16 (buffer, p->hashAlg); +} + +void +grub_Tss2_MU_TPMU_SCHEME_KEYEDHASH_Marshal (grub_tpm2_buffer_t buffer, +const TPMI_ALG_KEYEDHASH_SCHEME scheme, +const TPMU_SCHEME_KEYEDHASH *p) +{ +switch (scheme) + { +case TPM_ALG_HMAC : +grub_Tss2_MU_TPMS_SCHEME_HMAC_Marshal (buffer, &p->hmac); +break ; +case TPM_ALG_XOR : +grub_Tss2_MU_TPMS_SCHEME_XOR_Marshal (buffer, &p->exclusiveOr); +break ; +case TPM_ALG_NULL : +break ; +default : + buffer->error =1 ; +break ; + } +} + +void +grub_Tss2_MU_TPMT_KEYEDHASH_SCHEME_Marshal (grub_tpm2_buffer_t buffer, +const TPMT_KEYEDHASH_SCHEME *p) +{ +grub_tpm2_buffer_pack_u16 (buffer, p->scheme); +grub_Tss2_MU_TPMU_SCHEME_KEYEDHASH_Marshal (buffer, p->scheme, &p->details); +} + +void +grub_Tss2_MU_TPMS_KEYEDHASH_PARMS_Marshal (grub_tpm2_buffer_t buffer, +const TPMS_KEYEDHASH_PARMS *p) +{ +grub_Tss2_MU_TPMT_KEYEDHASH_SCHEME_Marshal (buffer, &p->scheme); +} + +void +grub_Tss2_MU_TPMT_SYM_DEF_OBJECT_Marshal (grub_tpm2_buffer_t buffer, +const TPMT_SYM_DEF_OBJECT *p) +{ +grub_tpm2_buffer_pack_u16 (buffer, p->algorithm); +grub_Tss2_MU_TPMU_SYM_KEY_BITS_Marshal (buffer, p->algorithm, &p->keyBits); +grub_Tss2_MU_TPMU_SYM_MODE_Marshal (buffer, p->algorithm, &p->mode); +} + +void +grub_Tss2_MU_TPMU_ASYM_SCHEME_Marshal (grub_tpm2_buffer_t buffer, +const TPMI_ALG_RSA_DECRYPT scheme, +const TPMU_ASYM_SCHEME *p __attribute__ ((unused))) +{ +switch (scheme) + { +case TPM_ALG_NULL : +break ; +default : +/* Unsupported */ + buffer->error =1 ; +break ; + } +} + +void +grub_Tss2_MU_TPMT_RSA_SCHEME_Marshal (grub_tpm2_buffer_t buffer, +const TPMT_RSA_SCHEME *p) +{ +grub_tpm2_buffer_pack_u16 (buffer, p->scheme); +grub_Tss2_MU_TPMU_ASYM_SCHEME_Marshal (buffer, p->scheme, &p->details); +} + +void +grub_Tss2_MU_TPMS_RSA_PARMS_Marshal (grub_tpm2_buffer_t buffer, +const TPMS_RSA_PARMS *p) +{ +grub_Tss2_MU_TPMT_SYM_DEF_OBJECT_Marshal (buffer, &p->symmetric); +grub_Tss2_MU_TPMT_RSA_SCHEME_Marshal (buffer, &p->scheme); +grub_tpm2_buffer_pack_u16 (buffer, p->keyBits); +grub_tpm2_buffer_pack_u32 (buffer, p->exponent); +} + +void +grub_Tss2_MU_TPMS_SYMCIPHER_PARMS_Marshal (grub_tpm2_buffer_t buffer, +const TPMS_SYMCIPHER_PARMS *p) +{ +grub_Tss2_MU_TPMT_SYM_DEF_OBJECT_Marshal (buffer, &p->sym); +} + +void +grub_Tss2_MU_TPMT_ECC_SCHEME_Marshal (grub_tpm2_buffer_t buffer, +const TPMT_ECC_SCHEME *p) +{ +grub_tpm2_buffer_pack_u16 (buffer, p->scheme); +grub_Tss2_MU_TPMU_ASYM_SCHEME_Marshal (buffer, p->scheme, &p->details); +} + +void +grub_Tss2_MU_TPMU_KDF_SCHEME_Marshal (grub_tpm2_buffer_t buffer, +const TPMI_ALG_KDF scheme, +const TPMU_KDF_SCHEME *p) +{ +switch (scheme) + { +case TPM_ALG_MGF1 : +grub_tpm2_buffer_pack_u16 (buffer, p->mgf1.hashAlg); +break ; +case TPM_ALG_KDF1_SP800_56A : +grub_tpm2_buffer_pack_u16 (buffer, p->kdf1_sp800_56a.hashAlg); +break ; +case TPM_ALG_KDF2 : +grub_tpm2_buffer_pack_u16 (buffer, p->kdf2.hashAlg); +break ; +case TPM_ALG_KDF1_SP800_108 : +grub_tpm2_buffer_pack_u16 (buffer, p->kdf1_sp800_108.hashAlg); +break ; +case TPM_ALG_NULL : +break ; +default : + buffer->error =1 ; +break ; + } +} + +void +grub_Tss2_MU_TPMT_KDF_SCHEME_Marshal (grub_tpm2_buffer_t buffer, +const TPMT_KDF_SCHEME *p) +{ +grub_tpm2_buffer_pack_u16 (buffer, p->scheme); +grub_Tss2_MU_TPMU_KDF_SCHEME_Marshal (buffer, p->scheme, &p->details); +} + +void +grub_Tss2_MU_TPMS_ECC_PARMS_Marshal (grub_tpm2_buffer_t buffer, +const TPMS_ECC_PARMS *p) +{ +grub_Tss2_MU_TPMT_SYM_DEF_OBJECT_Marshal (buffer, &p->symmetric); +grub_Tss2_MU_TPMT_ECC_SCHEME_Marshal (buffer, &p->scheme); +grub_tpm2_buffer_pack_u16 (buffer, p->curveID); +grub_Tss2_MU_TPMT_KDF_SCHEME_Marshal (buffer, &p->kdf); +} + +void +grub_Tss2_MU_TPMU_PUBLIC_PARMS_Marshal (grub_tpm2_buffer_t buffer, +const grub_uint32_t type, +const TPMU_PUBLIC_PARMS *p) +{ +switch (type) + { +case TPM_ALG_KEYEDHASH : +grub_Tss2_MU_TPMS_KEYEDHASH_PARMS_Marshal (buffer, &p->keyedHashDetail); +break ; +case TPM_ALG_SYMCIPHER : +grub_Tss2_MU_TPMS_SYMCIPHER_PARMS_Marshal (buffer, &p->symDetail); +break ; +case TPM_ALG_RSA : +grub_Tss2_MU_TPMS_RSA_PARMS_Marshal (buffer, &p->rsaDetail); +break ; +case TPM_ALG_ECC : +grub_Tss2_MU_TPMS_ECC_PARMS_Marshal (buffer, &p->eccDetail); +break ; +default : + buffer->error =1 ; +break ; + } +} + +void +grub_Tss2_MU_TPMS_ECC_POINT_Marshal (grub_tpm2_buffer_t buffer, +const TPMS_ECC_POINT *p) +{ +grub_Tss2_MU_TPM2B_Marshal (buffer, p->x.size, p->x.buffer); +grub_Tss2_MU_TPM2B_Marshal (buffer, p->y.size, p->y.buffer); +} + +void +grub_Tss2_MU_TPMU_PUBLIC_ID_Marshal (grub_tpm2_buffer_t buffer, +const TPMI_ALG_PUBLIC type, +const TPMU_PUBLIC_ID *p) +{ +switch (type) + { +case TPM_ALG_KEYEDHASH : +grub_Tss2_MU_TPM2B_Marshal (buffer, p->keyedHash.size, + p->keyedHash.buffer); +break ; +case TPM_ALG_SYMCIPHER : +grub_Tss2_MU_TPM2B_Marshal (buffer, p->sym.size, p->sym.buffer); +break ; +case TPM_ALG_RSA : +grub_Tss2_MU_TPM2B_Marshal (buffer, p->rsa.size, p->rsa.buffer); +break ; +case TPM_ALG_ECC : +grub_Tss2_MU_TPMS_ECC_POINT_Marshal (buffer, &p->ecc); +break ; +default : + buffer->error =1 ; +break ; + } +} + +void +grub_Tss2_MU_TPMT_PUBLIC_PARMS_Marshal (grub_tpm2_buffer_t buffer, +const TPMT_PUBLIC_PARMS *p) +{ +grub_tpm2_buffer_pack_u16 (buffer, p->type); +grub_Tss2_MU_TPMU_PUBLIC_PARMS_Marshal (buffer, p->type, &p->parameters); +} + +void +grub_Tss2_MU_TPMT_PUBLIC_Marshal (grub_tpm2_buffer_t buffer, +const TPMT_PUBLIC *p) +{ +grub_tpm2_buffer_pack_u16 (buffer, p->type); +grub_tpm2_buffer_pack_u16 (buffer, p->nameAlg); +grub_Tss2_MU_TPMA_OBJECT_Marshal (buffer, &p->objectAttributes); +grub_Tss2_MU_TPM2B_Marshal (buffer, p->authPolicy.size, p->authPolicy.buffer); +grub_Tss2_MU_TPMU_PUBLIC_PARMS_Marshal (buffer, p->type, &p->parameters); +grub_Tss2_MU_TPMU_PUBLIC_ID_Marshal (buffer, p->type, &p->unique); +} + +void +grub_Tss2_MU_TPM2B_PUBLIC_Marshal (grub_tpm2_buffer_t buffer, +const TPM2B_PUBLIC *p) +{ +grub_uint32_t start; +grub_uint16_t size; + +if (p) + { +grub_tpm2_buffer_pack_u16 (buffer, p->size); + + start = buffer->size; +grub_Tss2_MU_TPMT_PUBLIC_Marshal (buffer, &p->publicArea); + size =grub_cpu_to_be16 (buffer->size - start); +grub_memcpy (&buffer->data[start -sizeof (grub_uint16_t)], &size, +sizeof (size)); + } +else +grub_tpm2_buffer_pack_u16 (buffer,0 ); +} + +void +grub_Tss2_MU_TPMS_SENSITIVE_CREATE_Marshal (grub_tpm2_buffer_t buffer, +const TPMS_SENSITIVE_CREATE *p) +{ +grub_Tss2_MU_TPM2B_Marshal (buffer, p->userAuth.size, p->userAuth.buffer); +grub_Tss2_MU_TPM2B_Marshal (buffer, p->data.size, p->data.buffer); +} + +void +grub_Tss2_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_Tss2_MU_TPM2B_Marshal (buffer, p->rsa.size, p->rsa.buffer); +break ; +case TPM_ALG_ECC : +grub_Tss2_MU_TPM2B_Marshal (buffer, p->ecc.size, p->ecc.buffer); +break ; +case TPM_ALG_KEYEDHASH : +grub_Tss2_MU_TPM2B_Marshal (buffer, p->bits.size, p->bits.buffer); +break ; +case TPM_ALG_SYMCIPHER : +grub_Tss2_MU_TPM2B_Marshal (buffer, p->sym.size, p->sym.buffer); +break ; +default : + buffer->error =1 ; + } +} + +void +grub_Tss2_MU_TPMT_SENSITIVE_Marshal (grub_tpm2_buffer_t buffer, +const TPMT_SENSITIVE *p) +{ +grub_tpm2_buffer_pack_u16 (buffer, p->sensitiveType); +grub_Tss2_MU_TPM2B_Marshal (buffer, p->authValue.size, p->authValue.buffer); +grub_Tss2_MU_TPM2B_Marshal (buffer, p->seedValue.size, p->seedValue.buffer); +grub_Tss2_MU_TPMU_SENSITIVE_COMPOSITE_Marshal (buffer, p->sensitiveType, + &p->sensitive); +} + +void +grub_Tss2_MU_TPM2B_SENSITIVE_Marshal (grub_tpm2_buffer_t buffer, +const TPM2B_SENSITIVE *p) +{ +grub_tpm2_buffer_pack_u16 (buffer, p->size); +grub_Tss2_MU_TPMT_SENSITIVE_Marshal (buffer, &p->sensitiveArea); +} + +void +grub_Tss2_MU_TPM2B_SENSITIVE_CREATE_Marshal (grub_tpm2_buffer_t buffer, +const TPM2B_SENSITIVE_CREATE *sensitiveCreate) +{ +grub_uint32_t start; +grub_uint16_t size; + +if (sensitiveCreate) + { +grub_tpm2_buffer_pack_u16 (buffer, sensitiveCreate->size); + start = buffer->size; +grub_Tss2_MU_TPMS_SENSITIVE_CREATE_Marshal (buffer, + &sensitiveCreate->sensitive); + size =grub_cpu_to_be16 (buffer->size - start); + +grub_memcpy (&buffer->data[start -sizeof (grub_uint16_t)], &size, +sizeof (size)); + } +else +grub_tpm2_buffer_pack_u16 (buffer,0 ); +} + +void +grub_Tss2_MU_TPMS_SIGNATURE_RSA_Marshal (grub_tpm2_buffer_t buffer, +const TPMS_SIGNATURE_RSA *p) +{ +grub_tpm2_buffer_pack_u16 (buffer, p->hash); +grub_Tss2_MU_TPM2B_Marshal (buffer, p->sig.size, p->sig.buffer); +} + +void +grub_Tss2_MU_TPMS_SIGNATURE_ECC_Marshal (grub_tpm2_buffer_t buffer, +const TPMS_SIGNATURE_ECC *p) +{ +grub_tpm2_buffer_pack_u16 (buffer, p->hash); +grub_Tss2_MU_TPM2B_Marshal (buffer, p->signatureR.size, p->signatureR.buffer); +grub_Tss2_MU_TPM2B_Marshal (buffer, p->signatureS.size, p->signatureS.buffer); +} + +void +grub_Tss2_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_Tss2_MU_TPMT_HA_Marshal (grub_tpm2_buffer_t buffer, +const TPMT_HA *p) +{ +grub_tpm2_buffer_pack_u16 (buffer, p->hashAlg); +grub_Tss2_MU_TPMU_HA_Marshal (buffer, p->hashAlg, &p->digest); +} + +void +grub_Tss2_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_Tss2_MU_TPMS_SIGNATURE_RSA_Marshal (buffer, (TPMS_SIGNATURE_RSA *)&p->rsassa); +break ; +case TPM_ALG_RSAPSS : +grub_Tss2_MU_TPMS_SIGNATURE_RSA_Marshal (buffer, (TPMS_SIGNATURE_RSA *)&p->rsapss); +break ; +case TPM_ALG_ECDSA : +grub_Tss2_MU_TPMS_SIGNATURE_ECC_Marshal (buffer, (TPMS_SIGNATURE_ECC *)&p->ecdsa); +break ; +case TPM_ALG_ECDAA : +grub_Tss2_MU_TPMS_SIGNATURE_ECC_Marshal (buffer, (TPMS_SIGNATURE_ECC *)&p->ecdaa); +break ; +case TPM_ALG_SM2 : +grub_Tss2_MU_TPMS_SIGNATURE_ECC_Marshal (buffer, (TPMS_SIGNATURE_ECC *)&p->sm2); +break ; +case TPM_ALG_ECSCHNORR : +grub_Tss2_MU_TPMS_SIGNATURE_ECC_Marshal (buffer, (TPMS_SIGNATURE_ECC *)&p->ecschnorr); +break ; +case TPM_ALG_HMAC : +grub_Tss2_MU_TPMT_HA_Marshal (buffer, &p->hmac); +break ; +case TPM_ALG_NULL : +break ; +default : + buffer->error =1 ; +break ; + } +} + +void +grub_Tss2_MU_TPMT_SIGNATURE_Marshal (grub_tpm2_buffer_t buffer, +const TPMT_SIGNATURE *p) +{ +grub_tpm2_buffer_pack_u16 (buffer, p->sigAlg); +grub_Tss2_MU_TPMU_SIGNATURE_Marshal (buffer, p->sigAlg, &p->signature); +} + +void +grub_Tss2_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_Tss2_MU_TPM2B_Marshal (buffer, p->digest.size, p->digest.buffer); +} + +static void +__Tss2_MU_TPM2B_BUFFER_Unmarshal (grub_tpm2_buffer_t buffer, +TPM2B * p,grub_uint16_t bound) +{ +grub_tpm2_buffer_unpack_u16 (buffer, &p->size); + +if (p->size > bound) + { + buffer->error =1 ; +return ; + } + +grub_tpm2_buffer_unpack (buffer, &p->buffer, p->size); +} + +#define TPM2B_BUFFER_UNMARSHAL (buffer, type, data) \ + __Tss2_MU_TPM2B_BUFFER_Unmarshal(buffer, (TPM2B *)data, sizeof(type) - sizeof(grub_uint16_t)) + +void +grub_Tss2_MU_TPMS_AUTH_RESPONSE_Unmarshal (grub_tpm2_buffer_t buffer, +TPMS_AUTH_RESPONSE * p) +{ +grub_uint8_t tmp; +grub_uint32_t tmp32; + +grub_tpm2_buffer_unpack_u16 (buffer, &p->nonce.size); + +if (p->nonce.size) +grub_tpm2_buffer_unpack (buffer, &p->nonce.buffer, p->nonce.size); + +grub_tpm2_buffer_unpack_u8 (buffer, &tmp); + tmp32 = tmp; +grub_memcpy (&p->sessionAttributes, &tmp32,sizeof (grub_uint32_t)); + +grub_tpm2_buffer_unpack_u16 (buffer, &p->hmac.size); + +if (p->hmac.size) +grub_tpm2_buffer_unpack (buffer, &p->hmac.buffer, p->hmac.size); +} + +void +grub_Tss2_MU_TPM2B_DIGEST_Unmarshal (grub_tpm2_buffer_t buffer, +TPM2B_DIGEST * digest) +{ +TPM2B_BUFFER_UNMARSHAL (buffer,TPM2B_DIGEST , digest); +} + +void +grub_Tss2_MU_TPM2B_NONCE_Unmarshal (grub_tpm2_buffer_t buffer, +TPM2B_NONCE * nonce) +{ +TPM2B_BUFFER_UNMARSHAL (buffer,TPM2B_NONCE , nonce); +} + +void +grub_Tss2_MU_TPM2B_DATA_Unmarshal (grub_tpm2_buffer_t buffer, +TPM2B_DATA * data) +{ +TPM2B_BUFFER_UNMARSHAL (buffer,TPM2B_DATA , data); +} + +void +grub_Tss2_MU_TPMS_CREATION_DATA_Unmarshal (grub_tpm2_buffer_t buffer, +TPMS_CREATION_DATA *data) +{ +grub_Tss2_MU_TPML_PCR_SELECTION_Unmarshal (buffer, &data->pcrSelect); +grub_Tss2_MU_TPM2B_DIGEST_Unmarshal (buffer, &data->pcrDigest); +grub_tpm2_buffer_unpack_u8 (buffer, (grub_uint8_t *)&data->locality); +grub_tpm2_buffer_unpack_u16 (buffer, &data->parentNameAlg); +grub_Tss2_MU_TPM2B_NAME_Unmarshal (buffer, &data->parentName); +grub_Tss2_MU_TPM2B_NAME_Unmarshal (buffer, &data->parentQualifiedName); +grub_Tss2_MU_TPM2B_DATA_Unmarshal (buffer, &data->outsideInfo); +} + +void +grub_Tss2_MU_TPM2B_CREATION_DATA_Unmarshal (grub_tpm2_buffer_t buffer, +TPM2B_CREATION_DATA *data) +{ +grub_tpm2_buffer_unpack_u16 (buffer, &data->size); +grub_Tss2_MU_TPMS_CREATION_DATA_Unmarshal (buffer, &data->creationData); +} + +void +grub_Tss2_MU_TPM2B_PRIVATE_Unmarshal (grub_tpm2_buffer_t buffer, +TPM2B_PRIVATE *private) +{ +TPM2B_BUFFER_UNMARSHAL (buffer,TPM2B_PRIVATE , private); +} + +void +grub_Tss2_MU_TPM2B_SENSITIVE_DATA_Unmarshal (grub_tpm2_buffer_t buffer, +TPM2B_SENSITIVE_DATA *data) +{ +TPM2B_BUFFER_UNMARSHAL (buffer,TPM2B_SENSITIVE_DATA , data); +} + +void +grub_Tss2_MU_TPM2B_PUBLIC_KEY_RSA_Unmarshal (grub_tpm2_buffer_t buffer, +TPM2B_PUBLIC_KEY_RSA *rsa) +{ +TPM2B_BUFFER_UNMARSHAL (buffer,TPM2B_PUBLIC_KEY_RSA , rsa); +} + +void +grub_Tss2_MU_TPM2B_ECC_PARAMETER_Unmarshal (grub_tpm2_buffer_t buffer, +TPM2B_ECC_PARAMETER *param) +{ +TPM2B_BUFFER_UNMARSHAL (buffer,TPM2B_ECC_PARAMETER , param); +} + +void +grub_Tss2_MU_TPMA_OBJECT_Unmarshal (grub_tpm2_buffer_t buffer, +TPMA_OBJECT *p) +{ +grub_tpm2_buffer_unpack_u32 (buffer, (grub_uint32_t *)p); +} + +void +grub_Tss2_MU_TPMS_SCHEME_HMAC_Unmarshal (grub_tpm2_buffer_t buffer, +TPMS_SCHEME_HMAC *p) +{ +grub_tpm2_buffer_unpack_u16 (buffer, &p->hashAlg); +} + +void +grub_Tss2_MU_TPMS_SCHEME_XOR_Unmarshal (grub_tpm2_buffer_t buffer, +TPMS_SCHEME_XOR *p) +{ +grub_tpm2_buffer_unpack_u16 (buffer, &p->hashAlg); +grub_tpm2_buffer_unpack_u16 (buffer, &p->kdf); +} + +void +grub_Tss2_MU_TPMU_SCHEME_KEYEDHASH_Unmarshal (grub_tpm2_buffer_t buffer, +TPMI_ALG_KEYEDHASH_SCHEME scheme, +TPMU_SCHEME_KEYEDHASH *p) +{ +switch (scheme) + { +case TPM_ALG_HMAC : +grub_Tss2_MU_TPMS_SCHEME_HMAC_Unmarshal (buffer, &p->hmac); +break ; +case TPM_ALG_XOR : +grub_Tss2_MU_TPMS_SCHEME_XOR_Unmarshal (buffer, &p->exclusiveOr); +break ; +case TPM_ALG_NULL : +break ; +default : + buffer->error =1 ; +break ; + } +} + +void +grub_Tss2_MU_TPMT_KEYEDHASH_SCHEME_Unmarshal (grub_tpm2_buffer_t buffer, +TPMT_KEYEDHASH_SCHEME *p) +{ +grub_tpm2_buffer_unpack_u16 (buffer, &p->scheme); +grub_Tss2_MU_TPMU_SCHEME_KEYEDHASH_Unmarshal (buffer, p->scheme, &p->details); +} + +void +grub_Tss2_MU_TPMS_KEYEDHASH_PARMS_Unmarshal (grub_tpm2_buffer_t buffer, +TPMS_KEYEDHASH_PARMS *p) +{ +grub_Tss2_MU_TPMT_KEYEDHASH_SCHEME_Unmarshal (buffer, &p->scheme); +} + +void +grub_Tss2_MU_TPMU_SYM_KEY_BITS_Unmarshal (grub_tpm2_buffer_t buffer, +TPMI_ALG_SYM_OBJECT algorithm, +TPMU_SYM_KEY_BITS *p) +{ +switch (algorithm) + { +case TPM_ALG_AES : +case TPM_ALG_SM4 : +case TPM_ALG_CAMELLIA : +case TPM_ALG_XOR : +grub_tpm2_buffer_unpack_u16 (buffer, (grub_uint16_t *) p); +break ; +case TPM_ALG_NULL : +break ; +default : + buffer->error =1 ; +break ; + } +} + +void +grub_Tss2_MU_TPMU_SYM_MODE_Unmarshal (grub_tpm2_buffer_t buffer, +TPMI_ALG_SYM_OBJECT algorithm, +TPMU_SYM_MODE *p) +{ +switch (algorithm) + { +case TPM_ALG_AES : +case TPM_ALG_SM4 : +case TPM_ALG_CAMELLIA : +grub_tpm2_buffer_unpack_u16 (buffer, (grub_uint16_t *) p); +break ; +case TPM_ALG_XOR : +case TPM_ALG_NULL : +break ; +default : + buffer->error =1 ; +break ; + } +} + +void +grub_Tss2_MU_TPMT_SYM_DEF_OBJECT_Unmarshal (grub_tpm2_buffer_t buffer, +TPMT_SYM_DEF_OBJECT *p) +{ +grub_tpm2_buffer_unpack_u16 (buffer, &p->algorithm); +grub_Tss2_MU_TPMU_SYM_KEY_BITS_Unmarshal (buffer, p->algorithm, &p->keyBits); +grub_Tss2_MU_TPMU_SYM_MODE_Unmarshal (buffer, p->algorithm, &p->mode); +} + +void +grub_Tss2_MU_TPMS_SYMCIPHER_PARMS_Unmarshal (grub_tpm2_buffer_t buffer, +TPMS_SYMCIPHER_PARMS *p) +{ +grub_Tss2_MU_TPMT_SYM_DEF_OBJECT_Unmarshal (buffer, &p->sym); +} + +void +grub_Tss2_MU_TPMU_ASYM_SCHEME_Unmarshal (grub_tpm2_buffer_t buffer, +TPMI_ALG_RSA_DECRYPT scheme, +TPMU_ASYM_SCHEME *p __attribute__((unused))) +{ +switch (scheme) + { +case TPM_ALG_NULL : +break ; +default : +/* Unsupported */ + buffer->error =1 ; +break ; + } +} + +void +grub_Tss2_MU_TPMT_RSA_SCHEME_Unmarshal (grub_tpm2_buffer_t buffer, +TPMT_RSA_SCHEME *p) +{ +grub_tpm2_buffer_unpack_u16 (buffer, &p->scheme); +grub_Tss2_MU_TPMU_ASYM_SCHEME_Unmarshal (buffer, p->scheme, &p->details); +} + +void +grub_Tss2_MU_TPMS_RSA_PARMS_Unmarshal (grub_tpm2_buffer_t buffer, +TPMS_RSA_PARMS *p) +{ +grub_Tss2_MU_TPMT_SYM_DEF_OBJECT_Unmarshal (buffer, &p->symmetric); +grub_Tss2_MU_TPMT_RSA_SCHEME_Unmarshal (buffer, &p->scheme); +grub_tpm2_buffer_unpack_u16 (buffer, &p->keyBits); +grub_tpm2_buffer_unpack_u32 (buffer, &p->exponent); +} + +void +grub_Tss2_MU_TPMT_ECC_SCHEME_Unmarshal (grub_tpm2_buffer_t buffer, +TPMT_ECC_SCHEME *p) +{ +grub_tpm2_buffer_unpack_u16 (buffer, &p->scheme); +grub_Tss2_MU_TPMU_ASYM_SCHEME_Unmarshal (buffer, p->scheme, &p->details); +} + +void +grub_Tss2_MU_TPMU_KDF_SCHEME_Unmarshal (grub_tpm2_buffer_t buffer, +TPMI_ALG_KDF scheme, +TPMU_KDF_SCHEME *p) +{ +switch (scheme) + { +case TPM_ALG_MGF1 : +grub_tpm2_buffer_unpack_u16 (buffer, &p->mgf1.hashAlg); +break ; +case TPM_ALG_KDF1_SP800_56A : +grub_tpm2_buffer_unpack_u16 (buffer, &p->kdf1_sp800_56a.hashAlg); +break ; +case TPM_ALG_KDF2 : +grub_tpm2_buffer_unpack_u16 (buffer, &p->kdf2.hashAlg); +break ; +case TPM_ALG_KDF1_SP800_108 : +grub_tpm2_buffer_unpack_u16 (buffer, &p->kdf1_sp800_108.hashAlg); +break ; +case TPM_ALG_NULL : +break ; +default : + buffer->error =1 ; +break ; + } +} + +void +grub_Tss2_MU_TPMT_KDF_SCHEME_Unmarshal (grub_tpm2_buffer_t buffer, +TPMT_KDF_SCHEME *p) +{ +grub_tpm2_buffer_unpack_u16 (buffer, &p->scheme); +grub_Tss2_MU_TPMU_KDF_SCHEME_Unmarshal (buffer, p->scheme, &p->details); +} + +void +grub_Tss2_MU_TPMS_ECC_PARMS_Unmarshal (grub_tpm2_buffer_t buffer, +TPMS_ECC_PARMS *p) +{ +grub_Tss2_MU_TPMT_SYM_DEF_OBJECT_Unmarshal (buffer, &p->symmetric); +grub_Tss2_MU_TPMT_ECC_SCHEME_Unmarshal (buffer, &p->scheme ); +grub_tpm2_buffer_unpack_u16 (buffer, &p->curveID); +grub_Tss2_MU_TPMT_KDF_SCHEME_Unmarshal (buffer, &p->kdf); +} + +void +grub_Tss2_MU_TPMU_PUBLIC_PARMS_Unmarshal (grub_tpm2_buffer_t buffer, +grub_uint32_t type, +TPMU_PUBLIC_PARMS *p) +{ +switch (type) + { +case TPM_ALG_KEYEDHASH : +grub_Tss2_MU_TPMS_KEYEDHASH_PARMS_Unmarshal (buffer, &p->keyedHashDetail); +break ; +case TPM_ALG_SYMCIPHER : +grub_Tss2_MU_TPMS_SYMCIPHER_PARMS_Unmarshal (buffer, &p->symDetail); +break ; +case TPM_ALG_RSA : +grub_Tss2_MU_TPMS_RSA_PARMS_Unmarshal (buffer, &p->rsaDetail); +break ; +case TPM_ALG_ECC : +grub_Tss2_MU_TPMS_ECC_PARMS_Unmarshal (buffer, &p->eccDetail); +break ; +default : + buffer->error =1 ; +break ; + } +} + +void +grub_Tss2_MU_TPMS_ECC_POINT_Unmarshal (grub_tpm2_buffer_t buffer, +TPMS_ECC_POINT *p) +{ +grub_Tss2_MU_TPM2B_ECC_PARAMETER_Unmarshal (buffer, &p->x); +grub_Tss2_MU_TPM2B_ECC_PARAMETER_Unmarshal (buffer, &p->y); +} + +void +grub_Tss2_MU_TPMU_PUBLIC_ID_Unmarshal (grub_tpm2_buffer_t buffer, +TPMI_ALG_PUBLIC type, +TPMU_PUBLIC_ID *p) +{ +switch (type) + { +case TPM_ALG_KEYEDHASH : +grub_Tss2_MU_TPM2B_DIGEST_Unmarshal (buffer, &p->keyedHash); +break ; +case TPM_ALG_SYMCIPHER : +grub_Tss2_MU_TPM2B_DIGEST_Unmarshal (buffer, &p->sym); +break ; +case TPM_ALG_RSA : +grub_Tss2_MU_TPM2B_PUBLIC_KEY_RSA_Unmarshal (buffer, &p->rsa); +break ; +case TPM_ALG_ECC : +grub_Tss2_MU_TPMS_ECC_POINT_Unmarshal (buffer, &p->ecc); +break ; +default : + buffer->error =1 ; +break ; + } +} + +void +grub_Tss2_MU_TPMT_PUBLIC_Unmarshal (grub_tpm2_buffer_t buffer, +TPMT_PUBLIC *p) +{ +grub_tpm2_buffer_unpack_u16 (buffer, &p->type); +grub_tpm2_buffer_unpack_u16 (buffer, &p->nameAlg); +grub_Tss2_MU_TPMA_OBJECT_Unmarshal (buffer, &p->objectAttributes); +grub_Tss2_MU_TPM2B_DIGEST_Unmarshal (buffer, &p->authPolicy); +grub_Tss2_MU_TPMU_PUBLIC_PARMS_Unmarshal (buffer, p->type, &p->parameters); +grub_Tss2_MU_TPMU_PUBLIC_ID_Unmarshal (buffer, p->type, &p->unique); +} + +void +grub_Tss2_MU_TPM2B_PUBLIC_Unmarshal (grub_tpm2_buffer_t buffer, +TPM2B_PUBLIC *p) +{ +grub_tpm2_buffer_unpack_u16 (buffer, &p->size); +grub_Tss2_MU_TPMT_PUBLIC_Unmarshal (buffer, &p->publicArea); +} + +void +grub_Tss2_MU_TPMS_NV_PUBLIC_Unmarshal (grub_tpm2_buffer_t buffer, +TPMS_NV_PUBLIC *p) +{ +grub_tpm2_buffer_unpack_u32 (buffer, &p->nvIndex); +grub_tpm2_buffer_unpack_u16 (buffer, &p->nameAlg); +grub_tpm2_buffer_unpack_u32 (buffer, &p->attributes); +grub_Tss2_MU_TPM2B_DIGEST_Unmarshal (buffer, &p->authPolicy); +grub_tpm2_buffer_unpack_u16 (buffer, &p->dataSize); +} + +void +grub_Tss2_MU_TPM2B_NV_PUBLIC_Unmarshal (grub_tpm2_buffer_t buffer, +TPM2B_NV_PUBLIC *p) +{ +grub_tpm2_buffer_unpack_u16 (buffer, &p->size); +grub_Tss2_MU_TPMS_NV_PUBLIC_Unmarshal (buffer, &p->nvPublic); +} + +void +grub_Tss2_MU_TPM2B_NAME_Unmarshal (grub_tpm2_buffer_t buffer, +TPM2B_NAME *n) +{ +TPM2B_BUFFER_UNMARSHAL (buffer,TPM2B_NAME , n); +} + +void +grub_Tss2_MU_TPMS_TAGGED_PROPERTY_Unmarshal (grub_tpm2_buffer_t buffer, +TPMS_TAGGED_PROPERTY * property) +{ +grub_tpm2_buffer_unpack_u32 (buffer, &property->property); +grub_tpm2_buffer_unpack_u32 (buffer, &property->value); +} + +void +grub_Tss2_MU_TPMT_TK_CREATION_Unmarshal (grub_tpm2_buffer_t buffer, +TPMT_TK_CREATION *p) +{ +grub_tpm2_buffer_unpack_u16 (buffer, &p->tag); +grub_tpm2_buffer_unpack_u32 (buffer, &p->hierarchy); +grub_Tss2_MU_TPM2B_DIGEST_Unmarshal (buffer, &p->digest); +} + +void +grub_Tss2_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_Tss2_MU_TPM2B_DIGEST_Unmarshal (buffer, &p->digest); +} + +void +grub_Tss2_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_Tss2_MU_TPM2B_DIGEST_Unmarshal (buffer, &p->digest); +} + +void +grub_Tss2_MU_TPMS_PCR_SELECTION_Unmarshal (grub_tpm2_buffer_t buffer, +TPMS_PCR_SELECTION * pcrSelection) +{ +grub_tpm2_buffer_unpack_u16 (buffer, &pcrSelection->hash); +grub_tpm2_buffer_unpack_u8 (buffer, &pcrSelection->sizeOfSelect); + +if (pcrSelection->sizeOfSelect >TPM_PCR_SELECT_MAX ) + { + buffer->error =1 ; +return ; + } + +for (grub_uint32_t i =0 ; i < pcrSelection->sizeOfSelect; i++) +grub_tpm2_buffer_unpack_u8 (buffer, &pcrSelection->pcrSelect[i]); +} + +void +grub_Tss2_MU_TPML_PCR_SELECTION_Unmarshal (grub_tpm2_buffer_t buffer, +TPML_PCR_SELECTION * pcrSelection) +{ +grub_tpm2_buffer_unpack_u32 (buffer, &pcrSelection->count); + +if (pcrSelection->count >TPM_NUM_PCR_BANKS ) + { + buffer->error =1 ; +return ; + } + +for (grub_uint32_t i =0 ; i < pcrSelection->count; i++) +grub_Tss2_MU_TPMS_PCR_SELECTION_Unmarshal (buffer, &pcrSelection->pcrSelections[i]); +} + +void +grub_Tss2_MU_TPML_DIGEST_Unmarshal (grub_tpm2_buffer_t buffer, +TPML_DIGEST * digest) +{ +grub_tpm2_buffer_unpack_u32 (buffer, &digest->count); + +if (digest->count >8 ) + { + buffer->error =1 ; +return ; + } + +for (grub_uint32_t i =0 ; i < digest->count; i++) +grub_Tss2_MU_TPM2B_DIGEST_Unmarshal (buffer, &digest->digests[i]); +} + +void +grub_Tss2_MU_TPMS_SIGNATURE_RSA_Unmarshal (grub_tpm2_buffer_t buffer, +TPMS_SIGNATURE_RSA *rsa) +{ +grub_tpm2_buffer_unpack_u16 (buffer, &rsa->hash); +grub_Tss2_MU_TPM2B_PUBLIC_KEY_RSA_Unmarshal (buffer, &rsa->sig); +} + +void +grub_Tss2_MU_TPMS_SIGNATURE_ECC_Unmarshal (grub_tpm2_buffer_t buffer, +TPMS_SIGNATURE_ECC *ecc) +{ +grub_tpm2_buffer_unpack_u16 (buffer, &ecc->hash); +grub_Tss2_MU_TPM2B_ECC_PARAMETER_Unmarshal (buffer, &ecc->signatureR); +grub_Tss2_MU_TPM2B_ECC_PARAMETER_Unmarshal (buffer, &ecc->signatureS); +} + +void +grub_Tss2_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_Tss2_MU_TPMT_HA_Unmarshal (grub_tpm2_buffer_t buffer, +TPMT_HA *p) +{ +grub_tpm2_buffer_unpack_u16 (buffer, &p->hashAlg); +grub_Tss2_MU_TPMU_HA_Unmarshal (buffer, p->hashAlg, &p->digest); +} + +void +grub_Tss2_MU_TPMU_SIGNATURE_Unmarshal (grub_tpm2_buffer_t buffer, +TPMI_ALG_SIG_SCHEME sigAlg, +TPMU_SIGNATURE *p) +{ +switch (sigAlg) + { +case TPM_ALG_RSASSA : +grub_Tss2_MU_TPMS_SIGNATURE_RSA_Unmarshal (buffer, (TPMS_SIGNATURE_RSA *)&p->rsassa); +break ; +case TPM_ALG_RSAPSS : +grub_Tss2_MU_TPMS_SIGNATURE_RSA_Unmarshal (buffer, (TPMS_SIGNATURE_RSA *)&p->rsapss); +break ; +case TPM_ALG_ECDSA : +grub_Tss2_MU_TPMS_SIGNATURE_ECC_Unmarshal (buffer, (TPMS_SIGNATURE_ECC *)&p->ecdsa); +break ; +case TPM_ALG_ECDAA : +grub_Tss2_MU_TPMS_SIGNATURE_ECC_Unmarshal (buffer, (TPMS_SIGNATURE_ECC *)&p->ecdaa); +break ; +case TPM_ALG_SM2 : +grub_Tss2_MU_TPMS_SIGNATURE_ECC_Unmarshal (buffer, (TPMS_SIGNATURE_ECC *)&p->sm2); +break ; +case TPM_ALG_ECSCHNORR : +grub_Tss2_MU_TPMS_SIGNATURE_ECC_Unmarshal (buffer, (TPMS_SIGNATURE_ECC *)&p->ecschnorr); +break ; +case TPM_ALG_HMAC : +grub_Tss2_MU_TPMT_HA_Unmarshal (buffer, &p->hmac); +break ; +case TPM_ALG_NULL : +break ; +default : + buffer->error =1 ; +break ; + } +} + +void +grub_Tss2_MU_TPMT_SIGNATURE_Unmarshal (grub_tpm2_buffer_t buffer, +TPMT_SIGNATURE *p) +{ +grub_tpm2_buffer_unpack_u16 (buffer, &p->sigAlg); +grub_Tss2_MU_TPMU_SIGNATURE_Unmarshal (buffer, p->sigAlg, &p->signature); +}
grub-core/lib/tss2/tss2_mu.h new file +397 -0
397 lines not on this page · raw message
grub-core/lib/tss2/tss2_structs.h new file +768 -0
768 lines not on this page · raw message
grub-core/lib/tss2/tss2_types.h new file +404 -0
404 lines not on this page · raw message
Signature · 7 lines
2.35.3 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 14/25] tss2: Add TPM2 types and Marshal/Unmarshal functions
Quoted 25 lines · Gary Lin via Grub-devel
This commit adds the necessary TPM2 types and structs as the preparation for the TPM2 Software Stack (TSS2) support. The Marshal/Unmarshal functions are also added to handle the data structure to be submitted to TPM2 commands and to be received from the response.
Cc Stefan Berger <[email protected]>Signed-off-by Hernan Gatta <[email protected]>Signed-off-by Gary Lin <[email protected]>--- grub-core/lib/tss2/tss2_mu.c | 1170 +++++++++++++++++++++++++++++ grub-core/lib/tss2/tss2_mu.h | 397 ++++++++++ grub-core/lib/tss2/tss2_structs.h | 768 +++++++++++++++++++ grub-core/lib/tss2/tss2_types.h | 404 ++++++++++ 4 files changed, 2739 insertions(+) create mode 100644 grub-core/lib/tss2/tss2_mu.c create mode 100644 grub-core/lib/tss2/tss2_mu.h create mode 100644 grub-core/lib/tss2/tss2_structs.h create mode 100644 grub-core/lib/tss2/tss2_types.hgrub-core/lib/tss2/tss2_mu.c new file +0
-0
grub-core/lib/tss2/tss2_mu.c line 4
Quoted 4 lines
grub-core/lib/tss2/tss2_mu.c new file +4
-0@@ -0,0 +1,1170 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 Free Software Foundation, Inc. +* Copyright (C) 2022 Microsoft Corporation
Wrong order...
Quoted 11 lines
grub-core/lib/tss2/tss2_mu.c new file +11
-0+* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License
grub-core/lib/tss2/tss2_mu.c line 26
Quoted 10 lines
grub-core/lib/tss2/tss2_mu.c new file +10
-0+* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/misc.h> + +#include <tss2_mu.h> + +void +grub_Tss2_MU_TPMS_AUTH_COMMAND_Marshal (grub_tpm2_buffer_t buffer, +const TPMS_AUTH_COMMAND * authCommand)
s/const TPMS_AUTH_COMMAND*/ const TPMS_AUTH_COMMAND *authCommand/
As I can see this can be wrong in the whole patch set. Please fix it all over the place...
Quoted 5 lines
grub-core/lib/tss2/tss2_mu.c new file +5
-0+{ +grub_uint32_t start; +grub_uint32_t tmp; + +grub_tpm2_buffer_pack_u32 (buffer,0 );
grub-core/lib/tss2/tss2_mu.c line 41
Quoted 10 lines
grub-core/lib/tss2/tss2_mu.c new file +10
-0+ start = buffer->size; + +grub_tpm2_buffer_pack_u32 (buffer, authCommand->sessionHandle); + +grub_tpm2_buffer_pack_u16 (buffer, authCommand->nonce.size); +grub_tpm2_buffer_pack (buffer, authCommand->nonce.buffer, + authCommand->nonce.size); + +grub_tpm2_buffer_pack_u8 (buffer, + *((const grub_uint8_t *) &authCommand->sessionAttributes));
s/const grub_uint8_t*/const grub_uint8_t */
Similar problem to the above. It has to be fixes...
Quoted 14 lines
grub-core/lib/tss2/tss2_mu.c new file +14
-0+grub_tpm2_buffer_pack_u16 (buffer, authCommand->hmac.size); +grub_tpm2_buffer_pack (buffer, authCommand->hmac.buffer, + authCommand->hmac.size); + + tmp =grub_cpu_to_be32 (buffer->size - start); +grub_memcpy (&buffer->data[start -sizeof (grub_uint32_t)], &tmp, +sizeof (tmp)); +} + +void +grub_Tss2_MU_TPM2B_Marshal (grub_tpm2_buffer_t buffer, +const grub_uint16_t size, +const grub_uint8_t * b) +{
grub-core/lib/tss2/tss2_mu.c line 66
Quoted 10 lines
grub-core/lib/tss2/tss2_mu.c new file +10
-0+grub_tpm2_buffer_pack_u16 (buffer, size); + +for (grub_uint16_t i =0 ; i < size; i++) +grub_tpm2_buffer_pack_u8 (buffer, b[i]); +} + +void +grub_Tss2_MU_TPMU_SYM_KEY_BITS_Marshal (grub_tpm2_buffer_t buffer, +const TPMI_ALG_SYM_OBJECT algorithm, +const TPMU_SYM_KEY_BITS *p)
But here it is correct. Please be consistent...
Quoted 55 lines
grub-core/lib/tss2/tss2_mu.c new file +55
-0+{ +switch (algorithm) + { +case TPM_ALG_AES : +case TPM_ALG_SM4 : +case TPM_ALG_CAMELLIA : +case TPM_ALG_XOR : +grub_tpm2_buffer_pack_u16 (buffer, *((const grub_uint16_t *) p)); +break ; +case TPM_ALG_NULL : +break ; +default : + buffer->error =1 ; +break ; + } +} + +void +grub_Tss2_MU_TPMU_SYM_MODE_Marshal (grub_tpm2_buffer_t buffer, +const TPMI_ALG_SYM_OBJECT algorithm, +const TPMU_SYM_MODE *p) +{ +switch (algorithm) + { +case TPM_ALG_AES : +case TPM_ALG_SM4 : +case TPM_ALG_CAMELLIA : +grub_tpm2_buffer_pack_u16 (buffer, *((const grub_uint16_t *) p)); +break ; +case TPM_ALG_XOR : +case TPM_ALG_NULL : +break ; +default : + buffer->error =1 ; +break ; + } +} + +void +grub_Tss2_MU_TPMT_SYM_DEF_Marshal (grub_tpm2_buffer_t buffer, +const TPMT_SYM_DEF *p) +{ +grub_tpm2_buffer_pack_u16 (buffer, p->algorithm); +grub_Tss2_MU_TPMU_SYM_KEY_BITS_Marshal (buffer, p->algorithm, &p->keyBits); +grub_Tss2_MU_TPMU_SYM_MODE_Marshal (buffer, p->algorithm, &p->mode); +} + +void +grub_Tss2_MU_TPMS_PCR_SELECTION_Marshal (grub_tpm2_buffer_t buffer, +const TPMS_PCR_SELECTION * pcrSelection) +{ +grub_tpm2_buffer_pack_u16 (buffer, pcrSelection->hash); +grub_tpm2_buffer_pack_u8 (buffer, pcrSelection->sizeOfSelect); + +for (grub_uint32_t i =0 ; i < pcrSelection->sizeOfSelect; i++)
grub-core/lib/tss2/tss2_mu.c line 131
Quoted 10 lines
grub-core/lib/tss2/tss2_mu.c new file +10
-0+grub_tpm2_buffer_pack_u8 (buffer, pcrSelection->pcrSelect[i]); +} + +void +grub_Tss2_MU_TPML_PCR_SELECTION_Marshal (grub_tpm2_buffer_t buffer, +const TPML_PCR_SELECTION * pcrSelection) +{ +grub_tpm2_buffer_pack_u32 (buffer, pcrSelection->count); + +for (grub_uint32_t i =0 ; i < pcrSelection->count; i++)
Even if it works do not define variables in that way. Please do that at the beginning of a function.
Quoted 3 lines
grub-core/lib/tss2/tss2_mu.c new file +3
-0+grub_Tss2_MU_TPMS_PCR_SELECTION_Marshal (buffer, + &pcrSelection->pcrSelections[i]); +}
[...]
Quoted 6 lines
grub-core/lib/tss2/tss2_mu.c new file +6
-0+void +grub_Tss2_MU_TPM2B_PUBLIC_Marshal (grub_tpm2_buffer_t buffer, +const TPM2B_PUBLIC *p) +{ +grub_uint32_t start; +grub_uint16_t size;
grub-core/lib/tss2/tss2_mu.c line 391
Quoted 10 lines
grub-core/lib/tss2/tss2_mu.c new file +10
-0+ +if (p) + { +grub_tpm2_buffer_pack_u16 (buffer, p->size); + + start = buffer->size; +grub_Tss2_MU_TPMT_PUBLIC_Marshal (buffer, &p->publicArea); + size =grub_cpu_to_be16 (buffer->size - start); +grub_memcpy (&buffer->data[start -sizeof (grub_uint16_t)], &size, +sizeof (size));
Please reduce wrapping further where possible. And it is still possible in many places...
Quoted 4 lines
grub-core/lib/tss2/tss2_mu.c new file +4
-0+ } +else +grub_tpm2_buffer_pack_u16 (buffer,0 ); +}
[...]
grub-core/lib/tss2/tss2_mu.c line 532
Quoted 9 lines
grub-core/lib/tss2/tss2_mu.c new file +9
-0+void +grub_Tss2_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_Tss2_MU_TPMS_SIGNATURE_RSA_Marshal (buffer, (TPMS_SIGNATURE_RSA *)&p->rsassa);
Missing space in cast...
s/(TPMS_SIGNATURE_RSA *)&p->rsassa/(TPMS_SIGNATURE_RSA *) &p->rsassa/
grub-core/lib/tss2/tss2_mu.c line 535
Quoted 3 lines
grub-core/lib/tss2/tss2_mu.c new file +3
-0+break ; +case TPM_ALG_RSAPSS : +grub_Tss2_MU_TPMS_SIGNATURE_RSA_Marshal (buffer, (TPMS_SIGNATURE_RSA *)&p->rsapss);
Ditto and below...
Quoted 23 lines
grub-core/lib/tss2/tss2_mu.c new file +23
-0+break ; +case TPM_ALG_ECDSA : +grub_Tss2_MU_TPMS_SIGNATURE_ECC_Marshal (buffer, (TPMS_SIGNATURE_ECC *)&p->ecdsa); +break ; +case TPM_ALG_ECDAA : +grub_Tss2_MU_TPMS_SIGNATURE_ECC_Marshal (buffer, (TPMS_SIGNATURE_ECC *)&p->ecdaa); +break ; +case TPM_ALG_SM2 : +grub_Tss2_MU_TPMS_SIGNATURE_ECC_Marshal (buffer, (TPMS_SIGNATURE_ECC *)&p->sm2); +break ; +case TPM_ALG_ECSCHNORR : +grub_Tss2_MU_TPMS_SIGNATURE_ECC_Marshal (buffer, (TPMS_SIGNATURE_ECC *)&p->ecschnorr); +break ; +case TPM_ALG_HMAC : +grub_Tss2_MU_TPMT_HA_Marshal (buffer, &p->hmac); +break ; +case TPM_ALG_NULL : +break ; +default : + buffer->error =1 ; +break ; + } +}
[...]
grub-core/lib/tss2/tss2_mu.h line 4
Quoted 10 lines
grub-core/lib/tss2/tss2_mu.h new file +4
-0@@ -0,0 +1,397 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 Free Software Foundation, Inc. +* Copyright (C) 2022 Microsoft Corporation
Wrong order...
Quoted 13 lines
grub-core/lib/tss2/tss2_mu.h new file +13
-0+* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/
grub-core/lib/tss2/tss2_mu.h line 28
Quoted 10 lines
grub-core/lib/tss2/tss2_mu.h new file +10
-0+ +#ifndef GRUB_TPM2_MU_HEADER +#define GRUB_TPM2_MU_HEADER 1 + +#include <tss2_buffer.h> +#include <tss2_structs.h> + +void +grub_Tss2_MU_TPMS_AUTH_COMMAND_Marshal (grub_tpm2_buffer_t buffer, +const TPMS_AUTH_COMMAND * authCommand);
Missing externs...
[...]
grub-core/lib/tss2/tss2_structs.h line 4
Quoted 10 lines
grub-core/lib/tss2/tss2_structs.h new file +4
-0@@ -0,0 +1,768 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 Free Software Foundation, Inc. +* Copyright (C) 2022 Microsoft Corporation
Wrong order...
Quoted 16 lines
grub-core/lib/tss2/tss2_structs.h new file +16
-0+* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef GRUB_TPM2_INTERNAL_STRUCTS_HEADER +#define GRUB_TPM2_INTERNAL_STRUCTS_HEADER 1
grub-core/lib/tss2/tss2_structs.h line 31
Quoted 10 lines
grub-core/lib/tss2/tss2_structs.h new file +10
-0+ +#include <tss2_types.h> + +/* TPMS_TAGGED_PROPERTY Structure */ +struct TPMS_TAGGED_PROPERTY +{ +TPM_PT property; +grub_uint32_t value; +}; +typedef struct TPMS_TAGGED_PROPERTY TPMS_TAGGED_PROPERTY ;
Please add "_t" to typedefs, i.e.
typedef struct TPMS_TAGGED_PROPERTY TPMS_TAGGED_PROPERTY_t.
I think I asked for this last time.
[...]
grub-core/lib/tss2/tss2_structs.h line 628
Quoted 8 lines
grub-core/lib/tss2/tss2_structs.h new file +8
-0+/* _PRIVATE Structure */ +struct _PRIVATE +{ +TPM2B_DIGEST integrityOuter; +TPM2B_DIGEST integrityInner; +TPM2B_SENSITIVE sensitive; +}; +typedef struct _PRIVATE _PRIVATE ;
I would not use so generic name...
s/_PRIVATE/__TPM2B_PRIVATE/? At least...
grub-core/lib/tss2/tss2_structs.h line 636
Quoted 8 lines
grub-core/lib/tss2/tss2_structs.h new file +8
-0+ +/* TPM2B_PRIVATE Structure */ +struct TPM2B_PRIVATE +{ +grub_uint16_t size; +grub_uint8_t buffer[sizeof (_PRIVATE)]; +}; +typedef struct TPM2B_PRIVATE TPM2B_PRIVATE ;
Feel free to add my RB when you fix all these minor issues.
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 14/25] tss2: Add TPM2 types and Marshal/Unmarshal functions
Quoted 20 lines · Daniel Kiper
Quoted 19 lines · Gary Lin via Grub-devel
This commit adds the necessary TPM2 types and structs as the preparation for the TPM2 Software Stack (TSS2) support. The Marshal/Unmarshal functions are also added to handle the data structure to be submitted to TPM2 commands and to be received from the response.
Cc Stefan Berger <[email protected]>Signed-off-by Hernan Gatta <[email protected]>Signed-off-by Gary Lin <[email protected]>--- grub-core/lib/tss2/tss2_mu.c | 1170 +++++++++++++++++++++++++++++ grub-core/lib/tss2/tss2_mu.h | 397 ++++++++++ grub-core/lib/tss2/tss2_structs.h | 768 +++++++++++++++++++ grub-core/lib/tss2/tss2_types.h | 404 ++++++++++ 4 files changed, 2739 insertions(+) create mode 100644 grub-core/lib/tss2/tss2_mu.c create mode 100644 grub-core/lib/tss2/tss2_mu.h create mode 100644 grub-core/lib/tss2/tss2_structs.h create mode 100644 grub-core/lib/tss2/tss2_types.h
Quoted 13 lines
grub-core/lib/tss2/tss2_mu.c line 4
Quoted 10 lines
grub-core/lib/tss2/tss2_mu.c new file +4
-0@@ -0,0 +1,1170 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 Free Software Foundation, Inc. +* Copyright (C) 2022 Microsoft Corporation Wrong order...
Sorry for that. I've revised the whole patch set to fix the order.
Quoted 24 lines
Quoted 11 lines
grub-core/lib/tss2/tss2_mu.c new file +11
-0+* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License grub-core/lib/tss2/tss2_mu.c line 26
Quoted 10 lines
grub-core/lib/tss2/tss2_mu.c new file +10
-0+* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/misc.h> + +#include <tss2_mu.h> + +void +grub_Tss2_MU_TPMS_AUTH_COMMAND_Marshal (grub_tpm2_buffer_t buffer, +const TPMS_AUTH_COMMAND * authCommand)s/const TPMS_AUTH_COMMAND*/ const
TPMS_AUTH_COMMAND*authCommand/
Quoted 3 lines
As I can see this can be wrong in the whole patch set. Please fix it all over the place...
Sure.
Quoted 18 lines
Quoted 5 lines
grub-core/lib/tss2/tss2_mu.c new file +5
-0+{ +grub_uint32_t start; +grub_uint32_t tmp; + +grub_tpm2_buffer_pack_u32 (buffer,0 );grub-core/lib/tss2/tss2_mu.c line 41
Quoted 10 lines
grub-core/lib/tss2/tss2_mu.c new file +10
-0+ start = buffer->size; + +grub_tpm2_buffer_pack_u32 (buffer, authCommand->sessionHandle); + +grub_tpm2_buffer_pack_u16 (buffer, authCommand->nonce.size); +grub_tpm2_buffer_pack (buffer, authCommand->nonce.buffer, + authCommand->nonce.size); + +grub_tpm2_buffer_pack_u8 (buffer, + *((const grub_uint8_t *) &authCommand->sessionAttributes));s/const grub_uint8_t*/const
grub_uint8_t*/
Quoted 2 lines
Similar problem to the above. It has to be fixes...
Got it.
Quoted 87 lines
Quoted 14 lines
grub-core/lib/tss2/tss2_mu.c new file +14
-0+grub_tpm2_buffer_pack_u16 (buffer, authCommand->hmac.size); +grub_tpm2_buffer_pack (buffer, authCommand->hmac.buffer, + authCommand->hmac.size); + + tmp =grub_cpu_to_be32 (buffer->size - start); +grub_memcpy (&buffer->data[start -sizeof (grub_uint32_t)], &tmp, +sizeof (tmp)); +} + +void +grub_Tss2_MU_TPM2B_Marshal (grub_tpm2_buffer_t buffer, +const grub_uint16_t size, +const grub_uint8_t * b) +{grub-core/lib/tss2/tss2_mu.c line 66
Quoted 10 lines
grub-core/lib/tss2/tss2_mu.c new file +10
-0+grub_tpm2_buffer_pack_u16 (buffer, size); + +for (grub_uint16_t i =0 ; i < size; i++) +grub_tpm2_buffer_pack_u8 (buffer, b[i]); +} + +void +grub_Tss2_MU_TPMU_SYM_KEY_BITS_Marshal (grub_tpm2_buffer_t buffer, +const TPMI_ALG_SYM_OBJECT algorithm, +const TPMU_SYM_KEY_BITS *p)But here it is correct. Please be consistent...
Quoted 60 lines
grub-core/lib/tss2/tss2_mu.c new file +60
-0+{ +switch (algorithm) + { +case TPM_ALG_AES : +case TPM_ALG_SM4 : +case TPM_ALG_CAMELLIA : +case TPM_ALG_XOR : +grub_tpm2_buffer_pack_u16 (buffer, *((const grub_uint16_t *) p)); +break ; +case TPM_ALG_NULL : +break ; +default : + buffer->error =1 ; +break ; + } +} + +void +grub_Tss2_MU_TPMU_SYM_MODE_Marshal (grub_tpm2_buffer_t buffer, +const TPMI_ALG_SYM_OBJECT algorithm, +const TPMU_SYM_MODE *p) +{ +switch (algorithm) + { +case TPM_ALG_AES : +case TPM_ALG_SM4 : +case TPM_ALG_CAMELLIA : +grub_tpm2_buffer_pack_u16 (buffer, *((const grub_uint16_t *) p)); +break ; +case TPM_ALG_XOR : +case TPM_ALG_NULL : +break ; +default : + buffer->error =1 ; +break ; + } +} + +void +grub_Tss2_MU_TPMT_SYM_DEF_Marshal (grub_tpm2_buffer_t buffer, +const TPMT_SYM_DEF *p) +{ +grub_tpm2_buffer_pack_u16 (buffer, p->algorithm); +grub_Tss2_MU_TPMU_SYM_KEY_BITS_Marshal (buffer, p->algorithm, &p->keyBits); +grub_Tss2_MU_TPMU_SYM_MODE_Marshal (buffer, p->algorithm, &p->mode); +} + +void +grub_Tss2_MU_TPMS_PCR_SELECTION_Marshal (grub_tpm2_buffer_t buffer, +const TPMS_PCR_SELECTION * pcrSelection) +{ +grub_tpm2_buffer_pack_u16 (buffer, pcrSelection->hash); +grub_tpm2_buffer_pack_u8 (buffer, pcrSelection->sizeOfSelect); + +for (grub_uint32_t i =0 ; i < pcrSelection->sizeOfSelect; i++) +grub_tpm2_buffer_pack_u8 (buffer, pcrSelection->pcrSelect[i]); +} + +void +grub_Tss2_MU_TPML_PCR_SELECTION_Marshal (grub_tpm2_buffer_t buffer,
Quoted 9 lines
grub-core/lib/tss2/tss2_mu.c line 131
Quoted 5 lines
grub-core/lib/tss2/tss2_mu.c new file +5
-0+ const TPML_PCR_SELECTION* pcrSelection) +{ +grub_tpm2_buffer_pack_u32 (buffer, pcrSelection->count); + +for (grub_uint32_t i =0 ; i < pcrSelection->count; i++)Even if it works do not define variables in that way. Please do that at the beginning of a function.
Ok. I've spotted the similar usage in several MU functions. Will fix them in the next version.
Quoted 17 lines
Quoted 3 lines
grub-core/lib/tss2/tss2_mu.c new file +3
-0+grub_Tss2_MU_TPMS_PCR_SELECTION_Marshal (buffer, + &pcrSelection->pcrSelections[i]); +}[...]
Quoted 11 lines
grub-core/lib/tss2/tss2_mu.c new file +11
-0+void +grub_Tss2_MU_TPM2B_PUBLIC_Marshal (grub_tpm2_buffer_t buffer, +const TPM2B_PUBLIC *p) +{ +grub_uint32_t start; +grub_uint16_t size; + +if (p) + { +grub_tpm2_buffer_pack_u16 (buffer, p->size); +
Quoted 9 lines
grub-core/lib/tss2/tss2_mu.c line 391
Quoted 5 lines
grub-core/lib/tss2/tss2_mu.c new file +5
-0+ start = buffer->size; +grub_Tss2_MU_TPMT_PUBLIC_Marshal (buffer, &p->publicArea); + size =grub_cpu_to_be16 (buffer->size - start); +grub_memcpy (&buffer->data[start -sizeof (grub_uint16_t)], &size, +sizeof (size));Please reduce wrapping further where possible. And it is still possible in many places...
Ok.
Quoted 19 lines
Quoted 4 lines
grub-core/lib/tss2/tss2_mu.c new file +4
-0+ } +else +grub_tpm2_buffer_pack_u16 (buffer,0 ); +}[...]
grub-core/lib/tss2/tss2_mu.c line 532
Quoted 9 lines
grub-core/lib/tss2/tss2_mu.c new file +9
-0+void +grub_Tss2_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_Tss2_MU_TPMS_SIGNATURE_RSA_Marshal (buffer, (TPMS_SIGNATURE_RSA *)&p->rsassa);Missing space in cast...
Quoted 2 lines
s/(TPMS_SIGNATURE_RSA *)&p->rsassa/(TPMS_SIGNATURE_RSA *) &p->rsassa/
Ok.
Quoted 71 lines
grub-core/lib/tss2/tss2_mu.c line 535
Quoted 3 lines
grub-core/lib/tss2/tss2_mu.c new file +3
-0+break ; +case TPM_ALG_RSAPSS : +grub_Tss2_MU_TPMS_SIGNATURE_RSA_Marshal (buffer, (TPMS_SIGNATURE_RSA *)&p->rsapss);Ditto and below...
Quoted 23 lines
grub-core/lib/tss2/tss2_mu.c new file +23
-0+break ; +case TPM_ALG_ECDSA : +grub_Tss2_MU_TPMS_SIGNATURE_ECC_Marshal (buffer, (TPMS_SIGNATURE_ECC *)&p->ecdsa); +break ; +case TPM_ALG_ECDAA : +grub_Tss2_MU_TPMS_SIGNATURE_ECC_Marshal (buffer, (TPMS_SIGNATURE_ECC *)&p->ecdaa); +break ; +case TPM_ALG_SM2 : +grub_Tss2_MU_TPMS_SIGNATURE_ECC_Marshal (buffer, (TPMS_SIGNATURE_ECC *)&p->sm2); +break ; +case TPM_ALG_ECSCHNORR : +grub_Tss2_MU_TPMS_SIGNATURE_ECC_Marshal (buffer, (TPMS_SIGNATURE_ECC *)&p->ecschnorr); +break ; +case TPM_ALG_HMAC : +grub_Tss2_MU_TPMT_HA_Marshal (buffer, &p->hmac); +break ; +case TPM_ALG_NULL : +break ; +default : + buffer->error =1 ; +break ; + } +}[...]
grub-core/lib/tss2/tss2_mu.h line 4
Quoted 10 lines
grub-core/lib/tss2/tss2_mu.h new file +4
-0@@ -0,0 +1,397 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 Free Software Foundation, Inc. +* Copyright (C) 2022 Microsoft Corporation Wrong order...
Quoted 13 lines
grub-core/lib/tss2/tss2_mu.h new file +13
-0+* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ grub-core/lib/tss2/tss2_mu.h line 28
Quoted 10 lines
grub-core/lib/tss2/tss2_mu.h new file +10
-0+ +#ifndef GRUB_TPM2_MU_HEADER +#define GRUB_TPM2_MU_HEADER 1 + +#include <tss2_buffer.h> +#include <tss2_structs.h> + +void +grub_Tss2_MU_TPMS_AUTH_COMMAND_Marshal (grub_tpm2_buffer_t buffer, +const TPMS_AUTH_COMMAND * authCommand);Missing externs...
Quoted 2 lines
[...]
Will add externs to all tss2 functions in the headers.
Quoted 43 lines
grub-core/lib/tss2/tss2_structs.h line 4
Quoted 10 lines
grub-core/lib/tss2/tss2_structs.h new file +4
-0@@ -0,0 +1,768 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 Free Software Foundation, Inc. +* Copyright (C) 2022 Microsoft Corporation Wrong order...
Quoted 16 lines
grub-core/lib/tss2/tss2_structs.h new file +16
-0+* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef GRUB_TPM2_INTERNAL_STRUCTS_HEADER +#define GRUB_TPM2_INTERNAL_STRUCTS_HEADER 1grub-core/lib/tss2/tss2_structs.h line 31
Quoted 10 lines
grub-core/lib/tss2/tss2_structs.h new file +10
-0+ +#include <tss2_types.h> + +/* TPMS_TAGGED_PROPERTY Structure */ +struct TPMS_TAGGED_PROPERTY +{ +TPM_PT property; +grub_uint32_t value; +}; +typedef struct TPMS_TAGGED_PROPERTY TPMS_TAGGED_PROPERTY ;Please add "_t" to typedefs, i.e.
typedef structTPMS_TAGGED_PROPERTYTPMS_TAGGED_PROPERTY_t.
Quoted 2 lines
I think I asked for this last time.
I overlooked the comment. It's all renamed in my WIP branch.
Quoted 13 lines
[...]
grub-core/lib/tss2/tss2_structs.h line 628
Quoted 8 lines
grub-core/lib/tss2/tss2_structs.h new file +8
-0+/* _PRIVATE Structure */ +struct _PRIVATE +{ +TPM2B_DIGEST integrityOuter; +TPM2B_DIGEST integrityInner; +TPM2B_SENSITIVE sensitive; +}; +typedef struct _PRIVATE _PRIVATE ;I would not use so generic name...
Quoted 2 lines
s/_PRIVATE/__TPM2B_PRIVATE/? At least...
That name is actually from the TPM2 SPEC and the intel-tss2 library follows the naming. Anyway, the '_PRIVATE' struct is not used by any TPM2 command, so it's totally fine to rename the struct without leading to any confusion.
Quoted 11 lines
grub-core/lib/tss2/tss2_structs.h line 636
Quoted 8 lines
grub-core/lib/tss2/tss2_structs.h new file +8
-0+ +/* TPM2B_PRIVATE Structure */ +struct TPM2B_PRIVATE +{ +grub_uint16_t size; +grub_uint8_t buffer[sizeof (_PRIVATE)]; +}; +typedef struct TPM2B_PRIVATE TPM2B_PRIVATE ;Feel free to add my RB when you fix all these minor issues.
Thanks.
Gary Lin
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v18 15/25 tss2: Add TPM2 Software Stack (TSS2) support
In reply to Gary Lin via Grub-develA Trusted Platform Module (TPM) Software Stack (TSS) provides logic to compose and submit TPM commands and parse reponses.
A limited number of TPM commands may be accessed via the EFI TCG2 protocol. This protocol exposes functionality that is primarily geared toward TPM usage within the context of Secure Boot. For all other TPM commands, however, such as sealing and unsealing, this protocol does not provide any help, with the exception of passthrough command submission.
The SubmitCommand method allows a caller to send raw commands to the system's TPM and to receive the corresponding response. These command/response pairs are formatted using the TPM wire protocol. To construct commands in this way, and to parse the TPM's response, it is necessary to, first, possess knowledge of the various TPM structures, and, second, of the TPM wire protocol itself.
As such, this patch includes implementations of various TPM2_* functions (inventoried below), and logic to write and read command and response buffers, respectively, using the TPM wire protocol.
Functions: TPM2_Create, TPM2_CreatePrimary, TPM2_EvictControl, TPM2_FlushContext, TPM2_Load, TPM2_PCR_Read, TPM2_PolicyGetDigest, TPM2_PolicyPCR, TPM2_ReadPublic, TPM2_StartAuthSession, TPM2_Unseal, TPM2_LoadExternal, TPM2_Hash, TPM2_VerifySignature, TPM2_PolicyAuthorize, TPM2_TestParms
--- grub-core/Makefile.core.def | 11 + grub-core/lib/efi/tcg2.c | 144 +++++ grub-core/lib/tss2/tcg2.h | 35 ++ grub-core/lib/tss2/tpm2_cmd.c | 1054 +++++++++++++++++++++++++++++++++ grub-core/lib/tss2/tpm2_cmd.h | 157 +++++ grub-core/lib/tss2/tss2.c | 21 + 6 files changed, 1422 insertions(+) create mode 100644 grub-core/lib/efi/tcg2.c create mode 100644 grub-core/lib/tss2/tcg2.h create mode 100644 grub-core/lib/tss2/tpm2_cmd.c create mode 100644 grub-core/lib/tss2/tpm2_cmd.h create mode 100644 grub-core/lib/tss2/tss2.c
grub-core/Makefile.core.def +11 -0
@@ -2567,6 +2567,17 @@ module = { enable = efi; }; +module = { + name = tss2; + common = lib/tss2/buffer.c; + common = lib/tss2/tss2_mu.c; + common = lib/tss2/tpm2_cmd.c; + common = lib/tss2/tss2.c; + efi = lib/efi/tcg2.c; + enable = efi; + cppflags = '-I$(srcdir)/lib/tss2'; +}; + module = { name = tr; common = commands/tr.c;
grub-core/lib/efi/tcg2.c new file +144 -0
144 lines not on this page · raw message
grub-core/lib/tss2/tcg2.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 Free Software Foundation, Inc. +* Copyright (C) 2022 Microsoft Corporation +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef GRUB_TPM2_TCG2_HEADER +#define GRUB_TPM2_TCG2_HEADER 1 + +#include <grub/err.h> +#include <grub/types.h> + +grub_err_t +grub_tcg2_get_max_output_size (grub_size_t *size); + +grub_err_t +grub_tcg2_submit_command (grub_size_t input_size, +grub_uint8_t *input, +grub_size_t output_size, +grub_uint8_t *output); + +#endif /* ! GRUB_TPM2_TCG2_HEADER */
grub-core/lib/tss2/tpm2_cmd.c new file +1054 -0
1,054 lines not on this page · raw message
grub-core/lib/tss2/tpm2_cmd.h new file +157 -0
157 lines not on this page · raw message
grub-core/lib/tss2/tss2.c new file +21 -0
@@ -0,0 +1,21 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 Free Software Foundation, Inc. +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/dl.h> + +GRUB_MOD_LICENSE ("GPLv3+" );
Signature · 7 lines
2.35.3 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 15/25] tss2: Add TPM2 Software Stack (TSS2) support
Quoted 71 lines · Gary Lin via Grub-devel
A Trusted Platform Module (TPM) Software Stack (TSS) provides logic to compose and submit TPM commands and parse reponses.
A limited number of TPM commands may be accessed via the EFI TCG2 protocol. This protocol exposes functionality that is primarily geared toward TPM usage within the context of Secure Boot. For all other TPM commands, however, such as sealing and unsealing, this protocol does not provide any help, with the exception of passthrough command submission.
The SubmitCommand method allows a caller to send raw commands to the system's TPM and to receive the corresponding response. These command/response pairs are formatted using the TPM wire protocol. To construct commands in this way, and to parse the TPM's response, it is necessary to, first, possess knowledge of the various TPM structures, and, second, of the TPM wire protocol itself.
As such, this patch includes implementations of various TPM2_* functions (inventoried below), and logic to write and read command and response buffers, respectively, using the TPM wire protocol.
Functions:
TPM2_Create,TPM2_CreatePrimary,TPM2_EvictControl,TPM2_FlushContext,TPM2_Load,TPM2_PCR_Read,TPM2_PolicyGetDigest,TPM2_PolicyPCR,TPM2_ReadPublic,TPM2_StartAuthSession,TPM2_Unseal,TPM2_LoadExternal,TPM2_Hash,TPM2_VerifySignature,TPM2_PolicyAuthorize,TPM2_TestParmsCc Stefan Berger <[email protected]>Signed-off-by Hernan Gatta <[email protected]>Signed-off-by Gary Lin <[email protected]>--- grub-core/Makefile.core.def | 11 + grub-core/lib/efi/tcg2.c | 144 +++++ grub-core/lib/tss2/tcg2.h | 35 ++ grub-core/lib/tss2/tpm2_cmd.c | 1054 +++++++++++++++++++++++++++++++++ grub-core/lib/tss2/tpm2_cmd.h | 157 +++++ grub-core/lib/tss2/tss2.c | 21 + 6 files changed, 1422 insertions(+) create mode 100644 grub-core/lib/efi/tcg2.c create mode 100644 grub-core/lib/tss2/tcg2.h create mode 100644 grub-core/lib/tss2/tpm2_cmd.c create mode 100644 grub-core/lib/tss2/tpm2_cmd.h create mode 100644 grub-core/lib/tss2/tss2.cgrub-core/Makefile.core.def +11
-0@@ -2567,6 +2567,17 @@ module = { enable = efi; }; +module = { + name = tss2; + common = lib/tss2/buffer.c; + common = lib/tss2/tss2_mu.c; + common = lib/tss2/tpm2_cmd.c; + common = lib/tss2/tss2.c; + efi = lib/efi/tcg2.c; + enable = efi; + cppflags = '-I$(srcdir)/lib/tss2'; +}; + module = { name = tr; common = commands/tr.c;grub-core/lib/efi/tcg2.c new file +0
-0
grub-core/lib/efi/tcg2.c line 4
Quoted 4 lines
grub-core/lib/efi/tcg2.c new file +4
-0@@ -0,0 +1,144 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 Free Software Foundation, Inc. +* Copyright (C) 2022 Microsoft Corporation
Wrong order... I will not comment these mistakes any longer but all of them have to fixed.
Quoted 17 lines
grub-core/lib/efi/tcg2.c new file +17
-0+* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/efi/api.h> +#include <grub/efi/efi.h> +#include <grub/efi/tpm.h>
grub-core/lib/efi/tcg2.c line 32
Quoted 10 lines
grub-core/lib/efi/tcg2.c new file +10
-0+#include <grub/mm.h> + +#include <tcg2.h> + +static grub_err_t +grub_tcg2_get_caps (grub_efi_tpm2_protocol_t *protocol,int *tpm2, +grub_size_t *max_output_size) +{ +grub_efi_status_t status; +static int has_caps =0 ;
Please use bool instead.
Quoted 22 lines
grub-core/lib/efi/tcg2.c new file +22
-0+static EFI_TCG2_BOOT_SERVICE_CAPABILITY caps = + { + .Size = (grub_uint8_t )sizeof (caps) + }; + +if (has_caps) + goto exit; + + status = protocol->get_capability (protocol, &caps); +if (status !=GRUB_EFI_SUCCESS || !caps.TPMPresentFlag) +return GRUB_ERR_FILE_NOT_FOUND ; + + has_caps =1 ; + + exit: +if (tpm2 !=NULL ) + *tpm2 = caps.TPMPresentFlag; +if (max_output_size !=NULL ) + *max_output_size = caps.MaxResponseSize; + +return GRUB_ERR_NONE ; +}
[...]
Quoted 79 lines
grub-core/lib/tss2/tpm2_cmd.c new file +73
-0@@ -0,0 +1,1054 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 Free Software Foundation, Inc. +* Copyright (C) 2022 Microsoft Corporation +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/err.h> +#include <grub/mm.h> +#include <grub/misc.h> +#include <grub/types.h> + +#include <tss2_buffer.h> +#include <tss2_mu.h> +#include <tss2_structs.h> +#include <tcg2.h> +#include <tpm2_cmd.h> + +static TPM_RC +grub_tpm2_submit_command_real (const TPMI_ST_COMMAND_TAG tag, +const TPM_CC commandCode, +TPM_RC *responseCode, +const struct grub_tpm2_buffer *in, +struct grub_tpm2_buffer *out) +{ +grub_err_t err; +struct grub_tpm2_buffer buf; +TPMI_ST_COMMAND_TAG tag_out; +grub_uint32_t command_size; +grub_size_t max_output_size; + +/* Marshal */ +grub_tpm2_buffer_init (&buf); +grub_tpm2_buffer_pack_u16 (&buf, tag); +grub_tpm2_buffer_pack_u32 (&buf,0 ); +grub_tpm2_buffer_pack_u32 (&buf, commandCode); +grub_tpm2_buffer_pack (&buf, in->data, in->size); + +if (buf.error !=0 ) +return TPM_RC_FAILURE ; + + command_size =grub_swap_bytes32 (buf.size); +grub_memcpy (&buf.data[sizeof (grub_uint16_t)], &command_size, +sizeof (command_size)); + +/* Stay within output block limits */ + err =grub_tcg2_get_max_output_size (&max_output_size); +if (err !=GRUB_ERR_NONE || max_output_size > out->cap) + max_output_size = out->cap -1 ; + +/* Submit */ + err =grub_tcg2_submit_command (buf.size, buf.data, max_output_size, + out->data); +if (err !=GRUB_ERR_NONE ) +return TPM_RC_FAILURE ; + +/* Unmarshal */ + out->size =sizeof (grub_uint16_t) +sizeof (grub_uint32_t) + +sizeof (grub_uint32_t); +grub_tpm2_buffer_unpack_u16 (out, &tag_out); +grub_tpm2_buffer_unpack_u32 (out, &command_size);
grub-core/lib/tss2/tpm2_cmd.c line 83
Quoted 10 lines
grub-core/lib/tss2/tpm2_cmd.c new file +10
-0+grub_tpm2_buffer_unpack_u32 (out, responseCode); + out->size = command_size; +if (out->error !=0 ) +return TPM_RC_FAILURE ; + +return TPM_RC_SUCCESS ; +} + +static TPM_RC +grub_tpm2_submit_command (const TPMI_ST_COMMAND_TAG tag,
You do not need "grub_" prefix before local symbols. Please drop it here and there, in the other patches as well.
Quoted 13 lines
grub-core/lib/tss2/tpm2_cmd.c new file +13
-0+const TPM_CC commandCode, + TPM_RC *responseCode, + const struct grub_tpm2_buffer *in, + struct grub_tpm2_buffer *out) +{ + TPM_RC err; +int retry_cnt =0 ; + +/* Catch TPM_RC_RETRY and send the command again */ + do { + err = grub_tpm2_submit_command_real (tag, commandCode, responseCode, + in, out); + if (*responseCode != TPM_RC_RETRY)
grub-core/lib/tss2/tpm2_cmd.c line 106
Quoted 10 lines
grub-core/lib/tss2/tpm2_cmd.c new file +10
-0+break ; + + retry_cnt++; + }while (retry_cnt <3 ); + +return err; +} + +TPM_RC +TPM2_CreatePrimary (const TPMI_RH_HIERARCHY primaryHandle,
All global symbols should be prefixed with "grub_" or "GRUB_". [1] I think I saw similar problems in earlier patches as well. Please fix all these issues...
If you fix all these minor issues feel free to add my RB to the patch.
Daniel
[1] https://www.gnu.org/software/grub/manual/grub-dev/grub-dev.html#Naming-Conventions
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 15/25] tss2: Add TPM2 Software Stack (TSS2) support
Quoted 71 lines · Daniel Kiper
Quoted 70 lines · Gary Lin via Grub-devel
A Trusted Platform Module (TPM) Software Stack (TSS) provides logic to compose and submit TPM commands and parse reponses.
A limited number of TPM commands may be accessed via the EFI TCG2 protocol. This protocol exposes functionality that is primarily geared toward TPM usage within the context of Secure Boot. For all other TPM commands, however, such as sealing and unsealing, this protocol does not provide any help, with the exception of passthrough command submission.
The SubmitCommand method allows a caller to send raw commands to the system's TPM and to receive the corresponding response. These command/response pairs are formatted using the TPM wire protocol. To construct commands in this way, and to parse the TPM's response, it is necessary to, first, possess knowledge of the various TPM structures, and, second, of the TPM wire protocol itself.
As such, this patch includes implementations of various TPM2_* functions (inventoried below), and logic to write and read command and response buffers, respectively, using the TPM wire protocol.
Functions:
TPM2_Create,TPM2_CreatePrimary,TPM2_EvictControl,TPM2_FlushContext,TPM2_Load,TPM2_PCR_Read,TPM2_PolicyGetDigest,TPM2_PolicyPCR,TPM2_ReadPublic,TPM2_StartAuthSession,TPM2_Unseal,TPM2_LoadExternal,TPM2_Hash,TPM2_VerifySignature,TPM2_PolicyAuthorize,TPM2_TestParmsCc Stefan Berger <[email protected]>Signed-off-by Hernan Gatta <[email protected]>Signed-off-by Gary Lin <[email protected]>--- grub-core/Makefile.core.def | 11 + grub-core/lib/efi/tcg2.c | 144 +++++ grub-core/lib/tss2/tcg2.h | 35 ++ grub-core/lib/tss2/tpm2_cmd.c | 1054 +++++++++++++++++++++++++++++++++ grub-core/lib/tss2/tpm2_cmd.h | 157 +++++ grub-core/lib/tss2/tss2.c | 21 + 6 files changed, 1422 insertions(+) create mode 100644 grub-core/lib/efi/tcg2.c create mode 100644 grub-core/lib/tss2/tcg2.h create mode 100644 grub-core/lib/tss2/tpm2_cmd.c create mode 100644 grub-core/lib/tss2/tpm2_cmd.h create mode 100644 grub-core/lib/tss2/tss2.cgrub-core/Makefile.core.def +11
-0@@ -2567,6 +2567,17 @@ module = { enable = efi; }; +module = { + name = tss2; + common = lib/tss2/buffer.c; + common = lib/tss2/tss2_mu.c; + common = lib/tss2/tpm2_cmd.c; + common = lib/tss2/tss2.c; + efi = lib/efi/tcg2.c; + enable = efi; + cppflags = '-I$(srcdir)/lib/tss2'; +}; + module = { name = tr; common = commands/tr.c;grub-core/lib/efi/tcg2.c new file +0
-0
Quoted 9 lines
grub-core/lib/efi/tcg2.c line 4
Quoted 5 lines
grub-core/lib/efi/tcg2.c new file +4
-0@@ -0,0 +1,144 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 Free Software Foundation, Inc. +* Copyright (C) 2022 Microsoft Corporation Wrong order... I will not comment these mistakes any longer but all of them have to fixed.
Sorry for that. The order issues are fixed in my WIP branch.
Quoted 21 lines
Quoted 21 lines
grub-core/lib/efi/tcg2.c new file +21
-0+* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/efi/api.h> +#include <grub/efi/efi.h> +#include <grub/efi/tpm.h> +#include <grub/mm.h> + +#include <tcg2.h> +
Quoted 9 lines
grub-core/lib/efi/tcg2.c line 32
Quoted 6 lines
grub-core/lib/efi/tcg2.c new file +6
-0+static grub_err_t +grub_tcg2_get_caps (grub_efi_tpm2_protocol_t *protocol,int *tpm2, +grub_size_t *max_output_size) +{ +grub_efi_status_t status; +static int has_caps =0 ;Please use bool instead.
Sure.
Quoted 109 lines
Quoted 22 lines
grub-core/lib/efi/tcg2.c new file +22
-0+static EFI_TCG2_BOOT_SERVICE_CAPABILITY caps = + { + .Size = (grub_uint8_t )sizeof (caps) + }; + +if (has_caps) + goto exit; + + status = protocol->get_capability (protocol, &caps); +if (status !=GRUB_EFI_SUCCESS || !caps.TPMPresentFlag) +return GRUB_ERR_FILE_NOT_FOUND ; + + has_caps =1 ; + + exit: +if (tpm2 !=NULL ) + *tpm2 = caps.TPMPresentFlag; +if (max_output_size !=NULL ) + *max_output_size = caps.MaxResponseSize; + +return GRUB_ERR_NONE ; +}[...]
Quoted 84 lines
grub-core/lib/tss2/tpm2_cmd.c new file +78
-0@@ -0,0 +1,1054 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 Free Software Foundation, Inc. +* Copyright (C) 2022 Microsoft Corporation +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/err.h> +#include <grub/mm.h> +#include <grub/misc.h> +#include <grub/types.h> + +#include <tss2_buffer.h> +#include <tss2_mu.h> +#include <tss2_structs.h> +#include <tcg2.h> +#include <tpm2_cmd.h> + +static TPM_RC +grub_tpm2_submit_command_real (const TPMI_ST_COMMAND_TAG tag, +const TPM_CC commandCode, +TPM_RC *responseCode, +const struct grub_tpm2_buffer *in, +struct grub_tpm2_buffer *out) +{ +grub_err_t err; +struct grub_tpm2_buffer buf; +TPMI_ST_COMMAND_TAG tag_out; +grub_uint32_t command_size; +grub_size_t max_output_size; + +/* Marshal */ +grub_tpm2_buffer_init (&buf); +grub_tpm2_buffer_pack_u16 (&buf, tag); +grub_tpm2_buffer_pack_u32 (&buf,0 ); +grub_tpm2_buffer_pack_u32 (&buf, commandCode); +grub_tpm2_buffer_pack (&buf, in->data, in->size); + +if (buf.error !=0 ) +return TPM_RC_FAILURE ; + + command_size =grub_swap_bytes32 (buf.size); +grub_memcpy (&buf.data[sizeof (grub_uint16_t)], &command_size, +sizeof (command_size)); + +/* Stay within output block limits */ + err =grub_tcg2_get_max_output_size (&max_output_size); +if (err !=GRUB_ERR_NONE || max_output_size > out->cap) + max_output_size = out->cap -1 ; + +/* Submit */ + err =grub_tcg2_submit_command (buf.size, buf.data, max_output_size, + out->data); +if (err !=GRUB_ERR_NONE ) +return TPM_RC_FAILURE ; + +/* Unmarshal */ + out->size =sizeof (grub_uint16_t) +sizeof (grub_uint32_t) + +sizeof (grub_uint32_t); +grub_tpm2_buffer_unpack_u16 (out, &tag_out); +grub_tpm2_buffer_unpack_u32 (out, &command_size); +grub_tpm2_buffer_unpack_u32 (out, responseCode); + out->size = command_size; +if (out->error !=0 ) +return TPM_RC_FAILURE ; +
Quoted 9 lines
grub-core/lib/tss2/tpm2_cmd.c line 83
Quoted 5 lines
grub-core/lib/tss2/tpm2_cmd.c new file +5
-0+return TPM_RC_SUCCESS ; +} + +static TPM_RC +grub_tpm2_submit_command (const TPMI_ST_COMMAND_TAG tag,You do not need "
grub_" prefix before local symbols. Please drop it here and there, in the other patches as well.
I'll revise the patches to remove the unnecessary "grub_" prefix.
Quoted 19 lines
Quoted 19 lines
grub-core/lib/tss2/tpm2_cmd.c new file +19
-0+const TPM_CC commandCode, + TPM_RC *responseCode, + const struct grub_tpm2_buffer *in, + struct grub_tpm2_buffer *out) +{ + TPM_RC err; +int retry_cnt =0 ; + +/* Catch TPM_RC_RETRY and send the command again */ +do { + err =grub_tpm2_submit_command_real (tag, commandCode, responseCode, + in, out); +if (*responseCode !=TPM_RC_RETRY ) +break ; + + retry_cnt++; + }while (retry_cnt <3 ); + +return err;
Quoted 9 lines
grub-core/lib/tss2/tpm2_cmd.c line 106
Quoted 4 lines
grub-core/lib/tss2/tpm2_cmd.c new file +4
-0+} + +TPM_RC +TPM2_CreatePrimary (const TPMI_RH_HIERARCHY primaryHandle,All global symbols should be prefixed with "
grub_" or "GRUB_". [1] I think I saw similar problems in earlier patches as well. Please fix all these issues...
Ok.
Quoted 2 lines
If you fix all these minor issues feel free to add my RB to the patch.
Thanks.
Gary Lin
Quoted 3 lines
Daniel
[1] https://www.gnu.org/software/grub/manual/grub-dev/grub-dev.html#Naming-Conventions
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v18 16/25 key_protector: Add TPM2 Key Protector
In reply to Gary Lin via Grub-develFrom: Hernan Gatta <[email protected]>
The TPM2 key protector is a module that enables the automatic retrieval of a fully-encrypted disk's unlocking key from a TPM 2.0.
The theory of operation is such that the module accepts various arguments, most of which are optional and therefore possess reasonable defaults. One of these arguments is the keyfile/tpm2key parameter, which is mandatory. There are two supported key formats:
1. Raw Sealed Key (--keyfile)
When sealing a key with TPM2_Create, the public portion of the sealed key is stored in TPM2B_PUBLIC, and the private portion is in TPM2B_PRIVATE. The raw sealed key glues the fully marshalled TPM2B_PUBLIC and TPM2B_PRIVATE into one file.
2. TPM 2.0 Key (--tpm2key)
The following is the ASN.1 definition of TPM 2.0 Key File:
TPMPolicy ::= SEQUENCE {
CommandCode [0] EXPLICIT INTEGER
CommandPolicy [1] EXPLICIT OCTET STRING
}
TPMAuthPolicy ::= SEQUENCE {
Name [0] EXPLICIT UTF8STRING OPTIONAL
Policy [1] EXPLICIT SEQUENCE OF TPMPolicy
}TPMKey ::= SEQUENCE {
type OBJECT IDENTIFIER
emptyAuth [0] EXPLICIT BOOLEAN OPTIONAL
policy [1] EXPLICIT SEQUENCE OF TPMPolicy OPTIONAL
secret [2] EXPLICIT OCTET STRING OPTIONAL
authPolicy [3] EXPLICIT SEQUENCE OF TPMAuthPolicy OPTIONAL description [4] EXPLICIT UTF8String OPTIONAL,
rsaParent [5] EXPLICIT BOOLEAN OPTIONAL,
parent INTEGER
pubkey OCTET STRING
privkey OCTET STRING
}
The TPM2 key protector only expects a "sealed" key in DER encoding, so 'type' is always 2.23.133.10.1.5, 'emptyAuth' is 'TRUE', and 'secret' is empty. 'policy' and 'authPolicy' are the possible policy command sequences to construst the policy digest to unseal the key. Similar to the raw sealed key, the public portion (TPM2B_PUBLIC) of the sealed key is stored in 'pubkey', and the private portion (TPM2B_PRIVATE) is in 'privkey'.
For more details: https://www.hansenpartnership.com/draft-bottomley-tpm2-keys.html
This sealed key file is created via the grub-protect tool. The tool utilizes the TPM's sealing functionality to seal (i.e., encrypt) an unlocking key using a Storage Root Key (SRK) to the values of various Platform Configuration Registers (PCRs). These PCRs reflect the state of the system as it boots. If the values are as expected, the system may be considered trustworthy, at which point the TPM allows for a caller to utilize the private component of the SRK to unseal (i.e., decrypt) the sealed key file. The caller, in this case, is this key protector.
The TPM2 key protector registers two commands:
- tpm2_key_protector_init: Initializes the state of the TPM2 key protector for later usage, clearing any previous state, too, if any.
- tpm2_key_protector_clear: Clears any state set by tpm2_key_protector_init.
The way this is expected to be used requires the user to, either interactively or, normally, via a boot script, initialize/configure the key protector and then specify that it be used by the 'cryptomount' command (modifications to this command are in a different patch).
For instance, to unseal the raw sealed key file:
tpm2_key_protector_init --keyfile=(hd0,gpt1)/efi/grub2/sealed-1.key cryptomount -u <PART1_UUID> -P tpm2
tpm2_key_protector_init --keyfile=(hd0,gpt1)/efi/grub2/sealed-2.key --pcrs=7,11 cryptomount -u <PART2_UUID> -P tpm2
Or, to unseal the TPM 2.0 Key file:
tpm2_key_protector_init --tpm2key=(hd0,gpt1)/efi/grub2/sealed-1.tpm cryptomount -u <PART1_UUID> -P tpm2
tpm2_key_protector_init --tpm2key=(hd0,gpt1)/efi/grub2/sealed-2.tpm --pcrs=7,11 cryptomount -u <PART2_UUID> -P tpm2
If a user does not initialize the key protector and attempts to use it anyway, the protector returns an error.
Before unsealing the key, the TPM2 key protector follows the "TPMPolicy" sequences to enforce the TPM policy commands to construct a valid policy digest to unseal the key.
For the TPM 2.0 Key files, 'authPolicy' may contain multiple "TPMPolicy" sequences, the TPM2 key protector iterates 'authPolicy' to find a valid sequence to unseal key. If 'authPolicy' is empty or all sequences in 'authPolicy' fail, the protector tries the one from 'policy'. In case 'policy' is also empty, the protector creates a "TPMPolicy" sequence based on the given PCR selection.
For the raw sealed key, the TPM2 key protector treats the key file as a TPM 2.0 Key file without 'authPolicy' and 'policy', so the "TPMPolicy" sequence is always based on the PCR selection from the command parameters.
This commit only supports one policy command: TPM2_PolicyPCR. The command set will be extended to support advanced features, such as authorized policy, in the later commits.
--- grub-core/Makefile.core.def | 11 + grub-core/commands/tpm2_key_protector/args.c | 130 ++ .../commands/tpm2_key_protector/module.c | 1162 +++++++++++++++++ grub-core/commands/tpm2_key_protector/tpm2.h | 36 + .../commands/tpm2_key_protector/tpm2_args.h | 51 + .../commands/tpm2_key_protector/tpm2key.asn | 49 + .../commands/tpm2_key_protector/tpm2key.c | 499 +++++++ .../commands/tpm2_key_protector/tpm2key.h | 87 ++ .../tpm2_key_protector/tpm2key_asn1_tab.c | 63 + 9 files changed, 2088 insertions(+) create mode 100644 grub-core/commands/tpm2_key_protector/args.c create mode 100644 grub-core/commands/tpm2_key_protector/module.c create mode 100644 grub-core/commands/tpm2_key_protector/tpm2.h create mode 100644 grub-core/commands/tpm2_key_protector/tpm2_args.h create mode 100644 grub-core/commands/tpm2_key_protector/tpm2key.asn create mode 100644 grub-core/commands/tpm2_key_protector/tpm2key.c create mode 100644 grub-core/commands/tpm2_key_protector/tpm2key.h create mode 100644 grub-core/commands/tpm2_key_protector/tpm2key_asn1_tab.c
grub-core/Makefile.core.def +11 -0
@@ -2578,6 +2578,17 @@ module = { cppflags = '-I$(srcdir)/lib/tss2'; }; +module = { + name = tpm2_key_protector; + common = commands/tpm2_key_protector/args.c; + common = commands/tpm2_key_protector/module.c; + common = commands/tpm2_key_protector/tpm2key.c; + common = commands/tpm2_key_protector/tpm2key_asn1_tab.c; + /* The plaform support of tpm2_key_protector depends on the tcg2 implementation in tss2. */ + enable = efi; + cppflags = '-I$(srcdir)/lib/tss2 -I$(srcdir)/lib/libtasn1-grub'; +}; + module = { name = tr; common = commands/tr.c;
grub-core/commands/tpm2_key_protector/args.c new file +130 -0
130 lines not on this page · raw message
grub-core/commands/tpm2_key_protector/module.c new file +1162 -0
1,162 lines not on this page · raw message
grub-core/commands/tpm2_key_protector/tpm2.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 Free Software Foundation, Inc. +* Copyright (C) 2022 Microsoft Corporation +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef GRUB_TPM2_TPM2_HEADER +#define GRUB_TPM2_TPM2_HEADER 1 + +#include <tss2_types.h> +#include <tss2_structs.h> +#include <tpm2_cmd.h> + +/* Well-Known Windows SRK handle */ +#define TPM2_SRK_HANDLE 0x81000001 + +struct tpm2_sealed_key { +TPM2B_PUBLIC public; +TPM2B_PRIVATE private; +}; +typedef struct tpm2_sealed_key tpm2_sealed_key_t ; + +#endif /* ! GRUB_TPM2_TPM2_HEADER */
grub-core/commands/tpm2_key_protector/tpm2_args.h new file +51 -0
51 lines not on this page · raw message
grub-core/commands/tpm2_key_protector/tpm2key.asn new file +49 -0
49 lines not on this page · raw message
grub-core/commands/tpm2_key_protector/tpm2key.c new file +499 -0
499 lines not on this page · raw message
grub-core/commands/tpm2_key_protector/tpm2key.h new file +87 -0
87 lines not on this page · raw message
grub-core/commands/tpm2_key_protector/tpm2key_asn1_tab.c new file +63 -0
63 lines not on this page · raw message
Signature · 7 lines
2.35.3 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 16/25] key_protector: Add TPM2 Key Protector
Quoted 138 lines · Gary Lin via Grub-devel
From: Hernan Gatta <[email protected]>
The TPM2 key protector is a module that enables the automatic retrieval of a fully-encrypted disk's unlocking key from a TPM 2.0.
The theory of operation is such that the module accepts various arguments, most of which are optional and therefore possess reasonable defaults. One of these arguments is the keyfile/tpm2key parameter, which is mandatory. There are two supported key formats:
1. Raw Sealed Key (--keyfile)
When sealing a key withTPM2_Create, the public portion of the sealed key is stored inTPM2B_PUBLIC, and the private portion is inTPM2B_PRIVATE. The raw sealed key glues the fully marshalledTPM2B_PUBLICandTPM2B_PRIVATEinto one file.2. TPM 2.0 Key (--tpm2key)
The following is the ASN.1 definition of TPM 2.0 Key File:TPMPolicy ::= SEQUENCE { CommandCode [0] EXPLICIT INTEGER CommandPolicy [1] EXPLICIT OCTET STRING } TPMAuthPolicy ::= SEQUENCE { Name [0] EXPLICIT UTF8STRING OPTIONAL Policy [1] EXPLICIT SEQUENCE OF TPMPolicy }TPMKey ::= SEQUENCE {
type OBJECT IDENTIFIER emptyAuth [0] EXPLICIT BOOLEAN OPTIONAL policy [1] EXPLICIT SEQUENCE OF TPMPolicy OPTIONAL secret [2] EXPLICIT OCTET STRING OPTIONAL authPolicy [3] EXPLICIT SEQUENCE OF TPMAuthPolicy OPTIONALdescription [4] EXPLICIT UTF8String OPTIONAL,
rsaParent [5] EXPLICIT BOOLEAN OPTIONAL,
parent INTEGER
pubkey OCTET STRING
privkey OCTET STRING
}The TPM2 key protector only expects a "sealed" key in DER encoding, so 'type' is always 2.23.133.10.1.5, 'emptyAuth' is 'TRUE', and 'secret' is empty. 'policy' and 'authPolicy' are the possible policy command sequences to construst the policy digest to unseal the key. Similar to the raw sealed key, the public portion (
TPM2B_PUBLIC) of the sealed key is stored in 'pubkey', and the private portion (TPM2B_PRIVATE) is in 'privkey'.For more details: https://www.hansenpartnership.com/draft-bottomley-tpm2-keys.html
This sealed key file is created via the grub-protect tool. The tool utilizes the TPM's sealing functionality to seal (i.e., encrypt) an unlocking key using a Storage Root Key (SRK) to the values of various Platform Configuration Registers (PCRs). These PCRs reflect the state of the system as it boots. If the values are as expected, the system may be considered trustworthy, at which point the TPM allows for a caller to utilize the private component of the SRK to unseal (i.e., decrypt) the sealed key file. The caller, in this case, is this key protector.
The TPM2 key protector registers two commands:
-
tpm2_key_protector_init: Initializes the state of the TPM2 key protector for later usage, clearing any previous state, too, if any.-
tpm2_key_protector_clear: Clears any state set bytpm2_key_protector_init.The way this is expected to be used requires the user to, either interactively or, normally, via a boot script, initialize/configure the key protector and then specify that it be used by the 'cryptomount' command (modifications to this command are in a different patch).
For instance, to unseal the raw sealed key file:
tpm2_key_protector_init--keyfile=(hd0,gpt1)/efi/grub2/sealed-1.key cryptomount -u <PART1_UUID> -P tpm2
tpm2_key_protector_init--keyfile=(hd0,gpt1)/efi/grub2/sealed-2.key --pcrs=7,11 cryptomount -u <PART2_UUID> -P tpm2Or, to unseal the TPM 2.0 Key file:
tpm2_key_protector_init--tpm2key=(hd0,gpt1)/efi/grub2/sealed-1.tpm cryptomount -u <PART1_UUID> -P tpm2
tpm2_key_protector_init--tpm2key=(hd0,gpt1)/efi/grub2/sealed-2.tpm --pcrs=7,11 cryptomount -u <PART2_UUID> -P tpm2If a user does not initialize the key protector and attempts to use it anyway, the protector returns an error.
Before unsealing the key, the TPM2 key protector follows the "TPMPolicy" sequences to enforce the TPM policy commands to construct a valid policy digest to unseal the key.
For the TPM 2.0 Key files, 'authPolicy' may contain multiple "TPMPolicy" sequences, the TPM2 key protector iterates 'authPolicy' to find a valid sequence to unseal key. If 'authPolicy' is empty or all sequences in 'authPolicy' fail, the protector tries the one from 'policy'. In case 'policy' is also empty, the protector creates a "TPMPolicy" sequence based on the given PCR selection.
For the raw sealed key, the TPM2 key protector treats the key file as a TPM 2.0 Key file without 'authPolicy' and 'policy', so the "TPMPolicy" sequence is always based on the PCR selection from the command parameters.
This commit only supports one policy command:
TPM2_PolicyPCR. The command set will be extended to support advanced features, such as authorized policy, in the later commits.Cc Stefan Berger <[email protected]>Cc James Bottomley <[email protected]>Signed-off-by Hernan Gatta <[email protected]>Signed-off-by Gary Lin <[email protected]>--- grub-core/Makefile.core.def | 11 + grub-core/commands/tpm2_key_protector/args.c | 130 ++ .../commands/tpm2_key_protector/module.c | 1162 +++++++++++++++++ grub-core/commands/tpm2_key_protector/tpm2.h | 36 + .../commands/tpm2_key_protector/tpm2_args.h | 51 + .../commands/tpm2_key_protector/tpm2key.asn | 49 + .../commands/tpm2_key_protector/tpm2key.c | 499 +++++++ .../commands/tpm2_key_protector/tpm2key.h | 87 ++ .../tpm2_key_protector/tpm2key_asn1_tab.c | 63 + 9 files changed, 2088 insertions(+) create mode 100644 grub-core/commands/tpm2_key_protector/args.c create mode 100644 grub-core/commands/tpm2_key_protector/module.c create mode 100644 grub-core/commands/tpm2_key_protector/tpm2.h create mode 100644 grub-core/commands/tpm2_key_protector/tpm2_args.h create mode 100644 grub-core/commands/tpm2_key_protector/tpm2key.asn create mode 100644 grub-core/commands/tpm2_key_protector/tpm2key.c create mode 100644 grub-core/commands/tpm2_key_protector/tpm2key.h create mode 100644 grub-core/commands/tpm2_key_protector/tpm2key_asn1_tab.c
[...]
Quoted 5 lines
grub-core/commands/tpm2_key_protector/module.c new file +0
-0
[...]
grub-core/commands/tpm2_key_protector/module.c line 174
Quoted 12 lines
grub-core/commands/tpm2_key_protector/module.c new file +12
-0+static grub_err_t +grub_tpm2_protector_srk_read_file (const char *filepath,void **buffer, +grub_size_t *buffer_size) +{ +grub_file_t file; +grub_off_t file_size; +void *read_buffer; +grub_off_t read_n; +grub_err_t err; + +/* Using GRUB_FILE_TYPE_SIGNATURE ensures we do not hash the keyfile into PCR9 +* otherwise we'll never be able to predict the value of PCR9 at unseal time */
Wrong coding style...
Quoted 43 lines
grub-core/commands/tpm2_key_protector/module.c new file +43
-0+ file =grub_file_open (filepath,GRUB_FILE_TYPE_SIGNATURE ); +if (file ==NULL ) + { +/* Push errno from grub_file_open() into the error message stack */ +grub_error_push (); + err =grub_error (GRUB_ERR_FILE_NOT_FOUND ,N_ ("Could not open file: %s\n" ), filepath); + goto error; + } + + file_size =grub_file_size (file); +if (file_size ==0 ) + { + err =grub_error (GRUB_ERR_OUT_OF_RANGE ,N_ ("Could not read file size: %s" ), filepath); + goto error; + } + + read_buffer =grub_malloc (file_size); +if (read_buffer ==NULL ) + { + err =grub_error (GRUB_ERR_OUT_OF_MEMORY ,N_ ("Could not allocate buffer for %s" ), filepath); + goto error; + } + + read_n =grub_file_read (file, read_buffer, file_size); +if (read_n != file_size) + { +grub_free (read_buffer); + err =grub_error (GRUB_ERR_FILE_READ_ERROR ,N_ ("Could not retrieve file contents: %s" ), filepath); + goto error; + } + + *buffer = read_buffer; + *buffer_size = file_size; + + err =GRUB_ERR_NONE ; + + error: +if (file !=NULL ) +grub_file_close (file); + +return err; +} +
grub-core/commands/tpm2_key_protector/module.c line 227
Quoted 10 lines
grub-core/commands/tpm2_key_protector/module.c new file +10
-0+static grub_err_t +grub_tpm2_protector_srk_unmarshal_keyfile (void *sealed_key, +grub_size_t sealed_key_size, +tpm2_sealed_key_t *sk) +{ +struct grub_tpm2_buffer buf; + +grub_tpm2_buffer_init (&buf); +if (sealed_key_size > buf.cap) +return grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("Sealed key larger than %" PRIuGRUB_SIZE" bytes" ), buf.cap);
Macros, e.g PRIuGRUB_SIZE, cannot be used in _() and N_() macros.
In general please double check _() and N_() macros usage and drop some of them as Vladimir suggested.
[...]
Quoted 19 lines
grub-core/commands/tpm2_key_protector/tpm2key_asn1_tab.c new file +13
-0@@ -0,0 +1,63 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 Free Software Foundation, Inc. +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details.
grub-core/commands/tpm2_key_protector/tpm2key_asn1_tab.c line 23
Quoted 10 lines
grub-core/commands/tpm2_key_protector/tpm2key_asn1_tab.c new file +10
-0+* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +/* +* This file is generated by 'asn1Parser tpm2key.asn' and the '#include' +* headers are replaced with the ones in grub2. +* - 'grub/mm.h' for the definition of 'NULL' +* - 'libtasn1.h' for the definition of 'asn1_static_node'
I think the configure.ac should be updated to check for availability of asn1Parser command. This requirement should be reflected in INSTALL file too.
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 16/25] key_protector: Add TPM2 Key Protector
Quoted 150 lines · Daniel Kiper
Quoted 138 lines · Gary Lin via Grub-devel
From: Hernan Gatta <[email protected]>
The TPM2 key protector is a module that enables the automatic retrieval of a fully-encrypted disk's unlocking key from a TPM 2.0.
The theory of operation is such that the module accepts various arguments, most of which are optional and therefore possess reasonable defaults. One of these arguments is the keyfile/tpm2key parameter, which is mandatory. There are two supported key formats:
1. Raw Sealed Key (--keyfile)
When sealing a key withTPM2_Create, the public portion of the sealed key is stored inTPM2B_PUBLIC, and the private portion is inTPM2B_PRIVATE. The raw sealed key glues the fully marshalledTPM2B_PUBLICandTPM2B_PRIVATEinto one file.2. TPM 2.0 Key (--tpm2key)
The following is the ASN.1 definition of TPM 2.0 Key File:TPMPolicy ::= SEQUENCE { CommandCode [0] EXPLICIT INTEGER CommandPolicy [1] EXPLICIT OCTET STRING } TPMAuthPolicy ::= SEQUENCE { Name [0] EXPLICIT UTF8STRING OPTIONAL Policy [1] EXPLICIT SEQUENCE OF TPMPolicy }TPMKey ::= SEQUENCE {
type OBJECT IDENTIFIER emptyAuth [0] EXPLICIT BOOLEAN OPTIONAL policy [1] EXPLICIT SEQUENCE OF TPMPolicy OPTIONAL secret [2] EXPLICIT OCTET STRING OPTIONAL authPolicy [3] EXPLICIT SEQUENCE OF TPMAuthPolicy OPTIONALdescription [4] EXPLICIT UTF8String OPTIONAL,
rsaParent [5] EXPLICIT BOOLEAN OPTIONAL,
parent INTEGER
pubkey OCTET STRING
privkey OCTET STRING
}The TPM2 key protector only expects a "sealed" key in DER encoding, so 'type' is always 2.23.133.10.1.5, 'emptyAuth' is 'TRUE', and 'secret' is empty. 'policy' and 'authPolicy' are the possible policy command sequences to construst the policy digest to unseal the key. Similar to the raw sealed key, the public portion (
TPM2B_PUBLIC) of the sealed key is stored in 'pubkey', and the private portion (TPM2B_PRIVATE) is in 'privkey'.For more details: https://www.hansenpartnership.com/draft-bottomley-tpm2-keys.html
This sealed key file is created via the grub-protect tool. The tool utilizes the TPM's sealing functionality to seal (i.e., encrypt) an unlocking key using a Storage Root Key (SRK) to the values of various Platform Configuration Registers (PCRs). These PCRs reflect the state of the system as it boots. If the values are as expected, the system may be considered trustworthy, at which point the TPM allows for a caller to utilize the private component of the SRK to unseal (i.e., decrypt) the sealed key file. The caller, in this case, is this key protector.
The TPM2 key protector registers two commands:
-
tpm2_key_protector_init: Initializes the state of the TPM2 key protector for later usage, clearing any previous state, too, if any.-
tpm2_key_protector_clear: Clears any state set bytpm2_key_protector_init.The way this is expected to be used requires the user to, either interactively or, normally, via a boot script, initialize/configure the key protector and then specify that it be used by the 'cryptomount' command (modifications to this command are in a different patch).
For instance, to unseal the raw sealed key file:
tpm2_key_protector_init--keyfile=(hd0,gpt1)/efi/grub2/sealed-1.key cryptomount -u <PART1_UUID> -P tpm2
tpm2_key_protector_init--keyfile=(hd0,gpt1)/efi/grub2/sealed-2.key --pcrs=7,11 cryptomount -u <PART2_UUID> -P tpm2Or, to unseal the TPM 2.0 Key file:
tpm2_key_protector_init--tpm2key=(hd0,gpt1)/efi/grub2/sealed-1.tpm cryptomount -u <PART1_UUID> -P tpm2
tpm2_key_protector_init--tpm2key=(hd0,gpt1)/efi/grub2/sealed-2.tpm --pcrs=7,11 cryptomount -u <PART2_UUID> -P tpm2If a user does not initialize the key protector and attempts to use it anyway, the protector returns an error.
Before unsealing the key, the TPM2 key protector follows the "TPMPolicy" sequences to enforce the TPM policy commands to construct a valid policy digest to unseal the key.
For the TPM 2.0 Key files, 'authPolicy' may contain multiple "TPMPolicy" sequences, the TPM2 key protector iterates 'authPolicy' to find a valid sequence to unseal key. If 'authPolicy' is empty or all sequences in 'authPolicy' fail, the protector tries the one from 'policy'. In case 'policy' is also empty, the protector creates a "TPMPolicy" sequence based on the given PCR selection.
For the raw sealed key, the TPM2 key protector treats the key file as a TPM 2.0 Key file without 'authPolicy' and 'policy', so the "TPMPolicy" sequence is always based on the PCR selection from the command parameters.
This commit only supports one policy command:
TPM2_PolicyPCR. The command set will be extended to support advanced features, such as authorized policy, in the later commits.Cc Stefan Berger <[email protected]>Cc James Bottomley <[email protected]>Signed-off-by Hernan Gatta <[email protected]>Signed-off-by Gary Lin <[email protected]>--- grub-core/Makefile.core.def | 11 + grub-core/commands/tpm2_key_protector/args.c | 130 ++ .../commands/tpm2_key_protector/module.c | 1162 +++++++++++++++++ grub-core/commands/tpm2_key_protector/tpm2.h | 36 + .../commands/tpm2_key_protector/tpm2_args.h | 51 + .../commands/tpm2_key_protector/tpm2key.asn | 49 + .../commands/tpm2_key_protector/tpm2key.c | 499 +++++++ .../commands/tpm2_key_protector/tpm2key.h | 87 ++ .../tpm2_key_protector/tpm2key_asn1_tab.c | 63 + 9 files changed, 2088 insertions(+) create mode 100644 grub-core/commands/tpm2_key_protector/args.c create mode 100644 grub-core/commands/tpm2_key_protector/module.c create mode 100644 grub-core/commands/tpm2_key_protector/tpm2.h create mode 100644 grub-core/commands/tpm2_key_protector/tpm2_args.h create mode 100644 grub-core/commands/tpm2_key_protector/tpm2key.asn create mode 100644 grub-core/commands/tpm2_key_protector/tpm2key.c create mode 100644 grub-core/commands/tpm2_key_protector/tpm2key.h create mode 100644 grub-core/commands/tpm2_key_protector/tpm2key_asn1_tab.c[...]
Quoted 5 lines
grub-core/commands/tpm2_key_protector/module.c new file +0
-0[...]
Quoted 15 lines
grub-core/commands/tpm2_key_protector/module.c line 174
Quoted 12 lines
grub-core/commands/tpm2_key_protector/module.c new file +12
-0+static grub_err_t +grub_tpm2_protector_srk_read_file (const char *filepath,void **buffer, +grub_size_t *buffer_size) +{ +grub_file_t file; +grub_off_t file_size; +void *read_buffer; +grub_off_t read_n; +grub_err_t err; + +/* Using GRUB_FILE_TYPE_SIGNATURE ensures we do not hash the keyfile into PCR9 +* otherwise we'll never be able to predict the value of PCR9 at unseal time */ Wrong coding style...
Will fix it in the next version.
Quoted 56 lines
Quoted 43 lines
grub-core/commands/tpm2_key_protector/module.c new file +43
-0+ file =grub_file_open (filepath,GRUB_FILE_TYPE_SIGNATURE ); +if (file ==NULL ) + { +/* Push errno from grub_file_open() into the error message stack */ +grub_error_push (); + err =grub_error (GRUB_ERR_FILE_NOT_FOUND ,N_ ("Could not open file: %s\n" ), filepath); + goto error; + } + + file_size =grub_file_size (file); +if (file_size ==0 ) + { + err =grub_error (GRUB_ERR_OUT_OF_RANGE ,N_ ("Could not read file size: %s" ), filepath); + goto error; + } + + read_buffer =grub_malloc (file_size); +if (read_buffer ==NULL ) + { + err =grub_error (GRUB_ERR_OUT_OF_MEMORY ,N_ ("Could not allocate buffer for %s" ), filepath); + goto error; + } + + read_n =grub_file_read (file, read_buffer, file_size); +if (read_n != file_size) + { +grub_free (read_buffer); + err =grub_error (GRUB_ERR_FILE_READ_ERROR ,N_ ("Could not retrieve file contents: %s" ), filepath); + goto error; + } + + *buffer = read_buffer; + *buffer_size = file_size; + + err =GRUB_ERR_NONE ; + + error: +if (file !=NULL ) +grub_file_close (file); + +return err; +} +grub-core/commands/tpm2_key_protector/module.c line 227
Quoted 10 lines
grub-core/commands/tpm2_key_protector/module.c new file +10
-0+static grub_err_t +grub_tpm2_protector_srk_unmarshal_keyfile (void *sealed_key, +grub_size_t sealed_key_size, +tpm2_sealed_key_t *sk) +{ +struct grub_tpm2_buffer buf; + +grub_tpm2_buffer_init (&buf); +if (sealed_key_size > buf.cap) +return grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("Sealed key larger than %" PRIuGRUB_SIZE" bytes" ), buf.cap);Macros, e.g
PRIuGRUB_SIZE, cannot be used in_()andN_()macros.
Quoted 3 lines
In general please double check
_()andN_()macros usage and drop some of them as Vladimir suggested.
Sure, I've removed all _() and N_() from all grub_error() in my working branch.
Quoted 27 lines
[...]
Quoted 25 lines
grub-core/commands/tpm2_key_protector/tpm2key_asn1_tab.c new file +19
-0@@ -0,0 +1,63 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 Free Software Foundation, Inc. +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +/*
Quoted 9 lines
grub-core/commands/tpm2_key_protector/tpm2key_asn1_tab.c line 23
Quoted 4 lines
grub-core/commands/tpm2_key_protector/tpm2key_asn1_tab.c new file +4
-0+* This file is generated by 'asn1Parser tpm2key.asn' and the '#include' +* headers are replaced with the ones in grub2. +* - 'grub/mm.h' for the definition of 'NULL' +* - 'libtasn1.h' for the definition of 'asn1_static_node' I think the configure.ac should be updated to check for availability of asn1Parser command. This requirement should be reflected in INSTALL file too.
I manually ran the asn1Parser command to generate the C file and then edited the file to add the copyright header and replace the header files. Should I generate the C file at build time?
Gary Lin
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v18 17/25 cryptodisk: Support key protectors
In reply to Gary Lin via Grub-develFrom: Hernan Gatta <[email protected]>
Add a new parameter to cryptomount to support the key protectors framework: -P. The parameter is used to automatically retrieve a key from specified key protectors. The parameter may be repeated to specify any number of key protectors. These are tried in order until one provides a usable key for any given disk.
--- Makefile.util.def | 1 + grub-core/disk/cryptodisk.c | 243 ++++++++++++++++++++++++++---------- include/grub/cryptodisk.h | 16 +++ 3 files changed, 196 insertions(+), 64 deletions(-)
Makefile.util.def +1 -0
@@ -40,6 +40,7 @@ library = { common = grub-core/disk/luks.c; common = grub-core/disk/luks2.c; common = grub-core/disk/geli.c; + common = grub-core/disk/key_protector.c; common = grub-core/disk/cryptodisk.c; common = grub-core/disk/AFSplitter.c; common = grub-core/lib/pbkdf2.c;
grub-core/disk/cryptodisk.c +179 -64
343 lines not on this page · raw message
include/grub/cryptodisk.h +16 -0
@@ -70,6 +70,18 @@ typedef gcry_err_code_t (*grub_cryptodisk_rekey_func_t) (struct grub_cryptodisk *dev, grub_uint64_t zoneno); +struct grub_cryptomount_cached_key +{ +grub_uint8_t *key; +grub_size_t key_len; + +/* +* The key protector associated with this cache entry failed, so avoid it +* even if the cached entry (an instance of this structure) is empty. +*/ +int invalid; +}; +struct grub_cryptomount_args {/* scan: Flag to indicate that only bootable volumes should be decrypted */
@@ -81,6 +93,10 @@ struct grub_cryptomount_args/* recover_key: Length of key_data */ grub_size_t key_len;grub_file_t hdr_file; +/* recover_key: Names of the key protectors to use (NULL-terminated) */ +char **protectors; +/* recover_key: Key cache to avoid invoking the same key protector twice */ +struct grub_cryptomount_cached_key *key_cache; };typedef struct grub_cryptomount_args *grub_cryptomount_args_t ;
Signature · 7 lines
2.35.3 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 17/25] cryptodisk: Support key protectors
Quoted 27 lines · Gary Lin via Grub-devel
From: Hernan Gatta <[email protected]>
Add a new parameter to cryptomount to support the key protectors framework: -P. The parameter is used to automatically retrieve a key from specified key protectors. The parameter may be repeated to specify any number of key protectors. These are tried in order until one provides a usable key for any given disk.
Signed-off-by Hernan Gatta <[email protected]>Signed-off-by Michael Chang <[email protected]>Signed-off-by Gary Lin <[email protected]>Reviewed-by Glenn Washburn <[email protected]>Reviewed-by Stefan Berger <[email protected]>--- Makefile.util.def | 1 + grub-core/disk/cryptodisk.c | 243 ++++++++++++++++++++++++++---------- include/grub/cryptodisk.h | 16 +++ 3 files changed, 196 insertions(+), 64 deletions(-)include/grub/cryptodisk.h +0
-0@@ -70,6 +70,18 @@ typedef gcry_err_code_t (*grub_cryptodisk_rekey_func_t) (struct grub_cryptodisk *dev, grub_uint64_t zoneno);
include/grub/cryptodisk.h typedef gcry_err_code_t · line 82
Quoted 10 lines
include/grub/cryptodisk.h +10
-0+struct grub_cryptomount_cached_key +{ +grub_uint8_t *key; +grub_size_t key_len; + +/* +* The key protector associated with this cache entry failed, so avoid it +* even if the cached entry (an instance of this structure) is empty. +*/ +int invalid;
Please use bool instead.
If you fix this feel free to add my RB to this patch.
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v18 18/25 util/grub-protect: Add new tool
In reply to Gary Lin via Grub-develFrom: Hernan Gatta <[email protected]>
To utilize the key protectors framework, there must be a way to protect full-disk encryption keys in the first place. The grub-protect tool includes support for the TPM2 key protector but other protectors that require setup ahead of time can be supported in the future.
For the TPM2 key protector, the intended flow is for a user to have a LUKS 1 or LUKS 2-protected fully-encrypted disk. The user then creates a new LUKS key file, say by reading /dev/urandom into a file, and creates a new LUKS key slot for this key. Then, the user invokes the grub-protect tool to seal this key file to a set of PCRs using the system's TPM 2.0. The resulting sealed key file is stored in an unencrypted partition such as the EFI System Partition (ESP) so that GRUB may read it. The user also has to ensure the cryptomount command is included in GRUB's boot script and that it carries the requisite key protector (-P) parameter.
Sample usage:
$ dd if=/dev/urandom of=luks-key bs=1 count=32 $ sudo cryptsetup luksAddKey /dev/sdb1 luks-key --pbkdf=pbkdf2 --hash=sha512
To seal the key with TPM 2.0 Key File (recommended):
$ sudo grub-protect --action=add \
--protector=tpm2 \
--tpm2-pcrs=0,2,4,7,9 \
--tpm2key \
--tpm2-keyfile=luks-key \
--tpm2-outfile=/boot/efi/boot/grub2/sealed.tpmOr, to seal the key with the raw sealed key:
$ sudo grub-protect --action=add \
--protector=tpm2 \
--tpm2-pcrs=0,2,4,7,9 \
--tpm2-keyfile=luks-key \
--tpm2-outfile=/boot/efi/boot/grub2/sealed.keyThen, in the boot script, for TPM 2.0 Key File:
tpm2_key_protector_init --tpm2key=(hd0,gpt1)/boot/grub2/sealed.tpm cryptomount -u <SDB1_UUID> -P tpm2
Or, for the raw sealed key:
tpm2_key_protector_init --keyfile=(hd0,gpt1)/boot/grub2/sealed.key --pcrs=0,2,4,7,9 cryptomount -u <SDB1_UUID> -P tpm2
The benefit of using TPM 2.0 Key File is that the PCR set is already written in the key file, so there is no need to specify PCRs when invoking tpm2_key_protector_init.
--- .gitignore | 2 + Makefile.util.def | 26 + configure.ac | 30 + docs/man/grub-protect.h2m | 4 + util/grub-protect.c | 1423 +++++++++++++++++++++++++++++++++++++ 5 files changed, 1485 insertions(+) create mode 100644 docs/man/grub-protect.h2m create mode 100644 util/grub-protect.c
.gitignore +2 -0
@@ -169,6 +169,8 @@ widthspec.bin /grub-ofpathname.exe /grub-probe /grub-probe.exe +/grub-protect +/grub-protect.exe /grub-reboot /grub-render-label /grub-render-label.exe
Makefile.util.def +26 -0
@@ -208,6 +208,32 @@ program = { ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; +program = { + name = grub-protect; + mansection = 1; + + common = grub-core/kern/emu/argp_common.c; + common = grub-core/osdep/init.c; + common = grub-core/lib/tss2/buffer.c; + common = grub-core/lib/tss2/tss2_mu.c; + common = grub-core/lib/tss2/tpm2_cmd.c; + common = grub-core/commands/tpm2_key_protector/args.c; + common = grub-core/commands/tpm2_key_protector/tpm2key_asn1_tab.c; + common = util/grub-protect.c; + common = util/probe.c; + + cflags = '-I$(srcdir)/grub-core/lib/tss2 -I$(srcdir)/grub-core/commands/tpm2_key_protector'; + + ldadd = libgrubmods.a; + ldadd = libgrubgcry.a; + ldadd = libgrubkern.a; + ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = '$(LIBTASN1)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; + + condition = COND_GRUB_PROTECT; +}; + program = { name = grub-mkrelpath; mansection = 1;
configure.ac +30 -0
@@ -76,6 +76,7 @@ grub_TRANSFORM([grub-mkpasswd-pbkdf2]) grub_TRANSFORM([grub-mkrelpath]) grub_TRANSFORM([grub-mkrescue]) grub_TRANSFORM([grub-probe]) +grub_TRANSFORM([grub-protect]) grub_TRANSFORM([grub-reboot]) grub_TRANSFORM([grub-script-check]) grub_TRANSFORM([grub-set-default])
@@ -2057,6 +2058,29 @@ fi AC_SUBST([LIBZFS]) AC_SUBST([LIBNVPAIR]) +AC_ARG_ENABLE([grub-protect], + [AS_HELP_STRING([--enable-grub-protect], + [build and install the `grub-protect' utility (default=guessed)])]) +if test x"$enable_grub_protect" = xno ; then + grub_protect_excuse="explicitly disabled" +fi + +LIBTASN1= +if test x"$grub_protect_excuse" = x ; then + AC_CHECK_LIB([tasn1], [asn1_write_value], [LIBTASN1="-ltasn1"], [grub_protect_excuse="need libtasn1 library"]) +fi +AC_SUBST([LIBTASN1]) + +if test x"$enable_grub_protect" = xyes && test x"$grub_protect_excuse" != x ; then + AC_MSG_ERROR([grub-protect was explicitly requested but can't be compiled ($grub_protect_excuse)]) +fi +if test x"$grub_protect_excuse" = x ; then +enable_grub_protect=yes +else +enable_grub_protect=no +fi +AC_SUBST([enable_grub_protect]) + LIBS="" AC_SUBST([FONT_SOURCE])
@@ -2173,6 +2197,7 @@ AM_CONDITIONAL([COND_GRUB_EMU_SDL], [test x$enable_grub_emu_sdl = xyes]) AM_CONDITIONAL([COND_GRUB_EMU_PCI], [test x$enable_grub_emu_pci = xyes]) AM_CONDITIONAL([COND_GRUB_MKFONT], [test x$enable_grub_mkfont = xyes]) AM_CONDITIONAL([COND_GRUB_MOUNT], [test x$enable_grub_mount = xyes]) +AM_CONDITIONAL([COND_GRUB_PROTECT], [test x$enable_grub_protect = xyes]) AM_CONDITIONAL([COND_HAVE_FONT_SOURCE], [test x$FONT_SOURCE != x]) if test x$FONT_SOURCE != x ; then HAVE_FONT_SOURCE=1
@@ -2300,6 +2325,11 @@ echo grub-mount: Yes else echo grub-mount: No "($grub_mount_excuse)" fi +if [ x"$grub_protect_excuse" = x ]; then +echo grub-protect: Yes +else +echo grub-protect: No "($grub_protect_excuse)" +fi if [ x"$starfield_excuse" = x ]; then echo starfield theme: Yes echo With DejaVuSans font from $DJVU_FONT_SOURCE
docs/man/grub-protect.h2m new file +4 -0
@@ -0,0 +1,4 @@ +[NAME] +grub-protect \- protect a disk key with a key protector +[DESCRIPTION] +grub-protect helps to pretect a disk encryption key with a specified key protector.
util/grub-protect.c new file +1423 -0
1,423 lines not on this page · raw message
Signature · 7 lines
2.35.3 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 18/25] util/grub-protect: Add new tool
Quoted 44 lines · Gary Lin via Grub-devel
From: Hernan Gatta <[email protected]>
To utilize the key protectors framework, there must be a way to protect full-disk encryption keys in the first place. The grub-protect tool includes support for the TPM2 key protector but other protectors that require setup ahead of time can be supported in the future.
For the TPM2 key protector, the intended flow is for a user to have a LUKS 1 or LUKS 2-protected fully-encrypted disk. The user then creates a new LUKS key file, say by reading
/dev/urandominto a file, and creates a new LUKS key slot for this key. Then, the user invokes the grub-protect tool to seal this key file to a set of PCRs using the system's TPM 2.0. The resulting sealed key file is stored in an unencrypted partition such as the EFI System Partition (ESP) so that GRUB may read it. The user also has to ensure the cryptomount command is included in GRUB's boot script and that it carries the requisite key protector (-P) parameter.Sample usage:
$ dd if=/dev/urandom of=luks-key bs=1 count=32 $ sudo cryptsetup luksAddKey /dev/sdb1 luks-key --pbkdf=pbkdf2 --hash=sha512To seal the key with TPM 2.0 Key File (recommended):
$ sudo grub-protect --action=add \ --protector=tpm2 \ --tpm2-pcrs=0,2,4,7,9 \ --tpm2key \ --tpm2-keyfile=luks-key \ --tpm2-outfile=/boot/efi/boot/grub2/sealed.tpmOr, to seal the key with the raw sealed key:
$ sudo grub-protect --action=add \ --protector=tpm2 \ --tpm2-pcrs=0,2,4,7,9 \ --tpm2-keyfile=luks-key \ --tpm2-outfile=/boot/efi/boot/grub2/sealed.keyThen, in the boot script, for TPM 2.0 Key File:
tpm2_key_protector_init--tpm2key=(hd0,gpt1)/boot/grub2/sealed.tpm cryptomount -u <SDB1_UUID> -P tpm2
Quoted 8 lines
Or, for the raw sealed key:
tpm2_key_protector_init--keyfile=(hd0,gpt1)/boot/grub2/sealed.key --pcrs=0,2,4,7,9 cryptomount -u <SDB1_UUID> -P tpm2The benefit of using TPM 2.0 Key File is that the PCR set is already written in the key file, so there is no need to specify PCRs when invoking
tpm2_key_protector_init.
I think most if not all of this commit message should go to the GRUB documentation too.
Quoted 131 lines
Cc Stefan Berger <[email protected]>Signed-off-by Hernan Gatta <[email protected]>Signed-off-by Gary Lin <[email protected]>--- .gitignore | 2 + Makefile.util.def | 26 + configure.ac | 30 + docs/man/grub-protect.h2m | 4 + util/grub-protect.c | 1423 +++++++++++++++++++++++++++++++++++++ 5 files changed, 1485 insertions(+) create mode 100644 docs/man/grub-protect.h2m create mode 100644 util/grub-protect.c.gitignore +2
-0@@ -169,6 +169,8 @@ widthspec.bin /grub-ofpathname.exe /grub-probe /grub-probe.exe +/grub-protect +/grub-protect.exe /grub-reboot /grub-render-label /grub-render-label.exeMakefile.util.def +26
-0@@ -208,6 +208,32 @@ program = { ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; +program = { + name = grub-protect; + mansection = 1; + + common = grub-core/kern/emu/argp_common.c; + common = grub-core/osdep/init.c; + common = grub-core/lib/tss2/buffer.c; + common = grub-core/lib/tss2/tss2_mu.c; + common = grub-core/lib/tss2/tpm2_cmd.c; + common = grub-core/commands/tpm2_key_protector/args.c; + common = grub-core/commands/tpm2_key_protector/tpm2key_asn1_tab.c; + common = util/grub-protect.c; + common = util/probe.c; + + cflags = '-I$(srcdir)/grub-core/lib/tss2 -I$(srcdir)/grub-core/commands/tpm2_key_protector'; + + ldadd = libgrubmods.a; + ldadd = libgrubgcry.a; + ldadd = libgrubkern.a; + ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = '$(LIBTASN1)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; + + condition = COND_GRUB_PROTECT; +}; + program = { name = grub-mkrelpath; mansection = 1;configure.ac +30
-0@@ -76,6 +76,7 @@ grub_TRANSFORM([grub-mkpasswd-pbkdf2]) grub_TRANSFORM([grub-mkrelpath]) grub_TRANSFORM([grub-mkrescue]) grub_TRANSFORM([grub-probe]) +grub_TRANSFORM([grub-protect]) grub_TRANSFORM([grub-reboot]) grub_TRANSFORM([grub-script-check]) grub_TRANSFORM([grub-set-default])@@ -2057,6 +2058,29 @@ fi AC_SUBST([LIBZFS]) AC_SUBST([LIBNVPAIR]) +AC_ARG_ENABLE([grub-protect], + [AS_HELP_STRING([--enable-grub-protect], + [build and install the `grub-protect' utility (default=guessed)])]) +if test x"$enable_grub_protect" = xno ; then + grub_protect_excuse="explicitly disabled" +fi + +LIBTASN1= +if test x"$grub_protect_excuse" = x ; then + AC_CHECK_LIB([tasn1], [asn1_write_value], [LIBTASN1="-ltasn1"], [grub_protect_excuse="need libtasn1 library"]) +fi +AC_SUBST([LIBTASN1]) + +if test x"$enable_grub_protect" = xyes && test x"$grub_protect_excuse" != x ; then + AC_MSG_ERROR([grub-protect was explicitly requested but can't be compiled ($grub_protect_excuse)]) +fi +if test x"$grub_protect_excuse" = x ; then +enable_grub_protect=yes +else +enable_grub_protect=no +fi +AC_SUBST([enable_grub_protect]) + LIBS="" AC_SUBST([FONT_SOURCE])@@ -2173,6 +2197,7 @@ AM_CONDITIONAL([COND_GRUB_EMU_SDL], [test x$enable_grub_emu_sdl = xyes]) AM_CONDITIONAL([COND_GRUB_EMU_PCI], [test x$enable_grub_emu_pci = xyes]) AM_CONDITIONAL([COND_GRUB_MKFONT], [test x$enable_grub_mkfont = xyes]) AM_CONDITIONAL([COND_GRUB_MOUNT], [test x$enable_grub_mount = xyes]) +AM_CONDITIONAL([COND_GRUB_PROTECT], [test x$enable_grub_protect = xyes]) AM_CONDITIONAL([COND_HAVE_FONT_SOURCE], [test x$FONT_SOURCE != x]) if test x$FONT_SOURCE != x ; then HAVE_FONT_SOURCE=1@@ -2300,6 +2325,11 @@ echo grub-mount: Yes else echo grub-mount: No "($grub_mount_excuse)" fi +if [ x"$grub_protect_excuse" = x ]; then +echo grub-protect: Yes +else +echo grub-protect: No "($grub_protect_excuse)" +fi if [ x"$starfield_excuse" = x ]; then echo starfield theme: Yes echo With DejaVuSans font from $DJVU_FONT_SOURCEdocs/man/grub-protect.h2m new file +0
-0
docs/man/grub-protect.h2m line 4
Quoted 4 lines
docs/man/grub-protect.h2m new file +4
-0@@ -0,0 +1,4 @@ +[NAME] +grub-protect \- protect a disk key with a key protector +[DESCRIPTION] +grub-protect helps to pretect a disk encryption key with a specified key protector.
Please expand this too...
Quoted 41 lines
util/grub-protect.c new file +35
-0@@ -0,0 +1,1423 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 Free Software Foundation, Inc. +* Copyright (C) 2023 SUSE LLC +* Copyright (C) 2022 Microsoft Corporation +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <config.h> + +#include <errno.h> +#include <fcntl.h> +#include <libtasn1.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> + +#include <grub/emu/hostdisk.h> +#include <grub/emu/misc.h> + +#include <grub/util/misc.h> + +#include <tss2_buffer.h>
util/grub-protect.c line 45
Quoted 10 lines
util/grub-protect.c new file +10
-0+#include <tss2_mu.h> +#include <tcg2.h> +#include <tpm2_args.h> +#include <tpm2.h> + +#pragma GCC diagnostic ignored "-Wmissing-prototypes" +#pragma GCC diagnostic ignored "-Wmissing-declarations" +#include <argp.h> +#pragma GCC diagnostic error "-Wmissing-prototypes" +#pragma GCC diagnostic error "-Wmissing-declarations"
I can see this in other utils sources but it would be nice to know it is still needed, and why, or not...
Quoted 102 lines
util/grub-protect.c new file +102
-0+#include "progname.h" + +/* Unprintable option keys for argp */ +typedef enum grub_protect_opt +{ +/* General */ +GRUB_PROTECT_OPT_ACTION ='a' , +GRUB_PROTECT_OPT_PROTECTOR ='p' , +/* TPM2 */ +GRUB_PROTECT_OPT_TPM2_DEVICE =0x100 , +GRUB_PROTECT_OPT_TPM2_PCRS , +GRUB_PROTECT_OPT_TPM2_ASYMMETRIC , +GRUB_PROTECT_OPT_TPM2_BANK , +GRUB_PROTECT_OPT_TPM2_SRK , +GRUB_PROTECT_OPT_TPM2_KEYFILE , +GRUB_PROTECT_OPT_TPM2_OUTFILE , +GRUB_PROTECT_OPT_TPM2_EVICT , +GRUB_PROTECT_OPT_TPM2_TPM2KEY +}grub_protect_opt ; + +/* Option flags to keep track of specified arguments */ +typedef enum grub_protect_arg +{ +/* General */ +GRUB_PROTECT_ARG_ACTION =1 <<0 , +GRUB_PROTECT_ARG_PROTECTOR =1 <<1 , +/* TPM2 */ +GRUB_PROTECT_ARG_TPM2_DEVICE =1 <<2 , +GRUB_PROTECT_ARG_TPM2_PCRS =1 <<3 , +GRUB_PROTECT_ARG_TPM2_ASYMMETRIC =1 <<4 , +GRUB_PROTECT_ARG_TPM2_BANK =1 <<5 , +GRUB_PROTECT_ARG_TPM2_SRK =1 <<6 , +GRUB_PROTECT_ARG_TPM2_KEYFILE =1 <<7 , +GRUB_PROTECT_ARG_TPM2_OUTFILE =1 <<8 , +GRUB_PROTECT_ARG_TPM2_EVICT =1 <<9 , +GRUB_PROTECT_ARG_TPM2_TPM2KEY =1 <<10 +}grub_protect_arg_t ; + +typedef enum grub_protect_protector +{ +GRUB_PROTECT_TYPE_ERROR , +GRUB_PROTECT_TYPE_TPM2 +}grub_protect_protector_t ; + +typedef enum grub_protect_action +{ +GRUB_PROTECT_ACTION_ERROR , +GRUB_PROTECT_ACTION_ADD , +GRUB_PROTECT_ACTION_REMOVE +}grub_protect_action_t ; + +struct grub_protect_args +{ +grub_protect_arg_t args; +grub_protect_action_t action; +grub_protect_protector_t protector; + +const char *tpm2_device; +grub_uint8_t tpm2_pcrs[TPM_MAX_PCRS ]; +grub_uint8_t tpm2_pcr_count; +grub_srk_type_t srk_type; +TPM_ALG_ID tpm2_bank; +TPM_HANDLE tpm2_srk; +const char *tpm2_keyfile; +const char *tpm2_outfile; +int tpm2_evict; +int tpm2_tpm2key; +}; + +static struct argp_option grub_protect_options[] = + { +/* Top-level options */ + { + .name ="action" , + .key ='a' , + .arg ="add|remove" , + .flags =0 , + .doc = +N_ ("Add or remove a key protector to or from a key." ), + .group =0 + }, + { + .name ="protector" , + .key ='p' , + .arg ="tpm2" , + .flags =0 , + .doc = +N_ ("Key protector to use (only tpm2 is currently supported)." ), + .group =0 + }, +/* TPM2 key protector options */ + { + .name ="tpm2-device" , + .key =GRUB_PROTECT_OPT_TPM2_DEVICE , + .arg ="FILE" , + .flags =0 , + .doc = +N_ ("Path to the TPM2 device. (default: /dev/tpm0)" ), + .group =0 + }, + { + .name ="tpm2-pcrs" ,
util/grub-protect.c line 158
Quoted 10 lines
util/grub-protect.c new file +10
-0+ .key = GRUB_PROTECT_OPT_TPM2_PCRS, + .arg = "0[,1]...", + .flags = 0, + .doc = +N_ ("Comma-separated list of PCRs used to authorize key release " +"e.g., '7,11'. Please be aware that PCR 0~7 are used by the " +"firmware and the measurement result may change after a " +"firmware update (for baremetal systems) or a package " +"(OVMF/SeaBIOS/SLOF) update in the VM host. This may lead to" + "the failure of key unsealing. (default: 7)"),
I would add this to the GRUB docs too.
Quoted 63 lines
util/grub-protect.c new file +63
-0+ .group = 0 + }, + { + .name = "tpm2-bank", + .key = GRUB_PROTECT_OPT_TPM2_BANK, + .arg = "ALG", + .flags = 0, + .doc = +N_ ("Bank of PCRs used to authorize key release: " + "SHA1, SHA256, SHA384, or SHA512. (default: SHA256)"), + .group =0 + }, + { + .name = "tpm2-keyfile", + .key = GRUB_PROTECT_OPT_TPM2_KEYFILE, + .arg = "FILE", + .flags = 0, + .doc = + N_("Path to a file that contains the cleartext key to protect."), + .group =0 + }, + { + .name = "tpm2-outfile", + .key = GRUB_PROTECT_OPT_TPM2_OUTFILE, + .arg = "FILE", + .flags = 0, + .doc = +N_ ("Path to the file that will contain the key after sealing (must be " + "accessible to GRUB during boot)."), + .group =0 + }, + { + .name = "tpm2-srk", + .key = GRUB_PROTECT_OPT_TPM2_SRK, + .arg = "NUM", + .flags = 0, + .doc = + N_("The SRK handle if the SRK is to be made persistent."), + .group =0 + }, + { + .name = "tpm2-asymmetric", + .key = GRUB_PROTECT_OPT_TPM2_ASYMMETRIC, + .arg = "TYPE", + .flags = 0, + .doc = +N_ ("The type of SRK: RSA (RSA2048) and ECC (ECC_NIST_P256)." + "(default: ECC)"), + .group =0 + }, + { + .name = "tpm2-evict", + .key = GRUB_PROTECT_OPT_TPM2_EVICT, + .arg = NULL, + .flags = 0, + .doc = + N_("Evict a previously persisted SRK from the TPM, if any."), + .group =0 + }, + { + .name = "tpm2key", + .key = GRUB_PROTECT_OPT_TPM2_TPM2KEY, + .arg = NULL,
util/grub-protect.c line 231
Quoted 10 lines
util/grub-protect.c new file +10
-0+ .flags = 0, + .doc = + N_("Use TPM 2.0 Key File format instead of the raw format."), + .group = 0 + }, +/* End of list */ + { 0, 0, 0, 0, 0, 0 } + }; + +static int grub_protector_tpm2_fd =-1 ;
I would prefer if it is not global...
Quoted 41 lines
util/grub-protect.c new file +41
-0+static grub_err_t +grub_protect_read_file (const char *filepath,void **buffer, +size_t *buffer_size) +{ +grub_err_t err; +FILE *f; +long len; +void *buf; + + f =fopen (filepath,"rb" ); +if (f ==NULL ) +return GRUB_ERR_FILE_NOT_FOUND ; + +if (fseek (f,0 ,SEEK_END )) + { + err =GRUB_ERR_FILE_READ_ERROR ; + goto exit1; + } + + len =ftell (f); +if (len <=0 ) + { + err =GRUB_ERR_FILE_READ_ERROR ; + goto exit1; + } + +rewind (f); + + buf =grub_malloc (len); +if (buf ==NULL ) + { + err =GRUB_ERR_OUT_OF_MEMORY ; + goto exit1; + } + +if (fread (buf, len,1 , f) !=1 ) + { + err =GRUB_ERR_FILE_READ_ERROR ; + goto exit2; + } +
util/grub-protect.c line 283
Quoted 10 lines
util/grub-protect.c new file +10
-0+ *buffer = buf; + *buffer_size = len; + + buf =NULL ; + err =GRUB_ERR_NONE ; + +exit2: +grub_free (buf); + +exit1:
Missing spaces before labels.
Quoted 14 lines
util/grub-protect.c new file +14
-0+fclose (f); + +return err; +} + +static grub_err_t +grub_protect_write_file (const char *filepath,void *buffer,size_t buffer_size) +{ +grub_err_t err; +FILE *f; + + f =fopen (filepath,"wb" ); +if (f ==NULL ) +return GRUB_ERR_FILE_NOT_FOUND ;
util/grub-protect.c line 307
Quoted 10 lines
util/grub-protect.c new file +10
-0+ +if (fwrite (buffer, buffer_size,1 , f) !=1 ) + { + err =GRUB_ERR_WRITE_ERROR ; + goto exit1; + } + + err =GRUB_ERR_NONE ; + +exit1:
Ditto and below please...
Quoted 4 lines
util/grub-protect.c new file +4
-0+fclose (f); + +return err; +}
[...]
Quoted 72 lines
util/grub-protect.c new file +72
-0+static grub_err_t +grub_protect_tpm2_get_policy_digest (struct grub_protect_args *args, +TPM2B_DIGEST *digest) +{ +TPM_RC rc; +TPML_PCR_SELECTION pcr_sel = { + .count =1 , + .pcrSelections = { + { + .hash = args->tpm2_bank, + .sizeOfSelect =3 , + .pcrSelect = {0 } + }, + } + }; +TPML_PCR_SELECTION pcr_sel_out = {0 }; +TPML_DIGEST pcr_values = {0 }; +TPM2B_DIGEST pcr_digest = {0 }; +grub_size_t pcr_digest_len; +TPM2B_MAX_BUFFER pcr_concat = {0 }; +grub_size_t pcr_concat_len; +grub_uint8_t *pcr_cursor; +TPM2B_NONCE nonce = {0 }; +TPM2B_ENCRYPTED_SECRET salt = {0 }; +TPMT_SYM_DEF symmetric = {0 }; +TPMI_SH_AUTH_SESSION session =0 ; +TPM2B_DIGEST policy_digest = {0 }; +grub_uint8_t i; +grub_err_t err; + +/* PCR Read */ +for (i =0 ; i < args->tpm2_pcr_count; i++) +TPMS_PCR_SELECTION_SelectPCR (&pcr_sel.pcrSelections[0 ], args->tpm2_pcrs[i]); + + rc =TPM2_PCR_Read (NULL , &pcr_sel,NULL , &pcr_sel_out, &pcr_values,NULL ); +if (rc !=TPM_RC_SUCCESS ) + { +fprintf (stderr,_ ("Failed to read PCRs (TPM2_PCR_Read: 0x%x).\n" ), rc); +return GRUB_ERR_BAD_DEVICE ; + } + +if ((pcr_sel_out.count != pcr_sel.count) || + (pcr_sel.pcrSelections[0 ].sizeOfSelect != + pcr_sel_out.pcrSelections[0 ].sizeOfSelect)) + { +fprintf (stderr,_ ("Could not read all the specified PCRs.\n" )); +return GRUB_ERR_BAD_DEVICE ; + } + +/* Compute PCR Digest */ +switch (args->tpm2_bank) + { +case TPM_ALG_SHA1 : + pcr_digest_len =TPM_SHA1_DIGEST_SIZE ; +break ; +case TPM_ALG_SHA256 : + pcr_digest_len =TPM_SHA256_DIGEST_SIZE ; +break ; +case TPM_ALG_SHA384 : + pcr_digest_len =TPM_SHA384_DIGEST_SIZE ; +break ; +case TPM_ALG_SHA512 : + pcr_digest_len =TPM_SHA512_DIGEST_SIZE ; +break ; +default : +return GRUB_ERR_BAD_ARGUMENT ; + } + + pcr_concat_len = pcr_digest_len * args->tpm2_pcr_count; +if (pcr_concat_len >TPM_MAX_DIGEST_BUFFER ) + { +fprintf (stderr,_ ("PCR concatenation buffer not enough.\n" ));
util/grub-protect.c line 456
Quoted 10 lines
util/grub-protect.c new file +10
-0+return GRUB_ERR_OUT_OF_RANGE ; + } + + pcr_cursor = pcr_concat.buffer; +for (i =0 ; i < args->tpm2_pcr_count; i++) + { +if (pcr_values.digests[i].size != pcr_digest_len) + { + fprintf (stderr, + _("Bad PCR value size: expected %" PRIuGRUB_SIZE " bytes but got %u bytes.\n"),
You cannot use PRIuGRUB_SIZE within _() macro.
util/grub-protect.c line 459
Quoted 3 lines
util/grub-protect.c new file +3
-0+ pcr_digest_len, pcr_values.digests[i].size); +return GRUB_ERR_BAD_ARGUMENT ; + }
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 18/25] util/grub-protect: Add new tool
Quoted 50 lines · Daniel Kiper
Quoted 49 lines · Gary Lin via Grub-devel
From: Hernan Gatta <[email protected]>
To utilize the key protectors framework, there must be a way to protect full-disk encryption keys in the first place. The grub-protect tool includes support for the TPM2 key protector but other protectors that require setup ahead of time can be supported in the future.
For the TPM2 key protector, the intended flow is for a user to have a LUKS 1 or LUKS 2-protected fully-encrypted disk. The user then creates a new LUKS key file, say by reading
/dev/urandominto a file, and creates a new LUKS key slot for this key. Then, the user invokes the grub-protect tool to seal this key file to a set of PCRs using the system's TPM 2.0. The resulting sealed key file is stored in an unencrypted partition such as the EFI System Partition (ESP) so that GRUB may read it. The user also has to ensure the cryptomount command is included in GRUB's boot script and that it carries the requisite key protector (-P) parameter.Sample usage:
$ dd if=/dev/urandom of=luks-key bs=1 count=32 $ sudo cryptsetup luksAddKey /dev/sdb1 luks-key --pbkdf=pbkdf2 --hash=sha512To seal the key with TPM 2.0 Key File (recommended):
$ sudo grub-protect --action=add \ --protector=tpm2 \ --tpm2-pcrs=0,2,4,7,9 \ --tpm2key \ --tpm2-keyfile=luks-key \ --tpm2-outfile=/boot/efi/boot/grub2/sealed.tpmOr, to seal the key with the raw sealed key:
$ sudo grub-protect --action=add \ --protector=tpm2 \ --tpm2-pcrs=0,2,4,7,9 \ --tpm2-keyfile=luks-key \ --tpm2-outfile=/boot/efi/boot/grub2/sealed.keyThen, in the boot script, for TPM 2.0 Key File:
tpm2_key_protector_init--tpm2key=(hd0,gpt1)/boot/grub2/sealed.tpm cryptomount -u <SDB1_UUID> -P tpm2Or, for the raw sealed key:
tpm2_key_protector_init--keyfile=(hd0,gpt1)/boot/grub2/sealed.key --pcrs=0,2,4,7,9 cryptomount -u <SDB1_UUID> -P tpm2
Quoted 7 lines
Quoted 3 lines
The benefit of using TPM 2.0 Key File is that the PCR set is already written in the key file, so there is no need to specify PCRs when invoking
tpm2_key_protector_init.I think most if not all of this commit message should go to the GRUB documentation too.
I'm working on an additional commit to address TPM2 key protector, grub-protect, and grub-emu in docs/grub.texi.
Quoted 129 lines
Quoted 129 lines
Cc Stefan Berger <[email protected]>Signed-off-by Hernan Gatta <[email protected]>Signed-off-by Gary Lin <[email protected]>--- .gitignore | 2 + Makefile.util.def | 26 + configure.ac | 30 + docs/man/grub-protect.h2m | 4 + util/grub-protect.c | 1423 +++++++++++++++++++++++++++++++++++++ 5 files changed, 1485 insertions(+) create mode 100644 docs/man/grub-protect.h2m create mode 100644 util/grub-protect.c.gitignore +2
-0@@ -169,6 +169,8 @@ widthspec.bin /grub-ofpathname.exe /grub-probe /grub-probe.exe +/grub-protect +/grub-protect.exe /grub-reboot /grub-render-label /grub-render-label.exeMakefile.util.def +26
-0@@ -208,6 +208,32 @@ program = { ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; }; +program = { + name = grub-protect; + mansection = 1; + + common = grub-core/kern/emu/argp_common.c; + common = grub-core/osdep/init.c; + common = grub-core/lib/tss2/buffer.c; + common = grub-core/lib/tss2/tss2_mu.c; + common = grub-core/lib/tss2/tpm2_cmd.c; + common = grub-core/commands/tpm2_key_protector/args.c; + common = grub-core/commands/tpm2_key_protector/tpm2key_asn1_tab.c; + common = util/grub-protect.c; + common = util/probe.c; + + cflags = '-I$(srcdir)/grub-core/lib/tss2 -I$(srcdir)/grub-core/commands/tpm2_key_protector'; + + ldadd = libgrubmods.a; + ldadd = libgrubgcry.a; + ldadd = libgrubkern.a; + ldadd = grub-core/lib/gnulib/libgnu.a; + ldadd = '$(LIBTASN1)'; + ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; + + condition = COND_GRUB_PROTECT; +}; + program = { name = grub-mkrelpath; mansection = 1;configure.ac +30
-0@@ -76,6 +76,7 @@ grub_TRANSFORM([grub-mkpasswd-pbkdf2]) grub_TRANSFORM([grub-mkrelpath]) grub_TRANSFORM([grub-mkrescue]) grub_TRANSFORM([grub-probe]) +grub_TRANSFORM([grub-protect]) grub_TRANSFORM([grub-reboot]) grub_TRANSFORM([grub-script-check]) grub_TRANSFORM([grub-set-default])@@ -2057,6 +2058,29 @@ fi AC_SUBST([LIBZFS]) AC_SUBST([LIBNVPAIR]) +AC_ARG_ENABLE([grub-protect], + [AS_HELP_STRING([--enable-grub-protect], + [build and install the `grub-protect' utility (default=guessed)])]) +if test x"$enable_grub_protect" = xno ; then + grub_protect_excuse="explicitly disabled" +fi + +LIBTASN1= +if test x"$grub_protect_excuse" = x ; then + AC_CHECK_LIB([tasn1], [asn1_write_value], [LIBTASN1="-ltasn1"], [grub_protect_excuse="need libtasn1 library"]) +fi +AC_SUBST([LIBTASN1]) + +if test x"$enable_grub_protect" = xyes && test x"$grub_protect_excuse" != x ; then + AC_MSG_ERROR([grub-protect was explicitly requested but can't be compiled ($grub_protect_excuse)]) +fi +if test x"$grub_protect_excuse" = x ; then +enable_grub_protect=yes +else +enable_grub_protect=no +fi +AC_SUBST([enable_grub_protect]) + LIBS="" AC_SUBST([FONT_SOURCE])@@ -2173,6 +2197,7 @@ AM_CONDITIONAL([COND_GRUB_EMU_SDL], [test x$enable_grub_emu_sdl = xyes]) AM_CONDITIONAL([COND_GRUB_EMU_PCI], [test x$enable_grub_emu_pci = xyes]) AM_CONDITIONAL([COND_GRUB_MKFONT], [test x$enable_grub_mkfont = xyes]) AM_CONDITIONAL([COND_GRUB_MOUNT], [test x$enable_grub_mount = xyes]) +AM_CONDITIONAL([COND_GRUB_PROTECT], [test x$enable_grub_protect = xyes]) AM_CONDITIONAL([COND_HAVE_FONT_SOURCE], [test x$FONT_SOURCE != x]) if test x$FONT_SOURCE != x ; then HAVE_FONT_SOURCE=1@@ -2300,6 +2325,11 @@ echo grub-mount: Yes else echo grub-mount: No "($grub_mount_excuse)" fi +if [ x"$grub_protect_excuse" = x ]; then +echo grub-protect: Yes +else +echo grub-protect: No "($grub_protect_excuse)" +fi if [ x"$starfield_excuse" = x ]; then echo starfield theme: Yes echo With DejaVuSans font from $DJVU_FONT_SOURCEdocs/man/grub-protect.h2m new file +0
-1--- /dev/null
Quoted 9 lines
docs/man/grub-protect.h2m line 4
Quoted 6 lines
+++ b/docs/man/grub-protect.h2m
docs/man/grub-protect.h2m new file +4
-0@@ -0,0 +1,4 @@ +[NAME] +grub-protect \- protect a disk key with a key protector +[DESCRIPTION] +grub-protect helps to pretect a disk encryption key with a specified key protector.Please expand this too...
Ok, I'll expand the decription and add some samples.
Quoted 161 lines
Quoted 41 lines
util/grub-protect.c new file +35
-0@@ -0,0 +1,1423 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2024 Free Software Foundation, Inc. +* Copyright (C) 2023 SUSE LLC +* Copyright (C) 2022 Microsoft Corporation +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <config.h> + +#include <errno.h> +#include <fcntl.h> +#include <libtasn1.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> + +#include <grub/emu/hostdisk.h> +#include <grub/emu/misc.h> + +#include <grub/util/misc.h> + +#include <tss2_buffer.h> util/grub-protect.c line 45
Quoted 10 lines
util/grub-protect.c new file +10
-0+#include <tss2_mu.h> +#include <tcg2.h> +#include <tpm2_args.h> +#include <tpm2.h> + +#pragma GCC diagnostic ignored "-Wmissing-prototypes" +#pragma GCC diagnostic ignored "-Wmissing-declarations" +#include <argp.h> +#pragma GCC diagnostic error "-Wmissing-prototypes" +#pragma GCC diagnostic error "-Wmissing-declarations"I can see this in other utils sources but it would be nice to know it is still needed, and why, or not...
Quoted 106 lines
util/grub-protect.c new file +106
-0+#include "progname.h" + +/* Unprintable option keys for argp */ +typedef enum grub_protect_opt +{ +/* General */ +GRUB_PROTECT_OPT_ACTION ='a' , +GRUB_PROTECT_OPT_PROTECTOR ='p' , +/* TPM2 */ +GRUB_PROTECT_OPT_TPM2_DEVICE =0x100 , +GRUB_PROTECT_OPT_TPM2_PCRS , +GRUB_PROTECT_OPT_TPM2_ASYMMETRIC , +GRUB_PROTECT_OPT_TPM2_BANK , +GRUB_PROTECT_OPT_TPM2_SRK , +GRUB_PROTECT_OPT_TPM2_KEYFILE , +GRUB_PROTECT_OPT_TPM2_OUTFILE , +GRUB_PROTECT_OPT_TPM2_EVICT , +GRUB_PROTECT_OPT_TPM2_TPM2KEY +}grub_protect_opt ; + +/* Option flags to keep track of specified arguments */ +typedef enum grub_protect_arg +{ +/* General */ +GRUB_PROTECT_ARG_ACTION =1 <<0 , +GRUB_PROTECT_ARG_PROTECTOR =1 <<1 , +/* TPM2 */ +GRUB_PROTECT_ARG_TPM2_DEVICE =1 <<2 , +GRUB_PROTECT_ARG_TPM2_PCRS =1 <<3 , +GRUB_PROTECT_ARG_TPM2_ASYMMETRIC =1 <<4 , +GRUB_PROTECT_ARG_TPM2_BANK =1 <<5 , +GRUB_PROTECT_ARG_TPM2_SRK =1 <<6 , +GRUB_PROTECT_ARG_TPM2_KEYFILE =1 <<7 , +GRUB_PROTECT_ARG_TPM2_OUTFILE =1 <<8 , +GRUB_PROTECT_ARG_TPM2_EVICT =1 <<9 , +GRUB_PROTECT_ARG_TPM2_TPM2KEY =1 <<10 +}grub_protect_arg_t ; + +typedef enum grub_protect_protector +{ +GRUB_PROTECT_TYPE_ERROR , +GRUB_PROTECT_TYPE_TPM2 +}grub_protect_protector_t ; + +typedef enum grub_protect_action +{ +GRUB_PROTECT_ACTION_ERROR , +GRUB_PROTECT_ACTION_ADD , +GRUB_PROTECT_ACTION_REMOVE +}grub_protect_action_t ; + +struct grub_protect_args +{ +grub_protect_arg_t args; +grub_protect_action_t action; +grub_protect_protector_t protector; + +const char *tpm2_device; +grub_uint8_t tpm2_pcrs[TPM_MAX_PCRS ]; +grub_uint8_t tpm2_pcr_count; +grub_srk_type_t srk_type; +TPM_ALG_ID tpm2_bank; +TPM_HANDLE tpm2_srk; +const char *tpm2_keyfile; +const char *tpm2_outfile; +int tpm2_evict; +int tpm2_tpm2key; +}; + +static struct argp_option grub_protect_options[] = + { +/* Top-level options */ + { + .name ="action" , + .key ='a' , + .arg ="add|remove" , + .flags =0 , + .doc = +N_ ("Add or remove a key protector to or from a key." ), + .group =0 + }, + { + .name ="protector" , + .key ='p' , + .arg ="tpm2" , + .flags =0 , + .doc = +N_ ("Key protector to use (only tpm2 is currently supported)." ), + .group =0 + }, +/* TPM2 key protector options */ + { + .name ="tpm2-device" , + .key =GRUB_PROTECT_OPT_TPM2_DEVICE , + .arg ="FILE" , + .flags =0 , + .doc = +N_ ("Path to the TPM2 device. (default: /dev/tpm0)" ), + .group =0 + }, + { + .name ="tpm2-pcrs" , + .key =GRUB_PROTECT_OPT_TPM2_PCRS , + .arg ="0[,1]..." , + .flags =0 , + .doc =
Quoted 9 lines
util/grub-protect.c line 158
Quoted 6 lines
util/grub-protect.c new file +6
-0+N_ ("Comma-separated list of PCRs used to authorize key release " +"e.g., '7,11'. Please be aware that PCR 0~7 are used by the " +"firmware and the measurement result may change after a " +"firmware update (for baremetal systems) or a package " +"(OVMF/SeaBIOS/SLOF) update in the VM host. This may lead to" + "the failure of key unsealing. (default: 7)"),I would add this to the GRUB docs too.
Sure. I'll address the PCR usage in grub.texi.
Quoted 67 lines
Quoted 67 lines
util/grub-protect.c new file +67
-0+ .group = 0 + }, + { + .name = "tpm2-bank", + .key = GRUB_PROTECT_OPT_TPM2_BANK, + .arg = "ALG", + .flags = 0, + .doc = +N_ ("Bank of PCRs used to authorize key release: " + "SHA1, SHA256, SHA384, or SHA512. (default: SHA256)"), + .group =0 + }, + { + .name = "tpm2-keyfile", + .key = GRUB_PROTECT_OPT_TPM2_KEYFILE, + .arg = "FILE", + .flags = 0, + .doc = + N_("Path to a file that contains the cleartext key to protect."), + .group =0 + }, + { + .name = "tpm2-outfile", + .key = GRUB_PROTECT_OPT_TPM2_OUTFILE, + .arg = "FILE", + .flags = 0, + .doc = +N_ ("Path to the file that will contain the key after sealing (must be " + "accessible to GRUB during boot)."), + .group =0 + }, + { + .name = "tpm2-srk", + .key = GRUB_PROTECT_OPT_TPM2_SRK, + .arg = "NUM", + .flags = 0, + .doc = + N_("The SRK handle if the SRK is to be made persistent."), + .group =0 + }, + { + .name = "tpm2-asymmetric", + .key = GRUB_PROTECT_OPT_TPM2_ASYMMETRIC, + .arg = "TYPE", + .flags = 0, + .doc = +N_ ("The type of SRK: RSA (RSA2048) and ECC (ECC_NIST_P256)." + "(default: ECC)"), + .group =0 + }, + { + .name = "tpm2-evict", + .key = GRUB_PROTECT_OPT_TPM2_EVICT, + .arg = NULL, + .flags = 0, + .doc = + N_("Evict a previously persisted SRK from the TPM, if any."), + .group =0 + }, + { + .name = "tpm2key", + .key = GRUB_PROTECT_OPT_TPM2_TPM2KEY, + .arg = NULL, + .flags = 0, + .doc = +N_ ("Use TPM 2.0 Key File format instead of the raw format." ), + .group = 0
Quoted 9 lines
util/grub-protect.c line 231
Quoted 6 lines
util/grub-protect.c new file +6
-0+ }, +/* End of list */ + { 0, 0, 0, 0, 0, 0 } + }; + +static int grub_protector_tpm2_fd =-1 ;I would prefer if it is not global...
It's a bit tricky. 'grub_protector_tpm2_fd' is mainly for the command submission function, grub_tcg2_submit_command(), which only expects the TPM2 command input and output, so the variable is made global to avoid adding additional parameters to grub_tcg2_submit_command().
Quoted 45 lines
Quoted 45 lines
util/grub-protect.c new file +45
-0+static grub_err_t +grub_protect_read_file (const char *filepath,void **buffer, +size_t *buffer_size) +{ +grub_err_t err; +FILE *f; +long len; +void *buf; + + f =fopen (filepath,"rb" ); +if (f ==NULL ) +return GRUB_ERR_FILE_NOT_FOUND ; + +if (fseek (f,0 ,SEEK_END )) + { + err =GRUB_ERR_FILE_READ_ERROR ; + goto exit1; + } + + len =ftell (f); +if (len <=0 ) + { + err =GRUB_ERR_FILE_READ_ERROR ; + goto exit1; + } + +rewind (f); + + buf =grub_malloc (len); +if (buf ==NULL ) + { + err =GRUB_ERR_OUT_OF_MEMORY ; + goto exit1; + } + +if (fread (buf, len,1 , f) !=1 ) + { + err =GRUB_ERR_FILE_READ_ERROR ; + goto exit2; + } + + *buffer = buf; + *buffer_size = len; + + buf =NULL ;
Quoted 9 lines
util/grub-protect.c line 283
Quoted 6 lines
util/grub-protect.c new file +6
-0+ err =GRUB_ERR_NONE ; + +exit2: +grub_free (buf); + +exit1:Missing spaces before labels.
Will fix them in the next version.
Quoted 110 lines
Quoted 14 lines
util/grub-protect.c new file +14
-0+fclose (f); + +return err; +} + +static grub_err_t +grub_protect_write_file (const char *filepath,void *buffer,size_t buffer_size) +{ +grub_err_t err; +FILE *f; + + f =fopen (filepath,"wb" ); +if (f ==NULL ) +return GRUB_ERR_FILE_NOT_FOUND ;util/grub-protect.c line 307
Quoted 10 lines
util/grub-protect.c new file +10
-0+ +if (fwrite (buffer, buffer_size,1 , f) !=1 ) + { + err =GRUB_ERR_WRITE_ERROR ; + goto exit1; + } + + err =GRUB_ERR_NONE ; + +exit1:Ditto and below please...
Quoted 4 lines
util/grub-protect.c new file +4
-0+fclose (f); + +return err; +}[...]
Quoted 76 lines
util/grub-protect.c new file +76
-0+static grub_err_t +grub_protect_tpm2_get_policy_digest (struct grub_protect_args *args, +TPM2B_DIGEST *digest) +{ +TPM_RC rc; +TPML_PCR_SELECTION pcr_sel = { + .count =1 , + .pcrSelections = { + { + .hash = args->tpm2_bank, + .sizeOfSelect =3 , + .pcrSelect = {0 } + }, + } + }; +TPML_PCR_SELECTION pcr_sel_out = {0 }; +TPML_DIGEST pcr_values = {0 }; +TPM2B_DIGEST pcr_digest = {0 }; +grub_size_t pcr_digest_len; +TPM2B_MAX_BUFFER pcr_concat = {0 }; +grub_size_t pcr_concat_len; +grub_uint8_t *pcr_cursor; +TPM2B_NONCE nonce = {0 }; +TPM2B_ENCRYPTED_SECRET salt = {0 }; +TPMT_SYM_DEF symmetric = {0 }; +TPMI_SH_AUTH_SESSION session =0 ; +TPM2B_DIGEST policy_digest = {0 }; +grub_uint8_t i; +grub_err_t err; + +/* PCR Read */ +for (i =0 ; i < args->tpm2_pcr_count; i++) +TPMS_PCR_SELECTION_SelectPCR (&pcr_sel.pcrSelections[0 ], args->tpm2_pcrs[i]); + + rc =TPM2_PCR_Read (NULL , &pcr_sel,NULL , &pcr_sel_out, &pcr_values,NULL ); +if (rc !=TPM_RC_SUCCESS ) + { +fprintf (stderr,_ ("Failed to read PCRs (TPM2_PCR_Read: 0x%x).\n" ), rc); +return GRUB_ERR_BAD_DEVICE ; + } + +if ((pcr_sel_out.count != pcr_sel.count) || + (pcr_sel.pcrSelections[0 ].sizeOfSelect != + pcr_sel_out.pcrSelections[0 ].sizeOfSelect)) + { +fprintf (stderr,_ ("Could not read all the specified PCRs.\n" )); +return GRUB_ERR_BAD_DEVICE ; + } + +/* Compute PCR Digest */ +switch (args->tpm2_bank) + { +case TPM_ALG_SHA1 : + pcr_digest_len =TPM_SHA1_DIGEST_SIZE ; +break ; +case TPM_ALG_SHA256 : + pcr_digest_len =TPM_SHA256_DIGEST_SIZE ; +break ; +case TPM_ALG_SHA384 : + pcr_digest_len =TPM_SHA384_DIGEST_SIZE ; +break ; +case TPM_ALG_SHA512 : + pcr_digest_len =TPM_SHA512_DIGEST_SIZE ; +break ; +default : +return GRUB_ERR_BAD_ARGUMENT ; + } + + pcr_concat_len = pcr_digest_len * args->tpm2_pcr_count; +if (pcr_concat_len >TPM_MAX_DIGEST_BUFFER ) + { +fprintf (stderr,_ ("PCR concatenation buffer not enough.\n" )); +return GRUB_ERR_OUT_OF_RANGE ; + } + + pcr_cursor = pcr_concat.buffer;
Quoted 9 lines
util/grub-protect.c line 456
Quoted 6 lines
util/grub-protect.c new file +6
-0+for (i =0 ; i < args->tpm2_pcr_count; i++) + { +if (pcr_values.digests[i].size != pcr_digest_len) + { + fprintf (stderr, + _("Bad PCR value size: expected %" PRIuGRUB_SIZE " bytes but got %u bytes.\n"),You cannot use
PRIuGRUB_SIZEwithin_()macro.
Will fix it in the next version.
Gary Lin
Quoted 5 lines
util/grub-protect.c line 459
Quoted 3 lines
util/grub-protect.c new file +3
-0+ pcr_digest_len, pcr_values.digests[i].size); +return GRUB_ERR_BAD_ARGUMENT ; + }Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v18 19/25 tpm2_key_protector: Support authorized policy
In reply to Gary Lin via Grub-develThis commit handles the TPM2_PolicyAuthorize command from the key file in TPM 2.0 Key File format.
TPM2_PolicyAuthorize is the essential command to support authorized policy which allows the users to sign TPM policies with their own keys. Per TPM 2.0 Key File(*1), CommandPolicy for TPM2_PolicyAuthorize comprises 'TPM2B_PUBLIC pubkey', 'TPM2B_DIGEST policy_ref', and 'TPMT_SIGNATURE signature'. To verify the signature, the current policy digest is hashed with the hash algorithm written in 'signature', and then 'signature' is verified with the hashed policy digest and 'pubkey'. Once TPM accepts 'signature', TPM2_PolicyAuthorize is invoked to authorize the signed policy.
To create the key file with authorized policy, here are the pcr-oracle(*2) commands:
# Generate the RSA key and create the authorized policy file
$ pcr-oracle \ --rsa-generate-key \ --private-key policy-key.pem \ --auth authorized.policy \ create-authorized-policy 0,2,4,7,9
# Seal the secret with the authorized policy
$ pcr-oracle \ --key-format tpm2.0 \ --auth authorized.policy \ --input disk-secret.txt \ --output sealed.key \ seal-secret
# Sign the predicted PCR policy
$ pcr-oracle \ --key-format tpm2.0 \ --private-key policy-key.pem \ --from eventlog \ --stop-event "grub-file=grub.cfg" \ --after \ --input sealed.key \ --output sealed.tpm \ sign 0,2,4,7,9
Then specify the key file and the key protector to grub.cfg in the EFI system partition:
tpm2_key_protector_init -a RSA --tpm2key=(hd0,gpt1)/boot/grub2/sealed.tpm cryptomount -u <PART_UUID> -P tpm2
For any change in the boot components, just run the 'sign' command again to update the signature in sealed.tpm, and TPM can unseal the key file with the updated PCR policy.
(*1) https://www.hansenpartnership.com/draft-bottomley-tpm2-keys.html
(*2) https://github.com/okirch/pcr-oracle
--- .../commands/tpm2_key_protector/module.c | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+)
grub-core/commands/tpm2_key_protector/module.c +72 -0
@@ -618,6 +618,75 @@ 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_Tss2_MU_TPM2B_PUBLIC_Unmarshal (cmd_buf, &pubkey); +grub_Tss2_MU_TPM2B_DIGEST_Unmarshal (cmd_buf, &policy_ref); +grub_Tss2_MU_TPMT_SIGNATURE_Unmarshal (cmd_buf, &signature); +if (cmd_buf->error !=0 ) +return grub_error (GRUB_ERR_BAD_ARGUMENT ,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 ) +return grub_error (GRUB_ERR_BAD_DEVICE ,N_ ("Failed to get policy digest (TPM2_PolicyGetDigest: 0x%x)." ), rc); + +/* Calculate the digest of the polcy for VerifySignature */ + sig_hash =TPMT_SIGNATURE_get_hash_alg (&signature); +if (sig_hash ==TPM_ALG_NULL ) +return grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("Failed to get the hash algorithm of the signature" )); + + rc =TPM2_Hash (NULL , (TPM2B_MAX_BUFFER *)&pcr_policy, sig_hash, +TPM_RH_NULL , &pcr_policy_hash,NULL ,NULL ); +if (rc !=TPM_RC_SUCCESS ) +return grub_error (GRUB_ERR_BAD_DEVICE ,N_ ("Failed to create PCR policy hash (TPM2_Hash: 0x%x)" ), rc); + +/* Load the public key */ + rc =TPM2_LoadExternal (NULL ,NULL , &pubkey,TPM_RH_OWNER , + &pubkey_handle, &pubname,NULL ); +if (rc !=TPM_RC_SUCCESS ) +return grub_error (GRUB_ERR_BAD_DEVICE ,N_ ("Failed to load public key (TPM2_LoadExternal: 0x%x)" ), rc); + +/* 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_error (GRUB_ERR_BAD_DEVICE ,N_ ("Failed to verify signature (TPM2_VerifySignature: 0x%x)" ), 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_error (GRUB_ERR_BAD_DEVICE ,N_ ("Failed to authorize PCR policy (TPM2_PolicyAuthorize: 0x%x)" ), 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) {
@@ -636,6 +705,9 @@ grub_tpm2_protector_enforce_policy (tpm2key_policy_t policy, TPMI_SH_AUTH_SESSIOcase 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); }
Signature · 7 lines
2.35.3 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 19/25] tpm2_key_protector: Support authorized policy
Quoted 45 lines · Gary Lin via Grub-devel
This commit handles the
TPM2_PolicyAuthorizecommand from the key file in TPM 2.0 Key File format.
TPM2_PolicyAuthorizeis the essential command to support authorized policy which allows the users to sign TPM policies with their own keys. Per TPM 2.0 KeyFile(*1), CommandPolicy forTPM2_PolicyAuthorizecomprises 'TPM2B_PUBLICpubkey', 'TPM2B_DIGESTpolicy_ref', and 'TPMT_SIGNATUREsignature'. To verify the signature, the current policy digest is hashed with the hash algorithm written in 'signature', and then 'signature' is verified with the hashed policy digest and 'pubkey'. Once TPM accepts 'signature',TPM2_PolicyAuthorizeis invoked to authorize the signed policy.To create the key file with authorized policy, here are the pcr-oracle(*2) commands:
# Generate the RSA key and create the authorized policy file
$ pcr-oracle \ --rsa-generate-key \ --private-key policy-key.pem \ --auth authorized.policy \ create-authorized-policy 0,2,4,7,9# Seal the secret with the authorized policy
$ pcr-oracle \ --key-format tpm2.0 \ --auth authorized.policy \ --input disk-secret.txt \ --output sealed.key \ seal-secret# Sign the predicted PCR policy
$ pcr-oracle \ --key-format tpm2.0 \ --private-key policy-key.pem \ --from eventlog \ --stop-event "grub-file=grub.cfg" \ --after \ --input sealed.key \ --output sealed.tpm \ sign 0,2,4,7,9Then specify the key file and the key protector to grub.cfg in the EFI system partition:
Quoted 6 lines
tpm2_key_protector_init-a RSA --tpm2key=(hd0,gpt1)/boot/grub2/sealed.tpm cryptomount -u <PART_UUID> -P tpm2For any change in the boot components, just run the 'sign' command again to update the signature in sealed.tpm, and TPM can unseal the key file with the updated PCR policy.
Again, this should land in the GRUB docs as well...
Quoted 40 lines
(*1) https://www.hansenpartnership.com/draft-bottomley-tpm2-keys.html
(*2) https://github.com/okirch/pcr-oracleSigned-off-by Gary Lin <[email protected]>Reviewed-by Stefan Berger <[email protected]>--- .../commands/tpm2_key_protector/module.c | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+)grub-core/commands/tpm2_key_protector/module.c +23
-0@@ -618,6 +618,75 @@ 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_Tss2_MU_TPM2B_PUBLIC_Unmarshal (cmd_buf, &pubkey); +grub_Tss2_MU_TPM2B_DIGEST_Unmarshal (cmd_buf, &policy_ref); +grub_Tss2_MU_TPMT_SIGNATURE_Unmarshal (cmd_buf, &signature); +if (cmd_buf->error !=0 ) +return grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("Failed to unmarshal the buffer for TPM2_PolicyAuthorize" )); + +/* Retrieve Policy Digest */
grub-core/commands/tpm2_key_protector/module.c grub_tpm2_protector_policypcr (TPMI_SH_AUTH_SESSION session, · line 653
Quoted 10 lines
grub-core/commands/tpm2_key_protector/module.c +10
-0+ rc =TPM2_PolicyGetDigest (session,NULL , &pcr_policy,NULL ); +if (rc !=TPM_RC_SUCCESS ) +return grub_error (GRUB_ERR_BAD_DEVICE ,N_ ("Failed to get policy digest (TPM2_PolicyGetDigest: 0x%x)." ), rc); + +/* Calculate the digest of the polcy for VerifySignature */ + sig_hash =TPMT_SIGNATURE_get_hash_alg (&signature); +if (sig_hash ==TPM_ALG_NULL ) +return grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("Failed to get the hash algorithm of the signature" )); + + rc = TPM2_Hash (NULL, (TPM2B_MAX_BUFFER *)&pcr_policy, sig_hash,
A nit, wrong cast coding style...
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 19/25] tpm2_key_protector: Support authorized policy
Quoted 46 lines · Daniel Kiper
Quoted 45 lines · Gary Lin via Grub-devel
This commit handles the
TPM2_PolicyAuthorizecommand from the key file in TPM 2.0 Key File format.
TPM2_PolicyAuthorizeis the essential command to support authorized policy which allows the users to sign TPM policies with their own keys. Per TPM 2.0 KeyFile(*1), CommandPolicy forTPM2_PolicyAuthorizecomprises 'TPM2B_PUBLICpubkey', 'TPM2B_DIGESTpolicy_ref', and 'TPMT_SIGNATUREsignature'. To verify the signature, the current policy digest is hashed with the hash algorithm written in 'signature', and then 'signature' is verified with the hashed policy digest and 'pubkey'. Once TPM accepts 'signature',TPM2_PolicyAuthorizeis invoked to authorize the signed policy.To create the key file with authorized policy, here are the pcr-oracle(*2) commands:
# Generate the RSA key and create the authorized policy file
$ pcr-oracle \ --rsa-generate-key \ --private-key policy-key.pem \ --auth authorized.policy \ create-authorized-policy 0,2,4,7,9# Seal the secret with the authorized policy
$ pcr-oracle \ --key-format tpm2.0 \ --auth authorized.policy \ --input disk-secret.txt \ --output sealed.key \ seal-secret# Sign the predicted PCR policy
$ pcr-oracle \ --key-format tpm2.0 \ --private-key policy-key.pem \ --from eventlog \ --stop-event "grub-file=grub.cfg" \ --after \ --input sealed.key \ --output sealed.tpm \ sign 0,2,4,7,9Then specify the key file and the key protector to grub.cfg in the EFI system partition:
Quoted 9 lines
Quoted 6 lines
tpm2_key_protector_init-a RSA --tpm2key=(hd0,gpt1)/boot/grub2/sealed.tpm cryptomount -u <PART_UUID> -P tpm2For any change in the boot components, just run the 'sign' command again to update the signature in sealed.tpm, and TPM can unseal the key file with the updated PCR policy.
Again, this should land in the GRUB docs as well...
Sure, the document will be in the next version.
Quoted 44 lines
Quoted 44 lines
(*1) https://www.hansenpartnership.com/draft-bottomley-tpm2-keys.html
(*2) https://github.com/okirch/pcr-oracleSigned-off-by Gary Lin <[email protected]>Reviewed-by Stefan Berger <[email protected]>--- .../commands/tpm2_key_protector/module.c | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+)grub-core/commands/tpm2_key_protector/module.c +27
-0@@ -618,6 +618,75 @@ 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_Tss2_MU_TPM2B_PUBLIC_Unmarshal (cmd_buf, &pubkey); +grub_Tss2_MU_TPM2B_DIGEST_Unmarshal (cmd_buf, &policy_ref); +grub_Tss2_MU_TPMT_SIGNATURE_Unmarshal (cmd_buf, &signature); +if (cmd_buf->error !=0 ) +return grub_error (GRUB_ERR_BAD_ARGUMENT ,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 ) +return grub_error (GRUB_ERR_BAD_DEVICE ,N_ ("Failed to get policy digest (TPM2_PolicyGetDigest: 0x%x)." ), rc); +
Quoted 9 lines
grub-core/commands/tpm2_key_protector/module.c grub_tpm2_protector_policypcr (TPMI_SH_AUTH_SESSION session, · line 653
Quoted 6 lines
grub-core/commands/tpm2_key_protector/module.c +6
-0+/* Calculate the digest of the polcy for VerifySignature */ + sig_hash =TPMT_SIGNATURE_get_hash_alg (&signature); +if (sig_hash ==TPM_ALG_NULL ) +return grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("Failed to get the hash algorithm of the signature" )); + + rc = TPM2_Hash (NULL, (TPM2B_MAX_BUFFER *)&pcr_policy, sig_hash,A nit, wrong cast coding style...
Will fix it in the next version.
Gary Lin
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v18 20/25 tpm2_key_protector: Implement NV index
In reply to Gary Lin via Grub-develFrom: Patrick Colp <[email protected]>
Currently with the TPM2 protector, only SRK mode is supported and NV index support is just a stub. Implement the NV index option.
Note: This only extends support on the unseal path. grub2_protect has not been updated. tpm2-tools can be used to insert a key into the NV index.
An example of inserting a key using tpm2-tools:
# Get random key.
tpm2_getrandom 32 > key.dat
# Create primary object.
tpm2_createprimary -C o -g sha256 -G ecc -c primary.ctx
# Create policy object. pcrs.dat contains the PCR values to seal against. tpm2_startauthsession -S session.dat
tpm2_policypcr -S session.dat -l sha256:7,11 -f pcrs.dat -L policy.dat tpm2_flushcontext session.dat
# Seal key into TPM.
cat key.dat | tpm2_create -C primary.ctx -u key.pub -r key.priv -L policy.dat -i- tpm2_load -C primary.ctx -u key.pub -r key.priv -n sealing.name -c sealing.ctx tpm2_evictcontrol -C o -c sealing.ctx 0x81000000
Then to unseal the key in grub, add this to grub.cfg:
tpm2_key_protector_init --mode=nv --nvindex=0x81000000 --pcrs=7,11 cryptomount -u <UUID> --protector tpm2
--- .../commands/tpm2_key_protector/module.c | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-)
grub-core/commands/tpm2_key_protector/module.c +23 -4
@@ -981,11 +981,30 @@ grub_tpm2_protector_srk_recover (const struct grub_tpm2_protector_context *ctx, }static grub_err_t -grub_tpm2_protector_nv_recover (const struct grub_tpm2_protector_context *ctx __attribute__ ((unused)), -grub_uint8_t **key __attribute__ ((unused)), -grub_size_t *key_size __attribute__ ((unused))) +grub_tpm2_protector_nv_recover (const struct grub_tpm2_protector_context *ctx, +grub_uint8_t **key,grub_size_t *key_size) { -return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET ,N_ ("NV Index mode is not implemented yet" )); +TPM_HANDLE sealed_handle = ctx->nv; +tpm2key_policy_t policy_seq =NULL ; +grub_err_t err; + +/* Create a basic policy sequence based on the given PCR selection */ + err =grub_tpm2_protector_simple_policy_seq (ctx, &policy_seq); +if (err !=GRUB_ERR_NONE ) + goto exit; + + err =grub_tpm2_protector_unseal (policy_seq, sealed_handle, key, key_size); + +/* Pop error messages on success */ +if (err ==GRUB_ERR_NONE ) +while (grub_error_pop ()); + + exit: +TPM2_FlushContext (sealed_handle); + +grub_tpm2key_free_policy_seq (policy_seq); + +return err; } static grub_err_t
Signature · 7 lines
2.35.3 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 20/25] tpm2_key_protector: Implement NV index
Quoted 27 lines · Gary Lin via Grub-devel
From: Patrick Colp <[email protected]>
Currently with the TPM2 protector, only SRK mode is supported and NV index support is just a stub. Implement the NV index option.
Note: This only extends support on the unseal path.
grub2_protecthas not been updated. tpm2-tools can be used to insert a key into the NV index.An example of inserting a key using tpm2-tools:
# Get random key.
tpm2_getrandom32 > key.dat# Create primary object.
tpm2_createprimary-C o -g sha256 -G ecc -c primary.ctx# Create policy object.
pcrs.datcontains the PCR values to seal against.tpm2_startauthsession-S session.dat
tpm2_policypcr-S session.dat -l sha256:7,11 -f pcrs.dat -L policy.dattpm2_flushcontextsession.dat# Seal key into TPM.
cat key.dat |tpm2_create-C primary.ctx -u key.pub -r key.priv -L policy.dat -i-tpm2_load-C primary.ctx -u key.pub -r key.priv -n sealing.name -c sealing.ctxtpm2_evictcontrol-C o -c sealing.ctx0x81000000
Quoted 4 lines
Then to unseal the key in grub, add this to grub.cfg:
tpm2_key_protector_init --mode=nv --nvindex=0x81000000 --pcrs=7,11 cryptomount -u <UUID> --protector tpm2
Please add this to the GRUB documentation.
Quoted 26 lines
Signed-off-by Patrick Colp <[email protected]>Signed-off-by Gary Lin <[email protected]>Reviewed-by Stefan Berger <[email protected]>--- .../commands/tpm2_key_protector/module.c | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-)grub-core/commands/tpm2_key_protector/module.c +6
-4@@ -981,11 +981,30 @@ grub_tpm2_protector_srk_recover (const struct grub_tpm2_protector_context *ctx, }static grub_err_t -grub_tpm2_protector_nv_recover (const struct grub_tpm2_protector_context *ctx __attribute__ ((unused)), -grub_uint8_t **key __attribute__ ((unused)), -grub_size_t *key_size __attribute__ ((unused))) +grub_tpm2_protector_nv_recover (const struct grub_tpm2_protector_context *ctx, +grub_uint8_t **key,grub_size_t *key_size) { -return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET ,N_ ("NV Index mode is not implemented yet" )); +TPM_HANDLE sealed_handle = ctx->nv; +tpm2key_policy_t policy_seq =NULL ; +grub_err_t err; +
grub-core/commands/tpm2_key_protector/module.c grub_tpm2_protector_srk_recover (const struct grub_tpm2_protector_context *ctx, · line 1000
Quoted 10 lines
grub-core/commands/tpm2_key_protector/module.c +10
-0+/* Create a basic policy sequence based on the given PCR selection */ + err =grub_tpm2_protector_simple_policy_seq (ctx, &policy_seq); +if (err !=GRUB_ERR_NONE ) + goto exit; + + err =grub_tpm2_protector_unseal (policy_seq, sealed_handle, key, key_size); + +/* Pop error messages on success */ +if (err ==GRUB_ERR_NONE ) +while (grub_error_pop ());
Hmmm... Why does unseal success clear whole error stack? If it is correct it begs for comment here.
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 20/25] tpm2_key_protector: Implement NV index
Quoted 28 lines · Daniel Kiper
Quoted 27 lines · Gary Lin via Grub-devel
From: Patrick Colp <[email protected]>
Currently with the TPM2 protector, only SRK mode is supported and NV index support is just a stub. Implement the NV index option.
Note: This only extends support on the unseal path.
grub2_protecthas not been updated. tpm2-tools can be used to insert a key into the NV index.An example of inserting a key using tpm2-tools:
# Get random key.
tpm2_getrandom32 > key.dat# Create primary object.
tpm2_createprimary-C o -g sha256 -G ecc -c primary.ctx# Create policy object.
pcrs.datcontains the PCR values to seal against.tpm2_startauthsession-S session.dat
tpm2_policypcr-S session.dat -l sha256:7,11 -f pcrs.dat -L policy.dattpm2_flushcontextsession.dat# Seal key into TPM.
cat key.dat |tpm2_create-C primary.ctx -u key.pub -r key.priv -L policy.dat -i-tpm2_load-C primary.ctx -u key.pub -r key.priv -n sealing.name -c sealing.ctxtpm2_evictcontrol-C o -c sealing.ctx0x81000000
Quoted 7 lines
Quoted 4 lines
Then to unseal the key in grub, add this to grub.cfg:
tpm2_key_protector_init --mode=nv --nvindex=0x81000000 --pcrs=7,11 cryptomount -u <UUID> --protector tpm2Please add this to the GRUB documentation.
Sure.
Quoted 31 lines
Quoted 31 lines
Signed-off-by Patrick Colp <[email protected]>Signed-off-by Gary Lin <[email protected]>Reviewed-by Stefan Berger <[email protected]>--- .../commands/tpm2_key_protector/module.c | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-)grub-core/commands/tpm2_key_protector/module.c +11
-4@@ -981,11 +981,30 @@ grub_tpm2_protector_srk_recover (const struct grub_tpm2_protector_context *ctx, }static grub_err_t -grub_tpm2_protector_nv_recover (const struct grub_tpm2_protector_context *ctx __attribute__ ((unused)), -grub_uint8_t **key __attribute__ ((unused)), -grub_size_t *key_size __attribute__ ((unused))) +grub_tpm2_protector_nv_recover (const struct grub_tpm2_protector_context *ctx, +grub_uint8_t **key,grub_size_t *key_size) { -return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET ,N_ ("NV Index mode is not implemented yet" )); +TPM_HANDLE sealed_handle = ctx->nv; +tpm2key_policy_t policy_seq =NULL ; +grub_err_t err; + +/* Create a basic policy sequence based on the given PCR selection */ + err =grub_tpm2_protector_simple_policy_seq (ctx, &policy_seq); +if (err !=GRUB_ERR_NONE ) + goto exit; +
Quoted 9 lines
grub-core/commands/tpm2_key_protector/module.c grub_tpm2_protector_srk_recover (const struct grub_tpm2_protector_context *ctx, · line 1000
Quoted 5 lines
grub-core/commands/tpm2_key_protector/module.c +5
-0+ err =grub_tpm2_protector_unseal (policy_seq, sealed_handle, key, key_size); + +/* Pop error messages on success */ +if (err ==GRUB_ERR_NONE ) +while (grub_error_pop ());Hmmm... Why does unseal success clear whole error stack? If it is correct it begs for comment here.
It's mirrored from srk mode which may goes through several policy sequences. For nvindex, it only tries one policy sequence, so, yes, it's redundant to pop grub errors.
Gary Lin
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v18 21/25 cryptodisk: Fallback to passphrase
In reply to Gary Lin via Grub-develFrom: Patrick Colp <[email protected]>
If a protector is specified, but it fails to unlock the disk, fall back to asking for the passphrase. However, an error was set indicating that the protector(s) failed. Later code (e.g., LUKS code) fails as grub_errno is now set. Print the existing errors out first, before proceeding with the passphrase.
--- grub-core/disk/cryptodisk.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
grub-core/disk/cryptodisk.c +16 -1
@@ -1167,6 +1167,10 @@ grub_cryptodisk_scan_device_real (const char *name, ret = cr->recover_key (source, dev, cargs);if (ret !=GRUB_ERR_NONE ) { +/* Reset key data to trigger the passphrase prompt later */ + cargs->key_data =NULL ; + cargs->key_len =0 ; + part =grub_partition_get_name (source->partition);grub_dprintf ("cryptodisk" , "recovered a key from key protector %s but it "
@@ -1192,7 +1196,6 @@ grub_cryptodisk_scan_device_real (const char *name, source->name, source->partition !=NULL ?"," :"" , part != NULL ? part : N_("UNKNOWN"), dev->uuid);grub_free (part); - goto error; }if (cargs->key_len)
@@ -1207,6 +1210,18 @@ grub_cryptodisk_scan_device_real (const char *name,unsigned long tries =3 ;const char *tries_env; +/* +* Print the error from key protectors and clear grub_errno. +* Since '--protector' doesn't not coexist with '--password' and +* '--key-file', only "cargs->key_len == 0" is expected if all +* key protectors fail. +*/ +if (grub_errno) + { +grub_print_error (); + grub_errno =GRUB_ERR_NONE ; + } + askpass =1 ; cargs->key_data =grub_malloc (GRUB_CRYPTODISK_MAX_PASSPHRASE );if (cargs->key_data ==NULL )
Signature · 7 lines
2.35.3 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 21/25] cryptodisk: Fallback to passphrase
Quoted 7 lines · Gary Lin via Grub-devel
From: Patrick Colp <[email protected]>
If a protector is specified, but it fails to unlock the disk, fall back to asking for the passphrase. However, an error was set indicating that the protector(s) failed. Later code (e.g., LUKS code) fails as
grub_errnois now set. Print the existing errors out first, before proceeding with the passphrase.
This behavior has to be documented in the GRUB docs.
Quoted 31 lines
Signed-off-by Patrick Colp <[email protected]>Signed-off-by Gary Lin <[email protected]>Reviewed-by Stefan Berger <[email protected]>--- grub-core/disk/cryptodisk.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)grub-core/disk/cryptodisk.c +4
-1@@ -1167,6 +1167,10 @@ grub_cryptodisk_scan_device_real (const char *name, ret = cr->recover_key (source, dev, cargs);if (ret !=GRUB_ERR_NONE ) { +/* Reset key data to trigger the passphrase prompt later */ + cargs->key_data =NULL ; + cargs->key_len =0 ; + part =grub_partition_get_name (source->partition);grub_dprintf ("cryptodisk" , "recovered a key from key protector %s but it "@@ -1192,7 +1196,6 @@ grub_cryptodisk_scan_device_real (const char *name, source->name, source->partition !=NULL ?"," :"" , part != NULL ? part : N_("UNKNOWN"), dev->uuid);grub_free (part); - goto error; }if (cargs->key_len)
grub-core/disk/cryptodisk.c grub_cryptodisk_scan_device_real (const char *name, · line 1214
Quoted 5 lines
grub-core/disk/cryptodisk.c +2
-0@@ -1207,6 +1210,18 @@ grub_cryptodisk_scan_device_real (const char *name,unsigned long tries =3 ;const char *tries_env; +/* +* Print the error from key protectors and clear grub_errno.
I think you should explain why you have to do it here. Something similar to the commit message...
grub-core/disk/cryptodisk.c grub_cryptodisk_scan_device_real (const char *name, · line 1215
Quoted 1 line
grub-core/disk/cryptodisk.c +1
-0+* Since '--protector' doesn't not coexist with '--password' and
s/doesn't not/cannot/?
grub-core/disk/cryptodisk.c grub_cryptodisk_scan_device_real (const char *name, · line 1219
Quoted 4 lines
grub-core/disk/cryptodisk.c +4
-0+* '--key-file', only "cargs->key_len == 0" is expected if all +* key protectors fail. +*/ +if (grub_errno)
if (grub_errno != GRUB_ERR_NONE)
grub-core/disk/cryptodisk.c grub_cryptodisk_scan_device_real (const char *name, · line 1223
Quoted 4 lines
grub-core/disk/cryptodisk.c +4
-0+ { +grub_print_error (); + grub_errno =GRUB_ERR_NONE ; + }
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 21/25] cryptodisk: Fallback to passphrase
Quoted 11 lines · Daniel Kiper
Quoted 7 lines · Gary Lin via Grub-devel
From: Patrick Colp <[email protected]>
If a protector is specified, but it fails to unlock the disk, fall back to asking for the passphrase. However, an error was set indicating that the protector(s) failed. Later code (e.g., LUKS code) fails as
grub_errnois now set. Print the existing errors out first, before proceeding with the passphrase.This behavior has to be documented in the GRUB docs.
I'll address the behavior in the section for TPM2 key protector.
Quoted 34 lines
Quoted 34 lines
Signed-off-by Patrick Colp <[email protected]>Signed-off-by Gary Lin <[email protected]>Reviewed-by Stefan Berger <[email protected]>--- grub-core/disk/cryptodisk.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)grub-core/disk/cryptodisk.c +4
-1@@ -1167,6 +1167,10 @@ grub_cryptodisk_scan_device_real (const char *name, ret = cr->recover_key (source, dev, cargs);if (ret !=GRUB_ERR_NONE ) { +/* Reset key data to trigger the passphrase prompt later */ + cargs->key_data =NULL ; + cargs->key_len =0 ; + part =grub_partition_get_name (source->partition);grub_dprintf ("cryptodisk" , "recovered a key from key protector %s but it "@@ -1192,7 +1196,6 @@ grub_cryptodisk_scan_device_real (const char *name, source->name, source->partition !=NULL ?"," :"" , part != NULL ? part : N_("UNKNOWN"), dev->uuid);grub_free (part); - goto error; }if (cargs->key_len)@@ -1207,6 +1210,18 @@ grub_cryptodisk_scan_device_real (const char *name,unsigned long tries =3 ;const char *tries_env;
Quoted 6 lines
grub-core/disk/cryptodisk.c grub_cryptodisk_scan_device_real (const char *name, · line 1214
Quoted 2 lines
grub-core/disk/cryptodisk.c +2
-0+/* +* Print the error from key protectors and clear grub_errno. I think you should explain why you have to do it here. Something similar to the commit message...
It's mainly to print the error from the key protector. I'll add more comments for that.
Quoted 4 lines
grub-core/disk/cryptodisk.c grub_cryptodisk_scan_device_real (const char *name, · line 1215
Quoted 1 line
grub-core/disk/cryptodisk.c +1
-0+* Since '--protector' doesn't not coexist with '--password' and s/doesn't not/cannot/?
Will fix it in the next versino.
Quoted 7 lines
grub-core/disk/cryptodisk.c grub_cryptodisk_scan_device_real (const char *name, · line 1219
Quoted 4 lines
grub-core/disk/cryptodisk.c +4
-0+* '--key-file', only "cargs->key_len == 0" is expected if all +* key protectors fail. +*/ +if (grub_errno)if (
grub_errno!=GRUB_ERR_NONE)
Ok. I'll fix it.
Gary Lin
Quoted 6 lines
grub-core/disk/cryptodisk.c grub_cryptodisk_scan_device_real (const char *name, · line 1223
Quoted 4 lines
grub-core/disk/cryptodisk.c +4
-0+ { +grub_print_error (); + grub_errno =GRUB_ERR_NONE ; + }Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v18 22/25 cryptodisk: wipe out the cached keys from protectors
In reply to Gary Lin via Grub-develAn attacker may insert a malicious disk with the same crypto UUID and trick grub2 to mount the fake root. Even though the key from the key protector fails to unlock the fake root, it's not wiped out cleanly so the attacker could dump the memory to retrieve the secret key. To defend such attack, wipe out the cached key when we don't need it.
--- grub-core/disk/cryptodisk.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
grub-core/disk/cryptodisk.c +5 -1
@@ -1399,7 +1399,11 @@ grub_cryptodisk_clear_key_cache (struct grub_cryptomount_args *cargs)return ;for (i =0 ; cargs->protectors[i]; i++) -grub_free (cargs->key_cache[i].key); + { +if (cargs->key_cache[i].key) +grub_memset (cargs->key_cache[i].key,0 , cargs->key_cache[i].key_len); +grub_free (cargs->key_cache[i].key); + }grub_free (cargs->key_cache); }
Signature · 7 lines
2.35.3 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v18 22/25] cryptodisk: wipe out the cached keys from protectors
Quoted 9 lines · Gary Lin via Grub-devel
An attacker may insert a malicious disk with the same crypto UUID and trick grub2 to mount the fake root. Even though the key from the key protector fails to unlock the fake root, it's not wiped out cleanly so the attacker could dump the memory to retrieve the secret key. To defend such attack, wipe out the cached key when we don't need it.
Cc Fabian Vogt <[email protected]>Signed-off-by Gary Lin <[email protected]>Reviewed-by Stefan Berger <[email protected]>
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v18 23/25 diskfilter: look up cryptodisk devices first
In reply to Gary Lin via Grub-develWhen using disk auto-unlocking with TPM 2.0, the typical grub.cfg may look like this:
tpm2_key_protector_init --tpm2key=(hd0,gpt1)/boot/grub2/sealed.tpm cryptomount -u <PART-UUID> -P tpm2 search --fs-uuid --set=root <FS-UUID>
Since the disk search order is based on the order of module loading, the attacker could insert a malicious disk with the same FS-UUID root to trick grub2 to boot into the malicious root and further dump memory to steal the unsealed key.
Do defend against such an attack, we can specify the hint provided by 'grub-probe' to search the encrypted partition first:
search --fs-uuid --set=root --hint='cryptouuid/<PART-UUID>' <FS-UUID>
However, for LVM on an encrypted partition, the search hint provided by 'grub-probe' is:
--hint='lvmid/<VG-UUID>/<LV-UUID>'
It doesn't guarantee to look up the logical volume from the encrypted partition, so the attacker may have the chance to fool grub2 to boot into the malicious disk.
To minimize the attack surface, this commit tweaks the disk device search in diskfilter to look up cryptodisk devices first and then others, so that the auto-unlocked disk will be found first, not the attacker's disk.
--- grub-core/disk/diskfilter.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-)
grub-core/disk/diskfilter.c +26 -9
@@ -226,15 +226,32 @@ scan_devices (const char *arname)int need_rescan;for (pull =0 ; pull <GRUB_DISK_PULL_MAX ; pull++) -for (p = grub_disk_dev_list; p; p = p->next) -if (p->id !=GRUB_DISK_DEVICE_DISKFILTER_ID - && p->disk_iterate) - { -if ((p->disk_iterate) (scan_disk_hook,NULL , pull)) -return ; -if (arname &&is_lv_readable (find_lv (arname),1 )) -return ; - } + { +/* look up the crytodisk devices first */ +for (p = grub_disk_dev_list; p; p = p->next) +if (p->id ==GRUB_DISK_DEVICE_CRYPTODISK_ID + && p->disk_iterate) + { +if ((p->disk_iterate) (scan_disk_hook,NULL , pull)) +return ; +if (arname &&is_lv_readable (find_lv (arname),1 )) +return ; +break ; + } + +/* check the devices other than crytodisk */ +for (p = grub_disk_dev_list; p; p = p->next) +if (p->id ==GRUB_DISK_DEVICE_CRYPTODISK_ID ) +continue ; +else if (p->id !=GRUB_DISK_DEVICE_DISKFILTER_ID + && p->disk_iterate) + { +if ((p->disk_iterate) (scan_disk_hook,NULL , pull)) +return ; +if (arname &&is_lv_readable (find_lv (arname),1 )) +return ; + } + } scan_depth =0 ; need_rescan =1 ;
Signature · 7 lines
2.35.3 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel