/*!
* @file     Crypto_Types.h
*
* @version  1.0.0
*
* @brief    AUTOSAR Crypto Driver header file of types
 *         
* @attention
*
* Project Name      : AUTOSAR MCAL
*
* Platform          : Arm
*
* Autosar Standard  : Classic Platform 4.4.0
*
* Compiled Version  : G32A10xx_MCAL_1_0_0_15-Nov-25
*
* Copyright (C) 2026 Geehy Semiconductor
*
* You may not use this file except in compliance with the
* GEEHY COPYRIGHT NOTICE (Geehy Semiconductor Software License Agreement).
*
* The program is only for reference, which is distributed in the hope
* that it will be usefull and instructional for customers to develop
* their software. Unless required by applicable law or agreed to in
* writing, the program is distributed on an "AS IS" BASIS, WITHOUT
* ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
* See the Geehy Semiconductor Software License Agreement for the governing permissions
* and limitations under the License.
*/

#ifndef CRYPTO_TYPES_H
#define CRYPTO_TYPES_H

#ifdef __cplusplus
extern "C"{
#endif

#include "Mcal.h"
#include "Csm_Types.h"
#include "Crypto_Cfg.h"
/** @addtogroup G32A10xx_StdPeriphDriver
  @{
*/

/** @defgroup CRYPTO_Driver
  * @brief CRYPTO driver modules
  @{
*/

/** @defgroup CRYPTO_Macros
  @{
*/
/*******************************************************************************
                    VENDOR ID & AUTOSAR VERSION INFO
*******************************************************************************/
/** Vendor ID (vendorId) of the dedicated implementation of this module according to the AUTOSAR vendor list. */
#define CRYPTO_TYPES_H_VENDOR_ID                        0x00C1U
/** Major version number of AUTOSAR release on which the appropriate implementation is based on. */
#define CRYPTO_TYPES_H_AR_RELEASE_MAJOR_VERSION         0x04U
/** Minor version number of AUTOSAR release on which the appropriate implementation is based on. */
#define CRYPTO_TYPES_H_AR_RELEASE_MINOR_VERSION         0x04U
/** Revision version number of AUTOSAR release on which the appropriate implementation is based on. */
#define CRYPTO_TYPES_H_AR_RELEASE_REVISION_VERSION      0x00U
/** Major version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define CRYPTO_TYPES_H_SW_MAJOR_VERSION                 0x01U
/** Minor version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define CRYPTO_TYPES_H_SW_MINOR_VERSION                 0x00U
/** Patch level version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define CRYPTO_TYPES_H_SW_PATCH_VERSION                 0x00U

/*******************************************************************************
                             VERSION CHECK
*******************************************************************************/
/* Make sure the vendor id is the same between Crypto_Types.h and Crypto_Cfg.h */
#if (CRYPTO_TYPES_H_VENDOR_ID != CRYPTO_CFG_H_VENDOR_ID)
    #error "Vendor id mismatch between Crypto_Types.h and Crypto_Cfg.h"
#endif
/* Make sure the AUTOSAR major version number is the same between Crypto_Types.h and Crypto_Cfg.h */
#if (CRYPTO_TYPES_H_AR_RELEASE_MAJOR_VERSION != CRYPTO_CFG_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR major version number mismatch between Crypto_Types.h and Crypto_Cfg.h"
#endif
/* Make sure the AUTOSAR minor version number is the same between Crypto_Types.h and Crypto_Cfg.h */
#if (CRYPTO_TYPES_H_AR_RELEASE_MINOR_VERSION != CRYPTO_CFG_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR minor version number mismatch between Crypto_Types.h and Crypto_Cfg.h"
#endif
/* Make sure the AUTOSAR revision version number is the same between Crypto_Types.h and Crypto_Cfg.h */
#if (CRYPTO_TYPES_H_AR_RELEASE_REVISION_VERSION != CRYPTO_CFG_H_AR_RELEASE_REVISION_VERSION)
    #error "AUTOSAR revision version number mismatch between Crypto_Types.h and Crypto_Cfg.h"
#endif
/* Make sure the software major version number is the same between Crypto_Types.h and Crypto_Cfg.h */
#if (CRYPTO_TYPES_H_SW_MAJOR_VERSION != CRYPTO_CFG_H_SW_MAJOR_VERSION)
    #error "Software major version number mismatch between Crypto_Types.h and Crypto_Cfg.h"
#endif
/* Make sure the software minor version number is the same between Crypto_Types.h and Crypto_Cfg.h */
#if (CRYPTO_TYPES_H_SW_MINOR_VERSION != CRYPTO_CFG_H_SW_MINOR_VERSION)
    #error "Software minor version number mismatch between Crypto_Types.h and Crypto_Cfg.h"
#endif
/* Make sure the software patch version number is the same between Crypto_Types.h and Crypto_Cfg.h */
#if (CRYPTO_TYPES_H_SW_PATCH_VERSION != CRYPTO_CFG_H_SW_PATCH_VERSION)
    #error "Software patch version number mismatch between Crypto_Types.h and Crypto_Cfg.h"
#endif

#ifdef ENABLE_INTERMODULE_MCAL_CHECK
    /* Make sure the AUTOSAR major version number is the same between Crypto_Types.h and Csm_Types.h */
    #if (CRYPTO_TYPES_H_AR_RELEASE_MAJOR_VERSION != CSM_TYPES_H_AR_RELEASE_MAJOR_VERSION)
        #error "AUTOSAR major version number mismatch between Crypto_Types.h and Csm_Types.h"
    #endif
    /* Make sure the AUTOSAR minor version number is the same between Crypto_Types.h and Csm_Types.h */
    #if (CRYPTO_TYPES_H_AR_RELEASE_MINOR_VERSION != CSM_TYPES_H_AR_RELEASE_MINOR_VERSION)
        #error "AUTOSAR minor version number mismatch between Crypto_Types.h and Csm_Types.h"
    #endif
    /* Make sure the AUTOSAR major version number is the same between Crypto_Types.h and Mcal.h */
    #if (CRYPTO_TYPES_H_AR_RELEASE_MAJOR_VERSION != MCAL_H_AR_RELEASE_MAJOR_VERSION)
        #error "AUTOSAR major version number mismatch between Crypto_Types.h and Mcal.h"
    #endif
    /* Make sure the AUTOSAR minor version number is the same between Crypto_Types.h and Mcal.h */
    #if (CRYPTO_TYPES_H_AR_RELEASE_MINOR_VERSION != MCAL_H_AR_RELEASE_MINOR_VERSION)
        #error "AUTOSAR minor version number mismatch between Crypto_Types.h and Mcal.h"
    #endif
#endif


/*******************************************************************************
                                DEFINES
*******************************************************************************/
#define  ENCRYPT                CRYPTO_ENCRYPT
#define  DECRYPT                CRYPTO_DECRYPT
#define  MAC_GENERATE           CRYPTO_MACGENERATE
#define  MAC_VERIFY             CRYPTO_MACVERIFY
#define  RANDOM                 CRYPTO_RANDOMGENERATE
#define  AEAD_ENCRYPT           CRYPTO_AEADENCRYPT
#define  AEAD_DECRYPT           CRYPTO_AEADDECRYPT
#define  HASH                   CRYPTO_HASH
#define  MPC                    CRYPTO_MPCMGENERATE
#define  SIGNATURE_GENERATE     CRYPTO_SIGNATUREGENERATE
#define  SIGNATURE_VERIFY       CRYPTO_SIGNATUREVERIFY
#define  SECCOUNTERINCREMENT    CRYPTO_SECCOUNTERINCREMENT
#define  SECCOUNTERREAD         CRYPTO_SECCOUNTERREAD

#if (STD_ON == CRYPTO_DEV_ERR_DETECT_ENABLE)
/* Operation mode: UPDATE & FINISH  */
#define CRYPTO_OPERATIONMODE_UPDATE_FINISH ((uint8)((uint8)CRYPTO_OPERATIONMODE_UPDATE | (uint8)CRYPTO_OPERATIONMODE_FINISH))
#endif /* STD_ON == CRYPTO_DEV_ERR_DETECT_ENABLE */
/**@} end of group CRYPTO_Macros */
/*******************************************************************************
                                ENUMS
*******************************************************************************/
/** @defgroup CRYPTO_Enumerations
  @{
*/
/**
 * @brief  Crypto driver status
 */
typedef enum  
{
    CRYPTO_DRIVER_UNINIT = 0x00U, //!< Crypto driver not initialized
    CRYPTO_DRIVER_READY = 0x01U //!< Crypto driver has been initialized successfully
} Crypto_DriverStatusType;

#if (CRYPTO_KEYS_CONFIGURED == 1U)
/**
 * @brief  Key element format
 */
typedef enum  
{
    CRYPTO_KE_FORMAT_BIN_OCTET = 0x01U, //!< Key provided as octet value in binary form
    CRYPTO_KE_FORMAT_BIN_SHEKEYS = 0x02U, //!< Combined input/output keys for SHE operation (M1+M2+M3) and (M4+M5)
    CRYPTO_KE_FORMAT_BIN_IDENT_PRIVATEKEY_PKCS8 = 0x03U, //!< Private key material in ASN.1 coded form (BER coding) with identification
    CRYPTO_KE_FORMAT_BIN_IDENT_PUBLICKEY = 0x04U, //!< Public key material in ASN.1 coded form (BER coding) with identification
    CRYPTO_KE_FORMAT_BIN_RSA_PRIVATEKEY = 0x05U, //!< Private key material in ASN.1 coded form (BER coding)
    CRYPTO_KE_FORMAT_BIN_RSA_PUBLICKEY = 0x06U, //!< Public key material in ASN.1 coded form (BER coding)
    CRYPTO_KE_FORMAT_BIN_CERT_X509_V3 = 0x07U, //!< X509 certificate 
    CRYPTO_KE_FORMAT_BIN_CERT_CVC = 0x08U //!< CVC certificate
} Crypto_KeyElementFormatType;
/**
 * @brief  Key element read access
 */
typedef enum  
{
    CRYPTO_RA_DENIED = 0x01U, //!< Key element cannot be read from outside the Crypto Driver
    CRYPTO_RA_INTERNAL_COPY = 0x02U, //!< Key element can be copied to another key element in the same crypto driver
    CRYPTO_RA_ALLOWED = 0x03U, //!< Key element can be read as plaintext
    CRYPTO_RA_ENCRYPTED = 0x04U //!< Key element can be read encrypted. E.g. SHE Ram-Key export
} Crypto_KeyElementReadAccessType;
/**
 * @brief  Key element write access
 */
typedef enum   
{
    CRYPTO_WA_DENIED = 0x01U, //!< Key element can not be written from outside the Crypto Driver
    CRYPTO_WA_INTERNAL_COPY = 0x02U, //!< Key element can be filled with another key element in the same crypto driver
    CRYPTO_WA_ALLOWED = 0x03U, //!< Key element can be rewritten as plaintext
    CRYPTO_WA_ENCRYPTED = 0x04U //!< Key element can be written encrypted. E.g. SHE load key
} Crypto_KeyElementWriteAccessType;
#endif /* CRYPTO_KEYS_CONFIGURED == 1U */
/**
 * @brief  Defines function return values
 */
typedef enum
{
    CRYPTO_RET_OK           = 0x00U,
    CRYPTO_RET_NOT_OK       = 0x01U,
    CRYPTO_RET_NULL_PTR     = 0x02U,
    CRYPTO_RET_INVALID_LEN  = 0x03U
} Crypto_ReturnType;

/**@} end of group CRYPTO_Enumerations */
/*******************************************************************************
                                STRUCTURES
*******************************************************************************/
/** @defgroup CRYPTO_Structure
  @{
*/
/**
 * @brief  Status of Crypto Driver Object
 */
typedef struct  
{
    VAR(Std_ReturnType, AUTOMATIC) status;
    VAR(uint32, AUTOMATIC) index;
} Crypto_ObjectStatusType;
/**
 * @brief  Status of crypto key
 */
typedef struct 
{
    VAR(Std_ReturnType, AUTOMATIC) status;
    VAR(uint32, AUTOMATIC) index;
} Crypto_KeyStatusType;
/**
 * @brief  Status of crypto key element
 */
typedef struct  
{
    VAR(Std_ReturnType, AUTOMATIC) status;
    VAR(uint32, AUTOMATIC) index;
} Crypto_ElementStatusType;
/**
 * @brief  Internal job queue
 */
typedef struct  
{
    VAR(uint32,AUTOMATIC) next;
    P2VAR(Crypto_JobType, AUTOMATIC,CRYPTO_APPL_DATA) jobPtr;
} Crypto_QueueType;
/**
 * @brief  Configuration of crypto primitive
 */
typedef struct  
{
    CONST(Crypto_ServiceInfoType, CRYPTO_CONST) serviceInfo; //!< Crypto service
    CONST(Crypto_AlgorithmFamilyType, CRYPTO_CONST) algoFamily; //!< Crypto algorithm family
    CONST(Crypto_AlgorithmModeType, CRYPTO_CONST) algoMode; //!< Crypto algorithm mode
    CONST(Crypto_AlgorithmFamilyType, CRYPTO_CONST) secondaryAlgoFamily; //!< Crypto algorithm secondary family
} Crypto_PrimitiveType;
/**
 * @brief  Configuration of Crypto Driver Object
 */
typedef struct 
{
    CONST(uint32, CRYPTO_CONST) objectId; //!< ID of the crypto driver object
    P2VAR(Crypto_QueueType, AUTOMATIC, CRYPTO_APPL_DATA) queuedJobs; //!< The queue of the jobs
    CONST(uint32, CRYPTO_CONST) queueSize; //!< Size of the job queue
    VAR(uint32, CRYPTO_VAR) headOfFreeJobs; //!< Head of free jobs 
    VAR(uint32, CRYPTO_VAR) headOfQueuedJobs; //!< Head of queued jobs
    CONSTP2CONST(Crypto_PrimitiveType, CRYPTO_VAR, CRYPTO_APPL_CONST) primitives; //!< Crypto primitives
    CONST(uint32, CRYPTO_CONST) primitiveCount; //!< Number of crypto primitives
} Crypto_ObjectType;

#if (CRYPTO_KEYS_CONFIGURED == 1U)
/**
 * @brief  Configuration of key element
 */
typedef struct
{
    CONST(uint32, CRYPTO_CONST) elementId; //!< ID of the key element
    CONST(uint32, CRYPTO_CONST) uniqueId; //!< Key clement unique index
    CONST(boolean, CRYPTO_CONST) allowPartialAccess; //!< If the key element allows partial access 
    CONST(Crypto_KeyElementFormatType, CRYPTO_CONST) format; //!< Format of the key element
    CONST(boolean, CRYPTO_CONST) persist; //!< Enable or disable persisting of the key element in non-volatile storage
    CONST(Crypto_KeyElementReadAccessType, CRYPTO_CONST) readAccess;//!< Reading access rights of the key element
    CONST(uint32, CRYPTO_CONST) maxSize;//!< Maximum size of the key element in bytes
    VAR(uint32, CRYPTO_VAR) actualSize;//!< Actual size of the key element in bytes
    CONST(Crypto_KeyElementWriteAccessType, CRYPTO_CONST) writeAccess;//!< Writing access rights of the key element
    P2VAR(uint8, AUTOMATIC, CRYPTO_APPL_DATA) data;//!< Key element value
} Crypto_KeyElementType;
/**
 * @brief  List of key elements
 */
typedef struct
{
    CONST(uint32, CRYPTO_CONST) count;
    CONSTP2CONST(uint32, CRYPTO_VAR, CRYPTO_APPL_CONST) elements;
} Crypto_KeyElementListType;
/**
 * @brief  Configuration of crypto key
 */
typedef struct
{
    CONST(uint32, CRYPTO_CONST) keyId;//!< ID of the key
    CONST(uint32, CRYPTO_CONST) deriveIterations;//!< Number of iterations to be performed
    VAR(boolean, AUTOMATIC) valid;//!< If the key is valid
    CONSTP2CONST(Crypto_KeyElementListType, CRYPTO_VAR, CRYPTO_APPL_CONST) elementList;//!< List of key elements 
} Crypto_KeyType;
#endif /* CRYPTO_KEYS_CONFIGURED == 1U */


#if (STD_ON == CRYPTO_DEV_ERR_DETECT_ENABLE)
/**
 * @brief  Defines how the Crypto_ProcessJob() API should handle the parameters
 */
typedef struct
{
    uint8 outputModeMask;
    uint8 secondaryOutputModeMask;
    uint8 verifyPtrModeMask;
    uint8 inputModeMask;
    uint8 secondaryInputModeMask;
    uint8 tertiaryInputModeMask;
    boolean singleCallOnly;
} Crypto_JobParametersType;

#endif /* STD_ON == CRYPTO_DEV_ERR_DETECT_ENABLE */
/**@} end of group CRYPTO_Structure */

#ifdef __cplusplus
}
#endif

#endif /* CRYPTO_TYPES_H */
/**@} end of group CRYPTO_Driver */
/**@} end of group G32A10xx_StdPeriphDriver */
