/**
 * @file hv_drv_Hdcp2xRx.h
 * @brief Header file of drv module.
 *
 * @verbatim
 * ==============================================================================
 *                        ##### How to use #####
 * ==============================================================================
 * (+) Use Hv_Engine_RxCalcMontNPrime(...) calculate the Montgomery NPrime.
 * (+) Use Hv_Engine_RxRsaesOaepEncrypt(...) implements the RSAES-OAEP-Encrypt operation
 * (+) Use Hv_Engine_RxRsaesOaepDecrypt(...) implements the RSAES-OAEP-Decrypt operation.
 * (+) Use Hv_Engine_RxComputeHPrime(...) computes HPrime used during HDCP 2.2 authentication.
 * (+) Use Hv_Engine_RxComputeEkh(...) computes Ekh used during HDCP 2.2 authentication.
 * (+) Use Hv_Engine_RxComputeLPrime(...) computes LPrime used during HDCP 2.2 locality check.
 * (+) Use Hv_Engine_RxComputeKs(...) computes the Ks used during HDCP 2.2 session key exchange.
 * (+) Use Hv_Engine_RxComputeVPrime(...) computes VPrime used during HDCP 2.2 repeater.
 * (+) Use Hv_Engine_RxComputeMPrime(...) computes VPrime used during HDCP 2.2 repeater.
 *
 * @endverbatim
 *
 * @author HiView SoC Software Team
 * @version 1.0.0
 * @date 2022-08-30
 */


#ifndef HV_DRV_HDCP2X_RX_H		/* prevent circular inclusions */
#define HV_DRV_HDCP2X_RX_H		/* by using protection macros */

#ifdef __cplusplus
extern "C" {
#endif

/***************************** Include Files ********************************/
#include "hv_vos_Comm.h"
#include "hv_comm_DataType.h"
#include "hv_comm_Define.h"

/************************** Constant Definitions ****************************/

/************************** Variable Declaration ****************************/
#define HV_HDCP_2X_RX_AES_SIZE               16            /** AES size size in bytes */
#define HV_HDCP_2X_RX_SEQNUMV_SIZE           3             /** Repeater seq_num_V size in bytes */
#define HV_HDCP_2X_RX_RXINFO_SIZE            2             /** Repeater RxInfo size in bytes */
#define HV_HDCP_2X_RX_V_SIZE                 16            /** Repeater V size in bytes */
#define HV_HDCP_2X_RX_K_SIZE                 2            /** Repeater K size in bytes */

#define HV_HDCP_2X_RX_RECEIVER_ID_LIST_SIZE  5*31

#define HV_HDCP_2X_RX_EKPUBKM_SIZE           128
#define HV_HDCP_2X_Rx_EDKEYKS_SIZE           16            /** EDKEYKS size size in bytes */
#define HV_HDCP_2X_RX_KM_SIZE                16            /** Km size in bytes */
#define HV_HDCP_2X_RX_M_SIZE                 16            /** m size in bytes */
#define HV_HDCP_2X_RX_EKH_SIZE               16            /** Ekh size size in bytes */
#define HV_HDCP_2X_RX_HPRIME_SIZE            32            /** HPrime size size in bytes */
#define HV_HDCP_2X_RX_LPRIME_SIZE            32            /** LPrime size size in bytes */
#define HV_HDCP_2X_RX_RN_SIZE                8             /** Rn size size in bytes */
#define HV_HDCP_2X_RX_RIV_SIZE               8             /** Riv size size in bytes */
#define HV_HDCP_2X_RX_KS_SIZE                16            /** Ks size size in bytes */
#define HV_HDCP_2X_RX_RTX_SIZE               8             /** Rtx size size in bytes */
#define HV_HDCP_2X_RX_RRX_SIZE               8             /** Rrx size size in bytes */
#define HV_HDCP_2X_RX_TXCAPS_SIZE            3             /** TxCaps size size in bytes */
#define HV_HDCP_2X_RX_RXCAPS_SIZE            3             /** RxCaps size size in bytes */
#define HV_HDCP_2X_RX_VPRIME_SIZE            32            /** Repeater VPrime size in bytes */
#define HV_HDCP_2X_RX_SEQNUMM_SIZE           3             /** Repeater seq_num_M size in bytes */
#define HV_HDCP_2X_RX_MPRIME_SIZE            32            /** Repeater MPrime size in bytes */
#define HV_HDCP_2X_RX_STREAMID_SIZE          2             /** Repeater MPrime size in bytes */
#define HV_HDCP_2X_RX_MOD_SIZE               16           
#define HV_HDCP_2X_RX_MAX_MESSAGE_SIZE       534  /**< Maximum message size */
#define HV_HDCP_2X_RX_N_PRIME_P_SIZE         64           
#define HV_HDCP_2X_RX_N_PRIME_Q_SIZE         64         

/** Hdcp2x Tx  size in bytes */
#define HV_HDCP_2X_TX_E_KPUB_KM_SIZE         128  
#define HV_HDCP_2X_TX_EKH_KM_SIZE            16    
#define HV_HDCP_2X_TX_RN_SIZE                8     

/** Hdcp2x Public Key  size in bytes */
#define HV_HDCP_2X_RX_N_SIZE                 128           
#define HV_HDCP_2X_RX_E_SIZE                 3           

/** Hdcp2x Private Key  size in bytes */
#define HV_HDCP_2X_RX_P_SIZE                 64            
#define HV_HDCP_2X_RX_Q_SIZE                 64       
#define HV_HDCP_2X_RX_DP_SIZE                64           
#define HV_HDCP_2X_RX_DQ_SIZE                64            
#define HV_HDCP_2X_RX_QINV_SIZE              64 

/** Hdcp2x Cert  size in bytes */
#define HV_HDCP_2X_RECEIVER_ID_SIZE          5            
#define HV_HDCP_2X_RX_KPUB_SIZE              131            
#define HV_HDCP_2X_RESERVED_SIZE             2            
#define HV_HDCP_2X_SIGN_SIZE                 384            
/**
 * These constants are the message identification codes.
 */
typedef enum
{
    HV_HDCP_2X_RX_MSG_ID_AKEINIT                   = 2,   /**< AKE_Init message ID */
    HV_HDCP_2X_RX_MSG_ID_AKESENDCERT               = 3,   /**< AKE_Send_Cert message ID */
    HV_HDCP_2X_RX_MSG_ID_AKENOSTOREDKM             = 4,   /**< AKE_No_Stored_km message ID */
    HV_HDCP_2X_RX_MSG_ID_AKESTOREDKM               = 5,   /**< AKE_Stored_km message ID */
    HV_HDCP_2X_RX_MSG_ID_AKESENDHPRIME             = 7,   /**< AKE_Send_H_prime message ID */
    HV_HDCP_2X_RX_MSG_ID_AKESENDPAIRINGINFO        = 8,   /**< AKE_Send_Pairing_Info message ID */
    HV_HDCP_2X_RX_MSG_ID_LCINIT                    = 9,   /**< LC_Init message ID */
    HV_HDCP_2X_RX_MSG_ID_LCSENDLPRIME              = 10,  /**< LC_Send_L_prime message ID */
    HV_HDCP_2X_RX_MSG_ID_SKESENDEKS                = 11,  /**< SKE_Send_Eks message ID */
    HV_HDCP_2X_RX_MSG_ID_REPEATERAUTHSENDRXIDLIST  = 12,  /**< RepeaterAuth_Send_ReceiverID_List message ID */
    HV_HDCP_2X_RX_MSG_ID_REPEATERAUTHSENDACK       = 15,  /**< RepeaterAuth_Send_Ack message ID */
    HV_HDCP_2X_RX_MSG_ID_REPEATERAUTHSTREAMMANAGE  = 16,  /**< RepeaterAuth_Stream_Manage message ID */
    HV_HDCP_2X_RX_MSG_ID_REPEATERAUTHSTREAMREADY   = 17,  /**< RepeaterAuth_Stream_Ready message ID */
    HV_HDCP_2X_RX_MSG_ID_INVALID                   = 0xFF
} HV_HDCP_2X_RX_MSG_ID;

/*******HDCP 2.X***********************/


typedef struct
{
    /** Montgomery 2^2k mod p array */
    UINT32 AmodP[HV_HDCP_2X_RX_MOD_SIZE];
    /** Montgomery 2^2k mod q array */
    UINT32 AmodQ[HV_HDCP_2X_RX_MOD_SIZE];
    /** Montgomery 2^k mod p array */
    UINT32 CmodP[HV_HDCP_2X_RX_MOD_SIZE];
    /** Montgomery 2^k mod q array */
    UINT32 CmodQ[HV_HDCP_2X_RX_MOD_SIZE];

} Hdcp2xRxMmult;

/**
 * This typedef is used to store temporary parameters for computations
 */
typedef struct _Hdcp2xRxParams
{
    UCHAR8 Rtx[HV_HDCP_2X_RX_RTX_SIZE];
    UCHAR8 TxCaps[HV_HDCP_2X_RX_TXCAPS_SIZE];
    UCHAR8 Rrx[HV_HDCP_2X_RX_RRX_SIZE];
    UCHAR8 RxCaps[HV_HDCP_2X_RX_RXCAPS_SIZE];
    UCHAR8 Km[HV_HDCP_2X_RX_KM_SIZE];
    UCHAR8 Rn[HV_HDCP_2X_RX_RN_SIZE];
    UCHAR8 HPrime[HV_HDCP_2X_RX_HPRIME_SIZE];
    UCHAR8 LPrime[HV_HDCP_2X_RX_LPRIME_SIZE];
    UCHAR8 EKh[HV_HDCP_2X_RX_EKH_SIZE];
    UCHAR8 EKhKm[HV_HDCP_2X_RX_KM_SIZE];
    UCHAR8 M[HV_HDCP_2X_RX_M_SIZE];
    UCHAR8 Riv[HV_HDCP_2X_RX_RIV_SIZE];
    UCHAR8 Ks[HV_HDCP_2X_RX_KS_SIZE];
    UCHAR8 VPrime[HV_HDCP_2X_RX_VPRIME_SIZE];
    UCHAR8 SeqNumM[HV_HDCP_2X_RX_SEQNUMM_SIZE];
    UCHAR8 StreamIdType[HV_HDCP_2X_RX_STREAMID_SIZE];
    UCHAR8 MPrime[HV_HDCP_2X_RX_MPRIME_SIZE];
    UCHAR8 EDkeyKs[HV_HDCP_2X_Rx_EDKEYKS_SIZE];
    UCHAR8 EKpubKm[HV_HDCP_2X_RX_EKPUBKM_SIZE];
} Hdcp2xRxParams;

/**
 * The XHdcp driver instance data. The user is required to
 * allocate a variable of this type for every HDCP-RX device in the
 * system. A pointer to a variable of this type is then passed to the driver
 * API functions.
 */
typedef struct
{
    /** DCP public certificate pointer */
    const UCHAR8 *pucPubCert;

    /** RSA private key pointer */
    const UCHAR8 *pucPrivKey;

    /** pU8Lc128 is a pointer to the LC128 key.*/
    const UCHAR8 *pucLc128;

    /** Montgomery NPrimeP array */
    UCHAR8 NPrimeP[HV_HDCP_2X_RX_N_PRIME_P_SIZE];

    /** Montgomery NPrimeQ array */
    UCHAR8 NPrimeQ[HV_HDCP_2X_RX_N_PRIME_Q_SIZE];

    /** HDCP-RX authentication and key exchange parameters */
    Hdcp2xRxParams stParams;

    /** Message size */
    USHORT16 uiMsgSize;
    /** Message structure */
    UCHAR8 aucMsgBuff[HV_HDCP_2X_RX_MAX_MESSAGE_SIZE];

    Hdcp2xRxMmult   *pstmmult;
} Hdcp2xRx;

/************HDCP2x Rx Send Msg State************ */
typedef enum _Hdcp2xRxMsgState
{
    HDCP2X_AKE_SEND_CERT_DONE          = 0,                        /**< Compute Km: Send AKE_Send_Cert */
    HDCP2X_AKE_SEND_HPRIME_DONE,                                   /**< Compute Km: Send AKE_Send_H_prime */
    HDCP2X_AKE_SEND_PAIRING_DONE,                                  /**< Compute Km: Send AKE_Send_H_prime */
    HDCP2X_SEND_LPRIME_DONE,                                       /**< Compute Km: Send AKE_Send_H_prime */
    HDCP2X_SEND_MSG_INVALID                                   
} Hdcp2xRxMsgState;

/**
 * This typedef is the RSA private key quintuple definition.
 */
typedef struct
{
    UCHAR8 p[HV_HDCP_2X_RX_P_SIZE];
    UCHAR8 q[HV_HDCP_2X_RX_Q_SIZE];
    UCHAR8 dp[HV_HDCP_2X_RX_DP_SIZE];
    UCHAR8 dq[HV_HDCP_2X_RX_DQ_SIZE];
    UCHAR8 qinv[HV_HDCP_2X_RX_QINV_SIZE];
} HDCP2X_RX_KPriv;


/**
 * This typedef is the RSA public key definition.
 */
typedef struct
{
    UCHAR8 N[HV_HDCP_2X_RX_N_SIZE];
    UCHAR8 e[HV_HDCP_2X_RX_E_SIZE];
} HDCP2X_RX_Kpub;

/**
 * This typedef is the DCP public certificate definition.
 */
typedef struct
{
    UCHAR8 ReceiverId[HV_HDCP_2X_RECEIVER_ID_SIZE];
    UCHAR8 KpubRx[HV_HDCP_2X_RX_KPUB_SIZE];
    UCHAR8 Reserved[HV_HDCP_2X_RESERVED_SIZE];
    UCHAR8 Signature[HV_HDCP_2X_SIGN_SIZE];
} HDCP2X_RX_Cert;

/**
 * This typedef is the AKE_Init message definition.
 */
typedef struct
{
    UCHAR8 MsgId;
    UCHAR8 Rtx[HV_HDCP_2X_RX_RTX_SIZE];
    UCHAR8 TxCaps[HV_HDCP_2X_RX_TXCAPS_SIZE];
} HDCP2X_RX_AKEInit;

/**
 * This typedef is the AKE_Send_Cert message definition.
 */
typedef struct
{
    UCHAR8 MsgId;
    UCHAR8 CertRx[HV_HDCP_2X_RX_CERT_SIZE];
    UCHAR8 Rrx[HV_HDCP_2X_RX_RRX_SIZE];
    UCHAR8 RxCaps[HV_HDCP_2X_RX_RXCAPS_SIZE];
} HDCP2X_RX_AKESendCert;

/**
 * This typedef is the AKE_No_Stored_km message definition.
 */
typedef struct
{
    UCHAR8 MsgId;
    UCHAR8 EKpubKm[HV_HDCP_2X_RX_EKPUBKM_SIZE];
} HDCP2X_RX_AKENoStoredKm;

/**
 * This typedef is the AKE_Stored_km message definition.
 */
typedef struct
{
    UCHAR8 MsgId;
    UCHAR8 EKhKm[HV_HDCP_2X_RX_EKH_SIZE];
    UCHAR8 M[HV_HDCP_2X_RX_M_SIZE];
} HDCP2X_RX_AKEStoredKm;

/**
 * This typedef is the AKE_Send_H_prime message definition.
 */
typedef struct
{
    UCHAR8 MsgId;
    UCHAR8 HPrime[HV_HDCP_2X_RX_HPRIME_SIZE];
} HDCP2X_RX_AKESendHPrime;

/**
 * This typedef is the AKE_Send_Pairing_Info message definition.
 */
typedef struct
{
    UCHAR8 MsgId;
    UCHAR8 EKhKm[HV_HDCP_2X_RX_EKH_SIZE];
} HDCP2X_RX_AKESendPairingInfo;

/**
 * This typedef is the LC_Init message definition.
 */
typedef struct
{
    UCHAR8 MsgId;
    UCHAR8 Rn[HV_HDCP_2X_RX_RN_SIZE];
} HDCP2X_RX_LCInit;

/**
 * This typdef is the LC_Send_L_prime message definition.
 */
typedef struct
{
    UCHAR8 MsgId;
    UCHAR8 LPrime[HV_HDCP_2X_RX_LPRIME_SIZE];
} HDCP2X_RX_LCSendLPrime;

/**
 * This typedef is the SKE_Send_Eks message definition.
 */
typedef struct
{
    UCHAR8 MsgId;
    UCHAR8 EDkeyKs[HV_HDCP_2X_Rx_EDKEYKS_SIZE];
    UCHAR8 Riv[HV_HDCP_2X_RX_RIV_SIZE];
} HDCP2X_RX_SKESendEks;

/**
 * This typedef is the RepeaterAuth_Send_RceiverID_List message definition.
 */
typedef struct
{
    UCHAR8 MsgId;
    UCHAR8 RxInfo[HV_HDCP_2X_RX_RXINFO_SIZE];
    UCHAR8 SeqNumV[HV_HDCP_2X_RX_SEQNUMV_SIZE];
    UCHAR8 VPrime[HV_HDCP_2X_RX_VPRIME_SIZE];
    UCHAR8 ReceiverIdList[HV_HDCP_2X_RX_RECEIVER_ID_LIST_SIZE];
} HDCP2X_RX_RepeaterAuthSendRxIdList;

/**
 * This typedef is the RepeaterAuth_Send_Ack message definition.
 */
typedef struct
{
    UCHAR8 MsgId;
    UCHAR8 V[HV_HDCP_2X_RX_V_SIZE];
} HDCP2X_RX_RepeaterAuthSendAck;

/**
 * This typedef is the RepeaterAuth_Stream_Manage message definition.
 */
typedef struct
{
    UCHAR8 MsgId;
    UCHAR8 SeqNumM[HV_HDCP_2X_RX_SEQNUMM_SIZE];
    UCHAR8 K[HV_HDCP_2X_RX_K_SIZE];
    UCHAR8 StreamIdType[HV_HDCP_2X_RX_STREAMID_SIZE];
} HDCP2X_RX_RepeaterAuthStreamManage;

/**
 * This typedef is the RepeaterAuth_Stream_Ready message definition.
 */
typedef struct
{
    UCHAR8 MsgId;
    UCHAR8 MPrime[HV_HDCP_2X_RX_MPRIME_SIZE];
} HDCP2X_RX_RepeaterAuthStreamReady;

/**
 * This typedef is the union of all the message types.
 */
typedef union
{
    UCHAR8 MsgId;
    HDCP2X_RX_AKEInit                    AKEInit;
    HDCP2X_RX_AKESendCert                AKESendCert;
    HDCP2X_RX_AKENoStoredKm              AKENoStoredKm;
    HDCP2X_RX_AKEStoredKm                AKEStoredKm;
    HDCP2X_RX_AKESendHPrime              AKESendHPrime;
    HDCP2X_RX_AKESendPairingInfo         AKESendPairingInfo;
    HDCP2X_RX_LCInit                     LCInit;
    HDCP2X_RX_LCSendLPrime               LCSendLPrime;
    HDCP2X_RX_SKESendEks                 SKESendEks;
    HDCP2X_RX_RepeaterAuthSendRxIdList   RepeaterAuthSendRxIdList;
    HDCP2X_RX_RepeaterAuthSendAck        RepeaterAuthSendAck;
    HDCP2X_RX_RepeaterAuthStreamManage   RepeaterAuthStreamManage;
    HDCP2X_RX_RepeaterAuthStreamReady    RepeaterAuthStreamReady;
} HDCP2X_RX_Msg;


/**
 * These constants define the authentication status.
 */
typedef enum
{
	HV_HDCP_2X_RX_UNAUTHENTICATED,         /**< Unauthenticated */
	HV_HDCP_2X_RX_AUTHENTICATION_BUSY,     /**< Authentication Busy */
	HV_HDCP_2X_RX_AUTHENTICATED,           /**< Authenticated */
	HV_HDCP_2X_RX_REAUTHENTICATE_REQUESTED /**< Reauthentication requested */
} HV_HDCP_2X_RX_AuthenticationType;





/************************** Function Prototypes *****************************/

/* Crypto Functions */
/*****************************************************************************/
/**
* This function is used to calculate the Montgomery NPrime. NPrime is
* calculated from the following equation R*Rinv - N*NPrime == 1.
* For the HDCP2.2 receiver the modulus N has a fixed size
* of k = 512bits. Given k, the value R = 2^(k), and Rinv is the modular
* inverse of R.
*
* Reference:
* Analyzing and Comparing Montgomery Multiplication Algorithms
* IEEE Micro, 16(3):26-33,June 1996
* By: Cetin Koc, Tolga Acar, and Burton Kaliski
*
* @param    NPrime is the calculated value and 2*NDigits in Size.
* @param    N is modulus
* @param    NDigits is the integer precision of arguments (N, NPrime), which
*           should always be 16 for the HDCP2.2 receiver.
*
* @return   HV_SUCCESS or HV_FAILURE.
*
* @note     None.
******************************************************************************/
Status  Hv_Engine_RxCalcMontNPrime(UCHAR8 *NPrime, const UCHAR8 *N, int NDigits);

/****************************************************************************/
/**
* This function implements the RSAES-OAEP-Encrypt operation. The message
* is encoded using EME-OAEP and then encrypted with the public key
* using RSAEP.
*
* Reference: PKCS#1 v2.1, Section 7.1.1
*
* @param    KpubRx is the RSA public key structure containing the 1024 bit
*           modulus and 24 bit public exponent.
* @param    Message is the octet string to be encrypted.
* @param    MessageLen is the length of octet string to be encrypted and
*           must be less than or equal to (nLen - 2*hLen - 2)
* @param    MaskingSeed is the random octet string seed of length hLen
*           used by EME-OAEP encoding function.
*
* @return   HV_SUCCESS or HV_FAILURE.
*
* @note     None.
*****************************************************************************/
Status  Hv_Engine_RxRsaesOaepEncrypt(const HDCP2X_RX_Kpub *KpubRx, const UCHAR8 *Message,
            const UINT32 MessageLen, const UCHAR8 *MaskingSeed, UCHAR8 *EncryptedMessage);

/****************************************************************************/
/**
* This function implements the RSAES-OAEP-Decrypt operation. The message is
*   decrypted using RSADP and then decoded using EME-OAEP.
*
* Reference: PKCS#1 v2.1, Section 7.1.2
*
* @param    pstHdcpRxIns is a pointer to the MMULT instance.
* @param    KprivRx is the RSA private key structure containing the quintuple.
* @param    EncryptedMessage is the 128 byte octet string to be decrypted.
* @param    Message is the octet string after decryption.
* @param    MessageLen is the length of the message octet string after decryption.
*
* @return   HV_SUCCESS or HV_FAILURE.
*
* @note     None.
*****************************************************************************/
Status  Hv_Engine_RxRsaesOaepDecrypt(Hdcp2xRx *pstHdcpRxIns, const HDCP2X_RX_KPriv *KprivRx,
             UCHAR8 *EncryptedMessage, UCHAR8 *Message, int *MessageLen);

/*****************************************************************************/
/**
* This function computes HPrime used during HDCP 2.2 authentication and key
* exchange.
*
* Reference: HDCP v2.2, section 2.2
*
* @param    Rrx is the Rx random generated value.
* @param    RxCaps are the capabilities of the receiver.
* @param    Rtx is the Tx random generated value.
* @param    TxCaps are the capabilities of the receiver.
* @param    Km is the master key generated by tx.
* @param    HPrime is a pointer to the HPrime hash from the HDCP2.2 receiver.
*
* @return   None.
*
* @note     None.
******************************************************************************/
VOID Hv_Engine_RxComputeHPrime(const UCHAR8* Rrx, const UCHAR8 *RxCaps, const UCHAR8* Rtx,
         const UCHAR8 *TxCaps, const UCHAR8 *Km, UCHAR8 *HPrime);

/*****************************************************************************/
/**
* This function computes Ekh used during HDCP 2.2 authentication and key
* exchange for pairing with receiver.
*
* Reference: HDCP v2.2, section 2.2.1
*
* @param    KprivRx is the RSA private key structure containing the quintuple.
* @param    Km is the master key generated by tx.
* @param    M is constructed by concatenating Rtx || Rrx.
* @param    Ekh is the encrypted Km used for pairing.
*
* @return   None.
*
* @note     None.
******************************************************************************/
VOID Hv_Engine_RxComputeEkh(const UCHAR8 *KprivRx, const UCHAR8 *Km, const UCHAR8 *M, UCHAR8 *Ekh);

/*****************************************************************************/
/**
* This function computes LPrime used during HDCP 2.2 locality check.
*
* Reference: HDCP v2.2, section 2.3
*
* @param    Rn is the 64-bit psuedo-random nonce generated by the transmitter.
* @param    Km is the 128-bit master key generated by tx.
* @param    Rrx is the 64-bit pseudo-random number generated by the receiver.
* @param    Rtx is the 64-bit pseudo-random number generated by the transmitter.
* @param    LPrime is the 256-bit value generated for locality check.
*
* @return   None.
*
* @note     None.
******************************************************************************/
VOID Hv_Engine_RxComputeLPrime(const UCHAR8 *Rn, const UCHAR8 *Km, const UCHAR8 *Rrx, const UCHAR8 *Rtx, UCHAR8 *LPrime);

/*****************************************************************************/
/**
* This function computes the Ks used during HDCP 2.2 session key exchange.
*
* Reference: HDCP v2.2, section 2.4
*
* @param    Rrx is the Rx random generated value.
* @param    Rtx is the Tx random generated value.
* @param    Km is the master key generated by the transmitter.
* @param    Rn is the 64-bit psuedo-random nonce generated by the transmitter.
* @param    Eks is the encrypted session generated by the transmitter.
* @param    Ks is the decrypted session key.
*
* @return   None.
*
* @note     None.
******************************************************************************/
VOID Hv_Engine_RxComputeKs(const UCHAR8* Rrx, const UCHAR8* Rtx, const UCHAR8 *Km, const UCHAR8 *Rn,
             const UCHAR8 *Eks, UCHAR8 * Ks);

/*****************************************************************************/
/**
* This function computes VPrime used during HDCP 2.2 repeater
* authentication.
*
* Reference: HDCP v2.2, section 2.3
*
* @param  ReceiverIdList is a list of downstream receivers IDs in big-endian
*         order. Each receiver ID is 5 Bytes.
* @param  ReceiverIdListSize is the number of receiver Ids in ReceiverIdList.
*         There can be between 1 and 31 devices in the list.
* @param  RxInfo is the 16-bit field in the RepeaterAuth_Send_ReceiverID_List
*         message.
* @param  Km is the 128-bit master key generated by tx.
* @param  Rrx is the 64-bit pseudo-random number generated by the receiver.
* @param  Rtx is the 64-bit pseudo-random number generated by the transmitter.
* @param  VPrime is the 256-bit value generated for repeater authentication.
*
* @return None.
*
* @note   None.
******************************************************************************/
VOID Hv_Engine_RxComputeVPrime(const UCHAR8 *ReceiverIdList, UINT32 ReceiverIdListSize,
       const UCHAR8 *RxInfo, const UCHAR8 *SeqNumV, const UCHAR8 *Km, const UCHAR8 *Rrx,
       const UCHAR8 *Rtx, UCHAR8 *VPrime);

/*****************************************************************************/
/**
* This function computes VPrime used during HDCP 2.2 repeater
* authentication.
*
* Reference: HDCP v2.2, section 2.3
*
* @param  StreamIdType is the 16-bit field in the RepeaterAuth_Send_ReceiverID_List
*             message.
* @param  SeqNumM is the 24-bit field in the RepeaterAuth_Stream_Manage
*             message.
* @param  Km is the 128-bit master key generated by tx.
* @param  Rrx is the 64-bit pseudo-random number generated by the receiver.
* @param  Rtx is the 64-bit pseudo-random number generated by the transmitter.
* @param  MPrime is the 256-bit value generated for repeater stream
*         management ready.
*
* @return None.
*
* @note   None.
******************************************************************************/
Status Hv_Engine_RxComputeMPrime(const UCHAR8 *StreamIdType, const UCHAR8 *SeqNumM,
       const UCHAR8 *Km, const UCHAR8 *Rrx, const UCHAR8 *Rtx, UCHAR8 *MPrime);


#ifdef __cplusplus
}
#endif

#endif /* HV_HDCP_2X_RX_H_ */

/** @} */
