S32 SDK
csec_hal.h File Reference
#include <stdint.h>
#include <stdbool.h>
#include "device_registers.h"
#include <stddef.h>
#include "status.h"

Go to the source code of this file.

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...
 
#define CSEC_NO_ERROR   0x1U
 Represents the result of the execution of a command. Provides one bit for each error code as per SHE specification. More...
 
#define CSEC_SEQUENCE_ERROR   0x2U
 
#define CSEC_KEY_NOT_AVAILABLE   0x4U
 
#define CSEC_KEY_INVALID   0x8U
 
#define CSEC_KEY_EMPTY   0x10U
 
#define CSEC_NO_SECURE_BOOT   0x20U
 
#define CSEC_KEY_WRITE_PROTECTED   0x40U
 
#define CSEC_KEY_UPDATE_ERROR   0x80U
 
#define CSEC_RNG_SEED   0x100U
 
#define CSEC_NO_DEBUGGING   0x200U
 
#define CSEC_MEMORY_FAILURE   0x400U
 
#define CSEC_GENERAL_ERROR   0x800U
 

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_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_TRNG_RND,
  CSEC_CMD_RESERVED_2, CSEC_CMD_MP_COMPRESS
}
 CSEc commands which follow the same values as the SHE command definition. More...
 
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, CSEC_KEY_18, CSEC_KEY_19,
  CSEC_KEY_20, CSEC_KEY_21
}
 Specify the KeyID to be used to implement the requested cryptographic operation. More...
 
enum  csec_func_format_t { CSEC_FUNC_FORMAT_COPY, CSEC_FUNC_FORMAT_ADDR }
 Specifies how the data is transferred to/from the CSE. There are two use cases. One is to copy all data and the command function call method and the other is a pointer and function call method. 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...
 

Functions

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. More...
 
void CSEC_HAL_WriteCommandBytes (uint8_t offset, const uint8_t *bytes, uint8_t numBytes)
 Writes command bytes to CSE_PRAM. More...
 
void CSEC_HAL_WriteCommandHalfWord (uint8_t offset, uint16_t halfWord)
 Writes a command half word to CSE_PRAM. More...
 
void CSEC_HAL_WriteCommandByte (uint8_t offset, uint8_t byte)
 Writes a command byte to CSE_PRAM. More...
 
void CSEC_HAL_WriteCommandWords (uint8_t offset, const uint32_t *words, uint8_t numWords)
 Writes command words to CSE_PRAM. More...
 
void CSEC_HAL_ReadCommandBytes (uint8_t offset, uint8_t *bytes, uint8_t numBytes)
 Reads command bytes from CSE_PRAM. More...
 
uint16_t CSEC_HAL_ReadCommandHalfWord (uint8_t offset)
 Reads a command half word from CSE_PRAM. More...
 
uint8_t CSEC_HAL_ReadCommandByte (uint8_t offset)
 Reads a command byte from CSE_PRAM. More...
 
void CSEC_HAL_ReadCommandWords (uint8_t offset, uint32_t *words, uint8_t numWords)
 Reads command words from CSE_PRAM. More...
 
static void CSEC_HAL_WaitCommandCompletion (void)
 Waits for the completion of a CSEc command. More...
 
static status_t CSEC_HAL_ReadErrorBits (void)
 Reads the error bits from PRAM. More...
 
static csec_status_t CSEC_HAL_ReadStatus (void)
 Reads the status of the CSEc module. More...
 
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. More...