/*!
* @file     Crypto_Common.h
*
* @brief    Shared Crypto MCAL helpers (byte order / word packing for AES, SHA, RNG).
*           Implementations live in Crypto.c.
*
* @attention
*
* Copyright (C) 2026 Geehy Semiconductor
*
* You may not use this file except in compliance with the
* GEEHY COPYRIGHT NOTICE (Geehy Semiconductor Software License Agreement).
*/

#ifndef CRYPTO_COMMON_H
#define CRYPTO_COMMON_H

#ifdef __cplusplus
extern "C" {
#endif

#include "Crypto_Cse.h"

/** @addtogroup G32A10xx_StdPeriphDriver
  @{
*/

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

/** @defgroup CRYPTO_Common_ByteOrder
  * @brief Word packing and byte-swap helpers (AES / SHA / RNG)
  @{
*/

FUNC(uint32, CRYPTO_CODE) Crypto_Bswap32(VAR(uint32, AUTOMATIC) value);
FUNC(uint16, CRYPTO_CODE) Crypto_Bswap16(VAR(uint16, AUTOMATIC) value);
FUNC(uint32, CRYPTO_CODE) Crypto_BeU32FromBytes(P2CONST(uint8, AUTOMATIC, CRYPTO_APPL_CONST) bytes);
FUNC(uint32, CRYPTO_CODE) Crypto_LeU32FromBytes(P2CONST(uint8, AUTOMATIC, CRYPTO_APPL_CONST) bytes);
FUNC(void, CRYPTO_CODE) Crypto_BeU32ToBytes(VAR(uint32, AUTOMATIC) value, P2VAR(uint8, AUTOMATIC, CRYPTO_APPL_DATA) bytes);
FUNC(void, CRYPTO_CODE) Crypto_LeU32ToBytes(VAR(uint32, AUTOMATIC) value, P2VAR(uint8, AUTOMATIC, CRYPTO_APPL_DATA) bytes);
FUNC(void, CRYPTO_CODE) Crypto_SwapU32BufferInPlace(P2VAR(uint32, AUTOMATIC, CRYPTO_APPL_DATA) words, VAR(uint32, AUTOMATIC) wordCount);
FUNC(void, CRYPTO_CODE) Crypto_CopyU32BufferWithBswap(P2CONST(uint32, AUTOMATIC, CRYPTO_APPL_CONST) src,
    P2VAR(uint32, AUTOMATIC, CRYPTO_APPL_DATA) dst, VAR(uint32, AUTOMATIC) wordCount);

/**@} end of group CRYPTO_Common_ByteOrder */

/*!
 * @brief Legacy AES header names map to Crypto_* (same symbols in Crypto.c).
 */
#ifndef CRYPTO_NO_LEGACY_AES256_ENDIAN_NAMES
#define Crypto_Aes256_Bswap32                  Crypto_Bswap32
#define Crypto_Aes256_Bswap16                  Crypto_Bswap16
#define Crypto_Aes256_BeU32FromBytes           Crypto_BeU32FromBytes
#define Crypto_Aes256_LeU32FromBytes           Crypto_LeU32FromBytes
#define Crypto_Aes256_BeU32ToBytes             Crypto_BeU32ToBytes
#define Crypto_Aes256_LeU32ToBytes             Crypto_LeU32ToBytes
#define Crypto_Aes256_SwapU32BufferInPlace     Crypto_SwapU32BufferInPlace
#define Crypto_Aes256_CopyU32BufferWithBswap   Crypto_CopyU32BufferWithBswap
#endif /* CRYPTO_NO_LEGACY_AES256_ENDIAN_NAMES */

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

#ifdef __cplusplus
}
#endif

#endif /* CRYPTO_COMMON_H */
