/**
*   @file    Crypto_Ipw.h
*   @version 1.0.0
*
*   @brief   AUTOSAR Crypto - Separation header layer of high-low level drivers.
*   @details Header interface between common and low level 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_IPW_H
#define CRYPTO_IPW_H

#ifdef __cplusplus
extern "C"{
#endif

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

/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================*/
#define CRYPTO_VENDOR_ID_IPW_H                       43
#define CRYPTO_AR_RELEASE_MAJOR_VERSION_IPW_H        4
#define CRYPTO_AR_RELEASE_MINOR_VERSION_IPW_H        3
#define CRYPTO_AR_RELEASE_REVISION_VERSION_IPW_H     1
#define CRYPTO_SW_MAJOR_VERSION_IPW_H                1
#define CRYPTO_SW_MINOR_VERSION_IPW_H                0
#define CRYPTO_SW_PATCH_VERSION_IPW_H                0

/*==================================================================================================
*                                     FILE VERSION CHECKS
==================================================================================================*/
/* Check if Crypto Ipw source file and Crypto Cse header file are of the same vendor */
#if (CRYPTO_VENDOR_ID_IPW_H != CRYPTO_CSE_VENDOR_ID )
    #error "Crypt_Ipw.h and Crypto_Cse.h have different vendor ids"
#endif

/* Check if Crypto Ipw source file and Crypto Cse header file are of the same Autosar version */
#if ((CRYPTO_AR_RELEASE_MAJOR_VERSION_IPW_H    != CRYPTO_CSE_AR_RELEASE_MAJOR_VERSION) || \
     (CRYPTO_AR_RELEASE_MINOR_VERSION_IPW_H    != CRYPTO_CSE_AR_RELEASE_MINOR_VERSION) || \
     (CRYPTO_AR_RELEASE_REVISION_VERSION_IPW_H != CRYPTO_CSE_AR_RELEASE_REVISION_VERSION) \
    )
    #error "AutoSar Version Numbers of Crypto_Ipw.h and Crypto_Cse.h are different"
#endif

/* Check if Crypto Ipw source file and Crypto Cse header file are of the same Software version */
#if ((CRYPTO_SW_MAJOR_VERSION_IPW_H != CRYPTO_CSE_SW_MAJOR_VERSION) || \
     (CRYPTO_SW_MINOR_VERSION_IPW_H != CRYPTO_CSE_SW_MINOR_VERSION) || \
     (CRYPTO_SW_PATCH_VERSION_IPW_H != CRYPTO_CSE_SW_PATCH_VERSION) \
    )
    #error "Software Version Numbers of Crypto_Ipw.h and Crypto_Cse.h are different"
#endif

/* Check if Crypto Ipw source file and Crypto Cfg header file are of the same vendor */
#if (CRYPTO_VENDOR_ID_IPW_H != CRYPTO_VENDOR_ID_CFG )
    #error "Crypt_Ipw.h and Crypto_Cfg.h have different vendor ids"
#endif

/* Check if Crypto Ipw source file and Crypto Cfg header file are of the same Autosar version */
#if ((CRYPTO_AR_RELEASE_MAJOR_VERSION_IPW_H    != CRYPTO_AR_RELEASE_MAJOR_VERSION_CFG ) || \
     (CRYPTO_AR_RELEASE_MINOR_VERSION_IPW_H    != CRYPTO_AR_RELEASE_MINOR_VERSION_CFG) || \
     (CRYPTO_AR_RELEASE_REVISION_VERSION_IPW_H != CRYPTO_AR_RELEASE_REVISION_VERSION_CFG) \
    )
    #error "AutoSar Version Numbers of Crypto_Ipw.h and Crypto_Cfg.h are different"
#endif

/* Check if Crypto Ipw source file and Crypto Cfg header file are of the same Software version */
#if ((CRYPTO_SW_MAJOR_VERSION_IPW_H != CRYPTO_SW_MAJOR_VERSION_CFG) || \
     (CRYPTO_SW_MINOR_VERSION_IPW_H != CRYPTO_SW_MINOR_VERSION_CFG) || \
     (CRYPTO_SW_PATCH_VERSION_IPW_H != CRYPTO_SW_PATCH_VERSION_CFG) \
    )
    #error "Software Version Numbers of Crypto_Ipw.h and Crypto_Cfg.h are different"
#endif

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

/*==================================================================================================
*                                      DEFINES AND MACROS
==================================================================================================*/
#define     Crypto_Ipw_Init() \
           (Crypto_Cse_Init())

#define     Crypto_Ipw_MainFunction() \
           (Crypto_Cse_MainFunction())

#define     Crypto_Ipw_ProcessJob(objectIdIdx, job) \
           (Crypto_Cse_ProcessJob(objectIdIdx, job))

#define     Crypto_Ipw_CancelJob(objectIdIdx, job) \
           (Crypto_Cse_CancelJob(objectIdIdx, job))
           
#if (STD_ON == CRYPTO_KEYS_EXIST)

    #define    Crypto_Ipw_LoadKey(pKeyPtr,u32KeyLength,cryptoKeyId) \
              (Crypto_Cse_LoadKey(pKeyPtr,cryptoKeyId))
           

    #define     Crypto_Ipw_ExportKey(cryptoKeyId, pResult, pResultLength) \
               (Crypto_Cse_ExportKey(cryptoKeyId, pResult, pResultLength))


    #define     Crypto_Ipw_GenerateKey(KeyId, u32KeyBaseExchange) \
               (Crypto_Cse_GenerateKey(KeyId))

    #define     Crypto_Ipw_GenerateSeed(pSeed, u32SeedLength, pSeedState) \
               (Crypto_Cse_GenerateSeed(pSeed, u32SeedLength, pSeedState))

    /* Not supported  */
    #define     Crypto_Ipw_KeyDerive(keyIdIdx, targetKeyIdIdx) ((Std_ReturnType)CRYPTO_E_NOT_SUPPORTED)
    
    #define     Crypto_Ipw_CalcSecret(pPartnerPublicValue, partnerPublicValueLength, keyHandlePriv, keyHandlePub, keyHandleShared) ((Std_ReturnType)CRYPTO_E_NOT_SUPPORTED)
    
    #define     Crypto_Ipw_CertificateParse(keyIdIdx) ((Std_ReturnType)CRYPTO_E_NOT_SUPPORTED)
    
    #define     Crypto_Ipw_CertificateVerify(keyIdIdx, verifyKeyIdIdx, verifyPtr) ((Std_ReturnType)CRYPTO_E_NOT_SUPPORTED)

#endif /* (STD_ON == CRYPTO_KEYS_EXIST) */


/* Autosar extension functionalities */
#define Crypto_Ipw_ExtsDebugChal(pOutChallengeAdress)\
       (Crypto_Cse_DebugChallenge(pOutChallengeAdress))
       
#define Crypto_Ipw_ExtsDebugAuth(pAuthorization)\
       (Crypto_Cse_DebugAuthorization(pAuthorization))

/* MP compression is triggered as a synchronous command*/
#define Crypto_Ipw_ExtsMPCompression(pInputKey,pInputKeyBitLen,pResult)\
       (Crypto_Cse_MPCompression(pInputKey,pInputKeyBitLen,pResult,CRYPTO_PROCESSING_SYNC))

#define Crypto_Ipw_ExtsInitializeRng()\
       (Crypto_Cse_InitRng())

#define Crypto_Ipw_ExtsGenerateTrueRndNum(pRandomValue)\
       (Crypto_Cse_GenerateTrueRandom(pRandomValue))

#define Crypto_Ipw_ExtsExtendPrngSeed(pEntropy)\
       (Crypto_Cse_ExtendPrngSeed(pEntropy))

#define Crypto_Ipw_ExtsGetId(pUidResultAddr, pMacAddr, pSregAddr) \
       (Crypto_Cse_GetID(pUidResultAddr, pMacAddr, pSregAddr))
       
#define Crypto_Ipw_ExtsBootFailure() \
       (Crypto_Cse_BootFailure())

#define Crypto_Ipw_ExtsBootOk() \
       (Crypto_Cse_BootOk())

#define Crypto_Ipw_ExtsCfgSecCounter(CounterID, RolloverValue, Status) \
       (Crypto_Cse_CfgSecCounter(CounterID, RolloverValue, Status))

#define Crypto_Ipw_ExtsSecureSesssionChal(pOutChallengeAdress,u8CertificateId,u8ChallengeMode) \
       (Crypto_Cse_SessionChallenge(pOutChallengeAdress,u8CertificateId,u8ChallengeMode))

#define Crypto_Ipw_ExtsSecureSesssionAuth(pAuthorization) \
       (Crypto_Cse_SecureSessionAuth(pAuthorization))

#define Crypto_Ipw_ExtsDeletePlainTextKey(u8KeyId) \
       (Crypto_Cse_DeletePlainTextKey(u8KeyId))

#define Crypto_Ipw_ExtsMacGenerateSecCounter(KeyId, CounterId, MessageLength, pMessage, pMac, MacLen, pVolatileCounter) \
       (Crypto_Cse_MacGenerateSecCounter(KeyId, CounterId, MessageLength, pMessage, pMac, MacLen, pVolatileCounter))

#define Crypto_Ipw_ExtsMacVerifySecCounter(KeyId, CounterId, RlvPrtOffset, MessageLength, pMessage, pMac, MacLen, VolatileCounter, pStatus) \
       (Crypto_Cse_MacVerifySecCounter(KeyId, CounterId, RlvPrtOffset, MessageLength, pMessage, pMac, MacLen, VolatileCounter, pStatus))

#define Crypto_Ipw_Exts_InstallCertificate(u8CertifId,u8AuthCertifId,pCertifAddr,u8CertifType) \
       (Crypto_Cse_InstallCertificate(u8CertifId,u8AuthCertifId,pCertifAddr,u8CertifType))

#define Crypto_Ipw_Exts_VerifySignature(u8AuthCertifId,pMessAddr,u32MessLen,pSignatureAddr,u32VerifStatus,bClearBootMac) \
        (Crypto_Cse_VerifySignature(u8AuthCertifId,pMessAddr,u32MessLen,pSignatureAddr,u32VerifStatus,bClearBootMac))
        
#define Crypto_Ipw_Exts_BRCS(eBrcsMode,pImageAddress,pKeySlotStatus,pCounterSlotStatus) \
        (Crypto_Cse_BRCS(eBrcsMode,pImageAddress,pKeySlotStatus,pCounterSlotStatus))

#define Crypto_Ipw_ExtsUpdateFirmware(pFirmwareAddr,pSignatureAddr,u8AuthCertifId,pNewFirmVersion,pCurrentFirmVersion) \
        (Crypto_Cse_UpdateFirmware(pFirmwareAddr,pSignatureAddr,u8AuthCertifId,pNewFirmVersion,pCurrentFirmVersion))

/*==================================================================================================
*                                             ENUMS
==================================================================================================*/

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

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

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

#ifdef __cplusplus
}
#endif

#endif /* CRYPTO_IPW_H */

/** @} */
