Skip to content

Commit

Permalink
sys test: change hashalg from sha1 to sha256 for pcr extend test.
Browse files Browse the repository at this point in the history
The test failed when a physical TPM was used and the TPM did not
support a SHA1 bank.
The hash alg is changed to SHA256 and it's checked whether the TPM
supports the selected bank.

Signed-off-by: Juergen Repp <juergen_repp@web.de>
  • Loading branch information
JuergenReppSIT committed Feb 7, 2024
1 parent e637b84 commit 8d497ad
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions test/integration/sys-pcr-extension.int.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "test.h"
#include "sys-util.h"
#define PCR_8 8
#define EXIT_SKIP 77
/**
* This program contains integration test for SYS Tss2_Sys_PCR_Read
* and Tss2_Sys_PCR_Extend. This is an use case scenario on PCR extend.
Expand All @@ -37,8 +38,8 @@ test_invoke (TSS2_SYS_CONTEXT *sys_context)
TPML_PCR_SELECTION pcr_selection;
UINT32 pcr_update_counter_before_extend;
UINT32 pcr_update_counter_after_extend;
UINT8 pcr_before_extend[20];
UINT8 pcr_after_extend[20];
UINT8 pcr_before_extend[TPM2_SHA256_DIGEST_SIZE];
UINT8 pcr_after_extend[TPM2_SHA256_DIGEST_SIZE];
TPML_DIGEST pcr_values;
TPML_DIGEST_VALUES digests;
TPML_PCR_SELECTION pcr_selection_out;
Expand All @@ -57,15 +58,15 @@ test_invoke (TSS2_SYS_CONTEXT *sys_context)
exit(1);
}
digests.count = 1;
digests.digests[0].hashAlg = TPM2_ALG_SHA1;
digests.digests[0].hashAlg = TPM2_ALG_SHA256;
digest_size = GetDigestSize( digests.digests[0].hashAlg );

for( i = 0; i < digest_size; i++ )
{
digests.digests[0].digest.sha1[i] = (UINT8)(i % 256);
digests.digests[0].digest.sha256[i] = (UINT8)(i % 256);
}
pcr_selection.count = 1;
pcr_selection.pcrSelections[0].hash = TPM2_ALG_SHA1;
pcr_selection.pcrSelections[0].hash = TPM2_ALG_SHA256;
pcr_selection.pcrSelections[0].sizeofSelect = 3;
pcr_selection.pcrSelections[0].pcrSelect[0] = 0;
pcr_selection.pcrSelections[0].pcrSelect[1] = 0;
Expand All @@ -77,6 +78,11 @@ test_invoke (TSS2_SYS_CONTEXT *sys_context)
LOG_ERROR("PCR_Read FAILED! Response Code : 0x%x", rc);
exit(1);
}
if (!pcr_selection_out.pcrSelections[0].pcrSelect[PCR_8 / 8]) {
LOG_ERROR("PCR register not supported.");
return(EXIT_SKIP);
}

memcpy(&(pcr_before_extend[0]), &(pcr_values.digests[0].buffer[0]), pcr_values.digests[0].size);

rc = Tss2_Sys_PCR_Extend(sys_context, PCR_8, &sessions_data, &digests, 0);
Expand All @@ -89,13 +95,13 @@ test_invoke (TSS2_SYS_CONTEXT *sys_context)
LOG_ERROR("PCR_Read FAILED! Response Code : 0x%x", rc);
exit(1);
}
memcpy(&(pcr_after_extend[0]), &(pcr_values.digests[0].buffer[0]), pcr_values.digests[0].size);
memcpy(&(pcr_after_extend[0]), &(pcr_values.digests[0].buffer[0]), pcr_values.digests[0].size);

if(pcr_update_counter_before_extend == pcr_update_counter_after_extend) {
LOG_ERROR("ERROR!! pcr_update_counter didn't change value");
exit(1);
}
if(memcmp(&(pcr_before_extend[0]), &(pcr_after_extend[0]), 20) == 0) {
if(memcmp(&(pcr_before_extend[0]), &(pcr_after_extend[0]), TPM2_SHA256_DIGEST_SIZE) == 0) {
LOG_ERROR("ERROR!! PCR didn't change value");
exit(1);
}
Expand Down

0 comments on commit 8d497ad

Please sign in to comment.