XilinxProcessorIPLib/drivers/dp14txss/examples/src/zcu_pt_dp14_hdcp/xdp_hdcp_keys.c
int XHdcp_LoadKeys(u8 *Hdcp22Lc128, u32 Hdcp22Lc128Size, u8 *Hdcp22RxPrivateKey, u32 Hdcp22RxPrivateKeySize,
		u8 *Hdcp14KeyA, u32 Hdcp14KeyASize, u8 *Hdcp14KeyB, u32 Hdcp14KeyBSize)
{
	u8 i;
	u8 HdcpSignature[16] = {"xilinx_hdcp_keys"};
	u8 Buffer[1024];
	u8 Password[32];
	u8 Key[32];
	u8 SignatureOk;
	u8 HdcpSignatureBuffer[16];
	SHA256_CTX Ctx;

	xil_printf("Before the HDCP functionality can be enabled, \r\n");
	xil_printf("the application will load the encrypted HDCP keys\r\n");
	xil_printf("from the DP FMC EEPROM.\r\n");
	xil_printf("The HDCP keys are protected with a unique password.\r\n");
	xil_printf("Please enter your password.\r\n");

	EnterPassword(Password);
	xil_printf("\r\n");


	// Generate password hash
	sha256_init(&Ctx);
	sha256_update(&Ctx, Password, sizeof(Password));
	sha256_final(&Ctx, Key);

	// Signature
	EepromGet(SIGNATURE_OFFSET, Buffer, sizeof(HdcpSignature));
	Decrypt(Buffer, HdcpSignatureBuffer, Key, sizeof(HdcpSignature));

	SignatureOk = TRUE;
	for (i=0; i<sizeof(HdcpSignature); i++)
	{
		if (HdcpSignature[i] != HdcpSignatureBuffer[i])
			SignatureOk = FALSE;
	}

	if (SignatureOk)
	{
		xil_printf("Password is valid.\r\n");
		xil_printf("Loading HDCP keys from EEPROM... ");

		// HDCP 2.2 LC128
		// Read from EEPROM
		EepromGet(HDCP22_LC128_OFFSET, Buffer, Round16(Hdcp22Lc128Size));

		// Decrypt
		Decrypt(Buffer, Hdcp22Lc128, Key, Hdcp22Lc128Size);

		// Certificate
		// Read from EEPROM
		EepromGet(HDCP22_CERTIFICATE_OFFSET, Buffer, Round16(Hdcp22RxPrivateKeySize));

		// Decrypt
		Decrypt(Buffer, Hdcp22RxPrivateKey, Key, Hdcp22RxPrivateKeySize);

		// HDCP 1.4 key A
		// Read from EEPROM
		EepromGet(HDCP14_KEY1_OFFSET, Buffer, Round16(Hdcp14KeyASize));

		// Decrypt
		Decrypt(Buffer, Hdcp14KeyA, Key, Hdcp14KeyASize);

		// HDCP 1.4 key B
		// Read from EEPROM
		EepromGet(HDCP14_KEY2_OFFSET, Buffer, Round16(Hdcp14KeyBSize));

		// Decrypt
		Decrypt(Buffer, Hdcp14KeyB, Key, Hdcp14KeyBSize);
		xil_printf("done\r\n");
		xil_printf("Enabling HDCP functionality\r\n");

		return XST_SUCCESS;
	}
	else
	{
		xil_printf("The password is not valid.\r\n");
		xil_printf("Is the EEPROM programmed and is the password correct?\r\n");
		xil_printf("Disabled HDCP functionality\r\n");
		return XST_FAILURE;
	}
}
/*****************************************************************************/
/**
 *
 * This function loads the HDCP keys from the eeprom
 *
 *
 * @return
 *  - XST_SUCCESS if action was successful
 *  - XST_FAILURE if action was not successful
 *
 ******************************************************************************/
This function loads the HDCP keys from the eeprom
@return
- XST_SUCCESS if action was successful
- XST_FAILURE if action was not successful
This function loads the HDCP keys from the eeprom @return - XST_SUCCESS if action was successful - XST_FAILURE if action was not successful
int XHdcp_LoadKeys(u8 *Hdcp22Lc128, u32 Hdcp22Lc128Size, u8 *Hdcp22RxPrivateKey, u32 Hdcp22RxPrivateKeySize,
		u8 *Hdcp14KeyA, u32 Hdcp14KeyASize, u8 *Hdcp14KeyB, u32 Hdcp14KeyBSize)
{
	u8 i;
	u8 HdcpSignature[16] = {"xilinx_hdcp_keys"};
	u8 Buffer[1024];
	u8 Password[32];
	u8 Key[32];
	u8 SignatureOk;
	u8 HdcpSignatureBuffer[16];
	SHA256_CTX Ctx;
	xil_printf("Before the HDCP functionality can be enabled, \r\n");
	xil_printf("the application will load the encrypted HDCP keys\r\n");
	xil_printf("from the DP FMC EEPROM.\r\n");
	xil_printf("The HDCP keys are protected with a unique password.\r\n");
	xil_printf("Please enter your password.\r\n");
	EnterPassword(Password);
	xil_printf("\r\n");
	sha256_init(&Ctx);
	sha256_update(&Ctx, Password, sizeof(Password));
	sha256_final(&Ctx, Key);
	EepromGet(SIGNATURE_OFFSET, Buffer, sizeof(HdcpSignature));
	Decrypt(Buffer, HdcpSignatureBuffer, Key, sizeof(HdcpSignature));
	SignatureOk = TRUE;
	for (i=0; i<sizeof(HdcpSignature); i++)
	{
		if (HdcpSignature[i] != HdcpSignatureBuffer[i])
			SignatureOk = FALSE;
	}
	if (SignatureOk)
	{
		xil_printf("Password is valid.\r\n");
		xil_printf("Loading HDCP keys from EEPROM... ");
		EepromGet(HDCP22_LC128_OFFSET, Buffer, Round16(Hdcp22Lc128Size));
		Decrypt(Buffer, Hdcp22Lc128, Key, Hdcp22Lc128Size);
		EepromGet(HDCP22_CERTIFICATE_OFFSET, Buffer, Round16(Hdcp22RxPrivateKeySize));
		Decrypt(Buffer, Hdcp22RxPrivateKey, Key, Hdcp22RxPrivateKeySize);
		EepromGet(HDCP14_KEY1_OFFSET, Buffer, Round16(Hdcp14KeyASize));
		Decrypt(Buffer, Hdcp14KeyA, Key, Hdcp14KeyASize);
		EepromGet(HDCP14_KEY2_OFFSET, Buffer, Round16(Hdcp14KeyBSize));
		Decrypt(Buffer, Hdcp14KeyB, Key, Hdcp14KeyBSize);
		xil_printf("done\r\n");
		xil_printf("Enabling HDCP functionality\r\n");
		return XST_SUCCESS;
	}
	else
	{
		xil_printf("The password is not valid.\r\n");
		xil_printf("Is the EEPROM programmed and is the password correct?\r\n");
		xil_printf("Disabled HDCP functionality\r\n");
		return XST_FAILURE;
	}
}
int XHdcp_LoadKeys ( u8 * Hdcp22Lc128 , u32 Hdcp22Lc128Size , u8 * Hdcp22RxPrivateKey , u32 Hdcp22RxPrivateKeySize , u8 * Hdcp14KeyA , u32 Hdcp14KeyASize , u8 * Hdcp14KeyB , u32 Hdcp14KeyBSize ) { u8 i ; u8 HdcpSignature [ 16 ] = { " " } ; u8 Buffer [ 1024 ] ; u8 Password [ 32 ] ; u8 Key [ 32 ] ; u8 SignatureOk ; u8 HdcpSignatureBuffer [ 16 ] ; SHA256_CTX Ctx ; xil_printf ( " \r \n " ) ; xil_printf ( " \r \n " ) ; xil_printf ( " \r \n " ) ; xil_printf ( " \r \n " ) ; xil_printf ( " \r \n " ) ; EnterPassword ( Password ) ; xil_printf ( " \r \n " ) ; sha256_init ( & Ctx ) ; sha256_update ( & Ctx , Password , sizeof ( Password ) ) ; sha256_final ( & Ctx , Key ) ; EepromGet ( SIGNATURE_OFFSET , Buffer , sizeof ( HdcpSignature ) ) ; Decrypt ( Buffer , HdcpSignatureBuffer , Key , sizeof ( HdcpSignature ) ) ; SignatureOk = TRUE ; for ( i = 0 ; i < sizeof ( HdcpSignature ) ; i ++ ) { if ( HdcpSignature [ i ] != HdcpSignatureBuffer [ i ] ) SignatureOk = FALSE ; } if ( SignatureOk ) { xil_printf ( " \r \n " ) ; xil_printf ( " " ) ; EepromGet ( HDCP22_LC128_OFFSET , Buffer , Round16 ( Hdcp22Lc128Size ) ) ; Decrypt ( Buffer , Hdcp22Lc128 , Key , Hdcp22Lc128Size ) ; EepromGet ( HDCP22_CERTIFICATE_OFFSET , Buffer , Round16 ( Hdcp22RxPrivateKeySize ) ) ; Decrypt ( Buffer , Hdcp22RxPrivateKey , Key , Hdcp22RxPrivateKeySize ) ; EepromGet ( HDCP14_KEY1_OFFSET , Buffer , Round16 ( Hdcp14KeyASize ) ) ; Decrypt ( Buffer , Hdcp14KeyA , Key , Hdcp14KeyASize ) ; EepromGet ( HDCP14_KEY2_OFFSET , Buffer , Round16 ( Hdcp14KeyBSize ) ) ; Decrypt ( Buffer , Hdcp14KeyB , Key , Hdcp14KeyBSize ) ; xil_printf ( " \r \n " ) ; xil_printf ( " \r \n " ) ; return XST_SUCCESS ; } else { xil_printf ( " \r \n " ) ; xil_printf ( " \r \n " ) ; xil_printf ( " \r \n " ) ; return XST_FAILURE ; } }
This function loads the HDCP keys from the eeprom
 @return
  - XST_SUCCESS if action was successful
  - XST_FAILURE if action was not successful
This function loads the HDCP keys from the eeprom @return - XST_SUCCESS if action was successful - XST_FAILURE if action was not successful
// Generate password hash // Signature // HDCP 2.2 LC128 // Read from EEPROM // Decrypt // Certificate // Read from EEPROM // Decrypt // HDCP 1.4 key A // Read from EEPROM // Decrypt // HDCP 1.4 key B // Read from EEPROM // Decrypt