63 #define CSEC_PAGE_SIZE_IN_BYTES (16U)
67 #define CSEC_DATA_PAGES_AVAILABLE (7U)
70 #define CSEC_DATA_BYTES_AVAILABLE (112U)
73 #define CSEC_BYTES_TO_FROM_PAGES_SHIFT (4U)
75 #define CSEC_BYTES_TO_FROM_BITS_SHIFT (3U)
78 #define CSEC_M1_SIZE_IN_BYTES (16U)
80 #define CSEC_M2_SIZE_IN_BYTES (32U)
82 #define CSEC_M3_SIZE_IN_BYTES (16U)
84 #define CSEC_M4_SIZE_IN_BYTES (32U)
86 #define CSEC_M5_SIZE_IN_BYTES (16U)
100 const uint8_t * inBuff,
108 return (value + (roundTo - 1U)) & ~(roundTo - 1U);
136 g_csecStatePtr = state;
152 g_csecStatePtr = NULL;
166 const uint8_t * plainText,
168 uint8_t * cipherText)
191 return g_csecStatePtr->
errCode;
203 const uint8_t * cipherText,
227 return g_csecStatePtr->
errCode;
239 const uint8_t * plainText,
242 uint8_t * cipherText)
255 g_csecStatePtr->
iv = iv;
267 return g_csecStatePtr->
errCode;
279 const uint8_t * cipherText,
295 g_csecStatePtr->
iv = iv;
307 return g_csecStatePtr->
errCode;
333 g_csecStatePtr->
msgLen = msgLen;
345 return g_csecStatePtr->
errCode;
420 g_csecStatePtr->
msgLen = msgLen;
423 g_csecStatePtr->
mac = mac;
424 g_csecStatePtr->
macLen = macLen;
436 return g_csecStatePtr->
errCode;
819 uint8_t flavor = (uint8_t)bootFlavor;
981 uint8_t * mpCompress)
994 uint16_t numPagesLeft = msgLen;
997 while (numPagesLeft > 0U)
1020 numPagesLeft = (uint16_t)(numPagesLeft - numPages);
1021 index = (uint32_t)(index + numBytes);
1046 const uint8_t * plainText,
1048 uint8_t * cipherText)
1060 CSEC_HAL_SetInterrupt(
true);
1074 const uint8_t * cipherText,
1076 uint8_t * plainText)
1088 CSEC_HAL_SetInterrupt(
true);
1102 const uint8_t * cipherText,
1105 uint8_t * plainText)
1113 g_csecStatePtr->
iv = iv;
1118 CSEC_HAL_SetInterrupt(
true);
1132 const uint8_t * cipherText,
1135 uint8_t * plainText)
1143 g_csecStatePtr->
iv = iv;
1148 CSEC_HAL_SetInterrupt(
true);
1162 const uint8_t * msg,
1172 g_csecStatePtr->
msgLen = msgLen;
1177 CSEC_HAL_SetInterrupt(
true);
1191 const uint8_t * msg,
1193 const uint8_t * mac,
1203 g_csecStatePtr->
msgLen = msgLen;
1206 g_csecStatePtr->
mac = mac;
1207 g_csecStatePtr->
macLen = macLen;
1212 CSEC_HAL_SetInterrupt(
true);
1229 return g_csecStatePtr->
errCode;
1245 const uint8_t * inBuff,
1250 g_csecStatePtr->
cmd = cmd;
1253 g_csecStatePtr->
keyId = keyId;
1255 g_csecStatePtr->
index = 0U;
1298 CSEC_HAL_SetInterrupt(
false);
1300 if (g_csecStatePtr->
callback != NULL)
1326 g_csecStatePtr->
partSize = numBytes;
1364 g_csecStatePtr->
partSize = numBytes;
1379 uint8_t numBytes = (uint8_t)(((g_csecStatePtr->
fullSize - g_csecStatePtr->
index) >
1387 g_csecStatePtr->
partSize = numBytes;
1402 uint8_t numBytes = (uint8_t)(((g_csecStatePtr->
fullSize - g_csecStatePtr->
index) >
1421 g_csecStatePtr->
partSize = numBytes;
1486 (uint8_t)g_csecStatePtr->
partSize);
1492 (uint8_t)g_csecStatePtr->
partSize);
1600 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 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 CSEC_DATA_PAGES_AVAILABLE
static void CSEC_DRV_ContinueEncDecECBCmd(void)
static void CSEC_DRV_ContinueEncDecCBCCmd(void)
#define CSEC_M3_SIZE_IN_BYTES
#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_HAL_WaitCommandCompletion(void)
Waits for the completion of a CSEc command.
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...
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_PAGE_7_OFFSET
CSE_PRAM offset of page 7.
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
static void CSEC_HAL_WriteCommandHeader(csec_cmd_t funcId, csec_func_format_t funcFormat, csec_call_sequence_t callSeq, csec_key_id_t keyId)
Writes the command header to CSE_PRAM.
START_FUNCTION_DECLARATION_RAMSECTION void CSEC_HAL_WriteCmdAndWait(csec_cmd_t funcId, csec_func_format_t funcFormat, csec_call_sequence_t callSeq, csec_key_id_t keyId) END_FUNCTION_DECLARATION_RAMSECTION static inline void CSEC_HAL_SetInterrupt(bool enable)
Writes the command header to CSE_PRAM and waits for completion.
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 FEATURE_CSEC_PAGE_3_OFFSET
CSE_PRAM offset of page 3.
#define CSEC_BYTES_TO_FROM_BITS_SHIFT
#define FEATURE_CSEC_PAGE_4_OFFSET
CSE_PRAM offset of page 4.
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.
#define FEATURE_CSEC_PAGE_2_OFFSET
CSE_PRAM offset of page 2.
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)
void CSEC_HAL_WriteCommandBytes(uint8_t offset, const uint8_t *bytes, uint8_t numBytes)
Writes command bytes to CSE_PRAM.
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.
#define FEATURE_CSEC_SREG_OFFSET
CSE_PRAM offset of the SREG parameter used by the following commands: CMD_GET_ID. ...
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 (...
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.
csec_cmd_t
CSEc commands which follow the same values as the SHE command definition.
#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.
#define FEATURE_CSEC_PAGE_5_OFFSET
CSE_PRAM offset of page 5.
void CSEC_HAL_ReadCommandBytes(uint8_t offset, uint8_t *bytes, uint8_t numBytes)
Reads command bytes from CSE_PRAM.
void CSEC_HAL_WriteCommandWords(uint8_t offset, const uint32_t *words, uint8_t numWords)
Writes command words to CSE_PRAM.
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.
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.
static status_t CSEC_HAL_ReadErrorBits(void)
Reads the error bits from PRAM.
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)
#define FEATURE_CSEC_FLASH_START_ADDRESS_OFFSET
CSE_PRAM offset of the Flash start address parameter used by the following commands: CMD_GENERATE_MAC...
static void CSEC_DRV_ContinueGenMACCmd(void)
void CSEC_DRV_Deinit()
Clears the internal state of the driver and disables the FTFC interrupt.
uint8_t CSEC_HAL_ReadCommandByte(uint8_t offset)
Reads a command byte from CSE_PRAM.
#define FEATURE_CSEC_PAGE_1_OFFSET
CSE_PRAM offset of page 1.
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.
csec_call_sequence_t
Specifies if the information is the first or a following function call.
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_MAC_LENGTH_OFFSET
CSE_PRAM offset of the MAC length parameter used by the following commands: CMD_VERIFY_MAC (both copy...
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.
void INT_SYS_EnableIRQ(IRQn_Type irqNumber)
Enables an interrupt for a given IRQ number.
#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_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
#define FEATURE_CSEC_BOOT_SIZE_OFFSET
CSE_PRAM offset of the boot size parameter used by the following commands: CMD_BOOT_DEFINE.
void CSEC_HAL_WriteCommandHalfWord(uint8_t offset, uint16_t halfWord)
Writes a command half word to CSE_PRAM.
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.
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.
csec_key_id_t
Specify the KeyID to be used to implement the requested cryptographic operation.
uint16_t CSEC_HAL_ReadCommandHalfWord(uint8_t offset)
Reads a command half word from CSE_PRAM.
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...
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.
void CSEC_HAL_WriteCommandByte(uint8_t offset, uint8_t byte)
Writes a command byte to CSE_PRAM.