Sync: Implement platform function to determine enabled self tests

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2025-08-08 07:27:13 -04:00 committed by Stefan Berger
parent ea44b01eb4
commit 6d04f7c7ba
5 changed files with 51 additions and 4 deletions

View File

@ -283,6 +283,7 @@ libtpms_tpm2_la_SOURCES = \
tpm2/ResponseCodeProcessing.c \
tpm2/RunCommand.c \
tpm2/SecChannel.c \
tpm2/SelfTest.c \
tpm2/Session.c \
tpm2/SessionCommands.c \
tpm2/SessionProcess.c \

View File

@ -800,7 +800,7 @@ TestAlgorithm(TPM_ALG_ID alg, ALGORITHM_VECTOR* toTest)
// silently CLEAR it. Decided to just clear.
if(!TEST_BIT(alg, g_implementedAlgorithms))
{
CLEAR_BIT(alg, *toTest);
CLEAR_BOTH(alg);
continue;
}
// Process whatever is left.
@ -934,7 +934,7 @@ TestAlgorithm(TPM_ALG_ID alg, ALGORITHM_VECTOR* toTest)
break;
# endif // ALG_ECC
default:
CLEAR_BIT(alg, *toTest);
CLEAR_BOTH(alg);
break;
}
if(result != TPM_RC_SUCCESS)

View File

@ -58,7 +58,7 @@ TPM_RC
CryptSelfTest(TPMI_YES_NO fullTest // IN: if full test is required
)
{
ALGORITHM_VECTOR toTestVector = {0};
// If the caller requested a full test, then reset the to test vector so that
// all the tests will be run
@ -66,7 +66,21 @@ CryptSelfTest(TPMI_YES_NO fullTest // IN: if full test is required
{
MemoryCopy(g_toTest, g_implementedAlgorithms, sizeof(g_toTest));
}
return CryptRunSelfTests(&g_toTest);
// Some platforms may have alternative crypto libraries and self-test capabilities,
// so allow the platform to return the list of tests it wants the TPM code to run
// directly. We assume the platform will make alternative arrangements for any
// tests it does not return here, consistent with that platform's compliance goals.
//
// A platform may provide different lists at different times and we leave the
// g_toTest flags set for any tests that are not requested by the platform.
//
// Note that a crypto library may also perform additional self-tests through other
// means and/or in response to g_toTest at other points in the code.
MemoryCopy(toTestVector, g_toTest, sizeof(toTestVector));
_plat_GetEnabledSelfTest(fullTest, toTestVector, sizeof(toTestVector));
return CryptRunSelfTests(&toTestVector);
}
//*** CryptIncrementalSelfTest()

16
src/tpm2/SelfTest.c Normal file
View File

@ -0,0 +1,16 @@
// SPDX-License-Identifier: BSD-2-Clause
#include "Platform.h"
#include "TpmAlgorithmDefines.h"
#include "TpmTypes.h"
LIB_EXPORT void _plat_GetEnabledSelfTest(
uint8_t fullTest, // IN: full test or not
uint8_t* pToTestVector, // INOUT: initialized byte array of tracked tests
size_t toTestVectorSize // IN: size of the byte array in bytes
)
{
(void)fullTest;
(void)pToTestVector;
(void)toTestVectorSize;
}

View File

@ -377,6 +377,22 @@ typedef struct _spec_capability_value
// return info on TPM and Platform Specific capability values.
LIB_EXPORT void _plat_GetSpecCapabilityValue(SPEC_CAPABILITY_VALUE* returnData);
// Return enabled self-tests on the platform when TPM SelfTest is called.
//
// pToTestVector is a byte array allocated by the TPM library, each bit in the array
// represents a TPM_ALG_ID to be tested. The bit length of the vector is
// (8 * toTestVectorSize), which is larger than or equal to TPM_ALG_LAST + 1.
//
// Initially the vector have bits set for all implemented algorithms or remaining
// algorithms to test, based on fullTest option, and platform should update the vector
// to indicate which tests are actually enabled on the platform based on the its
// capabilities at the time of the call.
LIB_EXPORT void _plat_GetEnabledSelfTest(
uint8_t fullTest, // IN: full test or not
uint8_t* pToTestVector, // INOUT: initialized byte array of tracked tests
size_t toTestVectorSize // IN: size of the byte array in bytes
);
// return the TPM Firmware's current SVN.
LIB_EXPORT uint16_t _plat__GetTpmFirmwareSvn(void);