From 8dfb06e639a039b7d9bd315a651b7ae3dc786255 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 | 4 +++ lib/tss2-mu.map | 4 +++ src/tss2-mu/tpms-types.c | 8 +++++ src/tss2-mu/tpmt-types.c | 14 ++++++++ src/tss2-mu/tpmu-types.c | 11 +++++++ 7 files changed, 106 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 f3863336b..ba08ee3fc 100644 --- a/include/tss2/tss2_tpm2_types.h +++ b/include/tss2/tss2_tpm2_types.h @@ -1771,6 +1771,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 { @@ -1830,6 +1833,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..32f9e8505 100644 --- a/lib/tss2-mu.def +++ b/lib/tss2-mu.def @@ -96,6 +96,8 @@ EXPORTS Tss2_MU_TPM2B_OPERAND_Unmarshal Tss2_MU_TPM2B_TEMPLATE_Marshal Tss2_MU_TPM2B_TEMPLATE_Unmarshal + Tss2_MU_TPM2B_LABEL_Marshal + Tss2_MU_TPM2B_LABEL_Unmarshal Tss2_MU_TPM2B_TIMEOUT_Marshal Tss2_MU_TPM2B_TIMEOUT_Unmarshal Tss2_MU_TPMS_CONTEXT_Marshal @@ -264,6 +266,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..b3eb609ac 100644 --- a/lib/tss2-mu.map +++ b/lib/tss2-mu.map @@ -98,6 +98,8 @@ Tss2_MU_TPM2B_TIMEOUT_Unmarshal; Tss2_MU_TPM2B_TEMPLATE_Marshal; Tss2_MU_TPM2B_TEMPLATE_Unmarshal; + Tss2_MU_TPM2B_LABEL_Marshal; + Tss2_MU_TPM2B_LABEL_Unmarshal; Tss2_MU_TPMS_CONTEXT_Marshal; Tss2_MU_TPMS_CONTEXT_Unmarshal; Tss2_MU_TPMS_TIME_INFO_Marshal; @@ -264,6 +266,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 b234bed20..83d4a178e 100644 --- a/src/tss2-mu/tpms-types.c +++ b/src/tss2-mu/tpms-types.c @@ -1129,6 +1129,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 82854ae6a..8fb2ef5b5 100644 --- a/src/tss2-mu/tpmt-types.c +++ b/src/tss2-mu/tpmt-types.c @@ -589,6 +589,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 f9abfa010..91f5a296a 100644 --- a/src/tss2-mu/tpmu-types.c +++ b/src/tss2-mu/tpmu-types.c @@ -642,6 +642,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,