-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ESYS: Support of Cp and RpHashes from Esys Layer
The ESYS API is extended with the functions: Esys_GetCpHash, Esys_GetRpHash, and Esys_Abort. The cp hash can computed after the async call of a function. The rp hash after the finish call. If only the async call is executed to to compute the cp hash Esys_Abort has to be called to enable the execution of further ESYS commands. Addresses: #2930. Signed-off-by: Juergen Repp <[email protected]>
- Loading branch information
1 parent
e25ab67
commit bd830f7
Showing
12 changed files
with
355 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* SPDX-License-Identifier: BSD-2-Clause */ | ||
/******************************************************************************* | ||
* Copyright 2025, Juergen Repp | ||
* All rights reserved. | ||
******************************************************************************/ | ||
|
||
#ifdef HAVE_CONFIG_H | ||
#include "config.h" // IWYU pragma: keep | ||
#endif | ||
|
||
#include <inttypes.h> // for PRIx32, uint8_t, SIZE_MAX, int32_t | ||
#include <stdbool.h> // for bool, false, true | ||
#include <stdlib.h> // for NULL, malloc, size_t, calloc | ||
#include <string.h> // for memcmp | ||
|
||
#include "esys_int.h" // for RSRC_NODE_T, ESYS_CONTEXT, _ESYS_ASSERT... | ||
#include "esys_mu.h" // for iesys_MU_IESYS_RESOURCE_Marshal, iesys_... | ||
#include "esys_types.h" // for IESYS_RESOURCE, IESYS_RSRC_UNION, IESYS... | ||
#include "tss2_common.h" // for TSS2_RC, TSS2_RC_SUCCESS, TSS2_ESYS_RC_... | ||
#include "tss2_esys.h" // for ESYS_CONTEXT, ESYS_TR, ESYS_TR_NONE | ||
#include "tss2_tpm2_types.h" // for TPM2B_NAME, TPM2_HANDLE, TPM2_HR_SHIFT | ||
|
||
#define LOGMODULE esys | ||
#include "util/log.h" // for return_if_error, SAFE_FREE, goto_if_error | ||
|
||
|
||
static TSS2_RC get_hash(HASH_TAB_ITEM hash_tab[3], | ||
TPMI_ALG_HASH hashAlg, uint8_t **hash, size_t *hash_size) { | ||
int i; | ||
|
||
for (i = 0; i < 3; i++) { | ||
if (hash_tab[i].alg == hashAlg) { | ||
*hash_size = hash_tab[i].size; | ||
*hash = malloc(*hash_size); | ||
return_if_null(*hash, "Buffer could not be allocated", | ||
TSS2_ESYS_RC_MEMORY); | ||
memcpy(*hash, &hash_tab[i].digest[0], *hash_size); | ||
return TSS2_RC_SUCCESS; | ||
} | ||
} | ||
return TSS2_ESYS_RC_BAD_SEQUENCE; | ||
} | ||
|
||
/** Get the cpHash buffer computed by an ESYS async call. | ||
* | ||
* The buffer will be returned if the buffer is found for the passed hashAlg. | ||
* @param esys_ctxt [in,out] The ESYS_CONTEXT. | ||
* @param hashAlg [in] The hash alg used to compute the cp hash. | ||
* @param cpHash [out] The buffer containing the cp hash. | ||
* (caller-callocated) | ||
* @param cpHash_size [out] The size of the cpHash buffer. | ||
* @retval TSS2_RC_SUCCESS on Success. | ||
* @retval TSS2_ESYS_RC_BAD_SEQUENCE: if no cpHash has been computed. | ||
* @retval TSS2_ESYS_RC_BAD_VALUE if hashAlg is not found. | ||
* @retval TSS2_ESYS_RC_BAD_REFERENCE if esys_ctx is NULL. | ||
* @retval TSS2_ESYS_RC_MEMORY if the buffer for the cpHash can't | ||
* be allocated. | ||
*/ | ||
TSS2_RC Esys_GetCpHash(ESYS_CONTEXT* esys_ctx, | ||
TPMI_ALG_HASH hashAlg, uint8_t **cpHash, size_t *cpHash_size) { | ||
return_if_null(esys_ctx, "ESYS context is NULL", | ||
TSS2_ESYS_RC_BAD_REFERENCE); | ||
if (esys_ctx->cmd_hash != CP_HASH) { | ||
return_error(TSS2_ESYS_RC_BAD_SEQUENCE, "No cp hash is available."); | ||
} | ||
return get_hash(&esys_ctx->hash_tab[0], hashAlg, cpHash, cpHash_size); | ||
} | ||
|
||
/** Get the rpHash buffer computed by an ESYS finalize call. | ||
* | ||
* The buffer will be returned if the buffer is found for the passed hashAlg. | ||
* @param esys_ctx [in,out] The ESYS_CONTEXT. | ||
* @param hashAlg [in] The hash alg used to compute the rp hash. | ||
* @param cpHash [out] The buffer containing the rp hash. | ||
* (caller-callocated) | ||
* @param cpHash_size [out] The size of the cpHash buffer. | ||
* @retval TSS2_RC_SUCCESS on Success. | ||
* @retval TSS2_ESYS_RC_BAD_SEQUENCE: if no cpHash has been computed. | ||
* @retval TSS2_ESYS_RC_BAD_VALUE if hashAlg is not found. | ||
* @retval TSS2_ESYS_RC_BAD_REFERENCE if esys_ctx is NULL. | ||
* @retval TSS2_ESYS_RC_MEMORY if the buffer for the cpHash can't | ||
* be allocated. | ||
*/ | ||
TSS2_RC Esys_GetRpHash(ESYS_CONTEXT* esys_ctx, | ||
TPMI_ALG_HASH hashAlg, uint8_t **cpHash, size_t *cpHash_size) { | ||
return_if_null(esys_ctx, "ESYS context is NULL", | ||
TSS2_ESYS_RC_BAD_REFERENCE); | ||
if (esys_ctx->cmd_hash != RP_HASH) { | ||
return_error(TSS2_ESYS_RC_BAD_SEQUENCE, "No cp hash is available."); | ||
} | ||
return get_hash(&esys_ctx->hash_tab[0], hashAlg, cpHash, cpHash_size); | ||
} | ||
|
||
/** Reset the ESYS state. | ||
* | ||
* If only the cp hash will be computed and there will no finish call | ||
* after the async call the ESYS sate has to be reset to allow further ESYS calls. | ||
* @param esys_ctx [in,out] The ESYS_CONTEXT. | ||
* @param cpHash_size [out] The size of the cpHash buffer. | ||
* @retval TSS2_RC_SUCCESS on Success. | ||
* @retval TSS2_ESYS_RC_BAD_REFERENCE if esys_ctx is NULL. | ||
*/ | ||
TSS2_RC Esys_Abort(ESYS_CONTEXT* esys_ctx) { | ||
TSS2_SYS_CONTEXT *sys_ctx; | ||
TSS2_RC r; | ||
|
||
return_if_null(esys_ctx, "ESYS context is NULL", | ||
TSS2_ESYS_RC_BAD_REFERENCE); | ||
esys_ctx->state = ESYS_STATE_INIT; | ||
|
||
r = Esys_GetSysContext(esys_ctx, &sys_ctx); | ||
return_if_error(r, "Could not get Sys context"); | ||
|
||
return Tss2_Sys_Abort(sys_ctx); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.