/**
*   @file    Crypto_Cse_Types.h
*
*   @version 1.0.0
*
*   @brief   AUTOSAR Crypto - Crypto CSE Types.
*   @details Contains the Crypto CSE Types that are exported
*
*   @addtogroup Crypto
*   @{
*/
/*==================================================================================================
*   Project              : AUTOSAR 4.3 MCAL
*   Platform             : PA
*   Peripheral           : Crypto
*   Dependencies         : none
*
*   Autosar Version      : 4.3.1
*   Autosar Revision     : ASR_REL_4_3_REV_0001
*   Autosar Conf.Variant :
*   SW Version           : 1.0.0
*   Build Version        : MPC5777C_MCAL_1_0_0_RTM_ASR_REL_4_3_REV_0001_20190315
*
*   (c) Copyright 2006-2016 Freescale Semiconductor, Inc. 
*       Copyright 2017-2019 NXP
*   All Rights Reserved.
==================================================================================================*/
/*==================================================================================================
==================================================================================================*/

#ifndef CRYPTO_CSETYPES_H
#define CRYPTO_CSETYPES_H

#ifdef __cplusplus
extern "C"{
#endif

/**
* @page misra_violations MISRA-C:2004 violations
*
* @section [global]
*          Violates MISRA 2004 Required Rule 5.1, Identifiers (internal and external) shall not rely 
*          on the significance of more than 31 characters. The used compilers use more than 31 chars 
*          for identifiers.
*/

/*==================================================================================================
*                                        INCLUDE FILES
* 1) system and project includes
* 2) needed interfaces from external units
* 3) internal and external interfaces from this unit
==================================================================================================*/
#include "Std_Types.h"
#include "Crypto_Cfg.h"

/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================*/
#define CRYPTO_CSETYPES_H_VENDOR_ID                    43
#define CRYPTO_CSETYPES_H_AR_RELEASE_MAJOR_VERSION     4
#define CRYPTO_CSETYPES_H_AR_RELEASE_MINOR_VERSION     3
#define CRYPTO_CSETYPES_H_AR_RELEASE_REVISION_VERSION  1
#define CRYPTO_CSETYPES_H_SW_MAJOR_VERSION             1
#define CRYPTO_CSETYPES_H_SW_MINOR_VERSION             0
#define CRYPTO_CSETYPES_H_SW_PATCH_VERSION             0

/*==================================================================================================
*                                     FILE VERSION CHECKS
==================================================================================================*/
/* Check if Crypto_Cse_Types header file and Crypto configuration header file are of the same vendor */
#if (CRYPTO_CSETYPES_H_VENDOR_ID != CRYPTO_VENDOR_ID_CFG)
    #error "Crypto_Cse_Types.h and Crypto_Cfg.h have different vendor ids"
#endif

/* Check if Crypto_Cse_Types header file and Crypto configuration header file are of the same Autosar version */
#if ((CRYPTO_CSETYPES_H_AR_RELEASE_MAJOR_VERSION    != CRYPTO_AR_RELEASE_MAJOR_VERSION_CFG) || \
     (CRYPTO_CSETYPES_H_AR_RELEASE_MINOR_VERSION    != CRYPTO_AR_RELEASE_MINOR_VERSION_CFG) || \
     (CRYPTO_CSETYPES_H_AR_RELEASE_REVISION_VERSION != CRYPTO_AR_RELEASE_REVISION_VERSION_CFG) \
    )
    #error "AutoSar Version Numbers of Crypto_Cse_Types.h and Crypto_Cfg.h are different"
#endif

/* Check if Crypto_Cse_Types header file and Crypto configuration header file are of the same Software version */
#if ((CRYPTO_CSETYPES_H_SW_MAJOR_VERSION != CRYPTO_SW_MAJOR_VERSION_CFG) || \
     (CRYPTO_CSETYPES_H_SW_MINOR_VERSION != CRYPTO_SW_MINOR_VERSION_CFG) || \
     (CRYPTO_CSETYPES_H_SW_PATCH_VERSION != CRYPTO_SW_PATCH_VERSION_CFG) \
    )
    #error "Software Version Numbers of Crypto_Cse_Types.h and Crypto_Cfg.h are different"
#endif

#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
    /* Check if the files Crypto_Cse_Types.h and Std_Types.h are of the same version */
   #if ((CRYPTO_CSETYPES_H_AR_RELEASE_MAJOR_VERSION != STD_AR_RELEASE_MAJOR_VERSION) || \
        (CRYPTO_CSETYPES_H_AR_RELEASE_MINOR_VERSION != STD_AR_RELEASE_MINOR_VERSION)    \
       )
       #error "AutoSar Version Numbers of Crypto_Cse_Types.h and Std_Types.h are different"
   #endif
#endif

/*==================================================================================================
*                                          CONSTANTS
==================================================================================================*/

/*==================================================================================================
*                                      DEFINES AND MACROS
==================================================================================================*/

/*==================================================================================================
*                                             ENUMS
==================================================================================================*/
/**
* @brief          Cse_CmdType.
* @details        These are the CSE commands; they follow the same values as the SHE command definition.
*/
typedef enum
{
    CSE_CMD_ENC_ECB             = 0x01,         /**< @brief AES-128 encryption in ECB mode */
    CSE_CMD_ENC_CBC             = 0x02,         /**< @brief AES-128 encryption in CBC mode */
    CSE_CMD_DEC_ECB             = 0x03,         /**< @brief AES-128 decryption in ECB mode */
    CSE_CMD_DEC_CBC             = 0x04,         /**< @brief AES-128 decryption in CBC mode */
    CSE_CMD_GENERATE_MAC        = 0x05,         /**< @brief AES-128 based CMAC generation */
    CSE_CMD_VERIFY_MAC          = 0x06,         /**< @brief AES-128 based CMAC verification */
    CSE_CMD_LOAD_KEY            = 0x07,         /**< @brief Internal key update */
    CSE_CMD_LOAD_PLAIN_KEY      = 0x08,         /**< @brief RAM key update */
    CSE_CMD_EXPORT_RAM_KEY      = 0x09,         /**< @brief RAM key export */
    CSE_CMD_INIT_RNG            = 0x0A,         /**< @brief PRNG initialization */
    CSE_CMD_EXTEND_SEED         = 0x0B,         /**< @brief PRNG seed entropy extension */
    CSE_CMD_RND                 = 0x0C,         /**< @brief Random number generation */
    CSE_CMD_SECURE_BOOT         = 0x0D,         /**< @brief RESERVED */
    CSE_CMD_BOOT_FAILURE        = 0x0E,         /**< @brief Imporse sanction during invalid boot */
    CSE_CMD_BOOT_OK             = 0x0F,         /**< @brief Finish boot verification */
    CSE_CMD_GET_ID              = 0x10,         /**< @brief Get UID */
    CSE_CMD_CANCEL              = 0x11,         /**< @brief Secure boot configuration */
    CSE_CMD_DBG_CHAL            = 0x12,         /**< @brief Get debug challenge */
    CSE_CMD_DBG_AUTH            = 0x13,         /**< @brief Debug authentication */
    CSE_CMD_TRNG_RND            = 0x14,         /**< @brief Generate TRNG Random Number */
    CSE_CMD_INIT_CSE            = 0x15,         /**< @brief RESERVED */
    CSE_CMD_MP_COMPRESS         = 0x16,         /**< @brief Miyaguchi-Preneel compression */
    CSE_CMD_CFG_SEC_CNT         = 0x16,         /**< @brief Configure Secure Counter */
    CSE_CMD_BRCS                = 0x17,         /**< @brief Backup Restore Cleanup Status */
    CSE_CMD_LOAD_PT_KEY         = 0x18,         /**< @brief Load a plaintext key into NVM */
    CSE_CMD_DELETE_PT_KEY       = 0x19,         /**< @brief Clears plaintext key from RAM */
    CSE_CMD_GENERATE_MAC_SC     = 0x1A,         /**< @brief Generate CMAC and update secure counter */
    CSE_CMD_INSTALL_CERTIFICATE = 0x1B,         /**< @brief Command authenticates a public key */
    CSE_CMD_UPDATE_FIRMWARE     = 0x1C,         /**< @brief Update Firmware */
    CSE_CMD_VERIFY_SIGNATURE    = 0x1D,         /**< @brief Verify Signature */
    CSE_CMD_SHA_256_HASH        = 0x1E,         /**< @brief SHA-256 Hash */
    CSE_CMD_VERIFY_MAC_SC       = 0x1F          /**< @brief Verify CMAC with secure counter */
} Cse_CmdType;

/**
* @brief          Cse_ErrorCodeType.
* @details        This type defines a predefined bitfield. The bitfield provides one bit for each error code,
*                 as per SHE specification.
*/
typedef enum
{
    CSE_ERC_NO_ERROR                           = 0x00,  
    CSE_ERC_GENERAL_ERROR                      = 0x01,
    CSE_ERC_SEQUENCE_ERROR                     = 0x02,  
    CSE_ERC_KEY_NOT_AVAILABLE                  = 0x03,  
    CSE_ERC_KEY_INVALID                        = 0x04,  
    CSE_ERC_KEY_EMPTY                          = 0x05,  
    CSE_ERC_NO_SECURE_BOOT                     = 0x06,  
    CSE_ERC_KEY_WRITE_PROTECTED                = 0x07,  
    CSE_ERC_KEY_UPDATE_ERROR                   = 0x08,  
    CSE_ERC_RNG_SEED                           = 0x09,  
    CSE_ERC_NO_DEBUGGING                       = 0x0A,  
    CSE_ERC_BUSY                               = 0x0B,  
    CSE_ERC_SYSTEM_MEMMORY                     = 0x0C,  
    CSE_ERC_MEMORY_FAILURE                     = 0x10,
    CSE_ERC_INVALID_CMD                        = 0x11,
    CSE_ERC_TRNG                               = 0x12,
    CSE_ERC_FLASH_BLOCK                        = 0x13,
    CSE_ERC_INTERNAL_CMD_PROCESSOR             = 0x14,
    CSE_ERC_LENGTH                             = 0x15,
    CSE_CMD_TIMEOUT                            = 0x80,
    CSE_ERC_NOT_SUPPORTED                      = 0x81,
    CSE_ERC_NULL_POINTER                       = 0x82
} Cse_ErrorCodeType;

/**
* @brief          Cse_KeyIdType.
* @details        This type specifies the key slot used to implement a requested cryptographic operation.
*/
typedef enum
{
    CSE_SECRET_KEY      = 0x00,        /**< @brief Unique secret key */
    CSE_MASTER_ECU      = 0x01,        /**< @brief Used for updating other memory slots */
    CSE_BOOT_MAC_KEY    = 0x02,        /**< @brief Used by the secure booting mechanism to verify the authenticity of the software */
    CSE_BOOT_MAC        = 0x03,        /**< @brief Stores the MAC of the Bootloader for the secure booting mechanism */
    CSE_KEY_1           = 0x04,        /**< @brief User key 1, please see reference manual for more details */
    CSE_KEY_2           = 0x05,        /**< @brief User key 2, please see reference manual for more details */
    CSE_KEY_3           = 0x06,        /**< @brief User key 3 */
    CSE_KEY_4           = 0x07,        /**< @brief User key 4 */
    CSE_KEY_5           = 0x08,        /**< @brief User key 5 */
    CSE_KEY_6           = 0x09,        /**< @brief User key 6 */
    CSE_KEY_7           = 0x0A,        /**< @brief User key 7 */
    CSE_KEY_8           = 0x0B,        /**< @brief User key 8 */
    CSE_KEY_9           = 0x0C,        /**< @brief User key 9 */
    CSE_KEY_10          = 0x0D,        /**< @brief User key 10 */
    CSE_RAM_KEY         = 0x0E,        /**< @brief A volatile key that can be used for arbitrary operations */
    CSE_KEY_11          = 0x14,        /**< @brief User key 11 */
    CSE_KEY_12          = 0x15,        /**< @brief User key 12 */
    CSE_KEY_13          = 0x16,        /**< @brief User key 13 */
    CSE_KEY_14          = 0x17,        /**< @brief User key 14 */
    CSE_KEY_15          = 0x18,        /**< @brief User key 15 */
    CSE_KEY_16          = 0x19,        /**< @brief User key 16 */
    CSE_KEY_17          = 0x1A,        /**< @brief User key 17 */
    CSE_KEY_18          = 0x1B,        /**< @brief User key 18 */
    CSE_KEY_19          = 0x1C,        /**< @brief User key 19 */
    CSE_KEY_20          = 0x1D         /**< @brief User key 20 */
} Cse_KeyHandleType;

/**
* @brief          Cse_KeSecFlags.
* @details        The memory slot security flags for a specified key are checked against the associated bits in the CSE_SR 
*                 during command processing as described in the SHE specification..
*/
typedef enum
{
    WILDCARD    = 0x01,     /**< @brief If set, the memory slot key cannot be used by the GENERATE_MAC command, only by the VERIFY_MAC command. This bit has no effect if KEY_USAGE = 0.*/
    KEY_USAGE   = 0x02,     /**< @brief If set, the memory slot cannot be updated. */
    DEBUG_PROT  = 0x04,     /**< @brief If set, the memory slot is disabled if CSE_SR[BOK] = 0 or CSE_SR[BFN] = 0.*/
    BOOT_PROT   = 0x08,     /**< @brief If set, the memory slot is disabled if CSE_SR[EDB] = 1. */
    WRITE_PROT  = 0x10,     /**< @brief If set, the memory slot holds a MAC key; otherwise, it holds an encryption key.*/
    VERIFY_ONLY = 0x20      /**< @brief If set, the memory slot cannot be updated with the wildcard UID. */
}Cse_KeSecFlags;

/**
* @brief          Cse_CounterId.
* @details        This type specifies the id of the secure counter used in the requested cryptographic operation.
*/
typedef enum
{
    CSE_COUNTER_ID_00   = 0X00,     /**< Counter Id 0  */
    CSE_COUNTER_ID_01   = 0X01,     /**< Counter Id 1  */
    CSE_COUNTER_ID_02   = 0X02,     /**< Counter Id 2  */
    CSE_COUNTER_ID_03   = 0X03,     /**< Counter Id 3  */
    CSE_COUNTER_ID_04   = 0X04,     /**< Counter Id 4  */
    CSE_COUNTER_ID_05   = 0X05,     /**< Counter Id 5  */
    CSE_COUNTER_ID_06   = 0X06,     /**< Counter Id 6  */
    CSE_COUNTER_ID_07   = 0X07,     /**< Counter Id 7  */
    CSE_COUNTER_ID_08   = 0X08,     /**< Counter Id 8  */
    CSE_COUNTER_ID_09   = 0X09,     /**< Counter Id 9  */
    CSE_COUNTER_ID_10   = 0X0A,     /**< Counter Id 10 */
    CSE_COUNTER_ID_11   = 0X0B,     /**< Counter Id 11 */
    CSE_COUNTER_ID_12   = 0X0C,     /**< Counter Id 12 */
    CSE_COUNTER_ID_13   = 0X0D,     /**< Counter Id 13 */
    CSE_COUNTER_ID_14   = 0X0E,     /**< Counter Id 14 */
    CSE_COUNTER_ID_15   = 0X0F,     /**< Counter Id 15 */
    CSE_COUNTER_ID_16   = 0X10,     /**< Counter Id 16 */
    CSE_COUNTER_ID_17   = 0X11,     /**< Counter Id 17 */
    CSE_COUNTER_ID_18   = 0X12,     /**< Counter Id 18 */
    CSE_COUNTER_ID_19   = 0X13,     /**< Counter Id 19 */
    CSE_COUNTER_ID_20   = 0X14,     /**< Counter Id 20 */
    CSE_COUNTER_ID_21   = 0X15,     /**< Counter Id 21 */
    CSE_COUNTER_ID_22   = 0X16,     /**< Counter Id 22 */
    CSE_COUNTER_ID_23   = 0X17,     /**< Counter Id 23 */
    CSE_COUNTER_ID_24   = 0X18,     /**< Counter Id 24 */
    CSE_COUNTER_ID_25   = 0X19,     /**< Counter Id 25 */
    CSE_COUNTER_ID_26   = 0X1A,     /**< Counter Id 26 */
    CSE_COUNTER_ID_27   = 0X1B,     /**< Counter Id 27 */
    CSE_COUNTER_ID_28   = 0X1C,     /**< Counter Id 28 */
    CSE_COUNTER_ID_29   = 0X1D,     /**< Counter Id 29 */
    CSE_COUNTER_ID_30   = 0X1E,     /**< Counter Id 30 */
    CSE_COUNTER_ID_31   = 0X1F      /**< Counter Id 31 */
} Cse_CounterId;

/*==================================================================================================
*                                STRUCTURES AND OTHER TYPEDEFS
==================================================================================================*/

/*==================================================================================================
*                                GLOBAL VARIABLE DECLARATIONS
==================================================================================================*/

/*==================================================================================================
*                                    FUNCTION PROTOTYPES
==================================================================================================*/


#ifdef __cplusplus
}
#endif

#endif /*CRYPTO_CSETYPES_H*/

/** @} */
