/*!
* @file     Crypto.h
*
* @version  1.0.0
*
* @brief    AUTOSAR Crypto Driver header file
 *          This file contains AUTOSAR Crypto Driver APIs and error codes.
* @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_H
#define CRYPTO_H

#ifdef __cplusplus
extern "C"{
#endif

#include "Mcal.h"
#include "Crypto_Cfg.h"
#include "Csm_Types.h"
#include "Crypto_Types.h"
#include "Crypto_Cfg.h"
#include "Crypto_Common.h"
#include "Crypto_Rng.h"
#include "Crypto_Aes256.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_H_VENDOR_ID                      0x00C1U
/** Module ID of this module, as defined in the BSW Module List. */
#define CRYPTO_H_MODULE_ID                      0x0072U
/** Major version number of AUTOSAR release on which the appropriate implementation is based on. */
#define CRYPTO_H_AR_RELEASE_MAJOR_VERSION       0x04U
/** Minor version number of AUTOSAR release on which the appropriate implementation is based on. */
#define CRYPTO_H_AR_RELEASE_MINOR_VERSION       0x04U
/** Revision version number of AUTOSAR release on which the appropriate implementation is based on. */
#define CRYPTO_H_AR_RELEASE_REVISION_VERSION    0x00U
/** Major version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define CRYPTO_H_SW_MAJOR_VERSION               0x01U
/** Minor version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define CRYPTO_H_SW_MINOR_VERSION               0x00U
/** Patch level version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define CRYPTO_H_SW_PATCH_VERSION               0x00U

/*******************************************************************************
                             VERSION CHECK
*******************************************************************************/
/* Make sure the vendor id is the same between Crypto.h and Crypto_Cfg.h */
#if (CRYPTO_H_VENDOR_ID != CRYPTO_CFG_H_VENDOR_ID)
    #error "Vendor id mismatch between Crypto.h and Crypto_Cfg.h"
#endif
/* Make sure the AUTOSAR major version number is the same between Crypto.h and Crypto_Cfg.h */
#if (CRYPTO_H_AR_RELEASE_MAJOR_VERSION != CRYPTO_CFG_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR major version number mismatch between Crypto.h and Crypto_Cfg.h"
#endif
/* Make sure the AUTOSAR minor version number is the same between Crypto.h and Crypto_Cfg.h */
#if (CRYPTO_H_AR_RELEASE_MINOR_VERSION != CRYPTO_CFG_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR minor version number mismatch between Crypto.h and Crypto_Cfg.h"
#endif
/* Make sure the AUTOSAR revision version number is the same between Crypto.h and Crypto_Cfg.h */
#if (CRYPTO_H_AR_RELEASE_REVISION_VERSION != CRYPTO_CFG_H_AR_RELEASE_REVISION_VERSION)
    #error "AUTOSAR revision version number mismatch between Crypto.h and Crypto_Cfg.h"
#endif
/* Make sure the software major version number is the same between Crypto.h and Crypto_Cfg.h */
#if (CRYPTO_H_SW_MAJOR_VERSION != CRYPTO_CFG_H_SW_MAJOR_VERSION)
    #error "Software major version number mismatch between Crypto.h and Crypto_Cfg.h"
#endif
/* Make sure the software minor version number is the same between Crypto.h and Crypto_Cfg.h */
#if (CRYPTO_H_SW_MINOR_VERSION != CRYPTO_CFG_H_SW_MINOR_VERSION)
    #error "Software minor version number mismatch between Crypto.h and Crypto_Cfg.h"
#endif
/* Make sure the software patch version number is the same between Crypto.h and Crypto_Cfg.h */
#if (CRYPTO_H_SW_PATCH_VERSION != CRYPTO_CFG_H_SW_PATCH_VERSION)
    #error "Software patch version number mismatch between Crypto.h and Crypto_Cfg.h"
#endif

#ifdef ENABLE_INTERMODULE_MCAL_CHECK
    /* Make sure the AUTOSAR major version number is the same between Crypto.h and Csm_Types.h */
    #if (CRYPTO_H_AR_RELEASE_MAJOR_VERSION != CSM_TYPES_H_AR_RELEASE_MAJOR_VERSION)
        #error "AUTOSAR major version number mismatch between Crypto.h and Csm_Types.h"
    #endif
    /* Make sure the AUTOSAR minor version number is the same between Crypto.h and Csm_Types.h */
    #if (CRYPTO_H_AR_RELEASE_MINOR_VERSION != CSM_TYPES_H_AR_RELEASE_MINOR_VERSION)
        #error "AUTOSAR minor version number mismatch between Crypto.h and Csm_Types.h"
    #endif
    /* Make sure the AUTOSAR major version number is the same between Crypto.h and Mcal.h */
    #if (CRYPTO_H_AR_RELEASE_MAJOR_VERSION != MCAL_H_AR_RELEASE_MAJOR_VERSION)
        #error "AUTOSAR major version number mismatch between Crypto.h and Mcal.h"
    #endif
    /* Make sure the AUTOSAR minor version number is the same between Crypto.h and Mcal.h */
    #if (CRYPTO_H_AR_RELEASE_MINOR_VERSION != MCAL_H_AR_RELEASE_MINOR_VERSION)
        #error "AUTOSAR minor version number mismatch between Crypto.h and Mcal.h"
    #endif
#endif
/*******************************************************************************
                        AUTOSAR API SERVICE IDS
*******************************************************************************/
/** Service ID for Crypto_ProcessJob function */
#define CRYPTO_SID_PROCESS_JOB                      ((uint8)0x03U)

#if (STD_ON == CRYPTO_DEV_ERR_DETECT_ENABLE)
    /** Service ID for Crypto_Init function */
    #define CRYPTO_SID_INIT                         ((uint8)0x00U)
    /** Service ID for Crypto_CancelJob function */
    #define CRYPTO_SID_CANCEL_JOB                   ((uint8)0x0EU)
    /** Service ID for Crypto_RandomSeed function */
    #define CRYPTO_SID_RANDOM_SEED                  ((uint8)0x0DU)
    /** Service ID for Crypto_KeyGenerate function */
    #define CRYPTO_SID_KEY_GENERATE                 ((uint8)0x07U)
    /** Service ID for Crypto_KeyDerive function */
    #define CRYPTO_SID_KEY_DERIVE                   ((uint8)0x08U)
    /** Service ID for Crypto_KeyExchangeCalcPubVal function */
    #define CRYPTO_SID_KEY_EXCHANGE_CALC_PUB_VAL    ((uint8)0x09U)
    /** Service ID for Crypto_KeyExchangeCalcSecret function */
    #define CRYPTO_SID_KEY_EXCHANGE_CALC_SECRET     ((uint8)0x0AU)
    /** Service ID for Crypto_CertificateParse function */
    #define CRYPTO_SID_CERTIFICATE_PARSE            ((uint8)0x0BU)
    /** Service ID for Crypto_CertificateVerify function */
    #define CRYPTO_SID_CERTIFICATE_VERIFY           ((uint8)0x12U)

    #if (STD_ON == CRYPTO_VERSION_INFO_API_ENABLE)
        /** Service ID for Crypto_GetVersionInfo function */
        #define CRYPTO_SID_GET_VERSION_INFO        ((uint8)0x01U)
    #endif /* STD_ON == CRYPTO_VERSION_INFO_API_ENABLE */

    #if (CRYPTO_KEYS_CONFIGURED == 1U)
        /** Service ID for Crypto_KeyElementSet function */
        #define CRYPTO_SID_KEY_ELEMENT_SET          ((uint8)0x04U)
        /** Service ID for Crypto_KeyValidSet function */
        #define CRYPTO_SID_KEY_SET_VALID            ((uint8)0x05U)
        /** Service ID for Crypto_KeyElementCopy function */
        #define CRYPTO_SID_KEY_ELEMENT_COPY         ((uint8)0x0FU)
        /** Service ID for Crypto_KeyCopy function */
        #define CRYPTO_SID_KEY_COPY                 ((uint8)0x10U)
        /** Service ID for Crypto_KeyElementIdsGet function */
        #define CRYPTO_SID_KEY_ELEMENT_IDS_GET      ((uint8)0x11U)
    #endif /* CRYPTO_KEYS_CONFIGURED == 1U */
#endif /* STD_ON == CRYPTO_DEV_ERR_DETECT_ENABLE */

#if (CRYPTO_KEYS_CONFIGURED == 1U)
    /** Service ID for Crypto_KeyElementGet function */
    #define CRYPTO_SID_KEY_ELEMENT_GET              ((uint8)0x06U)
#endif /* CRYPTO_KEYS_CONFIGURED == 1U */

/*******************************************************************************
                        DET DEVELOPMENT ERRORS
*******************************************************************************/

#if (STD_ON == CRYPTO_DEV_ERR_DETECT_ENABLE)
    /** API request called before initialization of Crypto Driver */
    #define CRYPTO_E_UNINIT                    ((uint8)0x00U)
    /** Initialization of Crypto Driver failed */
    #define CRYPTO_E_INIT_FAILED               ((uint8)0x01U)
    /** API request called with invalid parameter (null pointer) */
    #define CRYPTO_E_PARAM_POINTER             ((uint8)0x02U)
    /** API request called with invalid parameter (out of range) */
    #define CRYPTO_E_PARAM_HANDLE              ((uint8)0x04U)
    /** API request called with invalid parameter (invalid value) */
    #define CRYPTO_E_PARAM_VALUE               ((uint8)0x05U)
#endif /* CRYPTO_DEV_ERR_DETECT_ENABLE == 1U */

/*******************************************************************************
                        DET RUNTIME ERRORS
*******************************************************************************/

/** Buffer is too small for operation */
#define CRYPTO_E_RE_SMALL_BUFFER                ((uint8)0x00U)

#if (CRYPTO_KEYS_CONFIGURED == 1U)
    /** Requested key is not available */
    #define CRYPTO_E_RE_KEY_NOT_AVAILABLE       ((uint8)0x01U)
    /** Key cannot be read */
    #define CRYPTO_E_RE_KEY_READ_FAIL           ((uint8)0x02U)
#endif /* CRYPTO_KEYS_CONFIGURED == 1U */

/** Entropy is too low */
#define CRYPTO_E_RE_ENTROPY_EXHAUSTED           ((uint8)0x03U)

/*******************************************************************************
                            RETURNED ERROR CODES
*******************************************************************************/

/** The service request failed because the service is still busy */
#define CRYPTO_E_BUSY                           ((uint8)0x02U)
/** The service request failed because the provided buffer is too small to store the result */
#define CRYPTO_E_SMALL_BUFFER                   ((uint8)0x03U)
/** The service request failed because the entropy of the random number generator is exhausted */
#define CRYPTO_E_ENTROPY_EXHAUSTION             ((uint8)0x04U)
/** The service request failed because the queue is full */
#define CRYPTO_E_QUEUE_FULL                     ((uint8)0x05U)
/** The service request failed because read access failed */
#define CRYPTO_E_KEY_READ_FAIL                  ((uint8)0x06U)
/** The service request failed because write access failed */
#define CRYPTO_E_KEY_WRITE_FAIL                 ((uint8)0x07U)
/** The service request failed because the key is not available */
#define CRYPTO_E_KEY_NOT_AVAILABLE              ((uint8)0x08U)
/** The service request failed because at least one needed key element is invalid */
#define CRYPTO_E_KEY_NOT_VALID                  ((uint8)0x09U)

#if (CRYPTO_KEYS_CONFIGURED == 1U)
    /** The service request failed because the key element is not partially accessible and
     *  the provided key element length is too short or too long for that key element.
     */
    #define CRYPTO_E_KEY_SIZE_MISMATCH          ((uint8)0x0AU)
#endif /* CRYPTO_KEYS_CONFIGURED == 1U */

/** The service request failed because the counter overflowed */
#define CRYPTO_E_COUNTER_OVERFLOW               ((uint8)0x0BU)
/** The service request failed because the Job has been canceled */
#define CRYPTO_E_JOB_CANCELED                   ((uint8)0x0CU)
/**@} end of group CRYPTO_Macros */

/*******************************************************************************
                            FUNCTION DECLARATIONS
*******************************************************************************/
/** @defgroup CRYPTO_Fuctions
  @{
*/
#define CRYPTO_START_SEC_CODE
#include "Crypto_MemMap.h"

FUNC(void, CRYPTO_CODE) Crypto_Init(const Crypto_ConfigType* configPtr);

FUNC(Std_ReturnType, CRYPTO_CODE) Crypto_RandomSeed(
        VAR(uint32, AUTOMATIC) CryptoKeyId,
        P2CONST(uint8, AUTOMATIC, CRYPTO_APPL_CONST) SeedPtr,
        VAR(uint32, AUTOMATIC) SeedLength);

FUNC(Std_ReturnType, CRYPTO_CODE) Crypto_KeySetValid(
        VAR(uint32, AUTOMATIC) CryptoKeyId);

FUNC(Std_ReturnType, CRYPTO_CODE) Crypto_KeyValidSet(
        VAR(uint32, AUTOMATIC) CryptoKeyId);

FUNC(Std_ReturnType, CRYPTO_CODE) Crypto_KeyElementGet(
        VAR(uint32, AUTOMATIC) CryptoKeyId,
        VAR(uint32, AUTOMATIC) KeyElementId,
        P2VAR(uint8, AUTOMATIC, CRYPTO_APPL_DATA) ResultPtr,
        P2VAR(uint32, AUTOMATIC, CRYPTO_APPL_DATA) ResultLengthPtr);

FUNC(Std_ReturnType, CRYPTO_CODE) Crypto_KeyElementSet(
        VAR(uint32, AUTOMATIC) CryptoKeyId,
        VAR(uint32, AUTOMATIC) KeyElementId,
        P2CONST(uint8, AUTOMATIC, CRYPTO_APPL_CONST) KeyPtr,
        VAR(uint32, AUTOMATIC) KeyLength);

FUNC(Std_ReturnType, CRYPTO_CODE) Crypto_KeyGenerate(
        VAR(uint32, AUTOMATIC) CryptoKeyId);

FUNC(Std_ReturnType, CRYPTO_CODE) Crypto_KeyDerive(
        VAR(uint32, AUTOMATIC) CryptoKeyId,
        VAR(uint32, AUTOMATIC) TargetCryptoKeyId);

FUNC(Std_ReturnType, CRYPTO_CODE) Crypto_KeyCopy(
        VAR(uint32, AUTOMATIC) CryptoKeyId,
        VAR(uint32, AUTOMATIC) TargetCryptoKeyId);

FUNC(Std_ReturnType, CRYPTO_CODE) Crypto_KeyElementCopy(
        VAR(uint32, AUTOMATIC) CryptoKeyId,
        VAR(uint32, AUTOMATIC) KeyElementId,
        VAR(uint32, AUTOMATIC) TargetCryptoKeyId,
        VAR(uint32, AUTOMATIC) TargetKeyElementId);

FUNC(Std_ReturnType, CRYPTO_CODE) Crypto_KeyElementIdsGet(
        VAR(uint32, AUTOMATIC) CryptoKeyId,
        P2VAR(uint32, AUTOMATIC, CRYPTO_APPL_DATA) KeyElementIdsPtr,
        P2VAR(uint32, AUTOMATIC, CRYPTO_APPL_DATA) KeyElementIdsLengthPtr);

FUNC(Std_ReturnType, CRYPTO_CODE) Crypto_KeyExchangeCalcPubVal(
        VAR(uint32, AUTOMATIC) CryptoKeyId,
        P2CONST(uint8, AUTOMATIC, CRYPTO_APPL_DATA) PublicValuePtr,
        P2CONST(uint32, AUTOMATIC, CRYPTO_APPL_DATA) PublicValueLengthPtr);

FUNC(Std_ReturnType, CRYPTO_CODE) Crypto_KeyExchangeCalcSecret(
        VAR(uint32, AUTOMATIC) CryptoKeyId,
        P2CONST(uint8, AUTOMATIC, CRYPTO_APPL_CONST) PartnerPublicValuePtr,
        VAR(uint32, AUTOMATIC) PartnerPublicValueLength);

FUNC(Std_ReturnType, CRYPTO_CODE) Crypto_CertificateParse(
        VAR(uint32, AUTOMATIC) CryptoKeyId);

FUNC(Std_ReturnType, CRYPTO_CODE) Crypto_CertificateVerify(
        VAR(uint32, AUTOMATIC) CryptoKeyId,
        VAR(uint32, AUTOMATIC) VerifyCryptoKeyId,
        P2CONST(Crypto_VerifyResultType, AUTOMATIC, CRYPTO_APPL_DATA) VerifyPtr);

FUNC(Std_ReturnType, CRYPTO_CODE) Crypto_ProcessJob(
        VAR(uint32, AUTOMATIC) ObjectId,
        P2VAR(Crypto_JobType, AUTOMATIC, CRYPTO_APPL_DATA) Job);

FUNC(Std_ReturnType, CRYPTO_CODE) Crypto_CancelJob(
        VAR(uint32, AUTOMATIC) ObjectId,
        P2CONST(Crypto_JobInfoType, AUTOMATIC, CRYPTO_APPL_DATA) JobInfo);

FUNC(void, CRYPTO_CODE) Crypto_MainFunction(void);

#if (STD_ON == CRYPTO_VERSION_INFO_API_ENABLE)
FUNC(void, CRYPTO_CODE) Crypto_GetVersionInfo(
        P2VAR(Std_VersionInfoType, AUTOMATIC, CRYPTO_APPL_DATA) VersionInfo);
#endif /* STD_ON == CRYPTO_VERSION_INFO_API_ENABLE */

#define CRYPTO_STOP_SEC_CODE
#include "Crypto_MemMap.h"
/**@} end of group CRYPTO_Fuctions */
#ifdef __cplusplus
}
#endif

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