Skip to content

Commit

Permalink
Add _ex version for GetKeyTemplate RSA/ECC to allow setting all templ…
Browse files Browse the repository at this point in the history
…ate parameters.
  • Loading branch information
dgarske committed Jan 9, 2024
1 parent 6a32ed4 commit ae60c59
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/tpm2_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down
52 changes: 52 additions & 0 deletions wolftpm/tpm2_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ae60c59

Please sign in to comment.