From 08249bc2f0145e1056e5cad7f3be235b1bb258b3 Mon Sep 17 00:00:00 2001 From: Christian Plappert Date: Tue, 22 Jun 2021 10:43:05 +0200 Subject: [PATCH] Add user-level mu-api call for key derivation This commit introduces a new user-level mu-api call (Tss2_MU_TPMT_PUBLIC_DERIVE_Marshal) that allows to create a Derived Object with the command TPM2_CreateLoaded. Signed-off-by: Christian Plappert --- include/tss2/tss2_mu.h | 59 ++++++++++++++++++++++++++++++++++ include/tss2/tss2_tpm2_types.h | 6 ++++ lib/tss2-mu.def | 2 ++ lib/tss2-mu.map | 2 ++ src/tss2-mu/tpms-types.c | 8 +++++ src/tss2-mu/tpmt-types.c | 14 ++++++++ src/tss2-mu/tpmu-types.c | 11 +++++++ 7 files changed, 102 insertions(+) diff --git a/include/tss2/tss2_mu.h b/include/tss2/tss2_mu.h index 8933efcfe..0381cbaf9 100644 --- a/include/tss2/tss2_mu.h +++ b/include/tss2/tss2_mu.h @@ -468,6 +468,21 @@ Tss2_MU_TPM2B_ECC_POINT_Unmarshal( size_t *offset, TPM2B_ECC_POINT *dest); +TSS2_RC +Tss2_MU_TPM2B_LABEL_Marshal( + TPM2B_LABEL const *src, + uint8_t buffer[], + size_t buffer_size, + size_t *offset); + +TSS2_RC +Tss2_MU_TPM2B_LABEL_Unmarshal( + uint8_t const buffer[], + size_t buffer_size, + size_t *offset, + TPM2B_LABEL *dest); + + TSS2_RC Tss2_MU_TPM2B_NV_PUBLIC_Marshal( TPM2B_NV_PUBLIC const *src, @@ -720,6 +735,20 @@ Tss2_MU_TPMS_ECC_POINT_Unmarshal( size_t *offset, TPMS_ECC_POINT *dest); +TSS2_RC +Tss2_MU_TPMS_DERIVE_Marshal( + TPMS_DERIVE const *src, + uint8_t buffer[], + size_t buffer_size, + size_t *offset); + +TSS2_RC +Tss2_MU_TPMS_DERIVE_Unmarshal( + uint8_t const buffer[], + size_t buffer_size, + size_t *offset, + TPMS_DERIVE *dest); + TSS2_RC Tss2_MU_TPMS_NV_PUBLIC_Marshal( TPMS_NV_PUBLIC const *src, @@ -1658,6 +1687,22 @@ Tss2_MU_TPMU_PUBLIC_ID_Unmarshal( uint32_t selector_value, TPMU_PUBLIC_ID *dest); +TSS2_RC +Tss2_MU_TPMU_PUBLIC_ID_DERIVE_Marshal( + TPMU_PUBLIC_ID_DERIVE const *src, + uint32_t selector_value, + uint8_t buffer[], + size_t buffer_size, + size_t *offset); + +TSS2_RC +Tss2_MU_TPMU_PUBLIC_ID_DERIVE_Unmarshal( + uint8_t const buffer[], + size_t buffer_size, + size_t *offset, + uint32_t selector_value, + TPMU_PUBLIC_ID_DERIVE *dest); + TSS2_RC Tss2_MU_TPMU_NAME_Marshal( TPMU_NAME const *src, @@ -1856,6 +1901,20 @@ Tss2_MU_TPMT_PUBLIC_Unmarshal( size_t *offset, TPMT_PUBLIC *dest); +TSS2_RC +Tss2_MU_TPMT_PUBLIC_DERIVE_Marshal( + TPMT_PUBLIC const *src, + uint8_t buffer[], + size_t buffer_size, + size_t *offset); + +TSS2_RC +Tss2_MU_TPMT_PUBLIC_DERIVE_Unmarshal( + uint8_t const buffer[], + size_t buffer_size, + size_t *offset, + TPMT_PUBLIC *dest); + TSS2_RC Tss2_MU_TPMT_PUBLIC_PARMS_Marshal( TPMT_PUBLIC_PARMS const *src, diff --git a/include/tss2/tss2_tpm2_types.h b/include/tss2/tss2_tpm2_types.h index 1ce737e42..4c20bfd8e 100644 --- a/include/tss2/tss2_tpm2_types.h +++ b/include/tss2/tss2_tpm2_types.h @@ -1755,6 +1755,9 @@ union TPMU_PUBLIC_ID { TPMS_DERIVE derive; }; +/* Definition of TPMU_PUBLIC_ID_DERIVE Union */ +typedef union TPMU_PUBLIC_ID TPMU_PUBLIC_ID_DERIVE; + /* Definition of TPMS_KEYEDHASH_PARMS Structure */ typedef struct TPMS_KEYEDHASH_PARMS TPMS_KEYEDHASH_PARMS; struct TPMS_KEYEDHASH_PARMS { @@ -1814,6 +1817,9 @@ struct TPMT_PUBLIC { TPMU_PUBLIC_ID unique; /* the unique identifier of the structure. For an asymmetric key this would be the public key. */ }; +/* Definition of TPMT_PUBLIC_DERIVE Structure */ +typedef struct TPMT_PUBLIC TPMT_PUBLIC_DERIVE; + /* Definition of TPM2B_PUBLIC Structure */ typedef struct TPM2B_PUBLIC TPM2B_PUBLIC; struct TPM2B_PUBLIC { diff --git a/lib/tss2-mu.def b/lib/tss2-mu.def index d978c839e..d1d271cc0 100644 --- a/lib/tss2-mu.def +++ b/lib/tss2-mu.def @@ -264,6 +264,8 @@ EXPORTS Tss2_MU_TPMT_SENSITIVE_Unmarshal Tss2_MU_TPMT_PUBLIC_Marshal Tss2_MU_TPMT_PUBLIC_Unmarshal + Tss2_MU_TPMT_PUBLIC_DERIVE_Marshal + Tss2_MU_TPMT_PUBLIC_DERIVE_Unmarshal Tss2_MU_TPMT_PUBLIC_PARMS_Marshal Tss2_MU_TPMT_PUBLIC_PARMS_Unmarshal Tss2_MU_TPMT_TK_CREATION_Marshal diff --git a/lib/tss2-mu.map b/lib/tss2-mu.map index 3f4c8cb91..b2045b1ea 100644 --- a/lib/tss2-mu.map +++ b/lib/tss2-mu.map @@ -264,6 +264,8 @@ Tss2_MU_TPMT_SENSITIVE_Unmarshal; Tss2_MU_TPMT_PUBLIC_Marshal; Tss2_MU_TPMT_PUBLIC_Unmarshal; + Tss2_MU_TPMT_PUBLIC_DERIVE_Marshal; + Tss2_MU_TPMT_PUBLIC_DERIVE_Unmarshal; Tss2_MU_TPMT_PUBLIC_PARMS_Marshal; Tss2_MU_TPMT_PUBLIC_PARMS_Unmarshal; Tss2_MU_TPMT_TK_CREATION_Marshal; diff --git a/src/tss2-mu/tpms-types.c b/src/tss2-mu/tpms-types.c index 3ad725203..ec6b63519 100644 --- a/src/tss2-mu/tpms-types.c +++ b/src/tss2-mu/tpms-types.c @@ -1111,6 +1111,14 @@ TPMS_UNMARSHAL_2(TPMS_ECC_POINT, x, Tss2_MU_TPM2B_ECC_PARAMETER_Unmarshal, y, Tss2_MU_TPM2B_ECC_PARAMETER_Unmarshal) +TPMS_MARSHAL_2(TPMS_DERIVE, + label, ADDR, Tss2_MU_TPM2B_LABEL_Marshal, + context, ADDR, Tss2_MU_TPM2B_LABEL_Marshal) + +TPMS_UNMARSHAL_2(TPMS_DERIVE, + label, Tss2_MU_TPM2B_LABEL_Unmarshal, + context, Tss2_MU_TPM2B_LABEL_Unmarshal) + TPMS_MARSHAL_2(TPMS_SIGNATURE_RSA, hash, VAL, Tss2_MU_UINT16_Marshal, sig, ADDR, Tss2_MU_TPM2B_PUBLIC_KEY_RSA_Marshal) diff --git a/src/tss2-mu/tpmt-types.c b/src/tss2-mu/tpmt-types.c index df899a664..0cacef655 100644 --- a/src/tss2-mu/tpmt-types.c +++ b/src/tss2-mu/tpmt-types.c @@ -588,6 +588,20 @@ TPMT_UNMARSHAL_6(TPMT_PUBLIC, type, Tss2_MU_UINT16_Unmarshal, parameters, type, Tss2_MU_TPMU_PUBLIC_PARMS_Unmarshal, unique, type, Tss2_MU_TPMU_PUBLIC_ID_Unmarshal) +TPMT_MARSHAL_6(TPMT_PUBLIC_DERIVE, type, VAL, Tss2_MU_UINT16_Marshal, + nameAlg, VAL, Tss2_MU_UINT16_Marshal, + objectAttributes, VAL, Tss2_MU_TPMA_OBJECT_Marshal, + authPolicy, ADDR, Tss2_MU_TPM2B_DIGEST_Marshal, + parameters, ADDR, type, Tss2_MU_TPMU_PUBLIC_PARMS_Marshal, + unique, ADDR, type, Tss2_MU_TPMU_PUBLIC_ID_DERIVE_Marshal) + +TPMT_UNMARSHAL_6(TPMT_PUBLIC_DERIVE, type, Tss2_MU_UINT16_Unmarshal, + nameAlg, Tss2_MU_UINT16_Unmarshal, + objectAttributes, Tss2_MU_TPMA_OBJECT_Unmarshal, + authPolicy, Tss2_MU_TPM2B_DIGEST_Unmarshal, + parameters, type, Tss2_MU_TPMU_PUBLIC_PARMS_Unmarshal, + unique, type, Tss2_MU_TPMU_PUBLIC_ID_DERIVE_Unmarshal) + TPMT_MARSHAL_2(TPMT_PUBLIC_PARMS, type, VAL, Tss2_MU_UINT16_Marshal, parameters, ADDR, type, Tss2_MU_TPMU_PUBLIC_PARMS_Marshal) diff --git a/src/tss2-mu/tpmu-types.c b/src/tss2-mu/tpmu-types.c index a615a9baf..42de078f9 100644 --- a/src/tss2-mu/tpmu-types.c +++ b/src/tss2-mu/tpmu-types.c @@ -640,6 +640,17 @@ TPMU_UNMARSHAL2(TPMU_PUBLIC_ID, TPM2_ALG_RSA, rsa, Tss2_MU_TPM2B_PUBLIC_KEY_RSA_Unmarshal, TPM2_ALG_ECC, ecc, Tss2_MU_TPMS_ECC_POINT_Unmarshal) +TPMU_MARSHAL2(TPMU_PUBLIC_ID_DERIVE, + TPM2_ALG_KEYEDHASH, ADDR, derive, Tss2_MU_TPMS_DERIVE_Marshal, + TPM2_ALG_SYMCIPHER, ADDR, sym, Tss2_MU_TPM2B_DIGEST_Marshal, + TPM2_ALG_RSA, ADDR, rsa, Tss2_MU_TPM2B_PUBLIC_KEY_RSA_Marshal, + TPM2_ALG_ECC, ADDR, ecc, Tss2_MU_TPMS_ECC_POINT_Marshal) +TPMU_UNMARSHAL2(TPMU_PUBLIC_ID_DERIVE, + TPM2_ALG_KEYEDHASH, derive, Tss2_MU_TPMS_DERIVE_Unmarshal, + TPM2_ALG_SYMCIPHER, sym, Tss2_MU_TPM2B_DIGEST_Unmarshal, + TPM2_ALG_RSA, rsa, Tss2_MU_TPM2B_PUBLIC_KEY_RSA_Unmarshal, + TPM2_ALG_ECC, ecc, Tss2_MU_TPMS_ECC_POINT_Unmarshal) + TPMU_MARSHAL2(TPMU_PUBLIC_PARMS, TPM2_ALG_KEYEDHASH, ADDR, keyedHashDetail, Tss2_MU_TPMS_KEYEDHASH_PARMS_Marshal, TPM2_ALG_SYMCIPHER, ADDR, symDetail, Tss2_MU_TPMS_SYMCIPHER_PARMS_Marshal,