XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_rx.c
static int XHdcp1x_RxCalculateSHA1Value(XHdcp1x *InstancePtr, u16 RepeaterInfo)
{
	SHA1Context Sha1Context;
	u8 Buf[24];
	u32 NumToRead = 0;
	int IsValid = FALSE;
	u32 KsvCount;
	u64 tempKsv;

	/* Initialize Buf */
	memset(Buf, 0, 24);

	/* Initialize Sha1Context */
	SHA1Reset(&Sha1Context);

	/* Assume success */
	IsValid = TRUE;

	/* Determine theNumToRead */
	NumToRead = ((RepeaterInfo & 0x7Fu));

	/* Read one ksv at a time from the
	 * Ksv List and send it to SHA1 Input
	 */
	KsvCount = 0;

	while (KsvCount < NumToRead) {
		if (InstancePtr->RepeaterValues.DeviceCount > 0) {
			tempKsv = InstancePtr->RepeaterValues.KsvList[KsvCount];
			XHDCP1X_PORT_UINT_TO_BUF(Buf , tempKsv ,
					(XHDCP1X_PORT_SIZE_BKSV*8));
			SHA1Input(&Sha1Context , Buf , XHDCP1X_PORT_SIZE_BKSV);
		}
		else {
			IsValid = FALSE;
		}
		KsvCount++;
	}

	/* Check for success */
	if (IsValid) {
		u64 Mo = 0;
		u8 Sha1Result[SHA1HashSize];

		/* Insert RepeaterInfo into the SHA-1 transform */
		Buf[0] = (u8) (RepeaterInfo & 0xFFu);
		Buf[1] = (u8) ((RepeaterInfo >> 8) & 0xFFu);
		SHA1Input(&Sha1Context, Buf, 2);

		/* Insert the Mo into the SHA-1 transform */
		Mo = XHdcp1x_CipherGetMo(InstancePtr);
		XHDCP1X_PORT_UINT_TO_BUF(Buf, Mo, 64);

		SHA1Input(&Sha1Context, Buf, 8);

		/* Finalize the SHA-1 result and confirm success */
		if (SHA1Result(&Sha1Context, Sha1Result) == shaSuccess) {
			/* Offset(XHDCP1X_PORT_OFFSET_VH0) = 0 */
			u8 Offset = 0;
			const u8 *Sha1Buf = Sha1Result;
			int NumIterations = (SHA1HashSize >> 2);

			/* Iterate through the SHA-1 chunks */
			do {
				u32 CalcValue = 0;

				/* Determine CalcValue */
				CalcValue = *Sha1Buf++;
				CalcValue <<= 8;
				CalcValue |= *Sha1Buf++;
				CalcValue <<= 8;
				CalcValue |= *Sha1Buf++;
				CalcValue <<= 8;
				CalcValue |= *Sha1Buf++;

				/* Update the V' value in the Instance
				 * Pointer for the HDCP state machine
				 */
				InstancePtr->RepeaterValues.V[Offset]
					= CalcValue;

				/* Update for loop */
				Offset++;
				NumIterations--;
			}
			while (NumIterations > 0);
		}
		/* Otherwise */
		else {
			IsValid = FALSE;
		}
	}

	return (IsValid);
}
/*****************************************************************************/
/**
* This function calculates the SHA-1 Hash value for the Repeater Rx interface.
*
* @param	InstancePtr is the hdcp state machine.
* @param	RepeaterInfo is the repeater information.
*
* @return	Truth value indicating valid (TRUE) or invalid (FALSE).
*
* @note		None.
*
******************************************************************************/
This function calculates the SHA-1 Hash value for the Repeater Rx interface.
This function calculates the SHA - 1 Hash value for the Repeater Rx interface .
static int XHdcp1x_RxCalculateSHA1Value(XHdcp1x *InstancePtr, u16 RepeaterInfo)
{
	SHA1Context Sha1Context;
	u8 Buf[24];
	u32 NumToRead = 0;
	int IsValid = FALSE;
	u32 KsvCount;
	u64 tempKsv;
	memset(Buf, 0, 24);
	SHA1Reset(&Sha1Context);
	IsValid = TRUE;
	NumToRead = ((RepeaterInfo & 0x7Fu));
	KsvCount = 0;
	while (KsvCount < NumToRead) {
		if (InstancePtr->RepeaterValues.DeviceCount > 0) {
			tempKsv = InstancePtr->RepeaterValues.KsvList[KsvCount];
			XHDCP1X_PORT_UINT_TO_BUF(Buf , tempKsv ,
					(XHDCP1X_PORT_SIZE_BKSV*8));
			SHA1Input(&Sha1Context , Buf , XHDCP1X_PORT_SIZE_BKSV);
		}
		else {
			IsValid = FALSE;
		}
		KsvCount++;
	}
	if (IsValid) {
		u64 Mo = 0;
		u8 Sha1Result[SHA1HashSize];
		Buf[0] = (u8) (RepeaterInfo & 0xFFu);
		Buf[1] = (u8) ((RepeaterInfo >> 8) & 0xFFu);
		SHA1Input(&Sha1Context, Buf, 2);
		Mo = XHdcp1x_CipherGetMo(InstancePtr);
		XHDCP1X_PORT_UINT_TO_BUF(Buf, Mo, 64);
		SHA1Input(&Sha1Context, Buf, 8);
		if (SHA1Result(&Sha1Context, Sha1Result) == shaSuccess) {
			u8 Offset = 0;
			const u8 *Sha1Buf = Sha1Result;
			int NumIterations = (SHA1HashSize >> 2);
			do {
				u32 CalcValue = 0;
				CalcValue = *Sha1Buf++;
				CalcValue <<= 8;
				CalcValue |= *Sha1Buf++;
				CalcValue <<= 8;
				CalcValue |= *Sha1Buf++;
				CalcValue <<= 8;
				CalcValue |= *Sha1Buf++;
				InstancePtr->RepeaterValues.V[Offset]
					= CalcValue;
				Offset++;
				NumIterations--;
			}
			while (NumIterations > 0);
		}
		else {
			IsValid = FALSE;
		}
	}
	return (IsValid);
}
static int XHdcp1x_RxCalculateSHA1Value ( XHdcp1x * InstancePtr , u16 RepeaterInfo ) { SHA1Context Sha1Context ; u8 Buf [ 24 ] ; u32 NumToRead = 0 ; int IsValid = FALSE ; u32 KsvCount ; u64 tempKsv ; memset ( Buf , 0 , 24 ) ; SHA1Reset ( & Sha1Context ) ; IsValid = TRUE ; NumToRead = ( ( RepeaterInfo & 0x7Fu ) ) ; KsvCount = 0 ; while ( KsvCount < NumToRead ) { if ( InstancePtr -> RepeaterValues . DeviceCount > 0 ) { tempKsv = InstancePtr -> RepeaterValues . KsvList [ KsvCount ] ; XHDCP1X_PORT_UINT_TO_BUF ( Buf , tempKsv , ( XHDCP1X_PORT_SIZE_BKSV * 8 ) ) ; SHA1Input ( & Sha1Context , Buf , XHDCP1X_PORT_SIZE_BKSV ) ; } else { IsValid = FALSE ; } KsvCount ++ ; } if ( IsValid ) { u64 Mo = 0 ; u8 Sha1Result [ SHA1HashSize ] ; Buf [ 0 ] = ( u8 ) ( RepeaterInfo & 0xFFu ) ; Buf [ 1 ] = ( u8 ) ( ( RepeaterInfo >> 8 ) & 0xFFu ) ; SHA1Input ( & Sha1Context , Buf , 2 ) ; Mo = XHdcp1x_CipherGetMo ( InstancePtr ) ; XHDCP1X_PORT_UINT_TO_BUF ( Buf , Mo , 64 ) ; SHA1Input ( & Sha1Context , Buf , 8 ) ; if ( SHA1Result ( & Sha1Context , Sha1Result ) == shaSuccess ) { u8 Offset = 0 ; const u8 * Sha1Buf = Sha1Result ; int NumIterations = ( SHA1HashSize >> 2 ) ; do { u32 CalcValue = 0 ; CalcValue = * Sha1Buf ++ ; CalcValue <<= 8 ; CalcValue |= * Sha1Buf ++ ; CalcValue <<= 8 ; CalcValue |= * Sha1Buf ++ ; CalcValue <<= 8 ; CalcValue |= * Sha1Buf ++ ; InstancePtr -> RepeaterValues . V [ Offset ] = CalcValue ; Offset ++ ; NumIterations -- ; } while ( NumIterations > 0 ) ; } else { IsValid = FALSE ; } } return ( IsValid ) ; }
This function calculates the SHA-1 Hash value for the Repeater Rx interface.
This function calculates the SHA - 1 Hash value for the Repeater Rx interface .
/* Initialize Buf */ /* Initialize Sha1Context */ /* Assume success */ /* Determine theNumToRead */ /* Read one ksv at a time from the
	 * Ksv List and send it to SHA1 Input
	 */ /* Check for success */ /* Insert RepeaterInfo into the SHA-1 transform */ /* Insert the Mo into the SHA-1 transform */ /* Finalize the SHA-1 result and confirm success */ /* Offset(XHDCP1X_PORT_OFFSET_VH0) = 0 */ /* Iterate through the SHA-1 chunks */ /* Determine CalcValue */ /* Update the V' value in the Instance
				 * Pointer for the HDCP state machine
				 */ /* Update for loop */ /* Otherwise */