csec_driver.h File Reference
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include "device_registers.h"
#include "interrupt_manager.h"
#include "status.h"
#include "callbacks.h"

Go to the source code of this file.

Data Structures

struct  csec_state_t
 Internal driver state information. More...
 

Macros

#define CSEC_STATUS_BUSY   (0x1U)
 The bit is set whenever SHE is processing a command. More...
 
#define CSEC_STATUS_SECURE_BOOT   (0x2U)
 The bit is set if the secure booting is activated. More...
 
#define CSEC_STATUS_BOOT_INIT   (0x4U)
 The bit is set if the secure booting has been personalized during the boot sequence. More...
 
#define CSEC_STATUS_BOOT_FINISHED   (0x8U)
 The bit is set when the secure booting has been finished by calling either CMD_BOOT_FAILURE or CMD_BOOT_OK or if CMD_SECURE_BOOT failed in verifying BOOT_MAC. More...
 
#define CSEC_STATUS_BOOT_OK   (0x10U)
 The bit is set if the secure booting (CMD_SECURE_BOOT) succeeded. If CMD_BOOT_FAILURE is called the bit is erased. More...
 
#define CSEC_STATUS_RND_INIT   (0x20U)
 The bit is set if the random number generator has been initialized. More...
 
#define CSEC_STATUS_EXT_DEBUGGER   (0x40U)
 The bit is set if an external debugger is connected to the chip. More...
 
#define CSEC_STATUS_INT_DEBUGGER   (0x80U)
 The bit is set if the internal debugging mechanisms of SHE are activated. More...
 

Typedefs

typedef uint8_t csec_status_t
 Represents the status of the CSEc module. Provides one bit for each status code as per SHE specification. CSEC_STATUS_* masks can be used for verifying the status. More...
 

Enumerations

enum  csec_key_id_t {
  CSEC_SECRET_KEY = 0x0U, CSEC_MASTER_ECU, CSEC_BOOT_MAC_KEY, CSEC_BOOT_MAC,
  CSEC_KEY_1, CSEC_KEY_2, CSEC_KEY_3, CSEC_KEY_4,
  CSEC_KEY_5, CSEC_KEY_6, CSEC_KEY_7, CSEC_KEY_8,
  CSEC_KEY_9, CSEC_KEY_10, CSEC_RAM_KEY = 0xFU, CSEC_KEY_11 = 0x14U,
  CSEC_KEY_12, CSEC_KEY_13, CSEC_KEY_14, CSEC_KEY_15,
  CSEC_KEY_16, CSEC_KEY_17
}
 Specify the KeyID to be used to implement the requested cryptographic operation. More...
 
enum  csec_cmd_t {
  CSEC_CMD_ENC_ECB = 0x1U, CSEC_CMD_ENC_CBC, CSEC_CMD_DEC_ECB, CSEC_CMD_DEC_CBC,
  CSEC_CMD_GENERATE_MAC, CSEC_CMD_VERIFY_MAC, CSEC_CMD_LOAD_KEY, CSEC_CMD_LOAD_PLAIN_KEY,
  CSEC_CMD_EXPORT_RAM_KEY, CSEC_CMD_INIT_RNG, CSEC_CMD_EXTEND_SEED, CSEC_CMD_RND,
  CSEC_CMD_RESERVED_1, CSEC_CMD_BOOT_FAILURE, CSEC_CMD_BOOT_OK, CSEC_CMD_GET_ID,
  CSEC_CMD_BOOT_DEFINE, CSEC_CMD_DBG_CHAL, CSEC_CMD_DBG_AUTH, CSEC_CMD_RESERVED_2,
  CSEC_CMD_RESERVED_3, CSEC_CMD_MP_COMPRESS
}
 CSEc commands which follow the same values as the SHE command definition. More...
 
enum  csec_call_sequence_t { CSEC_CALL_SEQ_FIRST, CSEC_CALL_SEQ_SUBSEQUENT }
 Specifies if the information is the first or a following function call. More...
 
enum  csec_boot_flavor_t { CSEC_BOOT_STRICT, CSEC_BOOT_SERIAL, CSEC_BOOT_PARALLEL, CSEC_BOOT_NOT_DEFINED }
 Specifies the boot type for the BOOT_DEFINE command. More...
 

Functions

void CSEC_DRV_Init (csec_state_t *state)
 Initializes the internal state of the driver and enables the FTFC interrupt. More...
 
void CSEC_DRV_Deinit (void)
 Clears the internal state of the driver and disables the FTFC interrupt. More...
 
status_t CSEC_DRV_EncryptECB (csec_key_id_t keyId, const uint8_t *plainText, uint32_t length, uint8_t *cipherText, uint32_t timeout)
 Performs the AES-128 encryption in ECB mode. More...
 
status_t CSEC_DRV_DecryptECB (csec_key_id_t keyId, const uint8_t *cipherText, uint32_t length, uint8_t *plainText, uint32_t timeout)
 Performs the AES-128 decryption in ECB mode. More...
 
status_t CSEC_DRV_EncryptCBC (csec_key_id_t keyId, const uint8_t *plainText, uint32_t length, const uint8_t *iv, uint8_t *cipherText, uint32_t timeout)
 Performs the AES-128 encryption in CBC mode. More...
 
status_t CSEC_DRV_DecryptCBC (csec_key_id_t keyId, const uint8_t *cipherText, uint32_t length, const uint8_t *iv, uint8_t *plainText, uint32_t timeout)
 Performs the AES-128 decryption in CBC mode. More...
 
status_t CSEC_DRV_GenerateMAC (csec_key_id_t keyId, const uint8_t *msg, uint32_t msgLen, uint8_t *cmac, uint32_t timeout)
 Calculates the MAC of a given message using CMAC with AES-128. More...
 
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. More...
 
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, uint32_t timeout)
 Verifies the MAC of a given message using CMAC with AES-128. More...
 
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. More...
 
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. More...
 
status_t CSEC_DRV_LoadPlainKey (const uint8_t *plainKey)
 Updates the RAM key memory slot with a 128-bit plaintext. More...
 
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. More...
 
status_t CSEC_DRV_InitRNG (void)
 Initializes the seed and derives a key for the PRNG. More...
 
status_t CSEC_DRV_ExtendSeed (const uint8_t *entropy)
 Extends the seed of the PRNG. More...
 
status_t CSEC_DRV_GenerateRND (uint8_t *rnd)
 Generates a vector of 128 random bits. More...
 
status_t CSEC_DRV_BootFailure (void)
 Signals a failure detected during later stages of the boot process. More...
 
status_t CSEC_DRV_BootOK (void)
 Marks a successful boot verification during later stages of the boot process. More...
 
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. More...
 
static csec_status_t CSEC_DRV_GetStatus (void)
 Returns the content of the status register. More...
 
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 and the data. More...
 
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 authorization request. More...
 
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. More...
 
status_t CSEC_DRV_MPCompress (const uint8_t *msg, uint16_t msgLen, uint8_t *mpCompress, uint32_t timeout)
 Compresses the given messages by accessing the Miyaguchi-Prenell compression feature with in the CSEc feature set. More...
 
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. More...
 
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. More...
 
status_t CSEC_DRV_EncryptCBCAsync (csec_key_id_t keyId, const uint8_t *plainText, uint32_t length, const uint8_t *iv, uint8_t *cipherText)
 Asynchronously performs the AES-128 encryption in CBC mode. More...
 
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. More...
 
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. More...
 
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. More...
 
status_t CSEC_DRV_GetAsyncCmdStatus (void)
 Checks the status of the execution of an asynchronous command. More...
 
void CSEC_DRV_InstallCallback (security_callback_t callbackFunc, void *callbackParam)
 Installs a callback function which will be invoked when an asynchronous command finishes its execution. More...
 
void CSEC_DRV_CancelCommand (void)
 Cancels a previously launched asynchronous command. More...