/***********************************************************************************************************************
 *  COPYRIGHT
 *  ------------------------------------------------------------------------------------------------------------------
 *  \verbatim
 *  Copyright (c) 2025 by Vector Informatik GmbH.                                                  All rights reserved.
 *
 *                This software is copyright protected and proprietary to Vector Informatik GmbH.
 *                Vector Informatik GmbH grants to you only those rights as set out in the license conditions.
 *                All other rights remain with Vector Informatik GmbH.
 *  \endverbatim
 *  ------------------------------------------------------------------------------------------------------------------
 *  FILE DESCRIPTION
 *  ------------------------------------------------------------------------------------------------------------------*/
/*!        \file  Crypto_30_LibCv_KeyWrap.c
 *        \brief  MICROSAR Crypto Driver (Crypto)
 *      \details  Implementation for key wrapping and unwrapping services
 **********************************************************************************************************************/

 /***********************************************************************************************************************
  *  REVISION HISTORY
  *  ------------------------------------------------------------------------------------------------------------------
  *  Refer to the module's header file.
  *
  *  FILE VERSION
  *  ------------------------------------------------------------------------------------------------------------------
  *  Refer to the VERSION CHECK below.
  **********************************************************************************************************************/

#define CRYPTO_30_LIBCV_KEYWRAP_SOURCE

/***********************************************************************************************************************
 *  INCLUDES
 **********************************************************************************************************************/
#include "Crypto_30_LibCv.h"
#include "Crypto_30_LibCv_Services.h"
#include "Crypto_30_LibCv_KeyUnwrap.h"
#include "Crypto_30_LibCv_KeyWrap.h"

/***********************************************************************************************************************
 *  LOCAL CONSTANT MACROS
 **********************************************************************************************************************/

/***********************************************************************************************************************
 *  LOCAL FUNCTION MACROS
 **********************************************************************************************************************/

/***********************************************************************************************************************
 *  LOCAL DATA TYPES AND STRUCTURES
 **********************************************************************************************************************/

/***********************************************************************************************************************
 *  LOCAL DATA PROTOTYPES
 **********************************************************************************************************************/

/***********************************************************************************************************************
 *  GLOBAL DATA
 **********************************************************************************************************************/

/***********************************************************************************************************************
 *  LOCAL FUNCTION PROTOTYPES
 **********************************************************************************************************************/
#define CRYPTO_30_LIBCV_START_SEC_CODE
#include "Crypto_30_LibCv_MemMap.h" /* PRQA S 5087 */ /* MD_MSR_MemMap */

#if ((CRYPTO_30_LIBCV_KEYWRAPAES == STD_ON) || (CRYPTO_30_LIBCV_KEYUNWRAPAES == STD_ON))
/**********************************************************************************************************************
 *  Crypto_30_LibCv_Dispatch_KeyWrappingAesStart()
 *********************************************************************************************************************/
/*!
 * \brief           This function dispatches and executes the Key Wrap/Unwrap Aes init function.
 * \details         This function initializes the vSecPrim workspace, gets the key encryption key and determines the
 *                  Aes variant according to the key length.
 *                  Supported variants are:
 *                  - Key Wrap/Unwrap Aes 128
 *                  - Key Wrap/Unwrap Aes 192
 *                  - Key Wrap/Unwrap Aes 256
 * \param[in,out]   workspace        Pointer to the vSecPrim key wrap/unwrap workspace.
 * \param[in]       job           Pointer to the job which shall be dispatched.
 * \param[in]       mode          Mode of the start function - it determines whether the start is used for a key wrap
 *                                or a key unwrap. The supported modes are:
 *                                - ESL_KEYWRAP_WRAP_MODE
 *                                - ESL_KEYWRAP_UNWRAP_MODE
 * \return          E_OK                        Dispatching was successful.
 * \return          E_NOT_OK                    Dispatching failed.
 * \return          CRYPTO_E_KEY_NOT_VALID      Request failed, the key is not valid.
 * \return          CRYPTO_E_KEY_SIZE_MISMATCH  Request failed, the provided buffer is too small to store the result.
 * \pre             job has to be a pointer to a valid job object.
 * \context         TASK
 * \reentrant       TRUE
 * \synchronous     TRUE
 *********************************************************************************************************************/
CRYPTO_30_LIBCV_LOCAL_INLINE FUNC(Std_ReturnType, CRYPTO_30_LIBCV_CODE) Crypto_30_LibCv_Dispatch_KeyWrappingAesStart(
  P2VAR(eslt_WorkspaceAESKeyWrap, AUTOMATIC, CRYPTO_30_LIBCV_APPL_VAR) workspace,
  P2CONST(Crypto_JobType, AUTOMATIC, CRYPTO_30_LIBCV_APPL_VAR) job, eslt_Mode mode);
#endif /* ((CRYPTO_30_LIBCV_KEYWRAPAES == STD_ON) || (CRYPTO_30_LIBCV_KEYUNWRAPAES == STD_ON)) */

#if (CRYPTO_30_LIBCV_KEYWRAPAES == STD_ON)
/**********************************************************************************************************************
 *  Crypto_30_LibCv_Dispatch_KeyWrapAesFinish()
 *********************************************************************************************************************/
/*!
 * \brief           This function dispatches and executes the Key Wrap Aes finish function.
 * \details         This function gets the key to wrap, checks its length and calls the underlying vSecPrim function
 * \param[in,out]   workspace     Pointer to the vSecPrim workspace.
 * \param[in]       job           Pointer to the job which shall be dispatched.
 * \return          E_OK                         Dispatching was successful.
 * \return          E_NOT_OK                     Dispatching failed.
 * \return          CRYPTO_E_KEY_NOT_VALID       Request failed, the key is not valid.
 * \return          CRYPTO_E_KEY_SIZE_MISMATCH   Request failed, the provided buffer is too small to store the result.
 * \pre             job has to be a pointer to a valid job object.
 * \context         TASK
 * \reentrant       TRUE
 * \synchronous     TRUE
 *********************************************************************************************************************/
CRYPTO_30_LIBCV_LOCAL_INLINE FUNC(Std_ReturnType, CRYPTO_30_LIBCV_CODE) Crypto_30_LibCv_Dispatch_KeyWrapAesFinish(
  P2VAR(eslt_WorkspaceAESKeyWrap, AUTOMATIC, CRYPTO_30_LIBCV_APPL_VAR) workspace,
  P2CONST(Crypto_JobType, AUTOMATIC, CRYPTO_30_LIBCV_APPL_VAR) job);
#endif /* (CRYPTO_30_LIBCV_KEYWRAPAES == STD_ON) */

#if (CRYPTO_30_LIBCV_KEYUNWRAPAES == STD_ON)
/**********************************************************************************************************************
 *  Crypto_30_LibCv_Dispatch_KeyUnwrapAesFinish()
 *********************************************************************************************************************/
/*!
 * \brief           This function dispatches and executes the Key Unwrap Aes finish function.
 * \details         This function checks the length of the input ptr:
 * \param[in,out]   workspace     Pointer to the vSecPrim hash workspace.
 * \param[in]       job           Pointer to the job which shall be dispatched.
 * \param[in]       objectId      Holds the identifier of the Crypto Driver Object.
 * \return          E_OK          Dispatching was successful.
 *                  E_NOT_OK      Dispatching failed.
 *                  CRYPTO_E_KEY_WRITE_FAIL Request failed, write access was denied.
 *                  CRYPTO_E_KEY_NOT_AVAILABLE  Request failed, the key is not available.
 *                  CRYPTO_E_KEY_SIZE_MISMATCH  Request failed, the key element sizes are not compatible.
 * \pre             job has to be a pointer to a valid job object.
 *                  inputPtrLength must be at least 3 * ESL_SIZEOF_AES_SEMIBLOCK and
 *                  a multiple of ESL_SIZEOF_AES_SEMIBLOCK
 * \context         TASK
 * \reentrant       TRUE
 * \synchronous     TRUE
 *********************************************************************************************************************/
CRYPTO_30_LIBCV_LOCAL_INLINE FUNC(Std_ReturnType, CRYPTO_30_LIBCV_CODE) Crypto_30_LibCv_Dispatch_KeyUnwrapAesFinish(
  P2VAR(eslt_WorkspaceAESKeyWrap, AUTOMATIC, CRYPTO_30_LIBCV_APPL_VAR) workspace,
  P2CONST(Crypto_JobType, AUTOMATIC, CRYPTO_30_LIBCV_APPL_VAR) job,
  uint32 objectId);
#endif /* (CRYPTO_30_LIBCV_KEYUNWRAPAES == STD_ON) */

/**********************************************************************************************************************
 *  LOCAL FUNCTIONS
 *********************************************************************************************************************/

#if ((CRYPTO_30_LIBCV_KEYWRAPAES == STD_ON) || (CRYPTO_30_LIBCV_KEYUNWRAPAES == STD_ON))
/**********************************************************************************************************************
 *  Crypto_30_LibCv_Dispatch_KeyWrappingAesStart()
 **********************************************************************************************************************/
/*!
 *
 * Internal comment removed.
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */
CRYPTO_30_LIBCV_LOCAL_INLINE FUNC(Std_ReturnType, CRYPTO_30_LIBCV_CODE) Crypto_30_LibCv_Dispatch_KeyWrappingAesStart(
  P2VAR(eslt_WorkspaceAESKeyWrap, AUTOMATIC, CRYPTO_30_LIBCV_APPL_VAR) workspace,
  P2CONST(Crypto_JobType, AUTOMATIC, CRYPTO_30_LIBCV_APPL_VAR) job, eslt_Mode mode)
{
  Std_ReturnType retVal = E_NOT_OK;
  eslt_ErrorCode retValCv = ESL_ERC_ERROR;

  /* # Initialize workspace header. */
  retValCv = esl_initWorkSpaceHeader(&(workspace->header), ESL_MAXSIZEOF_WS_AESKEYWRAP, CRYPTO_30_LIBCV_WATCHDOG_PTR); /* PRQA S 3395 */ /* MD_CRYPTO_30_LIBCV_3395 */ /* SBSW_CRYPTO_30_LIBCV_INIT_ESL_WORKSPACE */

  if (retValCv == ESL_ERC_NO_ERROR)
  {
    eslt_Mode cipher = 0u;

    /* get key encryption/wrapping key */
    P2CONST(eslt_Byte, AUTOMATIC, CRYPTO_30_LIBCV_APPL_VAR) keyEncryptionKey = NULL_PTR;
    Crypto_30_LibCv_SizeOfKeyStorageType indexOfkeyEncryptionKey = 0u;
    uint32 keyEncryptionKeyLength = ESL_SIZEOF_AES128_KEY; /* key must be at least 16 bytes for key wrapping with AES128, it must be larger for other AES variants */

    /* get index of key to encrypt */
    retVal = Crypto_30_LibCv_Local_KeyElementGetStorageIndexJob(job->cryptoKeyId, CRYPTO_KE_CIPHER_KEY, &indexOfkeyEncryptionKey, &keyEncryptionKeyLength, CRYPTO_30_LIBCV_LENGTH_CHECK_MIN); /* SBSW_CRYPTO_30_LIBCV_STACK_ARRAY_VARIABLE_AS_PTR */

    if (retVal == E_OK)
    {
      keyEncryptionKey = Crypto_30_LibCv_GetAddrKeyStorage(indexOfkeyEncryptionKey);

      /* length check to get ID of the used cipher */
      switch (keyEncryptionKeyLength)
      {
        case ESL_SIZEOF_AES128_KEY:
        {
          cipher = ESL_KEYWRAP_AES128;
          break;
        }

        case ESL_SIZEOF_AES192_KEY:
        {
          cipher = ESL_KEYWRAP_AES192;
          break;
        }

        case ESL_SIZEOF_AES256_KEY:
        {
          cipher = ESL_KEYWRAP_AES256;
          break;
        }

        default:
        {
          /* Kek is invalid */
          retVal = E_NOT_OK;
          break;
        }
      }
    }

    if (retVal == E_OK)
    {
      retValCv = esl_initAESKeyWrap(workspace, keyEncryptionKey, (eslt_Length)keyEncryptionKeyLength, cipher, mode); /* SBSW_CRYPTO_30_LIBCV_ESL_CALL_WITH_WORKSPACE_AND_STACK_BUFFER */

      if (retValCv == ESL_ERC_NO_ERROR)
      {
        retVal = E_OK;
      }
      else
      {
        retVal = E_NOT_OK;
      }
    }
  }

  return retVal;
} /* Crypto_30_LibCv_Dispatch_KeyWrappingAesStart() */
#endif

#if (CRYPTO_30_LIBCV_KEYWRAPAES == STD_ON)
/**********************************************************************************************************************
 *  Crypto_30_LibCv_Dispatch_KeyWrapAesFinish()
 **********************************************************************************************************************/
/*!
 *
 * Internal comment removed.
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */
CRYPTO_30_LIBCV_LOCAL_INLINE FUNC(Std_ReturnType, CRYPTO_30_LIBCV_CODE) Crypto_30_LibCv_Dispatch_KeyWrapAesFinish(
  P2VAR(eslt_WorkspaceAESKeyWrap, AUTOMATIC, CRYPTO_30_LIBCV_APPL_VAR) workspace,
  P2CONST(Crypto_JobType, AUTOMATIC, CRYPTO_30_LIBCV_APPL_VAR) job)
{
  Std_ReturnType retVal = E_NOT_OK;
  eslt_ErrorCode retValCv = ESL_ERC_ERROR;

  /* get key to wrap */
  P2CONST(eslt_Byte, AUTOMATIC, CRYPTO_30_LIBCV_APPL_VAR) plaintextKey = NULL_PTR;
  Crypto_30_LibCv_SizeOfKeyStorageType indexOfPlaintextKey = 0u;
  uint32 plaintextKeyLength = ESL_SIZEOF_AES_BLOCK; /* key must be at least 16 bytes */

  /*  get index of the plaintext key and check if the key element is big enough */
  retVal = Crypto_30_LibCv_Local_KeyElementGetStorageIndexJob(job->targetCryptoKeyId, CRYPTO_KE_KEYWRAP_KEY, &indexOfPlaintextKey, &plaintextKeyLength, CRYPTO_30_LIBCV_LENGTH_CHECK_MIN); /* SBSW_CRYPTO_30_LIBCV_STACK_ARRAY_VARIABLE_AS_PTR */

  if (retVal == E_OK)
  {
    plaintextKey = Crypto_30_LibCv_GetAddrKeyStorage(indexOfPlaintextKey);

    /* the plaintext key must be a multiple of ESL_SIZEOF_AES_SEMIBLOCK */
    if ((plaintextKeyLength % ESL_SIZEOF_AES_SEMIBLOCK) != 0u)
    {
      retVal = E_NOT_OK;
    }
    /* the buffer for wrapped key must be at least plaintextKeyLength + ESL_SIZEOF_AES_SEMIBLOCK */
    else if (*job->CRYPTO_30_LIBCV_JOB_PRIMITIVE_INPUT_OUTPUT_MEMBER.outputLengthPtr < (plaintextKeyLength + ESL_SIZEOF_AES_SEMIBLOCK))
    {
      retVal = E_NOT_OK;
    }
    else
    {
      eslt_Length outputLength = (eslt_Length)*(job->CRYPTO_30_LIBCV_JOB_PRIMITIVE_INPUT_OUTPUT_MEMBER.outputLengthPtr);

      /* call vSecPrim key wrap function */
      retValCv = esl_wrapAESKeyWrap(workspace,
        (P2CONST(eslt_Byte, AUTOMATIC, CRYPTO_30_LIBCV_CRYPTOCV_APPL_VAR)) plaintextKey,
        (eslt_Length)plaintextKeyLength,
        (P2VAR(eslt_Byte, AUTOMATIC, CRYPTO_30_LIBCV_CRYPTOCV_APPL_VAR))job->CRYPTO_30_LIBCV_JOB_PRIMITIVE_INPUT_OUTPUT_MEMBER.outputPtr,
        (P2VAR(eslt_Length, AUTOMATIC, CRYPTO_30_LIBCV_CRYPTOCV_APPL_VAR))&outputLength); /* SBSW_CRYPTO_30_LIBCV_ESL_CALL_WITH_WORKSPACE_AND_BUFFER_AND_STACK_BUFFER */

      *job->CRYPTO_30_LIBCV_JOB_PRIMITIVE_INPUT_OUTPUT_MEMBER.outputLengthPtr = (uint32)outputLength; /* SBSW_CRYPTO_30_LIBCV_WRITE_ACCESS_TO_JOBPRIMITIVE_INPUTOUTPUT_PTR */

      if (retValCv == ESL_ERC_NO_ERROR)
      {
        retVal = E_OK;
      }
      else
      {
        retVal = E_NOT_OK;
      }
    }
  }

  return retVal;
} /* Crypto_30_LibCv_Dispatch_KeyWrapAesFinish() */

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

#if (CRYPTO_30_LIBCV_KEYUNWRAPAES == STD_ON)
/**********************************************************************************************************************
 *  Crypto_30_LibCv_Dispatch_KeyUnwrapAesFinish()
 **********************************************************************************************************************/
/*!
 *
 * Internal comment removed.
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */
/* PRQA S 6080 3 */ /* MD_MSR_STMIF */
CRYPTO_30_LIBCV_LOCAL_INLINE FUNC(Std_ReturnType, CRYPTO_30_LIBCV_CODE) Crypto_30_LibCv_Dispatch_KeyUnwrapAesFinish(
  P2VAR(eslt_WorkspaceAESKeyWrap, AUTOMATIC, CRYPTO_30_LIBCV_APPL_VAR) workspace,
  P2CONST(Crypto_JobType, AUTOMATIC, CRYPTO_30_LIBCV_APPL_VAR) job,
  uint32 objectId)
{
  Std_ReturnType retVal = E_NOT_OK;
  eslt_ErrorCode retValCv = ESL_ERC_ERROR;
  *(job->CRYPTO_30_LIBCV_JOB_PRIMITIVE_INPUT_OUTPUT_MEMBER.verifyPtr) = CRYPTO_E_VER_NOT_OK; /* SBSW_CRYPTO_30_LIBCV_WRITE_ACCESS_TO_JOBPRIMITIVE_INPUTOUTPUT_PTR */

  /* length check - input length must be at least 3u * ESL_SIZEOF_AES_SEMIBLOCK bytes */
  if (job->CRYPTO_30_LIBCV_JOB_PRIMITIVE_INPUT_OUTPUT_MEMBER.inputLength < (uint32)(3u * ESL_SIZEOF_AES_SEMIBLOCK))
  {
    retVal = E_NOT_OK;
  }
  /* length of the input must be a multiple of ESL_SIZEOF_AES_SEMIBLOCK */
  else if ((job->CRYPTO_30_LIBCV_JOB_PRIMITIVE_INPUT_OUTPUT_MEMBER.inputLength % ESL_SIZEOF_AES_SEMIBLOCK) != 0u)
  {
    retVal = E_NOT_OK;
  }
  else
  {
    /*  get index of key where the plaintext key should be stored */
    P2VAR(eslt_Byte, AUTOMATIC, CRYPTO_30_LIBCV_APPL_VAR) plaintextKey = NULL_PTR;
    Crypto_30_LibCv_SizeOfKeyElementsType indexOfPlaintextKey = 0u;
    eslt_Length plaintextKeyLength = (eslt_Length) (job->CRYPTO_30_LIBCV_JOB_PRIMITIVE_INPUT_OUTPUT_MEMBER.inputLength - ESL_SIZEOF_AES_SEMIBLOCK);

    retVal = Crypto_30_LibCv_KeyElementSet_PreCheckWriteAccessAndLength(job->targetCryptoKeyId, CRYPTO_KE_KEYWRAP_KEY, &indexOfPlaintextKey, plaintextKeyLength, CRYPTO_30_LIBCV_WA_INTERNAL_COPY);  /* SBSW_CRYPTO_30_LIBCV_STACK_ARRAY_VARIABLE_AS_PTR */

    if (retVal == E_OK)
    {
      plaintextKey = Crypto_30_LibCv_GetAddrKeyStorage(Crypto_30_LibCv_GetKeyStorageStartIdxOfKeyElements(indexOfPlaintextKey));
      eslt_Length inputLen = (eslt_Length)job->CRYPTO_30_LIBCV_JOB_PRIMITIVE_INPUT_OUTPUT_MEMBER.inputLength;

      retValCv = esl_unwrapAESKeyWrap(workspace,
                  (P2CONST(eslt_Byte, AUTOMATIC, CRYPTO_30_LIBCV_CRYPTOCV_APPL_VAR))job->CRYPTO_30_LIBCV_JOB_PRIMITIVE_INPUT_OUTPUT_MEMBER.inputPtr,
                  inputLen, plaintextKey,
                  (P2VAR(eslt_Length, AUTOMATIC, CRYPTO_30_LIBCV_CRYPTOCV_APPL_VAR)) &plaintextKeyLength); /* SBSW_CRYPTO_30_LIBCV_ESL_CALL_WITH_WORKSPACE_AND_BUFFER_AND_STACK_BUFFER */

      if (retValCv == ESL_ERC_NO_ERROR)
      {
        /* Update key element. */
        Crypto_30_LibCv_Local_SetKeyElementStateWritten(indexOfPlaintextKey);
        Crypto_30_LibCv_SetKeyElementWrittenLengthWithCryptoKeyId(job->targetCryptoKeyId, indexOfPlaintextKey, plaintextKeyLength);

        /* set key to valid */
        Crypto_30_LibCv_SetProcessJob_Trigger_Write(objectId, Crypto_30_LibCv_Internal_KeySetValid(job->targetCryptoKeyId)); /* SBSW_CRYPTO_30_LIBCV_CSL01_OBJECTID */

        *(job->CRYPTO_30_LIBCV_JOB_PRIMITIVE_INPUT_OUTPUT_MEMBER.verifyPtr) = CRYPTO_E_VER_OK; /* SBSW_CRYPTO_30_LIBCV_WRITE_ACCESS_TO_JOBPRIMITIVE_INPUTOUTPUT_PTR */

        retVal = E_OK;
      }
      else if (retValCv == ESL_ERC_VERIFICATION_FAILED)
      {
        /* verification ptr has already been set to CRYPTO_E_VER_NOT_OK */
        retVal = E_OK;
      }
      else
      {
        /* verification ptr has already been set to CRYPTO_E_VER_NOT_OK */
        retVal = E_NOT_OK;
      }
    }
  }

  return retVal;
} /* Crypto_30_LibCv_Dispatch_KeyUnwrapAesFinish() */

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

/***********************************************************************************************************************
 *  GLOBAL FUNCTIONS
 **********************************************************************************************************************/

#if (CRYPTO_30_LIBCV_KEYWRAPAES == STD_ON)
/***********************************************************************************************************************
 *  Crypto_30_LibCv_Dispatch_KeyWrapAes()
 **********************************************************************************************************************/
/*!
 * Internal comment removed.
 *
 *
 *
 *
 *
 *
 *
 *
 */
FUNC(Std_ReturnType, CRYPTO_30_LIBCV_CODE) Crypto_30_LibCv_Dispatch_KeyWrapAes(
  uint32 objectId,
  P2VAR(Crypto_JobType, AUTOMATIC, CRYPTO_30_LIBCV_APPL_VAR) job, /* PRQA S 3673 */ /* MD_CRYPTO_30_LIBCV_3673_1 */
  Crypto_OperationModeType mode)
{
  /* ----- Local Variables ---------------------------------------------- */
  Std_ReturnType retVal = E_NOT_OK;

  /* ----- Implementation ----------------------------------------------- */
  /* job is single call only */
  if (Crypto_30_LibCv_IsJobMode(job, CRYPTO_OPERATIONMODE_SINGLECALL))
  {
    P2VAR(eslt_WorkspaceAESKeyWrap, AUTOMATIC, CRYPTO_30_LIBCV_CRYPTOCV_APPL_VAR) workspace = Crypto_30_LibCv_GetWorkspaceOfKeyWrapAes(Crypto_30_LibCv_GetKeyWrapAesIdxOfObjectInfo(objectId));

      /* # Distinguish modes. */
    switch (mode)
    {
      /* # Handle operationmode START. */
      case CRYPTO_OPERATIONMODE_START:
        /* note: key wrap and unwrap have the same init-API */
        retVal = Crypto_30_LibCv_Dispatch_KeyWrappingAesStart(workspace, job, ESL_KEYWRAP_WRAP_MODE); /* SBSW_CRYPTO_30_LIBCV_ESL_CALL_WITH_WORKSPACE_AND_BUFFERS */
        break;

      /* # Handle operationmode UPDATE. */
      case CRYPTO_OPERATIONMODE_UPDATE:
        retVal = E_OK;
        break;

      /* # Handle operationmode FINISH. */
      case CRYPTO_OPERATIONMODE_FINISH:
        retVal = Crypto_30_LibCv_Dispatch_KeyWrapAesFinish(workspace, job); /* SBSW_CRYPTO_30_LIBCV_ESL_CALL_WITH_WORKSPACE_AND_BUFFERS */
        break;

      default:  /* COV_CRYPTO_30_LIBCV_MISRA_ADDITIONAL_STATEMENT */
        /* Not supported State */
        break;
    }
  }

  return retVal;
} /* Crypto_30_LibCv_Dispatch_KeyWrapAes() */
#endif /* (CRYPTO_30_LIBCV_KEYWRAPAES == STD_ON) */

#if (CRYPTO_30_LIBCV_KEYUNWRAPAES == STD_ON)
/***********************************************************************************************************************
 *  Crypto_30_LibCv_Dispatch_KeyUnwrapAes()
 **********************************************************************************************************************/
/*!
 * Internal comment removed.
 *
 *
 *
 *
 *
 *
 *
 *
 */
FUNC(Std_ReturnType, CRYPTO_30_LIBCV_CODE) Crypto_30_LibCv_Dispatch_KeyUnwrapAes(
  uint32 objectId,
  P2VAR(Crypto_JobType, AUTOMATIC, CRYPTO_30_LIBCV_APPL_VAR) job, /* PRQA S 3673 */ /* MD_CRYPTO_30_LIBCV_3673_1 */
  Crypto_OperationModeType mode)
{
  /* ----- Local Variables ---------------------------------------------- */
  Std_ReturnType retVal = E_NOT_OK;

  /* job is single call only */
  if (Crypto_30_LibCv_IsJobMode(job, CRYPTO_OPERATIONMODE_SINGLECALL))
  {
    /* ----- Implementation ----------------------------------------------- */
    P2VAR(eslt_WorkspaceAESKeyWrap, AUTOMATIC, CRYPTO_30_LIBCV_CRYPTOCV_APPL_VAR) workspace = Crypto_30_LibCv_GetWorkspaceOfKeyUnwrapAes(Crypto_30_LibCv_GetKeyUnwrapAesIdxOfObjectInfo(objectId));
    Crypto_30_LibCv_SetLengthOfSaveAndRestoreWorkspace(objectId, sizeof(eslt_WorkspaceAESKeyWrap)); /* SBSW_CRYPTO_30_LIBCV_FORWARDING_SIZEOFWORKSPACELENGTH */

      /* # Distinguish modes. */
    switch (mode)
    {
    /* # Handle operationmode START. */
    case CRYPTO_OPERATIONMODE_START:
      /* note: key wrap and unwrap have the same init-API */
      retVal = Crypto_30_LibCv_Dispatch_KeyWrappingAesStart(workspace, job, ESL_KEYWRAP_UNWRAP_MODE); /* SBSW_CRYPTO_30_LIBCV_ESL_CALL_WITH_WORKSPACE_AND_BUFFERS */
      break;

    /* # Handle operationmode UPDATE. */
    case CRYPTO_OPERATIONMODE_UPDATE:
      retVal = E_OK;
      break;

    /* # Handle operationmode FINISH. */
    case CRYPTO_OPERATIONMODE_FINISH:
      retVal = Crypto_30_LibCv_Dispatch_KeyUnwrapAesFinish(workspace, job, objectId); /* SBSW_CRYPTO_30_LIBCV_ESL_CALL_WITH_WORKSPACE_AND_BUFFERS */
      break;

    default:  /* COV_CRYPTO_30_LIBCV_MISRA_ADDITIONAL_STATEMENT */
      /* Not supported State */
      break;
    }
  }

  return retVal;
} /* Crypto_30_LibCv_Dispatch_KeyUnwrapAes() */
#endif /* (CRYPTO_30_LIBCV_KEYUNWRAPAES == STD_ON) */

#define CRYPTO_30_LIBCV_STOP_SEC_CODE
#include "Crypto_30_LibCv_MemMap.h" /* PRQA S 5087 */ /* MD_MSR_MemMap */

/***********************************************************************************************************************
 *  END OF FILE: Crypto_30_LibCv_KeyWrap.c
 **********************************************************************************************************************/
