FUNC(Std_ReturnType, DCM_APPL_CODE) App_GetSeed(
P2CONST(Dcm_SecLevelType, AUTOMATIC, DCM_APPL_CONST) SecurityLevel,
P2CONST(uint8, AUTOMATIC, DCM_APPL_DATA) SeedLen,
P2VAR(uint8, AUTOMATIC, DCM_APPL_DATA) Seed,
P2VAR(uint8, AUTOMATIC, DCM_APPL_DATA) ErrorCode)
{
static uint32 storedSeed;
storedSeed = GetCryptoRandomSeed(); /* Hardware RNG or TRNG */
Seed[0] = (uint8)(storedSeed >> 24);
Seed[1] = (uint8)(storedSeed >> 16);
Seed[2] = (uint8)(storedSeed >> 8);
Seed[3] = (uint8)(storedSeed);
return E_OK;
}
FUNC(Std_ReturnType, DCM_APPL_CODE) App_CompareKey(
P2CONST(uint8, AUTOMATIC, DCM_APPL_DATA) Key,
P2CONST(Dcm_SecLevelType, AUTOMATIC, DCM_APPL_CONST) SecurityLevel,
P2VAR(uint8, AUTOMATIC, DCM_APPL_DATA) ErrorCode)
{
uint32 rx = ((uint32)Key[0]<<24)|((uint32)Key[1]<<16)|
((uint32)Key[2]<<8)|(uint32)Key[3];
if (rx == DeriveExpectedKey(storedSeed)) return E_OK;
*ErrorCode = DCM_E_REQUIREDTIMEDELAYNOTEXPIRED;
return E_NOT_OK; /* NRC 0x35 */
}