20 #include "csec_hw_access.h"
64 #define CSEC_PAGE_SIZE_IN_BYTES (16U)
68 #define CSEC_DATA_PAGES_AVAILABLE (7U)
71 #define CSEC_DATA_BYTES_AVAILABLE (112U)
74 #define CSEC_BYTES_TO_FROM_PAGES_SHIFT (4U)
76 #define CSEC_BYTES_TO_FROM_BITS_SHIFT (3U)
79 #define CSEC_M1_SIZE_IN_BYTES (16U)
81 #define CSEC_M2_SIZE_IN_BYTES (32U)
83 #define CSEC_M3_SIZE_IN_BYTES (16U)
85 #define CSEC_M4_SIZE_IN_BYTES (32U)
87 #define CSEC_M5_SIZE_IN_BYTES (16U)
101 const uint8_t * inBuff,
109 return (value + (roundTo - 1U)) & ~(roundTo - 1U);
137 g_csecStatePtr = state;
153 g_csecStatePtr = NULL;
167 const uint8_t * plainText,
169 uint8_t * cipherText)
187 CSEC_WaitCommandCompletion();
192 return g_csecStatePtr->
errCode;
204 const uint8_t * cipherText,
223 CSEC_WaitCommandCompletion();
228 return g_csecStatePtr->
errCode;
240 const uint8_t * plainText,
243 uint8_t * cipherText)
256 g_csecStatePtr->
iv = iv;
263 CSEC_WaitCommandCompletion();
268 return g_csecStatePtr->
errCode;
280 const uint8_t * cipherText,
296 g_csecStatePtr->
iv = iv;
303 CSEC_WaitCommandCompletion();
308 return g_csecStatePtr->
errCode;
334 g_csecStatePtr->
msgLen = msgLen;
341 CSEC_WaitCommandCompletion();
346 return g_csecStatePtr->
errCode;
383 stat = CSEC_ReadErrorBits();
421 g_csecStatePtr->
msgLen = msgLen;
424 g_csecStatePtr->
mac = mac;
425 g_csecStatePtr->
macLen = macLen;
432 CSEC_WaitCommandCompletion();
437 return g_csecStatePtr->
errCode;
481 stat = CSEC_ReadErrorBits();
531 CSEC_WaitCommandCompletion();
534 stat = CSEC_ReadErrorBits();
573 CSEC_WaitCommandCompletion();
576 stat = CSEC_ReadErrorBits();
615 CSEC_WaitCommandCompletion();
618 stat = CSEC_ReadErrorBits();
656 CSEC_WaitCommandCompletion();
659 stat = CSEC_ReadErrorBits();
695 CSEC_WaitCommandCompletion();
698 stat = CSEC_ReadErrorBits();
730 CSEC_WaitCommandCompletion();
733 stat = CSEC_ReadErrorBits();
767 CSEC_WaitCommandCompletion();
770 stat = CSEC_ReadErrorBits();
799 CSEC_WaitCommandCompletion();
802 stat = CSEC_ReadErrorBits();
820 uint8_t flavor = (uint8_t)bootFlavor;
836 CSEC_WaitCommandCompletion();
839 stat = CSEC_ReadErrorBits();
878 CSEC_WaitCommandCompletion();
881 stat = CSEC_ReadErrorBits();
921 CSEC_WaitCommandCompletion();
924 stat = CSEC_ReadErrorBits();
962 CSEC_WaitCommandCompletion();
965 stat = CSEC_ReadErrorBits();
982 uint8_t * mpCompress)
995 uint16_t numPagesLeft = msgLen;
998 while (numPagesLeft > 0U)
1012 CSEC_WaitCommandCompletion();
1015 stat = CSEC_ReadErrorBits();
1021 numPagesLeft = (uint16_t)(numPagesLeft - numPages);
1022 index = (uint32_t)(index + numBytes);
1047 const uint8_t * plainText,
1049 uint8_t * cipherText)
1061 CSEC_SetInterrupt(
true);
1075 const uint8_t * cipherText,
1077 uint8_t * plainText)
1089 CSEC_SetInterrupt(
true);
1103 const uint8_t * cipherText,
1106 uint8_t * plainText)
1114 g_csecStatePtr->
iv = iv;
1119 CSEC_SetInterrupt(
true);
1133 const uint8_t * cipherText,
1136 uint8_t * plainText)
1144 g_csecStatePtr->
iv = iv;
1149 CSEC_SetInterrupt(
true);
1163 const uint8_t * msg,
1173 g_csecStatePtr->
msgLen = msgLen;
1178 CSEC_SetInterrupt(
true);
1192 const uint8_t * msg,
1194 const uint8_t * mac,
1204 g_csecStatePtr->
msgLen = msgLen;
1207 g_csecStatePtr->
mac = mac;
1208 g_csecStatePtr->
macLen = macLen;
1213 CSEC_SetInterrupt(
true);
1230 return g_csecStatePtr->
errCode;
1246 const uint8_t * inBuff,
1251 g_csecStatePtr->
cmd = cmd;
1254 g_csecStatePtr->
keyId = keyId;
1256 g_csecStatePtr->
index = 0U;
1299 CSEC_SetInterrupt(
false);
1301 if (g_csecStatePtr->
callback != NULL)
1327 g_csecStatePtr->
partSize = numBytes;
1330 CSEC_WriteCommandHeader(g_csecStatePtr->
cmd, CSEC_FUNC_FORMAT_COPY, g_csecStatePtr->
seq, g_csecStatePtr->
keyId);
1365 g_csecStatePtr->
partSize = numBytes;
1368 CSEC_WriteCommandHeader(g_csecStatePtr->
cmd, CSEC_FUNC_FORMAT_COPY, g_csecStatePtr->
seq, g_csecStatePtr->
keyId);
1380 uint8_t numBytes = (uint8_t)(((g_csecStatePtr->
fullSize - g_csecStatePtr->
index) >
1388 g_csecStatePtr->
partSize = numBytes;
1391 CSEC_WriteCommandHeader(g_csecStatePtr->
cmd, CSEC_FUNC_FORMAT_COPY, g_csecStatePtr->
seq, g_csecStatePtr->
keyId);
1403 uint8_t numBytes = (uint8_t)(((g_csecStatePtr->
fullSize - g_csecStatePtr->
index) >
1422 g_csecStatePtr->
partSize = numBytes;
1425 CSEC_WriteCommandHeader(g_csecStatePtr->
cmd, CSEC_FUNC_FORMAT_COPY, g_csecStatePtr->
seq, g_csecStatePtr->
keyId);
1439 g_csecStatePtr->
errCode = CSEC_ReadErrorBits();
1475 g_csecStatePtr->
errCode = CSEC_ReadErrorBits();
1487 (uint8_t)g_csecStatePtr->
partSize);
1493 (uint8_t)g_csecStatePtr->
partSize);
1522 g_csecStatePtr->
errCode = CSEC_ReadErrorBits();
1562 g_csecStatePtr->
errCode = CSEC_ReadErrorBits();
1601 g_csecStatePtr->
callback = callbackFunc;
status_t CSEC_DRV_LoadPlainKey(const uint8_t *plainKey)
Updates the RAM key memory slot with a 128-bit plaintext.
status_t CSEC_DRV_GetAsyncCmdStatus()
Checks the status of the execution of an asynchronous command.
#define CSEC_DATA_PAGES_AVAILABLE
static void CSEC_DRV_ContinueEncDecECBCmd(void)
#define FEATURE_CSEC_BOOT_FLAVOR_OFFSET
CSE_PRAM offset of the boot flavor parameter used by the following commands: CMD_BOOT_DEFINE.
static void CSEC_DRV_ContinueEncDecCBCCmd(void)
#define CSEC_M3_SIZE_IN_BYTES
status_t CSEC_DRV_GetID(const uint8_t *challenge, uint8_t *uid, uint8_t *sreg, uint8_t *mac)
Returns the identity (UID) and the value of the status register protected by a MAC over a challenge a...
#define FEATURE_CSEC_PAGE_2_OFFSET
CSE_PRAM offset of page 2.
Internal driver state information.
static void CSEC_DRV_StartEncDecECBCmd(void)
#define FTFC_FSTAT_CCIF_MASK
#define CSEC_BYTES_TO_FROM_PAGES_SHIFT
#define FEATURE_CSEC_FLASH_START_ADDRESS_OFFSET
CSE_PRAM offset of the Flash start address parameter used by the following commands: CMD_GENERATE_MAC...
void CSEC_DRV_Init(csec_state_t *state)
Initializes the internal state of the driver and enables the FTFC interrupt.
status_t CSEC_DRV_DbgAuth(const uint8_t *authorization)
Erases all keys (actual and outdated) stored in NVM Memory if the authorization is confirmed by CSEc...
status_t CSEC_DRV_VerifyMACAsync(csec_key_id_t keyId, const uint8_t *msg, uint32_t msgLen, const uint8_t *mac, uint16_t macLen, bool *verifStatus)
Asynchronously verifies the MAC of a given message using CMAC with AES-128.
#define CSEC_M1_SIZE_IN_BYTES
csec_key_id_t
Specify the KeyID to be used to implement the requested cryptographic operation.
status_t CSEC_DRV_BootOK()
Marks a successful boot verification during later stages of the boot process.
status_t CSEC_DRV_MPCompress(const uint8_t *msg, uint16_t msgLen, uint8_t *mpCompress)
Compresses the given messages by accessing the Miyaguchi-Prenell compression feature with in the CSEc...
#define CSEC_BYTES_TO_FROM_BITS_SHIFT
status_t CSEC_DRV_VerifyMACAddrMode(csec_key_id_t keyId, const uint8_t *msg, uint32_t msgLen, const uint8_t *mac, uint16_t macLen, bool *verifStatus)
Verifies the MAC of a given message (located in Flash) using CMAC with AES-128.
status_t CSEC_DRV_InitRNG()
Initializes the seed and derives a key for the PRNG.
static void CSEC_DRV_StartVerifMACCmd(void)
void INT_SYS_DisableIRQ(IRQn_Type irqNumber)
Disables an interrupt for a given IRQ number.
#define CSEC_M2_SIZE_IN_BYTES
#define CSEC_DATA_BYTES_AVAILABLE
status_t CSEC_DRV_ExtendSeed(const uint8_t *entropy)
Extends the seed of the PRNG.
static void CSEC_DRV_StartEncDecCBCCmd(void)
status_t CSEC_DRV_BootFailure()
Signals a failure detected during later stages of the boot process.
status_t CSEC_DRV_DecryptECBAsync(csec_key_id_t keyId, const uint8_t *cipherText, uint32_t length, uint8_t *plainText)
Asynchronously performs the AES-128 decryption in ECB mode.
static void CSEC_DRV_InitState(csec_key_id_t keyId, csec_cmd_t cmd, const uint8_t *inBuff, uint8_t *outBuff, uint32_t length)
#define FEATURE_CSEC_VERIFICATION_STATUS_OFFSET
CSE_PRAM offset of the verification status parameter used by the following commands: CMD_VERIFY_MAC (...
#define FEATURE_CSEC_PAGE_3_OFFSET
CSE_PRAM offset of page 3.
status_t CSEC_DRV_EncryptECBAsync(csec_key_id_t keyId, const uint8_t *plainText, uint32_t length, uint8_t *cipherText)
Asynchronously performs the AES-128 encryption in ECB mode.
#define CSEC_PAGE_SIZE_IN_BYTES
void CSEC_DRV_InstallCallback(csec_callback_t callbackFunc, void *callbackParam)
Installs a callback function which will be invoked when an asynchronous command finishes its executio...
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
status_t CSEC_DRV_DecryptCBC(csec_key_id_t keyId, const uint8_t *cipherText, uint16_t length, const uint8_t *iv, uint8_t *plainText)
Performs the AES-128 decryption in CBC mode.
status_t CSEC_DRV_DecryptECB(csec_key_id_t keyId, const uint8_t *cipherText, uint32_t length, uint8_t *plainText)
Performs the AES-128 decryption in ECB mode.
#define FEATURE_CSEC_PAGE_5_OFFSET
CSE_PRAM offset of page 5.
status_t CSEC_DRV_EncryptCBC(csec_key_id_t keyId, const uint8_t *plainText, uint32_t length, const uint8_t *iv, uint8_t *cipherText)
Performs the AES-128 encryption in CBC mode.
status_t CSEC_DRV_GenerateMACAddrMode(csec_key_id_t keyId, const uint8_t *msg, uint32_t msgLen, uint8_t *cmac)
Calculates the MAC of a given message (located in Flash) using CMAC with AES-128. ...
static void CSEC_DRV_ContinueVerifMACCmd(void)
void FTFC_IRQHandler(void)
static void CSEC_DRV_ContinueGenMACCmd(void)
void CSEC_DRV_Deinit()
Clears the internal state of the driver and disables the FTFC interrupt.
#define FEATURE_CSEC_PAGE_LENGTH_OFFSET
CSE_PRAM offset of the page length parameter used by the following commands: CMD_ENC_ECB, CMD_ENC_CBC, CMD_DEC_ECB, CMD_DEC_CBC, CMD_MP_COMPRESS.
status_t CSEC_DRV_LoadKey(csec_key_id_t keyId, const uint8_t *m1, const uint8_t *m2, const uint8_t *m3, uint8_t *m4, uint8_t *m5)
Updates an internal key per the SHE specification.
status_t CSEC_DRV_EncryptECB(csec_key_id_t keyId, const uint8_t *plainText, uint32_t length, uint8_t *cipherText)
Performs the AES-128 encryption in ECB mode.
#define FEATURE_CSEC_BOOT_SIZE_OFFSET
CSE_PRAM offset of the boot size parameter used by the following commands: CMD_BOOT_DEFINE.
#define FEATURE_CSEC_PAGE_7_OFFSET
CSE_PRAM offset of page 7.
csec_boot_flavor_t
Specifies the boot type for the BOOT_DEFINE command.
status_t CSEC_DRV_DecryptCBCAsync(csec_key_id_t keyId, const uint8_t *cipherText, uint32_t length, const uint8_t *iv, uint8_t *plainText)
Asynchronously performs the AES-128 decryption in CBC mode.
csec_call_sequence_t
Specifies if the information is the first or a following function call.
void INT_SYS_EnableIRQ(IRQn_Type irqNumber)
Enables an interrupt for a given IRQ number.
csec_cmd_t
CSEc commands which follow the same values as the SHE command definition.
#define FEATURE_CSEC_PAGE_1_OFFSET
CSE_PRAM offset of page 1.
#define FEATURE_CSEC_PAGE_4_OFFSET
CSE_PRAM offset of page 4.
status_t CSEC_DRV_ExportRAMKey(uint8_t *m1, uint8_t *m2, uint8_t *m3, uint8_t *m4, uint8_t *m5)
Exports the RAM_KEY into a format protected by SECRET_KEY.
status_t CSEC_DRV_GenerateRND(uint8_t *rnd)
Generates a vector of 128 random bits.
status_t CSEC_DRV_EncryptCBCAsync(csec_key_id_t keyId, const uint8_t *cipherText, uint16_t length, const uint8_t *iv, uint8_t *plainText)
Asynchronously performs the AES-128 encryption in CBC mode.
#define CSEC_M4_SIZE_IN_BYTES
static uint32_t CSEC_DRV_RoundTo(uint32_t value, uint32_t roundTo)
const uint8_t * inputBuff
status_t CSEC_DRV_DbgChal(uint8_t *challenge)
Obtains a random number which the user shall use along with the MASTER_ECU_KEY and UID to return an a...
void(* csec_callback_t)(csec_cmd_t completedCmd, void *callbackParam)
CSEc asynchronous command complete callback function type.
#define FEATURE_CSEC_MESSAGE_LENGTH_OFFSET
CSE_PRAM offset of the message length parameter used by the following commands: CMD_GENERATE_MAC, CMD_VERIFY_MAC (both copy and pointer methods)
#define FEATURE_CSEC_MAC_LENGTH_OFFSET
CSE_PRAM offset of the MAC length parameter used by the following commands: CMD_VERIFY_MAC (both copy...
static csec_state_t * g_csecStatePtr
static void CSEC_DRV_StartGenMACCmd(void)
status_t CSEC_DRV_GenerateMAC(csec_key_id_t keyId, const uint8_t *msg, uint32_t msgLen, uint8_t *cmac)
Calculates the MAC of a given message using CMAC with AES-128.
status_t CSEC_DRV_VerifyMAC(csec_key_id_t keyId, const uint8_t *msg, uint32_t msgLen, const uint8_t *mac, uint16_t macLen, bool *verifStatus)
Verifies the MAC of a given message using CMAC with AES-128.
#define CSEC_M5_SIZE_IN_BYTES
status_t CSEC_DRV_BootDefine(uint32_t bootSize, csec_boot_flavor_t bootFlavor)
Implements an extension of the SHE standard to define both the user boot size and boot method...
#define FEATURE_CSEC_SREG_OFFSET
CSE_PRAM offset of the SREG parameter used by the following commands: CMD_GET_ID. ...
status_t CSEC_DRV_GenerateMACAsync(csec_key_id_t keyId, const uint8_t *msg, uint32_t msgLen, uint8_t *cmac)
Asynchronously calculates the MAC of a given message using CMAC with AES-128.