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

	u8 Aes_Iv[XHDCP22_TX_AES128_SIZE];
	u8 Aes_Key[XHDCP22_TX_AES128_SIZE];
	u8 Kd[2 * XHDCP22_TX_AES128_SIZE]; /* Dkey0 || Dkey 1. */
	u8 HashKey[XHDCP22_TX_SHA256_HASH_SIZE];

	/* For key derivation, use Km XOR Rn as AES key where Rn=0 during AKE.
	 * Note: Protocol says we should use incoming Rn and XOR it with Km,
	 * but then the output does not match the errata output.
	 * For now we use for Rn 0, which matches the test vectors.
	 */
	memcpy(Aes_Key, Km, XHDCP22_TX_KM_SIZE);

	/* Compute Dkey0. */
	/* Add m = Rtx || Rrx. */
	memcpy(Aes_Iv, Rtx, XHDCP22_TX_RTX_SIZE);
	/* Rrx XOR Ctr0, where Ctr0 is 0. */
	memcpy(&Aes_Iv[XHDCP22_TX_RTX_SIZE], Rrx, XHDCP22_TX_RRX_SIZE);
	XHdcp22Cmn_Aes128Encrypt(Aes_Iv, Aes_Key, Kd);


	/* Compute Dkey0 , counter is 1: Rrx | 0x01. */
	Aes_Iv[15] ^= 0x01; /* big endian! */
	XHdcp22Cmn_Aes128Encrypt(Aes_Iv, Aes_Key, &Kd[XHDCP22_TX_KM_SIZE]);


	/* Create hash with HMAC-SHA256. */
	/* Input: Rn. */
	/* Key:	Kd XOR Rrx (least sign. 64 bits). */
	memset(HashKey, 0x00, XHDCP22_TX_SHA256_HASH_SIZE);
	memcpy(&HashKey[XHDCP22_TX_SHA256_HASH_SIZE-XHDCP22_TX_RRX_SIZE], Rrx,
         XHDCP22_TX_RRX_SIZE);
	XHdcp22Tx_MemXor(HashKey, HashKey, Kd, XHDCP22_TX_SHA256_HASH_SIZE);
	XHdcp22Cmn_HmacSha256Hash(Rn, XHDCP22_TX_RN_SIZE, HashKey,
                           XHDCP22_TX_SHA256_HASH_SIZE, LPrime);
}
/*****************************************************************************/
/**
*
* This function computes LPrime. 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 and previouslyd stored.
* @param  Rrx is the random value generated by rx.
* @param  Rtx is the random value generated by tx.
* @param  LPrime is a pointer to the computed LPrime hash.
*
* @return None.
*
* @note   None.
******************************************************************************/
This function computes LPrime. 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 LPrime . 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_ComputeLPrime(const u8* Rn, const u8 *Km,
                             const u8 *Rrx, const u8 *Rtx,
                             u8 *LPrime)
{
	Xil_AssertVoid(Rn != NULL);
	Xil_AssertVoid(Km != NULL);
	Xil_AssertVoid(Rrx != NULL);
	Xil_AssertVoid(Rtx != NULL);
	Xil_AssertVoid(LPrime != NULL);
	u8 Aes_Iv[XHDCP22_TX_AES128_SIZE];
	u8 Aes_Key[XHDCP22_TX_AES128_SIZE];
	u8 Kd[2 * XHDCP22_TX_AES128_SIZE]; 
	u8 HashKey[XHDCP22_TX_SHA256_HASH_SIZE];
	memcpy(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);
	XHdcp22Cmn_Aes128Encrypt(Aes_Iv, Aes_Key, Kd);
	Aes_Iv[15] ^= 0x01; 
	XHdcp22Cmn_Aes128Encrypt(Aes_Iv, Aes_Key, &Kd[XHDCP22_TX_KM_SIZE]);
	memset(HashKey, 0x00, XHDCP22_TX_SHA256_HASH_SIZE);
	memcpy(&HashKey[XHDCP22_TX_SHA256_HASH_SIZE-XHDCP22_TX_RRX_SIZE], Rrx,
         XHDCP22_TX_RRX_SIZE);
	XHdcp22Tx_MemXor(HashKey, HashKey, Kd, XHDCP22_TX_SHA256_HASH_SIZE);
	XHdcp22Cmn_HmacSha256Hash(Rn, XHDCP22_TX_RN_SIZE, HashKey,
                           XHDCP22_TX_SHA256_HASH_SIZE, LPrime);
}
void XHdcp22Tx_ComputeLPrime ( const u8 * Rn , const u8 * Km , const u8 * Rrx , const u8 * Rtx , u8 * LPrime ) { Xil_AssertVoid ( Rn != NULL ) ; Xil_AssertVoid ( Km != NULL ) ; Xil_AssertVoid ( Rrx != NULL ) ; Xil_AssertVoid ( Rtx != NULL ) ; Xil_AssertVoid ( LPrime != NULL ) ; u8 Aes_Iv [ XHDCP22_TX_AES128_SIZE ] ; u8 Aes_Key [ XHDCP22_TX_AES128_SIZE ] ; u8 Kd [ 2 * XHDCP22_TX_AES128_SIZE ] ; u8 HashKey [ XHDCP22_TX_SHA256_HASH_SIZE ] ; memcpy ( 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 ) ; XHdcp22Cmn_Aes128Encrypt ( Aes_Iv , Aes_Key , Kd ) ; Aes_Iv [ 15 ] ^= 0x01 ; XHdcp22Cmn_Aes128Encrypt ( Aes_Iv , Aes_Key , & Kd [ XHDCP22_TX_KM_SIZE ] ) ; memset ( HashKey , 0x00 , XHDCP22_TX_SHA256_HASH_SIZE ) ; memcpy ( & HashKey [ XHDCP22_TX_SHA256_HASH_SIZE - XHDCP22_TX_RRX_SIZE ] , Rrx , XHDCP22_TX_RRX_SIZE ) ; XHdcp22Tx_MemXor ( HashKey , HashKey , Kd , XHDCP22_TX_SHA256_HASH_SIZE ) ; XHdcp22Cmn_HmacSha256Hash ( Rn , XHDCP22_TX_RN_SIZE , HashKey , XHDCP22_TX_SHA256_HASH_SIZE , LPrime ) ; }
This function computes LPrime.
This function computes LPrime .
/* Verify arguments */ /* Dkey0 || Dkey 1. */ /* For key derivation, use Km XOR Rn as AES key where Rn=0 during AKE.
	 * Note: Protocol says we should use incoming Rn and XOR it with Km,
	 * but then the output does not match the errata output.
	 * For now we use for Rn 0, which matches the test vectors.
	 */ /* Compute Dkey0. */ /* Add m = Rtx || Rrx. */ /* Rrx XOR Ctr0, where Ctr0 is 0. */ /* Compute Dkey0 , counter is 1: Rrx | 0x01. */ /* big endian! */ /* Create hash with HMAC-SHA256. */ /* Input: Rn. */ /* Key:	Kd XOR Rrx (least sign. 64 bits). */