/**
*   @file    Crypto_Types.h
*
*   @version 1.0.0
*   @brief   AUTOSAR Crypto - Crypto interface
*   @details API header for Crypto driver.
*
*   @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_TYPES_H
#define CRYPTO_TYPES_H

#ifdef __cplusplus
extern "C"{
#endif

/**
* @page misra_violations MISRA-C:2012 violations
*
* @section Crypto_Types_h_REF_1
* Violates MISRA 2012 Advisory Rule 2.5, A project should not contain unused macro declarations.
* This macro is reserved for future use.
*
* @section [global]
*          Violates MISRA 2012 Required Rule 5.1, External identifiers shall be distinct.
*          The used compilers use more than 31 chars for identifiers.
*
* @section [global]
*          Violates MISRA 2012 Required Rule 5.2, Identifiers declared in the same scope and name space shall be distinct.
*          The used compilers use more than 31 chars for identifiers.
*
* @section [global]
*          Violates MISRA 2012 Required Rule 5.4, Macro identifiers shall be distinct.
*          The used compilers use more than 31 chars for identifiers.
*
* @section [global]
*          Violates MISRA 2012 Required Rule 5.5, Identifiers shall be distinct from macro names.
*          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 "Mcal.h"
#include "Csm_Types.h"

/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================*/
#define CRYPTO_VENDOR_ID_TYPES                       43
#define CRYPTO_AR_RELEASE_MAJOR_VERSION_TYPES        4
#define CRYPTO_AR_RELEASE_MINOR_VERSION_TYPES        3
#define CRYPTO_AR_RELEASE_REVISION_VERSION_TYPES     1
#define CRYPTO_SW_MAJOR_VERSION_TYPES                1
#define CRYPTO_SW_MINOR_VERSION_TYPES                0
#define CRYPTO_SW_PATCH_VERSION_TYPES                0

/*==================================================================================================
*                                    FILE VERSION CHECKS
==================================================================================================*/
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
    /* Check if header file and Mcal header file are of the same AutoSar version */
    #if ((CRYPTO_AR_RELEASE_MAJOR_VERSION_TYPES != MCAL_AR_RELEASE_MAJOR_VERSION) || \
         (CRYPTO_AR_RELEASE_MINOR_VERSION_TYPES != MCAL_AR_RELEASE_MINOR_VERSION)    \
        )
        #error "AutoSar Version Numbers of Crypto_Types.h and Mcal.h are different"
    #endif
    
    /* Check if header file and Csm types header header file are of the same AutoSar version */
    #if ((CRYPTO_AR_RELEASE_MAJOR_VERSION_TYPES != CSM_AR_RELEASE_MAJOR_VERSION_TYPES) || \
         (CRYPTO_AR_RELEASE_MINOR_VERSION_TYPES != CSM_AR_RELEASE_MINOR_VERSION_TYPES)    \
        )
        #error "AutoSar Version Numbers of Crypto_Types.h and Csm_Types.h are different"
    #endif 
#endif

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

/*==================================================================================================
*                                       DEFINES AND MACROS
==================================================================================================*/
#define  ENCRYPT                CRYPTO_ENCRYPT
#define  DECRYPT                CRYPTO_DECRYPT
/** @violates @ref Crypto_Types_h_REF_1 This macro is reserved for future use. */ 
#define  HASH                   CRYPTO_HASH
#define  MAC_GENERATE           CRYPTO_MACGENERATE
#define  MAC_VERIFY             CRYPTO_MACVERIFY
#define  AEAD_ENCRYPT           CRYPTO_AEADENCRYPT
#define  AEAD_DECRYPT           CRYPTO_AEADDECRYPT
/** @violates @ref Crypto_Types_h_REF_1 This macro is reserved for future use. */         
#define  SIGNATURE_GENERATE     CRYPTO_SIGNATUREGENERATE
/** @violates @ref Crypto_Types_h_REF_1 This macro is reserved for future use. */   
#define  SIGNATURE_VERIFY       CRYPTO_SIGNATUREVERIFY
/** @violates @ref Crypto_Types_h_REF_1 This macro is reserved for future use. */   
#define  SECCOUNTERINCREMENT    CRYPTO_SECCOUNTERINCREMENT
/** @violates @ref Crypto_Types_h_REF_1 This macro is reserved for future use. */
#define  SECCOUNTERREAD         CRYPTO_SECCOUNTERREAD
#define  RANDOM                 CRYPTO_RANDOMGENERATE

/*==================================================================================================
*                                             ENUMS
==================================================================================================*/
typedef enum
{
    CRYPTO_WA_DENIED        = 0x01U,
    CRYPTO_WA_INTERNAL_COPY = 0x02U,
    CRYPTO_WA_ALLOWED       = 0x03U,
    CRYPTO_WA_ENCRYPTED     = 0x04U
} Crypto_KeyElementWriteAccessType;

typedef enum
{
    CRYPTO_RA_DENIED        = 0x01U,
    CRYPTO_RA_INTERNAL_COPY = 0x02U,
    CRYPTO_RA_ALLOWED       = 0x03U,
    CRYPTO_RA_ENCRYPTED     = 0x04U
} Crypto_KeyElementReadAccessType;

typedef enum
{
    CRYPTO_KE_FORMAT_BIN_OCTET                       = 0x01U,
    CRYPTO_KE_FORMAT_BIN_SHEKEYS                     = 0x02U,
    CRYPTO_KE_FORMAT_BIN_IDENT_PRIVATEKEY_PKCS8      = 0x03U,
    CRYPTO_KE_FORMAT_BIN_IDENT_PUBLICKEY             = 0x04U,
    CRYPTO_KE_FORMAT_BIN_RSA_PRIVATEKEY              = 0x05U,
    CRYPTO_KE_FORMAT_BIN_RSA_PUBLICKEY               = 0x06U,
    CRYPTO_KE_FORMAT_BIN_CERT_X509_V3                = 0x07U,
    CRYPTO_KE_FORMAT_BIN_CERT_CVC                    = 0x08U
} Crypto_KeyFormatType;

/**
* @brief Enum containing the possible states of the Crypto driver
*/
typedef enum
{
    CRYPTO_DRIVER_UNINIT      = 0x00U,
    CRYPTO_DRIVER_INITIALIZED = 0x01U
} Crypto_DriverStateType;

/**
* @brief          BRCS mode .
* @details        BRCS command provides 4 separate functions based on the mode input value.
*/
typedef enum
{
    STATUS  = 0x00,
    BACKUP  = 0x01,
    CLEANUP = 0x02,
    RESTORE = 0x03
}Crypto_BrcsModeType;

/*==================================================================================================
*                                 STRUCTURES AND OTHER TYPEDEFS
==================================================================================================*/
typedef struct
{
    CONST (Crypto_ServiceInfoType,     CRYPTO_CONST) eService;
    CONST (Crypto_AlgorithmFamilyType, CRYPTO_CONST) eFamily;
    CONST (Crypto_AlgorithmModeType,   CRYPTO_CONST) eMode;
    CONST (Crypto_AlgorithmFamilyType, CRYPTO_CONST) eSecondaryFamily;
} Crypto_PrimitiveType;

typedef struct
{
    CONST(uint32, CRYPTO_CONST) u32NoCryptoKeyElements;
    CONSTP2CONST(uint32, CRYPTO_VAR, CRYPTO_APPL_CONST) u32CryptoKeyElements; 
} Crypto_KeyElementsType;

typedef struct
{
    CONST(uint32,  CRYPTO_CONST) u32CryptoKeyId;
    CONST(uint32,  CRYPTO_CONST) u32CryptoKeyDeriveIterations;
    VAR  (boolean, AUTOMATIC   ) bCryptoKeyValid;
    CONSTP2CONST(Crypto_KeyElementsType, CRYPTO_VAR, CRYPTO_APPL_CONST) pCryptoKeyElementList;
} Crypto_KeyType;

typedef struct
{
    VAR(uint32,         AUTOMATIC) u32Next;
    VAR(Crypto_JobType, AUTOMATIC) Job;
} Crypto_QueueType;

typedef struct
{
    CONST(uint32, CRYPTO_CONST) u32CryptoDriverObjectId;
    P2VAR(Crypto_QueueType, AUTOMATIC, CRYPTO_APPL_DATA) pQueuedJobs;
    CONST(uint32, CRYPTO_CONST) u32CryptoQueueSize;
    VAR(uint32, CRYPTO_VAR) u32HeadOfFreeJobs;
    VAR(uint32, CRYPTO_VAR) u32HeadOfQueuedJobs;
    CONSTP2CONST(Crypto_PrimitiveType, CRYPTO_VAR, CRYPTO_APPL_CONST) pCryptoKeyPrimitives;
    CONST(uint32, CRYPTO_CONST) u32NoCryptoPrimitives;
} Crypto_ObjectType;

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

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

#ifdef __cplusplus
}
#endif

#endif /* CRYPTO_TYPES_H */

/** @} */
