/*!
* @file     Csm_Types.h
*
* @version  1.0.0
*
* @brief    AUTOSAR Crypto Service Manager header file
 *          This file is only a sample. It contains data types of the AUTOSAR Csm module.
* @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 CSM_TYPES_H
#define CSM_TYPES_H

#ifdef __cplusplus
extern "C"{
#endif

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

/** @defgroup CSM_Driver
  * @brief CSM driver modules
  @{
*/

/** @defgroup CSM_Macros
  @{
*/
/*******************************************************************************
                    VENDOR ID & AUTOSAR VERSION INFO
*******************************************************************************/
#define CSM_TYPES_H_VENDOR_ID                   0x00C1U
#define CSM_TYPES_H_MODULE_ID                   0x006EU

#define CSM_TYPES_H_AR_RELEASE_MAJOR_VERSION    0x04U
#define CSM_TYPES_H_AR_RELEASE_MINOR_VERSION    0x04U
#define CSM_TYPES_H_AR_RELEASE_REVISION_VERSION 0x00U

#define CSM_TYPES_H_SW_MAJOR_VERSION            0x01U
#define CSM_TYPES_H_SW_MINOR_VERSION            0x00U
#define CSM_TYPES_H_SW_PATCH_VERSION            0x00U

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

/*******************************************************************************
                            DEFINES AND MACROS
*******************************************************************************/
/** Key element index definitions */
#define CRYPTO_KE_MAC_PROOF         ((uint32)2U)    /* MAC Proof */
#define CRYPTO_KE_CIPHER_PROOF      ((uint32)6U)    /* Cipher Proof */
/**@} end of group CSM_Macros */

/** @defgroup CSM_Enumerations
  @{
*/
/**
 * @brief   Enumeration of the kind of the service
 */
typedef enum
{
    CRYPTO_HASH                 = 0x00U,    //!< Hash Service 
    CRYPTO_MACGENERATE          = 0x01U,    //!< MacGenerate Service 
    CRYPTO_MACVERIFY            = 0x02U,    //!< MacVerify Service 
    CRYPTO_ENCRYPT              = 0x03U,    //!< Encrypt Service 
    CRYPTO_DECRYPT              = 0x04U,    //!< Decrypt Service 
    CRYPTO_AEADENCRYPT          = 0x05U,    //!< AEADEncrypt Service 
    CRYPTO_AEADDECRYPT          = 0x06U,    //!< AEADDecrypt Service 
    CRYPTO_SIGNATUREGENERATE    = 0x07U,    //!< SignatureGenerate Service 
    CRYPTO_SIGNATUREVERIFY      = 0x08U,    //!< SignatureVerify Service 
    CRYPTO_SECCOUNTERINCREMENT  = 0x09U,    //!< SecureCounterIncrement Service 
    CRYPTO_SECCOUNTERREAD       = 0x0AU,    //!< SecureCounterDecrement Service 
    CRYPTO_RANDOMGENERATE       = 0x0BU,    //!< RandomGenerate Service 
    CRYPTO_MPCMGENERATE         = 0x0CU     //!< MpcGenerate Service 
} Crypto_ServiceInfoType;

/**
 * @brief   Enumeration of the algorithm family
 */
typedef enum
{
    CRYPTO_ALGOFAM_NOT_SET          = 0x00U,
    CRYPTO_ALGOFAM_SHA1             = 0x01U,
    CRYPTO_ALGOFAM_SHA2_224         = 0x02U,
    CRYPTO_ALGOFAM_SHA2_256         = 0x03U,
    CRYPTO_ALGOFAM_SHA2_384         = 0x04U,
    CRYPTO_ALGOFAM_SHA2_512         = 0x05U,
    CRYPTO_ALGOFAM_SHA2_512_224     = 0x06U,
    CRYPTO_ALGOFAM_SHA2_512_256     = 0x07U,
    CRYPTO_ALGOFAM_SHA3_224         = 0x08U,
    CRYPTO_ALGOFAM_SHA3_256         = 0x09U,
    CRYPTO_ALGOFAM_SHA3_384         = 0x0AU,
    CRYPTO_ALGOFAM_SHA3_512         = 0x0BU,
    CRYPTO_ALGOFAM_SHAKE128         = 0x0CU,
    CRYPTO_ALGOFAM_SHAKE256         = 0x0DU,
    CRYPTO_ALGOFAM_RIPEMD160        = 0x0EU,
    CRYPTO_ALGOFAM_BLAKE_1_256      = 0x0FU,
    CRYPTO_ALGOFAM_BLAKE_1_512      = 0x10U,
    CRYPTO_ALGOFAM_BLAKE_2s_256     = 0x11U,
    CRYPTO_ALGOFAM_BLAKE_2s_512     = 0x12U,
    CRYPTO_ALGOFAM_3DES             = 0x13U,
    CRYPTO_ALGOFAM_AES              = 0x14U,
    CRYPTO_ALGOFAM_CHACHA           = 0x15U,
    CRYPTO_ALGOFAM_RSA              = 0x16U,
    CRYPTO_ALGOFAM_ED25519          = 0x17U,
    CRYPTO_ALGOFAM_BRAINPOOL        = 0x18U,
    CRYPTO_ALGOFAM_ECCNIST          = 0x19U,
    CRYPTO_ALGOFAM_SECURECOUNTER    = 0x1AU,
    CRYPTO_ALGOFAM_RNG              = 0x1BU,
    CRYPTO_ALGOFAM_SIPHASH          = 0x1CU,
    CRYPTO_ALGOFAM_ECIES            = 0x1DU,
    CRYPTO_ALGOFAM_CUSTOM           = 0xFFU
} Crypto_AlgorithmFamilyType;

/**
 * @brief   Enumeration of the algorithm mode
 */
typedef enum
{
    CRYPTO_ALGOMODE_NOT_SET           = 0x00U, //!< Algorithm key is not set 
    CRYPTO_ALGOMODE_ECB               = 0x01U, //!< Blockmode: Electronic Code Book 
    CRYPTO_ALGOMODE_CBC               = 0x02U, //!< Blockmode: Cipher Block Chaining 
    CRYPTO_ALGOMODE_CFB               = 0x03U, //!< Blockmode: Cipher Feedback Mode 
    CRYPTO_ALGOMODE_OFB               = 0x04U, //!< Blockmode: Output Feedback Mode 
    CRYPTO_ALGOMODE_CTR               = 0x05U, //!< Blockmode: Counter Mode 
    CRYPTO_ALGOMODE_GCM               = 0x06U, //!< Blockmode: Galois/Counter Mode 
    CRYPTO_ALGOMODE_XTS               = 0x07U, //!< XOR-encryption-based tweaked-codebook mode with ciphertext stealing 
    CRYPTO_ALGOMODE_RSAES_OAEP        = 0x08U, //!< RSA Optimal Asymmetric Encryption Padding 
    CRYPTO_ALGOMODE_RSAES_PKCS1_v1_5  = 0x09U, //!< RSA encryption/decryption with PKCS#1 v1.5 padding 
    CRYPTO_ALGOMODE_RSASSA_PSS        = 0x0AU, //!< RSA Probabilistic Signature Scheme 
    CRYPTO_ALGOMODE_RSASSA_PKCS1_v1_5 = 0x0BU, //!< RSA signature with PKCS#1 v1.5 
    CRYPTO_ALGOMODE_8ROUNDS           = 0x0CU, //!< 8 rounds (e.g. ChaCha8) 
    CRYPTO_ALGOMODE_12ROUNDS          = 0x0DU, //!< 12 rounds (e.g. ChaCha12) 
    CRYPTO_ALGOMODE_20ROUNDS          = 0x0EU, //!< 20 rounds (e.g. ChaCha20) 
    CRYPTO_ALGOMODE_HMAC              = 0x0FU, //!< Hashed-based MAC 
    CRYPTO_ALGOMODE_CMAC              = 0x10U, //!< Cipher-based MAC 
    CRYPTO_ALGOMODE_GMAC              = 0x11U, //!< Galois MAC 
    CRYPTO_ALGOMODE_CTRDRBG           = 0x12U, //!< Counter-based Deterministic Random Bit Generator 
    CRYPTO_ALGOMODE_SIPHASH_2_4       = 0x13U, //!< Siphash-2-4 
    CRYPTO_ALGOMODE_SIPHASH_4_8       = 0x14U, //!< Siphash-4-8 
    CRYPTO_ALGOMODE_CCM               = 0x15U, //!< Blockmode: Galois/Counter Mode 
    CRYPTO_ALGOMODE_MPC               = 0x16U, 
    CRYPTO_ALGOMODE_TRNG              = 0x17U, 
    CRYPTO_ALGOMODE_SHA256            = 0x18U, 
    CRYPTO_ALGOMODE_CUSTOM            = 0xFFU  //!< Custom algorithm mode 
} Crypto_AlgorithmModeType;

/**
 * @brief   Enumeration which operation shall be performed. This enumeration is
 *           constructed from a bit mask, where the first bit indicates "Start", the
 *           second "Update" and the third "Finish".
 */
typedef enum
{
    /** Operation Mode is "Start". The job's state shall be reset, i.e. previous
    * input data and intermediate results shall be deleted. */
    CRYPTO_OPERATIONMODE_START          = 0x01U,

    /** Operation Mode is "Update". Used to calculate intermediate results. */
    CRYPTO_OPERATIONMODE_UPDATE         = 0x02U,

    /** Operation Mode is "Stream Start". Mixture of "Start" and "Update". Used for streaming. */
    CRYPTO_OPERATIONMODE_STREAMSTART    = 0x03U,

    /** Operation Mode is "Finish". The calculations shall be finalized. */
    CRYPTO_OPERATIONMODE_FINISH         = 0x04U,

    /** Operation Mode is "Single Call". Mixture of "Start", "Update" and "Finish". */
    CRYPTO_OPERATIONMODE_SINGLECALL     = 0x07U
} Crypto_OperationModeType;

/**
 * @brief   Enumeration of the result type of verification operations
 */
typedef enum
{
    /** The result of the verification is "true", i.e. the two compared elements
    * are identical. This return code shall be given as value "0". */
    CRYPTO_E_VER_OK         = 0x00U,

    /** The result of the verification is "false", i.e. the two compared elements
    * are not identical. This return code shall be given as value "1". */
    CRYPTO_E_VER_NOT_OK     = 0x01U
} Crypto_VerifyResultType;

/**
 * @brief   Enumeration of the processing type
 */
typedef enum
{
    /** Asynchronous job processing */
    CRYPTO_PROCESSING_ASYNC = 0x00U,
    /** Synchronous job processing */
    CRYPTO_PROCESSING_SYNC  = 0x01U
} Crypto_ProcessingType;

/**
 * @brief   Enumeration of the current job state
 */
typedef enum
{
    /** Job is in the state "idle". This state is reached after Csm_Init() or
    * when the "Finish" state is finished. */
    CRYPTO_JOBSTATE_IDLE    = 0x00U,

    /** Job is in the state "active". There was already some input or there are
    * intermediate results. This state is reached, when the "update" or "start"
    * operation finishes. */
    CRYPTO_JOBSTATE_ACTIVE  = 0x01U
} Crypto_JobStateType;

/**@} end of group CSM_Enumerations */

/** @defgroup CSM_Structure
  @{
*/

/**
 * @brief   Structure which determines the exact algorithm. Note, not every algorithm
 *          needs to specify all fields. AUTOSAR shall only allow valid combinations.
 */
typedef struct
{
    /** The family of the algorithm */
    VAR(Crypto_AlgorithmFamilyType, AUTOMATIC) family;

    /** The secondary family of the algorithm */
    VAR(Crypto_AlgorithmFamilyType, AUTOMATIC) secondaryFamily;

    /** The key length in bits to be used with that algorithm */
    VAR(uint32, AUTOMATIC) keyLength;

    /** The operation mode to be used with that algorithm */
    VAR(Crypto_AlgorithmModeType, AUTOMATIC) mode;
} Crypto_AlgorithmInfoType;

/**
 * @brief   Structure which contains basic information about the crypto primitive.
 */
typedef struct
{
    /** Contains the result length in bytes. */
    CONST(uint32, CSM_CONST) resultLength;

    /** Contains the enum of the used service, e.g. Encrypt */
    CONST(Crypto_ServiceInfoType, CSM_CONST) service;

    /** Contains the information of the used algorithm */
    CONST(Crypto_AlgorithmInfoType, CSM_CONST) algorithm;
} Crypto_PrimitiveInfoType;

/**
 * @brief   Structure which contains input and output information depending on the job and the crypto primitive.
 */
typedef struct
{
    /** Pointer to the input data. */
    P2CONST(uint8, AUTOMATIC, CSM_APPL_CONST) inputPtr;

    /** Contains the input length in bytes. */
    VAR(uint32, AUTOMATIC) inputLength;

    /** Pointer to the secondary input data (for MacVerify, SignatureVerify). */
    P2CONST(uint8, AUTOMATIC, CSM_APPL_CONST) secondaryInputPtr;

    /** Contains the secondary input length in bytes. */
    VAR(uint32, AUTOMATIC) secondaryInputLength;

    /** Pointer to the tertiary input data (for MacVerify, SignatureVerify). */
    P2CONST(uint8, AUTOMATIC, CSM_APPL_CONST) tertiaryInputPtr;

    /** Contains the tertiary input length in bytes. */
    VAR(uint32, AUTOMATIC) tertiaryInputLength;

    /** Pointer to the output data. */
    P2VAR(uint8, AUTOMATIC, CSM_APPL_DATA) outputPtr;

    /** Holds a pointer to a memory location containing the output length in bytes. */
    P2VAR(uint32, AUTOMATIC, CSM_APPL_DATA) outputLengthPtr;

    /** Pointer to the secondary output data. */
    P2VAR(uint8, AUTOMATIC, CSM_APPL_DATA) secondaryOutputPtr;

    /** Holds a pointer to a memory location containing the secondary output length in bytes. */
    P2VAR(uint32, AUTOMATIC, CSM_APPL_DATA) secondaryOutputLengthPtr;

    /** Versatile input parameter */
    VAR(uint64, AUTOMATIC) input64;

    /** Output pointer to a memory location holding a Crypto_VerifyResultType */
    P2VAR(Crypto_VerifyResultType, AUTOMATIC, CSM_APPL_DATA) verifyPtr;

    /** Output pointer to a memory location holding an uint64. */
    P2VAR(uint64, AUTOMATIC, CSM_APPL_DATA) output64Ptr;

    /** Indicator of the mode(s)/operation(s) to be performed */
    VAR(Crypto_OperationModeType, AUTOMATIC) mode;
} Crypto_JobPrimitiveInputOutputType;

/**
 * @brief   Structure which contains further information, which depends on the job and the crypto primitive.
 */
typedef struct
{
    /** Identifier of the callback function, to be called, if the configured service finished. */
    CONST(uint32, CSM_CONST) callbackId;

    /** Pointer to a structure containing further configuration of the crypto primitives */
    P2CONST(Crypto_PrimitiveInfoType, CSM_VAR, CSM_APPL_CONST) primitiveInfo;

    /** Identifier of a secure counter. */
    CONST(uint32, CSM_CONST) secureCounterId;

    /** Identifier of the CryIf key. */
    CONST(uint32, CSM_CONST) cryIfKeyId;

    /** Determines the synchronous or asynchronous behavior. */
    CONST(Crypto_ProcessingType, CSM_CONST) processingType;

    /** Indicates, whether the callback function shall be called, if the UPDATE operation has finished. */
    CONST(boolean, CSM_CONST) callbackUpdateNotification;
} Crypto_JobPrimitiveInfoType;

/**
 * @brief   Structure which contains job information
 */
typedef struct
{
    /** The family of the algorithm */
    CONST(uint32, CSM_CONST) jobId;

    /** Specifies the importance of the job (the higher, the more important). */
    CONST(uint32, CSM_CONST) jobPriority;
} Crypto_JobInfoType;

/**
 * @brief   Structure which contains job redirection information
 */
typedef struct
{
    VAR(uint8, AUTOMATIC) redirectionConfig;
    VAR(uint32, AUTOMATIC) inputKeyId;
    VAR(uint32, AUTOMATIC) inputKeyElementId;
    VAR(uint32, AUTOMATIC) secondaryInputKeyId;
    VAR(uint32, AUTOMATIC) secondaryInputKeyElementId;
    VAR(uint32, AUTOMATIC) tertiaryInputKeyId;
    VAR(uint32, AUTOMATIC) tertiaryInputKeyElementId;
    VAR(uint32, AUTOMATIC) outputKeyId;
    VAR(uint32, AUTOMATIC) outputKeyElementId;
    VAR(uint32, AUTOMATIC) secondaryOutputKeyId;
    VAR(uint32, AUTOMATIC) secondaryOutputKeyElementId;
} Crypto_JobRedirectionInfoType;

/**
 * @brief   Structure which contains further information, which depends on the job and the crypto primitive.
 */
typedef struct
{
    /** Identifier for the job structure. */
    CONST(uint32, CSM_CONST) jobId;

    /** Determines the current job state */
    VAR(Crypto_JobStateType, AUTOMATIC) jobState;

    /** Structure containing input and output information depending on the job and the crypto primitive. */
    VAR(Crypto_JobPrimitiveInputOutputType, AUTOMATIC) jobPrimitiveInputOutput;

    /** Pointer to a structure containing further information, which depends on the job and the crypto primitive. */
    P2CONST(Crypto_JobPrimitiveInfoType, CSM_VAR, CSM_APPL_CONST) jobPrimitiveInfo;

    /** Pointer to a structure containing further information, which depends on the job and the crypto primitive. */
    P2CONST(Crypto_JobInfoType, CSM_VAR, CSM_APPL_CONST) jobInfo;

    /** Identifier of the Crypto Driver key. The identifier shall be written by the Crypto Interface. */
    VAR(uint8, AUTOMATIC) cryptoKeyId;
    VAR(uint32, AUTOMATIC) KeyElementId;
} Crypto_JobType;

/**
 * @brief   Structure which Configuration data structure of CryIf module,currently not used.
 */
typedef struct 
{
    VAR(uint32, AUTOMATIC) reserved;
}Crypto_ConfigType;

/**@} end of group CSM_Structure */

#ifdef __cplusplus
}
#endif

#endif  /* CSM_TYPES_H */

/**@} end of group CSM_Driver */
/**@} end of group G32A10xx_StdPeriphDriver */
