From ae60c59af7605303753be1279ec06c39f02f368a Mon Sep 17 00:00:00 2001 From: David Garske Date: Tue, 9 Jan 2024 13:20:25 -0800 Subject: [PATCH] Add _ex version for GetKeyTemplate RSA/ECC to allow setting all template parameters. --- src/tpm2_wrap.c | 16 ++++++++++++++ wolftpm/tpm2_wrap.h | 52 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/src/tpm2_wrap.c b/src/tpm2_wrap.c index d2257dd3..a747eb3b 100644 --- a/src/tpm2_wrap.c +++ b/src/tpm2_wrap.c @@ -5419,6 +5419,14 @@ int GetKeyTemplateECC(TPMT_PUBLIC* publicTemplate, return TPM_RC_SUCCESS; } +int wolfTPM2_GetKeyTemplate_RSA_ex(TPMT_PUBLIC* publicTemplate, + TPM_ALG_ID nameAlg, TPMA_OBJECT objectAttributes, int keyBits, long exponent, + TPM_ALG_ID sigScheme, TPM_ALG_ID sigHash) +{ + return GetKeyTemplateRSA(publicTemplate, nameAlg, + objectAttributes, keyBits, exponent, sigScheme, sigHash); +} + int wolfTPM2_GetKeyTemplate_RSA(TPMT_PUBLIC* publicTemplate, TPMA_OBJECT objectAttributes) { @@ -5427,6 +5435,14 @@ int wolfTPM2_GetKeyTemplate_RSA(TPMT_PUBLIC* publicTemplate, TPM_ALG_NULL, WOLFTPM2_WRAP_DIGEST); } +int wolfTPM2_GetKeyTemplate_ECC_ex(TPMT_PUBLIC* publicTemplate, + TPM_ALG_ID nameAlg, TPMA_OBJECT objectAttributes, TPM_ECC_CURVE curve, + TPM_ALG_ID sigScheme, TPM_ALG_ID sigHash) +{ + return GetKeyTemplateECC(publicTemplate, nameAlg, + objectAttributes, curve, sigScheme, sigHash); +} + int wolfTPM2_GetKeyTemplate_ECC(TPMT_PUBLIC* publicTemplate, TPMA_OBJECT objectAttributes, TPM_ECC_CURVE curve, TPM_ALG_ID sigScheme) { diff --git a/wolftpm/tpm2_wrap.h b/wolftpm/tpm2_wrap.h index e2d43d43..15644772 100644 --- a/wolftpm/tpm2_wrap.h +++ b/wolftpm/tpm2_wrap.h @@ -2354,6 +2354,7 @@ WOLFTPM_API int wolfTPM2_UnloadHandles_AllTransient(WOLFTPM2_DEV* dev); \param publicTemplate pointer to an empty structure of TPMT_PUBLIC type, to store the new RSA template \param objectAttributes integer value of TPMA_OBJECT type, can contain one or more attributes, e.g. TPMA_OBJECT_fixedTPM + \sa wolfTPM2_GetKeyTemplate_RSA_ex \sa wolfTPM2_GetKeyTemplate_ECC \sa wolfTPM2_GetKeyTemplate_Symmetric \sa wolfTPM2_GetKeyTemplate_KeyedHash @@ -2362,6 +2363,32 @@ WOLFTPM_API int wolfTPM2_UnloadHandles_AllTransient(WOLFTPM2_DEV* dev); WOLFTPM_API int wolfTPM2_GetKeyTemplate_RSA(TPMT_PUBLIC* publicTemplate, TPMA_OBJECT objectAttributes); +/*! + \ingroup wolfTPM2_Wrappers + \brief Prepares a TPM public template for new RSA key based on user selected object attributes + + \return TPM_RC_SUCCESS: successful + \return BAD_FUNC_ARG: check the provided arguments + + \param publicTemplate pointer to an empty structure of TPMT_PUBLIC type, to store the new RSA template + \param nameAlg integer value of TPM_ALG_ID type, specifying a TPM supported hashing algorithm, typically TPM_ALG_SHA256 for SHA 256 + \param objectAttributes integer value of TPMA_OBJECT type, can contain one or more attributes, e.g. TPMA_OBJECT_fixedTPM + \param keyBits integer value, specifying the size of the symmetric key, typically 128 or 256 bits + \param exponent integer value of word32 type, specifying the RSA exponent + \param sigScheme integer value of TPM_ALG_ID type, specifying a TPM supported signature scheme + \param sigHash integer value of TPM_ALG_ID type, specifying a TPM supported signature hash scheme + + \sa wolfTPM2_GetKeyTemplate_RSA + \sa wolfTPM2_GetKeyTemplate_ECC + \sa wolfTPM2_GetKeyTemplate_ECC_ex + \sa wolfTPM2_GetKeyTemplate_Symmetric + \sa wolfTPM2_GetKeyTemplate_KeyedHash + \sa wolfTPM2_GetKeyTemplate_KeySeal +*/ +WOLFTPM_API int wolfTPM2_GetKeyTemplate_RSA_ex(TPMT_PUBLIC* publicTemplate, + TPM_ALG_ID nameAlg, TPMA_OBJECT objectAttributes, int keyBits, long exponent, + TPM_ALG_ID sigScheme, TPM_ALG_ID sigHash); + /*! \ingroup wolfTPM2_Wrappers \brief Prepares a TPM public template for new ECC key based on user selected object attributes @@ -2374,6 +2401,7 @@ WOLFTPM_API int wolfTPM2_GetKeyTemplate_RSA(TPMT_PUBLIC* publicTemplate, \param curve integer value of TPM_ECC_CURVE type, specifying a TPM supported ECC curve ID \param sigScheme integer value of TPM_ALG_ID type, specifying a TPM supported signature scheme + \sa wolfTPM2_GetKeyTemplate_ECC_ex \sa wolfTPM2_GetKeyTemplate_RSA \sa wolfTPM2_GetKeyTemplate_Symmetric \sa wolfTPM2_GetKeyTemplate_KeyedHash @@ -2382,6 +2410,30 @@ WOLFTPM_API int wolfTPM2_GetKeyTemplate_RSA(TPMT_PUBLIC* publicTemplate, WOLFTPM_API int wolfTPM2_GetKeyTemplate_ECC(TPMT_PUBLIC* publicTemplate, TPMA_OBJECT objectAttributes, TPM_ECC_CURVE curve, TPM_ALG_ID sigScheme); +/*! + \ingroup wolfTPM2_Wrappers + \brief Prepares a TPM public template for new ECC key based on user selected object attributes + + \return TPM_RC_SUCCESS: successful + \return BAD_FUNC_ARG: check the provided arguments + + \param publicTemplate pointer to an empty structure of TPMT_PUBLIC type, to store the new ECC key template + \param nameAlg integer value of TPM_ALG_ID type, specifying a TPM supported hashing algorithm, typically TPM_ALG_SHA256 for SHA 256 + \param objectAttributes integer value of TPMA_OBJECT type, can contain one or more attributes, e.g. TPMA_OBJECT_fixedTPM + \param curve integer value of TPM_ECC_CURVE type, specifying a TPM supported ECC curve ID + \param sigScheme integer value of TPM_ALG_ID type, specifying a TPM supported signature scheme + \param sigHash integer value of TPM_ALG_ID type, specifying a TPM supported signature hash scheme + + \sa wolfTPM2_GetKeyTemplate_ECC + \sa wolfTPM2_GetKeyTemplate_RSA + \sa wolfTPM2_GetKeyTemplate_Symmetric + \sa wolfTPM2_GetKeyTemplate_KeyedHash + \sa wolfTPM2_GetKeyTemplate_KeySeal +*/ +WOLFTPM_API int wolfTPM2_GetKeyTemplate_ECC_ex(TPMT_PUBLIC* publicTemplate, + TPM_ALG_ID nameAlg, TPMA_OBJECT objectAttributes, TPM_ECC_CURVE curve, + TPM_ALG_ID sigScheme, TPM_ALG_ID sigHash); + /*! \ingroup wolfTPM2_Wrappers \brief Prepares a TPM public template for new Symmetric key