XilinxProcessorIPLib/drivers/hdcp22_tx/src/xhdcp22_tx_crypt.c
void XHdcp22Tx_ComputeEdkeyKs(const u8* Rn, const u8* Km,
                              const u8 *Ks,
                              const u8 *Rrx, const u8 *Rtx,
                              u8 *EdkeyKs)
{
	/* Verify arguments */
	Xil_AssertVoid(Rn != NULL);
	Xil_AssertVoid(Km != NULL);
	Xil_AssertVoid(Ks != NULL);
	Xil_AssertVoid(Rrx != NULL);
	Xil_AssertVoid(Rtx != NULL);
	Xil_AssertVoid(EdkeyKs != NULL);

	u8 Aes_Iv[XHDCP22_TX_AES128_SIZE];
	u8 Aes_Key[XHDCP22_TX_AES128_SIZE];
	u8 Dkey2[XHDCP22_TX_AES128_SIZE]; /* Dkey2. */

	/* Key XOR with Rn. */
	/* Copy Rn to least significant 64-bits. */
	memset(Aes_Key, 0x0, XHDCP22_TX_KM_SIZE);
	memcpy(&Aes_Key[XHDCP22_TX_RN_SIZE], Rn, XHDCP22_TX_RN_SIZE);
	XHdcp22Tx_MemXor(Aes_Key, Aes_Key, Km, XHDCP22_TX_KM_SIZE);

	/* Determine dkey2. */
	/* Add m = Rtx || Rrx. */
	memcpy(Aes_Iv, Rtx, XHDCP22_TX_RTX_SIZE);
	memcpy(&Aes_Iv[XHDCP22_TX_RTX_SIZE], Rrx, XHDCP22_TX_RRX_SIZE);
	Aes_Iv[15] ^= 0x02; /* big endian! */
	XHdcp22Cmn_Aes128Encrypt(Aes_Iv, Aes_Key, Dkey2);


	/* EdkeyKs = Ks XOR (Dkey2 XOR Rrx). */
	/* Rrx XOR Dkey2. */
	memset(EdkeyKs, 0x00, XHDCP22_TX_EDKEY_KS_SIZE);
	/* Copy Rrx to the least significant 64 bits. */
	memcpy(&EdkeyKs[XHDCP22_TX_EDKEY_KS_SIZE - XHDCP22_TX_RRX_SIZE], Rrx,
					XHDCP22_TX_RRX_SIZE);
	XHdcp22Tx_MemXor(EdkeyKs, EdkeyKs, Dkey2, XHDCP22_TX_AES128_SIZE);
	/* XOR with Ks. */
	XHdcp22Tx_MemXor(EdkeyKs, EdkeyKs, Ks, XHDCP22_TX_KS_SIZE);
}
/*****************************************************************************/
/**
*
* This function computes EdkeyKs. Kd is calculated as in
* #XHdcp22Tx_ComputeHPrime, but could also be stored the first time.
* This could save some computing time.
* According protocol however, only Rrx and Rtx are supposed to be stored.
*
* @param  Rn is a pseudo-random nonce.
* @param  Km is the master key generated by tx..
*         See also #XHdcp22Tx_ComputeHPrime
* @param  Ks is the session key.
* @param  Rrx is the random value generated by rx.
* @param  Rtx is the random value generated by tx.
* @param  EdkeyKs is the encrypted Ks output.
*
* @return None.
*
* @note   None.
******************************************************************************/
This function computes EdkeyKs. Kd is calculated as in
XHdcp22Tx_ComputeHPrime, but could also be stored the first time.
This could save some computing time.
According protocol however, only Rrx and Rtx are supposed to be stored.
This function computes EdkeyKs . Kd is calculated as in XHdcp22Tx_ComputeHPrime but could also be stored the first time . This could save some computing time . According protocol however only Rrx and Rtx are supposed to be stored .
void XHdcp22Tx_ComputeEdkeyKs(const u8* Rn, const u8* Km,
                              const u8 *Ks,
                              const u8 *Rrx, const u8 *Rtx,
                              u8 *EdkeyKs)
{
	Xil_AssertVoid(Rn != NULL);
	Xil_AssertVoid(Km != NULL);
	Xil_AssertVoid(Ks != NULL);
	Xil_AssertVoid(Rrx != NULL);
	Xil_AssertVoid(Rtx != NULL);
	Xil_AssertVoid(EdkeyKs != NULL);
	u8 Aes_Iv[XHDCP22_TX_AES128_SIZE];
	u8 Aes_Key[XHDCP22_TX_AES128_SIZE];
	u8 Dkey2[XHDCP22_TX_AES128_SIZE]; 
	memset(Aes_Key, 0x0, XHDCP22_TX_KM_SIZE);
	memcpy(&Aes_Key[XHDCP22_TX_RN_SIZE], Rn, XHDCP22_TX_RN_SIZE);
	XHdcp22Tx_MemXor(Aes_Key, Aes_Key, Km, XHDCP22_TX_KM_SIZE);
	memcpy(Aes_Iv, Rtx, XHDCP22_TX_RTX_SIZE);
	memcpy(&Aes_Iv[XHDCP22_TX_RTX_SIZE], Rrx, XHDCP22_TX_RRX_SIZE);
	Aes_Iv[15] ^= 0x02; 
	XHdcp22Cmn_Aes128Encrypt(Aes_Iv, Aes_Key, Dkey2);
	memset(EdkeyKs, 0x00, XHDCP22_TX_EDKEY_KS_SIZE);
	memcpy(&EdkeyKs[XHDCP22_TX_EDKEY_KS_SIZE - XHDCP22_TX_RRX_SIZE], Rrx,
					XHDCP22_TX_RRX_SIZE);
	XHdcp22Tx_MemXor(EdkeyKs, EdkeyKs, Dkey2, XHDCP22_TX_AES128_SIZE);
	XHdcp22Tx_MemXor(EdkeyKs, EdkeyKs, Ks, XHDCP22_TX_KS_SIZE);
}
void XHdcp22Tx_ComputeEdkeyKs ( const u8 * Rn , const u8 * Km , const u8 * Ks , const u8 * Rrx , const u8 * Rtx , u8 * EdkeyKs ) { Xil_AssertVoid ( Rn != NULL ) ; Xil_AssertVoid ( Km != NULL ) ; Xil_AssertVoid ( Ks != NULL ) ; Xil_AssertVoid ( Rrx != NULL ) ; Xil_AssertVoid ( Rtx != NULL ) ; Xil_AssertVoid ( EdkeyKs != NULL ) ; u8 Aes_Iv [ XHDCP22_TX_AES128_SIZE ] ; u8 Aes_Key [ XHDCP22_TX_AES128_SIZE ] ; u8 Dkey2 [ XHDCP22_TX_AES128_SIZE ] ; memset ( Aes_Key , 0x0 , XHDCP22_TX_KM_SIZE ) ; memcpy ( & Aes_Key [ XHDCP22_TX_RN_SIZE ] , Rn , XHDCP22_TX_RN_SIZE ) ; XHdcp22Tx_MemXor ( Aes_Key , Aes_Key , Km , XHDCP22_TX_KM_SIZE ) ; memcpy ( Aes_Iv , Rtx , XHDCP22_TX_RTX_SIZE ) ; memcpy ( & Aes_Iv [ XHDCP22_TX_RTX_SIZE ] , Rrx , XHDCP22_TX_RRX_SIZE ) ; Aes_Iv [ 15 ] ^= 0x02 ; XHdcp22Cmn_Aes128Encrypt ( Aes_Iv , Aes_Key , Dkey2 ) ; memset ( EdkeyKs , 0x00 , XHDCP22_TX_EDKEY_KS_SIZE ) ; memcpy ( & EdkeyKs [ XHDCP22_TX_EDKEY_KS_SIZE - XHDCP22_TX_RRX_SIZE ] , Rrx , XHDCP22_TX_RRX_SIZE ) ; XHdcp22Tx_MemXor ( EdkeyKs , EdkeyKs , Dkey2 , XHDCP22_TX_AES128_SIZE ) ; XHdcp22Tx_MemXor ( EdkeyKs , EdkeyKs , Ks , XHDCP22_TX_KS_SIZE ) ; }
This function computes EdkeyKs.
This function computes EdkeyKs .
/* Verify arguments */ /* Dkey2. */ /* Key XOR with Rn. */ /* Copy Rn to least significant 64-bits. */ /* Determine dkey2. */ /* Add m = Rtx || Rrx. */ /* big endian! */ /* EdkeyKs = Ks XOR (Dkey2 XOR Rrx). */ /* Rrx XOR Dkey2. */ /* Copy Rrx to the least significant 64 bits. */ /* XOR with Ks. */